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) 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]
theorem natCast_toNat (p : ℕ) : ∀ {z : ℤ} (_h : 0 ≤ z), (z.toNat : ZMod p) = z
| (n : ℕ), _h => by simp only [Int.cast_natCast, Int.toNat_natCast]
| Int.negSucc n, h => by simp at h
theorem val_injective (n : ℕ) [NeZero n] : Function.Injective (val : ZMod n → ℕ) := by
cases n
· cases NeZero.ne 0 rfl
intro a b h
dsimp [ZMod]
ext
exact h
theorem val_one_eq_one_mod (n : ℕ) : (1 : ZMod n).val = 1 % n := by
rw [← Nat.cast_one, val_natCast]
theorem val_two_eq_two_mod (n : ℕ) : (2 : ZMod n).val = 2 % n := by
rw [← Nat.cast_two, val_natCast]
theorem val_one (n : ℕ) [Fact (1 < n)] : (1 : ZMod n).val = 1 := by
rw [val_one_eq_one_mod]
exact Nat.mod_eq_of_lt Fact.out
lemma val_one'' : ∀ {n}, n ≠ 1 → (1 : ZMod n).val = 1
| 0, _ => rfl
| 1, hn => by cases hn rfl
| n + 2, _ =>
haveI : Fact (1 < n + 2) := ⟨by simp⟩
ZMod.val_one _
theorem val_add {n : ℕ} [NeZero n] (a b : ZMod n) : (a + b).val = (a.val + b.val) % n := by
cases n
· cases NeZero.ne 0 rfl
· apply Fin.val_add
theorem val_add_of_lt {n : ℕ} {a b : ZMod n} (h : a.val + b.val < n) :
(a + b).val = a.val + b.val := by
have : NeZero n := by constructor; rintro rfl; simp at h
rw [ZMod.val_add, Nat.mod_eq_of_lt h]
theorem val_add_val_of_le {n : ℕ} [NeZero n] {a b : ZMod n} (h : n ≤ a.val + b.val) :
a.val + b.val = (a + b).val + n := by
rw [val_add, Nat.add_mod_add_of_le_add_mod, Nat.mod_eq_of_lt (val_lt _),
Nat.mod_eq_of_lt (val_lt _)]
rwa [Nat.mod_eq_of_lt (val_lt _), Nat.mod_eq_of_lt (val_lt _)]
theorem val_add_of_le {n : ℕ} [NeZero n] {a b : ZMod n} (h : n ≤ a.val + b.val) :
(a + b).val = a.val + b.val - n := by
rw [val_add_val_of_le h]
exact eq_tsub_of_add_eq rfl
theorem val_add_le {n : ℕ} (a b : ZMod n) : (a + b).val ≤ a.val + b.val := by
cases n
· simpa [ZMod.val] using Int.natAbs_add_le _ _
· simpa [ZMod.val_add] using Nat.mod_le _ _
theorem val_mul {n : ℕ} (a b : ZMod n) : (a * b).val = a.val * b.val % n := by
cases n
· rw [Nat.mod_zero]
apply Int.natAbs_mul
· apply Fin.val_mul
theorem val_mul_le {n : ℕ} (a b : ZMod n) : (a * b).val ≤ a.val * b.val := by
rw [val_mul]
apply Nat.mod_le
theorem val_mul_of_lt {n : ℕ} {a b : ZMod n} (h : a.val * b.val < n) :
(a * b).val = a.val * b.val := by
rw [val_mul]
apply Nat.mod_eq_of_lt h
theorem val_mul_iff_lt {n : ℕ} [NeZero n] (a b : ZMod n) :
(a * b).val = a.val * b.val ↔ a.val * b.val < n := by
constructor <;> intro h
· rw [← h]; apply ZMod.val_lt
· apply ZMod.val_mul_of_lt h
instance nontrivial (n : ℕ) [Fact (1 < n)] : Nontrivial (ZMod n) :=
⟨⟨0, 1, fun h =>
zero_ne_one <|
calc
0 = (0 : ZMod n).val := by rw [val_zero]
_ = (1 : ZMod n).val := congr_arg ZMod.val h
_ = 1 := val_one n
⟩⟩
instance nontrivial' : Nontrivial (ZMod 0) := by
delta ZMod; infer_instance
lemma one_eq_zero_iff {n : ℕ} : (1 : ZMod n) = 0 ↔ n = 1 := by
rw [← Nat.cast_one, natCast_zmod_eq_zero_iff_dvd, Nat.dvd_one]
/-- The inversion on `ZMod n`.
It is setup in such a way that `a * a⁻¹` is equal to `gcd a.val n`.
In particular, if `a` is coprime to `n`, and hence a unit, `a * a⁻¹ = 1`. -/
def inv : ∀ n : ℕ, ZMod n → ZMod n
| 0, i => Int.sign i
| n + 1, i => Nat.gcdA i.val (n + 1)
instance (n : ℕ) : Inv (ZMod n) :=
⟨inv n⟩
theorem inv_zero : ∀ n : ℕ, (0 : ZMod n)⁻¹ = 0
| 0 => Int.sign_zero
| n + 1 =>
show (Nat.gcdA _ (n + 1) : ZMod (n + 1)) = 0 by
rw [val_zero]
unfold Nat.gcdA Nat.xgcd Nat.xgcdAux
rfl
theorem mul_inv_eq_gcd {n : ℕ} (a : ZMod n) : a * a⁻¹ = Nat.gcd a.val n := by
rcases n with - | n
· dsimp [ZMod] at a ⊢
calc
_ = a * Int.sign a := rfl
_ = a.natAbs := by rw [Int.mul_sign_self]
_ = a.natAbs.gcd 0 := by rw [Nat.gcd_zero_right]
· calc
a * a⁻¹ = a * a⁻¹ + n.succ * Nat.gcdB (val a) n.succ := by
rw [natCast_self, zero_mul, add_zero]
_ = ↑(↑a.val * Nat.gcdA (val a) n.succ + n.succ * Nat.gcdB (val a) n.succ) := by
push_cast
rw [natCast_zmod_val]
rfl
_ = Nat.gcd a.val n.succ := by rw [← Nat.gcd_eq_gcd_ab a.val n.succ]; rfl
@[simp] protected lemma inv_one (n : ℕ) : (1⁻¹ : ZMod n) = 1 := by
obtain rfl | hn := eq_or_ne n 1
· exact Subsingleton.elim _ _
· simpa [ZMod.val_one'' hn] using mul_inv_eq_gcd (1 : ZMod n)
@[simp]
theorem natCast_mod (a : ℕ) (n : ℕ) : ((a % n : ℕ) : ZMod n) = a := by
conv =>
rhs
rw [← Nat.mod_add_div a n]
simp
theorem eq_iff_modEq_nat (n : ℕ) {a b : ℕ} : (a : ZMod n) = b ↔ a ≡ b [MOD n] := by
cases n
· simp [Nat.ModEq, Int.natCast_inj, Nat.mod_zero]
· rw [Fin.ext_iff, Nat.ModEq, ← val_natCast, ← val_natCast]
exact Iff.rfl
theorem eq_zero_iff_even {n : ℕ} : (n : ZMod 2) = 0 ↔ Even n :=
(CharP.cast_eq_zero_iff (ZMod 2) 2 n).trans even_iff_two_dvd.symm
theorem eq_one_iff_odd {n : ℕ} : (n : ZMod 2) = 1 ↔ Odd n := by
rw [← @Nat.cast_one (ZMod 2), ZMod.eq_iff_modEq_nat, Nat.odd_iff, Nat.ModEq]
theorem ne_zero_iff_odd {n : ℕ} : (n : ZMod 2) ≠ 0 ↔ Odd n := by
constructor <;>
· contrapose
simp [eq_zero_iff_even]
theorem coe_mul_inv_eq_one {n : ℕ} (x : ℕ) (h : Nat.Coprime x n) :
((x : ZMod n) * (x : ZMod n)⁻¹) = 1 := by
rw [Nat.Coprime, Nat.gcd_comm, Nat.gcd_rec] at h
rw [mul_inv_eq_gcd, val_natCast, h, Nat.cast_one]
lemma mul_val_inv (hmn : m.Coprime n) : (m * (m⁻¹ : ZMod n).val : ZMod n) = 1 := by
obtain rfl | hn := eq_or_ne n 0
· simp [m.coprime_zero_right.1 hmn]
haveI : NeZero n := ⟨hn⟩
rw [ZMod.natCast_zmod_val, ZMod.coe_mul_inv_eq_one _ hmn]
lemma val_inv_mul (hmn : m.Coprime n) : ((m⁻¹ : ZMod n).val * m : ZMod n) = 1 := by
rw [mul_comm, mul_val_inv hmn]
/-- `unitOfCoprime` makes an element of `(ZMod n)ˣ` given
a natural number `x` and a proof that `x` is coprime to `n` -/
def unitOfCoprime {n : ℕ} (x : ℕ) (h : Nat.Coprime x n) : (ZMod n)ˣ :=
⟨x, x⁻¹, coe_mul_inv_eq_one x h, by rw [mul_comm, coe_mul_inv_eq_one x h]⟩
@[simp]
theorem coe_unitOfCoprime {n : ℕ} (x : ℕ) (h : Nat.Coprime x n) :
(unitOfCoprime x h : ZMod n) = x :=
rfl
theorem val_coe_unit_coprime {n : ℕ} (u : (ZMod n)ˣ) : Nat.Coprime (u : ZMod n).val n := by
rcases n with - | n
· rcases Int.units_eq_one_or u with (rfl | rfl) <;> simp
apply Nat.coprime_of_mul_modEq_one ((u⁻¹ : Units (ZMod (n + 1))) : ZMod (n + 1)).val
have := Units.ext_iff.1 (mul_inv_cancel u)
rw [Units.val_one] at this
rw [← eq_iff_modEq_nat, Nat.cast_one, ← this]; clear this
rw [← natCast_zmod_val ((u * u⁻¹ : Units (ZMod (n + 1))) : ZMod (n + 1))]
rw [Units.val_mul, val_mul, natCast_mod]
lemma isUnit_iff_coprime (m n : ℕ) : IsUnit (m : ZMod n) ↔ m.Coprime n := by
refine ⟨fun H ↦ ?_, fun H ↦ (unitOfCoprime m H).isUnit⟩
have H' := val_coe_unit_coprime H.unit
rw [IsUnit.unit_spec, val_natCast, Nat.coprime_iff_gcd_eq_one] at H'
rw [Nat.coprime_iff_gcd_eq_one, Nat.gcd_comm, ← H']
exact Nat.gcd_rec n m
lemma isUnit_prime_iff_not_dvd {n p : ℕ} (hp : p.Prime) : IsUnit (p : ZMod n) ↔ ¬p ∣ n := by
rw [isUnit_iff_coprime, Nat.Prime.coprime_iff_not_dvd hp]
lemma isUnit_prime_of_not_dvd {n p : ℕ} (hp : p.Prime) (h : ¬ p ∣ n) : IsUnit (p : ZMod n) :=
(isUnit_prime_iff_not_dvd hp).mpr h
@[simp]
theorem inv_coe_unit {n : ℕ} (u : (ZMod n)ˣ) : (u : ZMod n)⁻¹ = (u⁻¹ : (ZMod n)ˣ) := by
have := congr_arg ((↑) : ℕ → ZMod n) (val_coe_unit_coprime u)
rw [← mul_inv_eq_gcd, Nat.cast_one] at this
let u' : (ZMod n)ˣ := ⟨u, (u : ZMod n)⁻¹, this, by rwa [mul_comm]⟩
have h : u = u' := by
apply Units.ext
rfl
rw [h]
rfl
theorem mul_inv_of_unit {n : ℕ} (a : ZMod n) (h : IsUnit a) : a * a⁻¹ = 1 := by
rcases h with ⟨u, rfl⟩
rw [inv_coe_unit, u.mul_inv]
theorem inv_mul_of_unit {n : ℕ} (a : ZMod n) (h : IsUnit a) : a⁻¹ * a = 1 := by
rw [mul_comm, mul_inv_of_unit a h]
-- TODO: If we changed `⁻¹` so that `ZMod n` is always a `DivisionMonoid`,
-- then we could use the general lemma `inv_eq_of_mul_eq_one`
protected theorem inv_eq_of_mul_eq_one (n : ℕ) (a b : ZMod n) (h : a * b = 1) : a⁻¹ = b :=
left_inv_eq_right_inv (inv_mul_of_unit a ⟨⟨a, b, h, mul_comm a b ▸ h⟩, rfl⟩) h
lemma inv_mul_eq_one_of_isUnit {n : ℕ} {a : ZMod n} (ha : IsUnit a) (b : ZMod n) :
a⁻¹ * b = 1 ↔ a = b := by
-- ideally, this would be `ha.inv_mul_eq_one`, but `ZMod n` is not a `DivisionMonoid`...
-- (see the "TODO" above)
refine ⟨fun H ↦ ?_, fun H ↦ H ▸ a.inv_mul_of_unit ha⟩
apply_fun (a * ·) at H
rwa [← mul_assoc, a.mul_inv_of_unit ha, one_mul, mul_one, eq_comm] at H
-- TODO: this equivalence is true for `ZMod 0 = ℤ`, but needs to use different functions.
/-- Equivalence between the units of `ZMod n` and
the subtype of terms `x : ZMod n` for which `x.val` is coprime to `n` -/
def unitsEquivCoprime {n : ℕ} [NeZero n] : (ZMod n)ˣ ≃ { x : ZMod n // Nat.Coprime x.val n } where
toFun x := ⟨x, val_coe_unit_coprime x⟩
invFun x := unitOfCoprime x.1.val x.2
left_inv := fun ⟨_, _, _, _⟩ => Units.ext (natCast_zmod_val _)
right_inv := fun ⟨_, _⟩ => by simp
/-- The **Chinese remainder theorem**. For a pair of coprime natural numbers, `m` and `n`,
the rings `ZMod (m * n)` and `ZMod m × ZMod n` are isomorphic.
See `Ideal.quotientInfRingEquivPiQuotient` for the Chinese remainder theorem for ideals in any
ring.
-/
def chineseRemainder {m n : ℕ} (h : m.Coprime n) : ZMod (m * n) ≃+* ZMod m × ZMod n :=
let to_fun : ZMod (m * n) → ZMod m × ZMod n :=
ZMod.castHom (show m.lcm n ∣ m * n by simp [Nat.lcm_dvd_iff]) (ZMod m × ZMod n)
let inv_fun : ZMod m × ZMod n → ZMod (m * n) := fun x =>
if m * n = 0 then
if m = 1 then cast (RingHom.snd _ (ZMod n) x) else cast (RingHom.fst (ZMod m) _ x)
else Nat.chineseRemainder h x.1.val x.2.val
have inv : Function.LeftInverse inv_fun to_fun ∧ Function.RightInverse inv_fun to_fun :=
if hmn0 : m * n = 0 then by
rcases h.eq_of_mul_eq_zero hmn0 with (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩)
· constructor
· intro x; rfl
· rintro ⟨x, y⟩
fin_cases y
simp [to_fun, inv_fun, castHom, Prod.ext_iff, eq_iff_true_of_subsingleton]
· constructor
· intro x; rfl
· rintro ⟨x, y⟩
fin_cases x
simp [to_fun, inv_fun, castHom, Prod.ext_iff, eq_iff_true_of_subsingleton]
else by
haveI : NeZero (m * n) := ⟨hmn0⟩
haveI : NeZero m := ⟨left_ne_zero_of_mul hmn0⟩
haveI : NeZero n := ⟨right_ne_zero_of_mul hmn0⟩
have left_inv : Function.LeftInverse inv_fun to_fun := by
intro x
dsimp only [to_fun, inv_fun, ZMod.castHom_apply]
conv_rhs => rw [← ZMod.natCast_zmod_val x]
rw [if_neg hmn0, ZMod.eq_iff_modEq_nat, ← Nat.modEq_and_modEq_iff_modEq_mul h,
Prod.fst_zmod_cast, Prod.snd_zmod_cast]
refine
⟨(Nat.chineseRemainder h (cast x : ZMod m).val (cast x : ZMod n).val).2.left.trans ?_,
(Nat.chineseRemainder h (cast x : ZMod m).val (cast x : ZMod n).val).2.right.trans ?_⟩
· rw [← ZMod.eq_iff_modEq_nat, ZMod.natCast_zmod_val, ZMod.natCast_val]
· rw [← ZMod.eq_iff_modEq_nat, ZMod.natCast_zmod_val, ZMod.natCast_val]
exact ⟨left_inv, left_inv.rightInverse_of_card_le (by simp)⟩
{ toFun := to_fun,
invFun := inv_fun,
map_mul' := RingHom.map_mul _
map_add' := RingHom.map_add _
left_inv := inv.1
right_inv := inv.2 }
lemma subsingleton_iff {n : ℕ} : Subsingleton (ZMod n) ↔ n = 1 := by
constructor
· obtain (_ | _ | n) := n
· simpa [ZMod] using not_subsingleton _
· simp [ZMod]
· simpa [ZMod] using not_subsingleton _
· rintro rfl
infer_instance
lemma nontrivial_iff {n : ℕ} : Nontrivial (ZMod n) ↔ n ≠ 1 := by
rw [← not_subsingleton_iff_nontrivial, subsingleton_iff]
-- todo: this can be made a `Unique` instance.
instance subsingleton_units : Subsingleton (ZMod 2)ˣ :=
⟨by decide⟩
@[simp]
theorem add_self_eq_zero_iff_eq_zero {n : ℕ} (hn : Odd n) {a : ZMod n} :
a + a = 0 ↔ a = 0 := by
rw [Nat.odd_iff, ← Nat.two_dvd_ne_zero, ← Nat.prime_two.coprime_iff_not_dvd] at hn
rw [← mul_two, ← @Nat.cast_two (ZMod n), ← ZMod.coe_unitOfCoprime 2 hn, Units.mul_left_eq_zero]
theorem ne_neg_self {n : ℕ} (hn : Odd n) {a : ZMod n} (ha : a ≠ 0) : a ≠ -a := by
rwa [Ne, eq_neg_iff_add_eq_zero, add_self_eq_zero_iff_eq_zero hn]
theorem neg_one_ne_one {n : ℕ} [Fact (2 < n)] : (-1 : ZMod n) ≠ 1 :=
CharP.neg_one_ne_one (ZMod n) n
@[simp]
theorem neg_eq_self_mod_two (a : ZMod 2) : -a = a := by
fin_cases a <;> apply Fin.ext <;> simp [Fin.coe_neg, Int.natMod]; rfl
@[simp]
theorem natAbs_mod_two (a : ℤ) : (a.natAbs : ZMod 2) = a := by
cases a
· simp only [Int.natAbs_natCast, Int.cast_natCast, Int.ofNat_eq_coe]
· simp only [neg_eq_self_mod_two, Nat.cast_succ, Int.natAbs, Int.cast_negSucc]
theorem val_ne_zero {n : ℕ} (a : ZMod n) : a.val ≠ 0 ↔ a ≠ 0 :=
(val_eq_zero a).not
theorem val_pos {n : ℕ} {a : ZMod n} : 0 < a.val ↔ a ≠ 0 := by
simp [pos_iff_ne_zero]
theorem val_eq_one : ∀ {n : ℕ} (_ : 1 < n) (a : ZMod n), a.val = 1 ↔ a = 1
| 0, hn, _
| 1, hn, _ => by simp at hn
| n + 2, _, _ => by simp only [val, ZMod, Fin.ext_iff, Fin.val_one]
theorem neg_eq_self_iff {n : ℕ} (a : ZMod n) : -a = a ↔ a = 0 ∨ 2 * a.val = n := by
rw [neg_eq_iff_add_eq_zero, ← two_mul]
cases n
· rw [@mul_eq_zero ℤ, @mul_eq_zero ℕ, val_eq_zero]
exact
⟨fun h => h.elim (by simp) Or.inl, fun h =>
Or.inr (h.elim id fun h => h.elim (by simp) id)⟩
conv_lhs =>
rw [← a.natCast_zmod_val, ← Nat.cast_two, ← Nat.cast_mul, natCast_zmod_eq_zero_iff_dvd]
constructor
· rintro ⟨m, he⟩
rcases m with - | m
· rw [mul_zero, mul_eq_zero] at he
rcases he with (⟨⟨⟩⟩ | he)
exact Or.inl (a.val_eq_zero.1 he)
cases m
· right
rwa [show 0 + 1 = 1 from rfl, mul_one] at he
refine (a.val_lt.not_le <| Nat.le_of_mul_le_mul_left ?_ zero_lt_two).elim
rw [he, mul_comm]
apply Nat.mul_le_mul_left
simp
· rintro (rfl | h)
· rw [val_zero, mul_zero]
apply dvd_zero
· rw [h]
theorem val_cast_of_lt {n : ℕ} {a : ℕ} (h : a < n) : (a : ZMod n).val = a := by
rw [val_natCast, Nat.mod_eq_of_lt h]
theorem val_cast_zmod_lt {m : ℕ} [NeZero m] (n : ℕ) [NeZero n] (a : ZMod m) :
(a.cast : ZMod n).val < m := by
rcases m with (⟨⟩|⟨m⟩); · cases NeZero.ne 0 rfl
by_cases h : m < n
· rcases n with (⟨⟩|⟨n⟩); · simp at h
rw [← natCast_val, val_cast_of_lt]
· apply a.val_lt
apply lt_of_le_of_lt (Nat.le_of_lt_succ (ZMod.val_lt a)) h
· rw [not_lt] at h
apply lt_of_lt_of_le (ZMod.val_lt _) (le_trans h (Nat.le_succ m))
theorem neg_val' {n : ℕ} [NeZero n] (a : ZMod n) : (-a).val = (n - a.val) % n :=
calc
(-a).val = val (-a) % n := by rw [Nat.mod_eq_of_lt (-a).val_lt]
_ = (n - val a) % n :=
Nat.ModEq.add_right_cancel' (val a)
(by
rw [Nat.ModEq, ← val_add, neg_add_cancel, tsub_add_cancel_of_le a.val_le, Nat.mod_self,
val_zero])
theorem neg_val {n : ℕ} [NeZero n] (a : ZMod n) : (-a).val = if a = 0 then 0 else n - a.val := by
rw [neg_val']
by_cases h : a = 0; · rw [if_pos h, h, val_zero, tsub_zero, Nat.mod_self]
rw [if_neg h]
apply Nat.mod_eq_of_lt
apply Nat.sub_lt (NeZero.pos n)
contrapose! h
rwa [Nat.le_zero, val_eq_zero] at h
theorem val_neg_of_ne_zero {n : ℕ} [nz : NeZero n] (a : ZMod n) [na : NeZero a] :
(- a).val = n - a.val := by simp_all [neg_val a, na.out]
theorem val_sub {n : ℕ} [NeZero n] {a b : ZMod n} (h : b.val ≤ a.val) :
(a - b).val = a.val - b.val := by
by_cases hb : b = 0
· cases hb; simp
· have : NeZero b := ⟨hb⟩
rw [sub_eq_add_neg, val_add, val_neg_of_ne_zero, ← Nat.add_sub_assoc (le_of_lt (val_lt _)),
add_comm, Nat.add_sub_assoc h, Nat.add_mod_left]
apply Nat.mod_eq_of_lt (tsub_lt_of_lt (val_lt _))
theorem val_cast_eq_val_of_lt {m n : ℕ} [nzm : NeZero m] {a : ZMod m}
(h : a.val < n) : (a.cast : ZMod n).val = a.val := by
have nzn : NeZero n := by constructor; rintro rfl; simp at h
cases m with
| zero => cases nzm; simp_all
| succ m =>
cases n with
| zero => cases nzn; simp_all
| succ n => exact Fin.val_cast_of_lt h
theorem cast_cast_zmod_of_le {m n : ℕ} [hm : NeZero m] (h : m ≤ n) (a : ZMod m) :
(cast (cast a : ZMod n) : ZMod m) = a := by
have : NeZero n := ⟨((Nat.zero_lt_of_ne_zero hm.out).trans_le h).ne'⟩
rw [cast_eq_val, val_cast_eq_val_of_lt (a.val_lt.trans_le h), natCast_zmod_val]
theorem val_pow {m n : ℕ} {a : ZMod n} [ilt : Fact (1 < n)] (h : a.val ^ m < n) :
(a ^ m).val = a.val ^ m := by
induction m with
| zero => simp [ZMod.val_one]
| succ m ih =>
have : a.val ^ m < n := by
obtain rfl | ha := eq_or_ne a 0
· by_cases hm : m = 0
· cases hm; simp [ilt.out]
· simp only [val_zero, ne_eq, hm, not_false_eq_true, zero_pow, Nat.zero_lt_of_lt h]
· exact lt_of_le_of_lt
(Nat.pow_le_pow_right (by rwa [gt_iff_lt, ZMod.val_pos]) (Nat.le_succ m)) h
rw [pow_succ, ZMod.val_mul, ih this, ← pow_succ, Nat.mod_eq_of_lt h]
theorem val_pow_le {m n : ℕ} [Fact (1 < n)] {a : ZMod n} : (a ^ m).val ≤ a.val ^ m := by
induction m with
| zero => simp [ZMod.val_one]
| succ m ih =>
rw [pow_succ, pow_succ]
apply le_trans (ZMod.val_mul_le _ _)
apply Nat.mul_le_mul_right _ ih
theorem natAbs_min_of_le_div_two (n : ℕ) (x y : ℤ) (he : (x : ZMod n) = y) (hl : x.natAbs ≤ n / 2) :
x.natAbs ≤ y.natAbs := by
rw [intCast_eq_intCast_iff_dvd_sub] at he
obtain ⟨m, he⟩ := he
rw [sub_eq_iff_eq_add] at he
subst he
obtain rfl | hm := eq_or_ne m 0
· rw [mul_zero, zero_add]
apply hl.trans
rw [← add_le_add_iff_right x.natAbs]
refine le_trans (le_trans ((add_le_add_iff_left _).2 hl) ?_) (Int.natAbs_sub_le _ _)
rw [add_sub_cancel_right, Int.natAbs_mul, Int.natAbs_natCast]
refine le_trans ?_ (Nat.le_mul_of_pos_right _ <| Int.natAbs_pos.2 hm)
rw [← mul_two]; apply Nat.div_mul_le_self
end ZMod
theorem RingHom.ext_zmod {n : ℕ} {R : Type*} [NonAssocSemiring R] (f g : ZMod n →+* R) : f = g := by
ext a
obtain ⟨k, rfl⟩ := ZMod.intCast_surjective a
let φ : ℤ →+* R := f.comp (Int.castRingHom (ZMod n))
let ψ : ℤ →+* R := g.comp (Int.castRingHom (ZMod n))
show φ k = ψ k
rw [φ.ext_int ψ]
namespace ZMod
variable {n : ℕ} {R : Type*}
instance subsingleton_ringHom [Semiring R] : Subsingleton (ZMod n →+* R) :=
⟨RingHom.ext_zmod⟩
instance subsingleton_ringEquiv [Semiring R] : Subsingleton (ZMod n ≃+* R) :=
⟨fun f g => by
rw [RingEquiv.coe_ringHom_inj_iff]
apply RingHom.ext_zmod _ _⟩
@[simp]
theorem ringHom_map_cast [NonAssocRing R] (f : R →+* ZMod n) (k : ZMod n) : f (cast k) = k := by
cases n
· dsimp [ZMod, ZMod.cast] at f k ⊢; simp
· dsimp [ZMod.cast]
rw [map_natCast, natCast_zmod_val]
/-- Any ring homomorphism into `ZMod n` has a right inverse. -/
theorem ringHom_rightInverse [NonAssocRing R] (f : R →+* ZMod n) :
Function.RightInverse (cast : ZMod n → R) f :=
ringHom_map_cast f
/-- Any ring homomorphism into `ZMod n` is surjective. -/
theorem ringHom_surjective [NonAssocRing R] (f : R →+* ZMod n) : Function.Surjective f :=
(ringHom_rightInverse f).surjective
@[simp]
lemma castHom_self : ZMod.castHom dvd_rfl (ZMod n) = RingHom.id (ZMod n) :=
Subsingleton.elim _ _
@[simp]
lemma castHom_comp {m d : ℕ} (hm : n ∣ m) (hd : m ∣ d) :
(castHom hm (ZMod n)).comp (castHom hd (ZMod m)) = castHom (dvd_trans hm hd) (ZMod n) :=
RingHom.ext_zmod _ _
section lift
variable (n) {A : Type*} [AddGroup A]
/-- The map from `ZMod n` induced by `f : ℤ →+ A` that maps `n` to `0`. -/
def lift : { f : ℤ →+ A // f n = 0 } ≃ (ZMod n →+ A) :=
(Equiv.subtypeEquivRight <| by
intro f
rw [ker_intCastAddHom]
constructor
· rintro hf _ ⟨x, rfl⟩
simp only [f.map_zsmul, zsmul_zero, f.mem_ker, hf]
· intro h
exact h (AddSubgroup.mem_zmultiples _)).trans <|
(Int.castAddHom (ZMod n)).liftOfRightInverse cast intCast_zmod_cast
variable (f : { f : ℤ →+ A // f n = 0 })
@[simp]
theorem lift_coe (x : ℤ) : lift n f (x : ZMod n) = f.val x :=
AddMonoidHom.liftOfRightInverse_comp_apply _ _ (fun _ => intCast_zmod_cast _) _ _
theorem lift_castAddHom (x : ℤ) : lift n f (Int.castAddHom (ZMod n) x) = f.1 x :=
AddMonoidHom.liftOfRightInverse_comp_apply _ _ (fun _ => intCast_zmod_cast _) _ _
@[simp]
theorem lift_comp_coe : ZMod.lift n f ∘ ((↑) : ℤ → _) = f :=
funext <| lift_coe _ _
@[simp]
theorem lift_comp_castAddHom : (ZMod.lift n f).comp (Int.castAddHom (ZMod n)) = f :=
AddMonoidHom.ext <| lift_castAddHom _ _
lemma lift_injective {f : {f : ℤ →+ A // f n = 0}} :
Injective (lift n f) ↔ ∀ m, f.1 m = 0 → (m : ZMod n) = 0 := by
simp only [← AddMonoidHom.ker_eq_bot_iff, eq_bot_iff, SetLike.le_def,
ZMod.intCast_surjective.forall, ZMod.lift_coe, AddMonoidHom.mem_ker, AddSubgroup.mem_bot]
end lift
end ZMod
/-!
### Groups of bounded torsion
For `G` a group and `n` a natural number, `G` having torsion dividing `n`
(`∀ x : G, n • x = 0`) can be derived from `Module R G` where `R` has characteristic dividing `n`.
It is however painful to have the API for such groups `G` stated in this generality, as `R` does not
appear anywhere in the lemmas' return type. Instead of writing the API in terms of a general `R`, we
therefore specialise to the canonical ring of order `n`, namely `ZMod n`.
This spelling `Module (ZMod n) G` has the extra advantage of providing the canonical action by
`ZMod n`. It is however Type-valued, so we might want to acquire a Prop-valued version in the
future.
-/
section Module
variable {n : ℕ} {S G : Type*} [AddCommGroup G] [SetLike S G] [AddSubgroupClass S G] {K : S} {x : G}
section general
variable [Module (ZMod n) G] {x : G}
lemma zmod_smul_mem (hx : x ∈ K) : ∀ a : ZMod n, a • x ∈ K := by
simpa [ZMod.forall, Int.cast_smul_eq_zsmul] using zsmul_mem hx
/-- This cannot be made an instance because of the `[Module (ZMod n) G]` argument and the fact that
`n` only appears in the second argument of `SMulMemClass`, which is an `OutParam`. -/
lemma smulMemClass : SMulMemClass S (ZMod n) G where smul_mem _ _ {_x} hx := zmod_smul_mem hx _
namespace AddSubgroupClass
instance instZModSMul : SMul (ZMod n) K where smul a x := ⟨a • x, zmod_smul_mem x.2 _⟩
@[simp, norm_cast] lemma coe_zmod_smul (a : ZMod n) (x : K) : ↑(a • x) = (a • x : G) := rfl
instance instZModModule : Module (ZMod n) K :=
Subtype.coe_injective.module _ (AddSubmonoidClass.subtype K) coe_zmod_smul
end AddSubgroupClass
variable (n)
lemma ZModModule.char_nsmul_eq_zero (x : G) : n • x = 0 := by
simp [← Nat.cast_smul_eq_nsmul (ZMod n)]
variable (G) in
lemma ZModModule.char_ne_one [Nontrivial G] : n ≠ 1 := by
rintro rfl
obtain ⟨x, hx⟩ := exists_ne (0 : G)
exact hx <| by simpa using char_nsmul_eq_zero 1 x
variable (G) in
lemma ZModModule.two_le_char [NeZero n] [Nontrivial G] : 2 ≤ n := by
have := NeZero.ne n
have := char_ne_one n G
omega
lemma ZModModule.periodicPts_add_left [NeZero n] (x : G) : periodicPts (x + ·) = .univ :=
Set.eq_univ_of_forall fun y ↦ ⟨n, NeZero.pos n, by
simpa [char_nsmul_eq_zero, IsPeriodicPt] using isFixedPt_id _⟩
end general
section two
variable [Module (ZMod 2) G]
lemma ZModModule.add_self (x : G) : x + x = 0 := by
simpa [two_nsmul] using char_nsmul_eq_zero 2 x
lemma ZModModule.neg_eq_self (x : G) : -x = x := by simp [add_self, eq_comm, ← sub_eq_zero]
lemma ZModModule.sub_eq_add (x y : G) : x - y = x + y := by simp [neg_eq_self, sub_eq_add_neg]
lemma ZModModule.add_add_add_cancel (x y z : G) : (x + y) + (y + z) = x + z := by
simpa [sub_eq_add] using sub_add_sub_cancel x y z
end two
end Module
section AddGroup
variable {α : Type*} [AddGroup α] {n : ℕ}
@[simp]
lemma nsmul_zmod_val_inv_nsmul (hn : (Nat.card α).Coprime n) (a : α) :
n • (n⁻¹ : ZMod (Nat.card α)).val • a = a := by
rw [← mul_nsmul', ← mod_natCard_nsmul, ← ZMod.val_natCast, Nat.cast_mul,
ZMod.mul_val_inv hn.symm, ZMod.val_one_eq_one_mod, mod_natCard_nsmul, one_nsmul]
@[simp]
lemma zmod_val_inv_nsmul_nsmul (hn : (Nat.card α).Coprime n) (a : α) :
(n⁻¹ : ZMod (Nat.card α)).val • n • a = a := by
rw [nsmul_left_comm, nsmul_zmod_val_inv_nsmul hn]
end AddGroup
section Group
variable {α : Type*} [Group α] {n : ℕ}
-- TODO: Without the `existing`, `to_additive` chokes on `Inv (ZMod n)`.
@[to_additive existing (attr := simp) nsmul_zmod_val_inv_nsmul]
lemma pow_zmod_val_inv_pow (hn : (Nat.card α).Coprime n) (a : α) :
(a ^ (n⁻¹ : ZMod (Nat.card α)).val) ^ n = a := by
rw [← pow_mul', ← pow_mod_natCard, ← ZMod.val_natCast, Nat.cast_mul, ZMod.mul_val_inv hn.symm,
ZMod.val_one_eq_one_mod, pow_mod_natCard, pow_one]
@[to_additive existing (attr := simp) zmod_val_inv_nsmul_nsmul]
lemma pow_pow_zmod_val_inv (hn : (Nat.card α).Coprime n) (a : α) :
(a ^ n) ^ (n⁻¹ : ZMod (Nat.card α)).val = a := by rw [pow_right_comm, pow_zmod_val_inv_pow hn]
end Group
open ZMod
/-- The range of `(m * · + k)` on natural numbers is the set of elements `≥ k` in the
residue class of `k` mod `m`. -/
lemma Nat.range_mul_add (m k : ℕ) :
| Set.range (fun n : ℕ ↦ m * n + k) = {n : ℕ | (n : ZMod m) = k ∧ k ≤ n} := by
ext n
simp only [Set.mem_range, Set.mem_setOf_eq]
conv => enter [1, 1, y]; rw [add_comm, eq_comm]
| Mathlib/Data/ZMod/Basic.lean | 1,263 | 1,266 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Finite.Defs
import Mathlib.Data.Finset.BooleanAlgebra
import Mathlib.Data.Finset.Image
import Mathlib.Data.Fintype.Defs
import Mathlib.Data.Fintype.OfMap
import Mathlib.Data.Fintype.Sets
import Mathlib.Data.List.FinRange
/-!
# Instances for finite types
This file is a collection of basic `Fintype` instances for types such as `Fin`, `Prod` and pi types.
-/
assert_not_exists Monoid
open Function
open Nat
universe u v
variable {α β γ : Type*}
open Finset
instance Fin.fintype (n : ℕ) : Fintype (Fin n) :=
⟨⟨List.finRange n, List.nodup_finRange n⟩, List.mem_finRange⟩
theorem Fin.univ_def (n : ℕ) : (univ : Finset (Fin n)) = ⟨List.finRange n, List.nodup_finRange n⟩ :=
rfl
theorem Finset.val_univ_fin (n : ℕ) : (Finset.univ : Finset (Fin n)).val = List.finRange n := rfl
/-- See also `nonempty_encodable`, `nonempty_denumerable`. -/
theorem nonempty_fintype (α : Type*) [Finite α] : Nonempty (Fintype α) := by
rcases Finite.exists_equiv_fin α with ⟨n, ⟨e⟩⟩
exact ⟨.ofEquiv _ e.symm⟩
@[simp] theorem List.toFinset_finRange (n : ℕ) : (List.finRange n).toFinset = Finset.univ := by
ext; simp
@[simp] theorem Fin.univ_val_map {n : ℕ} (f : Fin n → α) :
Finset.univ.val.map f = List.ofFn f := by
simp [List.ofFn_eq_map, univ_def]
theorem Fin.univ_image_def {n : ℕ} [DecidableEq α] (f : Fin n → α) :
Finset.univ.image f = (List.ofFn f).toFinset := by
simp [Finset.image]
theorem Fin.univ_map_def {n : ℕ} (f : Fin n ↪ α) :
Finset.univ.map f = ⟨List.ofFn f, List.nodup_ofFn.mpr f.injective⟩ := by
simp [Finset.map]
@[simp]
theorem Fin.image_succAbove_univ {n : ℕ} (i : Fin (n + 1)) : univ.image i.succAbove = {i}ᶜ := by
ext m
simp
@[simp]
theorem Fin.image_succ_univ (n : ℕ) : (univ : Finset (Fin n)).image Fin.succ = {0}ᶜ := by
rw [← Fin.succAbove_zero, Fin.image_succAbove_univ]
@[simp]
theorem Fin.image_castSucc (n : ℕ) :
(univ : Finset (Fin n)).image Fin.castSucc = {Fin.last n}ᶜ := by
rw [← Fin.succAbove_last, Fin.image_succAbove_univ]
/- The following three lemmas use `Finset.cons` instead of `insert` and `Finset.map` instead of
`Finset.image` to reduce proof obligations downstream. -/
/-- Embed `Fin n` into `Fin (n + 1)` by prepending zero to the `univ` -/
theorem Fin.univ_succ (n : ℕ) :
(univ : Finset (Fin (n + 1))) =
Finset.cons 0 (univ.map ⟨Fin.succ, Fin.succ_injective _⟩) (by simp [map_eq_image]) := by
simp [map_eq_image]
/-- Embed `Fin n` into `Fin (n + 1)` by appending a new `Fin.last n` to the `univ` -/
theorem Fin.univ_castSuccEmb (n : ℕ) :
(univ : Finset (Fin (n + 1))) =
Finset.cons (Fin.last n) (univ.map Fin.castSuccEmb) (by simp [map_eq_image]) := by
simp [map_eq_image]
/-- Embed `Fin n` into `Fin (n + 1)` by inserting
around a specified pivot `p : Fin (n + 1)` into the `univ` -/
theorem Fin.univ_succAbove (n : ℕ) (p : Fin (n + 1)) :
(univ : Finset (Fin (n + 1))) = Finset.cons p (univ.map <| Fin.succAboveEmb p) (by simp) := by
simp [map_eq_image]
@[simp] theorem Fin.univ_image_get [DecidableEq α] (l : List α) :
Finset.univ.image l.get = l.toFinset := by
simp [univ_image_def]
@[simp] theorem Fin.univ_image_getElem' [DecidableEq β] (l : List α) (f : α → β) :
Finset.univ.image (fun i : Fin l.length => f <| l[(i : Nat)]) = (l.map f).toFinset := by
simp only [univ_image_def, List.ofFn_getElem_eq_map]
theorem Fin.univ_image_get' [DecidableEq β] (l : List α) (f : α → β) :
Finset.univ.image (f <| l.get ·) = (l.map f).toFinset := by
simp
@[instance]
def Unique.fintype {α : Type*} [Unique α] : Fintype α :=
Fintype.ofSubsingleton default
/-- Short-circuit instance to decrease search for `Unique.fintype`,
since that relies on a subsingleton elimination for `Unique`. -/
instance Fintype.subtypeEq (y : α) : Fintype { x // x = y } :=
Fintype.subtype {y} (by simp)
/-- Short-circuit instance to decrease search for `Unique.fintype`,
since that relies on a subsingleton elimination for `Unique`. -/
instance Fintype.subtypeEq' (y : α) : Fintype { x // y = x } :=
Fintype.subtype {y} (by simp [eq_comm])
theorem Fintype.univ_empty : @univ Empty _ = ∅ :=
rfl
theorem Fintype.univ_pempty : @univ PEmpty _ = ∅ :=
rfl
instance Unit.fintype : Fintype Unit :=
Fintype.ofSubsingleton ()
theorem Fintype.univ_unit : @univ Unit _ = {()} :=
rfl
instance PUnit.fintype : Fintype PUnit :=
Fintype.ofSubsingleton PUnit.unit
theorem Fintype.univ_punit : @univ PUnit _ = {PUnit.unit} :=
rfl
@[simp]
theorem Fintype.univ_bool : @univ Bool _ = {true, false} :=
rfl
/-- Given that `α × β` is a fintype, `α` is also a fintype. -/
def Fintype.prodLeft {α β} [DecidableEq α] [Fintype (α × β)] [Nonempty β] : Fintype α :=
⟨(@univ (α × β) _).image Prod.fst, fun a => by simp⟩
/-- Given that `α × β` is a fintype, `β` is also a fintype. -/
def Fintype.prodRight {α β} [DecidableEq β] [Fintype (α × β)] [Nonempty α] : Fintype β :=
⟨(@univ (α × β) _).image Prod.snd, fun b => by simp⟩
instance ULift.fintype (α : Type*) [Fintype α] : Fintype (ULift α) :=
Fintype.ofEquiv _ Equiv.ulift.symm
instance PLift.fintype (α : Type*) [Fintype α] : Fintype (PLift α) :=
Fintype.ofEquiv _ Equiv.plift.symm
instance PLift.fintypeProp (p : Prop) [Decidable p] : Fintype (PLift p) :=
⟨if h : p then {⟨h⟩} else ∅, fun ⟨h⟩ => by simp [h]⟩
instance Quotient.fintype [Fintype α] (s : Setoid α) [DecidableRel ((· ≈ ·) : α → α → Prop)] :
Fintype (Quotient s) :=
Fintype.ofSurjective Quotient.mk'' Quotient.mk''_surjective
instance PSigma.fintypePropLeft {α : Prop} {β : α → Type*} [Decidable α] [∀ a, Fintype (β a)] :
Fintype (Σ'a, β a) :=
if h : α then Fintype.ofEquiv (β h) ⟨fun x => ⟨h, x⟩, PSigma.snd, fun _ => rfl, fun ⟨_, _⟩ => rfl⟩
else ⟨∅, fun x => (h x.1).elim⟩
instance PSigma.fintypePropRight {α : Type*} {β : α → Prop} [∀ a, Decidable (β a)] [Fintype α] :
Fintype (Σ'a, β a) :=
Fintype.ofEquiv { a // β a }
⟨fun ⟨x, y⟩ => ⟨x, y⟩, fun ⟨x, y⟩ => ⟨x, y⟩, fun ⟨_, _⟩ => rfl, fun ⟨_, _⟩ => rfl⟩
instance PSigma.fintypePropProp {α : Prop} {β : α → Prop} [Decidable α] [∀ a, Decidable (β a)] :
Fintype (Σ'a, β a) :=
if h : ∃ a, β a then ⟨{⟨h.fst, h.snd⟩}, fun ⟨_, _⟩ => by simp⟩ else ⟨∅, fun ⟨x, y⟩ =>
(h ⟨x, y⟩).elim⟩
instance pfunFintype (p : Prop) [Decidable p] (α : p → Type*) [∀ hp, Fintype (α hp)] :
Fintype (∀ hp : p, α hp) :=
if hp : p then Fintype.ofEquiv (α hp) ⟨fun a _ => a, fun f => f hp, fun _ => rfl, fun _ => rfl⟩
else ⟨singleton fun h => (hp h).elim, fun h => mem_singleton.2
(funext fun x => by contradiction)⟩
section Trunc
/-- For `s : Multiset α`, we can lift the existential statement that `∃ x, x ∈ s` to a `Trunc α`.
-/
def truncOfMultisetExistsMem {α} (s : Multiset α) : (∃ x, x ∈ s) → Trunc α :=
Quotient.recOnSubsingleton s fun l h =>
match l, h with
| [], _ => False.elim (by tauto)
| a :: _, _ => Trunc.mk a
/-- A `Nonempty` `Fintype` constructively contains an element.
-/
def truncOfNonemptyFintype (α) [Nonempty α] [Fintype α] : Trunc α :=
truncOfMultisetExistsMem Finset.univ.val (by simp)
/-- By iterating over the elements of a fintype, we can lift an existential statement `∃ a, P a`
to `Trunc (Σ' a, P a)`, containing data.
-/
def truncSigmaOfExists {α} [Fintype α] {P : α → Prop} [DecidablePred P] (h : ∃ a, P a) :
Trunc (Σ'a, P a) :=
@truncOfNonemptyFintype (Σ'a, P a) ((Exists.elim h) fun a ha => ⟨⟨a, ha⟩⟩) _
end Trunc
namespace Multiset
variable [Fintype α] [Fintype β]
@[simp]
theorem count_univ [DecidableEq α] (a : α) : count a Finset.univ.val = 1 :=
count_eq_one_of_mem Finset.univ.nodup (Finset.mem_univ _)
@[simp]
theorem map_univ_val_equiv (e : α ≃ β) :
map e univ.val = univ.val := by
rw [← congr_arg Finset.val (Finset.map_univ_equiv e), Finset.map_val, Equiv.coe_toEmbedding]
/-- For functions on finite sets, they are bijections iff they map universes into universes. -/
@[simp]
theorem bijective_iff_map_univ_eq_univ (f : α → β) :
f.Bijective ↔ map f (Finset.univ : Finset α).val = univ.val :=
⟨fun bij ↦ congr_arg (·.val) (map_univ_equiv <| Equiv.ofBijective f bij),
fun eq ↦ ⟨
fun a₁ a₂ ↦ inj_on_of_nodup_map (eq.symm ▸ univ.nodup) _ (mem_univ a₁) _ (mem_univ a₂),
fun b ↦ have ⟨a, _, h⟩ := mem_map.mp (eq.symm ▸ mem_univ_val b); ⟨a, h⟩⟩⟩
end Multiset
/-- Auxiliary definition to show `exists_seq_of_forall_finset_exists`. -/
noncomputable def seqOfForallFinsetExistsAux {α : Type*} [DecidableEq α] (P : α → Prop)
(r : α → α → Prop) (h : ∀ s : Finset α, ∃ y, (∀ x ∈ s, P x) → P y ∧ ∀ x ∈ s, r x y) : ℕ → α
| n =>
Classical.choose
(h
(Finset.image (fun i : Fin n => seqOfForallFinsetExistsAux P r h i)
(Finset.univ : Finset (Fin n))))
| /-- Induction principle to build a sequence, by adding one point at a time satisfying a given
relation with respect to all the previously chosen points.
| Mathlib/Data/Fintype/Basic.lean | 241 | 243 |
/-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Manuel Candales
-/
import Mathlib.Geometry.Euclidean.PerpBisector
import Mathlib.Algebra.QuadraticDiscriminant
/-!
# Euclidean spaces
This file makes some definitions and proves very basic geometrical
results about real inner product spaces and Euclidean affine spaces.
Results about real inner product spaces that involve the norm and
inner product but not angles generally go in
`Analysis.NormedSpace.InnerProduct`. Results with longer
proofs or more geometrical content generally go in separate files.
## Implementation notes
To declare `P` as the type of points in a Euclidean affine space with
`V` as the type of vectors, use
`[NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P]`.
This works better with `outParam` to make
`V` implicit in most cases than having a separate type alias for
Euclidean affine spaces.
Rather than requiring Euclidean affine spaces to be finite-dimensional
(as in the definition on Wikipedia), this is specified only for those
theorems that need it.
## References
* https://en.wikipedia.org/wiki/Euclidean_space
-/
noncomputable section
open RealInnerProductSpace
namespace EuclideanGeometry
/-!
### Geometrical results on Euclidean affine spaces
This section develops some geometrical definitions and results on
Euclidean affine spaces.
-/
variable {V : Type*} {P : Type*}
variable [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P]
variable [NormedAddTorsor V P]
/-- The inner product of two vectors given with `weightedVSub`, in
terms of the pairwise distances. -/
theorem inner_weightedVSub {ι₁ : Type*} {s₁ : Finset ι₁} {w₁ : ι₁ → ℝ} (p₁ : ι₁ → P)
(h₁ : ∑ i ∈ s₁, w₁ i = 0) {ι₂ : Type*} {s₂ : Finset ι₂} {w₂ : ι₂ → ℝ} (p₂ : ι₂ → P)
(h₂ : ∑ i ∈ s₂, w₂ i = 0) :
⟪s₁.weightedVSub p₁ w₁, s₂.weightedVSub p₂ w₂⟫ =
(-∑ i₁ ∈ s₁, ∑ i₂ ∈ s₂, w₁ i₁ * w₂ i₂ * (dist (p₁ i₁) (p₂ i₂) * dist (p₁ i₁) (p₂ i₂))) /
2 := by
rw [Finset.weightedVSub_apply, Finset.weightedVSub_apply,
inner_sum_smul_sum_smul_of_sum_eq_zero _ h₁ _ h₂]
simp_rw [vsub_sub_vsub_cancel_right]
rcongr (i₁ i₂) <;> rw [dist_eq_norm_vsub V (p₁ i₁) (p₂ i₂)]
/-- The distance between two points given with `affineCombination`,
in terms of the pairwise distances between the points in that
combination. -/
theorem dist_affineCombination {ι : Type*} {s : Finset ι} {w₁ w₂ : ι → ℝ} (p : ι → P)
(h₁ : ∑ i ∈ s, w₁ i = 1) (h₂ : ∑ i ∈ s, w₂ i = 1) : by
have a₁ := s.affineCombination ℝ p w₁
have a₂ := s.affineCombination ℝ p w₂
exact dist a₁ a₂ * dist a₁ a₂ = (-∑ i₁ ∈ s, ∑ i₂ ∈ s,
(w₁ - w₂) i₁ * (w₁ - w₂) i₂ * (dist (p i₁) (p i₂) * dist (p i₁) (p i₂))) / 2 := by
dsimp only
rw [dist_eq_norm_vsub V (s.affineCombination ℝ p w₁) (s.affineCombination ℝ p w₂), ←
@inner_self_eq_norm_mul_norm ℝ, Finset.affineCombination_vsub]
have h : (∑ i ∈ s, (w₁ - w₂) i) = 0 := by
simp_rw [Pi.sub_apply, Finset.sum_sub_distrib, h₁, h₂, sub_self]
exact inner_weightedVSub p h p h
-- Porting note: `inner_vsub_vsub_of_dist_eq_of_dist_eq` moved to `PerpendicularBisector`
/-- The squared distance between points on a line (expressed as a
multiple of a fixed vector added to a point) and another point,
expressed as a quadratic. -/
theorem dist_smul_vadd_sq (r : ℝ) (v : V) (p₁ p₂ : P) :
dist (r • v +ᵥ p₁) p₂ * dist (r • v +ᵥ p₁) p₂ =
⟪v, v⟫ * r * r + 2 * ⟪v, p₁ -ᵥ p₂⟫ * r + ⟪p₁ -ᵥ p₂, p₁ -ᵥ p₂⟫ := by
rw [dist_eq_norm_vsub V _ p₂, ← real_inner_self_eq_norm_mul_norm, vadd_vsub_assoc,
real_inner_add_add_self, real_inner_smul_left, real_inner_smul_left, real_inner_smul_right]
ring
/-- The condition for two points on a line to be equidistant from
another point. -/
theorem dist_smul_vadd_eq_dist {v : V} (p₁ p₂ : P) (hv : v ≠ 0) (r : ℝ) :
dist (r • v +ᵥ p₁) p₂ = dist p₁ p₂ ↔ r = 0 ∨ r = -2 * ⟪v, p₁ -ᵥ p₂⟫ / ⟪v, v⟫ := by
conv_lhs =>
rw [← mul_self_inj_of_nonneg dist_nonneg dist_nonneg, dist_smul_vadd_sq, mul_assoc,
← sub_eq_zero, add_sub_assoc, dist_eq_norm_vsub V p₁ p₂, ← real_inner_self_eq_norm_mul_norm,
sub_self]
have hvi : ⟪v, v⟫ ≠ 0 := by simpa using hv
have hd : discrim ⟪v, v⟫ (2 * ⟪v, p₁ -ᵥ p₂⟫) 0 = 2 * ⟪v, p₁ -ᵥ p₂⟫ * (2 * ⟪v, p₁ -ᵥ p₂⟫) := by
rw [discrim]
ring
rw [quadratic_eq_zero_iff hvi hd, neg_add_cancel, zero_div, neg_mul_eq_neg_mul, ←
mul_sub_right_distrib, sub_eq_add_neg, ← mul_two, mul_assoc, mul_div_assoc, mul_div_mul_left,
mul_div_assoc]
norm_num
open AffineSubspace Module
/-- Distances `r₁` `r₂` of `p` from two different points `c₁` `c₂` determine at
most two points `p₁` `p₂` in a two-dimensional subspace containing those points
(two circles intersect in at most two points). -/
theorem eq_of_dist_eq_of_dist_eq_of_mem_of_finrank_eq_two {s : AffineSubspace ℝ P}
[FiniteDimensional ℝ s.direction] (hd : finrank ℝ s.direction = 2) {c₁ c₂ p₁ p₂ p : P}
(hc₁s : c₁ ∈ s) (hc₂s : c₂ ∈ s) (hp₁s : p₁ ∈ s) (hp₂s : p₂ ∈ s) (hps : p ∈ s) {r₁ r₂ : ℝ}
(hc : c₁ ≠ c₂) (hp : p₁ ≠ p₂) (hp₁c₁ : dist p₁ c₁ = r₁) (hp₂c₁ : dist p₂ c₁ = r₁)
(hpc₁ : dist p c₁ = r₁) (hp₁c₂ : dist p₁ c₂ = r₂) (hp₂c₂ : dist p₂ c₂ = r₂)
(hpc₂ : dist p c₂ = r₂) : p = p₁ ∨ p = p₂ := by
have ho : ⟪c₂ -ᵥ c₁, p₂ -ᵥ p₁⟫ = 0 :=
inner_vsub_vsub_of_dist_eq_of_dist_eq (hp₁c₁.trans hp₂c₁.symm) (hp₁c₂.trans hp₂c₂.symm)
have hop : ⟪c₂ -ᵥ c₁, p -ᵥ p₁⟫ = 0 :=
inner_vsub_vsub_of_dist_eq_of_dist_eq (hp₁c₁.trans hpc₁.symm) (hp₁c₂.trans hpc₂.symm)
let b : Fin 2 → V := ![c₂ -ᵥ c₁, p₂ -ᵥ p₁]
have hb : LinearIndependent ℝ b := by
refine linearIndependent_of_ne_zero_of_inner_eq_zero ?_ ?_
· intro i
fin_cases i <;> simp [b, hc.symm, hp.symm]
· intro i j hij
fin_cases i <;> fin_cases j <;> try exact False.elim (hij rfl)
· exact ho
· rw [real_inner_comm]
exact ho
have hbs : Submodule.span ℝ (Set.range b) = s.direction := by
refine Submodule.eq_of_le_of_finrank_eq ?_ ?_
· rw [Submodule.span_le, Set.range_subset_iff]
intro i
fin_cases i
· exact vsub_mem_direction hc₂s hc₁s
· exact vsub_mem_direction hp₂s hp₁s
· rw [finrank_span_eq_card hb, Fintype.card_fin, hd]
have hv : ∀ v ∈ s.direction, ∃ t₁ t₂ : ℝ, v = t₁ • (c₂ -ᵥ c₁) + t₂ • (p₂ -ᵥ p₁) := by
intro v hv
have hr : Set.range b = {c₂ -ᵥ c₁, p₂ -ᵥ p₁} := by
have hu : (Finset.univ : Finset (Fin 2)) = {0, 1} := by decide
classical
rw [← Fintype.coe_image_univ, hu]
simp [b]
rw [← hbs, hr, Submodule.mem_span_insert] at hv
rcases hv with ⟨t₁, v', hv', hv⟩
rw [Submodule.mem_span_singleton] at hv'
rcases hv' with ⟨t₂, rfl⟩
exact ⟨t₁, t₂, hv⟩
rcases hv (p -ᵥ p₁) (vsub_mem_direction hps hp₁s) with ⟨t₁, t₂, hpt⟩
simp only [hpt, inner_add_right, inner_smul_right, ho, mul_zero, add_zero,
mul_eq_zero, inner_self_eq_zero, vsub_eq_zero_iff_eq, hc.symm, or_false] at hop
rw [hop, zero_smul, zero_add, ← eq_vadd_iff_vsub_eq] at hpt
subst hpt
have hp' : (p₂ -ᵥ p₁ : V) ≠ 0 := by simp [hp.symm]
have hp₂ : dist ((1 : ℝ) • (p₂ -ᵥ p₁) +ᵥ p₁) c₁ = r₁ := by simp [hp₂c₁]
rw [← hp₁c₁, dist_smul_vadd_eq_dist _ _ hp'] at hpc₁ hp₂
simp only [one_ne_zero, false_or] at hp₂
rw [hp₂.symm] at hpc₁
rcases hpc₁ with hpc₁ | hpc₁ <;> simp [hpc₁]
/-- Distances `r₁` `r₂` of `p` from two different points `c₁` `c₂` determine at
most two points `p₁` `p₂` in two-dimensional space (two circles intersect in at
most two points). -/
theorem eq_of_dist_eq_of_dist_eq_of_finrank_eq_two [FiniteDimensional ℝ V] (hd : finrank ℝ V = 2)
{c₁ c₂ p₁ p₂ p : P} {r₁ r₂ : ℝ} (hc : c₁ ≠ c₂) (hp : p₁ ≠ p₂) (hp₁c₁ : dist p₁ c₁ = r₁)
(hp₂c₁ : dist p₂ c₁ = r₁) (hpc₁ : dist p c₁ = r₁) (hp₁c₂ : dist p₁ c₂ = r₂)
(hp₂c₂ : dist p₂ c₂ = r₂) (hpc₂ : dist p c₂ = r₂) : p = p₁ ∨ p = p₂ :=
haveI hd' : finrank ℝ (⊤ : AffineSubspace ℝ P).direction = 2 := by
rw [direction_top, finrank_top]
exact hd
eq_of_dist_eq_of_dist_eq_of_mem_of_finrank_eq_two hd' (mem_top ℝ V _) (mem_top ℝ V _)
(mem_top ℝ V _) (mem_top ℝ V _) (mem_top ℝ V _) hc hp hp₁c₁ hp₂c₁ hpc₁ hp₁c₂ hp₂c₂ hpc₂
end EuclideanGeometry
| Mathlib/Geometry/Euclidean/Basic.lean | 604 | 607 | |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios
-/
import Mathlib.Algebra.GroupWithZero.Divisibility
import Mathlib.Data.Nat.SuccPred
import Mathlib.Order.SuccPred.InitialSeg
import Mathlib.SetTheory.Ordinal.Basic
/-!
# Ordinal arithmetic
Ordinals have an addition (corresponding to disjoint union) that turns them into an additive
monoid, and a multiplication (corresponding to the lexicographic order on the product) that turns
them into a monoid. One can also define correspondingly a subtraction, a division, a successor
function, a power function and a logarithm function.
We also define limit ordinals and prove the basic induction principle on ordinals separating
successor ordinals and limit ordinals, in `limitRecOn`.
## Main definitions and results
* `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that
every element of `o₁` is smaller than every element of `o₂`.
* `o₁ - o₂` is the unique ordinal `o` such that `o₂ + o = o₁`, when `o₂ ≤ o₁`.
* `o₁ * o₂` is the lexicographic order on `o₂ × o₁`.
* `o₁ / o₂` is the ordinal `o` such that `o₁ = o₂ * o + o'` with `o' < o₂`. We also define the
divisibility predicate, and a modulo operation.
* `Order.succ o = o + 1` is the successor of `o`.
* `pred o` if the predecessor of `o`. If `o` is not a successor, we set `pred o = o`.
We discuss the properties of casts of natural numbers of and of `ω` with respect to these
operations.
Some properties of the operations are also used to discuss general tools on ordinals:
* `IsLimit o`: an ordinal is a limit ordinal if it is neither `0` nor a successor.
* `limitRecOn` is the main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals.
* `IsNormal`: a function `f : Ordinal → Ordinal` satisfies `IsNormal` if it is strictly increasing
and order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`.
Various other basic arithmetic results are given in `Principal.lean` instead.
-/
assert_not_exists Field Module
noncomputable section
open Function Cardinal Set Equiv Order
open scoped Ordinal
universe u v w
namespace Ordinal
variable {α β γ : Type*} {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop}
/-! ### Further properties of addition on ordinals -/
@[simp]
theorem lift_add (a b : Ordinal.{v}) : lift.{u} (a + b) = lift.{u} a + lift.{u} b :=
Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ =>
Quotient.sound
⟨(RelIso.preimage Equiv.ulift _).trans
(RelIso.sumLexCongr (RelIso.preimage Equiv.ulift _) (RelIso.preimage Equiv.ulift _)).symm⟩
@[simp]
theorem lift_succ (a : Ordinal.{v}) : lift.{u} (succ a) = succ (lift.{u} a) := by
rw [← add_one_eq_succ, lift_add, lift_one]
rfl
instance instAddLeftReflectLE :
AddLeftReflectLE Ordinal.{u} where
elim c a b := by
refine inductionOn₃ a b c fun α r _ β s _ γ t _ ⟨f⟩ ↦ ?_
have H₁ a : f (Sum.inl a) = Sum.inl a := by
simpa using ((InitialSeg.leAdd t r).trans f).eq (InitialSeg.leAdd t s) a
have H₂ a : ∃ b, f (Sum.inr a) = Sum.inr b := by
generalize hx : f (Sum.inr a) = x
obtain x | x := x
· rw [← H₁, f.inj] at hx
contradiction
· exact ⟨x, rfl⟩
choose g hg using H₂
refine (RelEmbedding.ofMonotone g fun _ _ h ↦ ?_).ordinal_type_le
rwa [← @Sum.lex_inr_inr _ t _ s, ← hg, ← hg, f.map_rel_iff, Sum.lex_inr_inr]
instance : IsLeftCancelAdd Ordinal where
add_left_cancel a b c h := by simpa only [le_antisymm_iff, add_le_add_iff_left] using h
@[deprecated add_left_cancel_iff (since := "2024-12-11")]
protected theorem add_left_cancel (a) {b c : Ordinal} : a + b = a + c ↔ b = c :=
add_left_cancel_iff
private theorem add_lt_add_iff_left' (a) {b c : Ordinal} : a + b < a + c ↔ b < c := by
rw [← not_le, ← not_le, add_le_add_iff_left]
instance instAddLeftStrictMono : AddLeftStrictMono Ordinal.{u} :=
⟨fun a _b _c ↦ (add_lt_add_iff_left' a).2⟩
instance instAddLeftReflectLT : AddLeftReflectLT Ordinal.{u} :=
⟨fun a _b _c ↦ (add_lt_add_iff_left' a).1⟩
instance instAddRightReflectLT : AddRightReflectLT Ordinal.{u} :=
⟨fun _a _b _c ↦ lt_imp_lt_of_le_imp_le fun h => add_le_add_right h _⟩
theorem add_le_add_iff_right {a b : Ordinal} : ∀ n : ℕ, a + n ≤ b + n ↔ a ≤ b
| 0 => by simp
| n + 1 => by
simp only [natCast_succ, add_succ, add_succ, succ_le_succ_iff, add_le_add_iff_right]
theorem add_right_cancel {a b : Ordinal} (n : ℕ) : a + n = b + n ↔ a = b := by
simp only [le_antisymm_iff, add_le_add_iff_right]
theorem add_eq_zero_iff {a b : Ordinal} : a + b = 0 ↔ a = 0 ∧ b = 0 :=
inductionOn₂ a b fun α r _ β s _ => by
simp_rw [← type_sum_lex, type_eq_zero_iff_isEmpty]
exact isEmpty_sum
theorem left_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : a = 0 :=
(add_eq_zero_iff.1 h).1
theorem right_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : b = 0 :=
(add_eq_zero_iff.1 h).2
/-! ### The predecessor of an ordinal -/
open Classical in
/-- The ordinal predecessor of `o` is `o'` if `o = succ o'`,
and `o` otherwise. -/
def pred (o : Ordinal) : Ordinal :=
if h : ∃ a, o = succ a then Classical.choose h else o
@[simp]
theorem pred_succ (o) : pred (succ o) = o := by
have h : ∃ a, succ o = succ a := ⟨_, rfl⟩
simpa only [pred, dif_pos h] using (succ_injective <| Classical.choose_spec h).symm
theorem pred_le_self (o) : pred o ≤ o := by
classical
exact if h : ∃ a, o = succ a then by
let ⟨a, e⟩ := h
rw [e, pred_succ]; exact le_succ a
else by rw [pred, dif_neg h]
theorem pred_eq_iff_not_succ {o} : pred o = o ↔ ¬∃ a, o = succ a :=
⟨fun e ⟨a, e'⟩ => by rw [e', pred_succ] at e; exact (lt_succ a).ne e, fun h => dif_neg h⟩
theorem pred_eq_iff_not_succ' {o} : pred o = o ↔ ∀ a, o ≠ succ a := by
simpa using pred_eq_iff_not_succ
theorem pred_lt_iff_is_succ {o} : pred o < o ↔ ∃ a, o = succ a :=
Iff.trans (by simp only [le_antisymm_iff, pred_le_self, true_and, not_le])
(iff_not_comm.1 pred_eq_iff_not_succ).symm
@[simp]
theorem pred_zero : pred 0 = 0 :=
pred_eq_iff_not_succ'.2 fun a => (succ_ne_zero a).symm
theorem succ_pred_iff_is_succ {o} : succ (pred o) = o ↔ ∃ a, o = succ a :=
⟨fun e => ⟨_, e.symm⟩, fun ⟨a, e⟩ => by simp only [e, pred_succ]⟩
theorem succ_lt_of_not_succ {o b : Ordinal} (h : ¬∃ a, o = succ a) : succ b < o ↔ b < o :=
⟨(lt_succ b).trans, fun l => lt_of_le_of_ne (succ_le_of_lt l) fun e => h ⟨_, e.symm⟩⟩
theorem lt_pred {a b} : a < pred b ↔ succ a < b := by
classical
exact if h : ∃ a, b = succ a then by
let ⟨c, e⟩ := h
rw [e, pred_succ, succ_lt_succ_iff]
else by simp only [pred, dif_neg h, succ_lt_of_not_succ h]
theorem pred_le {a b} : pred a ≤ b ↔ a ≤ succ b :=
le_iff_le_iff_lt_iff_lt.2 lt_pred
@[simp]
theorem lift_is_succ {o : Ordinal.{v}} : (∃ a, lift.{u} o = succ a) ↔ ∃ a, o = succ a :=
⟨fun ⟨a, h⟩ =>
let ⟨b, e⟩ := mem_range_lift_of_le <| show a ≤ lift.{u} o from le_of_lt <| h.symm ▸ lt_succ a
⟨b, (lift_inj.{u,v}).1 <| by rw [h, ← e, lift_succ]⟩,
fun ⟨a, h⟩ => ⟨lift.{u} a, by simp only [h, lift_succ]⟩⟩
@[simp]
theorem lift_pred (o : Ordinal.{v}) : lift.{u} (pred o) = pred (lift.{u} o) := by
classical
exact if h : ∃ a, o = succ a then by obtain ⟨a, e⟩ := h; simp only [e, pred_succ, lift_succ]
else by rw [pred_eq_iff_not_succ.2 h, pred_eq_iff_not_succ.2 (mt lift_is_succ.1 h)]
/-! ### Limit ordinals -/
/-- A limit ordinal is an ordinal which is not zero and not a successor.
TODO: deprecate this in favor of `Order.IsSuccLimit`. -/
def IsLimit (o : Ordinal) : Prop :=
IsSuccLimit o
theorem isLimit_iff {o} : IsLimit o ↔ o ≠ 0 ∧ IsSuccPrelimit o := by
simp [IsLimit, IsSuccLimit]
theorem IsLimit.isSuccPrelimit {o} (h : IsLimit o) : IsSuccPrelimit o :=
IsSuccLimit.isSuccPrelimit h
theorem IsLimit.succ_lt {o a : Ordinal} (h : IsLimit o) : a < o → succ a < o :=
IsSuccLimit.succ_lt h
theorem isSuccPrelimit_zero : IsSuccPrelimit (0 : Ordinal) := isSuccPrelimit_bot
theorem not_zero_isLimit : ¬IsLimit 0 :=
not_isSuccLimit_bot
theorem not_succ_isLimit (o) : ¬IsLimit (succ o) :=
not_isSuccLimit_succ o
theorem not_succ_of_isLimit {o} (h : IsLimit o) : ¬∃ a, o = succ a
| ⟨a, e⟩ => not_succ_isLimit a (e ▸ h)
theorem succ_lt_of_isLimit {o a : Ordinal} (h : IsLimit o) : succ a < o ↔ a < o :=
IsSuccLimit.succ_lt_iff h
theorem le_succ_of_isLimit {o} (h : IsLimit o) {a} : o ≤ succ a ↔ o ≤ a :=
le_iff_le_iff_lt_iff_lt.2 <| succ_lt_of_isLimit h
theorem limit_le {o} (h : IsLimit o) {a} : o ≤ a ↔ ∀ x < o, x ≤ a :=
⟨fun h _x l => l.le.trans h, fun H =>
(le_succ_of_isLimit h).1 <| le_of_not_lt fun hn => not_lt_of_le (H _ hn) (lt_succ a)⟩
theorem lt_limit {o} (h : IsLimit o) {a} : a < o ↔ ∃ x < o, a < x := by
-- Porting note: `bex_def` is required.
simpa only [not_forall₂, not_le, bex_def] using not_congr (@limit_le _ h a)
@[simp]
theorem lift_isLimit (o : Ordinal.{v}) : IsLimit (lift.{u,v} o) ↔ IsLimit o :=
liftInitialSeg.isSuccLimit_apply_iff
theorem IsLimit.pos {o : Ordinal} (h : IsLimit o) : 0 < o :=
IsSuccLimit.bot_lt h
theorem IsLimit.ne_zero {o : Ordinal} (h : IsLimit o) : o ≠ 0 :=
h.pos.ne'
theorem IsLimit.one_lt {o : Ordinal} (h : IsLimit o) : 1 < o := by
simpa only [succ_zero] using h.succ_lt h.pos
theorem IsLimit.nat_lt {o : Ordinal} (h : IsLimit o) : ∀ n : ℕ, (n : Ordinal) < o
| 0 => h.pos
| n + 1 => h.succ_lt (IsLimit.nat_lt h n)
theorem zero_or_succ_or_limit (o : Ordinal) : o = 0 ∨ (∃ a, o = succ a) ∨ IsLimit o := by
simpa [eq_comm] using isMin_or_mem_range_succ_or_isSuccLimit o
theorem isLimit_of_not_succ_of_ne_zero {o : Ordinal} (h : ¬∃ a, o = succ a) (h' : o ≠ 0) :
IsLimit o := ((zero_or_succ_or_limit o).resolve_left h').resolve_left h
-- TODO: this is an iff with `IsSuccPrelimit`
theorem IsLimit.sSup_Iio {o : Ordinal} (h : IsLimit o) : sSup (Iio o) = o := by
apply (csSup_le' (fun a ha ↦ le_of_lt ha)).antisymm
apply le_of_forall_lt
intro a ha
exact (lt_succ a).trans_le (le_csSup bddAbove_Iio (h.succ_lt ha))
theorem IsLimit.iSup_Iio {o : Ordinal} (h : IsLimit o) : ⨆ a : Iio o, a.1 = o := by
rw [← sSup_eq_iSup', h.sSup_Iio]
/-- Main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals. -/
@[elab_as_elim]
def limitRecOn {motive : Ordinal → Sort*} (o : Ordinal)
(zero : motive 0) (succ : ∀ o, motive o → motive (succ o))
(isLimit : ∀ o, IsLimit o → (∀ o' < o, motive o') → motive o) : motive o := by
refine SuccOrder.limitRecOn o (fun a ha ↦ ?_) (fun a _ ↦ succ a) isLimit
convert zero
simpa using ha
@[simp]
theorem limitRecOn_zero {motive} (H₁ H₂ H₃) : @limitRecOn motive 0 H₁ H₂ H₃ = H₁ :=
SuccOrder.limitRecOn_isMin _ _ _ isMin_bot
@[simp]
theorem limitRecOn_succ {motive} (o H₁ H₂ H₃) :
@limitRecOn motive (succ o) H₁ H₂ H₃ = H₂ o (@limitRecOn motive o H₁ H₂ H₃) :=
SuccOrder.limitRecOn_succ ..
@[simp]
theorem limitRecOn_limit {motive} (o H₁ H₂ H₃ h) :
@limitRecOn motive o H₁ H₂ H₃ = H₃ o h fun x _h => @limitRecOn motive x H₁ H₂ H₃ :=
SuccOrder.limitRecOn_of_isSuccLimit ..
/-- Bounded recursion on ordinals. Similar to `limitRecOn`, with the assumption `o < l`
added to all cases. The final term's domain is the ordinals below `l`. -/
@[elab_as_elim]
def boundedLimitRecOn {l : Ordinal} (lLim : l.IsLimit) {motive : Iio l → Sort*} (o : Iio l)
(zero : motive ⟨0, lLim.pos⟩)
(succ : (o : Iio l) → motive o → motive ⟨succ o, lLim.succ_lt o.2⟩)
(isLimit : (o : Iio l) → IsLimit o → (Π o' < o, motive o') → motive o) : motive o :=
limitRecOn (motive := fun p ↦ (h : p < l) → motive ⟨p, h⟩) o.1 (fun _ ↦ zero)
(fun o ih h ↦ succ ⟨o, _⟩ <| ih <| (lt_succ o).trans h)
(fun _o ho ih _ ↦ isLimit _ ho fun _o' h ↦ ih _ h _) o.2
@[simp]
theorem boundedLimitRec_zero {l} (lLim : l.IsLimit) {motive} (H₁ H₂ H₃) :
@boundedLimitRecOn l lLim motive ⟨0, lLim.pos⟩ H₁ H₂ H₃ = H₁ := by
rw [boundedLimitRecOn, limitRecOn_zero]
@[simp]
theorem boundedLimitRec_succ {l} (lLim : l.IsLimit) {motive} (o H₁ H₂ H₃) :
@boundedLimitRecOn l lLim motive ⟨succ o.1, lLim.succ_lt o.2⟩ H₁ H₂ H₃ = H₂ o
(@boundedLimitRecOn l lLim motive o H₁ H₂ H₃) := by
rw [boundedLimitRecOn, limitRecOn_succ]
rfl
theorem boundedLimitRec_limit {l} (lLim : l.IsLimit) {motive} (o H₁ H₂ H₃ oLim) :
@boundedLimitRecOn l lLim motive o H₁ H₂ H₃ = H₃ o oLim (fun x _ ↦
@boundedLimitRecOn l lLim motive x H₁ H₂ H₃) := by
rw [boundedLimitRecOn, limitRecOn_limit]
rfl
instance orderTopToTypeSucc (o : Ordinal) : OrderTop (succ o).toType :=
@OrderTop.mk _ _ (Top.mk _) le_enum_succ
theorem enum_succ_eq_top {o : Ordinal} :
enum (α := (succ o).toType) (· < ·) ⟨o, type_toType _ ▸ lt_succ o⟩ = ⊤ :=
rfl
theorem has_succ_of_type_succ_lt {α} {r : α → α → Prop} [wo : IsWellOrder α r]
(h : ∀ a < type r, succ a < type r) (x : α) : ∃ y, r x y := by
use enum r ⟨succ (typein r x), h _ (typein_lt_type r x)⟩
convert enum_lt_enum.mpr _
· rw [enum_typein]
· rw [Subtype.mk_lt_mk, lt_succ_iff]
theorem toType_noMax_of_succ_lt {o : Ordinal} (ho : ∀ a < o, succ a < o) : NoMaxOrder o.toType :=
⟨has_succ_of_type_succ_lt (type_toType _ ▸ ho)⟩
theorem bounded_singleton {r : α → α → Prop} [IsWellOrder α r] (hr : (type r).IsLimit) (x) :
Bounded r {x} := by
refine ⟨enum r ⟨succ (typein r x), hr.succ_lt (typein_lt_type r x)⟩, ?_⟩
intro b hb
rw [mem_singleton_iff.1 hb]
nth_rw 1 [← enum_typein r x]
rw [@enum_lt_enum _ r, Subtype.mk_lt_mk]
apply lt_succ
@[simp]
theorem typein_ordinal (o : Ordinal.{u}) :
@typein Ordinal (· < ·) _ o = Ordinal.lift.{u + 1} o := by
refine Quotient.inductionOn o ?_
rintro ⟨α, r, wo⟩; apply Quotient.sound
constructor; refine ((RelIso.preimage Equiv.ulift r).trans (enum r).symm).symm
theorem mk_Iio_ordinal (o : Ordinal.{u}) :
#(Iio o) = Cardinal.lift.{u + 1} o.card := by
rw [lift_card, ← typein_ordinal]
rfl
/-! ### Normal ordinal functions -/
/-- A normal ordinal function is a strictly increasing function which is
order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`. -/
def IsNormal (f : Ordinal → Ordinal) : Prop :=
(∀ o, f o < f (succ o)) ∧ ∀ o, IsLimit o → ∀ a, f o ≤ a ↔ ∀ b < o, f b ≤ a
theorem IsNormal.limit_le {f} (H : IsNormal f) :
∀ {o}, IsLimit o → ∀ {a}, f o ≤ a ↔ ∀ b < o, f b ≤ a :=
@H.2
theorem IsNormal.limit_lt {f} (H : IsNormal f) {o} (h : IsLimit o) {a} :
a < f o ↔ ∃ b < o, a < f b :=
not_iff_not.1 <| by simpa only [exists_prop, not_exists, not_and, not_lt] using H.2 _ h a
theorem IsNormal.strictMono {f} (H : IsNormal f) : StrictMono f := fun a b =>
limitRecOn b (Not.elim (not_lt_of_le <| Ordinal.zero_le _))
(fun _b IH h =>
(lt_or_eq_of_le (le_of_lt_succ h)).elim (fun h => (IH h).trans (H.1 _)) fun e => e ▸ H.1 _)
fun _b l _IH h => lt_of_lt_of_le (H.1 a) ((H.2 _ l _).1 le_rfl _ (l.succ_lt h))
theorem IsNormal.monotone {f} (H : IsNormal f) : Monotone f :=
H.strictMono.monotone
theorem isNormal_iff_strictMono_limit (f : Ordinal → Ordinal) :
IsNormal f ↔ StrictMono f ∧ ∀ o, IsLimit o → ∀ a, (∀ b < o, f b ≤ a) → f o ≤ a :=
⟨fun hf => ⟨hf.strictMono, fun a ha c => (hf.2 a ha c).2⟩, fun ⟨hs, hl⟩ =>
⟨fun a => hs (lt_succ a), fun a ha c =>
⟨fun hac _b hba => ((hs hba).trans_le hac).le, hl a ha c⟩⟩⟩
theorem IsNormal.lt_iff {f} (H : IsNormal f) {a b} : f a < f b ↔ a < b :=
StrictMono.lt_iff_lt <| H.strictMono
theorem IsNormal.le_iff {f} (H : IsNormal f) {a b} : f a ≤ f b ↔ a ≤ b :=
le_iff_le_iff_lt_iff_lt.2 H.lt_iff
theorem IsNormal.inj {f} (H : IsNormal f) {a b} : f a = f b ↔ a = b := by
simp only [le_antisymm_iff, H.le_iff]
theorem IsNormal.id_le {f} (H : IsNormal f) : id ≤ f :=
H.strictMono.id_le
theorem IsNormal.le_apply {f} (H : IsNormal f) {a} : a ≤ f a :=
H.strictMono.le_apply
theorem IsNormal.le_iff_eq {f} (H : IsNormal f) {a} : f a ≤ a ↔ f a = a :=
H.le_apply.le_iff_eq
theorem IsNormal.le_set {f o} (H : IsNormal f) (p : Set Ordinal) (p0 : p.Nonempty) (b)
(H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f a ≤ o :=
⟨fun h _ pa => (H.le_iff.2 ((H₂ _).1 le_rfl _ pa)).trans h, fun h => by
induction b using limitRecOn with
| zero =>
obtain ⟨x, px⟩ := p0
have := Ordinal.le_zero.1 ((H₂ _).1 (Ordinal.zero_le _) _ px)
rw [this] at px
exact h _ px
| succ S _ =>
rcases not_forall₂.1 (mt (H₂ S).2 <| (lt_succ S).not_le) with ⟨a, h₁, h₂⟩
exact (H.le_iff.2 <| succ_le_of_lt <| not_le.1 h₂).trans (h _ h₁)
| isLimit S L _ =>
refine (H.2 _ L _).2 fun a h' => ?_
rcases not_forall₂.1 (mt (H₂ a).2 h'.not_le) with ⟨b, h₁, h₂⟩
exact (H.le_iff.2 <| (not_le.1 h₂).le).trans (h _ h₁)⟩
theorem IsNormal.le_set' {f o} (H : IsNormal f) (p : Set α) (p0 : p.Nonempty) (g : α → Ordinal) (b)
(H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, g a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f (g a) ≤ o := by
simpa [H₂] using H.le_set (g '' p) (p0.image g) b
theorem IsNormal.refl : IsNormal id :=
⟨lt_succ, fun _o l _a => Ordinal.limit_le l⟩
theorem IsNormal.trans {f g} (H₁ : IsNormal f) (H₂ : IsNormal g) : IsNormal (f ∘ g) :=
⟨fun _x => H₁.lt_iff.2 (H₂.1 _), fun o l _a =>
H₁.le_set' (· < o) ⟨0, l.pos⟩ g _ fun _c => H₂.2 _ l _⟩
theorem IsNormal.isLimit {f} (H : IsNormal f) {o} (ho : IsLimit o) : IsLimit (f o) := by
rw [isLimit_iff, isSuccPrelimit_iff_succ_lt]
use (H.lt_iff.2 ho.pos).ne_bot
intro a ha
obtain ⟨b, hb, hab⟩ := (H.limit_lt ho).1 ha
rw [← succ_le_iff] at hab
apply hab.trans_lt
rwa [H.lt_iff]
theorem add_le_of_limit {a b c : Ordinal} (h : IsLimit b) :
a + b ≤ c ↔ ∀ b' < b, a + b' ≤ c :=
⟨fun h _ l => (add_le_add_left l.le _).trans h, fun H =>
le_of_not_lt <| by
-- Porting note: `induction` tactics are required because of the parser bug.
induction a using inductionOn with
| H α r =>
induction b using inductionOn with
| H β s =>
intro l
suffices ∀ x : β, Sum.Lex r s (Sum.inr x) (enum _ ⟨_, l⟩) by
-- Porting note: `revert` & `intro` is required because `cases'` doesn't replace
-- `enum _ _ l` in `this`.
revert this; rcases enum _ ⟨_, l⟩ with x | x <;> intro this
· cases this (enum s ⟨0, h.pos⟩)
· exact irrefl _ (this _)
intro x
rw [← typein_lt_typein (Sum.Lex r s), typein_enum]
have := H _ (h.succ_lt (typein_lt_type s x))
rw [add_succ, succ_le_iff] at this
refine
(RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this
· rcases a with ⟨a | b, h⟩
· exact Sum.inl a
· exact Sum.inr ⟨b, by cases h; assumption⟩
· rcases a with ⟨a | a, h₁⟩ <;> rcases b with ⟨b | b, h₂⟩ <;> cases h₁ <;> cases h₂ <;>
rintro ⟨⟩ <;> constructor <;> assumption⟩
theorem isNormal_add_right (a : Ordinal) : IsNormal (a + ·) :=
⟨fun b => (add_lt_add_iff_left a).2 (lt_succ b), fun _b l _c => add_le_of_limit l⟩
theorem isLimit_add (a) {b} : IsLimit b → IsLimit (a + b) :=
(isNormal_add_right a).isLimit
alias IsLimit.add := isLimit_add
/-! ### Subtraction on ordinals -/
/-- The set in the definition of subtraction is nonempty. -/
private theorem sub_nonempty {a b : Ordinal} : { o | a ≤ b + o }.Nonempty :=
⟨a, le_add_left _ _⟩
/-- `a - b` is the unique ordinal satisfying `b + (a - b) = a` when `b ≤ a`. -/
instance sub : Sub Ordinal :=
⟨fun a b => sInf { o | a ≤ b + o }⟩
theorem le_add_sub (a b : Ordinal) : a ≤ b + (a - b) :=
csInf_mem sub_nonempty
theorem sub_le {a b c : Ordinal} : a - b ≤ c ↔ a ≤ b + c :=
⟨fun h => (le_add_sub a b).trans (add_le_add_left h _), fun h => csInf_le' h⟩
theorem lt_sub {a b c : Ordinal} : a < b - c ↔ c + a < b :=
lt_iff_lt_of_le_iff_le sub_le
theorem add_sub_cancel (a b : Ordinal) : a + b - a = b :=
le_antisymm (sub_le.2 <| le_rfl) ((add_le_add_iff_left a).1 <| le_add_sub _ _)
theorem sub_eq_of_add_eq {a b c : Ordinal} (h : a + b = c) : c - a = b :=
h ▸ add_sub_cancel _ _
theorem sub_le_self (a b : Ordinal) : a - b ≤ a :=
sub_le.2 <| le_add_left _ _
protected theorem add_sub_cancel_of_le {a b : Ordinal} (h : b ≤ a) : b + (a - b) = a :=
(le_add_sub a b).antisymm'
(by
rcases zero_or_succ_or_limit (a - b) with (e | ⟨c, e⟩ | l)
· simp only [e, add_zero, h]
· rw [e, add_succ, succ_le_iff, ← lt_sub, e]
exact lt_succ c
· exact (add_le_of_limit l).2 fun c l => (lt_sub.1 l).le)
theorem le_sub_of_le {a b c : Ordinal} (h : b ≤ a) : c ≤ a - b ↔ b + c ≤ a := by
rw [← add_le_add_iff_left b, Ordinal.add_sub_cancel_of_le h]
theorem sub_lt_of_le {a b c : Ordinal} (h : b ≤ a) : a - b < c ↔ a < b + c :=
lt_iff_lt_of_le_iff_le (le_sub_of_le h)
instance existsAddOfLE : ExistsAddOfLE Ordinal :=
⟨fun h => ⟨_, (Ordinal.add_sub_cancel_of_le h).symm⟩⟩
@[simp]
theorem sub_zero (a : Ordinal) : a - 0 = a := by simpa only [zero_add] using add_sub_cancel 0 a
@[simp]
theorem zero_sub (a : Ordinal) : 0 - a = 0 := by rw [← Ordinal.le_zero]; apply sub_le_self
@[simp]
theorem sub_self (a : Ordinal) : a - a = 0 := by simpa only [add_zero] using add_sub_cancel a 0
protected theorem sub_eq_zero_iff_le {a b : Ordinal} : a - b = 0 ↔ a ≤ b :=
⟨fun h => by simpa only [h, add_zero] using le_add_sub a b, fun h => by
rwa [← Ordinal.le_zero, sub_le, add_zero]⟩
protected theorem sub_ne_zero_iff_lt {a b : Ordinal} : a - b ≠ 0 ↔ b < a := by
simpa using Ordinal.sub_eq_zero_iff_le.not
theorem sub_sub (a b c : Ordinal) : a - b - c = a - (b + c) :=
eq_of_forall_ge_iff fun d => by rw [sub_le, sub_le, sub_le, add_assoc]
@[simp]
theorem add_sub_add_cancel (a b c : Ordinal) : a + b - (a + c) = b - c := by
rw [← sub_sub, add_sub_cancel]
theorem le_sub_of_add_le {a b c : Ordinal} (h : b + c ≤ a) : c ≤ a - b := by
rw [← add_le_add_iff_left b]
exact h.trans (le_add_sub a b)
theorem sub_lt_of_lt_add {a b c : Ordinal} (h : a < b + c) (hc : 0 < c) : a - b < c := by
obtain hab | hba := lt_or_le a b
· rwa [Ordinal.sub_eq_zero_iff_le.2 hab.le]
· rwa [sub_lt_of_le hba]
theorem lt_add_iff {a b c : Ordinal} (hc : c ≠ 0) : a < b + c ↔ ∃ d < c, a ≤ b + d := by
use fun h ↦ ⟨_, sub_lt_of_lt_add h hc.bot_lt, le_add_sub a b⟩
rintro ⟨d, hd, ha⟩
exact ha.trans_lt (add_lt_add_left hd b)
theorem add_le_iff {a b c : Ordinal} (hb : b ≠ 0) : a + b ≤ c ↔ ∀ d < b, a + d < c := by
simpa using (lt_add_iff hb).not
@[deprecated add_le_iff (since := "2024-12-08")]
theorem add_le_of_forall_add_lt {a b c : Ordinal} (hb : 0 < b) (h : ∀ d < b, a + d < c) :
a + b ≤ c :=
(add_le_iff hb.ne').2 h
theorem isLimit_sub {a b} (ha : IsLimit a) (h : b < a) : IsLimit (a - b) := by
rw [isLimit_iff, Ordinal.sub_ne_zero_iff_lt, isSuccPrelimit_iff_succ_lt]
refine ⟨h, fun c hc ↦ ?_⟩
rw [lt_sub] at hc ⊢
rw [add_succ]
exact ha.succ_lt hc
/-! ### Multiplication of ordinals -/
/-- The multiplication of ordinals `o₁` and `o₂` is the (well founded) lexicographic order on
`o₂ × o₁`. -/
instance monoid : Monoid Ordinal.{u} where
mul a b :=
Quotient.liftOn₂ a b
(fun ⟨α, r, _⟩ ⟨β, s, _⟩ => ⟦⟨β × α, Prod.Lex s r, inferInstance⟩⟧ :
WellOrder → WellOrder → Ordinal)
fun ⟨_, _, _⟩ _ _ _ ⟨f⟩ ⟨g⟩ => Quot.sound ⟨RelIso.prodLexCongr g f⟩
one := 1
| mul_assoc a b c :=
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ =>
Eq.symm <|
| Mathlib/SetTheory/Ordinal/Arithmetic.lean | 593 | 595 |
/-
Copyright (c) 2023 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Mathlib.Data.Nat.Choose.Basic
import Mathlib.Data.Sym.Sym2
/-! # Unordered tuples of elements of a list
Defines `List.sym` and the specialized `List.sym2` for computing lists of all unordered n-tuples
from a given list. These are list versions of `Nat.multichoose`.
## Main declarations
* `List.sym`: `xs.sym n` is a list of all unordered n-tuples of elements from `xs`,
with multiplicity. The list's values are in `Sym α n`.
* `List.sym2`: `xs.sym2` is a list of all unordered pairs of elements from `xs`,
with multiplicity. The list's values are in `Sym2 α`.
## TODO
* Prove `protected theorem Perm.sym (n : ℕ) {xs ys : List α} (h : xs ~ ys) : xs.sym n ~ ys.sym n`
and lift the result to `Multiset` and `Finset`.
-/
namespace List
variable {α β : Type*}
section Sym2
/-- `xs.sym2` is a list of all unordered pairs of elements from `xs`.
If `xs` has no duplicates then neither does `xs.sym2`. -/
protected def sym2 : List α → List (Sym2 α)
| [] => []
| x :: xs => (x :: xs).map (fun y => s(x, y)) ++ xs.sym2
theorem sym2_map (f : α → β) (xs : List α) :
(xs.map f).sym2 = xs.sym2.map (Sym2.map f) := by
induction xs with
| nil => simp [List.sym2]
| cons x xs ih => simp [List.sym2, ih, Function.comp]
theorem mem_sym2_cons_iff {x : α} {xs : List α} {z : Sym2 α} :
z ∈ (x :: xs).sym2 ↔ z = s(x, x) ∨ (∃ y, y ∈ xs ∧ z = s(x, y)) ∨ z ∈ xs.sym2 := by
simp only [List.sym2, map_cons, cons_append, mem_cons, mem_append, mem_map]
simp only [eq_comm]
@[simp]
theorem sym2_eq_nil_iff {xs : List α} : xs.sym2 = [] ↔ xs = [] := by
cases xs <;> simp [List.sym2]
theorem left_mem_of_mk_mem_sym2 {xs : List α} {a b : α}
(h : s(a, b) ∈ xs.sym2) : a ∈ xs := by
induction xs with
| nil => exact (not_mem_nil h).elim
| cons x xs ih =>
rw [mem_cons]
rw [mem_sym2_cons_iff] at h
obtain (h | ⟨c, hc, h⟩ | h) := h
· rw [Sym2.eq_iff, ← and_or_left] at h
exact .inl h.1
· rw [Sym2.eq_iff] at h
obtain (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩) := h <;> simp [hc]
· exact .inr <| ih h
|
theorem right_mem_of_mk_mem_sym2 {xs : List α} {a b : α}
(h : s(a, b) ∈ xs.sym2) : b ∈ xs := by
rw [Sym2.eq_swap] at h
exact left_mem_of_mk_mem_sym2 h
theorem mk_mem_sym2 {xs : List α} {a b : α} (ha : a ∈ xs) (hb : b ∈ xs) :
s(a, b) ∈ xs.sym2 := by
induction xs with
| nil => simp at ha
| cons x xs ih =>
rw [mem_sym2_cons_iff]
| Mathlib/Data/List/Sym.lean | 68 | 79 |
/-
Copyright (c) 2018 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Kim Morrison
-/
import Mathlib.CategoryTheory.Opposites
/-!
# Morphisms from equations between objects.
When working categorically, sometimes one encounters an equation `h : X = Y` between objects.
Your initial aversion to this is natural and appropriate:
you're in for some trouble, and if there is another way to approach the problem that won't
rely on this equality, it may be worth pursuing.
You have two options:
1. Use the equality `h` as one normally would in Lean (e.g. using `rw` and `subst`).
This may immediately cause difficulties, because in category theory everything is dependently
typed, and equations between objects quickly lead to nasty goals with `eq.rec`.
2. Promote `h` to a morphism using `eqToHom h : X ⟶ Y`, or `eqToIso h : X ≅ Y`.
This file introduces various `simp` lemmas which in favourable circumstances
result in the various `eqToHom` morphisms to drop out at the appropriate moment!
-/
universe v₁ v₂ v₃ u₁ u₂ u₃
-- morphism levels before object levels. See note [CategoryTheory universes].
namespace CategoryTheory
open Opposite
variable {C : Type u₁} [Category.{v₁} C]
/-- An equality `X = Y` gives us a morphism `X ⟶ Y`.
It is typically better to use this, rather than rewriting by the equality then using `𝟙 _`
which usually leads to dependent type theory hell.
-/
def eqToHom {X Y : C} (p : X = Y) : X ⟶ Y := by rw [p]; exact 𝟙 _
@[simp]
theorem eqToHom_refl (X : C) (p : X = X) : eqToHom p = 𝟙 X :=
rfl
@[reassoc (attr := simp)]
theorem eqToHom_trans {X Y Z : C} (p : X = Y) (q : Y = Z) :
eqToHom p ≫ eqToHom q = eqToHom (p.trans q) := by
cases p
cases q
simp
/-- `eqToHom h` is heterogeneously equal to the identity of its domain. -/
lemma eqToHom_heq_id_dom (X Y : C) (h : X = Y) : HEq (eqToHom h) (𝟙 X) := by
subst h; rfl
/-- `eqToHom h` is heterogeneously equal to the identity of its codomain. -/
lemma eqToHom_heq_id_cod (X Y : C) (h : X = Y) : HEq (eqToHom h) (𝟙 Y) := by
subst h; rfl
/-- Two morphisms are conjugate via eqToHom if and only if they are heterogeneously equal.
Note this used to be in the Functor namespace, where it doesn't belong. -/
theorem conj_eqToHom_iff_heq {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) (h : W = Y) (h' : X = Z) :
f = eqToHom h ≫ g ≫ eqToHom h'.symm ↔ HEq f g := by
cases h
cases h'
simp
theorem conj_eqToHom_iff_heq' {C} [Category C] {W X Y Z : C}
(f : W ⟶ X) (g : Y ⟶ Z) (h : W = Y) (h' : Z = X) :
f = eqToHom h ≫ g ≫ eqToHom h' ↔ HEq f g := conj_eqToHom_iff_heq _ _ _ h'.symm
theorem comp_eqToHom_iff {X Y Y' : C} (p : Y = Y') (f : X ⟶ Y) (g : X ⟶ Y') :
f ≫ eqToHom p = g ↔ f = g ≫ eqToHom p.symm :=
{ mp := fun h => h ▸ by simp
mpr := fun h => by simp [eq_whisker h (eqToHom p)] }
theorem eqToHom_comp_iff {X X' Y : C} (p : X = X') (f : X ⟶ Y) (g : X' ⟶ Y) :
eqToHom p ≫ g = f ↔ g = eqToHom p.symm ≫ f :=
{ mp := fun h => h ▸ by simp
mpr := fun h => h ▸ by simp [whisker_eq _ h] }
theorem eqToHom_comp_heq {C} [Category C] {W X Y : C}
(f : Y ⟶ X) (h : W = Y) : HEq (eqToHom h ≫ f) f := by
rw [← conj_eqToHom_iff_heq _ _ h rfl, eqToHom_refl, Category.comp_id]
@[simp] theorem eqToHom_comp_heq_iff {C} [Category C] {W X Y Z Z' : C}
(f : Y ⟶ X) (g : Z ⟶ Z') (h : W = Y) :
HEq (eqToHom h ≫ f) g ↔ HEq f g :=
⟨(eqToHom_comp_heq ..).symm.trans, (eqToHom_comp_heq ..).trans⟩
@[simp] theorem heq_eqToHom_comp_iff {C} [Category C] {W X Y Z Z' : C}
(f : Y ⟶ X) (g : Z ⟶ Z') (h : W = Y) :
HEq g (eqToHom h ≫ f) ↔ HEq g f :=
⟨(·.trans (eqToHom_comp_heq ..)), (·.trans (eqToHom_comp_heq ..).symm)⟩
theorem comp_eqToHom_heq {C} [Category C] {X Y Z : C}
(f : X ⟶ Y) (h : Y = Z) : HEq (f ≫ eqToHom h) f := by
rw [← conj_eqToHom_iff_heq' _ _ rfl h, eqToHom_refl, Category.id_comp]
@[simp] theorem comp_eqToHom_heq_iff {C} [Category C] {W X Y Z Z' : C}
(f : X ⟶ Y) (g : Z ⟶ Z') (h : Y = W) :
HEq (f ≫ eqToHom h) g ↔ HEq f g :=
⟨(comp_eqToHom_heq ..).symm.trans, (comp_eqToHom_heq ..).trans⟩
@[simp] theorem heq_comp_eqToHom_iff {C} [Category C] {W X Y Z Z' : C}
(f : X ⟶ Y) (g : Z ⟶ Z') (h : Y = W) :
HEq g (f ≫ eqToHom h) ↔ HEq g f :=
⟨(·.trans (comp_eqToHom_heq ..)), (·.trans (comp_eqToHom_heq ..).symm)⟩
theorem heq_comp {C} [Category C] {X Y Z X' Y' Z' : C}
{f : X ⟶ Y} {g : Y ⟶ Z} {f' : X' ⟶ Y'} {g' : Y' ⟶ Z'}
(eq1 : X = X') (eq2 : Y = Y') (eq3 : Z = Z')
(H1 : HEq f f') (H2 : HEq g g') :
HEq (f ≫ g) (f' ≫ g') := by
cases eq1; cases eq2; cases eq3; cases H1; cases H2; rfl
variable {β : Sort*}
/-- We can push `eqToHom` to the left through families of morphisms. -/
-- The simpNF linter incorrectly claims that this will never apply.
-- It seems the side condition `w` is not applied by `simpNF`.
-- https://github.com/leanprover-community/mathlib4/issues/5049
@[reassoc (attr := simp, nolint simpNF)]
theorem eqToHom_naturality {f g : β → C} (z : ∀ b, f b ⟶ g b) {j j' : β} (w : j = j') :
z j ≫ eqToHom (by simp [w]) = eqToHom (by simp [w]) ≫ z j' := by
cases w
simp
/-- A variant on `eqToHom_naturality` that helps Lean identify the families `f` and `g`. -/
-- The simpNF linter incorrectly claims that this will never apply.
-- It seems the side condition `w` is not applied by `simpNF`.
-- https://github.com/leanprover-community/mathlib4/issues/5049
@[reassoc (attr := simp, nolint simpNF)]
theorem eqToHom_iso_hom_naturality {f g : β → C} (z : ∀ b, f b ≅ g b) {j j' : β} (w : j = j') :
(z j).hom ≫ eqToHom (by simp [w]) = eqToHom (by simp [w]) ≫ (z j').hom := by
cases w
simp
/-- A variant on `eqToHom_naturality` that helps Lean identify the families `f` and `g`. -/
-- The simpNF linter incorrectly claims that this will never apply.
-- It seems the side condition `w` is not applied by `simpNF`.
-- https://github.com/leanprover-community/mathlib4/issues/5049
@[reassoc (attr := simp, nolint simpNF)]
theorem eqToHom_iso_inv_naturality {f g : β → C} (z : ∀ b, f b ≅ g b) {j j' : β} (w : j = j') :
(z j).inv ≫ eqToHom (by simp [w]) = eqToHom (by simp [w]) ≫ (z j').inv := by
cases w
simp
/-- Reducible form of congrArg_mpr_hom_left -/
@[simp]
theorem congrArg_cast_hom_left {X Y Z : C} (p : X = Y) (q : Y ⟶ Z) :
cast (congrArg (fun W : C => W ⟶ Z) p.symm) q = eqToHom p ≫ q := by
cases p
simp
/-- If we (perhaps unintentionally) perform equational rewriting on
the source object of a morphism,
we can replace the resulting `_.mpr f` term by a composition with an `eqToHom`.
It may be advisable to introduce any necessary `eqToHom` morphisms manually,
rather than relying on this lemma firing.
-/
theorem congrArg_mpr_hom_left {X Y Z : C} (p : X = Y) (q : Y ⟶ Z) :
(congrArg (fun W : C => W ⟶ Z) p).mpr q = eqToHom p ≫ q := by
cases p
simp
/-- Reducible form of `congrArg_mpr_hom_right` -/
@[simp]
theorem congrArg_cast_hom_right {X Y Z : C} (p : X ⟶ Y) (q : Z = Y) :
cast (congrArg (fun W : C => X ⟶ W) q.symm) p = p ≫ eqToHom q.symm := by
cases q
simp
/-- If we (perhaps unintentionally) perform equational rewriting on
the target object of a morphism,
we can replace the resulting `_.mpr f` term by a composition with an `eqToHom`.
It may be advisable to introduce any necessary `eqToHom` morphisms manually,
rather than relying on this lemma firing.
-/
theorem congrArg_mpr_hom_right {X Y Z : C} (p : X ⟶ Y) (q : Z = Y) :
(congrArg (fun W : C => X ⟶ W) q).mpr p = p ≫ eqToHom q.symm := by
cases q
simp
/-- An equality `X = Y` gives us an isomorphism `X ≅ Y`.
It is typically better to use this, rather than rewriting by the equality then using `Iso.refl _`
which usually leads to dependent type theory hell.
-/
def eqToIso {X Y : C} (p : X = Y) : X ≅ Y :=
⟨eqToHom p, eqToHom p.symm, by simp, by simp⟩
@[simp]
theorem eqToIso.hom {X Y : C} (p : X = Y) : (eqToIso p).hom = eqToHom p :=
rfl
|
@[simp]
theorem eqToIso.inv {X Y : C} (p : X = Y) : (eqToIso p).inv = eqToHom p.symm :=
rfl
@[simp]
theorem eqToIso_refl {X : C} (p : X = X) : eqToIso p = Iso.refl X :=
rfl
@[simp]
theorem eqToIso_trans {X Y Z : C} (p : X = Y) (q : Y = Z) :
eqToIso p ≪≫ eqToIso q = eqToIso (p.trans q) := by ext; simp
@[simp]
| Mathlib/CategoryTheory/EqToHom.lean | 200 | 213 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Group.Action.Pi
import Mathlib.Algebra.Order.AbsoluteValue.Basic
import Mathlib.Algebra.Order.Field.Basic
import Mathlib.Algebra.Order.Group.MinMax
import Mathlib.Algebra.Ring.Pi
import Mathlib.Data.Setoid.Basic
import Mathlib.GroupTheory.GroupAction.Ring
import Mathlib.Tactic.GCongr
/-!
# Cauchy sequences
A basic theory of Cauchy sequences, used in the construction of the reals and p-adic numbers. Where
applicable, lemmas that will be reused in other contexts have been stated in extra generality.
There are other "versions" of Cauchyness in the library, in particular Cauchy filters in topology.
This is a concrete implementation that is useful for simplicity and computability reasons.
## Important definitions
* `IsCauSeq`: a predicate that says `f : ℕ → β` is Cauchy.
* `CauSeq`: the type of Cauchy sequences valued in type `β` with respect to an absolute value
function `abv`.
## Tags
sequence, cauchy, abs val, absolute value
-/
assert_not_exists Finset Module Submonoid FloorRing Module
variable {α β : Type*}
open IsAbsoluteValue
section
variable [Field α] [LinearOrder α] [IsStrictOrderedRing α] [Ring β]
(abv : β → α) [IsAbsoluteValue abv]
theorem rat_add_continuous_lemma {ε : α} (ε0 : 0 < ε) :
∃ δ > 0, ∀ {a₁ a₂ b₁ b₂ : β}, abv (a₁ - b₁) < δ → abv (a₂ - b₂) < δ →
abv (a₁ + a₂ - (b₁ + b₂)) < ε :=
⟨ε / 2, half_pos ε0, fun {a₁ a₂ b₁ b₂} h₁ h₂ => by
simpa [add_halves, sub_eq_add_neg, add_comm, add_left_comm, add_assoc] using
lt_of_le_of_lt (abv_add abv _ _) (add_lt_add h₁ h₂)⟩
theorem rat_mul_continuous_lemma {ε K₁ K₂ : α} (ε0 : 0 < ε) :
∃ δ > 0, ∀ {a₁ a₂ b₁ b₂ : β}, abv a₁ < K₁ → abv b₂ < K₂ → abv (a₁ - b₁) < δ →
abv (a₂ - b₂) < δ → abv (a₁ * a₂ - b₁ * b₂) < ε := by
have K0 : (0 : α) < max 1 (max K₁ K₂) := lt_of_lt_of_le zero_lt_one (le_max_left _ _)
have εK := div_pos (half_pos ε0) K0
refine ⟨_, εK, fun {a₁ a₂ b₁ b₂} ha₁ hb₂ h₁ h₂ => ?_⟩
replace ha₁ := lt_of_lt_of_le ha₁ (le_trans (le_max_left _ K₂) (le_max_right 1 _))
replace hb₂ := lt_of_lt_of_le hb₂ (le_trans (le_max_right K₁ _) (le_max_right 1 _))
set M := max 1 (max K₁ K₂)
have : abv (a₁ - b₁) * abv b₂ + abv (a₂ - b₂) * abv a₁ < ε / 2 / M * M + ε / 2 / M * M := by
gcongr
rw [← abv_mul abv, mul_comm, div_mul_cancel₀ _ (ne_of_gt K0), ← abv_mul abv, add_halves] at this
simpa [sub_eq_add_neg, mul_add, add_mul, add_left_comm] using
lt_of_le_of_lt (abv_add abv _ _) this
theorem rat_inv_continuous_lemma {β : Type*} [DivisionRing β] (abv : β → α) [IsAbsoluteValue abv]
{ε K : α} (ε0 : 0 < ε) (K0 : 0 < K) :
∃ δ > 0, ∀ {a b : β}, K ≤ abv a → K ≤ abv b → abv (a - b) < δ → abv (a⁻¹ - b⁻¹) < ε := by
refine ⟨K * ε * K, mul_pos (mul_pos K0 ε0) K0, fun {a b} ha hb h => ?_⟩
have a0 := K0.trans_le ha
have b0 := K0.trans_le hb
rw [inv_sub_inv' ((abv_pos abv).1 a0) ((abv_pos abv).1 b0), abv_mul abv, abv_mul abv, abv_inv abv,
abv_inv abv, abv_sub abv]
refine lt_of_mul_lt_mul_left (lt_of_mul_lt_mul_right ?_ b0.le) a0.le
rw [mul_assoc, inv_mul_cancel_right₀ b0.ne', ← mul_assoc, mul_inv_cancel₀ a0.ne', one_mul]
refine h.trans_le ?_
gcongr
end
/-- A sequence is Cauchy if the distance between its entries tends to zero. -/
@[nolint unusedArguments]
def IsCauSeq {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
{β : Type*} [Ring β] (abv : β → α) (f : ℕ → β) :
Prop :=
∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j - f i) < ε
namespace IsCauSeq
variable [Field α] [LinearOrder α] [IsStrictOrderedRing α] [Ring β]
{abv : β → α} [IsAbsoluteValue abv] {f g : ℕ → β}
-- see Note [nolint_ge]
--@[nolint ge_or_gt] -- Porting note: restore attribute
theorem cauchy₂ (hf : IsCauSeq abv f) {ε : α} (ε0 : 0 < ε) :
∃ i, ∀ j ≥ i, ∀ k ≥ i, abv (f j - f k) < ε := by
refine (hf _ (half_pos ε0)).imp fun i hi j ij k ik => ?_
rw [← add_halves ε]
refine lt_of_le_of_lt (abv_sub_le abv _ _ _) (add_lt_add (hi _ ij) ?_)
rw [abv_sub abv]; exact hi _ ik
theorem cauchy₃ (hf : IsCauSeq abv f) {ε : α} (ε0 : 0 < ε) :
∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - f j) < ε :=
let ⟨i, H⟩ := hf.cauchy₂ ε0
⟨i, fun _ ij _ jk => H _ (le_trans ij jk) _ ij⟩
lemma bounded (hf : IsCauSeq abv f) : ∃ r, ∀ i, abv (f i) < r := by
obtain ⟨i, h⟩ := hf _ zero_lt_one
set R : ℕ → α := @Nat.rec (fun _ => α) (abv (f 0)) fun i c => max c (abv (f i.succ)) with hR
have : ∀ i, ∀ j ≤ i, abv (f j) ≤ R i := by
refine Nat.rec (by simp [hR]) ?_
rintro i hi j (rfl | hj)
· simp [R]
· exact (hi j hj).trans (le_max_left _ _)
refine ⟨R i + 1, fun j ↦ ?_⟩
obtain hji | hij := le_total j i
· exact (this i _ hji).trans_lt (lt_add_one _)
· simpa using (abv_add abv _ _).trans_lt <| add_lt_add_of_le_of_lt (this i _ le_rfl) (h _ hij)
lemma bounded' (hf : IsCauSeq abv f) (x : α) : ∃ r > x, ∀ i, abv (f i) < r :=
let ⟨r, h⟩ := hf.bounded
⟨max r (x + 1), (lt_add_one x).trans_le (le_max_right _ _),
fun i ↦ (h i).trans_le (le_max_left _ _)⟩
lemma const (x : β) : IsCauSeq abv fun _ ↦ x :=
fun ε ε0 ↦ ⟨0, fun j _ => by simpa [abv_zero] using ε0⟩
theorem add (hf : IsCauSeq abv f) (hg : IsCauSeq abv g) : IsCauSeq abv (f + g) := fun _ ε0 =>
let ⟨_, δ0, Hδ⟩ := rat_add_continuous_lemma abv ε0
let ⟨i, H⟩ := exists_forall_ge_and (hf.cauchy₃ δ0) (hg.cauchy₃ δ0)
⟨i, fun _ ij =>
let ⟨H₁, H₂⟩ := H _ le_rfl
Hδ (H₁ _ ij) (H₂ _ ij)⟩
lemma mul (hf : IsCauSeq abv f) (hg : IsCauSeq abv g) : IsCauSeq abv (f * g) := fun _ ε0 =>
let ⟨_, _, hF⟩ := hf.bounded' 0
let ⟨_, _, hG⟩ := hg.bounded' 0
let ⟨_, δ0, Hδ⟩ := rat_mul_continuous_lemma abv ε0
let ⟨i, H⟩ := exists_forall_ge_and (hf.cauchy₃ δ0) (hg.cauchy₃ δ0)
⟨i, fun j ij =>
let ⟨H₁, H₂⟩ := H _ le_rfl
Hδ (hF j) (hG i) (H₁ _ ij) (H₂ _ ij)⟩
@[simp] lemma _root_.isCauSeq_neg : IsCauSeq abv (-f) ↔ IsCauSeq abv f := by
simp only [IsCauSeq, Pi.neg_apply, ← neg_sub', abv_neg]
protected alias ⟨of_neg, neg⟩ := isCauSeq_neg
end IsCauSeq
/-- `CauSeq β abv` is the type of `β`-valued Cauchy sequences, with respect to the absolute value
function `abv`. -/
def CauSeq {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
(β : Type*) [Ring β] (abv : β → α) : Type _ :=
{ f : ℕ → β // IsCauSeq abv f }
namespace CauSeq
variable [Field α] [LinearOrder α] [IsStrictOrderedRing α]
section Ring
variable [Ring β] {abv : β → α}
instance : CoeFun (CauSeq β abv) fun _ => ℕ → β :=
⟨Subtype.val⟩
@[ext]
theorem ext {f g : CauSeq β abv} (h : ∀ i, f i = g i) : f = g := Subtype.eq (funext h)
theorem isCauSeq (f : CauSeq β abv) : IsCauSeq abv f :=
f.2
theorem cauchy (f : CauSeq β abv) : ∀ {ε}, 0 < ε → ∃ i, ∀ j ≥ i, abv (f j - f i) < ε := @f.2
/-- Given a Cauchy sequence `f`, create a Cauchy sequence from a sequence `g` with
the same values as `f`. -/
def ofEq (f : CauSeq β abv) (g : ℕ → β) (e : ∀ i, f i = g i) : CauSeq β abv :=
⟨g, fun ε => by rw [show g = f from (funext e).symm]; exact f.cauchy⟩
variable [IsAbsoluteValue abv]
-- see Note [nolint_ge]
-- @[nolint ge_or_gt] -- Porting note: restore attribute
theorem cauchy₂ (f : CauSeq β abv) {ε} :
0 < ε → ∃ i, ∀ j ≥ i, ∀ k ≥ i, abv (f j - f k) < ε :=
f.2.cauchy₂
theorem cauchy₃ (f : CauSeq β abv) {ε} : 0 < ε → ∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - f j) < ε :=
f.2.cauchy₃
theorem bounded (f : CauSeq β abv) : ∃ r, ∀ i, abv (f i) < r := f.2.bounded
theorem bounded' (f : CauSeq β abv) (x : α) : ∃ r > x, ∀ i, abv (f i) < r := f.2.bounded' x
instance : Add (CauSeq β abv) :=
⟨fun f g => ⟨f + g, f.2.add g.2⟩⟩
@[simp, norm_cast]
theorem coe_add (f g : CauSeq β abv) : ⇑(f + g) = (f : ℕ → β) + g :=
rfl
@[simp, norm_cast]
theorem add_apply (f g : CauSeq β abv) (i : ℕ) : (f + g) i = f i + g i :=
rfl
variable (abv) in
/-- The constant Cauchy sequence. -/
def const (x : β) : CauSeq β abv := ⟨fun _ ↦ x, IsCauSeq.const _⟩
/-- The constant Cauchy sequence -/
local notation "const" => const abv
@[simp, norm_cast]
theorem coe_const (x : β) : (const x : ℕ → β) = Function.const ℕ x :=
rfl
@[simp, norm_cast]
theorem const_apply (x : β) (i : ℕ) : (const x : ℕ → β) i = x :=
rfl
theorem const_inj {x y : β} : (const x : CauSeq β abv) = const y ↔ x = y :=
⟨fun h => congr_arg (fun f : CauSeq β abv => (f : ℕ → β) 0) h, congr_arg _⟩
instance : Zero (CauSeq β abv) :=
⟨const 0⟩
instance : One (CauSeq β abv) :=
⟨const 1⟩
instance : Inhabited (CauSeq β abv) :=
⟨0⟩
@[simp, norm_cast]
theorem coe_zero : ⇑(0 : CauSeq β abv) = 0 :=
rfl
@[simp, norm_cast]
theorem coe_one : ⇑(1 : CauSeq β abv) = 1 :=
rfl
@[simp, norm_cast]
theorem zero_apply (i) : (0 : CauSeq β abv) i = 0 :=
rfl
@[simp, norm_cast]
theorem one_apply (i) : (1 : CauSeq β abv) i = 1 :=
rfl
@[simp]
theorem const_zero : const 0 = 0 :=
rfl
@[simp]
theorem const_one : const 1 = 1 :=
rfl
theorem const_add (x y : β) : const (x + y) = const x + const y :=
rfl
instance : Mul (CauSeq β abv) := ⟨fun f g ↦ ⟨f * g, f.2.mul g.2⟩⟩
@[simp, norm_cast]
theorem coe_mul (f g : CauSeq β abv) : ⇑(f * g) = (f : ℕ → β) * g :=
rfl
@[simp, norm_cast]
theorem mul_apply (f g : CauSeq β abv) (i : ℕ) : (f * g) i = f i * g i :=
rfl
theorem const_mul (x y : β) : const (x * y) = const x * const y :=
rfl
instance : Neg (CauSeq β abv) := ⟨fun f ↦ ⟨-f, f.2.neg⟩⟩
@[simp, norm_cast]
theorem coe_neg (f : CauSeq β abv) : ⇑(-f) = -f :=
rfl
@[simp, norm_cast]
theorem neg_apply (f : CauSeq β abv) (i) : (-f) i = -f i :=
rfl
theorem const_neg (x : β) : const (-x) = -const x :=
rfl
instance : Sub (CauSeq β abv) :=
⟨fun f g => ofEq (f + -g) (fun x => f x - g x) fun i => by simp [sub_eq_add_neg]⟩
@[simp, norm_cast]
theorem coe_sub (f g : CauSeq β abv) : ⇑(f - g) = (f : ℕ → β) - g :=
rfl
@[simp, norm_cast]
theorem sub_apply (f g : CauSeq β abv) (i : ℕ) : (f - g) i = f i - g i :=
rfl
theorem const_sub (x y : β) : const (x - y) = const x - const y :=
rfl
section SMul
variable {G : Type*} [SMul G β] [IsScalarTower G β β]
instance : SMul G (CauSeq β abv) :=
⟨fun a f => (ofEq (const (a • (1 : β)) * f) (a • (f : ℕ → β))) fun _ => smul_one_mul _ _⟩
@[simp, norm_cast]
theorem coe_smul (a : G) (f : CauSeq β abv) : ⇑(a • f) = a • (f : ℕ → β) :=
rfl
@[simp, norm_cast]
theorem smul_apply (a : G) (f : CauSeq β abv) (i : ℕ) : (a • f) i = a • f i :=
rfl
theorem const_smul (a : G) (x : β) : const (a • x) = a • const x :=
rfl
instance : IsScalarTower G (CauSeq β abv) (CauSeq β abv) :=
⟨fun a f g => Subtype.ext <| smul_assoc a (f : ℕ → β) (g : ℕ → β)⟩
end SMul
instance addGroup : AddGroup (CauSeq β abv) :=
Function.Injective.addGroup Subtype.val Subtype.val_injective rfl coe_add coe_neg coe_sub
(fun _ _ => coe_smul _ _) fun _ _ => coe_smul _ _
instance instNatCast : NatCast (CauSeq β abv) := ⟨fun n => const n⟩
instance instIntCast : IntCast (CauSeq β abv) := ⟨fun n => const n⟩
instance addGroupWithOne : AddGroupWithOne (CauSeq β abv) :=
Function.Injective.addGroupWithOne Subtype.val Subtype.val_injective rfl rfl
coe_add coe_neg coe_sub
(by intros; rfl)
(by intros; rfl)
(by intros; rfl)
(by intros; rfl)
instance : Pow (CauSeq β abv) ℕ :=
⟨fun f n =>
(ofEq (npowRec n f) fun i => f i ^ n) <| by induction n <;> simp [*, npowRec, pow_succ]⟩
@[simp, norm_cast]
theorem coe_pow (f : CauSeq β abv) (n : ℕ) : ⇑(f ^ n) = (f : ℕ → β) ^ n :=
rfl
@[simp, norm_cast]
theorem pow_apply (f : CauSeq β abv) (n i : ℕ) : (f ^ n) i = f i ^ n :=
rfl
theorem const_pow (x : β) (n : ℕ) : const (x ^ n) = const x ^ n :=
rfl
instance ring : Ring (CauSeq β abv) :=
Function.Injective.ring Subtype.val Subtype.val_injective rfl rfl coe_add coe_mul coe_neg coe_sub
(fun _ _ => coe_smul _ _) (fun _ _ => coe_smul _ _) coe_pow (fun _ => rfl) fun _ => rfl
instance {β : Type*} [CommRing β] {abv : β → α} [IsAbsoluteValue abv] : CommRing (CauSeq β abv) :=
{ CauSeq.ring with
mul_comm := fun a b => ext fun n => by simp [mul_left_comm, mul_comm] }
/-- `LimZero f` holds when `f` approaches 0. -/
def LimZero {abv : β → α} (f : CauSeq β abv) : Prop :=
∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j) < ε
theorem add_limZero {f g : CauSeq β abv} (hf : LimZero f) (hg : LimZero g) : LimZero (f + g)
| ε, ε0 =>
(exists_forall_ge_and (hf _ <| half_pos ε0) (hg _ <| half_pos ε0)).imp fun _ H j ij => by
let ⟨H₁, H₂⟩ := H _ ij
simpa [add_halves ε] using lt_of_le_of_lt (abv_add abv _ _) (add_lt_add H₁ H₂)
theorem mul_limZero_right (f : CauSeq β abv) {g} (hg : LimZero g) : LimZero (f * g)
| ε, ε0 =>
let ⟨F, F0, hF⟩ := f.bounded' 0
(hg _ <| div_pos ε0 F0).imp fun _ H j ij => by
have := mul_lt_mul' (le_of_lt <| hF j) (H _ ij) (abv_nonneg abv _) F0
rwa [mul_comm F, div_mul_cancel₀ _ (ne_of_gt F0), ← abv_mul] at this
theorem mul_limZero_left {f} (g : CauSeq β abv) (hg : LimZero f) : LimZero (f * g)
| ε, ε0 =>
let ⟨G, G0, hG⟩ := g.bounded' 0
(hg _ <| div_pos ε0 G0).imp fun _ H j ij => by
have := mul_lt_mul'' (H _ ij) (hG j) (abv_nonneg abv _) (abv_nonneg abv _)
rwa [div_mul_cancel₀ _ (ne_of_gt G0), ← abv_mul] at this
theorem neg_limZero {f : CauSeq β abv} (hf : LimZero f) : LimZero (-f) := by
rw [← neg_one_mul f]
exact mul_limZero_right _ hf
theorem sub_limZero {f g : CauSeq β abv} (hf : LimZero f) (hg : LimZero g) : LimZero (f - g) := by
simpa only [sub_eq_add_neg] using add_limZero hf (neg_limZero hg)
theorem limZero_sub_rev {f g : CauSeq β abv} (hfg : LimZero (f - g)) : LimZero (g - f) := by
simpa using neg_limZero hfg
theorem zero_limZero : LimZero (0 : CauSeq β abv)
| ε, ε0 => ⟨0, fun j _ => by simpa [abv_zero abv] using ε0⟩
theorem const_limZero {x : β} : LimZero (const x) ↔ x = 0 :=
⟨fun H =>
(abv_eq_zero abv).1 <|
(eq_of_le_of_forall_lt_imp_le_of_dense (abv_nonneg abv _)) fun _ ε0 =>
let ⟨_, hi⟩ := H _ ε0
le_of_lt <| hi _ le_rfl,
fun e => e.symm ▸ zero_limZero⟩
instance equiv : Setoid (CauSeq β abv) :=
⟨fun f g => LimZero (f - g),
⟨fun f => by simp [zero_limZero],
fun f ε hε => by simpa using neg_limZero f ε hε,
fun fg gh => by simpa using add_limZero fg gh⟩⟩
theorem add_equiv_add {f1 f2 g1 g2 : CauSeq β abv} (hf : f1 ≈ f2) (hg : g1 ≈ g2) :
f1 + g1 ≈ f2 + g2 := by simpa only [← add_sub_add_comm] using add_limZero hf hg
theorem neg_equiv_neg {f g : CauSeq β abv} (hf : f ≈ g) : -f ≈ -g := by
simpa only [neg_sub'] using neg_limZero hf
theorem sub_equiv_sub {f1 f2 g1 g2 : CauSeq β abv} (hf : f1 ≈ f2) (hg : g1 ≈ g2) :
f1 - g1 ≈ f2 - g2 := by simpa only [sub_eq_add_neg] using add_equiv_add hf (neg_equiv_neg hg)
theorem equiv_def₃ {f g : CauSeq β abv} (h : f ≈ g) {ε : α} (ε0 : 0 < ε) :
∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - g j) < ε :=
(exists_forall_ge_and (h _ <| half_pos ε0) (f.cauchy₃ <| half_pos ε0)).imp fun _ H j ij k jk => by
let ⟨h₁, h₂⟩ := H _ ij
have := lt_of_le_of_lt (abv_add abv (f j - g j) _) (add_lt_add h₁ (h₂ _ jk))
rwa [sub_add_sub_cancel', add_halves] at this
theorem limZero_congr {f g : CauSeq β abv} (h : f ≈ g) : LimZero f ↔ LimZero g :=
⟨fun l => by simpa using add_limZero (Setoid.symm h) l, fun l => by simpa using add_limZero h l⟩
theorem abv_pos_of_not_limZero {f : CauSeq β abv} (hf : ¬LimZero f) :
∃ K > 0, ∃ i, ∀ j ≥ i, K ≤ abv (f j) := by
haveI := Classical.propDecidable
by_contra nk
refine hf fun ε ε0 => ?_
simp? [not_forall] at nk says
simp only [gt_iff_lt, ge_iff_le, not_exists, not_and, not_forall, Classical.not_imp,
not_le] at nk
obtain ⟨i, hi⟩ := f.cauchy₃ (half_pos ε0)
rcases nk _ (half_pos ε0) i with ⟨j, ij, hj⟩
refine ⟨j, fun k jk => ?_⟩
have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add (hi j ij k jk) hj)
rwa [sub_add_cancel, add_halves] at this
theorem of_near (f : ℕ → β) (g : CauSeq β abv) (h : ∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j - g j) < ε) :
IsCauSeq abv f
| | ε, ε0 =>
let ⟨i, hi⟩ := exists_forall_ge_and (h _ (half_pos <| half_pos ε0)) (g.cauchy₃ <| half_pos ε0)
| Mathlib/Algebra/Order/CauSeq/Basic.lean | 450 | 451 |
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Wrenna Robson
-/
import Mathlib.Algebra.BigOperators.Group.Finset.Pi
import Mathlib.Algebra.Polynomial.FieldDivision
import Mathlib.LinearAlgebra.Vandermonde
import Mathlib.RingTheory.Polynomial.Basic
/-!
# Lagrange interpolation
## Main definitions
* In everything that follows, `s : Finset ι` is a finite set of indexes, with `v : ι → F` an
indexing of the field over some type. We call the image of v on s the interpolation nodes,
though strictly unique nodes are only defined when v is injective on s.
* `Lagrange.basisDivisor x y`, with `x y : F`. These are the normalised irreducible factors of
the Lagrange basis polynomials. They evaluate to `1` at `x` and `0` at `y` when `x` and `y`
are distinct.
* `Lagrange.basis v i` with `i : ι`: the Lagrange basis polynomial that evaluates to `1` at `v i`
and `0` at `v j` for `i ≠ j`.
* `Lagrange.interpolate v r` where `r : ι → F` is a function from the fintype to the field: the
Lagrange interpolant that evaluates to `r i` at `x i` for all `i : ι`. The `r i` are the _values_
associated with the _nodes_`x i`.
-/
open Polynomial
section PolynomialDetermination
namespace Polynomial
variable {R : Type*} [CommRing R] [IsDomain R] {f g : R[X]}
section Finset
open Function Fintype
open scoped Finset
variable (s : Finset R)
| theorem eq_zero_of_degree_lt_of_eval_finset_eq_zero (degree_f_lt : f.degree < #s)
(eval_f : ∀ x ∈ s, f.eval x = 0) : f = 0 := by
rw [← mem_degreeLT] at degree_f_lt
simp_rw [eval_eq_sum_degreeLTEquiv degree_f_lt] at eval_f
rw [← degreeLTEquiv_eq_zero_iff_eq_zero degree_f_lt]
exact
Matrix.eq_zero_of_forall_index_sum_mul_pow_eq_zero
(Injective.comp (Embedding.subtype _).inj' (equivFinOfCardEq (card_coe _)).symm.injective)
fun _ => eval_f _ (Finset.coe_mem _)
| Mathlib/LinearAlgebra/Lagrange.lean | 44 | 52 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Sean Leather
-/
import Batteries.Data.List.Perm
import Mathlib.Data.List.Pairwise
import Mathlib.Data.List.Nodup
import Mathlib.Data.List.Lookmap
import Mathlib.Data.Sigma.Basic
/-!
# Utilities for lists of sigmas
This file includes several ways of interacting with `List (Sigma β)`, treated as a key-value store.
If `α : Type*` and `β : α → Type*`, then we regard `s : Sigma β` as having key `s.1 : α` and value
`s.2 : β s.1`. Hence, `List (Sigma β)` behaves like a key-value store.
## Main Definitions
- `List.keys` extracts the list of keys.
- `List.NodupKeys` determines if the store has duplicate keys.
- `List.lookup`/`lookup_all` accesses the value(s) of a particular key.
- `List.kreplace` replaces the first value with a given key by a given value.
- `List.kerase` removes a value.
- `List.kinsert` inserts a value.
- `List.kunion` computes the union of two stores.
- `List.kextract` returns a value with a given key and the rest of the values.
-/
universe u u' v v'
namespace List
variable {α : Type u} {α' : Type u'} {β : α → Type v} {β' : α' → Type v'} {l l₁ l₂ : List (Sigma β)}
/-! ### `keys` -/
/-- List of keys from a list of key-value pairs -/
def keys : List (Sigma β) → List α :=
map Sigma.fst
@[simp]
theorem keys_nil : @keys α β [] = [] :=
rfl
@[simp]
theorem keys_cons {s} {l : List (Sigma β)} : (s :: l).keys = s.1 :: l.keys :=
rfl
theorem mem_keys_of_mem {s : Sigma β} {l : List (Sigma β)} : s ∈ l → s.1 ∈ l.keys :=
mem_map_of_mem
theorem exists_of_mem_keys {a} {l : List (Sigma β)} (h : a ∈ l.keys) :
∃ b : β a, Sigma.mk a b ∈ l :=
let ⟨⟨_, b'⟩, m, e⟩ := exists_of_mem_map h
Eq.recOn e (Exists.intro b' m)
theorem mem_keys {a} {l : List (Sigma β)} : a ∈ l.keys ↔ ∃ b : β a, Sigma.mk a b ∈ l :=
⟨exists_of_mem_keys, fun ⟨_, h⟩ => mem_keys_of_mem h⟩
theorem not_mem_keys {a} {l : List (Sigma β)} : a ∉ l.keys ↔ ∀ b : β a, Sigma.mk a b ∉ l :=
(not_congr mem_keys).trans not_exists
theorem ne_key {a} {l : List (Sigma β)} : a ∉ l.keys ↔ ∀ s : Sigma β, s ∈ l → a ≠ s.1 :=
Iff.intro (fun h₁ s h₂ e => absurd (mem_keys_of_mem h₂) (by rwa [e] at h₁)) fun f h₁ =>
let ⟨_, h₂⟩ := exists_of_mem_keys h₁
f _ h₂ rfl
@[deprecated (since := "2025-04-27")]
alias not_eq_key := ne_key
/-! ### `NodupKeys` -/
/-- Determines whether the store uses a key several times. -/
def NodupKeys (l : List (Sigma β)) : Prop :=
l.keys.Nodup
theorem nodupKeys_iff_pairwise {l} : NodupKeys l ↔ Pairwise (fun s s' : Sigma β => s.1 ≠ s'.1) l :=
pairwise_map
theorem NodupKeys.pairwise_ne {l} (h : NodupKeys l) :
Pairwise (fun s s' : Sigma β => s.1 ≠ s'.1) l :=
nodupKeys_iff_pairwise.1 h
@[simp]
theorem nodupKeys_nil : @NodupKeys α β [] :=
Pairwise.nil
@[simp]
theorem nodupKeys_cons {s : Sigma β} {l : List (Sigma β)} :
NodupKeys (s :: l) ↔ s.1 ∉ l.keys ∧ NodupKeys l := by simp [keys, NodupKeys]
theorem not_mem_keys_of_nodupKeys_cons {s : Sigma β} {l : List (Sigma β)} (h : NodupKeys (s :: l)) :
s.1 ∉ l.keys :=
(nodupKeys_cons.1 h).1
theorem nodupKeys_of_nodupKeys_cons {s : Sigma β} {l : List (Sigma β)} (h : NodupKeys (s :: l)) :
NodupKeys l :=
(nodupKeys_cons.1 h).2
theorem NodupKeys.eq_of_fst_eq {l : List (Sigma β)} (nd : NodupKeys l) {s s' : Sigma β} (h : s ∈ l)
(h' : s' ∈ l) : s.1 = s'.1 → s = s' :=
@Pairwise.forall_of_forall _ (fun s s' : Sigma β => s.1 = s'.1 → s = s') _
(fun _ _ H h => (H h.symm).symm) (fun _ _ _ => rfl)
((nodupKeys_iff_pairwise.1 nd).imp fun h h' => (h h').elim) _ h _ h'
theorem NodupKeys.eq_of_mk_mem {a : α} {b b' : β a} {l : List (Sigma β)} (nd : NodupKeys l)
(h : Sigma.mk a b ∈ l) (h' : Sigma.mk a b' ∈ l) : b = b' := by
cases nd.eq_of_fst_eq h h' rfl; rfl
theorem nodupKeys_singleton (s : Sigma β) : NodupKeys [s] :=
nodup_singleton _
theorem NodupKeys.sublist {l₁ l₂ : List (Sigma β)} (h : l₁ <+ l₂) : NodupKeys l₂ → NodupKeys l₁ :=
Nodup.sublist <| h.map _
protected theorem NodupKeys.nodup {l : List (Sigma β)} : NodupKeys l → Nodup l :=
Nodup.of_map _
theorem perm_nodupKeys {l₁ l₂ : List (Sigma β)} (h : l₁ ~ l₂) : NodupKeys l₁ ↔ NodupKeys l₂ :=
(h.map _).nodup_iff
theorem nodupKeys_flatten {L : List (List (Sigma β))} :
NodupKeys (flatten L) ↔ (∀ l ∈ L, NodupKeys l) ∧ Pairwise Disjoint (L.map keys) := by
rw [nodupKeys_iff_pairwise, pairwise_flatten, pairwise_map]
refine and_congr (forall₂_congr fun l _ => by simp [nodupKeys_iff_pairwise]) ?_
apply iff_of_eq; congr! with (l₁ l₂)
simp [keys, disjoint_iff_ne, Sigma.forall]
theorem nodup_zipIdx_map_snd (l : List α) : (l.zipIdx.map Prod.snd).Nodup := by
simp [List.nodup_range']
@[deprecated (since := "2025-01-28")] alias nodup_enum_map_fst := nodup_zipIdx_map_snd
theorem mem_ext {l₀ l₁ : List (Sigma β)} (nd₀ : l₀.Nodup) (nd₁ : l₁.Nodup)
(h : ∀ x, x ∈ l₀ ↔ x ∈ l₁) : l₀ ~ l₁ :=
(perm_ext_iff_of_nodup nd₀ nd₁).2 h
variable [DecidableEq α] [DecidableEq α']
/-! ### `dlookup` -/
/-- `dlookup a l` is the first value in `l` corresponding to the key `a`,
or `none` if no such element exists. -/
def dlookup (a : α) : List (Sigma β) → Option (β a)
| [] => none
| ⟨a', b⟩ :: l => if h : a' = a then some (Eq.recOn h b) else dlookup a l
@[simp]
theorem dlookup_nil (a : α) : dlookup a [] = @none (β a) :=
rfl
@[simp]
theorem dlookup_cons_eq (l) (a : α) (b : β a) : dlookup a (⟨a, b⟩ :: l) = some b :=
dif_pos rfl
@[simp]
theorem dlookup_cons_ne (l) {a} : ∀ s : Sigma β, a ≠ s.1 → dlookup a (s :: l) = dlookup a l
| ⟨_, _⟩, h => dif_neg h.symm
theorem dlookup_isSome {a : α} : ∀ {l : List (Sigma β)}, (dlookup a l).isSome ↔ a ∈ l.keys
| [] => by simp
| ⟨a', b⟩ :: l => by
by_cases h : a = a'
· subst a'
simp
· simp [h, dlookup_isSome]
theorem dlookup_eq_none {a : α} {l : List (Sigma β)} : dlookup a l = none ↔ a ∉ l.keys := by
simp [← dlookup_isSome, Option.isNone_iff_eq_none]
theorem of_mem_dlookup {a : α} {b : β a} :
∀ {l : List (Sigma β)}, b ∈ dlookup a l → Sigma.mk a b ∈ l
| ⟨a', b'⟩ :: l, H => by
by_cases h : a = a'
· subst a'
simp? at H says simp only [dlookup_cons_eq, Option.mem_def, Option.some.injEq] at H
simp [H]
· simp only [ne_eq, h, not_false_iff, dlookup_cons_ne] at H
simp [of_mem_dlookup H]
theorem mem_dlookup {a} {b : β a} {l : List (Sigma β)} (nd : l.NodupKeys) (h : Sigma.mk a b ∈ l) :
b ∈ dlookup a l := by
obtain ⟨b', h'⟩ := Option.isSome_iff_exists.mp (dlookup_isSome.mpr (mem_keys_of_mem h))
cases nd.eq_of_mk_mem h (of_mem_dlookup h')
exact h'
theorem map_dlookup_eq_find (a : α) :
∀ l : List (Sigma β), (dlookup a l).map (Sigma.mk a) = find? (fun s => a = s.1) l
| [] => rfl
| ⟨a', b'⟩ :: l => by
by_cases h : a = a'
· subst a'
simp
· simpa [h] using map_dlookup_eq_find a l
theorem mem_dlookup_iff {a : α} {b : β a} {l : List (Sigma β)} (nd : l.NodupKeys) :
b ∈ dlookup a l ↔ Sigma.mk a b ∈ l :=
⟨of_mem_dlookup, mem_dlookup nd⟩
theorem perm_dlookup (a : α) {l₁ l₂ : List (Sigma β)} (nd₁ : l₁.NodupKeys) (nd₂ : l₂.NodupKeys)
(p : l₁ ~ l₂) : dlookup a l₁ = dlookup a l₂ := by
ext b; simp only [mem_dlookup_iff nd₁, mem_dlookup_iff nd₂]; exact p.mem_iff
theorem lookup_ext {l₀ l₁ : List (Sigma β)} (nd₀ : l₀.NodupKeys) (nd₁ : l₁.NodupKeys)
(h : ∀ x y, y ∈ l₀.dlookup x ↔ y ∈ l₁.dlookup x) : l₀ ~ l₁ :=
mem_ext nd₀.nodup nd₁.nodup fun ⟨a, b⟩ => by
rw [← mem_dlookup_iff, ← mem_dlookup_iff, h] <;> assumption
theorem dlookup_map (l : List (Sigma β))
{f : α → α'} (hf : Function.Injective f) (g : ∀ a, β a → β' (f a)) (a : α) :
(l.map fun x => ⟨f x.1, g _ x.2⟩).dlookup (f a) = (l.dlookup a).map (g a) := by
induction' l with b l IH
· rw [map_nil, dlookup_nil, dlookup_nil, Option.map_none']
· rw [map_cons]
obtain rfl | h := eq_or_ne a b.1
· rw [dlookup_cons_eq, dlookup_cons_eq, Option.map_some']
· rw [dlookup_cons_ne _ _ h, dlookup_cons_ne _ _ (fun he => h <| hf he), IH]
theorem dlookup_map₁ {β : Type v} (l : List (Σ _ : α, β))
{f : α → α'} (hf : Function.Injective f) (a : α) :
(l.map fun x => ⟨f x.1, x.2⟩ : List (Σ _ : α', β)).dlookup (f a) = l.dlookup a := by
rw [dlookup_map (β' := fun _ => β) l hf (fun _ x => x) a, Option.map_id']
theorem dlookup_map₂ {γ δ : α → Type*} {l : List (Σ a, γ a)} {f : ∀ a, γ a → δ a} (a : α) :
(l.map fun x => ⟨x.1, f _ x.2⟩ : List (Σ a, δ a)).dlookup a = (l.dlookup a).map (f a) :=
dlookup_map l Function.injective_id _ _
/-! ### `lookupAll` -/
/-- `lookup_all a l` is the list of all values in `l` corresponding to the key `a`. -/
def lookupAll (a : α) : List (Sigma β) → List (β a)
| [] => []
| ⟨a', b⟩ :: l => if h : a' = a then Eq.recOn h b :: lookupAll a l else lookupAll a l
@[simp]
theorem lookupAll_nil (a : α) : lookupAll a [] = @nil (β a) :=
rfl
@[simp]
theorem lookupAll_cons_eq (l) (a : α) (b : β a) : lookupAll a (⟨a, b⟩ :: l) = b :: lookupAll a l :=
dif_pos rfl
@[simp]
theorem lookupAll_cons_ne (l) {a} : ∀ s : Sigma β, a ≠ s.1 → lookupAll a (s :: l) = lookupAll a l
| ⟨_, _⟩, h => dif_neg h.symm
theorem lookupAll_eq_nil {a : α} :
∀ {l : List (Sigma β)}, lookupAll a l = [] ↔ ∀ b : β a, Sigma.mk a b ∉ l
| [] => by simp
| ⟨a', b⟩ :: l => by
by_cases h : a = a'
· subst a'
simp only [lookupAll_cons_eq, mem_cons, Sigma.mk.inj_iff, heq_eq_eq, true_and, not_or,
false_iff, not_forall, not_and, not_not, reduceCtorEq]
use b
simp
· simp [h, lookupAll_eq_nil]
theorem head?_lookupAll (a : α) : ∀ l : List (Sigma β), head? (lookupAll a l) = dlookup a l
| [] => by simp
| ⟨a', b⟩ :: l => by
by_cases h : a = a'
· subst h; simp
· rw [lookupAll_cons_ne, dlookup_cons_ne, head?_lookupAll a l] <;> assumption
theorem mem_lookupAll {a : α} {b : β a} :
∀ {l : List (Sigma β)}, b ∈ lookupAll a l ↔ Sigma.mk a b ∈ l
| [] => by simp
| ⟨a', b'⟩ :: l => by
by_cases h : a = a'
· subst h
simp [*, mem_lookupAll]
· simp [*, mem_lookupAll]
theorem lookupAll_sublist (a : α) : ∀ l : List (Sigma β), (lookupAll a l).map (Sigma.mk a) <+ l
| [] => by simp
| ⟨a', b'⟩ :: l => by
by_cases h : a = a'
· subst h
simp only [ne_eq, not_true, lookupAll_cons_eq, List.map]
exact (lookupAll_sublist a l).cons₂ _
· simp only [ne_eq, h, not_false_iff, lookupAll_cons_ne]
exact (lookupAll_sublist a l).cons _
theorem lookupAll_length_le_one (a : α) {l : List (Sigma β)} (h : l.NodupKeys) :
length (lookupAll a l) ≤ 1 := by
have := Nodup.sublist ((lookupAll_sublist a l).map _) h
rw [map_map] at this
rwa [← nodup_replicate, ← map_const]
theorem lookupAll_eq_dlookup (a : α) {l : List (Sigma β)} (h : l.NodupKeys) :
lookupAll a l = (dlookup a l).toList := by
rw [← head?_lookupAll]
have h1 := lookupAll_length_le_one a h; revert h1
rcases lookupAll a l with (_ | ⟨b, _ | ⟨c, l⟩⟩) <;> intro h1 <;> try rfl
exact absurd h1 (by simp)
theorem lookupAll_nodup (a : α) {l : List (Sigma β)} (h : l.NodupKeys) : (lookupAll a l).Nodup := by
(rw [lookupAll_eq_dlookup a h]; apply Option.toList_nodup)
theorem perm_lookupAll (a : α) {l₁ l₂ : List (Sigma β)} (nd₁ : l₁.NodupKeys) (nd₂ : l₂.NodupKeys)
(p : l₁ ~ l₂) : lookupAll a l₁ = lookupAll a l₂ := by
simp [lookupAll_eq_dlookup, nd₁, nd₂, perm_dlookup a nd₁ nd₂ p]
theorem dlookup_append (l₁ l₂ : List (Sigma β)) (a : α) :
(l₁ ++ l₂).dlookup a = (l₁.dlookup a).or (l₂.dlookup a) := by
induction l₁ with
| nil => rfl
| cons x l₁ IH =>
rw [cons_append]
obtain rfl | hb := Decidable.eq_or_ne a x.1
· rw [dlookup_cons_eq, dlookup_cons_eq, Option.or]
· rw [dlookup_cons_ne _ _ hb, dlookup_cons_ne _ _ hb, IH]
/-! ### `kreplace` -/
/-- Replaces the first value with key `a` by `b`. -/
def kreplace (a : α) (b : β a) : List (Sigma β) → List (Sigma β) :=
lookmap fun s => if a = s.1 then some ⟨a, b⟩ else none
theorem kreplace_of_forall_not (a : α) (b : β a) {l : List (Sigma β)}
(H : ∀ b : β a, Sigma.mk a b ∉ l) : kreplace a b l = l :=
lookmap_of_forall_not _ <| by
rintro ⟨a', b'⟩ h; dsimp; split_ifs
· subst a'
exact H _ h
· rfl
theorem kreplace_self {a : α} {b : β a} {l : List (Sigma β)} (nd : NodupKeys l)
(h : Sigma.mk a b ∈ l) : kreplace a b l = l := by
refine (lookmap_congr ?_).trans (lookmap_id' (Option.guard fun (s : Sigma β) => a = s.1) ?_ _)
· rintro ⟨a', b'⟩ h'
dsimp [Option.guard]
split_ifs
· subst a'
simp [nd.eq_of_mk_mem h h']
· rfl
· rintro ⟨a₁, b₁⟩ ⟨a₂, b₂⟩
dsimp [Option.guard]
split_ifs
· simp
· rintro ⟨⟩
theorem keys_kreplace (a : α) (b : β a) : ∀ l : List (Sigma β), (kreplace a b l).keys = l.keys :=
lookmap_map_eq _ _ <| by
rintro ⟨a₁, b₂⟩ ⟨a₂, b₂⟩
dsimp
split_ifs with h <;> simp +contextual [h]
theorem kreplace_nodupKeys (a : α) (b : β a) {l : List (Sigma β)} :
(kreplace a b l).NodupKeys ↔ l.NodupKeys := by simp [NodupKeys, keys_kreplace]
theorem Perm.kreplace {a : α} {b : β a} {l₁ l₂ : List (Sigma β)} (nd : l₁.NodupKeys) :
l₁ ~ l₂ → kreplace a b l₁ ~ kreplace a b l₂ :=
perm_lookmap _ <| by
refine nd.pairwise_ne.imp ?_
intro x y h z h₁ w h₂
split_ifs at h₁ h₂ with h_2 h_1 <;> cases h₁ <;> cases h₂
exact (h (h_2.symm.trans h_1)).elim
| /-! ### `kerase` -/
/-- Remove the first pair with the key `a`. -/
def kerase (a : α) : List (Sigma β) → List (Sigma β) :=
| Mathlib/Data/List/Sigma.lean | 368 | 372 |
/-
Copyright (c) 2024 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Lie.Derivation.Killing
import Mathlib.Algebra.Lie.Killing
import Mathlib.Algebra.Lie.Sl2
import Mathlib.Algebra.Lie.Weights.Chain
import Mathlib.LinearAlgebra.Eigenspace.Semisimple
import Mathlib.LinearAlgebra.JordanChevalley
/-!
# Roots of Lie algebras with non-degenerate Killing forms
The file contains definitions and results about roots of Lie algebras with non-degenerate Killing
forms.
## Main definitions
* `LieAlgebra.IsKilling.ker_restrict_eq_bot_of_isCartanSubalgebra`: if the Killing form of
a Lie algebra is non-singular, it remains non-singular when restricted to a Cartan subalgebra.
* `LieAlgebra.IsKilling.instIsLieAbelianOfIsCartanSubalgebra`: if the Killing form of a Lie
algebra is non-singular, then its Cartan subalgebras are Abelian.
* `LieAlgebra.IsKilling.isSemisimple_ad_of_mem_isCartanSubalgebra`: over a perfect field, if a Lie
algebra has non-degenerate Killing form, Cartan subalgebras contain only semisimple elements.
* `LieAlgebra.IsKilling.span_weight_eq_top`: given a splitting Cartan subalgebra `H` of a
finite-dimensional Lie algebra with non-singular Killing form, the corresponding roots span the
dual space of `H`.
* `LieAlgebra.IsKilling.coroot`: the coroot corresponding to a root.
* `LieAlgebra.IsKilling.isCompl_ker_weight_span_coroot`: given a root `α` with respect to a Cartan
subalgebra `H`, we have a natural decomposition of `H` as the kernel of `α` and the span of the
coroot corresponding to `α`.
* `LieAlgebra.IsKilling.finrank_rootSpace_eq_one`: root spaces are one-dimensional.
-/
variable (R K L : Type*) [CommRing R] [LieRing L] [LieAlgebra R L] [Field K] [LieAlgebra K L]
namespace LieAlgebra
lemma restrict_killingForm (H : LieSubalgebra R L) :
(killingForm R L).restrict H = LieModule.traceForm R H L :=
rfl
namespace IsKilling
variable [IsKilling R L]
/-- If the Killing form of a Lie algebra is non-singular, it remains non-singular when restricted
to a Cartan subalgebra. -/
lemma ker_restrict_eq_bot_of_isCartanSubalgebra
[IsNoetherian R L] [IsArtinian R L] (H : LieSubalgebra R L) [H.IsCartanSubalgebra] :
LinearMap.ker ((killingForm R L).restrict H) = ⊥ := by
have h : Codisjoint (rootSpace H 0) (LieModule.posFittingComp R H L) :=
(LieModule.isCompl_genWeightSpace_zero_posFittingComp R H L).codisjoint
replace h : Codisjoint (H : Submodule R L) (LieModule.posFittingComp R H L : Submodule R L) := by
rwa [codisjoint_iff, ← LieSubmodule.toSubmodule_inj, LieSubmodule.sup_toSubmodule,
LieSubmodule.top_toSubmodule, rootSpace_zero_eq R L H, LieSubalgebra.coe_toLieSubmodule,
← codisjoint_iff] at h
suffices this : ∀ m₀ ∈ H, ∀ m₁ ∈ LieModule.posFittingComp R H L, killingForm R L m₀ m₁ = 0 by
simp [LinearMap.BilinForm.ker_restrict_eq_of_codisjoint h this]
intro m₀ h₀ m₁ h₁
exact killingForm_eq_zero_of_mem_zeroRoot_mem_posFitting R L H (le_zeroRootSubalgebra R L H h₀) h₁
@[simp] lemma ker_traceForm_eq_bot_of_isCartanSubalgebra
[IsNoetherian R L] [IsArtinian R L] (H : LieSubalgebra R L) [H.IsCartanSubalgebra] :
LinearMap.ker (LieModule.traceForm R H L) = ⊥ :=
ker_restrict_eq_bot_of_isCartanSubalgebra R L H
lemma traceForm_cartan_nondegenerate
[IsNoetherian R L] [IsArtinian R L] (H : LieSubalgebra R L) [H.IsCartanSubalgebra] :
(LieModule.traceForm R H L).Nondegenerate := by
simp [LinearMap.BilinForm.nondegenerate_iff_ker_eq_bot]
variable [Module.Free R L] [Module.Finite R L]
instance instIsLieAbelianOfIsCartanSubalgebra
[IsDomain R] [IsPrincipalIdealRing R] [IsArtinian R L]
(H : LieSubalgebra R L) [H.IsCartanSubalgebra] :
IsLieAbelian H :=
LieModule.isLieAbelian_of_ker_traceForm_eq_bot R H L <|
ker_restrict_eq_bot_of_isCartanSubalgebra R L H
end IsKilling
section Field
open Module LieModule Set
open Submodule (span subset_span)
variable [FiniteDimensional K L] (H : LieSubalgebra K L) [H.IsCartanSubalgebra]
section
variable [IsTriangularizable K H L]
/-- For any `α` and `β`, the corresponding root spaces are orthogonal with respect to the Killing
form, provided `α + β ≠ 0`. -/
lemma killingForm_apply_eq_zero_of_mem_rootSpace_of_add_ne_zero {α β : H → K} {x y : L}
(hx : x ∈ rootSpace H α) (hy : y ∈ rootSpace H β) (hαβ : α + β ≠ 0) :
killingForm K L x y = 0 := by
/- If `ad R L z` is semisimple for all `z ∈ H` then writing `⟪x, y⟫ = killingForm K L x y`, there
is a slick proof of this lemma that requires only invariance of the Killing form as follows.
For any `z ∈ H`, we have:
`α z • ⟪x, y⟫ = ⟪α z • x, y⟫ = ⟪⁅z, x⁆, y⟫ = - ⟪x, ⁅z, y⁆⟫ = - ⟪x, β z • y⟫ = - β z • ⟪x, y⟫`.
Since this is true for any `z`, we thus have: `(α + β) • ⟪x, y⟫ = 0`, and hence the result.
However the semisimplicity of `ad R L z` is (a) non-trivial and (b) requires the assumption
that `K` is a perfect field and `L` has non-degenerate Killing form. -/
let σ : (H → K) → (H → K) := fun γ ↦ α + (β + γ)
have hσ : ∀ γ, σ γ ≠ γ := fun γ ↦ by simpa only [σ, ← add_assoc] using add_ne_right.mpr hαβ
let f : Module.End K L := (ad K L x) ∘ₗ (ad K L y)
have hf : ∀ γ, MapsTo f (rootSpace H γ) (rootSpace H (σ γ)) := fun γ ↦
(mapsTo_toEnd_genWeightSpace_add_of_mem_rootSpace K L H L α (β + γ) hx).comp <|
mapsTo_toEnd_genWeightSpace_add_of_mem_rootSpace K L H L β γ hy
classical
have hds := DirectSum.isInternal_submodule_of_iSupIndep_of_iSup_eq_top
(LieSubmodule.iSupIndep_toSubmodule.mpr <| iSupIndep_genWeightSpace K H L)
(LieSubmodule.iSup_toSubmodule_eq_top.mpr <| iSup_genWeightSpace_eq_top K H L)
exact LinearMap.trace_eq_zero_of_mapsTo_ne hds σ hσ hf
/-- Elements of the `α` root space which are Killing-orthogonal to the `-α` root space are
Killing-orthogonal to all of `L`. -/
lemma mem_ker_killingForm_of_mem_rootSpace_of_forall_rootSpace_neg
{α : H → K} {x : L} (hx : x ∈ rootSpace H α)
(hx' : ∀ y ∈ rootSpace H (-α), killingForm K L x y = 0) :
x ∈ LinearMap.ker (killingForm K L) := by
rw [LinearMap.mem_ker]
ext y
have hy : y ∈ ⨆ β, rootSpace H β := by simp [iSup_genWeightSpace_eq_top K H L]
induction hy using LieSubmodule.iSup_induction' with
| mem β y hy =>
by_cases hαβ : α + β = 0
· exact hx' _ (add_eq_zero_iff_neg_eq.mp hαβ ▸ hy)
· exact killingForm_apply_eq_zero_of_mem_rootSpace_of_add_ne_zero K L H hx hy hαβ
| zero => simp
| add => simp_all
end
namespace IsKilling
variable [IsKilling K L]
/-- If a Lie algebra `L` has non-degenerate Killing form, the only element of a Cartan subalgebra
whose adjoint action on `L` is nilpotent, is the zero element.
Over a perfect field a much stronger result is true, see
`LieAlgebra.IsKilling.isSemisimple_ad_of_mem_isCartanSubalgebra`. -/
lemma eq_zero_of_isNilpotent_ad_of_mem_isCartanSubalgebra {x : L} (hx : x ∈ H)
(hx' : _root_.IsNilpotent (ad K L x)) : x = 0 := by
suffices ⟨x, hx⟩ ∈ LinearMap.ker (traceForm K H L) by
simp at this
exact (AddSubmonoid.mk_eq_zero H.toAddSubmonoid).mp this
simp only [LinearMap.mem_ker]
ext y
have comm : Commute (toEnd K H L ⟨x, hx⟩) (toEnd K H L y) := by
rw [commute_iff_lie_eq, ← LieHom.map_lie, trivial_lie_zero, LieHom.map_zero]
rw [traceForm_apply_apply, ← Module.End.mul_eq_comp, LinearMap.zero_apply]
exact (LinearMap.isNilpotent_trace_of_isNilpotent (comm.isNilpotent_mul_left hx')).eq_zero
@[simp]
lemma corootSpace_zero_eq_bot :
| corootSpace (0 : H → K) = ⊥ := by
refine eq_bot_iff.mpr fun x hx ↦ ?_
suffices {x | ∃ y ∈ H, ∃ z ∈ H, ⁅y, z⁆ = x} = {0} by simpa [mem_corootSpace, this] using hx
refine eq_singleton_iff_unique_mem.mpr ⟨⟨0, H.zero_mem, 0, H.zero_mem, zero_lie 0⟩, ?_⟩
rintro - ⟨y, hy, z, hz, rfl⟩
suffices ⁅(⟨y, hy⟩ : H), (⟨z, hz⟩ : H)⁆ = 0 by
simpa only [Subtype.ext_iff, LieSubalgebra.coe_bracket, ZeroMemClass.coe_zero] using this
simp
variable {K L} in
/-- The restriction of the Killing form to a Cartan subalgebra, as a linear equivalence to the
dual. -/
@[simps! apply_apply]
noncomputable def cartanEquivDual :
H ≃ₗ[K] Module.Dual K H :=
(traceForm K H L).toDual <| traceForm_cartan_nondegenerate K L H
| Mathlib/Algebra/Lie/Weights/Killing.lean | 161 | 176 |
/-
Copyright (c) 2019 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Eric Wieser
-/
import Mathlib.LinearAlgebra.Span.Basic
import Mathlib.LinearAlgebra.BilinearMap
/-!
# Images of pairs of submodules under bilinear maps
This file provides `Submodule.map₂`, which is later used to implement `Submodule.mul`.
## Main results
* `Submodule.map₂_eq_span_image2`: the image of two submodules under a bilinear map is the span of
their `Set.image2`.
## Notes
This file is quite similar to the n-ary section of `Data.Set.Basic` and to `Order.Filter.NAry`.
Please keep them in sync.
-/
universe uι u v
open Set
open Pointwise
namespace Submodule
variable {ι : Sort uι} {R M N P : Type*}
variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P]
variable [Module R M] [Module R N] [Module R P]
/-- Map a pair of submodules under a bilinear map.
This is the submodule version of `Set.image2`. -/
def map₂ (f : M →ₗ[R] N →ₗ[R] P) (p : Submodule R M) (q : Submodule R N) : Submodule R P :=
⨆ s : p, q.map (f s)
theorem apply_mem_map₂ (f : M →ₗ[R] N →ₗ[R] P) {m : M} {n : N} {p : Submodule R M}
{q : Submodule R N} (hm : m ∈ p) (hn : n ∈ q) : f m n ∈ map₂ f p q :=
(le_iSup _ ⟨m, hm⟩ : _ ≤ map₂ f p q) ⟨n, hn, by rfl⟩
theorem map₂_le {f : M →ₗ[R] N →ₗ[R] P} {p : Submodule R M} {q : Submodule R N}
{r : Submodule R P} : map₂ f p q ≤ r ↔ ∀ m ∈ p, ∀ n ∈ q, f m n ∈ r :=
⟨fun H _m hm _n hn => H <| apply_mem_map₂ _ hm hn, fun H =>
iSup_le fun ⟨m, hm⟩ => map_le_iff_le_comap.2 fun n hn => H m hm n hn⟩
variable (R) in
theorem map₂_span_span (f : M →ₗ[R] N →ₗ[R] P) (s : Set M) (t : Set N) :
map₂ f (span R s) (span R t) = span R (Set.image2 (fun m n => f m n) s t) := by
apply le_antisymm
· rw [map₂_le]
apply @span_induction R M _ _ _ s
on_goal 1 =>
intro a ha
apply @span_induction R N _ _ _ t
· intro b hb
exact subset_span ⟨_, ‹_›, _, ‹_›, rfl⟩
all_goals
intros
simp only [*, add_mem, smul_mem, zero_mem, map_zero, map_add,
LinearMap.zero_apply, LinearMap.add_apply, LinearMap.smul_apply, map_smul]
· rw [span_le, image2_subset_iff]
intro a ha b hb
exact apply_mem_map₂ _ (subset_span ha) (subset_span hb)
@[simp]
theorem map₂_bot_right (f : M →ₗ[R] N →ₗ[R] P) (p : Submodule R M) : map₂ f p ⊥ = ⊥ :=
eq_bot_iff.2 <|
map₂_le.2 fun m _hm n hn => by
rw [Submodule.mem_bot] at hn
rw [hn, LinearMap.map_zero]; simp only [mem_bot]
@[simp]
theorem map₂_bot_left (f : M →ₗ[R] N →ₗ[R] P) (q : Submodule R N) : map₂ f ⊥ q = ⊥ :=
eq_bot_iff.2 <|
map₂_le.2 fun m hm n _ => by
rw [Submodule.mem_bot] at hm ⊢
rw [hm, LinearMap.map_zero₂]
@[gcongr, mono]
theorem map₂_le_map₂ {f : M →ₗ[R] N →ₗ[R] P} {p₁ p₂ : Submodule R M} {q₁ q₂ : Submodule R N}
(hp : p₁ ≤ p₂) (hq : q₁ ≤ q₂) : map₂ f p₁ q₁ ≤ map₂ f p₂ q₂ :=
map₂_le.2 fun _m hm _n hn => apply_mem_map₂ _ (hp hm) (hq hn)
theorem map₂_le_map₂_left {f : M →ₗ[R] N →ₗ[R] P} {p₁ p₂ : Submodule R M} {q : Submodule R N}
(h : p₁ ≤ p₂) : map₂ f p₁ q ≤ map₂ f p₂ q :=
map₂_le_map₂ h (le_refl q)
theorem map₂_le_map₂_right {f : M →ₗ[R] N →ₗ[R] P} {p : Submodule R M} {q₁ q₂ : Submodule R N}
(h : q₁ ≤ q₂) : map₂ f p q₁ ≤ map₂ f p q₂ :=
map₂_le_map₂ (le_refl p) h
theorem map₂_sup_right (f : M →ₗ[R] N →ₗ[R] P) (p : Submodule R M) (q₁ q₂ : Submodule R N) :
map₂ f p (q₁ ⊔ q₂) = map₂ f p q₁ ⊔ map₂ f p q₂ :=
le_antisymm
(map₂_le.2 fun _m hm _np hnp =>
let ⟨_n, hn, _p, hp, hnp⟩ := mem_sup.1 hnp
mem_sup.2 ⟨_, apply_mem_map₂ _ hm hn, _, apply_mem_map₂ _ hm hp, hnp ▸ (map_add _ _ _).symm⟩)
(sup_le (map₂_le_map₂_right le_sup_left) (map₂_le_map₂_right le_sup_right))
theorem map₂_sup_left (f : M →ₗ[R] N →ₗ[R] P) (p₁ p₂ : Submodule R M) (q : Submodule R N) :
map₂ f (p₁ ⊔ p₂) q = map₂ f p₁ q ⊔ map₂ f p₂ q :=
le_antisymm
(map₂_le.2 fun _mn hmn _p hp =>
let ⟨_m, hm, _n, hn, hmn⟩ := mem_sup.1 hmn
mem_sup.2
⟨_, apply_mem_map₂ _ hm hp, _, apply_mem_map₂ _ hn hp,
hmn ▸ (LinearMap.map_add₂ _ _ _ _).symm⟩)
(sup_le (map₂_le_map₂_left le_sup_left) (map₂_le_map₂_left le_sup_right))
theorem image2_subset_map₂ (f : M →ₗ[R] N →ₗ[R] P) (p : Submodule R M) (q : Submodule R N) :
Set.image2 (fun m n => f m n) (↑p : Set M) (↑q : Set N) ⊆ (↑(map₂ f p q) : Set P) := by
rintro _ ⟨i, hi, j, hj, rfl⟩
exact apply_mem_map₂ _ hi hj
theorem map₂_eq_span_image2 (f : M →ₗ[R] N →ₗ[R] P) (p : Submodule R M) (q : Submodule R N) :
map₂ f p q = span R (Set.image2 (fun m n => f m n) (p : Set M) (q : Set N)) := by
rw [← map₂_span_span, span_eq, span_eq]
theorem map₂_flip (f : M →ₗ[R] N →ₗ[R] P) (p : Submodule R M) (q : Submodule R N) :
map₂ f.flip q p = map₂ f p q := by
rw [map₂_eq_span_image2, map₂_eq_span_image2, Set.image2_swap]
rfl
theorem map₂_iSup_left (f : M →ₗ[R] N →ₗ[R] P) (s : ι → Submodule R M) (t : Submodule R N) :
map₂ f (⨆ i, s i) t = ⨆ i, map₂ f (s i) t := by
suffices map₂ f (⨆ i, span R (s i : Set M)) (span R t) = ⨆ i, map₂ f (span R (s i)) (span R t) by
simpa only [span_eq] using this
simp_rw [map₂_span_span, ← span_iUnion, map₂_span_span, Set.image2_iUnion_left]
theorem map₂_iSup_right (f : M →ₗ[R] N →ₗ[R] P) (s : Submodule R M) (t : ι → Submodule R N) :
map₂ f s (⨆ i, t i) = ⨆ i, map₂ f s (t i) := by
suffices map₂ f (span R s) (⨆ i, span R (t i : Set N)) = ⨆ i, map₂ f (span R s) (span R (t i)) by
simpa only [span_eq] using this
simp_rw [map₂_span_span, ← span_iUnion, map₂_span_span, Set.image2_iUnion_right]
theorem map₂_span_singleton_eq_map (f : M →ₗ[R] N →ₗ[R] P) (m : M) :
map₂ f (span R {m}) = map (f m) := by
funext s
rw [← span_eq s, map₂_span_span, image2_singleton_left, map_span]
|
theorem map₂_span_singleton_eq_map_flip (f : M →ₗ[R] N →ₗ[R] P) (s : Submodule R M) (n : N) :
map₂ f s (span R {n}) = map (f.flip n) s := by rw [← map₂_span_singleton_eq_map, map₂_flip]
end Submodule
| Mathlib/Algebra/Module/Submodule/Bilinear.lean | 146 | 150 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.Group.Conj
import Mathlib.Algebra.Group.Subgroup.Lattice
import Mathlib.Algebra.Group.Submonoid.BigOperators
import Mathlib.Data.Finset.Fin
import Mathlib.Data.Finset.Sort
import Mathlib.Data.Fintype.Perm
import Mathlib.Data.Fintype.Prod
import Mathlib.Data.Fintype.Sum
import Mathlib.Data.Int.Order.Units
import Mathlib.GroupTheory.Perm.Support
import Mathlib.Logic.Equiv.Fin.Basic
import Mathlib.Logic.Equiv.Fintype
import Mathlib.Tactic.NormNum.Ineq
import Mathlib.Data.Finset.Sigma
/-!
# Sign of a permutation
The main definition of this file is `Equiv.Perm.sign`,
associating a `ℤˣ` sign with a permutation.
Other lemmas have been moved to `Mathlib.GroupTheory.Perm.Fintype`
-/
universe u v
open Equiv Function Fintype Finset
variable {α : Type u} [DecidableEq α] {β : Type v}
namespace Equiv.Perm
/-- `modSwap i j` contains permutations up to swapping `i` and `j`.
We use this to partition permutations in `Matrix.det_zero_of_row_eq`, such that each partition
sums up to `0`.
-/
def modSwap (i j : α) : Setoid (Perm α) :=
⟨fun σ τ => σ = τ ∨ σ = swap i j * τ, fun σ => Or.inl (refl σ), fun {σ τ} h =>
Or.casesOn h (fun h => Or.inl h.symm) fun h => Or.inr (by rw [h, swap_mul_self_mul]),
fun {σ τ υ} hστ hτυ => by
rcases hστ with hστ | hστ <;> rcases hτυ with hτυ | hτυ <;>
(try rw [hστ, hτυ, swap_mul_self_mul]) <;>
simp [hστ, hτυ]⟩
noncomputable instance {α : Type*} [Fintype α] [DecidableEq α] (i j : α) :
DecidableRel (modSwap i j).r :=
fun _ _ => inferInstanceAs (Decidable (_ ∨ _))
/-- Given a list `l : List α` and a permutation `f : Perm α` such that the nonfixed points of `f`
are in `l`, recursively factors `f` as a product of transpositions. -/
def swapFactorsAux :
∀ (l : List α) (f : Perm α),
(∀ {x}, f x ≠ x → x ∈ l) → { l : List (Perm α) // l.prod = f ∧ ∀ g ∈ l, IsSwap g }
| [] => fun f h =>
⟨[],
Equiv.ext fun x => by
rw [List.prod_nil]
exact (Classical.not_not.1 (mt h List.not_mem_nil)).symm,
by simp⟩
| x::l => fun f h =>
if hfx : x = f x then
swapFactorsAux l f fun {y} hy =>
List.mem_of_ne_of_mem (fun h : y = x => by simp [h, hfx.symm] at hy) (h hy)
else
let m :=
swapFactorsAux l (swap x (f x) * f) fun {y} hy =>
have : f y ≠ y ∧ y ≠ x := ne_and_ne_of_swap_mul_apply_ne_self hy
List.mem_of_ne_of_mem this.2 (h this.1)
⟨swap x (f x)::m.1, by
rw [List.prod_cons, m.2.1, ← mul_assoc, mul_def (swap x (f x)), swap_swap, ← one_def,
one_mul],
fun {_} hg => ((List.mem_cons).1 hg).elim (fun h => ⟨x, f x, hfx, h⟩) (m.2.2 _)⟩
/-- `swapFactors` represents a permutation as a product of a list of transpositions.
The representation is non unique and depends on the linear order structure.
For types without linear order `truncSwapFactors` can be used. -/
def swapFactors [Fintype α] [LinearOrder α] (f : Perm α) :
{ l : List (Perm α) // l.prod = f ∧ ∀ g ∈ l, IsSwap g } :=
swapFactorsAux ((@univ α _).sort (· ≤ ·)) f fun {_ _} => (mem_sort _).2 (mem_univ _)
/-- This computably represents the fact that any permutation can be represented as the product of
a list of transpositions. -/
def truncSwapFactors [Fintype α] (f : Perm α) :
Trunc { l : List (Perm α) // l.prod = f ∧ ∀ g ∈ l, IsSwap g } :=
Quotient.recOnSubsingleton (@univ α _).1 (fun l h => Trunc.mk (swapFactorsAux l f (h _)))
(show ∀ x, f x ≠ x → x ∈ (@univ α _).1 from fun _ _ => mem_univ _)
/-- An induction principle for permutations. If `P` holds for the identity permutation, and
is preserved under composition with a non-trivial swap, then `P` holds for all permutations. -/
@[elab_as_elim]
theorem swap_induction_on [Finite α] {motive : Perm α → Prop} (f : Perm α)
(one : motive 1) (swap_mul : ∀ f x y, x ≠ y → motive f → motive (swap x y * f)) : motive f := by
cases nonempty_fintype α
obtain ⟨l, hl⟩ := (truncSwapFactors f).out
induction l generalizing f with
| nil =>
simp only [one, hl.left.symm, List.prod_nil, forall_true_iff]
| cons g l ih =>
rcases hl.2 g (by simp) with ⟨x, y, hxy⟩
rw [← hl.1, List.prod_cons, hxy.2]
exact swap_mul _ _ _ hxy.1 (ih _ ⟨rfl, fun v hv => hl.2 _ (List.mem_cons_of_mem _ hv)⟩)
theorem mclosure_isSwap [Finite α] : Submonoid.closure { σ : Perm α | IsSwap σ } = ⊤ := by
cases nonempty_fintype α
refine top_unique fun x _ ↦ ?_
obtain ⟨h1, h2⟩ := Subtype.mem (truncSwapFactors x).out
rw [← h1]
exact Submonoid.list_prod_mem _ fun y hy ↦ Submonoid.subset_closure (h2 y hy)
theorem closure_isSwap [Finite α] : Subgroup.closure { σ : Perm α | IsSwap σ } = ⊤ :=
Subgroup.closure_eq_top_of_mclosure_eq_top mclosure_isSwap
/-- Every finite symmetric group is generated by transpositions of adjacent elements. -/
theorem mclosure_swap_castSucc_succ (n : ℕ) :
Submonoid.closure (Set.range fun i : Fin n ↦ swap i.castSucc i.succ) = ⊤ := by
apply top_unique
rw [← mclosure_isSwap, Submonoid.closure_le]
rintro _ ⟨i, j, ne, rfl⟩
wlog lt : i < j generalizing i j
· rw [swap_comm]; exact this _ _ ne.symm (ne.lt_or_lt.resolve_left lt)
induction' j using Fin.induction with j ih
· cases lt
have mem : swap j.castSucc j.succ ∈ Submonoid.closure
(Set.range fun (i : Fin n) ↦ swap i.castSucc i.succ) := Submonoid.subset_closure ⟨_, rfl⟩
obtain rfl | lts := (Fin.le_castSucc_iff.mpr lt).eq_or_lt
· exact mem
rw [swap_comm, ← swap_mul_swap_mul_swap (y := Fin.castSucc j) lts.ne lt.ne]
exact mul_mem (mul_mem mem <| ih lts.ne lts) mem
/-- Like `swap_induction_on`, but with the composition on the right of `f`.
An induction principle for permutations. If `motive` holds for the identity permutation, and
is preserved under composition with a non-trivial swap, then `motive` holds for all permutations. -/
@[elab_as_elim]
theorem swap_induction_on' [Finite α] {motive : Perm α → Prop} (f : Perm α) (one : motive 1)
(mul_swap : ∀ f x y, x ≠ y → motive f → motive (f * swap x y)) : motive f :=
inv_inv f ▸ swap_induction_on f⁻¹ one fun f => mul_swap f⁻¹
theorem isConj_swap {w x y z : α} (hwx : w ≠ x) (hyz : y ≠ z) : IsConj (swap w x) (swap y z) :=
isConj_iff.2
(have h :
∀ {y z : α},
y ≠ z → w ≠ z → swap w y * swap x z * swap w x * (swap w y * swap x z)⁻¹ = swap y z :=
fun {y z} hyz hwz => by
rw [mul_inv_rev, swap_inv, swap_inv, mul_assoc (swap w y), mul_assoc (swap w y), ←
mul_assoc _ (swap x z), swap_mul_swap_mul_swap hwx hwz, ← mul_assoc,
swap_mul_swap_mul_swap hwz.symm hyz.symm]
if hwz : w = z then
have hwy : w ≠ y := by rw [hwz]; exact hyz.symm
⟨swap w z * swap x y, by rw [swap_comm y z, h hyz.symm hwy]⟩
else ⟨swap w y * swap x z, h hyz hwz⟩)
/-- set of all pairs (⟨a, b⟩ : Σ a : fin n, fin n) such that b < a -/
def finPairsLT (n : ℕ) : Finset (Σ_ : Fin n, Fin n) :=
(univ : Finset (Fin n)).sigma fun a => (range a).attachFin fun _ hm => (mem_range.1 hm).trans a.2
theorem mem_finPairsLT {n : ℕ} {a : Σ _ : Fin n, Fin n} : a ∈ finPairsLT n ↔ a.2 < a.1 := by
simp only [finPairsLT, Fin.lt_iff_val_lt_val, true_and, mem_attachFin, mem_range, mem_univ,
mem_sigma]
/-- `signAux σ` is the sign of a permutation on `Fin n`, defined as the parity of the number of
pairs `(x₁, x₂)` such that `x₂ < x₁` but `σ x₁ ≤ σ x₂` -/
def signAux {n : ℕ} (a : Perm (Fin n)) : ℤˣ :=
∏ x ∈ finPairsLT n, if a x.1 ≤ a x.2 then -1 else 1
@[simp]
theorem signAux_one (n : ℕ) : signAux (1 : Perm (Fin n)) = 1 := by
unfold signAux
conv => rhs; rw [← @Finset.prod_const_one _ _ (finPairsLT n)]
exact Finset.prod_congr rfl fun a ha => if_neg (mem_finPairsLT.1 ha).not_le
/-- `signBijAux f ⟨a, b⟩` returns the pair consisting of `f a` and `f b` in decreasing order. -/
def signBijAux {n : ℕ} (f : Perm (Fin n)) (a : Σ _ : Fin n, Fin n) : Σ_ : Fin n, Fin n :=
if _ : f a.2 < f a.1 then ⟨f a.1, f a.2⟩ else ⟨f a.2, f a.1⟩
theorem signBijAux_injOn {n : ℕ} {f : Perm (Fin n)} :
(finPairsLT n : Set (Σ _, Fin n)).InjOn (signBijAux f) := by
rintro ⟨a₁, a₂⟩ ha ⟨b₁, b₂⟩ hb h
dsimp [signBijAux] at h
rw [Finset.mem_coe, mem_finPairsLT] at *
have : ¬b₁ < b₂ := hb.le.not_lt
split_ifs at h <;>
simp_all only [not_lt, Sigma.mk.inj_iff, (Equiv.injective f).eq_iff, heq_eq_eq]
· exact absurd this (not_le.mpr ha)
· exact absurd this (not_le.mpr ha)
theorem signBijAux_surj {n : ℕ} {f : Perm (Fin n)} :
∀ a ∈ finPairsLT n, ∃ b ∈ finPairsLT n, signBijAux f b = a :=
fun ⟨a₁, a₂⟩ ha =>
if hxa : f⁻¹ a₂ < f⁻¹ a₁ then
⟨⟨f⁻¹ a₁, f⁻¹ a₂⟩, mem_finPairsLT.2 hxa, by
dsimp [signBijAux]
rw [apply_inv_self, apply_inv_self, if_pos (mem_finPairsLT.1 ha)]⟩
else
⟨⟨f⁻¹ a₂, f⁻¹ a₁⟩,
mem_finPairsLT.2 <|
(le_of_not_gt hxa).lt_of_ne fun h => by
simp [mem_finPairsLT, f⁻¹.injective h, lt_irrefl] at ha, by
dsimp [signBijAux]
rw [apply_inv_self, apply_inv_self, if_neg (mem_finPairsLT.1 ha).le.not_lt]⟩
theorem signBijAux_mem {n : ℕ} {f : Perm (Fin n)} :
∀ a : Σ_ : Fin n, Fin n, a ∈ finPairsLT n → signBijAux f a ∈ finPairsLT n :=
fun ⟨a₁, a₂⟩ ha => by
unfold signBijAux
split_ifs with h
· exact mem_finPairsLT.2 h
· exact mem_finPairsLT.2
((le_of_not_gt h).lt_of_ne fun h => (mem_finPairsLT.1 ha).ne (f.injective h.symm))
@[simp]
theorem signAux_inv {n : ℕ} (f : Perm (Fin n)) : signAux f⁻¹ = signAux f :=
prod_nbij (signBijAux f⁻¹) signBijAux_mem signBijAux_injOn signBijAux_surj fun ⟨a, b⟩ hab ↦
if h : f⁻¹ b < f⁻¹ a then by
simp_all [signBijAux, dif_pos h, if_neg h.not_le, apply_inv_self, apply_inv_self,
if_neg (mem_finPairsLT.1 hab).not_le]
else by
simp_all [signBijAux, if_pos (le_of_not_gt h), dif_neg h, apply_inv_self, apply_inv_self,
if_pos (mem_finPairsLT.1 hab).le]
theorem signAux_mul {n : ℕ} (f g : Perm (Fin n)) : signAux (f * g) = signAux f * signAux g := by
rw [← signAux_inv g]
unfold signAux
rw [← prod_mul_distrib]
refine prod_nbij (signBijAux g) signBijAux_mem signBijAux_injOn signBijAux_surj ?_
rintro ⟨a, b⟩ hab
dsimp only [signBijAux]
rw [mul_apply, mul_apply]
rw [mem_finPairsLT] at hab
by_cases h : g b < g a
· rw [dif_pos h]
simp only [not_le_of_gt hab, mul_one, mul_ite, mul_neg, Perm.inv_apply_self, if_false]
· rw [dif_neg h, inv_apply_self, inv_apply_self, if_pos hab.le]
by_cases h₁ : f (g b) ≤ f (g a)
· have : f (g b) ≠ f (g a) := by
rw [Ne, f.injective.eq_iff, g.injective.eq_iff]
exact ne_of_lt hab
rw [if_pos h₁, if_neg (h₁.lt_of_ne this).not_le]
rfl
· rw [if_neg h₁, if_pos (lt_of_not_ge h₁).le]
rfl
private theorem signAux_swap_zero_one' (n : ℕ) : signAux (swap (0 : Fin (n + 2)) 1) = -1 :=
show _ = ∏ x ∈ {(⟨1, 0⟩ : Σ _ : Fin (n + 2), Fin (n + 2))},
if (Equiv.swap 0 1) x.1 ≤ swap 0 1 x.2 then (-1 : ℤˣ) else 1 by
refine Eq.symm (prod_subset (fun ⟨x₁, x₂⟩ => by
simp +contextual [mem_finPairsLT, Fin.one_pos]) fun a ha₁ ha₂ => ?_)
rcases a with ⟨a₁, a₂⟩
replace ha₁ : a₂ < a₁ := mem_finPairsLT.1 ha₁
dsimp only
rcases a₁.zero_le.eq_or_lt with (rfl | H)
· exact absurd a₂.zero_le ha₁.not_le
rcases a₂.zero_le.eq_or_lt with (rfl | H')
· simp only [and_true, eq_self_iff_true, heq_iff_eq, mem_singleton, Sigma.mk.inj_iff] at ha₂
have : 1 < a₁ := lt_of_le_of_ne (Nat.succ_le_of_lt ha₁)
(Ne.symm (by intro h; apply ha₂; simp [h]))
have h01 : Equiv.swap (0 : Fin (n + 2)) 1 0 = 1 := by simp
rw [swap_apply_of_ne_of_ne (ne_of_gt H) ha₂, h01, if_neg this.not_le]
· have le : 1 ≤ a₂ := Nat.succ_le_of_lt H'
have lt : 1 < a₁ := le.trans_lt ha₁
have h01 : Equiv.swap (0 : Fin (n + 2)) 1 1 = 0 := by simp only [swap_apply_right]
rcases le.eq_or_lt with (rfl | lt')
· rw [swap_apply_of_ne_of_ne H.ne' lt.ne', h01, if_neg H.not_le]
· rw [swap_apply_of_ne_of_ne (ne_of_gt H) (ne_of_gt lt),
swap_apply_of_ne_of_ne (ne_of_gt H') (ne_of_gt lt'), if_neg ha₁.not_le]
private theorem signAux_swap_zero_one {n : ℕ} (hn : 2 ≤ n) :
signAux (swap (⟨0, lt_of_lt_of_le (by decide) hn⟩ : Fin n) ⟨1, lt_of_lt_of_le (by decide) hn⟩) =
-1 := by
rcases n with (_ | _ | n)
· norm_num at hn
· norm_num at hn
· exact signAux_swap_zero_one' n
theorem signAux_swap : ∀ {n : ℕ} {x y : Fin n} (_hxy : x ≠ y), signAux (swap x y) = -1
| 0, x, y => by intro; exact Fin.elim0 x
| 1, x, y => by
dsimp [signAux, swap, swapCore]
simp only [eq_iff_true_of_subsingleton, not_true, ite_true, le_refl, prod_const,
IsEmpty.forall_iff]
| n + 2, x, y => fun hxy => by
have h2n : 2 ≤ n + 2 := by exact le_add_self
rw [← isConj_iff_eq, ← signAux_swap_zero_one h2n]
exact (MonoidHom.mk' signAux signAux_mul).map_isConj
(isConj_swap hxy (by exact of_decide_eq_true rfl))
/-- When the list `l : List α` contains all nonfixed points of the permutation `f : Perm α`,
`signAux2 l f` recursively calculates the sign of `f`. -/
def signAux2 : List α → Perm α → ℤˣ
| [], _ => 1
| x::l, f => if x = f x then signAux2 l f else -signAux2 l (swap x (f x) * f)
|
theorem signAux_eq_signAux2 {n : ℕ} :
∀ (l : List α) (f : Perm α) (e : α ≃ Fin n) (_h : ∀ x, f x ≠ x → x ∈ l),
signAux ((e.symm.trans f).trans e) = signAux2 l f
| [], f, e, h => by
have : f = 1 := Equiv.ext fun y => Classical.not_not.1 (mt (h y) List.not_mem_nil)
rw [this, one_def, Equiv.trans_refl, Equiv.symm_trans_self, ← one_def, signAux_one, signAux2]
| x::l, f, e, h => by
rw [signAux2]
by_cases hfx : x = f x
· rw [if_pos hfx]
| Mathlib/GroupTheory/Perm/Sign.lean | 299 | 309 |
/-
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
-/
import Mathlib.Algebra.Polynomial.Expand
import Mathlib.Algebra.Polynomial.Laurent
import Mathlib.Algebra.Polynomial.Eval.SMul
import Mathlib.LinearAlgebra.Matrix.Charpoly.Basic
import Mathlib.LinearAlgebra.Matrix.Reindex
import Mathlib.RingTheory.Polynomial.Nilpotent
/-!
# Characteristic polynomials
We give methods for computing coefficients of the characteristic polynomial.
## Main definitions
- `Matrix.charpoly_degree_eq_dim` proves that the degree of the characteristic polynomial
over a nonzero ring is the dimension of the matrix
- `Matrix.det_eq_sign_charpoly_coeff` proves that the determinant is the constant term of the
characteristic polynomial, up to sign.
- `Matrix.trace_eq_neg_charpoly_coeff` proves that the trace is the negative of the (d-1)th
coefficient of the characteristic polynomial, where d is the dimension of the matrix.
For a nonzero ring, this is the second-highest coefficient.
- `Matrix.charpolyRev` the reverse of the characteristic polynomial.
- `Matrix.reverse_charpoly` characterises the reverse of the characteristic polynomial.
-/
noncomputable section
universe u v w z
open Finset Matrix Polynomial
variable {R : Type u} [CommRing R]
variable {n G : Type v} [DecidableEq n] [Fintype n]
variable {α β : Type v} [DecidableEq α]
variable {M : Matrix n n R}
namespace Matrix
theorem charmatrix_apply_natDegree [Nontrivial R] (i j : n) :
(charmatrix M i j).natDegree = ite (i = j) 1 0 := by
by_cases h : i = j <;> simp [h, ← degree_eq_iff_natDegree_eq_of_pos (Nat.succ_pos 0)]
theorem charmatrix_apply_natDegree_le (i j : n) :
(charmatrix M i j).natDegree ≤ ite (i = j) 1 0 := by
split_ifs with h <;> simp [h, natDegree_X_le]
variable (M)
theorem charpoly_sub_diagonal_degree_lt :
(M.charpoly - ∏ i : n, (X - C (M i i))).degree < ↑(Fintype.card n - 1) := by
rw [charpoly, det_apply', ← insert_erase (mem_univ (Equiv.refl n)),
sum_insert (not_mem_erase (Equiv.refl n) univ), add_comm]
simp only [charmatrix_apply_eq, one_mul, Equiv.Perm.sign_refl, id, Int.cast_one,
Units.val_one, add_sub_cancel_right, Equiv.coe_refl]
rw [← mem_degreeLT]
apply Submodule.sum_mem (degreeLT R (Fintype.card n - 1))
intro c hc; rw [← C_eq_intCast, C_mul']
apply Submodule.smul_mem (degreeLT R (Fintype.card n - 1)) ↑↑(Equiv.Perm.sign c)
rw [mem_degreeLT]
apply lt_of_le_of_lt degree_le_natDegree _
rw [Nat.cast_lt]
apply lt_of_le_of_lt _ (Equiv.Perm.fixed_point_card_lt_of_ne_one (ne_of_mem_erase hc))
apply le_trans (Polynomial.natDegree_prod_le univ fun i : n => charmatrix M (c i) i) _
rw [card_eq_sum_ones]; rw [sum_filter]; apply sum_le_sum
intros
apply charmatrix_apply_natDegree_le
theorem charpoly_coeff_eq_prod_coeff_of_le {k : ℕ} (h : Fintype.card n - 1 ≤ k) :
M.charpoly.coeff k = (∏ i : n, (X - C (M i i))).coeff k := by
apply eq_of_sub_eq_zero; rw [← coeff_sub]
apply Polynomial.coeff_eq_zero_of_degree_lt
apply lt_of_lt_of_le (charpoly_sub_diagonal_degree_lt M) ?_
rw [Nat.cast_le]; apply h
theorem det_of_card_zero (h : Fintype.card n = 0) (M : Matrix n n R) : M.det = 1 := by
rw [Fintype.card_eq_zero_iff] at h
suffices M = 1 by simp [this]
ext i
exact h.elim i
theorem charpoly_degree_eq_dim [Nontrivial R] (M : Matrix n n R) :
M.charpoly.degree = Fintype.card n := by
by_cases h : Fintype.card n = 0
· rw [h]
unfold charpoly
rw [det_of_card_zero]
· simp
· assumption
| rw [← sub_add_cancel M.charpoly (∏ i : n, (X - C (M i i)))]
-- Porting note: added `↑` in front of `Fintype.card n`
have h1 : (∏ i : n, (X - C (M i i))).degree = ↑(Fintype.card n) := by
rw [degree_eq_iff_natDegree_eq_of_pos (Nat.pos_of_ne_zero h), natDegree_prod']
· simp_rw [natDegree_X_sub_C]
rw [← Finset.card_univ, sum_const, smul_eq_mul, mul_one]
simp_rw [(monic_X_sub_C _).leadingCoeff]
simp
rw [degree_add_eq_right_of_degree_lt]
· exact h1
rw [h1]
apply lt_trans (charpoly_sub_diagonal_degree_lt M)
rw [Nat.cast_lt]
rw [← Nat.pred_eq_sub_one]
apply Nat.pred_lt
apply h
@[simp] theorem charpoly_natDegree_eq_dim [Nontrivial R] (M : Matrix n n R) :
M.charpoly.natDegree = Fintype.card n :=
natDegree_eq_of_degree_eq_some (charpoly_degree_eq_dim M)
theorem charpoly_monic (M : Matrix n n R) : M.charpoly.Monic := by
nontriviality R
by_cases h : Fintype.card n = 0
| Mathlib/LinearAlgebra/Matrix/Charpoly/Coeff.lean | 96 | 119 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes Hölzl, Patrick Massot
-/
import Mathlib.Data.Set.Image
import Mathlib.Data.SProd
/-!
# Sets in product and pi types
This file proves basic properties of product of sets in `α × β` and in `Π i, α i`, and of the
diagonal of a type.
## Main declarations
This file contains basic results on the following notions, which are defined in `Set.Operations`.
* `Set.prod`: Binary product of sets. For `s : Set α`, `t : Set β`, we have
`s.prod t : Set (α × β)`. Denoted by `s ×ˢ t`.
* `Set.diagonal`: Diagonal of a type. `Set.diagonal α = {(x, x) | x : α}`.
* `Set.offDiag`: Off-diagonal. `s ×ˢ s` without the diagonal.
* `Set.pi`: Arbitrary product of sets.
-/
open Function
namespace Set
/-! ### Cartesian binary product of sets -/
section Prod
variable {α β γ δ : Type*} {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {a : α} {b : β}
theorem Subsingleton.prod (hs : s.Subsingleton) (ht : t.Subsingleton) :
(s ×ˢ t).Subsingleton := fun _x hx _y hy ↦
Prod.ext (hs hx.1 hy.1) (ht hx.2 hy.2)
noncomputable instance decidableMemProd [DecidablePred (· ∈ s)] [DecidablePred (· ∈ t)] :
DecidablePred (· ∈ s ×ˢ t) := fun x => inferInstanceAs (Decidable (x.1 ∈ s ∧ x.2 ∈ t))
@[gcongr]
theorem prod_mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : s₁ ×ˢ t₁ ⊆ s₂ ×ˢ t₂ :=
fun _ ⟨h₁, h₂⟩ => ⟨hs h₁, ht h₂⟩
@[gcongr]
theorem prod_mono_left (hs : s₁ ⊆ s₂) : s₁ ×ˢ t ⊆ s₂ ×ˢ t :=
prod_mono hs Subset.rfl
@[gcongr]
theorem prod_mono_right (ht : t₁ ⊆ t₂) : s ×ˢ t₁ ⊆ s ×ˢ t₂ :=
prod_mono Subset.rfl ht
@[simp]
theorem prod_self_subset_prod_self : s₁ ×ˢ s₁ ⊆ s₂ ×ˢ s₂ ↔ s₁ ⊆ s₂ :=
⟨fun h _ hx => (h (mk_mem_prod hx hx)).1, fun h _ hx => ⟨h hx.1, h hx.2⟩⟩
@[simp]
theorem prod_self_ssubset_prod_self : s₁ ×ˢ s₁ ⊂ s₂ ×ˢ s₂ ↔ s₁ ⊂ s₂ :=
and_congr prod_self_subset_prod_self <| not_congr prod_self_subset_prod_self
theorem prod_subset_iff {P : Set (α × β)} : s ×ˢ t ⊆ P ↔ ∀ x ∈ s, ∀ y ∈ t, (x, y) ∈ P :=
⟨fun h _ hx _ hy => h (mk_mem_prod hx hy), fun h ⟨_, _⟩ hp => h _ hp.1 _ hp.2⟩
theorem forall_prod_set {p : α × β → Prop} : (∀ x ∈ s ×ˢ t, p x) ↔ ∀ x ∈ s, ∀ y ∈ t, p (x, y) :=
prod_subset_iff
theorem exists_prod_set {p : α × β → Prop} : (∃ x ∈ s ×ˢ t, p x) ↔ ∃ x ∈ s, ∃ y ∈ t, p (x, y) := by
simp [and_assoc]
@[simp]
theorem prod_empty : s ×ˢ (∅ : Set β) = ∅ := by
ext
exact iff_of_eq (and_false _)
@[simp]
theorem empty_prod : (∅ : Set α) ×ˢ t = ∅ := by
ext
exact iff_of_eq (false_and _)
@[simp, mfld_simps]
theorem univ_prod_univ : @univ α ×ˢ @univ β = univ := by
ext
exact iff_of_eq (true_and _)
theorem univ_prod {t : Set β} : (univ : Set α) ×ˢ t = Prod.snd ⁻¹' t := by simp [prod_eq]
theorem prod_univ {s : Set α} : s ×ˢ (univ : Set β) = Prod.fst ⁻¹' s := by simp [prod_eq]
@[simp] lemma prod_eq_univ [Nonempty α] [Nonempty β] : s ×ˢ t = univ ↔ s = univ ∧ t = univ := by
simp [eq_univ_iff_forall, forall_and]
theorem singleton_prod : ({a} : Set α) ×ˢ t = Prod.mk a '' t := by
ext ⟨x, y⟩
simp [and_left_comm, eq_comm]
theorem prod_singleton : s ×ˢ ({b} : Set β) = (fun a => (a, b)) '' s := by
ext ⟨x, y⟩
simp [and_left_comm, eq_comm]
@[simp]
theorem singleton_prod_singleton : ({a} : Set α) ×ˢ ({b} : Set β) = {(a, b)} := by ext ⟨c, d⟩; simp
@[simp]
theorem union_prod : (s₁ ∪ s₂) ×ˢ t = s₁ ×ˢ t ∪ s₂ ×ˢ t := by
ext ⟨x, y⟩
simp [or_and_right]
@[simp]
theorem prod_union : s ×ˢ (t₁ ∪ t₂) = s ×ˢ t₁ ∪ s ×ˢ t₂ := by
ext ⟨x, y⟩
simp [and_or_left]
theorem inter_prod : (s₁ ∩ s₂) ×ˢ t = s₁ ×ˢ t ∩ s₂ ×ˢ t := by
ext ⟨x, y⟩
simp only [← and_and_right, mem_inter_iff, mem_prod]
theorem prod_inter : s ×ˢ (t₁ ∩ t₂) = s ×ˢ t₁ ∩ s ×ˢ t₂ := by
ext ⟨x, y⟩
simp only [← and_and_left, mem_inter_iff, mem_prod]
@[mfld_simps]
theorem prod_inter_prod : s₁ ×ˢ t₁ ∩ s₂ ×ˢ t₂ = (s₁ ∩ s₂) ×ˢ (t₁ ∩ t₂) := by
ext ⟨x, y⟩
simp [and_assoc, and_left_comm]
lemma compl_prod_eq_union {α β : Type*} (s : Set α) (t : Set β) :
(s ×ˢ t)ᶜ = (sᶜ ×ˢ univ) ∪ (univ ×ˢ tᶜ) := by
ext p
simp only [mem_compl_iff, mem_prod, not_and, mem_union, mem_univ, and_true, true_and]
constructor <;> intro h
· by_cases fst_in_s : p.fst ∈ s
· exact Or.inr (h fst_in_s)
· exact Or.inl fst_in_s
· intro fst_in_s
simpa only [fst_in_s, not_true, false_or] using h
@[simp]
theorem disjoint_prod : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) ↔ Disjoint s₁ s₂ ∨ Disjoint t₁ t₂ := by
simp_rw [disjoint_left, mem_prod, not_and_or, Prod.forall, and_imp, ← @forall_or_right α, ←
@forall_or_left β, ← @forall_or_right (_ ∈ s₁), ← @forall_or_left (_ ∈ t₁)]
theorem Disjoint.set_prod_left (hs : Disjoint s₁ s₂) (t₁ t₂ : Set β) :
Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) :=
disjoint_left.2 fun ⟨_a, _b⟩ ⟨ha₁, _⟩ ⟨ha₂, _⟩ => disjoint_left.1 hs ha₁ ha₂
theorem Disjoint.set_prod_right (ht : Disjoint t₁ t₂) (s₁ s₂ : Set α) :
Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) :=
disjoint_left.2 fun ⟨_a, _b⟩ ⟨_, hb₁⟩ ⟨_, hb₂⟩ => disjoint_left.1 ht hb₁ hb₂
theorem prodMap_image_prod (f : α → β) (g : γ → δ) (s : Set α) (t : Set γ) :
(Prod.map f g) '' (s ×ˢ t) = (f '' s) ×ˢ (g '' t) := by
ext
aesop
theorem insert_prod : insert a s ×ˢ t = Prod.mk a '' t ∪ s ×ˢ t := by
simp only [insert_eq, union_prod, singleton_prod]
theorem prod_insert : s ×ˢ insert b t = (fun a => (a, b)) '' s ∪ s ×ˢ t := by
simp only [insert_eq, prod_union, prod_singleton]
theorem prod_preimage_eq {f : γ → α} {g : δ → β} :
(f ⁻¹' s) ×ˢ (g ⁻¹' t) = (fun p : γ × δ => (f p.1, g p.2)) ⁻¹' s ×ˢ t :=
rfl
theorem prod_preimage_left {f : γ → α} :
(f ⁻¹' s) ×ˢ t = (fun p : γ × β => (f p.1, p.2)) ⁻¹' s ×ˢ t :=
rfl
theorem prod_preimage_right {g : δ → β} :
s ×ˢ (g ⁻¹' t) = (fun p : α × δ => (p.1, g p.2)) ⁻¹' s ×ˢ t :=
rfl
theorem preimage_prod_map_prod (f : α → β) (g : γ → δ) (s : Set β) (t : Set δ) :
Prod.map f g ⁻¹' s ×ˢ t = (f ⁻¹' s) ×ˢ (g ⁻¹' t) :=
rfl
|
theorem mk_preimage_prod (f : γ → α) (g : γ → β) :
(fun x => (f x, g x)) ⁻¹' s ×ˢ t = f ⁻¹' s ∩ g ⁻¹' t :=
| Mathlib/Data/Set/Prod.lean | 180 | 182 |
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Set.NAry
import Mathlib.Order.SupClosed
import Mathlib.Order.UpperLower.Closure
/-!
# Set family operations
This file defines a few binary operations on `Set α` for use in set family combinatorics.
## Main declarations
* `s ⊻ t`: Set of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t`.
* `s ⊼ t`: Set of elements of the form `a ⊓ b` where `a ∈ s`, `b ∈ t`.
## Notation
We define the following notation in locale `SetFamily`:
* `s ⊻ t`
* `s ⊼ t`
## References
[B. Bollobás, *Combinatorics*][bollobas1986]
-/
open Function
variable {F α β : Type*}
/-- Notation typeclass for pointwise supremum `⊻`. -/
class HasSups (α : Type*) where
/-- The point-wise supremum `a ⊔ b` of `a, b : α`. -/
sups : α → α → α
/-- Notation typeclass for pointwise infimum `⊼`. -/
class HasInfs (α : Type*) where
/-- The point-wise infimum `a ⊓ b` of `a, b : α`. -/
infs : α → α → α
-- This notation is meant to have higher precedence than `⊔` and `⊓`, but still within the
-- realm of other binary notation.
@[inherit_doc]
infixl:74 " ⊻ " => HasSups.sups
@[inherit_doc]
infixl:75 " ⊼ " => HasInfs.infs
namespace Set
section Sups
variable [SemilatticeSup α] [SemilatticeSup β] [FunLike F α β] [SupHomClass F α β]
variable (s s₁ s₂ t t₁ t₂ u v : Set α)
/-- `s ⊻ t` is the set of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t`. -/
protected def hasSups : HasSups (Set α) :=
⟨image2 (· ⊔ ·)⟩
scoped[SetFamily] attribute [instance] Set.hasSups
open SetFamily
variable {s s₁ s₂ t t₁ t₂ u} {a b c : α}
@[simp]
theorem mem_sups : c ∈ s ⊻ t ↔ ∃ a ∈ s, ∃ b ∈ t, a ⊔ b = c := by simp [(· ⊻ ·)]
theorem sup_mem_sups : a ∈ s → b ∈ t → a ⊔ b ∈ s ⊻ t :=
mem_image2_of_mem
theorem sups_subset : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ ⊻ t₁ ⊆ s₂ ⊻ t₂ :=
image2_subset
theorem sups_subset_left : t₁ ⊆ t₂ → s ⊻ t₁ ⊆ s ⊻ t₂ :=
image2_subset_left
theorem sups_subset_right : s₁ ⊆ s₂ → s₁ ⊻ t ⊆ s₂ ⊻ t :=
image2_subset_right
theorem image_subset_sups_left : b ∈ t → (fun a => a ⊔ b) '' s ⊆ s ⊻ t :=
image_subset_image2_left
theorem image_subset_sups_right : a ∈ s → (· ⊔ ·) a '' t ⊆ s ⊻ t :=
image_subset_image2_right
theorem forall_sups_iff {p : α → Prop} : (∀ c ∈ s ⊻ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, p (a ⊔ b) :=
forall_mem_image2
@[simp]
theorem sups_subset_iff : s ⊻ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a ⊔ b ∈ u :=
image2_subset_iff
@[simp]
theorem sups_nonempty : (s ⊻ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty :=
image2_nonempty_iff
protected theorem Nonempty.sups : s.Nonempty → t.Nonempty → (s ⊻ t).Nonempty :=
Nonempty.image2
theorem Nonempty.of_sups_left : (s ⊻ t).Nonempty → s.Nonempty :=
Nonempty.of_image2_left
theorem Nonempty.of_sups_right : (s ⊻ t).Nonempty → t.Nonempty :=
Nonempty.of_image2_right
@[simp]
theorem empty_sups : ∅ ⊻ t = ∅ :=
image2_empty_left
@[simp]
theorem sups_empty : s ⊻ ∅ = ∅ :=
image2_empty_right
@[simp]
theorem sups_eq_empty : s ⊻ t = ∅ ↔ s = ∅ ∨ t = ∅ :=
image2_eq_empty_iff
@[simp]
theorem singleton_sups : {a} ⊻ t = t.image fun b => a ⊔ b :=
image2_singleton_left
@[simp]
theorem sups_singleton : s ⊻ {b} = s.image fun a => a ⊔ b :=
image2_singleton_right
theorem singleton_sups_singleton : ({a} ⊻ {b} : Set α) = {a ⊔ b} :=
image2_singleton
theorem sups_union_left : (s₁ ∪ s₂) ⊻ t = s₁ ⊻ t ∪ s₂ ⊻ t :=
image2_union_left
theorem sups_union_right : s ⊻ (t₁ ∪ t₂) = s ⊻ t₁ ∪ s ⊻ t₂ :=
image2_union_right
theorem sups_inter_subset_left : (s₁ ∩ s₂) ⊻ t ⊆ s₁ ⊻ t ∩ s₂ ⊻ t :=
image2_inter_subset_left
theorem sups_inter_subset_right : s ⊻ (t₁ ∩ t₂) ⊆ s ⊻ t₁ ∩ s ⊻ t₂ :=
image2_inter_subset_right
lemma image_sups (f : F) (s t : Set α) : f '' (s ⊻ t) = f '' s ⊻ f '' t :=
image_image2_distrib <| map_sup f
lemma subset_sups_self : s ⊆ s ⊻ s := fun _a ha ↦ mem_sups.2 ⟨_, ha, _, ha, sup_idem _⟩
lemma sups_subset_self : s ⊻ s ⊆ s ↔ SupClosed s := sups_subset_iff
@[simp] lemma sups_eq_self : s ⊻ s = s ↔ SupClosed s :=
subset_sups_self.le.le_iff_eq.symm.trans sups_subset_self
lemma sep_sups_le (s t : Set α) (a : α) :
{b ∈ s ⊻ t | b ≤ a} = {b ∈ s | b ≤ a} ⊻ {b ∈ t | b ≤ a} := by ext; aesop
variable (s t u)
theorem iUnion_image_sup_left : ⋃ a ∈ s, (· ⊔ ·) a '' t = s ⊻ t :=
iUnion_image_left _
theorem iUnion_image_sup_right : ⋃ b ∈ t, (· ⊔ b) '' s = s ⊻ t :=
iUnion_image_right _
@[simp]
theorem image_sup_prod (s t : Set α) : Set.image2 (· ⊔ ·) s t = s ⊻ t := rfl
theorem sups_assoc : s ⊻ t ⊻ u = s ⊻ (t ⊻ u) := image2_assoc sup_assoc
theorem sups_comm : s ⊻ t = t ⊻ s := image2_comm sup_comm
theorem sups_left_comm : s ⊻ (t ⊻ u) = t ⊻ (s ⊻ u) :=
image2_left_comm sup_left_comm
theorem sups_right_comm : s ⊻ t ⊻ u = s ⊻ u ⊻ t :=
image2_right_comm sup_right_comm
theorem sups_sups_sups_comm : s ⊻ t ⊻ (u ⊻ v) = s ⊻ u ⊻ (t ⊻ v) :=
image2_image2_image2_comm sup_sup_sup_comm
end Sups
section Infs
variable [SemilatticeInf α] [SemilatticeInf β] [FunLike F α β] [InfHomClass F α β]
variable (s s₁ s₂ t t₁ t₂ u v : Set α)
/-- `s ⊼ t` is the set of elements of the form `a ⊓ b` where `a ∈ s`, `b ∈ t`. -/
protected def hasInfs : HasInfs (Set α) :=
⟨image2 (· ⊓ ·)⟩
scoped[SetFamily] attribute [instance] Set.hasInfs
open SetFamily
variable {s s₁ s₂ t t₁ t₂ u} {a b c : α}
@[simp]
theorem mem_infs : c ∈ s ⊼ t ↔ ∃ a ∈ s, ∃ b ∈ t, a ⊓ b = c := by simp [(· ⊼ ·)]
theorem inf_mem_infs : a ∈ s → b ∈ t → a ⊓ b ∈ s ⊼ t :=
mem_image2_of_mem
theorem infs_subset : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ ⊼ t₁ ⊆ s₂ ⊼ t₂ :=
image2_subset
theorem infs_subset_left : t₁ ⊆ t₂ → s ⊼ t₁ ⊆ s ⊼ t₂ :=
image2_subset_left
theorem infs_subset_right : s₁ ⊆ s₂ → s₁ ⊼ t ⊆ s₂ ⊼ t :=
image2_subset_right
theorem image_subset_infs_left : b ∈ t → (fun a => a ⊓ b) '' s ⊆ s ⊼ t :=
image_subset_image2_left
theorem image_subset_infs_right : a ∈ s → (a ⊓ ·) '' t ⊆ s ⊼ t :=
image_subset_image2_right
theorem forall_infs_iff {p : α → Prop} : (∀ c ∈ s ⊼ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, p (a ⊓ b) :=
forall_mem_image2
@[simp]
theorem infs_subset_iff : s ⊼ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a ⊓ b ∈ u :=
image2_subset_iff
@[simp]
theorem infs_nonempty : (s ⊼ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty :=
image2_nonempty_iff
protected theorem Nonempty.infs : s.Nonempty → t.Nonempty → (s ⊼ t).Nonempty :=
Nonempty.image2
theorem Nonempty.of_infs_left : (s ⊼ t).Nonempty → s.Nonempty :=
Nonempty.of_image2_left
theorem Nonempty.of_infs_right : (s ⊼ t).Nonempty → t.Nonempty :=
Nonempty.of_image2_right
@[simp]
theorem empty_infs : ∅ ⊼ t = ∅ :=
image2_empty_left
@[simp]
theorem infs_empty : s ⊼ ∅ = ∅ :=
image2_empty_right
@[simp]
theorem infs_eq_empty : s ⊼ t = ∅ ↔ s = ∅ ∨ t = ∅ :=
image2_eq_empty_iff
@[simp]
theorem singleton_infs : {a} ⊼ t = t.image fun b => a ⊓ b :=
image2_singleton_left
@[simp]
theorem infs_singleton : s ⊼ {b} = s.image fun a => a ⊓ b :=
image2_singleton_right
theorem singleton_infs_singleton : ({a} ⊼ {b} : Set α) = {a ⊓ b} :=
image2_singleton
theorem infs_union_left : (s₁ ∪ s₂) ⊼ t = s₁ ⊼ t ∪ s₂ ⊼ t :=
image2_union_left
theorem infs_union_right : s ⊼ (t₁ ∪ t₂) = s ⊼ t₁ ∪ s ⊼ t₂ :=
image2_union_right
theorem infs_inter_subset_left : (s₁ ∩ s₂) ⊼ t ⊆ s₁ ⊼ t ∩ s₂ ⊼ t :=
image2_inter_subset_left
theorem infs_inter_subset_right : s ⊼ (t₁ ∩ t₂) ⊆ s ⊼ t₁ ∩ s ⊼ t₂ :=
image2_inter_subset_right
lemma image_infs (f : F) (s t : Set α) : f '' (s ⊼ t) = f '' s ⊼ f '' t :=
image_image2_distrib <| map_inf f
lemma subset_infs_self : s ⊆ s ⊼ s := fun _a ha ↦ mem_infs.2 ⟨_, ha, _, ha, inf_idem _⟩
lemma infs_self_subset : s ⊼ s ⊆ s ↔ InfClosed s := infs_subset_iff
@[simp] lemma infs_self : s ⊼ s = s ↔ InfClosed s :=
subset_infs_self.le.le_iff_eq.symm.trans infs_self_subset
lemma sep_infs_le (s t : Set α) (a : α) :
{b ∈ s ⊼ t | a ≤ b} = {b ∈ s | a ≤ b} ⊼ {b ∈ t | a ≤ b} := by ext; aesop
variable (s t u)
theorem iUnion_image_inf_left : ⋃ a ∈ s, (a ⊓ ·) '' t = s ⊼ t :=
iUnion_image_left _
theorem iUnion_image_inf_right : ⋃ b ∈ t, (· ⊓ b) '' s = s ⊼ t :=
iUnion_image_right _
@[simp]
theorem image_inf_prod (s t : Set α) : Set.image2 (fun x x_1 => x ⊓ x_1) s t = s ⊼ t := by
have : (s ×ˢ t).image (uncurry (· ⊓ ·)) = Set.image2 (fun x x_1 => x ⊓ x_1) s t := by
simp only [Set.image_uncurry_prod]
rw [← this]
exact image_uncurry_prod _ _ _
theorem infs_assoc : s ⊼ t ⊼ u = s ⊼ (t ⊼ u) := image2_assoc inf_assoc
theorem infs_comm : s ⊼ t = t ⊼ s := image2_comm inf_comm
theorem infs_left_comm : s ⊼ (t ⊼ u) = t ⊼ (s ⊼ u) :=
image2_left_comm inf_left_comm
theorem infs_right_comm : s ⊼ t ⊼ u = s ⊼ u ⊼ t :=
image2_right_comm inf_right_comm
theorem infs_infs_infs_comm : s ⊼ t ⊼ (u ⊼ v) = s ⊼ u ⊼ (t ⊼ v) :=
image2_image2_image2_comm inf_inf_inf_comm
end Infs
open SetFamily
section DistribLattice
variable [DistribLattice α] (s t u : Set α)
theorem sups_infs_subset_left : s ⊻ t ⊼ u ⊆ (s ⊻ t) ⊼ (s ⊻ u) :=
image2_distrib_subset_left sup_inf_left
theorem sups_infs_subset_right : t ⊼ u ⊻ s ⊆ (t ⊻ s) ⊼ (u ⊻ s) :=
image2_distrib_subset_right sup_inf_right
theorem infs_sups_subset_left : s ⊼ (t ⊻ u) ⊆ s ⊼ t ⊻ s ⊼ u :=
image2_distrib_subset_left inf_sup_left
theorem infs_sups_subset_right : (t ⊻ u) ⊼ s ⊆ t ⊼ s ⊻ u ⊼ s :=
image2_distrib_subset_right inf_sup_right
end DistribLattice
end Set
open SetFamily
@[simp]
theorem upperClosure_sups [SemilatticeSup α] (s t : Set α) :
upperClosure (s ⊻ t) = upperClosure s ⊔ upperClosure t := by
ext a
simp only [SetLike.mem_coe, mem_upperClosure, Set.mem_sups, exists_and_left, exists_prop,
UpperSet.coe_sup, Set.mem_inter_iff]
constructor
· rintro ⟨_, ⟨b, hb, c, hc, rfl⟩, ha⟩
exact ⟨⟨b, hb, le_sup_left.trans ha⟩, c, hc, le_sup_right.trans ha⟩
· rintro ⟨⟨b, hb, hab⟩, c, hc, hac⟩
exact ⟨_, ⟨b, hb, c, hc, rfl⟩, sup_le hab hac⟩
@[simp]
theorem lowerClosure_infs [SemilatticeInf α] (s t : Set α) :
lowerClosure (s ⊼ t) = lowerClosure s ⊓ lowerClosure t := by
ext a
simp only [SetLike.mem_coe, mem_lowerClosure, Set.mem_infs, exists_and_left, exists_prop,
LowerSet.coe_sup, Set.mem_inter_iff]
constructor
· rintro ⟨_, ⟨b, hb, c, hc, rfl⟩, ha⟩
exact ⟨⟨b, hb, ha.trans inf_le_left⟩, c, hc, ha.trans inf_le_right⟩
· rintro ⟨⟨b, hb, hab⟩, c, hc, hac⟩
exact ⟨_, ⟨b, hb, c, hc, rfl⟩, le_inf hab hac⟩
| Mathlib/Data/Set/Sups.lean | 429 | 438 | |
/-
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.RCLike.Basic
import Mathlib.Data.Complex.BigOperators
import Mathlib.Data.Complex.Module
import Mathlib.Data.Complex.Order
import Mathlib.Topology.Algebra.InfiniteSum.Field
import Mathlib.Topology.Algebra.InfiniteSum.Module
import Mathlib.Topology.Instances.RealVectorSpace
import Mathlib.Topology.MetricSpace.ProperSpace.Real
/-!
# Normed space structure on `ℂ`.
This file gathers basic facts of analytic nature on the complex numbers.
## Main results
This file registers `ℂ` as a normed field, expresses basic properties of the norm, and gives tools
on the real vector space structure of `ℂ`. Notably, it defines the following functions in the
namespace `Complex`.
|Name |Type |Description |
|------------------|-------------|--------------------------------------------------------|
|`equivRealProdCLM`|ℂ ≃L[ℝ] ℝ × ℝ|The natural `ContinuousLinearEquiv` from `ℂ` to `ℝ × ℝ` |
|`reCLM` |ℂ →L[ℝ] ℝ |Real part function as a `ContinuousLinearMap` |
|`imCLM` |ℂ →L[ℝ] ℝ |Imaginary part function as a `ContinuousLinearMap` |
|`ofRealCLM` |ℝ →L[ℝ] ℂ |Embedding of the reals as a `ContinuousLinearMap` |
|`ofRealLI` |ℝ →ₗᵢ[ℝ] ℂ |Embedding of the reals as a `LinearIsometry` |
|`conjCLE` |ℂ ≃L[ℝ] ℂ |Complex conjugation as a `ContinuousLinearEquiv` |
|`conjLIE` |ℂ ≃ₗᵢ[ℝ] ℂ |Complex conjugation as a `LinearIsometryEquiv` |
We also register the fact that `ℂ` is an `RCLike` field.
-/
assert_not_exists Absorbs
noncomputable section
namespace Complex
variable {z : ℂ}
open ComplexConjugate Topology Filter
instance : NormedField ℂ where
dist_eq _ _ := rfl
norm_mul := Complex.norm_mul
instance : DenselyNormedField ℂ where
lt_norm_lt r₁ r₂ h₀ hr :=
let ⟨x, h⟩ := exists_between hr
⟨x, by rwa [norm_real, Real.norm_of_nonneg (h₀.trans_lt h.1).le]⟩
instance {R : Type*} [NormedField R] [NormedAlgebra R ℝ] : NormedAlgebra R ℂ where
norm_smul_le r x := by
rw [← algebraMap_smul ℝ r x, real_smul, norm_mul, norm_real, norm_algebraMap']
variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ℂ E]
-- see Note [lower instance priority]
/-- The module structure from `Module.complexToReal` is a normed space. -/
instance (priority := 900) _root_.NormedSpace.complexToReal : NormedSpace ℝ E :=
NormedSpace.restrictScalars ℝ ℂ E
-- see Note [lower instance priority]
/-- The algebra structure from `Algebra.complexToReal` is a normed algebra. -/
instance (priority := 900) _root_.NormedAlgebra.complexToReal {A : Type*} [SeminormedRing A]
[NormedAlgebra ℂ A] : NormedAlgebra ℝ A :=
NormedAlgebra.restrictScalars ℝ ℂ A
-- This result cannot be moved to `Data/Complex/Norm` since `ℤ` gets its norm from its
-- normed ring structure and that file does not know about rings
@[simp 1100, norm_cast] lemma nnnorm_intCast (n : ℤ) : ‖(n : ℂ)‖₊ = ‖n‖₊ := by
ext; exact norm_intCast n
@[deprecated (since := "2025-02-16")] alias comap_abs_nhds_zero := comap_norm_nhds_zero
@[deprecated (since := "2025-02-16")] alias continuous_abs := continuous_norm
@[continuity, fun_prop]
theorem continuous_normSq : Continuous normSq := by
simpa [← Complex.normSq_eq_norm_sq] using continuous_norm (E := ℂ).pow 2
theorem nnnorm_eq_one_of_pow_eq_one {ζ : ℂ} {n : ℕ} (h : ζ ^ n = 1) (hn : n ≠ 0) : ‖ζ‖₊ = 1 :=
(pow_left_inj₀ zero_le' zero_le' hn).1 <| by rw [← nnnorm_pow, h, nnnorm_one, one_pow]
theorem norm_eq_one_of_pow_eq_one {ζ : ℂ} {n : ℕ} (h : ζ ^ n = 1) (hn : n ≠ 0) : ‖ζ‖ = 1 :=
congr_arg Subtype.val (nnnorm_eq_one_of_pow_eq_one h hn)
lemma le_of_eq_sum_of_eq_sum_norm {ι : Type*} {a b : ℝ} (f : ι → ℂ) (s : Finset ι) (ha₀ : 0 ≤ a)
(ha : a = ∑ i ∈ s, f i) (hb : b = ∑ i ∈ s, (‖f i‖ : ℂ)) : a ≤ b := by
norm_cast at hb; rw [← Complex.norm_of_nonneg ha₀, ha, hb]; exact norm_sum_le s f
theorem equivRealProd_apply_le (z : ℂ) : ‖equivRealProd z‖ ≤ ‖z‖ := by
simp [Prod.norm_def, abs_re_le_norm, abs_im_le_norm]
theorem equivRealProd_apply_le' (z : ℂ) : ‖equivRealProd z‖ ≤ 1 * ‖z‖ := by
simpa using equivRealProd_apply_le z
theorem lipschitz_equivRealProd : LipschitzWith 1 equivRealProd := by
simpa using AddMonoidHomClass.lipschitz_of_bound equivRealProdLm 1 equivRealProd_apply_le'
theorem antilipschitz_equivRealProd : AntilipschitzWith (NNReal.sqrt 2) equivRealProd :=
AddMonoidHomClass.antilipschitz_of_bound equivRealProdLm fun z ↦ by
simpa only [Real.coe_sqrt, NNReal.coe_ofNat] using norm_le_sqrt_two_mul_max z
theorem isUniformEmbedding_equivRealProd : IsUniformEmbedding equivRealProd :=
antilipschitz_equivRealProd.isUniformEmbedding lipschitz_equivRealProd.uniformContinuous
instance : CompleteSpace ℂ :=
(completeSpace_congr isUniformEmbedding_equivRealProd).mpr inferInstance
instance instT2Space : T2Space ℂ := TopologicalSpace.t2Space_of_metrizableSpace
/-- The natural `ContinuousLinearEquiv` from `ℂ` to `ℝ × ℝ`. -/
@[simps! +simpRhs apply symm_apply_re symm_apply_im]
def equivRealProdCLM : ℂ ≃L[ℝ] ℝ × ℝ :=
equivRealProdLm.toContinuousLinearEquivOfBounds 1 (√2) equivRealProd_apply_le' fun p =>
norm_le_sqrt_two_mul_max (equivRealProd.symm p)
theorem equivRealProdCLM_symm_apply (p : ℝ × ℝ) :
Complex.equivRealProdCLM.symm p = p.1 + p.2 * Complex.I := Complex.equivRealProd_symm_apply p
instance : ProperSpace ℂ := lipschitz_equivRealProd.properSpace
equivRealProdCLM.toHomeomorph.isProperMap
@[deprecated (since := "2025-02-16")] alias tendsto_abs_cocompact_atTop :=
tendsto_norm_cocompact_atTop
/-- The `normSq` function on `ℂ` is proper. -/
theorem tendsto_normSq_cocompact_atTop : Tendsto normSq (cocompact ℂ) atTop := by
simpa [norm_mul_self_eq_normSq]
using tendsto_norm_cocompact_atTop.atTop_mul_atTop₀ (tendsto_norm_cocompact_atTop (E := ℂ))
open ContinuousLinearMap
/-- Continuous linear map version of the real part function, from `ℂ` to `ℝ`. -/
def reCLM : ℂ →L[ℝ] ℝ :=
reLm.mkContinuous 1 fun x => by simp [abs_re_le_norm]
@[continuity, fun_prop]
theorem continuous_re : Continuous re :=
reCLM.continuous
lemma uniformlyContinuous_re : UniformContinuous re :=
reCLM.uniformContinuous
@[deprecated (since := "2024-11-04")] alias uniformlyContinous_re := uniformlyContinuous_re
@[simp]
theorem reCLM_coe : (reCLM : ℂ →ₗ[ℝ] ℝ) = reLm :=
rfl
@[simp]
theorem reCLM_apply (z : ℂ) : (reCLM : ℂ → ℝ) z = z.re :=
rfl
/-- Continuous linear map version of the imaginary part function, from `ℂ` to `ℝ`. -/
def imCLM : ℂ →L[ℝ] ℝ :=
imLm.mkContinuous 1 fun x => by simp [abs_im_le_norm]
@[continuity, fun_prop]
theorem continuous_im : Continuous im :=
imCLM.continuous
lemma uniformlyContinuous_im : UniformContinuous im :=
imCLM.uniformContinuous
@[deprecated (since := "2024-11-04")] alias uniformlyContinous_im := uniformlyContinuous_im
@[simp]
theorem imCLM_coe : (imCLM : ℂ →ₗ[ℝ] ℝ) = imLm :=
rfl
@[simp]
theorem imCLM_apply (z : ℂ) : (imCLM : ℂ → ℝ) z = z.im :=
rfl
theorem restrictScalars_one_smulRight' (x : E) :
ContinuousLinearMap.restrictScalars ℝ ((1 : ℂ →L[ℂ] ℂ).smulRight x : ℂ →L[ℂ] E) =
reCLM.smulRight x + I • imCLM.smulRight x := by
ext ⟨a, b⟩
simp [map_add, mk_eq_add_mul_I, mul_smul, smul_comm I b x]
theorem restrictScalars_one_smulRight (x : ℂ) :
ContinuousLinearMap.restrictScalars ℝ ((1 : ℂ →L[ℂ] ℂ).smulRight x : ℂ →L[ℂ] ℂ) =
x • (1 : ℂ →L[ℝ] ℂ) := by
ext1 z
dsimp
apply mul_comm
/-- The complex-conjugation function from `ℂ` to itself is an isometric linear equivalence. -/
def conjLIE : ℂ ≃ₗᵢ[ℝ] ℂ :=
⟨conjAe.toLinearEquiv, norm_conj⟩
@[simp]
theorem conjLIE_apply (z : ℂ) : conjLIE z = conj z :=
rfl
@[simp]
theorem conjLIE_symm : conjLIE.symm = conjLIE :=
rfl
theorem isometry_conj : Isometry (conj : ℂ → ℂ) :=
conjLIE.isometry
@[simp]
theorem dist_conj_conj (z w : ℂ) : dist (conj z) (conj w) = dist z w :=
isometry_conj.dist_eq z w
@[simp]
theorem nndist_conj_conj (z w : ℂ) : nndist (conj z) (conj w) = nndist z w :=
isometry_conj.nndist_eq z w
theorem dist_conj_comm (z w : ℂ) : dist (conj z) w = dist z (conj w) := by
rw [← dist_conj_conj, conj_conj]
theorem nndist_conj_comm (z w : ℂ) : nndist (conj z) w = nndist z (conj w) :=
Subtype.ext <| dist_conj_comm _ _
instance : ContinuousStar ℂ :=
⟨conjLIE.continuous⟩
|
@[continuity]
| Mathlib/Analysis/Complex/Basic.lean | 228 | 229 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Topology.Algebra.Constructions
import Mathlib.Topology.Bases
import Mathlib.Algebra.Order.Group.Nat
import Mathlib.Topology.UniformSpace.Basic
/-!
# Theory of Cauchy filters in uniform spaces. Complete uniform spaces. Totally bounded subsets.
-/
universe u v
open Filter Function TopologicalSpace Topology Set UniformSpace Uniformity
variable {α : Type u} {β : Type v} [uniformSpace : UniformSpace α]
/-- A filter `f` is Cauchy if for every entourage `r`, there exists an
`s ∈ f` such that `s × s ⊆ r`. This is a generalization of Cauchy
sequences, because if `a : ℕ → α` then the filter of sets containing
cofinitely many of the `a n` is Cauchy iff `a` is a Cauchy sequence. -/
def Cauchy (f : Filter α) :=
NeBot f ∧ f ×ˢ f ≤ 𝓤 α
/-- A set `s` is called *complete*, if any Cauchy filter `f` such that `s ∈ f`
has a limit in `s` (formally, it satisfies `f ≤ 𝓝 x` for some `x ∈ s`). -/
def IsComplete (s : Set α) :=
∀ f, Cauchy f → f ≤ 𝓟 s → ∃ x ∈ s, f ≤ 𝓝 x
theorem Filter.HasBasis.cauchy_iff {ι} {p : ι → Prop} {s : ι → Set (α × α)} (h : (𝓤 α).HasBasis p s)
{f : Filter α} :
Cauchy f ↔ NeBot f ∧ ∀ i, p i → ∃ t ∈ f, ∀ x ∈ t, ∀ y ∈ t, (x, y) ∈ s i :=
and_congr Iff.rfl <|
(f.basis_sets.prod_self.le_basis_iff h).trans <| by
simp only [subset_def, Prod.forall, mem_prod_eq, and_imp, id, forall_mem_comm]
theorem cauchy_iff' {f : Filter α} :
Cauchy f ↔ NeBot f ∧ ∀ s ∈ 𝓤 α, ∃ t ∈ f, ∀ x ∈ t, ∀ y ∈ t, (x, y) ∈ s :=
(𝓤 α).basis_sets.cauchy_iff
theorem cauchy_iff {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ s ∈ 𝓤 α, ∃ t ∈ f, t ×ˢ t ⊆ s :=
cauchy_iff'.trans <| by
simp only [subset_def, Prod.forall, mem_prod_eq, and_imp, id, forall_mem_comm]
lemma cauchy_iff_le {l : Filter α} [hl : l.NeBot] :
Cauchy l ↔ l ×ˢ l ≤ 𝓤 α := by
simp only [Cauchy, hl, true_and]
theorem Cauchy.ultrafilter_of {l : Filter α} (h : Cauchy l) :
Cauchy (@Ultrafilter.of _ l h.1 : Filter α) := by
haveI := h.1
have := Ultrafilter.of_le l
exact ⟨Ultrafilter.neBot _, (Filter.prod_mono this this).trans h.2⟩
theorem cauchy_map_iff {l : Filter β} {f : β → α} :
Cauchy (l.map f) ↔ NeBot l ∧ Tendsto (fun p : β × β => (f p.1, f p.2)) (l ×ˢ l) (𝓤 α) := by
rw [Cauchy, map_neBot_iff, prod_map_map_eq, Tendsto]
theorem cauchy_map_iff' {l : Filter β} [hl : NeBot l] {f : β → α} :
Cauchy (l.map f) ↔ Tendsto (fun p : β × β => (f p.1, f p.2)) (l ×ˢ l) (𝓤 α) :=
cauchy_map_iff.trans <| and_iff_right hl
theorem Cauchy.mono {f g : Filter α} [hg : NeBot g] (h_c : Cauchy f) (h_le : g ≤ f) : Cauchy g :=
⟨hg, le_trans (Filter.prod_mono h_le h_le) h_c.right⟩
theorem Cauchy.mono' {f g : Filter α} (h_c : Cauchy f) (_ : NeBot g) (h_le : g ≤ f) : Cauchy g :=
h_c.mono h_le
theorem cauchy_nhds {a : α} : Cauchy (𝓝 a) :=
⟨nhds_neBot, nhds_prod_eq.symm.trans_le (nhds_le_uniformity a)⟩
theorem cauchy_pure {a : α} : Cauchy (pure a) :=
cauchy_nhds.mono (pure_le_nhds a)
theorem Filter.Tendsto.cauchy_map {l : Filter β} [NeBot l] {f : β → α} {a : α}
(h : Tendsto f l (𝓝 a)) : Cauchy (map f l) :=
cauchy_nhds.mono h
lemma Cauchy.mono_uniformSpace {u v : UniformSpace β} {F : Filter β} (huv : u ≤ v)
(hF : Cauchy (uniformSpace := u) F) : Cauchy (uniformSpace := v) F :=
⟨hF.1, hF.2.trans huv⟩
lemma cauchy_inf_uniformSpace {u v : UniformSpace β} {F : Filter β} :
Cauchy (uniformSpace := u ⊓ v) F ↔
Cauchy (uniformSpace := u) F ∧ Cauchy (uniformSpace := v) F := by
unfold Cauchy
rw [inf_uniformity (u := u), le_inf_iff, and_and_left]
lemma cauchy_iInf_uniformSpace {ι : Sort*} [Nonempty ι] {u : ι → UniformSpace β}
{l : Filter β} :
Cauchy (uniformSpace := ⨅ i, u i) l ↔ ∀ i, Cauchy (uniformSpace := u i) l := by
unfold Cauchy
rw [iInf_uniformity, le_iInf_iff, forall_and, forall_const]
lemma cauchy_iInf_uniformSpace' {ι : Sort*} {u : ι → UniformSpace β}
{l : Filter β} [l.NeBot] :
Cauchy (uniformSpace := ⨅ i, u i) l ↔ ∀ i, Cauchy (uniformSpace := u i) l := by
simp_rw [cauchy_iff_le (uniformSpace := _), iInf_uniformity, le_iInf_iff]
lemma cauchy_comap_uniformSpace {u : UniformSpace β} {α} {f : α → β} {l : Filter α} :
Cauchy (uniformSpace := comap f u) l ↔ Cauchy (map f l) := by
simp only [Cauchy, map_neBot_iff, prod_map_map_eq, map_le_iff_le_comap]
rfl
lemma cauchy_prod_iff [UniformSpace β] {F : Filter (α × β)} :
Cauchy F ↔ Cauchy (map Prod.fst F) ∧ Cauchy (map Prod.snd F) := by
simp_rw [instUniformSpaceProd, ← cauchy_comap_uniformSpace, ← cauchy_inf_uniformSpace]
theorem Cauchy.prod [UniformSpace β] {f : Filter α} {g : Filter β} (hf : Cauchy f) (hg : Cauchy g) :
Cauchy (f ×ˢ g) := by
have := hf.1; have := hg.1
simpa [cauchy_prod_iff, hf.1] using ⟨hf, hg⟩
/-- The common part of the proofs of `le_nhds_of_cauchy_adhp` and
`SequentiallyComplete.le_nhds_of_seq_tendsto_nhds`: if for any entourage `s`
one can choose a set `t ∈ f` of diameter `s` such that it contains a point `y`
with `(x, y) ∈ s`, then `f` converges to `x`. -/
theorem le_nhds_of_cauchy_adhp_aux {f : Filter α} {x : α}
(adhs : ∀ s ∈ 𝓤 α, ∃ t ∈ f, t ×ˢ t ⊆ s ∧ ∃ y, (x, y) ∈ s ∧ y ∈ t) : f ≤ 𝓝 x := by
-- Consider a neighborhood `s` of `x`
intro s hs
-- Take an entourage twice smaller than `s`
rcases comp_mem_uniformity_sets (mem_nhds_uniformity_iff_right.1 hs) with ⟨U, U_mem, hU⟩
-- Take a set `t ∈ f`, `t × t ⊆ U`, and a point `y ∈ t` such that `(x, y) ∈ U`
rcases adhs U U_mem with ⟨t, t_mem, ht, y, hxy, hy⟩
apply mem_of_superset t_mem
-- Given a point `z ∈ t`, we have `(x, y) ∈ U` and `(y, z) ∈ t × t ⊆ U`, hence `z ∈ s`
exact fun z hz => hU (prodMk_mem_compRel hxy (ht <| mk_mem_prod hy hz)) rfl
/-- If `x` is an adherent (cluster) point for a Cauchy filter `f`, then it is a limit point
for `f`. -/
theorem le_nhds_of_cauchy_adhp {f : Filter α} {x : α} (hf : Cauchy f) (adhs : ClusterPt x f) :
f ≤ 𝓝 x :=
le_nhds_of_cauchy_adhp_aux
(fun s hs => by
obtain ⟨t, t_mem, ht⟩ : ∃ t ∈ f, t ×ˢ t ⊆ s := (cauchy_iff.1 hf).2 s hs
use t, t_mem, ht
exact forall_mem_nonempty_iff_neBot.2 adhs _ (inter_mem_inf (mem_nhds_left x hs) t_mem))
theorem le_nhds_iff_adhp_of_cauchy {f : Filter α} {x : α} (hf : Cauchy f) :
f ≤ 𝓝 x ↔ ClusterPt x f :=
⟨fun h => ClusterPt.of_le_nhds' h hf.1, le_nhds_of_cauchy_adhp hf⟩
nonrec theorem Cauchy.map [UniformSpace β] {f : Filter α} {m : α → β} (hf : Cauchy f)
(hm : UniformContinuous m) : Cauchy (map m f) :=
⟨hf.1.map _,
calc
map m f ×ˢ map m f = map (Prod.map m m) (f ×ˢ f) := Filter.prod_map_map_eq
_ ≤ Filter.map (Prod.map m m) (𝓤 α) := map_mono hf.right
_ ≤ 𝓤 β := hm⟩
nonrec theorem Cauchy.comap [UniformSpace β] {f : Filter β} {m : α → β} (hf : Cauchy f)
(hm : comap (fun p : α × α => (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α) [NeBot (comap m f)] :
Cauchy (comap m f) :=
⟨‹_›,
calc
comap m f ×ˢ comap m f = comap (Prod.map m m) (f ×ˢ f) := prod_comap_comap_eq
_ ≤ comap (Prod.map m m) (𝓤 β) := comap_mono hf.right
_ ≤ 𝓤 α := hm⟩
theorem Cauchy.comap' [UniformSpace β] {f : Filter β} {m : α → β} (hf : Cauchy f)
(hm : Filter.comap (fun p : α × α => (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α)
(_ : NeBot (Filter.comap m f)) : Cauchy (Filter.comap m f) :=
hf.comap hm
/-- Cauchy sequences. Usually defined on ℕ, but often it is also useful to say that a function
defined on ℝ is Cauchy at +∞ to deduce convergence. Therefore, we define it in a type class that
is general enough to cover both ℕ and ℝ, which are the main motivating examples. -/
def CauchySeq [Preorder β] (u : β → α) :=
Cauchy (atTop.map u)
theorem CauchySeq.tendsto_uniformity [Preorder β] {u : β → α} (h : CauchySeq u) :
Tendsto (Prod.map u u) atTop (𝓤 α) := by
simpa only [Tendsto, prod_map_map_eq', prod_atTop_atTop_eq] using h.right
theorem CauchySeq.nonempty [Preorder β] {u : β → α} (hu : CauchySeq u) : Nonempty β :=
@nonempty_of_neBot _ _ <| (map_neBot_iff _).1 hu.1
theorem CauchySeq.mem_entourage {β : Type*} [SemilatticeSup β] {u : β → α} (h : CauchySeq u)
{V : Set (α × α)} (hV : V ∈ 𝓤 α) : ∃ k₀, ∀ i j, k₀ ≤ i → k₀ ≤ j → (u i, u j) ∈ V := by
haveI := h.nonempty
have := h.tendsto_uniformity; rw [← prod_atTop_atTop_eq] at this
simpa [MapsTo] using atTop_basis.prod_self.tendsto_left_iff.1 this V hV
theorem Filter.Tendsto.cauchySeq [SemilatticeSup β] [Nonempty β] {f : β → α} {x}
(hx : Tendsto f atTop (𝓝 x)) : CauchySeq f :=
hx.cauchy_map
theorem cauchySeq_const [SemilatticeSup β] [Nonempty β] (x : α) : CauchySeq fun _ : β => x :=
tendsto_const_nhds.cauchySeq
theorem cauchySeq_iff_tendsto [Nonempty β] [SemilatticeSup β] {u : β → α} :
CauchySeq u ↔ Tendsto (Prod.map u u) atTop (𝓤 α) :=
cauchy_map_iff'.trans <| by simp only [prod_atTop_atTop_eq, Prod.map_def]
theorem CauchySeq.comp_tendsto {γ} [Preorder β] [SemilatticeSup γ] [Nonempty γ] {f : β → α}
(hf : CauchySeq f) {g : γ → β} (hg : Tendsto g atTop atTop) : CauchySeq (f ∘ g) :=
⟨inferInstance, le_trans (prod_le_prod.mpr ⟨Tendsto.comp le_rfl hg, Tendsto.comp le_rfl hg⟩) hf.2⟩
theorem CauchySeq.comp_injective [SemilatticeSup β] [NoMaxOrder β] [Nonempty β] {u : ℕ → α}
(hu : CauchySeq u) {f : β → ℕ} (hf : Injective f) : CauchySeq (u ∘ f) :=
hu.comp_tendsto <| Nat.cofinite_eq_atTop ▸ hf.tendsto_cofinite.mono_left atTop_le_cofinite
theorem Function.Bijective.cauchySeq_comp_iff {f : ℕ → ℕ} (hf : Bijective f) (u : ℕ → α) :
CauchySeq (u ∘ f) ↔ CauchySeq u := by
refine ⟨fun H => ?_, fun H => H.comp_injective hf.injective⟩
lift f to ℕ ≃ ℕ using hf
simpa only [Function.comp_def, f.apply_symm_apply] using H.comp_injective f.symm.injective
theorem CauchySeq.subseq_subseq_mem {V : ℕ → Set (α × α)} (hV : ∀ n, V n ∈ 𝓤 α) {u : ℕ → α}
(hu : CauchySeq u) {f g : ℕ → ℕ} (hf : Tendsto f atTop atTop) (hg : Tendsto g atTop atTop) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, ((u ∘ f ∘ φ) n, (u ∘ g ∘ φ) n) ∈ V n := by
rw [cauchySeq_iff_tendsto] at hu
exact ((hu.comp <| hf.prod_atTop hg).comp tendsto_atTop_diagonal).subseq_mem hV
-- todo: generalize this and other lemmas to a nonempty semilattice
theorem cauchySeq_iff' {u : ℕ → α} :
CauchySeq u ↔ ∀ V ∈ 𝓤 α, ∀ᶠ k in atTop, k ∈ Prod.map u u ⁻¹' V :=
cauchySeq_iff_tendsto
theorem cauchySeq_iff {u : ℕ → α} :
CauchySeq u ↔ ∀ V ∈ 𝓤 α, ∃ N, ∀ k ≥ N, ∀ l ≥ N, (u k, u l) ∈ V := by
simp only [cauchySeq_iff', Filter.eventually_atTop_prod_self', mem_preimage, Prod.map_apply]
theorem CauchySeq.prodMap {γ δ} [UniformSpace β] [Preorder γ] [Preorder δ] {u : γ → α} {v : δ → β}
(hu : CauchySeq u) (hv : CauchySeq v) : CauchySeq (Prod.map u v) := by
simpa only [CauchySeq, prod_map_map_eq', prod_atTop_atTop_eq] using hu.prod hv
@[deprecated (since := "2025-03-10")]
alias CauchySeq.prod_map := CauchySeq.prodMap
theorem CauchySeq.prodMk {γ} [UniformSpace β] [Preorder γ] {u : γ → α} {v : γ → β}
(hu : CauchySeq u) (hv : CauchySeq v) : CauchySeq fun x => (u x, v x) :=
haveI := hu.1.of_map
(Cauchy.prod hu hv).mono (tendsto_map.prodMk tendsto_map)
@[deprecated (since := "2025-03-10")]
alias CauchySeq.prod := CauchySeq.prodMk
theorem CauchySeq.eventually_eventually [Preorder β] {u : β → α} (hu : CauchySeq u)
{V : Set (α × α)} (hV : V ∈ 𝓤 α) : ∀ᶠ k in atTop, ∀ᶠ l in atTop, (u k, u l) ∈ V :=
eventually_atTop_curry <| hu.tendsto_uniformity hV
theorem UniformContinuous.comp_cauchySeq {γ} [UniformSpace β] [Preorder γ] {f : α → β}
(hf : UniformContinuous f) {u : γ → α} (hu : CauchySeq u) : CauchySeq (f ∘ u) :=
hu.map hf
theorem CauchySeq.subseq_mem {V : ℕ → Set (α × α)} (hV : ∀ n, V n ∈ 𝓤 α) {u : ℕ → α}
(hu : CauchySeq u) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, (u <| φ (n + 1), u <| φ n) ∈ V n := by
have : ∀ n, ∃ N, ∀ k ≥ N, ∀ l ≥ k, (u l, u k) ∈ V n := fun n => by
rw [cauchySeq_iff] at hu
rcases hu _ (hV n) with ⟨N, H⟩
exact ⟨N, fun k hk l hl => H _ (le_trans hk hl) _ hk⟩
obtain ⟨φ : ℕ → ℕ, φ_extr : StrictMono φ, hφ : ∀ n, ∀ l ≥ φ n, (u l, u <| φ n) ∈ V n⟩ :=
extraction_forall_of_eventually' this
exact ⟨φ, φ_extr, fun n => hφ _ _ (φ_extr <| Nat.lt_add_one n).le⟩
theorem Filter.Tendsto.subseq_mem_entourage {V : ℕ → Set (α × α)} (hV : ∀ n, V n ∈ 𝓤 α) {u : ℕ → α}
{a : α} (hu : Tendsto u atTop (𝓝 a)) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ (u (φ 0), a) ∈ V 0 ∧
∀ n, (u <| φ (n + 1), u <| φ n) ∈ V (n + 1) := by
rcases mem_atTop_sets.1 (hu (ball_mem_nhds a (symm_le_uniformity <| hV 0))) with ⟨n, hn⟩
rcases (hu.comp (tendsto_add_atTop_nat n)).cauchySeq.subseq_mem fun n => hV (n + 1) with
⟨φ, φ_mono, hφV⟩
exact ⟨fun k => φ k + n, φ_mono.add_const _, hn _ le_add_self, hφV⟩
/-- If a Cauchy sequence has a convergent subsequence, then it converges. -/
theorem tendsto_nhds_of_cauchySeq_of_subseq [Preorder β] {u : β → α} (hu : CauchySeq u)
{ι : Type*} {f : ι → β} {p : Filter ι} [NeBot p] (hf : Tendsto f p atTop) {a : α}
(ha : Tendsto (u ∘ f) p (𝓝 a)) : Tendsto u atTop (𝓝 a) :=
le_nhds_of_cauchy_adhp hu (ha.mapClusterPt.of_comp hf)
/-- Any shift of a Cauchy sequence is also a Cauchy sequence. -/
theorem cauchySeq_shift {u : ℕ → α} (k : ℕ) : CauchySeq (fun n ↦ u (n + k)) ↔ CauchySeq u := by
constructor <;> intro h
· rw [cauchySeq_iff] at h ⊢
intro V mV
obtain ⟨N, h⟩ := h V mV
use N + k
intro a ha b hb
convert h (a - k) (Nat.le_sub_of_add_le ha) (b - k) (Nat.le_sub_of_add_le hb) <;> omega
· exact h.comp_tendsto (tendsto_add_atTop_nat k)
theorem Filter.HasBasis.cauchySeq_iff {γ} [Nonempty β] [SemilatticeSup β] {u : β → α} {p : γ → Prop}
{s : γ → Set (α × α)} (h : (𝓤 α).HasBasis p s) :
CauchySeq u ↔ ∀ i, p i → ∃ N, ∀ m, N ≤ m → ∀ n, N ≤ n → (u m, u n) ∈ s i := by
rw [cauchySeq_iff_tendsto, ← prod_atTop_atTop_eq]
refine (atTop_basis.prod_self.tendsto_iff h).trans ?_
simp only [exists_prop, true_and, MapsTo, preimage, subset_def, Prod.forall, mem_prod_eq,
mem_setOf_eq, mem_Ici, and_imp, Prod.map, @forall_swap (_ ≤ _) β]
theorem Filter.HasBasis.cauchySeq_iff' {γ} [Nonempty β] [SemilatticeSup β] {u : β → α}
{p : γ → Prop} {s : γ → Set (α × α)} (H : (𝓤 α).HasBasis p s) :
CauchySeq u ↔ ∀ i, p i → ∃ N, ∀ n ≥ N, (u n, u N) ∈ s i := by
refine H.cauchySeq_iff.trans ⟨fun h i hi => ?_, fun h i hi => ?_⟩
· exact (h i hi).imp fun N hN n hn => hN n hn N le_rfl
· rcases comp_symm_of_uniformity (H.mem_of_mem hi) with ⟨t, ht, ht', hts⟩
rcases H.mem_iff.1 ht with ⟨j, hj, hjt⟩
refine (h j hj).imp fun N hN m hm n hn => hts ⟨u N, hjt ?_, ht' <| hjt ?_⟩
exacts [hN m hm, hN n hn]
theorem cauchySeq_of_controlled [SemilatticeSup β] [Nonempty β] (U : β → Set (α × α))
(hU : ∀ s ∈ 𝓤 α, ∃ n, U n ⊆ s) {f : β → α}
(hf : ∀ ⦃N m n : β⦄, N ≤ m → N ≤ n → (f m, f n) ∈ U N) : CauchySeq f :=
cauchySeq_iff_tendsto.2
(by
intro s hs
rw [mem_map, mem_atTop_sets]
obtain ⟨N, hN⟩ := hU s hs
refine ⟨(N, N), fun mn hmn => ?_⟩
obtain ⟨m, n⟩ := mn
exact hN (hf hmn.1 hmn.2))
theorem isComplete_iff_clusterPt {s : Set α} :
IsComplete s ↔ ∀ l, Cauchy l → l ≤ 𝓟 s → ∃ x ∈ s, ClusterPt x l :=
forall₃_congr fun _ hl _ => exists_congr fun _ => and_congr_right fun _ =>
le_nhds_iff_adhp_of_cauchy hl
theorem isComplete_iff_ultrafilter {s : Set α} :
IsComplete s ↔ ∀ l : Ultrafilter α, Cauchy (l : Filter α) → ↑l ≤ 𝓟 s → ∃ x ∈ s, ↑l ≤ 𝓝 x := by
refine ⟨fun h l => h l, fun H => isComplete_iff_clusterPt.2 fun l hl hls => ?_⟩
haveI := hl.1
rcases H (Ultrafilter.of l) hl.ultrafilter_of ((Ultrafilter.of_le l).trans hls) with ⟨x, hxs, hxl⟩
exact ⟨x, hxs, (ClusterPt.of_le_nhds hxl).mono (Ultrafilter.of_le l)⟩
theorem isComplete_iff_ultrafilter' {s : Set α} :
IsComplete s ↔ ∀ l : Ultrafilter α, Cauchy (l : Filter α) → s ∈ l → ∃ x ∈ s, ↑l ≤ 𝓝 x :=
isComplete_iff_ultrafilter.trans <| by simp only [le_principal_iff, Ultrafilter.mem_coe]
protected theorem IsComplete.union {s t : Set α} (hs : IsComplete s) (ht : IsComplete t) :
IsComplete (s ∪ t) := by
simp only [isComplete_iff_ultrafilter', Ultrafilter.union_mem_iff, or_imp] at *
exact fun l hl =>
⟨fun hsl => (hs l hl hsl).imp fun x hx => ⟨Or.inl hx.1, hx.2⟩, fun htl =>
(ht l hl htl).imp fun x hx => ⟨Or.inr hx.1, hx.2⟩⟩
theorem isComplete_iUnion_separated {ι : Sort*} {s : ι → Set α} (hs : ∀ i, IsComplete (s i))
{U : Set (α × α)} (hU : U ∈ 𝓤 α) (hd : ∀ (i j : ι), ∀ x ∈ s i, ∀ y ∈ s j, (x, y) ∈ U → i = j) :
IsComplete (⋃ i, s i) := by
set S := ⋃ i, s i
intro l hl hls
rw [le_principal_iff] at hls
obtain ⟨hl_ne, hl'⟩ := cauchy_iff.1 hl
obtain ⟨t, htS, htl, htU⟩ : ∃ t, t ⊆ S ∧ t ∈ l ∧ t ×ˢ t ⊆ U := by
rcases hl' U hU with ⟨t, htl, htU⟩
refine ⟨t ∩ S, inter_subset_right, inter_mem htl hls, Subset.trans ?_ htU⟩
gcongr <;> apply inter_subset_left
obtain ⟨i, hi⟩ : ∃ i, t ⊆ s i := by
rcases Filter.nonempty_of_mem htl with ⟨x, hx⟩
rcases mem_iUnion.1 (htS hx) with ⟨i, hi⟩
refine ⟨i, fun y hy => ?_⟩
rcases mem_iUnion.1 (htS hy) with ⟨j, hj⟩
rwa [hd i j x hi y hj (htU <| mk_mem_prod hx hy)]
rcases hs i l hl (le_principal_iff.2 <| mem_of_superset htl hi) with ⟨x, hxs, hlx⟩
exact ⟨x, mem_iUnion.2 ⟨i, hxs⟩, hlx⟩
/-- A complete space is defined here using uniformities. A uniform space
is complete if every Cauchy filter converges. -/
class CompleteSpace (α : Type u) [UniformSpace α] : Prop where
/-- In a complete uniform space, every Cauchy filter converges. -/
complete : ∀ {f : Filter α}, Cauchy f → ∃ x, f ≤ 𝓝 x
theorem complete_univ {α : Type u} [UniformSpace α] [CompleteSpace α] :
IsComplete (univ : Set α) := fun f hf _ => by
rcases CompleteSpace.complete hf with ⟨x, hx⟩
exact ⟨x, mem_univ x, hx⟩
instance CompleteSpace.prod [UniformSpace β] [CompleteSpace α] [CompleteSpace β] :
CompleteSpace (α × β) where
complete hf :=
let ⟨x1, hx1⟩ := CompleteSpace.complete <| hf.map uniformContinuous_fst
let ⟨x2, hx2⟩ := CompleteSpace.complete <| hf.map uniformContinuous_snd
⟨(x1, x2), by rw [nhds_prod_eq, le_prod]; constructor <;> assumption⟩
lemma CompleteSpace.fst_of_prod [UniformSpace β] [CompleteSpace (α × β)] [h : Nonempty β] :
CompleteSpace α where
complete hf :=
let ⟨y⟩ := h
let ⟨(a, b), hab⟩ := CompleteSpace.complete <| hf.prod <| cauchy_pure (a := y)
⟨a, by simpa only [map_fst_prod, nhds_prod_eq] using map_mono (m := Prod.fst) hab⟩
lemma CompleteSpace.snd_of_prod [UniformSpace β] [CompleteSpace (α × β)] [h : Nonempty α] :
CompleteSpace β where
complete hf :=
let ⟨x⟩ := h
let ⟨(a, b), hab⟩ := CompleteSpace.complete <| (cauchy_pure (a := x)).prod hf
⟨b, by simpa only [map_snd_prod, nhds_prod_eq] using map_mono (m := Prod.snd) hab⟩
lemma completeSpace_prod_of_nonempty [UniformSpace β] [Nonempty α] [Nonempty β] :
CompleteSpace (α × β) ↔ CompleteSpace α ∧ CompleteSpace β :=
⟨fun _ ↦ ⟨.fst_of_prod (β := β), .snd_of_prod (α := α)⟩, fun ⟨_, _⟩ ↦ .prod⟩
@[to_additive]
instance CompleteSpace.mulOpposite [CompleteSpace α] : CompleteSpace αᵐᵒᵖ where
complete hf :=
MulOpposite.op_surjective.exists.mpr <|
let ⟨x, hx⟩ := CompleteSpace.complete (hf.map MulOpposite.uniformContinuous_unop)
⟨x, (map_le_iff_le_comap.mp hx).trans_eq <| MulOpposite.comap_unop_nhds _⟩
/-- If `univ` is complete, the space is a complete space -/
theorem completeSpace_of_isComplete_univ (h : IsComplete (univ : Set α)) : CompleteSpace α :=
⟨fun hf => let ⟨x, _, hx⟩ := h _ hf ((@principal_univ α).symm ▸ le_top); ⟨x, hx⟩⟩
theorem completeSpace_iff_isComplete_univ : CompleteSpace α ↔ IsComplete (univ : Set α) :=
⟨@complete_univ α _, completeSpace_of_isComplete_univ⟩
theorem completeSpace_iff_ultrafilter :
CompleteSpace α ↔ ∀ l : Ultrafilter α, Cauchy (l : Filter α) → ∃ x : α, ↑l ≤ 𝓝 x := by
simp [completeSpace_iff_isComplete_univ, isComplete_iff_ultrafilter]
theorem cauchy_iff_exists_le_nhds [CompleteSpace α] {l : Filter α} [NeBot l] :
Cauchy l ↔ ∃ x, l ≤ 𝓝 x :=
⟨CompleteSpace.complete, fun ⟨_, hx⟩ => cauchy_nhds.mono hx⟩
theorem cauchy_map_iff_exists_tendsto [CompleteSpace α] {l : Filter β} {f : β → α} [NeBot l] :
Cauchy (l.map f) ↔ ∃ x, Tendsto f l (𝓝 x) :=
cauchy_iff_exists_le_nhds
/-- A Cauchy sequence in a complete space converges -/
theorem cauchySeq_tendsto_of_complete [Preorder β] [CompleteSpace α] {u : β → α}
(H : CauchySeq u) : ∃ x, Tendsto u atTop (𝓝 x) :=
CompleteSpace.complete H
/-- If `K` is a complete subset, then any cauchy sequence in `K` converges to a point in `K` -/
theorem cauchySeq_tendsto_of_isComplete [Preorder β] {K : Set α} (h₁ : IsComplete K)
{u : β → α} (h₂ : ∀ n, u n ∈ K) (h₃ : CauchySeq u) : ∃ v ∈ K, Tendsto u atTop (𝓝 v) :=
h₁ _ h₃ <| le_principal_iff.2 <| mem_map_iff_exists_image.2
⟨univ, univ_mem, by rwa [image_univ, range_subset_iff]⟩
theorem Cauchy.le_nhds_lim [CompleteSpace α] {f : Filter α} (hf : Cauchy f) :
haveI := hf.1.nonempty; f ≤ 𝓝 (lim f) :=
_root_.le_nhds_lim (CompleteSpace.complete hf)
theorem CauchySeq.tendsto_limUnder [Preorder β] [CompleteSpace α] {u : β → α} (h : CauchySeq u) :
haveI := h.1.nonempty; Tendsto u atTop (𝓝 <| limUnder atTop u) :=
h.le_nhds_lim
theorem IsClosed.isComplete [CompleteSpace α] {s : Set α} (h : IsClosed s) : IsComplete s :=
fun _ cf fs =>
let ⟨x, hx⟩ := CompleteSpace.complete cf
⟨x, isClosed_iff_clusterPt.mp h x (cf.left.mono (le_inf hx fs)), hx⟩
/-- A set `s` is totally bounded if for every entourage `d` there is a finite
set of points `t` such that every element of `s` is `d`-near to some element of `t`. -/
def TotallyBounded (s : Set α) : Prop :=
∀ d ∈ 𝓤 α, ∃ t : Set α, t.Finite ∧ s ⊆ ⋃ y ∈ t, { x | (x, y) ∈ d }
theorem TotallyBounded.exists_subset {s : Set α} (hs : TotallyBounded s) {U : Set (α × α)}
(hU : U ∈ 𝓤 α) : ∃ t, t ⊆ s ∧ Set.Finite t ∧ s ⊆ ⋃ y ∈ t, { x | (x, y) ∈ U } := by
rcases comp_symm_of_uniformity hU with ⟨r, hr, rs, rU⟩
rcases hs r hr with ⟨k, fk, ks⟩
let u := k ∩ { y | ∃ x ∈ s, (x, y) ∈ r }
choose f hfs hfr using fun x : u => x.coe_prop.2
refine ⟨range f, ?_, ?_, ?_⟩
· exact range_subset_iff.2 hfs
· haveI : Fintype u := (fk.inter_of_left _).fintype
exact finite_range f
· intro x xs
obtain ⟨y, hy, xy⟩ := mem_iUnion₂.1 (ks xs)
rw [biUnion_range, mem_iUnion]
set z : ↥u := ⟨y, hy, ⟨x, xs, xy⟩⟩
exact ⟨z, rU <| mem_compRel.2 ⟨y, xy, rs (hfr z)⟩⟩
|
theorem totallyBounded_iff_subset {s : Set α} :
TotallyBounded s ↔
| Mathlib/Topology/UniformSpace/Cauchy.lean | 465 | 467 |
/-
Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import Mathlib.Analysis.Convex.Topology
import Mathlib.Analysis.NormedSpace.Pointwise
import Mathlib.Analysis.Seminorm
import Mathlib.Analysis.LocallyConvex.Bounded
import Mathlib.Analysis.RCLike.Basic
/-!
# The Minkowski functional
This file defines the Minkowski functional, aka gauge.
The Minkowski functional of a set `s` is the function which associates each point to how much you
need to scale `s` for `x` to be inside it. When `s` is symmetric, convex and absorbent, its gauge is
a seminorm. Reciprocally, any seminorm arises as the gauge of some set, namely its unit ball. This
induces the equivalence of seminorms and locally convex topological vector spaces.
## Main declarations
For a real vector space,
* `gauge`: Aka Minkowski functional. `gauge s x` is the least (actually, an infimum) `r` such
that `x ∈ r • s`.
* `gaugeSeminorm`: The Minkowski functional as a seminorm, when `s` is symmetric, convex and
absorbent.
## References
* [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966]
## Tags
Minkowski functional, gauge
-/
open NormedField Set
open scoped Pointwise Topology NNReal
noncomputable section
variable {𝕜 E : Type*}
section AddCommGroup
variable [AddCommGroup E] [Module ℝ E]
/-- The Minkowski functional. Given a set `s` in a real vector space, `gauge s` is the functional
which sends `x : E` to the smallest `r : ℝ` such that `x` is in `s` scaled by `r`. -/
def gauge (s : Set E) (x : E) : ℝ :=
sInf { r : ℝ | 0 < r ∧ x ∈ r • s }
variable {s t : Set E} {x : E} {a : ℝ}
theorem gauge_def : gauge s x = sInf ({ r ∈ Set.Ioi (0 : ℝ) | x ∈ r • s }) :=
rfl
/-- An alternative definition of the gauge using scalar multiplication on the element rather than on
the set. -/
theorem gauge_def' : gauge s x = sInf {r ∈ Set.Ioi (0 : ℝ) | r⁻¹ • x ∈ s} := by
congrm sInf {r | ?_}
exact and_congr_right fun hr => mem_smul_set_iff_inv_smul_mem₀ hr.ne' _ _
private theorem gauge_set_bddBelow : BddBelow { r : ℝ | 0 < r ∧ x ∈ r • s } :=
⟨0, fun _ hr => hr.1.le⟩
/-- If the given subset is `Absorbent` then the set we take an infimum over in `gauge` is nonempty,
which is useful for proving many properties about the gauge. -/
theorem Absorbent.gauge_set_nonempty (absorbs : Absorbent ℝ s) :
{ r : ℝ | 0 < r ∧ x ∈ r • s }.Nonempty :=
let ⟨r, hr₁, hr₂⟩ := (absorbs x).exists_pos
⟨r, hr₁, hr₂ r (Real.norm_of_nonneg hr₁.le).ge rfl⟩
theorem gauge_mono (hs : Absorbent ℝ s) (h : s ⊆ t) : gauge t ≤ gauge s := fun _ =>
csInf_le_csInf gauge_set_bddBelow hs.gauge_set_nonempty fun _ hr => ⟨hr.1, smul_set_mono h hr.2⟩
theorem exists_lt_of_gauge_lt (absorbs : Absorbent ℝ s) (h : gauge s x < a) :
∃ b, 0 < b ∧ b < a ∧ x ∈ b • s := by
obtain ⟨b, ⟨hb, hx⟩, hba⟩ := exists_lt_of_csInf_lt absorbs.gauge_set_nonempty h
exact ⟨b, hb, hba, hx⟩
/-- The gauge evaluated at `0` is always zero (mathematically this requires `0` to be in the set `s`
but, the real infimum of the empty set in Lean being defined as `0`, it holds unconditionally). -/
@[simp]
theorem gauge_zero : gauge s 0 = 0 := by
rw [gauge_def']
by_cases h : (0 : E) ∈ s
· simp only [smul_zero, sep_true, h, csInf_Ioi]
· simp only [smul_zero, sep_false, h, Real.sInf_empty]
@[simp]
theorem gauge_zero' : gauge (0 : Set E) = 0 := by
ext x
rw [gauge_def']
obtain rfl | hx := eq_or_ne x 0
· simp only [csInf_Ioi, mem_zero, Pi.zero_apply, eq_self_iff_true, sep_true, smul_zero]
· simp only [mem_zero, Pi.zero_apply, inv_eq_zero, smul_eq_zero]
convert Real.sInf_empty
exact eq_empty_iff_forall_not_mem.2 fun r hr => hr.2.elim (ne_of_gt hr.1) hx
@[simp]
theorem gauge_empty : gauge (∅ : Set E) = 0 := by
ext
simp only [gauge_def', Real.sInf_empty, mem_empty_iff_false, Pi.zero_apply, sep_false]
theorem gauge_of_subset_zero (h : s ⊆ 0) : gauge s = 0 := by
obtain rfl | rfl := subset_singleton_iff_eq.1 h
exacts [gauge_empty, gauge_zero']
/-- The gauge is always nonnegative. -/
theorem gauge_nonneg (x : E) : 0 ≤ gauge s x :=
Real.sInf_nonneg fun _ hx => hx.1.le
theorem gauge_neg (symmetric : ∀ x ∈ s, -x ∈ s) (x : E) : gauge s (-x) = gauge s x := by
have : ∀ x, -x ∈ s ↔ x ∈ s := fun x => ⟨fun h => by simpa using symmetric _ h, symmetric x⟩
simp_rw [gauge_def', smul_neg, this]
theorem gauge_neg_set_neg (x : E) : gauge (-s) (-x) = gauge s x := by
simp_rw [gauge_def', smul_neg, neg_mem_neg]
theorem gauge_neg_set_eq_gauge_neg (x : E) : gauge (-s) x = gauge s (-x) := by
rw [← gauge_neg_set_neg, neg_neg]
theorem gauge_le_of_mem (ha : 0 ≤ a) (hx : x ∈ a • s) : gauge s x ≤ a := by
obtain rfl | ha' := ha.eq_or_lt
· rw [mem_singleton_iff.1 (zero_smul_set_subset _ hx), gauge_zero]
· exact csInf_le gauge_set_bddBelow ⟨ha', hx⟩
theorem gauge_le_eq (hs₁ : Convex ℝ s) (hs₀ : (0 : E) ∈ s) (hs₂ : Absorbent ℝ s) (ha : 0 ≤ a) :
{ x | gauge s x ≤ a } = ⋂ (r : ℝ) (_ : a < r), r • s := by
ext x
simp_rw [Set.mem_iInter, Set.mem_setOf_eq]
refine ⟨fun h r hr => ?_, fun h => le_of_forall_pos_lt_add fun ε hε => ?_⟩
· have hr' := ha.trans_lt hr
rw [mem_smul_set_iff_inv_smul_mem₀ hr'.ne']
obtain ⟨δ, δ_pos, hδr, hδ⟩ := exists_lt_of_gauge_lt hs₂ (h.trans_lt hr)
suffices (r⁻¹ * δ) • δ⁻¹ • x ∈ s by rwa [smul_smul, mul_inv_cancel_right₀ δ_pos.ne'] at this
rw [mem_smul_set_iff_inv_smul_mem₀ δ_pos.ne'] at hδ
refine hs₁.smul_mem_of_zero_mem hs₀ hδ ⟨by positivity, ?_⟩
rw [inv_mul_le_iff₀ hr', mul_one]
exact hδr.le
· have hε' := (lt_add_iff_pos_right a).2 (half_pos hε)
exact
(gauge_le_of_mem (ha.trans hε'.le) <| h _ hε').trans_lt (add_lt_add_left (half_lt_self hε) _)
theorem gauge_lt_eq' (absorbs : Absorbent ℝ s) (a : ℝ) :
{ x | gauge s x < a } = ⋃ (r : ℝ) (_ : 0 < r) (_ : r < a), r • s := by
ext
simp_rw [mem_setOf, mem_iUnion, exists_prop]
exact
⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ =>
(gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩
theorem gauge_lt_eq (absorbs : Absorbent ℝ s) (a : ℝ) :
{ x | gauge s x < a } = ⋃ r ∈ Set.Ioo 0 (a : ℝ), r • s := by
ext
simp_rw [mem_setOf, mem_iUnion, exists_prop, mem_Ioo, and_assoc]
exact
⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ =>
(gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩
theorem mem_openSegment_of_gauge_lt_one (absorbs : Absorbent ℝ s) (hgauge : gauge s x < 1) :
∃ y ∈ s, x ∈ openSegment ℝ 0 y := by
rcases exists_lt_of_gauge_lt absorbs hgauge with ⟨r, hr₀, hr₁, y, hy, rfl⟩
refine ⟨y, hy, 1 - r, r, ?_⟩
simp [*]
theorem gauge_lt_one_subset_self (hs : Convex ℝ s) (h₀ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) :
{ x | gauge s x < 1 } ⊆ s := fun _x hx ↦
let ⟨_y, hys, hx⟩ := mem_openSegment_of_gauge_lt_one absorbs hx
hs.openSegment_subset h₀ hys hx
theorem gauge_le_one_of_mem {x : E} (hx : x ∈ s) : gauge s x ≤ 1 :=
gauge_le_of_mem zero_le_one <| by rwa [one_smul]
/-- Gauge is subadditive. -/
theorem gauge_add_le (hs : Convex ℝ s) (absorbs : Absorbent ℝ s) (x y : E) :
gauge s (x + y) ≤ gauge s x + gauge s y := by
refine le_of_forall_pos_lt_add fun ε hε => ?_
obtain ⟨a, ha, ha', x, hx, rfl⟩ :=
exists_lt_of_gauge_lt absorbs (lt_add_of_pos_right (gauge s x) (half_pos hε))
obtain ⟨b, hb, hb', y, hy, rfl⟩ :=
exists_lt_of_gauge_lt absorbs (lt_add_of_pos_right (gauge s y) (half_pos hε))
calc
gauge s (a • x + b • y) ≤ a + b := gauge_le_of_mem (by positivity) <| by
rw [hs.add_smul ha.le hb.le]
exact add_mem_add (smul_mem_smul_set hx) (smul_mem_smul_set hy)
_ < gauge s (a • x) + gauge s (b • y) + ε := by linarith
theorem self_subset_gauge_le_one : s ⊆ { x | gauge s x ≤ 1 } := fun _ => gauge_le_one_of_mem
theorem Convex.gauge_le (hs : Convex ℝ s) (h₀ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) (a : ℝ) :
Convex ℝ { x | gauge s x ≤ a } := by
by_cases ha : 0 ≤ a
· rw [gauge_le_eq hs h₀ absorbs ha]
exact convex_iInter fun i => convex_iInter fun _ => hs.smul _
· convert convex_empty (𝕜 := ℝ)
exact eq_empty_iff_forall_not_mem.2 fun x hx => ha <| (gauge_nonneg _).trans hx
theorem Balanced.starConvex (hs : Balanced ℝ s) : StarConvex ℝ 0 s :=
starConvex_zero_iff.2 fun _ hx a ha₀ ha₁ =>
hs _ (by rwa [Real.norm_of_nonneg ha₀]) (smul_mem_smul_set hx)
theorem le_gauge_of_not_mem (hs₀ : StarConvex ℝ 0 s) (hs₂ : Absorbs ℝ s {x}) (hx : x ∉ a • s) :
a ≤ gauge s x := by
rw [starConvex_zero_iff] at hs₀
obtain ⟨r, hr, h⟩ := hs₂.exists_pos
refine le_csInf ⟨r, hr, singleton_subset_iff.1 <| h _ (Real.norm_of_nonneg hr.le).ge⟩ ?_
rintro b ⟨hb, x, hx', rfl⟩
refine not_lt.1 fun hba => hx ?_
have ha := hb.trans hba
refine ⟨(a⁻¹ * b) • x, hs₀ hx' (by positivity) ?_, ?_⟩
· rw [← div_eq_inv_mul]
exact div_le_one_of_le₀ hba.le ha.le
· dsimp only
rw [← mul_smul, mul_inv_cancel_left₀ ha.ne']
theorem one_le_gauge_of_not_mem (hs₁ : StarConvex ℝ 0 s) (hs₂ : Absorbs ℝ s {x}) (hx : x ∉ s) :
1 ≤ gauge s x :=
le_gauge_of_not_mem hs₁ hs₂ <| by rwa [one_smul]
section LinearOrderedField
variable {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
[MulActionWithZero α ℝ] [OrderedSMul α ℝ]
theorem gauge_smul_of_nonneg [MulActionWithZero α E] [IsScalarTower α ℝ (Set E)] {s : Set E} {a : α}
(ha : 0 ≤ a) (x : E) : gauge s (a • x) = a • gauge s x := by
obtain rfl | ha' := ha.eq_or_lt
· rw [zero_smul, gauge_zero, zero_smul]
rw [gauge_def', gauge_def', ← Real.sInf_smul_of_nonneg ha]
congr 1
ext r
simp_rw [Set.mem_smul_set, Set.mem_sep_iff]
constructor
· rintro ⟨hr, hx⟩
simp_rw [mem_Ioi] at hr ⊢
rw [← mem_smul_set_iff_inv_smul_mem₀ hr.ne'] at hx
have := smul_pos (inv_pos.2 ha') hr
refine ⟨a⁻¹ • r, ⟨this, ?_⟩, smul_inv_smul₀ ha'.ne' _⟩
rwa [← mem_smul_set_iff_inv_smul_mem₀ this.ne', smul_assoc,
mem_smul_set_iff_inv_smul_mem₀ (inv_ne_zero ha'.ne'), inv_inv]
· rintro ⟨r, ⟨hr, hx⟩, rfl⟩
rw [mem_Ioi] at hr ⊢
rw [← mem_smul_set_iff_inv_smul_mem₀ hr.ne'] at hx
have := smul_pos ha' hr
refine ⟨this, ?_⟩
rw [← mem_smul_set_iff_inv_smul_mem₀ this.ne', smul_assoc]
exact smul_mem_smul_set hx
theorem gauge_smul_left_of_nonneg [MulActionWithZero α E] [SMulCommClass α ℝ ℝ]
[IsScalarTower α ℝ ℝ] [IsScalarTower α ℝ E] {s : Set E} {a : α} (ha : 0 ≤ a) :
gauge (a • s) = a⁻¹ • gauge s := by
obtain rfl | ha' := ha.eq_or_lt
· rw [inv_zero, zero_smul, gauge_of_subset_zero (zero_smul_set_subset _)]
ext x
rw [gauge_def', Pi.smul_apply, gauge_def', ← Real.sInf_smul_of_nonneg (inv_nonneg.2 ha)]
congr 1
ext r
simp_rw [Set.mem_smul_set, Set.mem_sep_iff]
constructor
· rintro ⟨hr, y, hy, h⟩
simp_rw [mem_Ioi] at hr ⊢
refine ⟨a • r, ⟨smul_pos ha' hr, ?_⟩, inv_smul_smul₀ ha'.ne' _⟩
rwa [smul_inv₀, smul_assoc, ← h, inv_smul_smul₀ ha'.ne']
· rintro ⟨r, ⟨hr, hx⟩, rfl⟩
rw [mem_Ioi] at hr ⊢
refine ⟨smul_pos (inv_pos.2 ha') hr, r⁻¹ • x, hx, ?_⟩
rw [smul_inv₀, smul_assoc, inv_inv]
theorem gauge_smul_left [Module α E] [SMulCommClass α ℝ ℝ] [IsScalarTower α ℝ ℝ]
[IsScalarTower α ℝ E] {s : Set E} (symmetric : ∀ x ∈ s, -x ∈ s) (a : α) :
gauge (a • s) = |a|⁻¹ • gauge s := by
rw [← gauge_smul_left_of_nonneg (abs_nonneg a)]
obtain h | h := abs_choice a
· rw [h]
· rw [h, Set.neg_smul_set, ← Set.smul_set_neg]
-- Porting note: was congr
apply congr_arg
apply congr_arg
ext y
refine ⟨symmetric _, fun hy => ?_⟩
rw [← neg_neg y]
exact symmetric _ hy
end LinearOrderedField
section RCLike
variable [RCLike 𝕜] [Module 𝕜 E] [IsScalarTower ℝ 𝕜 E]
theorem gauge_norm_smul (hs : Balanced 𝕜 s) (r : 𝕜) (x : E) :
gauge s (‖r‖ • x) = gauge s (r • x) := by
unfold gauge
congr with θ
rw [@RCLike.real_smul_eq_coe_smul 𝕜]
refine and_congr_right fun hθ => (hs.smul _).smul_mem_iff ?_
rw [RCLike.norm_ofReal, abs_norm]
/-- If `s` is balanced, then the Minkowski functional is ℂ-homogeneous. -/
theorem gauge_smul (hs : Balanced 𝕜 s) (r : 𝕜) (x : E) : gauge s (r • x) = ‖r‖ * gauge s x := by
rw [← smul_eq_mul, ← gauge_smul_of_nonneg (norm_nonneg r), gauge_norm_smul hs]
end RCLike
open Filter
section TopologicalSpace
variable [TopologicalSpace E]
theorem comap_gauge_nhds_zero_le (ha : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) :
comap (gauge s) (𝓝 0) ≤ 𝓝 0 := fun u hu ↦ by
rcases (hb hu).exists_pos with ⟨r, hr₀, hr⟩
filter_upwards [preimage_mem_comap (gt_mem_nhds (inv_pos.2 hr₀))] with x (hx : gauge s x < r⁻¹)
rcases exists_lt_of_gauge_lt ha hx with ⟨c, hc₀, hcr, y, hy, rfl⟩
have hrc := (lt_inv_comm₀ hr₀ hc₀).2 hcr
rcases hr c⁻¹ (hrc.le.trans (le_abs_self _)) hy with ⟨z, hz, rfl⟩
simpa only [smul_inv_smul₀ hc₀.ne']
variable [T1Space E]
theorem gauge_eq_zero (hs : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) :
gauge s x = 0 ↔ x = 0 := by
refine ⟨fun h₀ ↦ by_contra fun (hne : x ≠ 0) ↦ ?_, fun h ↦ h.symm ▸ gauge_zero⟩
have : {x}ᶜ ∈ comap (gauge s) (𝓝 0) :=
comap_gauge_nhds_zero_le hs hb (isOpen_compl_singleton.mem_nhds hne.symm)
rcases ((nhds_basis_zero_abs_lt _).comap _).mem_iff.1 this with ⟨r, hr₀, hr⟩
exact hr (by simpa [h₀]) rfl
theorem gauge_pos (hs : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) :
0 < gauge s x ↔ x ≠ 0 := by
simp only [(gauge_nonneg _).gt_iff_ne, Ne, gauge_eq_zero hs hb]
end TopologicalSpace
section ContinuousSMul
variable [TopologicalSpace E] [ContinuousSMul ℝ E]
open Filter in
theorem interior_subset_gauge_lt_one (s : Set E) : interior s ⊆ { x | gauge s x < 1 } := by
intro x hx
have H₁ : Tendsto (fun r : ℝ ↦ r⁻¹ • x) (𝓝[<] 1) (𝓝 ((1 : ℝ)⁻¹ • x)) :=
((tendsto_id.inv₀ one_ne_zero).smul tendsto_const_nhds).mono_left inf_le_left
rw [inv_one, one_smul] at H₁
have H₂ : ∀ᶠ r in 𝓝[<] (1 : ℝ), x ∈ r • s ∧ 0 < r ∧ r < 1 := by
filter_upwards [H₁ (mem_interior_iff_mem_nhds.1 hx), Ioo_mem_nhdsLT one_pos] with r h₁ h₂
exact ⟨(mem_smul_set_iff_inv_smul_mem₀ h₂.1.ne' _ _).2 h₁, h₂⟩
rcases H₂.exists with ⟨r, hxr, hr₀, hr₁⟩
exact (gauge_le_of_mem hr₀.le hxr).trans_lt hr₁
theorem gauge_lt_one_eq_self_of_isOpen (hs₁ : Convex ℝ s) (hs₀ : (0 : E) ∈ s) (hs₂ : IsOpen s) :
{ x | gauge s x < 1 } = s := by
refine (gauge_lt_one_subset_self hs₁ ‹_› <| absorbent_nhds_zero <| hs₂.mem_nhds hs₀).antisymm ?_
convert interior_subset_gauge_lt_one s
exact hs₂.interior_eq.symm
theorem gauge_lt_one_of_mem_of_isOpen (hs₂ : IsOpen s) {x : E} (hx : x ∈ s) :
gauge s x < 1 :=
interior_subset_gauge_lt_one s <| by rwa [hs₂.interior_eq]
theorem gauge_lt_of_mem_smul (x : E) (ε : ℝ) (hε : 0 < ε) (hs₂ : IsOpen s) (hx : x ∈ ε • s) :
gauge s x < ε := by
have : ε⁻¹ • x ∈ s := by rwa [← mem_smul_set_iff_inv_smul_mem₀ hε.ne']
have h_gauge_lt := gauge_lt_one_of_mem_of_isOpen hs₂ this
rwa [gauge_smul_of_nonneg (inv_nonneg.2 hε.le), smul_eq_mul, inv_mul_lt_iff₀ hε, mul_one]
at h_gauge_lt
theorem mem_closure_of_gauge_le_one (hc : Convex ℝ s) (hs₀ : 0 ∈ s) (ha : Absorbent ℝ s)
(h : gauge s x ≤ 1) : x ∈ closure s := by
have : ∀ᶠ r : ℝ in 𝓝[<] 1, r • x ∈ s := by
filter_upwards [Ico_mem_nhdsLT one_pos] with r ⟨hr₀, hr₁⟩
apply gauge_lt_one_subset_self hc hs₀ ha
rw [mem_setOf_eq, gauge_smul_of_nonneg hr₀]
exact mul_lt_one_of_nonneg_of_lt_one_left hr₀ hr₁ h
refine mem_closure_of_tendsto ?_ this
exact Filter.Tendsto.mono_left (Continuous.tendsto' (by fun_prop) _ _ (one_smul _ _))
inf_le_left
theorem mem_frontier_of_gauge_eq_one (hc : Convex ℝ s) (hs₀ : 0 ∈ s) (ha : Absorbent ℝ s)
(h : gauge s x = 1) : x ∈ frontier s :=
⟨mem_closure_of_gauge_le_one hc hs₀ ha h.le, fun h' ↦
(interior_subset_gauge_lt_one s h').out.ne h⟩
theorem tendsto_gauge_nhds_zero_nhdsGE (hs : s ∈ 𝓝 0) : Tendsto (gauge s) (𝓝 0) (𝓝[≥] 0) := by
refine nhdsGE_basis_Icc.tendsto_right_iff.2 fun ε hε ↦ ?_
rw [← set_smul_mem_nhds_zero_iff hε.ne'] at hs
filter_upwards [hs] with x hx
exact ⟨gauge_nonneg _, gauge_le_of_mem hε.le hx⟩
@[deprecated (since := "2025-03-02")]
alias tendsto_gauge_nhds_zero' := tendsto_gauge_nhds_zero_nhdsGE
theorem tendsto_gauge_nhds_zero (hs : s ∈ 𝓝 0) : Tendsto (gauge s) (𝓝 0) (𝓝 0) :=
(tendsto_gauge_nhds_zero_nhdsGE hs).mono_right inf_le_left
/-- If `s` is a neighborhood of the origin, then `gauge s` is continuous at the origin.
See also `continuousAt_gauge`. -/
theorem continuousAt_gauge_zero (hs : s ∈ 𝓝 0) : ContinuousAt (gauge s) 0 := by
rw [ContinuousAt, gauge_zero]
exact tendsto_gauge_nhds_zero hs
theorem comap_gauge_nhds_zero (hb : Bornology.IsVonNBounded ℝ s) (h₀ : s ∈ 𝓝 0) :
comap (gauge s) (𝓝 0) = 𝓝 0 :=
(comap_gauge_nhds_zero_le (absorbent_nhds_zero h₀) hb).antisymm
(tendsto_gauge_nhds_zero h₀).le_comap
end ContinuousSMul
section TopologicalVectorSpace
open Filter
variable [TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousSMul ℝ E]
/-- If `s` is a convex neighborhood of the origin in a topological real vector space, then `gauge s`
is continuous. If the ambient space is a normed space, then `gauge s` is Lipschitz continuous, see
`Convex.lipschitz_gauge`. -/
theorem continuousAt_gauge (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : ContinuousAt (gauge s) x := by
have ha : Absorbent ℝ s := absorbent_nhds_zero hs₀
refine (nhds_basis_Icc_pos _).tendsto_right_iff.2 fun ε hε₀ ↦ ?_
rw [← map_add_left_nhds_zero, eventually_map]
have : ε • s ∩ -(ε • s) ∈ 𝓝 0 :=
inter_mem ((set_smul_mem_nhds_zero_iff hε₀.ne').2 hs₀)
(neg_mem_nhds_zero _ ((set_smul_mem_nhds_zero_iff hε₀.ne').2 hs₀))
filter_upwards [this] with y hy
constructor
· rw [sub_le_iff_le_add]
calc
gauge s x = gauge s (x + y + (-y)) := by simp
_ ≤ gauge s (x + y) + gauge s (-y) := gauge_add_le hc ha _ _
_ ≤ gauge s (x + y) + ε := add_le_add_left (gauge_le_of_mem hε₀.le (mem_neg.1 hy.2)) _
· calc
gauge s (x + y) ≤ gauge s x + gauge s y := gauge_add_le hc ha _ _
_ ≤ gauge s x + ε := add_le_add_left (gauge_le_of_mem hε₀.le hy.1) _
/-- If `s` is a convex neighborhood of the origin in a topological real vector space, then `gauge s`
is continuous. If the ambient space is a normed space, then `gauge s` is Lipschitz continuous, see
`Convex.lipschitz_gauge`. -/
@[continuity]
theorem continuous_gauge (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : Continuous (gauge s) :=
continuous_iff_continuousAt.2 fun _ ↦ continuousAt_gauge hc hs₀
theorem gauge_lt_one_eq_interior (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) :
{ x | gauge s x < 1 } = interior s := by
refine Subset.antisymm (fun x hx ↦ ?_) (interior_subset_gauge_lt_one s)
rcases mem_openSegment_of_gauge_lt_one (absorbent_nhds_zero hs₀) hx with ⟨y, hys, hxy⟩
exact hc.openSegment_interior_self_subset_interior (mem_interior_iff_mem_nhds.2 hs₀) hys hxy
theorem gauge_lt_one_iff_mem_interior (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) :
gauge s x < 1 ↔ x ∈ interior s :=
Set.ext_iff.1 (gauge_lt_one_eq_interior hc hs₀) _
theorem gauge_le_one_iff_mem_closure (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) :
gauge s x ≤ 1 ↔ x ∈ closure s :=
⟨mem_closure_of_gauge_le_one hc (mem_of_mem_nhds hs₀) (absorbent_nhds_zero hs₀), fun h ↦
le_on_closure (fun _ ↦ gauge_le_one_of_mem) (continuous_gauge hc hs₀).continuousOn
continuousOn_const h⟩
theorem gauge_eq_one_iff_mem_frontier (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) :
gauge s x = 1 ↔ x ∈ frontier s := by
rw [eq_iff_le_not_lt, gauge_le_one_iff_mem_closure hc hs₀, gauge_lt_one_iff_mem_interior hc hs₀]
rfl
end TopologicalVectorSpace
section RCLike
variable [RCLike 𝕜] [Module 𝕜 E] [IsScalarTower ℝ 𝕜 E]
/-- `gauge s` as a seminorm when `s` is balanced, convex and absorbent. -/
@[simps!]
def gaugeSeminorm (hs₀ : Balanced 𝕜 s) (hs₁ : Convex ℝ s) (hs₂ : Absorbent ℝ s) : Seminorm 𝕜 E :=
Seminorm.of (gauge s) (gauge_add_le hs₁ hs₂) (gauge_smul hs₀)
variable {hs₀ : Balanced 𝕜 s} {hs₁ : Convex ℝ s} {hs₂ : Absorbent ℝ s} [TopologicalSpace E]
[ContinuousSMul ℝ E]
theorem gaugeSeminorm_lt_one_of_isOpen (hs : IsOpen s) {x : E} (hx : x ∈ s) :
gaugeSeminorm hs₀ hs₁ hs₂ x < 1 :=
gauge_lt_one_of_mem_of_isOpen hs hx
theorem gaugeSeminorm_ball_one (hs : IsOpen s) : (gaugeSeminorm hs₀ hs₁ hs₂).ball 0 1 = s := by
rw [Seminorm.ball_zero_eq]
exact gauge_lt_one_eq_self_of_isOpen hs₁ hs₂.zero_mem hs
end RCLike
/-- Any seminorm arises as the gauge of its unit ball. -/
@[simp]
protected theorem Seminorm.gauge_ball (p : Seminorm ℝ E) : gauge (p.ball 0 1) = p := by
ext x
obtain hp | hp := { r : ℝ | 0 < r ∧ x ∈ r • p.ball 0 1 }.eq_empty_or_nonempty
· rw [gauge, hp, Real.sInf_empty]
by_contra h
have hpx : 0 < p x := (apply_nonneg _ _).lt_of_ne h
have hpx₂ : 0 < 2 * p x := mul_pos zero_lt_two hpx
refine hp.subset ⟨hpx₂, (2 * p x)⁻¹ • x, ?_, smul_inv_smul₀ hpx₂.ne' _⟩
rw [p.mem_ball_zero, map_smul_eq_mul, Real.norm_eq_abs, abs_of_pos (inv_pos.2 hpx₂),
inv_mul_lt_iff₀ hpx₂, mul_one]
exact lt_mul_of_one_lt_left hpx one_lt_two
refine IsGLB.csInf_eq ⟨fun r => ?_, fun r hr => le_of_forall_pos_le_add fun ε hε => ?_⟩ hp
· rintro ⟨hr, y, hy, rfl⟩
rw [p.mem_ball_zero] at hy
rw [map_smul_eq_mul, Real.norm_eq_abs, abs_of_pos hr]
exact mul_le_of_le_one_right hr.le hy.le
· have hpε : 0 < p x + ε := by positivity
refine hr ⟨hpε, (p x + ε)⁻¹ • x, ?_, smul_inv_smul₀ hpε.ne' _⟩
rw [p.mem_ball_zero, map_smul_eq_mul, Real.norm_eq_abs, abs_of_pos (inv_pos.2 hpε),
inv_mul_lt_iff₀ hpε, mul_one]
exact lt_add_of_pos_right _ hε
theorem Seminorm.gaugeSeminorm_ball (p : Seminorm ℝ E) :
gaugeSeminorm (p.balanced_ball_zero 1) (p.convex_ball 0 1) (p.absorbent_ball_zero zero_lt_one) =
p :=
DFunLike.coe_injective p.gauge_ball
end AddCommGroup
section Seminormed
variable [SeminormedAddCommGroup E] [NormedSpace ℝ E] {s : Set E} {r : ℝ} {x : E}
open Metric
theorem gauge_unit_ball (x : E) : gauge (ball (0 : E) 1) x = ‖x‖ := by
rw [← ball_normSeminorm ℝ, Seminorm.gauge_ball, coe_normSeminorm]
theorem gauge_ball (hr : 0 ≤ r) (x : E) : gauge (ball (0 : E) r) x = ‖x‖ / r := by
rcases hr.eq_or_lt with rfl | hr
· simp
· rw [← smul_unitBall_of_pos hr, gauge_smul_left, Pi.smul_apply, gauge_unit_ball, smul_eq_mul,
abs_of_nonneg hr.le, div_eq_inv_mul]
simp_rw [mem_ball_zero_iff, norm_neg]
exact fun _ => id
@[simp]
theorem gauge_closure_zero : gauge (closure (0 : Set E)) = 0 := funext fun x ↦ by
simp only [← singleton_zero, gauge_def', mem_closure_zero_iff_norm, norm_smul, mul_eq_zero,
norm_eq_zero, inv_eq_zero]
rcases (norm_nonneg x).eq_or_gt with hx | hx
· convert csInf_Ioi (a := (0 : ℝ))
exact Set.ext fun r ↦ and_iff_left (.inr hx)
· convert Real.sInf_empty
exact eq_empty_of_forall_not_mem fun r ⟨hr₀, hr⟩ ↦ hx.ne' <| hr.resolve_left hr₀.out.ne'
@[simp]
theorem gauge_closedBall (hr : 0 ≤ r) (x : E) : gauge (closedBall (0 : E) r) x = ‖x‖ / r := by
rcases hr.eq_or_lt with rfl | hr'
· rw [div_zero, closedBall_zero', singleton_zero, gauge_closure_zero]; rfl
· apply le_antisymm
· rw [← gauge_ball hr]
exact gauge_mono (absorbent_ball_zero hr') ball_subset_closedBall x
· suffices ∀ᶠ R in 𝓝[>] r, ‖x‖ / R ≤ gauge (closedBall 0 r) x by
refine le_of_tendsto ?_ this
exact tendsto_const_nhds.div inf_le_left hr'.ne'
filter_upwards [self_mem_nhdsWithin] with R hR
rw [← gauge_ball (hr.trans hR.out.le)]
refine gauge_mono ?_ (closedBall_subset_ball hR) _
exact (absorbent_ball_zero hr').mono ball_subset_closedBall
theorem mul_gauge_le_norm (hs : Metric.ball (0 : E) r ⊆ s) : r * gauge s x ≤ ‖x‖ := by
obtain hr | hr := le_or_lt r 0
· exact (mul_nonpos_of_nonpos_of_nonneg hr <| gauge_nonneg _).trans (norm_nonneg _)
rw [mul_comm, ← le_div_iff₀ hr, ← gauge_ball hr.le]
exact gauge_mono (absorbent_ball_zero hr) hs x
theorem Convex.lipschitzWith_gauge {r : ℝ≥0} (hc : Convex ℝ s) (hr : 0 < r)
(hs : Metric.ball (0 : E) r ⊆ s) : LipschitzWith r⁻¹ (gauge s) :=
have : Absorbent ℝ (Metric.ball (0 : E) r) := absorbent_ball_zero hr
LipschitzWith.of_le_add_mul _ fun x y =>
calc
gauge s x = gauge s (y + (x - y)) := by simp
| _ ≤ gauge s y + gauge s (x - y) := gauge_add_le hc (this.mono hs) _ _
_ ≤ gauge s y + ‖x - y‖ / r :=
add_le_add_left ((gauge_mono this hs (x - y)).trans_eq (gauge_ball hr.le _)) _
_ = gauge s y + r⁻¹ * dist x y := by rw [dist_eq_norm, div_eq_inv_mul, NNReal.coe_inv]
theorem Convex.lipschitz_gauge (hc : Convex ℝ s) (h₀ : s ∈ 𝓝 (0 : E)) :
∃ K, LipschitzWith K (gauge s) :=
| Mathlib/Analysis/Convex/Gauge.lean | 576 | 582 |
/-
Copyright (c) 2017 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Stephen Morgan, Kim Morrison
-/
import Mathlib.CategoryTheory.Equivalence
/-!
# Opposite categories
We provide a category instance on `Cᵒᵖ`.
The morphisms `X ⟶ Y` are defined to be the morphisms `unop Y ⟶ unop X` in `C`.
Here `Cᵒᵖ` is an irreducible typeclass synonym for `C`
(it is the same one used in the algebra library).
We also provide various mechanisms for constructing opposite morphisms, functors,
and natural transformations.
Unfortunately, because we do not have a definitional equality `op (op X) = X`,
there are quite a few variations that are needed in practice.
-/
universe v₁ v₂ u₁ u₂
-- morphism levels before object levels. See note [CategoryTheory universes].
open Opposite
variable {C : Type u₁}
section Quiver
variable [Quiver.{v₁} C]
theorem Quiver.Hom.op_inj {X Y : C} :
Function.Injective (Quiver.Hom.op : (X ⟶ Y) → (Opposite.op Y ⟶ Opposite.op X)) := fun _ _ H =>
congr_arg Quiver.Hom.unop H
theorem Quiver.Hom.unop_inj {X Y : Cᵒᵖ} :
Function.Injective (Quiver.Hom.unop : (X ⟶ Y) → (Opposite.unop Y ⟶ Opposite.unop X)) :=
fun _ _ H => congr_arg Quiver.Hom.op H
@[simp]
theorem Quiver.Hom.unop_op {X Y : C} (f : X ⟶ Y) : f.op.unop = f :=
rfl
@[simp]
theorem Quiver.Hom.unop_op' {X Y : Cᵒᵖ} {x} :
@Quiver.Hom.unop C _ X Y no_index (Opposite.op (unop := x)) = x := rfl
@[simp]
theorem Quiver.Hom.op_unop {X Y : Cᵒᵖ} (f : X ⟶ Y) : f.unop.op = f :=
rfl
@[simp] theorem Quiver.Hom.unop_mk {X Y : Cᵒᵖ} (f : X ⟶ Y) : Quiver.Hom.unop {unop := f} = f := rfl
end Quiver
namespace CategoryTheory
variable [Category.{v₁} C]
/-- The opposite category. -/
@[stacks 001M]
instance Category.opposite : Category.{v₁} Cᵒᵖ where
comp f g := (g.unop ≫ f.unop).op
id X := (𝟙 (unop X)).op
@[simp, reassoc]
theorem op_comp {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g).op = g.op ≫ f.op :=
rfl
@[simp]
theorem op_id {X : C} : (𝟙 X).op = 𝟙 (op X) :=
rfl
@[simp, reassoc]
theorem unop_comp {X Y Z : Cᵒᵖ} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g).unop = g.unop ≫ f.unop :=
rfl
@[simp]
theorem unop_id {X : Cᵒᵖ} : (𝟙 X).unop = 𝟙 (unop X) :=
rfl
@[simp]
theorem unop_id_op {X : C} : (𝟙 (op X)).unop = 𝟙 X :=
rfl
@[simp]
theorem op_id_unop {X : Cᵒᵖ} : (𝟙 (unop X)).op = 𝟙 X :=
rfl
section
variable (C)
/-- The functor from the double-opposite of a category to the underlying category. -/
@[simps]
def unopUnop : Cᵒᵖᵒᵖ ⥤ C where
obj X := unop (unop X)
map f := f.unop.unop
/-- The functor from a category to its double-opposite. -/
@[simps]
def opOp : C ⥤ Cᵒᵖᵒᵖ where
obj X := op (op X)
map f := f.op.op
/-- The double opposite category is equivalent to the original. -/
@[simps]
def opOpEquivalence : Cᵒᵖᵒᵖ ≌ C where
functor := unopUnop C
inverse := opOp C
unitIso := Iso.refl (𝟭 Cᵒᵖᵒᵖ)
counitIso := Iso.refl (opOp C ⋙ unopUnop C)
instance : (opOp C).IsEquivalence :=
(opOpEquivalence C).isEquivalence_inverse
instance : (unopUnop C).IsEquivalence :=
(opOpEquivalence C).isEquivalence_functor
end
/-- If `f` is an isomorphism, so is `f.op` -/
instance isIso_op {X Y : C} (f : X ⟶ Y) [IsIso f] : IsIso f.op :=
⟨⟨(inv f).op, ⟨Quiver.Hom.unop_inj (by simp), Quiver.Hom.unop_inj (by simp)⟩⟩⟩
/-- If `f.op` is an isomorphism `f` must be too.
(This cannot be an instance as it would immediately loop!)
-/
theorem isIso_of_op {X Y : C} (f : X ⟶ Y) [IsIso f.op] : IsIso f :=
⟨⟨(inv f.op).unop, ⟨Quiver.Hom.op_inj (by simp), Quiver.Hom.op_inj (by simp)⟩⟩⟩
theorem isIso_op_iff {X Y : C} (f : X ⟶ Y) : IsIso f.op ↔ IsIso f :=
⟨fun _ => isIso_of_op _, fun _ => inferInstance⟩
theorem isIso_unop_iff {X Y : Cᵒᵖ} (f : X ⟶ Y) : IsIso f.unop ↔ IsIso f := by
rw [← isIso_op_iff f.unop, Quiver.Hom.op_unop]
instance isIso_unop {X Y : Cᵒᵖ} (f : X ⟶ Y) [IsIso f] : IsIso f.unop :=
(isIso_unop_iff _).2 inferInstance
@[simp]
theorem op_inv {X Y : C} (f : X ⟶ Y) [IsIso f] : (inv f).op = inv f.op := by
apply IsIso.eq_inv_of_hom_inv_id
rw [← op_comp, IsIso.inv_hom_id, op_id]
@[simp]
theorem unop_inv {X Y : Cᵒᵖ} (f : X ⟶ Y) [IsIso f] : (inv f).unop = inv f.unop := by
apply IsIso.eq_inv_of_hom_inv_id
rw [← unop_comp, IsIso.inv_hom_id, unop_id]
namespace Functor
section
variable {D : Type u₂} [Category.{v₂} D]
/-- The opposite of a functor, i.e. considering a functor `F : C ⥤ D` as a functor `Cᵒᵖ ⥤ Dᵒᵖ`.
In informal mathematics no distinction is made between these. -/
@[simps]
protected def op (F : C ⥤ D) : Cᵒᵖ ⥤ Dᵒᵖ where
obj X := op (F.obj (unop X))
map f := (F.map f.unop).op
/-- Given a functor `F : Cᵒᵖ ⥤ Dᵒᵖ` we can take the "unopposite" functor `F : C ⥤ D`.
In informal mathematics no distinction is made between these.
-/
@[simps]
protected def unop (F : Cᵒᵖ ⥤ Dᵒᵖ) : C ⥤ D where
obj X := unop (F.obj (op X))
map f := (F.map f.op).unop
/-- The isomorphism between `F.op.unop` and `F`. -/
@[simps!]
def opUnopIso (F : C ⥤ D) : F.op.unop ≅ F :=
NatIso.ofComponents fun _ => Iso.refl _
/-- The isomorphism between `F.unop.op` and `F`. -/
@[simps!]
def unopOpIso (F : Cᵒᵖ ⥤ Dᵒᵖ) : F.unop.op ≅ F :=
NatIso.ofComponents fun _ => Iso.refl _
variable (C D)
/-- Taking the opposite of a functor is functorial.
-/
@[simps]
def opHom : (C ⥤ D)ᵒᵖ ⥤ Cᵒᵖ ⥤ Dᵒᵖ where
obj F := (unop F).op
map α :=
{ app := fun X => (α.unop.app (unop X)).op
naturality := fun _ _ f => Quiver.Hom.unop_inj (α.unop.naturality f.unop).symm }
/-- Take the "unopposite" of a functor is functorial.
-/
@[simps]
def opInv : (Cᵒᵖ ⥤ Dᵒᵖ) ⥤ (C ⥤ D)ᵒᵖ where
obj F := op F.unop
map α :=
Quiver.Hom.op
{ app := fun X => (α.app (op X)).unop
naturality := fun _ _ f => Quiver.Hom.op_inj <| (α.naturality f.op).symm }
variable {C D}
/--
Another variant of the opposite of functor, turning a functor `C ⥤ Dᵒᵖ` into a functor `Cᵒᵖ ⥤ D`.
In informal mathematics no distinction is made.
-/
@[simps]
protected def leftOp (F : C ⥤ Dᵒᵖ) : Cᵒᵖ ⥤ D where
obj X := unop (F.obj (unop X))
map f := (F.map f.unop).unop
/--
Another variant of the opposite of functor, turning a functor `Cᵒᵖ ⥤ D` into a functor `C ⥤ Dᵒᵖ`.
In informal mathematics no distinction is made.
-/
@[simps]
protected def rightOp (F : Cᵒᵖ ⥤ D) : C ⥤ Dᵒᵖ where
obj X := op (F.obj (op X))
map f := (F.map f.op).op
lemma rightOp_map_unop {F : Cᵒᵖ ⥤ D} {X Y} (f : X ⟶ Y) :
(F.rightOp.map f).unop = F.map f.op := rfl
instance {F : C ⥤ D} [Full F] : Full F.op where
map_surjective f := ⟨(F.preimage f.unop).op, by simp⟩
instance {F : C ⥤ D} [Faithful F] : Faithful F.op where
map_injective h := Quiver.Hom.unop_inj <| by simpa using map_injective F (Quiver.Hom.op_inj h)
/-- If F is faithful then the right_op of F is also faithful. -/
instance rightOp_faithful {F : Cᵒᵖ ⥤ D} [Faithful F] : Faithful F.rightOp where
map_injective h := Quiver.Hom.op_inj (map_injective F (Quiver.Hom.op_inj h))
/-- If F is faithful then the left_op of F is also faithful. -/
instance leftOp_faithful {F : C ⥤ Dᵒᵖ} [Faithful F] : Faithful F.leftOp where
map_injective h := Quiver.Hom.unop_inj (map_injective F (Quiver.Hom.unop_inj h))
instance rightOp_full {F : Cᵒᵖ ⥤ D} [Full F] : Full F.rightOp where
map_surjective f := ⟨(F.preimage f.unop).unop, by simp⟩
instance leftOp_full {F : C ⥤ Dᵒᵖ} [Full F] : Full F.leftOp where
map_surjective f := ⟨(F.preimage f.op).op, by simp⟩
/-- The isomorphism between `F.leftOp.rightOp` and `F`. -/
@[simps!]
def leftOpRightOpIso (F : C ⥤ Dᵒᵖ) : F.leftOp.rightOp ≅ F :=
NatIso.ofComponents fun _ => Iso.refl _
/-- The isomorphism between `F.rightOp.leftOp` and `F`. -/
@[simps!]
def rightOpLeftOpIso (F : Cᵒᵖ ⥤ D) : F.rightOp.leftOp ≅ F :=
NatIso.ofComponents fun _ => Iso.refl _
/-- Whenever possible, it is advisable to use the isomorphism `rightOpLeftOpIso`
instead of this equality of functors. -/
theorem rightOp_leftOp_eq (F : Cᵒᵖ ⥤ D) : F.rightOp.leftOp = F := by
cases F
rfl
end
end Functor
namespace NatTrans
variable {D : Type u₂} [Category.{v₂} D]
section
variable {F G : C ⥤ D}
/-- The opposite of a natural transformation. -/
@[simps]
protected def op (α : F ⟶ G) : G.op ⟶ F.op where
app X := (α.app (unop X)).op
naturality X Y f := Quiver.Hom.unop_inj (by simp)
@[simp]
theorem op_id (F : C ⥤ D) : NatTrans.op (𝟙 F) = 𝟙 F.op :=
rfl
/-- The "unopposite" of a natural transformation. -/
@[simps]
protected def unop {F G : Cᵒᵖ ⥤ Dᵒᵖ} (α : F ⟶ G) : G.unop ⟶ F.unop where
app X := (α.app (op X)).unop
naturality X Y f := Quiver.Hom.op_inj (by simp)
@[simp]
theorem unop_id (F : Cᵒᵖ ⥤ Dᵒᵖ) : NatTrans.unop (𝟙 F) = 𝟙 F.unop :=
rfl
/-- Given a natural transformation `α : F.op ⟶ G.op`,
we can take the "unopposite" of each component obtaining a natural transformation `G ⟶ F`.
-/
@[simps]
protected def removeOp (α : F.op ⟶ G.op) : G ⟶ F where
app X := (α.app (op X)).unop
naturality X Y f :=
Quiver.Hom.op_inj <| by simpa only [Functor.op_map] using (α.naturality f.op).symm
@[simp]
theorem removeOp_id (F : C ⥤ D) : NatTrans.removeOp (𝟙 F.op) = 𝟙 F :=
rfl
/-- Given a natural transformation `α : F.unop ⟶ G.unop`, we can take the opposite of each
component obtaining a natural transformation `G ⟶ F`. -/
@[simps]
protected def removeUnop {F G : Cᵒᵖ ⥤ Dᵒᵖ} (α : F.unop ⟶ G.unop) : G ⟶ F where
app X := (α.app (unop X)).op
naturality X Y f :=
Quiver.Hom.unop_inj <| by simpa only [Functor.unop_map] using (α.naturality f.unop).symm
@[simp]
theorem removeUnop_id (F : Cᵒᵖ ⥤ Dᵒᵖ) : NatTrans.removeUnop (𝟙 F.unop) = 𝟙 F :=
rfl
end
section
variable {F G H : C ⥤ Dᵒᵖ}
/-- Given a natural transformation `α : F ⟶ G`, for `F G : C ⥤ Dᵒᵖ`,
taking `unop` of each component gives a natural transformation `G.leftOp ⟶ F.leftOp`.
-/
@[simps]
protected def leftOp (α : F ⟶ G) : G.leftOp ⟶ F.leftOp where
app X := (α.app (unop X)).unop
naturality X Y f := Quiver.Hom.op_inj (by simp)
@[simp]
theorem leftOp_id : NatTrans.leftOp (𝟙 F : F ⟶ F) = 𝟙 F.leftOp :=
rfl
@[simp]
theorem leftOp_comp (α : F ⟶ G) (β : G ⟶ H) : NatTrans.leftOp (α ≫ β) =
NatTrans.leftOp β ≫ NatTrans.leftOp α :=
rfl
/-- Given a natural transformation `α : F.leftOp ⟶ G.leftOp`, for `F G : C ⥤ Dᵒᵖ`,
taking `op` of each component gives a natural transformation `G ⟶ F`.
-/
@[simps]
protected def removeLeftOp (α : F.leftOp ⟶ G.leftOp) : G ⟶ F where
app X := (α.app (op X)).op
naturality X Y f :=
Quiver.Hom.unop_inj <| by simpa only [Functor.leftOp_map] using (α.naturality f.op).symm
@[simp]
theorem removeLeftOp_id : NatTrans.removeLeftOp (𝟙 F.leftOp) = 𝟙 F :=
rfl
end
section
variable {F G H : Cᵒᵖ ⥤ D}
/-- Given a natural transformation `α : F ⟶ G`, for `F G : Cᵒᵖ ⥤ D`,
taking `op` of each component gives a natural transformation `G.rightOp ⟶ F.rightOp`.
-/
@[simps]
protected def rightOp (α : F ⟶ G) : G.rightOp ⟶ F.rightOp where
app _ := (α.app _).op
naturality X Y f := Quiver.Hom.unop_inj (by simp)
@[simp]
theorem rightOp_id : NatTrans.rightOp (𝟙 F : F ⟶ F) = 𝟙 F.rightOp :=
rfl
@[simp]
theorem rightOp_comp (α : F ⟶ G) (β : G ⟶ H) : NatTrans.rightOp (α ≫ β) =
NatTrans.rightOp β ≫ NatTrans.rightOp α :=
rfl
/-- Given a natural transformation `α : F.rightOp ⟶ G.rightOp`, for `F G : Cᵒᵖ ⥤ D`,
taking `unop` of each component gives a natural transformation `G ⟶ F`.
-/
@[simps]
protected def removeRightOp (α : F.rightOp ⟶ G.rightOp) : G ⟶ F where
app X := (α.app X.unop).unop
naturality X Y f :=
Quiver.Hom.op_inj <| by simpa only [Functor.rightOp_map] using (α.naturality f.unop).symm
@[simp]
theorem removeRightOp_id : NatTrans.removeRightOp (𝟙 F.rightOp) = 𝟙 F :=
rfl
end
end NatTrans
namespace Iso
variable {X Y : C}
/-- The opposite isomorphism.
-/
@[simps]
protected def op (α : X ≅ Y) : op Y ≅ op X where
hom := α.hom.op
inv := α.inv.op
hom_inv_id := Quiver.Hom.unop_inj α.inv_hom_id
inv_hom_id := Quiver.Hom.unop_inj α.hom_inv_id
/-- The isomorphism obtained from an isomorphism in the opposite category. -/
@[simps]
def unop {X Y : Cᵒᵖ} (f : X ≅ Y) : Y.unop ≅ X.unop where
hom := f.hom.unop
inv := f.inv.unop
hom_inv_id := by simp only [← unop_comp, f.inv_hom_id, unop_id]
inv_hom_id := by simp only [← unop_comp, f.hom_inv_id, unop_id]
@[simp]
theorem unop_op {X Y : Cᵒᵖ} (f : X ≅ Y) : f.unop.op = f := by (ext; rfl)
@[simp]
theorem op_unop {X Y : C} (f : X ≅ Y) : f.op.unop = f := by (ext; rfl)
section
variable {D : Type*} [Category D] {F G : C ⥤ Dᵒᵖ} (e : F ≅ G) (X : C)
@[reassoc (attr := simp)]
lemma unop_hom_inv_id_app : (e.hom.app X).unop ≫ (e.inv.app X).unop = 𝟙 _ := by
rw [← unop_comp, inv_hom_id_app, unop_id]
@[reassoc (attr := simp)]
lemma unop_inv_hom_id_app : (e.inv.app X).unop ≫ (e.hom.app X).unop = 𝟙 _ := by
rw [← unop_comp, hom_inv_id_app, unop_id]
end
end Iso
namespace NatIso
variable {D : Type u₂} [Category.{v₂} D]
variable {F G : C ⥤ D}
/-- The natural isomorphism between opposite functors `G.op ≅ F.op` induced by a natural
isomorphism between the original functors `F ≅ G`. -/
@[simps]
protected def op (α : F ≅ G) : G.op ≅ F.op where
hom := NatTrans.op α.hom
inv := NatTrans.op α.inv
hom_inv_id := by ext; dsimp; rw [← op_comp]; rw [α.inv_hom_id_app]; rfl
inv_hom_id := by ext; dsimp; rw [← op_comp]; rw [α.hom_inv_id_app]; rfl
/-- The natural isomorphism between functors `G ≅ F` induced by a natural isomorphism
between the opposite functors `F.op ≅ G.op`. -/
@[simps]
protected def removeOp (α : F.op ≅ G.op) : G ≅ F where
hom := NatTrans.removeOp α.hom
inv := NatTrans.removeOp α.inv
/-- The natural isomorphism between functors `G.unop ≅ F.unop` induced by a natural isomorphism
between the original functors `F ≅ G`. -/
@[simps]
protected def unop {F G : Cᵒᵖ ⥤ Dᵒᵖ} (α : F ≅ G) : G.unop ≅ F.unop where
hom := NatTrans.unop α.hom
inv := NatTrans.unop α.inv
end NatIso
namespace Equivalence
variable {D : Type u₂} [Category.{v₂} D]
/-- An equivalence between categories gives an equivalence between the opposite categories.
-/
@[simps]
def op (e : C ≌ D) : Cᵒᵖ ≌ Dᵒᵖ where
functor := e.functor.op
inverse := e.inverse.op
unitIso := (NatIso.op e.unitIso).symm
counitIso := (NatIso.op e.counitIso).symm
functor_unitIso_comp X := by
apply Quiver.Hom.unop_inj
dsimp
simp
|
/-- An equivalence between opposite categories gives an equivalence between the original categories.
-/
| Mathlib/CategoryTheory/Opposites.lean | 488 | 490 |
/-
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,149 | 2,151 | |
/-
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.Order.ConditionallyCompleteLattice.Group
import Mathlib.Topology.MetricSpace.Isometry
/-!
# Metric space gluing
Gluing two metric spaces along a common subset. Formally, we are given
```
Φ
Z ---> X
|
|Ψ
v
Y
```
where `hΦ : Isometry Φ` and `hΨ : Isometry Ψ`.
We want to complete the square by a space `GlueSpacescan hΦ hΨ` and two isometries
`toGlueL hΦ hΨ` and `toGlueR hΦ hΨ` that make the square commute.
We start by defining a predistance on the disjoint union `X ⊕ Y`, for which
points `Φ p` and `Ψ p` are at distance 0. The (quotient) metric space associated
to this predistance is the desired space.
This is an instance of a more general construction, where `Φ` and `Ψ` do not have to be isometries,
but the distances in the image almost coincide, up to `2ε` say. Then one can almost glue the two
spaces so that the images of a point under `Φ` and `Ψ` are `ε`-close. If `ε > 0`, this yields a
metric space structure on `X ⊕ Y`, without the need to take a quotient. In particular,
this gives a natural metric space structure on `X ⊕ Y`, where the basepoints
are at distance 1, say, and the distances between other points are obtained by going through the two
basepoints.
(We also register the same metric space structure on a general disjoint union `Σ i, E i`).
We also define the inductive limit of metric spaces. Given
```
f 0 f 1 f 2 f 3
X 0 -----> X 1 -----> X 2 -----> X 3 -----> ...
```
where the `X n` are metric spaces and `f n` isometric embeddings, we define the inductive
limit of the `X n`, also known as the increasing union of the `X n` in this context, if we
identify `X n` and `X (n+1)` through `f n`. This is a metric space in which all `X n` embed
isometrically and in a way compatible with `f n`.
-/
noncomputable section
universe u v w
open Function Set Uniformity Topology
namespace Metric
section ApproxGluing
variable {X : Type u} {Y : Type v} {Z : Type w}
variable [MetricSpace X] [MetricSpace Y] {Φ : Z → X} {Ψ : Z → Y} {ε : ℝ}
/-- Define a predistance on `X ⊕ Y`, for which `Φ p` and `Ψ p` are at distance `ε` -/
def glueDist (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) : X ⊕ Y → X ⊕ Y → ℝ
| .inl x, .inl y => dist x y
| .inr x, .inr y => dist x y
| .inl x, .inr y => (⨅ p, dist x (Φ p) + dist y (Ψ p)) + ε
| .inr x, .inl y => (⨅ p, dist y (Φ p) + dist x (Ψ p)) + ε
private theorem glueDist_self (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) : ∀ x, glueDist Φ Ψ ε x x = 0
| .inl _ => dist_self _
| .inr _ => dist_self _
theorem glueDist_glued_points [Nonempty Z] (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (p : Z) :
glueDist Φ Ψ ε (.inl (Φ p)) (.inr (Ψ p)) = ε := by
have : ⨅ q, dist (Φ p) (Φ q) + dist (Ψ p) (Ψ q) = 0 := by
have A : ∀ q, 0 ≤ dist (Φ p) (Φ q) + dist (Ψ p) (Ψ q) := fun _ =>
add_nonneg dist_nonneg dist_nonneg
refine le_antisymm ?_ (le_ciInf A)
have : 0 = dist (Φ p) (Φ p) + dist (Ψ p) (Ψ p) := by simp
rw [this]
exact ciInf_le ⟨0, forall_mem_range.2 A⟩ p
simp only [glueDist, this, zero_add]
private theorem glueDist_comm (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) :
∀ x y, glueDist Φ Ψ ε x y = glueDist Φ Ψ ε y x
| .inl _, .inl _ => dist_comm _ _
| .inr _, .inr _ => dist_comm _ _
| .inl _, .inr _ => rfl
| .inr _, .inl _ => rfl
theorem glueDist_swap (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) :
∀ x y, glueDist Ψ Φ ε x.swap y.swap = glueDist Φ Ψ ε x y
| .inl _, .inl _ => rfl
| .inr _, .inr _ => rfl
| .inl _, .inr _ => by simp only [glueDist, Sum.swap_inl, Sum.swap_inr, dist_comm, add_comm]
| .inr _, .inl _ => by simp only [glueDist, Sum.swap_inl, Sum.swap_inr, dist_comm, add_comm]
theorem le_glueDist_inl_inr (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (x y) :
ε ≤ glueDist Φ Ψ ε (.inl x) (.inr y) :=
le_add_of_nonneg_left <| Real.iInf_nonneg fun _ => add_nonneg dist_nonneg dist_nonneg
theorem le_glueDist_inr_inl (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (x y) :
ε ≤ glueDist Φ Ψ ε (.inr x) (.inl y) := by
rw [glueDist_comm]; apply le_glueDist_inl_inr
section
variable [Nonempty Z]
private theorem glueDist_triangle_inl_inr_inr (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (x : X) (y z : Y) :
glueDist Φ Ψ ε (.inl x) (.inr z) ≤
glueDist Φ Ψ ε (.inl x) (.inr y) + glueDist Φ Ψ ε (.inr y) (.inr z) := by
simp only [glueDist]
rw [add_right_comm, add_le_add_iff_right]
refine le_ciInf_add fun p => ciInf_le_of_le ⟨0, ?_⟩ p ?_
· exact forall_mem_range.2 fun _ => add_nonneg dist_nonneg dist_nonneg
· linarith [dist_triangle_left z (Ψ p) y]
private theorem glueDist_triangle_inl_inr_inl (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ)
(H : ∀ p q, |dist (Φ p) (Φ q) - dist (Ψ p) (Ψ q)| ≤ 2 * ε) (x : X) (y : Y) (z : X) :
glueDist Φ Ψ ε (.inl x) (.inl z) ≤
glueDist Φ Ψ ε (.inl x) (.inr y) + glueDist Φ Ψ ε (.inr y) (.inl z) := by
simp_rw [glueDist, add_add_add_comm _ ε, add_assoc]
refine le_ciInf_add fun p => ?_
rw [add_left_comm, add_assoc, ← two_mul]
refine le_ciInf_add fun q => ?_
rw [dist_comm z]
linarith [dist_triangle4 x (Φ p) (Φ q) z, dist_triangle_left (Ψ p) (Ψ q) y, (abs_le.1 (H p q)).2]
private theorem glueDist_triangle (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ)
(H : ∀ p q, |dist (Φ p) (Φ q) - dist (Ψ p) (Ψ q)| ≤ 2 * ε) :
∀ x y z, glueDist Φ Ψ ε x z ≤ glueDist Φ Ψ ε x y + glueDist Φ Ψ ε y z
| .inl _, .inl _, .inl _ => dist_triangle _ _ _
| .inr _, .inr _, .inr _ => dist_triangle _ _ _
| .inr x, .inl y, .inl z => by
simp only [← glueDist_swap Φ]
apply glueDist_triangle_inl_inr_inr
| .inr x, .inr y, .inl z => by
simpa only [glueDist_comm, add_comm] using glueDist_triangle_inl_inr_inr _ _ _ z y x
| .inl x, .inl y, .inr z => by
simpa only [← glueDist_swap Φ, glueDist_comm, add_comm, Sum.swap_inl, Sum.swap_inr]
using glueDist_triangle_inl_inr_inr Ψ Φ ε z y x
| .inl _, .inr _, .inr _ => glueDist_triangle_inl_inr_inr ..
| .inl x, .inr y, .inl z => glueDist_triangle_inl_inr_inl Φ Ψ ε H x y z
| .inr x, .inl y, .inr z => by
simp only [← glueDist_swap Φ]
apply glueDist_triangle_inl_inr_inl
simpa only [abs_sub_comm]
end
private theorem eq_of_glueDist_eq_zero (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (ε0 : 0 < ε) :
∀ p q : X ⊕ Y, glueDist Φ Ψ ε p q = 0 → p = q
| .inl x, .inl y, h => by rw [eq_of_dist_eq_zero h]
| .inl x, .inr y, h => by exfalso; linarith [le_glueDist_inl_inr Φ Ψ ε x y]
| .inr x, .inl y, h => by exfalso; linarith [le_glueDist_inr_inl Φ Ψ ε x y]
| .inr x, .inr y, h => by rw [eq_of_dist_eq_zero h]
theorem Sum.mem_uniformity_iff_glueDist (hε : 0 < ε) (s : Set ((X ⊕ Y) × (X ⊕ Y))) :
s ∈ 𝓤 (X ⊕ Y) ↔ ∃ δ > 0, ∀ a b, glueDist Φ Ψ ε a b < δ → (a, b) ∈ s := by
simp only [Sum.uniformity, Filter.mem_sup, Filter.mem_map, mem_uniformity_dist, mem_preimage]
constructor
· rintro ⟨⟨δX, δX0, hX⟩, δY, δY0, hY⟩
refine ⟨min (min δX δY) ε, lt_min (lt_min δX0 δY0) hε, ?_⟩
rintro (a | a) (b | b) h <;> simp only [lt_min_iff] at h
· exact hX h.1.1
· exact absurd h.2 (le_glueDist_inl_inr _ _ _ _ _).not_lt
· exact absurd h.2 (le_glueDist_inr_inl _ _ _ _ _).not_lt
· exact hY h.1.2
· rintro ⟨ε, ε0, H⟩
constructor <;> exact ⟨ε, ε0, fun _ _ h => H _ _ h⟩
/-- Given two maps `Φ` and `Ψ` intro metric spaces `X` and `Y` such that the distances between
`Φ p` and `Φ q`, and between `Ψ p` and `Ψ q`, coincide up to `2 ε` where `ε > 0`, one can almost
glue the two spaces `X` and `Y` along the images of `Φ` and `Ψ`, so that `Φ p` and `Ψ p` are
at distance `ε`. -/
def glueMetricApprox [Nonempty Z] (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (ε0 : 0 < ε)
(H : ∀ p q, |dist (Φ p) (Φ q) - dist (Ψ p) (Ψ q)| ≤ 2 * ε) : MetricSpace (X ⊕ Y) where
dist := glueDist Φ Ψ ε
dist_self := glueDist_self Φ Ψ ε
dist_comm := glueDist_comm Φ Ψ ε
dist_triangle := glueDist_triangle Φ Ψ ε H
eq_of_dist_eq_zero := eq_of_glueDist_eq_zero Φ Ψ ε ε0 _ _
toUniformSpace := Sum.instUniformSpace
uniformity_dist := uniformity_dist_of_mem_uniformity _ _ <| Sum.mem_uniformity_iff_glueDist ε0
end ApproxGluing
section Sum
/-!
### Metric on `X ⊕ Y`
A particular case of the previous construction is when one uses basepoints in `X` and `Y` and one
glues only along the basepoints, putting them at distance 1. We give a direct definition of
the distance, without `iInf`, as it is easier to use in applications, and show that it is equal to
the gluing distance defined above to take advantage of the lemmas we have already proved.
-/
variable {X : Type u} {Y : Type v} {Z : Type w}
variable [MetricSpace X] [MetricSpace Y]
/-- Distance on a disjoint union. There are many (noncanonical) ways to put a distance compatible
with each factor.
If the two spaces are bounded, one can say for instance that each point in the first is at distance
`diam X + diam Y + 1` of each point in the second.
Instead, we choose a construction that works for unbounded spaces, but requires basepoints,
chosen arbitrarily.
We embed isometrically each factor, set the basepoints at distance 1,
arbitrarily, and say that the distance from `a` to `b` is the sum of the distances of `a` and `b` to
their respective basepoints, plus the distance 1 between the basepoints.
Since there is an arbitrary choice in this construction, it is not an instance by default. -/
protected def Sum.dist : X ⊕ Y → X ⊕ Y → ℝ
| .inl a, .inl a' => dist a a'
| .inr b, .inr b' => dist b b'
| .inl a, .inr b => dist a (Nonempty.some ⟨a⟩) + 1 + dist (Nonempty.some ⟨b⟩) b
| .inr b, .inl a => dist b (Nonempty.some ⟨b⟩) + 1 + dist (Nonempty.some ⟨a⟩) a
theorem Sum.dist_eq_glueDist {p q : X ⊕ Y} (x : X) (y : Y) :
Sum.dist p q =
glueDist (fun _ : Unit => Nonempty.some ⟨x⟩) (fun _ : Unit => Nonempty.some ⟨y⟩) 1 p q := by
cases p <;> cases q <;> first |rfl|simp [Sum.dist, glueDist, dist_comm, add_comm,
add_left_comm, add_assoc]
private theorem Sum.dist_comm (x y : X ⊕ Y) : Sum.dist x y = Sum.dist y x := by
cases x <;> cases y <;> simp [Sum.dist, _root_.dist_comm, add_comm, add_left_comm, add_assoc]
theorem Sum.one_le_dist_inl_inr {x : X} {y : Y} : 1 ≤ Sum.dist (.inl x) (.inr y) :=
le_trans (le_add_of_nonneg_right dist_nonneg) <|
add_le_add_right (le_add_of_nonneg_left dist_nonneg) _
theorem Sum.one_le_dist_inr_inl {x : X} {y : Y} : 1 ≤ Sum.dist (.inr y) (.inl x) := by
rw [Sum.dist_comm]; exact Sum.one_le_dist_inl_inr
private theorem Sum.mem_uniformity (s : Set ((X ⊕ Y) × (X ⊕ Y))) :
s ∈ 𝓤 (X ⊕ Y) ↔ ∃ ε > 0, ∀ a b, Sum.dist a b < ε → (a, b) ∈ s := by
constructor
· rintro ⟨hsX, hsY⟩
rcases mem_uniformity_dist.1 hsX with ⟨εX, εX0, hX⟩
rcases mem_uniformity_dist.1 hsY with ⟨εY, εY0, hY⟩
refine ⟨min (min εX εY) 1, lt_min (lt_min εX0 εY0) zero_lt_one, ?_⟩
rintro (a | a) (b | b) h
· exact hX (lt_of_lt_of_le h (le_trans (min_le_left _ _) (min_le_left _ _)))
· cases not_le_of_lt (lt_of_lt_of_le h (min_le_right _ _)) Sum.one_le_dist_inl_inr
· cases not_le_of_lt (lt_of_lt_of_le h (min_le_right _ _)) Sum.one_le_dist_inr_inl
· exact hY (lt_of_lt_of_le h (le_trans (min_le_left _ _) (min_le_right _ _)))
· rintro ⟨ε, ε0, H⟩
constructor <;> rw [Filter.mem_map, mem_uniformity_dist] <;> exact ⟨ε, ε0, fun _ _ h => H _ _ h⟩
/-- The distance on the disjoint union indeed defines a metric space. All the distance properties
follow from our choice of the distance. The harder work is to show that the uniform structure
defined by the distance coincides with the disjoint union uniform structure. -/
def metricSpaceSum : MetricSpace (X ⊕ Y) where
dist := Sum.dist
dist_self x := by cases x <;> simp only [Sum.dist, dist_self]
dist_comm := Sum.dist_comm
dist_triangle
| .inl p, .inl q, .inl r => dist_triangle p q r
| .inl p, .inr q, _ => by
simp only [Sum.dist_eq_glueDist p q]
exact glueDist_triangle _ _ _ (by norm_num) _ _ _
| _, .inl q, .inr r => by
simp only [Sum.dist_eq_glueDist q r]
exact glueDist_triangle _ _ _ (by norm_num) _ _ _
| .inr p, _, .inl r => by
simp only [Sum.dist_eq_glueDist r p]
exact glueDist_triangle _ _ _ (by norm_num) _ _ _
| .inr p, .inr q, .inr r => dist_triangle p q r
eq_of_dist_eq_zero {p q} h := by
rcases p with p | p <;> rcases q with q | q
· rw [eq_of_dist_eq_zero h]
· exact eq_of_glueDist_eq_zero _ _ _ one_pos _ _ ((Sum.dist_eq_glueDist p q).symm.trans h)
· exact eq_of_glueDist_eq_zero _ _ _ one_pos _ _ ((Sum.dist_eq_glueDist q p).symm.trans h)
· rw [eq_of_dist_eq_zero h]
toUniformSpace := Sum.instUniformSpace
uniformity_dist := uniformity_dist_of_mem_uniformity _ _ Sum.mem_uniformity
attribute [local instance] metricSpaceSum
theorem Sum.dist_eq {x y : X ⊕ Y} : dist x y = Sum.dist x y := rfl
/-- The left injection of a space in a disjoint union is an isometry -/
theorem isometry_inl : Isometry (Sum.inl : X → X ⊕ Y) :=
Isometry.of_dist_eq fun _ _ => rfl
/-- The right injection of a space in a disjoint union is an isometry -/
theorem isometry_inr : Isometry (Sum.inr : Y → X ⊕ Y) :=
Isometry.of_dist_eq fun _ _ => rfl
end Sum
namespace Sigma
/- Copy of the previous paragraph, but for arbitrary disjoint unions instead of the disjoint union
of two spaces. I.e., work with sigma types instead of sum types. -/
variable {ι : Type*} {E : ι → Type*} [∀ i, MetricSpace (E i)]
open Classical in
/-- Distance on a disjoint union. There are many (noncanonical) ways to put a distance compatible
with each factor.
We choose a construction that works for unbounded spaces, but requires basepoints,
chosen arbitrarily.
We embed isometrically each factor, set the basepoints at distance 1, arbitrarily,
and say that the distance from `a` to `b` is the sum of the distances of `a` and `b` to
their respective basepoints, plus the distance 1 between the basepoints.
Since there is an arbitrary choice in this construction, it is not an instance by default. -/
protected def dist : (Σ i, E i) → (Σ i, E i) → ℝ
| ⟨i, x⟩, ⟨j, y⟩ =>
if h : i = j then
haveI : E j = E i := by rw [h]
Dist.dist x (cast this y)
else Dist.dist x (Nonempty.some ⟨x⟩) + 1 + Dist.dist (Nonempty.some ⟨y⟩) y
/-- A `Dist` instance on the disjoint union `Σ i, E i`.
We embed isometrically each factor, set the basepoints at distance 1, arbitrarily,
and say that the distance from `a` to `b` is the sum of the distances of `a` and `b` to
their respective basepoints, plus the distance 1 between the basepoints.
Since there is an arbitrary choice in this construction, it is not an instance by default. -/
def instDist : Dist (Σ i, E i) :=
⟨Sigma.dist⟩
attribute [local instance] Sigma.instDist
@[simp]
theorem dist_same (i : ι) (x y : E i) : dist (Sigma.mk i x) ⟨i, y⟩ = dist x y := by
simp [Dist.dist, Sigma.dist]
@[simp]
theorem dist_ne {i j : ι} (h : i ≠ j) (x : E i) (y : E j) :
dist (⟨i, x⟩ : Σk, E k) ⟨j, y⟩ = dist x (Nonempty.some ⟨x⟩) + 1 + dist (Nonempty.some ⟨y⟩) y :=
dif_neg h
theorem one_le_dist_of_ne {i j : ι} (h : i ≠ j) (x : E i) (y : E j) :
1 ≤ dist (⟨i, x⟩ : Σk, E k) ⟨j, y⟩ := by
rw [Sigma.dist_ne h x y]
linarith [@dist_nonneg _ _ x (Nonempty.some ⟨x⟩), @dist_nonneg _ _ (Nonempty.some ⟨y⟩) y]
theorem fst_eq_of_dist_lt_one (x y : Σ i, E i) (h : dist x y < 1) : x.1 = y.1 := by
cases x; cases y
contrapose! h
apply one_le_dist_of_ne h
protected theorem dist_triangle (x y z : Σ i, E i) : dist x z ≤ dist x y + dist y z := by
rcases x with ⟨i, x⟩; rcases y with ⟨j, y⟩; rcases z with ⟨k, z⟩
rcases eq_or_ne i k with (rfl | hik)
· rcases eq_or_ne i j with (rfl | hij)
· simpa using dist_triangle x y z
· simp only [Sigma.dist_same, Sigma.dist_ne hij, Sigma.dist_ne hij.symm]
calc
dist x z ≤ dist x (Nonempty.some ⟨x⟩) + 0 + 0 + (0 + 0 + dist (Nonempty.some ⟨z⟩) z) := by
simpa only [zero_add, add_zero] using dist_triangle _ _ _
_ ≤ _ := by apply_rules [add_le_add, le_rfl, dist_nonneg, zero_le_one]
· rcases eq_or_ne i j with (rfl | hij)
· simp only [Sigma.dist_ne hik, Sigma.dist_same]
calc
dist x (Nonempty.some ⟨x⟩) + 1 + dist (Nonempty.some ⟨z⟩) z ≤
dist x y + dist y (Nonempty.some ⟨y⟩) + 1 + dist (Nonempty.some ⟨z⟩) z := by
apply_rules [add_le_add, le_rfl, dist_triangle]
_ = _ := by abel
· rcases eq_or_ne j k with (rfl | hjk)
· simp only [Sigma.dist_ne hij, Sigma.dist_same]
calc
dist x (Nonempty.some ⟨x⟩) + 1 + dist (Nonempty.some ⟨z⟩) z ≤
dist x (Nonempty.some ⟨x⟩) + 1 + (dist (Nonempty.some ⟨z⟩) y + dist y z) := by
apply_rules [add_le_add, le_rfl, dist_triangle]
_ = _ := by abel
· simp only [hik, hij, hjk, Sigma.dist_ne, Ne, not_false_iff]
calc
dist x (Nonempty.some ⟨x⟩) + 1 + dist (Nonempty.some ⟨z⟩) z =
dist x (Nonempty.some ⟨x⟩) + 1 + 0 + (0 + 0 + dist (Nonempty.some ⟨z⟩) z) := by
simp only [add_zero, zero_add]
_ ≤ _ := by apply_rules [add_le_add, zero_le_one, dist_nonneg, le_rfl]
protected theorem isOpen_iff (s : Set (Σ i, E i)) :
IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ∀ y, dist x y < ε → y ∈ s := by
constructor
· rintro hs ⟨i, x⟩ hx
obtain ⟨ε, εpos, hε⟩ : ∃ ε > 0, ball x ε ⊆ Sigma.mk i ⁻¹' s :=
Metric.isOpen_iff.1 (isOpen_sigma_iff.1 hs i) x hx
refine ⟨min ε 1, lt_min εpos zero_lt_one, ?_⟩
rintro ⟨j, y⟩ hy
rcases eq_or_ne i j with (rfl | hij)
· simp only [Sigma.dist_same, lt_min_iff] at hy
exact hε (mem_ball'.2 hy.1)
· apply (lt_irrefl (1 : ℝ) _).elim
calc
1 ≤ Sigma.dist ⟨i, x⟩ ⟨j, y⟩ := Sigma.one_le_dist_of_ne hij _ _
_ < 1 := hy.trans_le (min_le_right _ _)
· refine fun H => isOpen_sigma_iff.2 fun i => Metric.isOpen_iff.2 fun x hx => ?_
obtain ⟨ε, εpos, hε⟩ : ∃ ε > 0, ∀ y, dist (⟨i, x⟩ : Σj, E j) y < ε → y ∈ s :=
H ⟨i, x⟩ hx
refine ⟨ε, εpos, fun y hy => ?_⟩
apply hε ⟨i, y⟩
rw [Sigma.dist_same]
exact mem_ball'.1 hy
/-- A metric space structure on the disjoint union `Σ i, E i`.
We embed isometrically each factor, set the basepoints at distance 1, arbitrarily,
and say that the distance from `a` to `b` is the sum of the distances of `a` and `b` to
their respective basepoints, plus the distance 1 between the basepoints.
Since there is an arbitrary choice in this construction, it is not an instance by default. -/
protected def metricSpace : MetricSpace (Σ i, E i) := by
refine MetricSpace.ofDistTopology Sigma.dist ?_ ?_ Sigma.dist_triangle Sigma.isOpen_iff ?_
· rintro ⟨i, x⟩
simp [Sigma.dist]
· rintro ⟨i, x⟩ ⟨j, y⟩
rcases eq_or_ne i j with (rfl | h)
· simp [Sigma.dist, dist_comm]
· simp only [Sigma.dist, dist_comm, h, h.symm, not_false_iff, dif_neg]
abel
· rintro ⟨i, x⟩ ⟨j, y⟩
rcases eq_or_ne i j with (rfl | hij)
· simp [Sigma.dist]
· intro h
apply (lt_irrefl (1 : ℝ) _).elim
calc
1 ≤ Sigma.dist (⟨i, x⟩ : Σk, E k) ⟨j, y⟩ := Sigma.one_le_dist_of_ne hij _ _
_ < 1 := by rw [h]; exact zero_lt_one
attribute [local instance] Sigma.metricSpace
open Topology
open Filter
/-- The injection of a space in a disjoint union is an isometry -/
theorem isometry_mk (i : ι) : Isometry (Sigma.mk i : E i → Σk, E k) :=
Isometry.of_dist_eq fun x y => by simp
/-- A disjoint union of complete metric spaces is complete. -/
protected theorem completeSpace [∀ i, CompleteSpace (E i)] : CompleteSpace (Σ i, E i) := by
set s : ι → Set (Σ i, E i) := fun i => Sigma.fst ⁻¹' {i}
set U := { p : (Σk, E k) × Σk, E k | dist p.1 p.2 < 1 }
have hc : ∀ i, IsComplete (s i) := fun i => by
simp only [s, ← range_sigmaMk]
exact (isometry_mk i).isUniformInducing.isComplete_range
have hd : ∀ (i j), ∀ x ∈ s i, ∀ y ∈ s j, (x, y) ∈ U → i = j := fun i j x hx y hy hxy =>
(Eq.symm hx).trans ((fst_eq_of_dist_lt_one _ _ hxy).trans hy)
refine completeSpace_of_isComplete_univ ?_
convert isComplete_iUnion_separated hc (dist_mem_uniformity zero_lt_one) hd
simp only [s, ← preimage_iUnion, iUnion_of_singleton, preimage_univ]
end Sigma
section Gluing
-- Exact gluing of two metric spaces along isometric subsets.
variable {X : Type u} {Y : Type v} {Z : Type w}
variable [Nonempty Z] [MetricSpace Z] [MetricSpace X] [MetricSpace Y] {Φ : Z → X} {Ψ : Z → Y}
{ε : ℝ}
/-- Given two isometric embeddings `Φ : Z → X` and `Ψ : Z → Y`, we define a pseudo metric space
structure on `X ⊕ Y` by declaring that `Φ x` and `Ψ x` are at distance `0`. -/
def gluePremetric (hΦ : Isometry Φ) (hΨ : Isometry Ψ) : PseudoMetricSpace (X ⊕ Y) where
dist := glueDist Φ Ψ 0
dist_self := glueDist_self Φ Ψ 0
dist_comm := glueDist_comm Φ Ψ 0
dist_triangle := glueDist_triangle Φ Ψ 0 fun p q => by rw [hΦ.dist_eq, hΨ.dist_eq]; simp
/-- Given two isometric embeddings `Φ : Z → X` and `Ψ : Z → Y`, we define a
space `GlueSpace hΦ hΨ` by identifying in `X ⊕ Y` the points `Φ x` and `Ψ x`. -/
def GlueSpace (hΦ : Isometry Φ) (hΨ : Isometry Ψ) : Type _ :=
@SeparationQuotient _ (gluePremetric hΦ hΨ).toUniformSpace.toTopologicalSpace
instance (hΦ : Isometry Φ) (hΨ : Isometry Ψ) : MetricSpace (GlueSpace hΦ hΨ) :=
inferInstanceAs <| MetricSpace <|
@SeparationQuotient _ (gluePremetric hΦ hΨ).toUniformSpace.toTopologicalSpace
/-- The canonical map from `X` to the space obtained by gluing isometric subsets in `X` and `Y`. -/
def toGlueL (hΦ : Isometry Φ) (hΨ : Isometry Ψ) (x : X) : GlueSpace hΦ hΨ :=
Quotient.mk'' (.inl x)
/-- The canonical map from `Y` to the space obtained by gluing isometric subsets in `X` and `Y`. -/
def toGlueR (hΦ : Isometry Φ) (hΨ : Isometry Ψ) (y : Y) : GlueSpace hΦ hΨ :=
Quotient.mk'' (.inr y)
instance inhabitedLeft (hΦ : Isometry Φ) (hΨ : Isometry Ψ) [Inhabited X] :
Inhabited (GlueSpace hΦ hΨ) :=
⟨toGlueL _ _ default⟩
instance inhabitedRight (hΦ : Isometry Φ) (hΨ : Isometry Ψ) [Inhabited Y] :
Inhabited (GlueSpace hΦ hΨ) :=
⟨toGlueR _ _ default⟩
theorem toGlue_commute (hΦ : Isometry Φ) (hΨ : Isometry Ψ) :
toGlueL hΦ hΨ ∘ Φ = toGlueR hΦ hΨ ∘ Ψ := by
let i : PseudoMetricSpace (X ⊕ Y) := gluePremetric hΦ hΨ
let _ := i.toUniformSpace.toTopologicalSpace
funext
simp only [comp, toGlueL, toGlueR]
refine SeparationQuotient.mk_eq_mk.2 (Metric.inseparable_iff.2 ?_)
exact glueDist_glued_points Φ Ψ 0 _
theorem toGlueL_isometry (hΦ : Isometry Φ) (hΨ : Isometry Ψ) : Isometry (toGlueL hΦ hΨ) :=
Isometry.of_dist_eq fun _ _ => rfl
theorem toGlueR_isometry (hΦ : Isometry Φ) (hΨ : Isometry Ψ) : Isometry (toGlueR hΦ hΨ) :=
Isometry.of_dist_eq fun _ _ => rfl
end Gluing
--section
section InductiveLimit
/-!
### Inductive limit of metric spaces
In this section, we define the inductive limit of
```
f 0 f 1 f 2 f 3
X 0 -----> X 1 -----> X 2 -----> X 3 -----> ...
```
where the `X n` are metric spaces and f n isometric embeddings. We do it by defining a premetric
space structure on `Σ n, X n`, where the predistance `dist x y` is obtained by pushing `x` and `y`
in a common `X k` using composition by the `f n`, and taking the distance there. This does not
depend on the choice of `k` as the `f n` are isometries. The metric space associated to this
premetric space is the desired inductive limit.
-/
open Nat
variable {X : ℕ → Type u} [∀ n, MetricSpace (X n)] {f : ∀ n, X n → X (n + 1)}
/-- Predistance on the disjoint union `Σ n, X n`. -/
def inductiveLimitDist (f : ∀ n, X n → X (n + 1)) (x y : Σ n, X n) : ℝ :=
dist (leRecOn (le_max_left x.1 y.1) (f _) x.2 : X (max x.1 y.1))
(leRecOn (le_max_right x.1 y.1) (f _) y.2 : X (max x.1 y.1))
/-- The predistance on the disjoint union `Σ n, X n` can be computed in any `X k` for large
enough `k`. -/
theorem inductiveLimitDist_eq_dist (I : ∀ n, Isometry (f n)) (x y : Σ n, X n) :
∀ m (hx : x.1 ≤ m) (hy : y.1 ≤ m), inductiveLimitDist f x y =
dist (leRecOn hx (f _) x.2 : X m) (leRecOn hy (f _) y.2 : X m)
| 0, hx, hy => by
obtain ⟨i, x⟩ := x; obtain ⟨j, y⟩ := y
obtain rfl : i = 0 := nonpos_iff_eq_zero.1 hx
obtain rfl : j = 0 := nonpos_iff_eq_zero.1 hy
rfl
| (m + 1), hx, hy => by
by_cases h : max x.1 y.1 = (m + 1)
· generalize m + 1 = m' at *
subst m'
rfl
· have : max x.1 y.1 ≤ succ m := by simp [hx, hy]
have : max x.1 y.1 ≤ m := by simpa [h] using of_le_succ this
have xm : x.1 ≤ m := le_trans (le_max_left _ _) this
have ym : y.1 ≤ m := le_trans (le_max_right _ _) this
rw [leRecOn_succ xm, leRecOn_succ ym, (I m).dist_eq]
exact inductiveLimitDist_eq_dist I x y m xm ym
/-- Premetric space structure on `Σ n, X n`. -/
def inductivePremetric (I : ∀ n, Isometry (f n)) : PseudoMetricSpace (Σn, X n) where
dist := inductiveLimitDist f
dist_self x := by simp [dist, inductiveLimitDist]
dist_comm x y := by
let m := max x.1 y.1
have hx : x.1 ≤ m := le_max_left _ _
have hy : y.1 ≤ m := le_max_right _ _
rw [inductiveLimitDist_eq_dist I x y m hx hy, inductiveLimitDist_eq_dist I y x m hy hx,
dist_comm]
dist_triangle x y z := by
let m := max (max x.1 y.1) z.1
have hx : x.1 ≤ m := le_trans (le_max_left _ _) (le_max_left _ _)
have hy : y.1 ≤ m := le_trans (le_max_right _ _) (le_max_left _ _)
have hz : z.1 ≤ m := le_max_right _ _
calc
inductiveLimitDist f x z = dist (leRecOn hx (f _) x.2 : X m) (leRecOn hz (f _) z.2 : X m) :=
inductiveLimitDist_eq_dist I x z m hx hz
_ ≤ dist (leRecOn hx (f _) x.2 : X m) (leRecOn hy (f _) y.2 : X m) +
dist (leRecOn hy (f _) y.2 : X m) (leRecOn hz (f _) z.2 : X m) :=
(dist_triangle _ _ _)
_ = inductiveLimitDist f x y + inductiveLimitDist f y z := by
rw [inductiveLimitDist_eq_dist I x y m hx hy, inductiveLimitDist_eq_dist I y z m hy hz]
attribute [local instance] inductivePremetric
/-- The type giving the inductive limit in a metric space context. -/
def InductiveLimit (I : ∀ n, Isometry (f n)) : Type _ :=
@SeparationQuotient _ (inductivePremetric I).toUniformSpace.toTopologicalSpace
instance {I : ∀ (n : ℕ), Isometry (f n)} : MetricSpace (InductiveLimit (f := f) I) :=
inferInstanceAs <| MetricSpace <|
@SeparationQuotient _ (inductivePremetric I).toUniformSpace.toTopologicalSpace
/-- Mapping each `X n` to the inductive limit. -/
def toInductiveLimit (I : ∀ n, Isometry (f n)) (n : ℕ) (x : X n) : Metric.InductiveLimit I :=
Quotient.mk'' (Sigma.mk n x)
instance (I : ∀ n, Isometry (f n)) [Inhabited (X 0)] : Inhabited (InductiveLimit I) :=
⟨toInductiveLimit _ 0 default⟩
/-- The map `toInductiveLimit n` mapping `X n` to the inductive limit is an isometry. -/
theorem toInductiveLimit_isometry (I : ∀ n, Isometry (f n)) (n : ℕ) :
Isometry (toInductiveLimit I n) :=
Isometry.of_dist_eq fun x y => by
change inductiveLimitDist f ⟨n, x⟩ ⟨n, y⟩ = dist x y
rw [inductiveLimitDist_eq_dist I ⟨n, x⟩ ⟨n, y⟩ n (le_refl n) (le_refl n), leRecOn_self,
leRecOn_self]
/-- The maps `toInductiveLimit n` are compatible with the maps `f n`. -/
theorem toInductiveLimit_commute (I : ∀ n, Isometry (f n)) (n : ℕ) :
toInductiveLimit I n.succ ∘ f n = toInductiveLimit I n := by
let h := inductivePremetric I
let _ := h.toUniformSpace.toTopologicalSpace
funext x
simp only [comp, toInductiveLimit]
refine SeparationQuotient.mk_eq_mk.2 (Metric.inseparable_iff.2 ?_)
show inductiveLimitDist f ⟨n.succ, f n x⟩ ⟨n, x⟩ = 0
rw [inductiveLimitDist_eq_dist I ⟨n.succ, f n x⟩ ⟨n, x⟩ n.succ, leRecOn_self,
leRecOn_succ, leRecOn_self, dist_self]
exact le_succ _
end InductiveLimit
--section
end Metric
--namespace
| Mathlib/Topology/MetricSpace/Gluing.lean | 636 | 641 | |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.CoreAttrs
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (least upper bound, or `sup`) or meet (greatest
lower bound, or `inf`) operations. Lattices are posets that are both join-semilattices and
meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `⊔` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `⊓` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `⊔` and `⊓` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a ⊔ b`: the supremum or join of `a` and `b`
* `a ⊓ b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
/-- See if the term is `a ⊂ b` and the goal is `a ⊆ b`. -/
@[gcongr_forward] def exactSubsetOfSSubset : Mathlib.Tactic.GCongr.ForwardExt where
eval h goal := do goal.assignIfDefEq (← Lean.Meta.mkAppM ``subset_of_ssubset #[h])
universe u v w
variable {α : Type u} {β : Type v}
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`⊔` which is the least element larger than both factors. -/
class SemilatticeSup (α : Type u) extends PartialOrder α where
/-- The binary supremum, used to derive `Max α` -/
sup : α → α → α
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : ∀ a b : α, a ≤ sup a b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : ∀ a b : α, b ≤ sup a b
/-- The supremum is the *least* upper bound -/
protected sup_le : ∀ a b c : α, a ≤ c → b ≤ c → sup a b ≤ c
instance SemilatticeSup.toMax [SemilatticeSup α] : Max α where max a b := SemilatticeSup.sup a b
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a ≤ b` unfolds to `a ⊔ b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {α : Type*} [Max α] (sup_comm : ∀ a b : α, a ⊔ b = b ⊔ a)
(sup_assoc : ∀ a b c : α, a ⊔ b ⊔ c = a ⊔ (b ⊔ c)) (sup_idem : ∀ a : α, a ⊔ a = a) :
SemilatticeSup α where
sup := (· ⊔ ·)
le a b := a ⊔ b = b
le_refl := sup_idem
le_trans a b c hab hbc := by rw [← hbc, ← sup_assoc, hab]
le_antisymm a b hab hba := by rwa [← hba, sup_comm]
le_sup_left a b := by rw [← sup_assoc, sup_idem]
le_sup_right a b := by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by rwa [sup_assoc, hbc]
section SemilatticeSup
variable [SemilatticeSup α] {a b c d : α}
@[simp]
theorem le_sup_left : a ≤ a ⊔ b :=
SemilatticeSup.le_sup_left a b
@[simp]
theorem le_sup_right : b ≤ a ⊔ b :=
SemilatticeSup.le_sup_right a b
theorem le_sup_of_le_left (h : c ≤ a) : c ≤ a ⊔ b :=
le_trans h le_sup_left
theorem le_sup_of_le_right (h : c ≤ b) : c ≤ a ⊔ b :=
le_trans h le_sup_right
theorem lt_sup_of_lt_left (h : c < a) : c < a ⊔ b :=
h.trans_le le_sup_left
theorem lt_sup_of_lt_right (h : c < b) : c < a ⊔ b :=
h.trans_le le_sup_right
theorem sup_le : a ≤ c → b ≤ c → a ⊔ b ≤ c :=
SemilatticeSup.sup_le a b c
@[simp]
theorem sup_le_iff : a ⊔ b ≤ c ↔ a ≤ c ∧ b ≤ c :=
⟨fun h : a ⊔ b ≤ c => ⟨le_trans le_sup_left h, le_trans le_sup_right h⟩,
fun ⟨h₁, h₂⟩ => sup_le h₁ h₂⟩
@[simp]
theorem sup_eq_left : a ⊔ b = a ↔ b ≤ a :=
le_antisymm_iff.trans <| by simp [le_rfl]
@[simp]
theorem sup_eq_right : a ⊔ b = b ↔ a ≤ b :=
le_antisymm_iff.trans <| by simp [le_rfl]
@[simp]
theorem left_eq_sup : a = a ⊔ b ↔ b ≤ a :=
eq_comm.trans sup_eq_left
@[simp]
theorem right_eq_sup : b = a ⊔ b ↔ a ≤ b :=
eq_comm.trans sup_eq_right
alias ⟨_, sup_of_le_left⟩ := sup_eq_left
alias ⟨le_of_sup_eq, sup_of_le_right⟩ := sup_eq_right
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a ⊔ b ↔ ¬b ≤ a :=
le_sup_left.lt_iff_ne.trans <| not_congr left_eq_sup
@[simp]
theorem right_lt_sup : b < a ⊔ b ↔ ¬a ≤ b :=
le_sup_right.lt_iff_ne.trans <| not_congr right_eq_sup
theorem left_or_right_lt_sup (h : a ≠ b) : a < a ⊔ b ∨ b < a ⊔ b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
theorem le_iff_exists_sup : a ≤ b ↔ ∃ c, b = a ⊔ c := by
constructor
· intro h
exact ⟨b, (sup_eq_right.mpr h).symm⟩
· rintro ⟨c, rfl : _ = _ ⊔ _⟩
exact le_sup_left
@[gcongr]
theorem sup_le_sup (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊔ c ≤ b ⊔ d :=
sup_le (le_sup_of_le_left h₁) (le_sup_of_le_right h₂)
@[gcongr]
theorem sup_le_sup_left (h₁ : a ≤ b) (c) : c ⊔ a ≤ c ⊔ b :=
sup_le_sup le_rfl h₁
@[gcongr]
theorem sup_le_sup_right (h₁ : a ≤ b) (c) : a ⊔ c ≤ b ⊔ c :=
sup_le_sup h₁ le_rfl
theorem sup_idem (a : α) : a ⊔ a = a := by simp
instance : Std.IdempotentOp (α := α) (· ⊔ ·) := ⟨sup_idem⟩
theorem sup_comm (a b : α) : a ⊔ b = b ⊔ a := by apply le_antisymm <;> simp
instance : Std.Commutative (α := α) (· ⊔ ·) := ⟨sup_comm⟩
theorem sup_assoc (a b c : α) : a ⊔ b ⊔ c = a ⊔ (b ⊔ c) :=
eq_of_forall_ge_iff fun x => by simp only [sup_le_iff]; rw [and_assoc]
instance : Std.Associative (α := α) (· ⊔ ·) := ⟨sup_assoc⟩
theorem sup_left_right_swap (a b c : α) : a ⊔ b ⊔ c = c ⊔ b ⊔ a := by
rw [sup_comm, sup_comm a, sup_assoc]
theorem sup_left_idem (a b : α) : a ⊔ (a ⊔ b) = a ⊔ b := by simp
theorem sup_right_idem (a b : α) : a ⊔ b ⊔ b = a ⊔ b := by simp
theorem sup_left_comm (a b c : α) : a ⊔ (b ⊔ c) = b ⊔ (a ⊔ c) := by
rw [← sup_assoc, ← sup_assoc, @sup_comm α _ a]
theorem sup_right_comm (a b c : α) : a ⊔ b ⊔ c = a ⊔ c ⊔ b := by
rw [sup_assoc, sup_assoc, sup_comm b]
theorem sup_sup_sup_comm (a b c d : α) : a ⊔ b ⊔ (c ⊔ d) = a ⊔ c ⊔ (b ⊔ d) := by
rw [sup_assoc, sup_left_comm b, ← sup_assoc]
theorem sup_sup_distrib_left (a b c : α) : a ⊔ (b ⊔ c) = a ⊔ b ⊔ (a ⊔ c) := by
rw [sup_sup_sup_comm, sup_idem]
theorem sup_sup_distrib_right (a b c : α) : a ⊔ b ⊔ c = a ⊔ c ⊔ (b ⊔ c) := by
rw [sup_sup_sup_comm, sup_idem]
theorem sup_congr_left (hb : b ≤ a ⊔ c) (hc : c ≤ a ⊔ b) : a ⊔ b = a ⊔ c :=
(sup_le le_sup_left hb).antisymm <| sup_le le_sup_left hc
theorem sup_congr_right (ha : a ≤ b ⊔ c) (hb : b ≤ a ⊔ c) : a ⊔ c = b ⊔ c :=
(sup_le ha le_sup_right).antisymm <| sup_le hb le_sup_right
theorem sup_eq_sup_iff_left : a ⊔ b = a ⊔ c ↔ b ≤ a ⊔ c ∧ c ≤ a ⊔ b :=
⟨fun h => ⟨h ▸ le_sup_right, h.symm ▸ le_sup_right⟩, fun h => sup_congr_left h.1 h.2⟩
theorem sup_eq_sup_iff_right : a ⊔ c = b ⊔ c ↔ a ≤ b ⊔ c ∧ b ≤ a ⊔ c :=
⟨fun h => ⟨h ▸ le_sup_left, h.symm ▸ le_sup_left⟩, fun h => sup_congr_right h.1 h.2⟩
theorem Ne.lt_sup_or_lt_sup (hab : a ≠ b) : a < a ⊔ b ∨ b < a ⊔ b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
/-- If `f` is monotone, `g` is antitone, and `f ≤ g`, then for all `a`, `b` we have `f a ≤ g b`. -/
theorem Monotone.forall_le_of_antitone {β : Type*} [Preorder β] {f g : α → β} (hf : Monotone f)
(hg : Antitone g) (h : f ≤ g) (m n : α) : f m ≤ g n :=
calc
f m ≤ f (m ⊔ n) := hf le_sup_left
_ ≤ g (m ⊔ n) := h _
_ ≤ g n := hg le_sup_right
theorem SemilatticeSup.ext_sup {α} {A B : SemilatticeSup α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y)
(x y : α) :
(haveI := A; x ⊔ y) = x ⊔ y :=
eq_of_forall_ge_iff fun c => by simp only [sup_le_iff]; rw [← H, @sup_le_iff α A, H, H]
theorem SemilatticeSup.ext {α} {A B : SemilatticeSup α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) :
A = B := by
cases A
cases B
cases PartialOrder.ext H
congr
ext; apply SemilatticeSup.ext_sup H
theorem ite_le_sup (s s' : α) (P : Prop) [Decidable P] : ite P s s' ≤ s ⊔ s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`⊓` which is the greatest element smaller than both factors. -/
class SemilatticeInf (α : Type u) extends PartialOrder α where
/-- The binary infimum, used to derive `Min α` -/
inf : α → α → α
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : ∀ a b : α, inf a b ≤ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : ∀ a b : α, inf a b ≤ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : ∀ a b c : α, a ≤ b → a ≤ c → a ≤ inf b c
instance SemilatticeInf.toMin [SemilatticeInf α] : Min α where min a b := SemilatticeInf.inf a b
instance OrderDual.instSemilatticeSup (α) [SemilatticeInf α] : SemilatticeSup αᵒᵈ where
sup := @SemilatticeInf.inf α _
le_sup_left := @SemilatticeInf.inf_le_left α _
le_sup_right := @SemilatticeInf.inf_le_right α _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf α _ _ _ _ hca hcb
instance OrderDual.instSemilatticeInf (α) [SemilatticeSup α] : SemilatticeInf αᵒᵈ where
inf := @SemilatticeSup.sup α _
inf_le_left := @le_sup_left α _
inf_le_right := @le_sup_right α _
le_inf := fun _ _ _ hca hcb => @sup_le α _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (α : Type*) [H : SemilatticeSup α] :
OrderDual.instSemilatticeSup αᵒᵈ = H :=
SemilatticeSup.ext fun _ _ => Iff.rfl
section SemilatticeInf
variable [SemilatticeInf α] {a b c d : α}
@[simp]
theorem inf_le_left : a ⊓ b ≤ a :=
SemilatticeInf.inf_le_left a b
@[simp]
theorem inf_le_right : a ⊓ b ≤ b :=
SemilatticeInf.inf_le_right a b
theorem le_inf : a ≤ b → a ≤ c → a ≤ b ⊓ c :=
SemilatticeInf.le_inf a b c
theorem inf_le_of_left_le (h : a ≤ c) : a ⊓ b ≤ c :=
le_trans inf_le_left h
theorem inf_le_of_right_le (h : b ≤ c) : a ⊓ b ≤ c :=
le_trans inf_le_right h
theorem inf_lt_of_left_lt (h : a < c) : a ⊓ b < c :=
lt_of_le_of_lt inf_le_left h
theorem inf_lt_of_right_lt (h : b < c) : a ⊓ b < c :=
lt_of_le_of_lt inf_le_right h
@[simp]
theorem le_inf_iff : a ≤ b ⊓ c ↔ a ≤ b ∧ a ≤ c :=
@sup_le_iff αᵒᵈ _ _ _ _
@[simp]
theorem inf_eq_left : a ⊓ b = a ↔ a ≤ b :=
le_antisymm_iff.trans <| by simp [le_rfl]
@[simp]
theorem inf_eq_right : a ⊓ b = b ↔ b ≤ a :=
le_antisymm_iff.trans <| by simp [le_rfl]
@[simp]
theorem left_eq_inf : a = a ⊓ b ↔ a ≤ b :=
eq_comm.trans inf_eq_left
@[simp]
theorem right_eq_inf : b = a ⊓ b ↔ b ≤ a :=
eq_comm.trans inf_eq_right
alias ⟨le_of_inf_eq, inf_of_le_left⟩ := inf_eq_left
alias ⟨_, inf_of_le_right⟩ := inf_eq_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a ⊓ b < a ↔ ¬a ≤ b :=
@left_lt_sup αᵒᵈ _ _ _
@[simp]
theorem inf_lt_right : a ⊓ b < b ↔ ¬b ≤ a :=
@right_lt_sup αᵒᵈ _ _ _
theorem inf_lt_left_or_right (h : a ≠ b) : a ⊓ b < a ∨ a ⊓ b < b :=
@left_or_right_lt_sup αᵒᵈ _ _ _ h
@[gcongr]
theorem inf_le_inf (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊓ c ≤ b ⊓ d :=
@sup_le_sup αᵒᵈ _ _ _ _ _ h₁ h₂
@[gcongr]
theorem inf_le_inf_right (a : α) {b c : α} (h : b ≤ c) : b ⊓ a ≤ c ⊓ a :=
inf_le_inf h le_rfl
@[gcongr]
theorem inf_le_inf_left (a : α) {b c : α} (h : b ≤ c) : a ⊓ b ≤ a ⊓ c :=
inf_le_inf le_rfl h
theorem inf_idem (a : α) : a ⊓ a = a := by simp
instance : Std.IdempotentOp (α := α) (· ⊓ ·) := ⟨inf_idem⟩
theorem inf_comm (a b : α) : a ⊓ b = b ⊓ a := @sup_comm αᵒᵈ _ _ _
instance : Std.Commutative (α := α) (· ⊓ ·) := ⟨inf_comm⟩
theorem inf_assoc (a b c : α) : a ⊓ b ⊓ c = a ⊓ (b ⊓ c) := @sup_assoc αᵒᵈ _ _ _ _
instance : Std.Associative (α := α) (· ⊓ ·) := ⟨inf_assoc⟩
theorem inf_left_right_swap (a b c : α) : a ⊓ b ⊓ c = c ⊓ b ⊓ a :=
@sup_left_right_swap αᵒᵈ _ _ _ _
theorem inf_left_idem (a b : α) : a ⊓ (a ⊓ b) = a ⊓ b := by simp
theorem inf_right_idem (a b : α) : a ⊓ b ⊓ b = a ⊓ b := by simp
theorem inf_left_comm (a b c : α) : a ⊓ (b ⊓ c) = b ⊓ (a ⊓ c) :=
@sup_left_comm αᵒᵈ _ a b c
theorem inf_right_comm (a b c : α) : a ⊓ b ⊓ c = a ⊓ c ⊓ b :=
@sup_right_comm αᵒᵈ _ a b c
theorem inf_inf_inf_comm (a b c d : α) : a ⊓ b ⊓ (c ⊓ d) = a ⊓ c ⊓ (b ⊓ d) :=
@sup_sup_sup_comm αᵒᵈ _ _ _ _ _
theorem inf_inf_distrib_left (a b c : α) : a ⊓ (b ⊓ c) = a ⊓ b ⊓ (a ⊓ c) :=
@sup_sup_distrib_left αᵒᵈ _ _ _ _
theorem inf_inf_distrib_right (a b c : α) : a ⊓ b ⊓ c = a ⊓ c ⊓ (b ⊓ c) :=
@sup_sup_distrib_right αᵒᵈ _ _ _ _
theorem inf_congr_left (hb : a ⊓ c ≤ b) (hc : a ⊓ b ≤ c) : a ⊓ b = a ⊓ c :=
@sup_congr_left αᵒᵈ _ _ _ _ hb hc
theorem inf_congr_right (h1 : b ⊓ c ≤ a) (h2 : a ⊓ c ≤ b) : a ⊓ c = b ⊓ c :=
@sup_congr_right αᵒᵈ _ _ _ _ h1 h2
theorem inf_eq_inf_iff_left : a ⊓ b = a ⊓ c ↔ a ⊓ c ≤ b ∧ a ⊓ b ≤ c :=
@sup_eq_sup_iff_left αᵒᵈ _ _ _ _
theorem inf_eq_inf_iff_right : a ⊓ c = b ⊓ c ↔ b ⊓ c ≤ a ∧ a ⊓ c ≤ b :=
@sup_eq_sup_iff_right αᵒᵈ _ _ _ _
theorem Ne.inf_lt_or_inf_lt : a ≠ b → a ⊓ b < a ∨ a ⊓ b < b :=
@Ne.lt_sup_or_lt_sup αᵒᵈ _ _ _
theorem SemilatticeInf.ext_inf {α} {A B : SemilatticeInf α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y)
(x y : α) :
(haveI := A; x ⊓ y) = x ⊓ y :=
eq_of_forall_le_iff fun c => by simp only [le_inf_iff]; rw [← H, @le_inf_iff α A, H, H]
theorem SemilatticeInf.ext {α} {A B : SemilatticeInf α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) :
A = B := by
cases A
cases B
cases PartialOrder.ext H
congr
ext; apply SemilatticeInf.ext_inf H
theorem SemilatticeInf.dual_dual (α : Type*) [H : SemilatticeInf α] :
OrderDual.instSemilatticeInf αᵒᵈ = H :=
SemilatticeInf.ext fun _ _ => Iff.rfl
theorem inf_le_ite (s s' : α) (P : Prop) [Decidable P] : s ⊓ s' ≤ ite P s s' :=
@ite_le_sup αᵒᵈ _ _ _ _ _
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a ≤ b` unfolds to `b ⊓ a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {α : Type*} [Min α] (inf_comm : ∀ a b : α, a ⊓ b = b ⊓ a)
(inf_assoc : ∀ a b c : α, a ⊓ b ⊓ c = a ⊓ (b ⊓ c)) (inf_idem : ∀ a : α, a ⊓ a = a) :
SemilatticeInf α := by
haveI : SemilatticeSup αᵒᵈ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.instSemilatticeInf αᵒᵈ
exact i
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (α : Type u) extends SemilatticeSup α, SemilatticeInf α
instance OrderDual.instLattice (α) [Lattice α] : Lattice αᵒᵈ where
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a ⊔ a ⊓ b = a`)
and `inf_sup_self` (`a ⊓ (a ⊔ b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{α : Type*} [Max α] [Min α]
(sup_comm : ∀ a b : α, a ⊔ b = b ⊔ a) (sup_assoc : ∀ a b c : α, a ⊔ b ⊔ c = a ⊔ (b ⊔ c))
(sup_idem : ∀ a : α, a ⊔ a = a) (inf_comm : ∀ a b : α, a ⊓ b = b ⊓ a)
(inf_assoc : ∀ a b c : α, a ⊓ b ⊓ c = a ⊓ (b ⊓ c)) (inf_idem : ∀ a : α, a ⊓ a = a)
(sup_inf_self : ∀ a b : α, a ⊔ a ⊓ b = a) (inf_sup_self : ∀ a b : α, a ⊓ (a ⊔ b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext fun a b =>
show a ⊔ b = b ↔ b ⊓ a = a from
⟨fun h => by rw [← h, inf_comm, inf_sup_self], fun h => by rw [← h, sup_comm, sup_inf_self]⟩
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a ≤ b` unfolds to `a ⊔ b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {α : Type*} [Max α] [Min α] (sup_comm : ∀ a b : α, a ⊔ b = b ⊔ a)
(sup_assoc : ∀ a b c : α, a ⊔ b ⊔ c = a ⊔ (b ⊔ c)) (inf_comm : ∀ a b : α, a ⊓ b = b ⊓ a)
(inf_assoc : ∀ a b c : α, a ⊓ b ⊓ c = a ⊓ (b ⊓ c)) (sup_inf_self : ∀ a b : α, a ⊔ a ⊓ b = a)
(inf_sup_self : ∀ a b : α, a ⊓ (a ⊔ b) = a) : Lattice α :=
have sup_idem : ∀ b : α, b ⊔ b = b := fun b =>
calc
b ⊔ b = b ⊔ b ⊓ (b ⊔ b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : ∀ b : α, b ⊓ b = b := fun b =>
calc
b ⊓ b = b ⊓ (b ⊔ b ⊓ b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
section Lattice
variable [Lattice α] {a b c : α}
theorem inf_le_sup : a ⊓ b ≤ a ⊔ b :=
inf_le_left.trans le_sup_left
theorem sup_le_inf : a ⊔ b ≤ a ⊓ b ↔ a = b := by simp [le_antisymm_iff, and_comm]
@[simp] lemma inf_eq_sup : a ⊓ b = a ⊔ b ↔ a = b := by rw [← inf_le_sup.ge_iff_eq, sup_le_inf]
@[simp] lemma sup_eq_inf : a ⊔ b = a ⊓ b ↔ a = b := eq_comm.trans inf_eq_sup
@[simp] lemma inf_lt_sup : a ⊓ b < a ⊔ b ↔ a ≠ b := by rw [inf_le_sup.lt_iff_ne, Ne, inf_eq_sup]
lemma inf_eq_and_sup_eq_iff : a ⊓ b = c ∧ a ⊔ b = c ↔ a = c ∧ b = c := by
refine ⟨fun h ↦ ?_, ?_⟩
· obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h
· rintro ⟨rfl, rfl⟩
exact ⟨inf_idem _, sup_idem _⟩
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a ⊔ b ⊓ c ≤ (a ⊔ b) ⊓ (a ⊔ c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
theorem le_inf_sup : a ⊓ b ⊔ a ⊓ c ≤ a ⊓ (b ⊔ c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
theorem inf_sup_self : a ⊓ (a ⊔ b) = a := by simp
theorem sup_inf_self : a ⊔ a ⊓ b = a := by simp
theorem sup_eq_iff_inf_eq : a ⊔ b = b ↔ a ⊓ b = a := by rw [sup_eq_right, ← inf_eq_left]
theorem Lattice.ext {α} {A B : Lattice α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ (y ⊓ z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (α) extends Lattice α where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : ∀ x y z : α, (x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ y ⊓ z
section DistribLattice
variable [DistribLattice α] {x y z : α}
theorem le_sup_inf : ∀ {x y z : α}, (x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ y ⊓ z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
theorem sup_inf_left (a b c : α) : a ⊔ b ⊓ c = (a ⊔ b) ⊓ (a ⊔ c) :=
le_antisymm sup_inf_le le_sup_inf
theorem sup_inf_right (a b c : α) : a ⊓ b ⊔ c = (a ⊔ c) ⊓ (b ⊔ c) := by
simp only [sup_inf_left, sup_comm _ c, eq_self_iff_true]
theorem inf_sup_left (a b c : α) : a ⊓ (b ⊔ c) = a ⊓ b ⊔ a ⊓ c :=
calc
a ⊓ (b ⊔ c) = a ⊓ (a ⊔ c) ⊓ (b ⊔ c) := by rw [inf_sup_self]
_ = a ⊓ (a ⊓ b ⊔ c) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (a ⊔ a ⊓ b) ⊓ (a ⊓ b ⊔ c) := by rw [sup_inf_self]
_ = (a ⊓ b ⊔ a) ⊓ (a ⊓ b ⊔ c) := by rw [sup_comm]
_ = a ⊓ b ⊔ a ⊓ c := by rw [sup_inf_left]
instance OrderDual.instDistribLattice (α : Type*) [DistribLattice α] : DistribLattice αᵒᵈ where
le_sup_inf _ _ _ := (inf_sup_left _ _ _).le
theorem inf_sup_right (a b c : α) : (a ⊔ b) ⊓ c = a ⊓ c ⊔ b ⊓ c := by
simp only [inf_sup_left, inf_comm _ c, eq_self_iff_true]
theorem le_of_inf_le_sup_le (h₁ : x ⊓ z ≤ y ⊓ z) (h₂ : x ⊔ z ≤ y ⊔ z) : x ≤ y :=
calc
x ≤ y ⊓ z ⊔ x := le_sup_right
_ = (y ⊔ x) ⊓ (x ⊔ z) := by rw [sup_inf_right, sup_comm x]
_ ≤ (y ⊔ x) ⊓ (y ⊔ z) := inf_le_inf_left _ h₂
_ = y ⊔ x ⊓ z := by rw [← sup_inf_left]
_ ≤ y ⊔ y ⊓ z := sup_le_sup_left h₁ _
_ ≤ _ := sup_le (le_refl y) inf_le_left
theorem eq_of_inf_eq_sup_eq {a b c : α} (h₁ : b ⊓ a = c ⊓ a) (h₂ : b ⊔ a = c ⊔ a) : b = c :=
le_antisymm (le_of_inf_le_sup_le (le_of_eq h₁) (le_of_eq h₂))
(le_of_inf_le_sup_le (le_of_eq h₁.symm) (le_of_eq h₂.symm))
end DistribLattice
-- See note [reducible non-instances]
/-- Prove distributivity of an existing lattice from the dual distributive law. -/
abbrev DistribLattice.ofInfSupLe
[Lattice α] (inf_sup_le : ∀ a b c : α, a ⊓ (b ⊔ c) ≤ a ⊓ b ⊔ a ⊓ c) : DistribLattice α where
le_sup_inf := (@OrderDual.instDistribLattice αᵒᵈ {inferInstanceAs (Lattice αᵒᵈ) with
le_sup_inf := inf_sup_le}).le_sup_inf
/-!
### Lattices derived from linear orders
-/
-- see Note [lower instance priority]
instance (priority := 100) LinearOrder.toLattice {α : Type u} [LinearOrder α] : Lattice α where
sup := max
inf := min
le_sup_left := le_max_left; le_sup_right := le_max_right; sup_le _ _ _ := max_le
inf_le_left := min_le_left; inf_le_right := min_le_right; le_inf _ _ _ := le_min
section LinearOrder
variable [LinearOrder α] {a b c d : α}
@[deprecated "is syntactical" (since := "2024-11-13"), nolint synTaut]
theorem sup_eq_max : a ⊔ b = max a b :=
rfl
@[deprecated "is syntactical" (since := "2024-11-13"), nolint synTaut]
theorem inf_eq_min : a ⊓ b = min a b :=
rfl
theorem sup_ind (a b : α) {p : α → Prop} (ha : p a) (hb : p b) : p (a ⊔ b) :=
(IsTotal.total a b).elim (fun h : a ≤ b => by rwa [sup_eq_right.2 h]) fun h => by
rwa [sup_eq_left.2 h]
@[simp]
theorem le_sup_iff : a ≤ b ⊔ c ↔ a ≤ b ∨ a ≤ c := by
exact ⟨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
| fun h => h.elim le_sup_of_le_left le_sup_of_le_right⟩
| Mathlib/Order/Lattice.lean | 669 | 669 |
/-
Copyright (c) 2021 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import Mathlib.GroupTheory.Index
/-!
# Complements
In this file we define the complement of a subgroup.
## Main definitions
- `Subgroup.IsComplement S T` where `S` and `T` are subsets of `G` states that every `g : G` can be
written uniquely as a product `s * t` for `s ∈ S`, `t ∈ T`.
- `H.LeftTransversal` where `H` is a subgroup of `G` is the type of all left-complements of `H`,
i.e. the set of all `S : Set G` that contain exactly one element of each left coset of `H`.
- `H.RightTransversal` where `H` is a subgroup of `G` is the set of all right-complements of `H`,
i.e. the set of all `T : Set G` that contain exactly one element of each right coset of `H`.
## Main results
- `isComplement'_of_coprime` : Subgroups of coprime order are complements.
-/
open Function Set
open scoped Pointwise
namespace Subgroup
variable {G : Type*} [Group G] (H K : Subgroup G) (S T : Set G)
/-- `S` and `T` are complements if `(*) : S × T → G` is a bijection.
This notion generalizes left transversals, right transversals, and complementary subgroups. -/
@[to_additive "`S` and `T` are complements if `(+) : S × T → G` is a bijection"]
def IsComplement : Prop :=
Function.Bijective fun x : S × T => x.1.1 * x.2.1
/-- `H` and `K` are complements if `(*) : H × K → G` is a bijection -/
@[to_additive "`H` and `K` are complements if `(+) : H × K → G` is a bijection"]
abbrev IsComplement' :=
IsComplement (H : Set G) (K : Set G)
/-- The set of left-complements of `T : Set G` -/
@[to_additive (attr := deprecated IsComplement (since := "2024-12-18"))
"The set of left-complements of `T : Set G`"]
def leftTransversals : Set (Set G) :=
{ S : Set G | IsComplement S T }
/-- The set of right-complements of `S : Set G` -/
@[to_additive (attr := deprecated IsComplement (since := "2024-12-18"))
"The set of right-complements of `S : Set G`"]
def rightTransversals : Set (Set G) :=
{ T : Set G | IsComplement S T }
variable {H K S T}
@[to_additive]
theorem isComplement'_def : IsComplement' H K ↔ IsComplement (H : Set G) (K : Set G) :=
Iff.rfl
@[to_additive]
theorem isComplement_iff_existsUnique :
IsComplement S T ↔ ∀ g : G, ∃! x : S × T, x.1.1 * x.2.1 = g :=
Function.bijective_iff_existsUnique _
@[to_additive]
theorem IsComplement.existsUnique (h : IsComplement S T) (g : G) :
∃! x : S × T, x.1.1 * x.2.1 = g :=
isComplement_iff_existsUnique.mp h g
@[to_additive]
theorem IsComplement'.symm (h : IsComplement' H K) : IsComplement' K H := by
let ϕ : H × K ≃ K × H :=
Equiv.mk (fun x => ⟨x.2⁻¹, x.1⁻¹⟩) (fun x => ⟨x.2⁻¹, x.1⁻¹⟩)
(fun x => Prod.ext (inv_inv _) (inv_inv _)) fun x => Prod.ext (inv_inv _) (inv_inv _)
let ψ : G ≃ G := Equiv.mk (fun g : G => g⁻¹) (fun g : G => g⁻¹) inv_inv inv_inv
suffices hf : (ψ ∘ fun x : H × K => x.1.1 * x.2.1) = (fun x : K × H => x.1.1 * x.2.1) ∘ ϕ by
rw [isComplement'_def, IsComplement, ← Equiv.bijective_comp ϕ]
apply (congr_arg Function.Bijective hf).mp -- Porting note: This was a `rw` in mathlib3
rwa [ψ.comp_bijective]
exact funext fun x => mul_inv_rev _ _
@[to_additive]
theorem isComplement'_comm : IsComplement' H K ↔ IsComplement' K H :=
⟨IsComplement'.symm, IsComplement'.symm⟩
@[to_additive]
theorem isComplement_univ_singleton {g : G} : IsComplement (univ : Set G) {g} :=
⟨fun ⟨_, _, rfl⟩ ⟨_, _, rfl⟩ h => Prod.ext (Subtype.ext (mul_right_cancel h)) rfl, fun x =>
⟨⟨⟨x * g⁻¹, ⟨⟩⟩, g, rfl⟩, inv_mul_cancel_right x g⟩⟩
@[to_additive]
theorem isComplement_singleton_univ {g : G} : IsComplement ({g} : Set G) univ :=
⟨fun ⟨⟨_, rfl⟩, _⟩ ⟨⟨_, rfl⟩, _⟩ h => Prod.ext rfl (Subtype.ext (mul_left_cancel h)), fun x =>
⟨⟨⟨g, rfl⟩, g⁻¹ * x, ⟨⟩⟩, mul_inv_cancel_left g x⟩⟩
@[to_additive]
theorem isComplement_singleton_left {g : G} : IsComplement {g} S ↔ S = univ := by
refine
⟨fun h => top_le_iff.mp fun x _ => ?_, fun h => (congr_arg _ h).mpr isComplement_singleton_univ⟩
obtain ⟨⟨⟨z, rfl : z = g⟩, y, _⟩, hy⟩ := h.2 (g * x)
rwa [← mul_left_cancel hy]
@[to_additive]
theorem isComplement_singleton_right {g : G} : IsComplement S {g} ↔ S = univ := by
refine
⟨fun h => top_le_iff.mp fun x _ => ?_, fun h => h ▸ isComplement_univ_singleton⟩
obtain ⟨y, hy⟩ := h.2 (x * g)
conv_rhs at hy => rw [← show y.2.1 = g from y.2.2]
rw [← mul_right_cancel hy]
exact y.1.2
@[to_additive]
theorem isComplement_univ_left : IsComplement univ S ↔ ∃ g : G, S = {g} := by
refine
⟨fun h => Set.exists_eq_singleton_iff_nonempty_subsingleton.mpr ⟨?_, fun a ha b hb => ?_⟩, ?_⟩
· obtain ⟨a, _⟩ := h.2 1
exact ⟨a.2.1, a.2.2⟩
· have : (⟨⟨_, mem_top a⁻¹⟩, ⟨a, ha⟩⟩ : (⊤ : Set G) × S) = ⟨⟨_, mem_top b⁻¹⟩, ⟨b, hb⟩⟩ :=
h.1 ((inv_mul_cancel a).trans (inv_mul_cancel b).symm)
exact Subtype.ext_iff.mp (Prod.ext_iff.mp this).2
· rintro ⟨g, rfl⟩
exact isComplement_univ_singleton
@[to_additive]
theorem isComplement_univ_right : IsComplement S univ ↔ ∃ g : G, S = {g} := by
refine
⟨fun h => Set.exists_eq_singleton_iff_nonempty_subsingleton.mpr ⟨?_, fun a ha b hb => ?_⟩, ?_⟩
· obtain ⟨a, _⟩ := h.2 1
exact ⟨a.1.1, a.1.2⟩
· have : (⟨⟨a, ha⟩, ⟨_, mem_top a⁻¹⟩⟩ : S × (⊤ : Set G)) = ⟨⟨b, hb⟩, ⟨_, mem_top b⁻¹⟩⟩ :=
h.1 ((mul_inv_cancel a).trans (mul_inv_cancel b).symm)
exact Subtype.ext_iff.mp (Prod.ext_iff.mp this).1
· rintro ⟨g, rfl⟩
exact isComplement_singleton_univ
@[to_additive]
lemma IsComplement.mul_eq (h : IsComplement S T) : S * T = univ :=
eq_univ_of_forall fun x ↦ by simpa [mem_mul] using (h.existsUnique x).exists
@[to_additive (attr := simp)]
lemma not_isComplement_empty_left : ¬ IsComplement ∅ T :=
fun h ↦ by simpa [eq_comm (a := ∅)] using h.mul_eq
@[to_additive (attr := simp)]
lemma not_isComplement_empty_right : ¬ IsComplement S ∅ :=
fun h ↦ by simpa [eq_comm (a := ∅)] using h.mul_eq
@[to_additive]
lemma IsComplement.nonempty_left (hst : IsComplement S T) : S.Nonempty := by
contrapose! hst; simp [hst]
@[to_additive]
lemma IsComplement.nonempty_right (hst : IsComplement S T) : T.Nonempty := by
contrapose! hst; simp [hst]
@[to_additive] lemma IsComplement.pairwiseDisjoint_smul (hst : IsComplement S T) :
S.PairwiseDisjoint (· • T) := fun a ha b hb hab ↦ disjoint_iff_forall_ne.2 <| by
rintro _ ⟨c, hc, rfl⟩ _ ⟨d, hd, rfl⟩
exact hst.1.ne (a₁ := (⟨a, ha⟩, ⟨c, hc⟩)) (a₂:= (⟨b, hb⟩, ⟨d, hd⟩)) (by simp [hab])
@[to_additive AddSubgroup.IsComplement.card_mul_card]
lemma IsComplement.card_mul_card (h : IsComplement S T) : Nat.card S * Nat.card T = Nat.card G :=
(Nat.card_prod _ _).symm.trans <| Nat.card_congr <| Equiv.ofBijective _ h
@[to_additive]
theorem isComplement'_top_bot : IsComplement' (⊤ : Subgroup G) ⊥ :=
isComplement_univ_singleton
@[to_additive]
theorem isComplement'_bot_top : IsComplement' (⊥ : Subgroup G) ⊤ :=
isComplement_singleton_univ
@[to_additive (attr := simp)]
theorem isComplement'_bot_left : IsComplement' ⊥ H ↔ H = ⊤ :=
isComplement_singleton_left.trans coe_eq_univ
@[to_additive (attr := simp)]
theorem isComplement'_bot_right : IsComplement' H ⊥ ↔ H = ⊤ :=
isComplement_singleton_right.trans coe_eq_univ
@[to_additive (attr := simp)]
theorem isComplement'_top_left : IsComplement' ⊤ H ↔ H = ⊥ :=
isComplement_univ_left.trans coe_eq_singleton
@[to_additive (attr := simp)]
theorem isComplement'_top_right : IsComplement' H ⊤ ↔ H = ⊥ :=
isComplement_univ_right.trans coe_eq_singleton
@[to_additive]
lemma isComplement_iff_existsUnique_inv_mul_mem :
IsComplement S T ↔ ∀ g, ∃! s : S, (s : G)⁻¹ * g ∈ T := by
convert isComplement_iff_existsUnique with g
constructor <;> rintro ⟨x, hx, hx'⟩
· exact ⟨(x, ⟨_, hx⟩), by simp, by aesop⟩
· exact ⟨x.1, by simp [← hx], fun y hy ↦ (Prod.ext_iff.1 <| by simpa using hx' (y, ⟨_, hy⟩)).1⟩
set_option linter.deprecated false in
@[to_additive
(attr := deprecated isComplement_iff_existsUnique_inv_mul_mem (since := "2024-12-18"))]
theorem mem_leftTransversals_iff_existsUnique_inv_mul_mem :
S ∈ leftTransversals T ↔ ∀ g : G, ∃! s : S, (s : G)⁻¹ * g ∈ T := by
rw [leftTransversals, Set.mem_setOf_eq, isComplement_iff_existsUnique]
refine ⟨fun h g => ?_, fun h g => ?_⟩
· obtain ⟨x, h1, h2⟩ := h g
exact
⟨x.1, (congr_arg (· ∈ T) (eq_inv_mul_of_mul_eq h1)).mp x.2.2, fun y hy =>
(Prod.ext_iff.mp (h2 ⟨y, (↑y)⁻¹ * g, hy⟩ (mul_inv_cancel_left ↑y g))).1⟩
· obtain ⟨x, h1, h2⟩ := h g
refine ⟨⟨x, (↑x)⁻¹ * g, h1⟩, mul_inv_cancel_left (↑x) g, fun y hy => ?_⟩
have hf := h2 y.1 ((congr_arg (· ∈ T) (eq_inv_mul_of_mul_eq hy)).mp y.2.2)
exact Prod.ext hf (Subtype.ext (eq_inv_mul_of_mul_eq (hf ▸ hy)))
@[to_additive]
lemma isComplement_iff_existsUnique_mul_inv_mem :
IsComplement S T ↔ ∀ g, ∃! t : T, g * (t : G)⁻¹ ∈ S := by
convert isComplement_iff_existsUnique with g
constructor <;> rintro ⟨x, hx, hx'⟩
· exact ⟨(⟨_, hx⟩, x), by simp, by aesop⟩
· exact ⟨x.2, by simp [← hx], fun y hy ↦ (Prod.ext_iff.1 <| by simpa using hx' (⟨_, hy⟩, y)).2⟩
set_option linter.deprecated false in
@[to_additive
(attr := deprecated isComplement_iff_existsUnique_mul_inv_mem (since := "2024-12-18"))]
theorem mem_rightTransversals_iff_existsUnique_mul_inv_mem :
S ∈ rightTransversals T ↔ ∀ g : G, ∃! s : S, g * (s : G)⁻¹ ∈ T := by
rw [rightTransversals, Set.mem_setOf_eq, isComplement_iff_existsUnique]
refine ⟨fun h g => ?_, fun h g => ?_⟩
· obtain ⟨x, h1, h2⟩ := h g
exact
⟨x.2, (congr_arg (· ∈ T) (eq_mul_inv_of_mul_eq h1)).mp x.1.2, fun y hy =>
(Prod.ext_iff.mp (h2 ⟨⟨g * (↑y)⁻¹, hy⟩, y⟩ (inv_mul_cancel_right g y))).2⟩
· obtain ⟨x, h1, h2⟩ := h g
refine ⟨⟨⟨g * (↑x)⁻¹, h1⟩, x⟩, inv_mul_cancel_right g x, fun y hy => ?_⟩
have hf := h2 y.2 ((congr_arg (· ∈ T) (eq_mul_inv_of_mul_eq hy)).mp y.1.2)
exact Prod.ext (Subtype.ext (eq_mul_inv_of_mul_eq (hf ▸ hy))) hf
@[to_additive]
lemma isComplement_subgroup_right_iff_existsUnique_quotientGroupMk :
IsComplement S H ↔ ∀ q : G ⧸ H, ∃! s : S, QuotientGroup.mk s.1 = q := by
simp_rw [isComplement_iff_existsUnique_inv_mul_mem, SetLike.mem_coe, ← QuotientGroup.eq,
QuotientGroup.forall_mk]
set_option linter.deprecated false in
@[to_additive
(attr := deprecated isComplement_subgroup_right_iff_existsUnique_quotientGroupMk
(since := "2024-12-18"))]
theorem mem_leftTransversals_iff_existsUnique_quotient_mk''_eq :
S ∈ leftTransversals (H : Set G) ↔
∀ q : Quotient (QuotientGroup.leftRel H), ∃! s : S, Quotient.mk'' s.1 = q := by
simp_rw [mem_leftTransversals_iff_existsUnique_inv_mul_mem, SetLike.mem_coe, ←
QuotientGroup.eq]
exact ⟨fun h q => Quotient.inductionOn' q h, fun h g => h (Quotient.mk'' g)⟩
set_option linter.docPrime false in
@[to_additive]
lemma isComplement_subgroup_left_iff_existsUnique_quotientMk'' :
IsComplement H T ↔
∀ q : Quotient (QuotientGroup.rightRel H), ∃! t : T, Quotient.mk'' t.1 = q := by
simp_rw [isComplement_iff_existsUnique_mul_inv_mem, SetLike.mem_coe,
← QuotientGroup.rightRel_apply, ← Quotient.eq'', Quotient.forall]
set_option linter.deprecated false in
@[to_additive
(attr := deprecated isComplement_subgroup_left_iff_existsUnique_quotientMk''
(since := "2024-12-18"))]
theorem mem_rightTransversals_iff_existsUnique_quotient_mk''_eq :
S ∈ rightTransversals (H : Set G) ↔
∀ q : Quotient (QuotientGroup.rightRel H), ∃! s : S, Quotient.mk'' s.1 = q := by
simp_rw [mem_rightTransversals_iff_existsUnique_mul_inv_mem, SetLike.mem_coe, ←
QuotientGroup.rightRel_apply, ← Quotient.eq'']
exact ⟨fun h q => Quotient.inductionOn' q h, fun h g => h (Quotient.mk'' g)⟩
@[to_additive]
lemma isComplement_subgroup_right_iff_bijective :
IsComplement S H ↔ Bijective (S.restrict (QuotientGroup.mk : G → G ⧸ H)) :=
isComplement_subgroup_right_iff_existsUnique_quotientGroupMk.trans
(bijective_iff_existsUnique (S.restrict QuotientGroup.mk)).symm
set_option linter.deprecated false in
@[to_additive
(attr := deprecated isComplement_subgroup_right_iff_bijective (since := "2024-12-18"))]
theorem mem_leftTransversals_iff_bijective :
S ∈ leftTransversals (H : Set G) ↔
Function.Bijective (S.restrict (Quotient.mk'' : G → Quotient (QuotientGroup.leftRel H))) :=
mem_leftTransversals_iff_existsUnique_quotient_mk''_eq.trans
(Function.bijective_iff_existsUnique (S.restrict Quotient.mk'')).symm
@[to_additive]
lemma isComplement_subgroup_left_iff_bijective :
IsComplement H T ↔
Bijective (T.restrict (Quotient.mk'' : G → Quotient (QuotientGroup.rightRel H))) :=
isComplement_subgroup_left_iff_existsUnique_quotientMk''.trans
(bijective_iff_existsUnique (T.restrict Quotient.mk'')).symm
set_option linter.deprecated false in
@[to_additive
(attr := deprecated isComplement_subgroup_left_iff_bijective (since := "2024-12-18"))]
theorem mem_rightTransversals_iff_bijective :
S ∈ rightTransversals (H : Set G) ↔
Function.Bijective (S.restrict (Quotient.mk'' : G → Quotient (QuotientGroup.rightRel H))) :=
mem_rightTransversals_iff_existsUnique_quotient_mk''_eq.trans
(Function.bijective_iff_existsUnique (S.restrict Quotient.mk'')).symm
@[to_additive]
lemma IsComplement.card_left (h : IsComplement S H) : Nat.card S = H.index :=
Nat.card_congr <| .ofBijective _ <| isComplement_subgroup_right_iff_bijective.mp h
set_option linter.deprecated false in
@[to_additive (attr := deprecated IsComplement.card_left (since := "2024-12-18"))]
theorem card_left_transversal (h : S ∈ leftTransversals (H : Set G)) : Nat.card S = H.index :=
Nat.card_congr <| Equiv.ofBijective _ <| mem_leftTransversals_iff_bijective.mp h
@[to_additive]
lemma IsComplement.card_right (h : IsComplement H T) : Nat.card T = H.index :=
Nat.card_congr <| (Equiv.ofBijective _ <| isComplement_subgroup_left_iff_bijective.mp h).trans <|
QuotientGroup.quotientRightRelEquivQuotientLeftRel H
set_option linter.deprecated false in
@[to_additive (attr := deprecated IsComplement.card_right (since := "2024-12-18"))]
theorem card_right_transversal (h : S ∈ rightTransversals (H : Set G)) : Nat.card S = H.index :=
Nat.card_congr <|
(Equiv.ofBijective _ <| mem_rightTransversals_iff_bijective.mp h).trans <|
QuotientGroup.quotientRightRelEquivQuotientLeftRel H
@[to_additive]
lemma isComplement_range_left {f : G ⧸ H → G} (hf : ∀ q, ↑(f q) = q) :
IsComplement (range f) H := by
rw [isComplement_subgroup_right_iff_bijective]
refine ⟨?_, fun q ↦ ⟨⟨f q, q, rfl⟩, hf q⟩⟩
rintro ⟨-, q₁, rfl⟩ ⟨-, q₂, rfl⟩ h
exact Subtype.ext <| congr_arg f <| ((hf q₁).symm.trans h).trans (hf q₂)
set_option linter.deprecated false in
@[to_additive (attr := deprecated isComplement_range_left (since := "2024-12-18"))]
theorem range_mem_leftTransversals {f : G ⧸ H → G} (hf : ∀ q, ↑(f q) = q) :
Set.range f ∈ leftTransversals (H : Set G) :=
mem_leftTransversals_iff_bijective.mpr
⟨by rintro ⟨-, q₁, rfl⟩ ⟨-, q₂, rfl⟩ h
exact Subtype.ext <| congr_arg f <| ((hf q₁).symm.trans h).trans (hf q₂),
fun q => ⟨⟨f q, q, rfl⟩, hf q⟩⟩
@[to_additive]
lemma isComplement_range_right {f : Quotient (QuotientGroup.rightRel H) → G}
(hf : ∀ q, Quotient.mk'' (f q) = q) : IsComplement H (range f) := by
rw [isComplement_subgroup_left_iff_bijective]
refine ⟨?_, fun q ↦ ⟨⟨f q, q, rfl⟩, hf q⟩⟩
rintro ⟨-, q₁, rfl⟩ ⟨-, q₂, rfl⟩ h
exact Subtype.ext <| congr_arg f <| ((hf q₁).symm.trans h).trans (hf q₂)
set_option linter.deprecated false in
@[to_additive (attr := deprecated isComplement_range_right (since := "2024-12-18"))]
theorem range_mem_rightTransversals {f : Quotient (QuotientGroup.rightRel H) → G}
(hf : ∀ q, Quotient.mk'' (f q) = q) : Set.range f ∈ rightTransversals (H : Set G) :=
mem_rightTransversals_iff_bijective.mpr
⟨by rintro ⟨-, q₁, rfl⟩ ⟨-, q₂, rfl⟩ h
exact Subtype.ext <| congr_arg f <| ((hf q₁).symm.trans h).trans (hf q₂),
fun q => ⟨⟨f q, q, rfl⟩, hf q⟩⟩
@[to_additive]
lemma exists_isComplement_left (H : Subgroup G) (g : G) : ∃ S, IsComplement S H ∧ g ∈ S := by
classical
refine ⟨Set.range (Function.update Quotient.out _ g), isComplement_range_left fun q ↦ ?_,
QuotientGroup.mk g, Function.update_self (Quotient.mk'' g) g Quotient.out⟩
by_cases hq : q = Quotient.mk'' g
· exact hq.symm ▸ congr_arg _ (Function.update_self (Quotient.mk'' g) g Quotient.out)
· refine Function.update_of_ne ?_ g Quotient.out ▸ q.out_eq'
exact hq
set_option linter.deprecated false in
@[to_additive (attr := deprecated exists_isComplement_left (since := "2024-12-18"))]
lemma exists_left_transversal (H : Subgroup G) (g : G) :
∃ S ∈ leftTransversals (H : Set G), g ∈ S := by
classical
refine
⟨Set.range (Function.update Quotient.out _ g), range_mem_leftTransversals fun q => ?_,
Quotient.mk'' g, Function.update_self (Quotient.mk'' g) g Quotient.out⟩
by_cases hq : q = Quotient.mk'' g
· exact hq.symm ▸ congr_arg _ (Function.update_self (Quotient.mk'' g) g Quotient.out)
· refine (Function.update_of_ne ?_ g Quotient.out) ▸ q.out_eq'
exact hq
@[to_additive]
lemma exists_isComplement_right (H : Subgroup G) (g : G) :
∃ T, IsComplement H T ∧ g ∈ T := by
classical
refine ⟨Set.range (Function.update Quotient.out _ g), isComplement_range_right fun q ↦ ?_,
Quotient.mk'' g, Function.update_self (Quotient.mk'' g) g Quotient.out⟩
by_cases hq : q = Quotient.mk'' g
· exact hq.symm ▸ congr_arg _ (Function.update_self (Quotient.mk'' g) g Quotient.out)
· refine Function.update_of_ne ?_ g Quotient.out ▸ q.out_eq'
exact hq
set_option linter.deprecated false in
@[to_additive (attr := deprecated exists_isComplement_right (since := "2024-12-18"))]
lemma exists_right_transversal (H : Subgroup G) (g : G) :
∃ S ∈ rightTransversals (H : Set G), g ∈ S := by
classical
refine
⟨Set.range (Function.update Quotient.out _ g), range_mem_rightTransversals fun q => ?_,
Quotient.mk'' g, Function.update_self (Quotient.mk'' g) g Quotient.out⟩
by_cases hq : q = Quotient.mk'' g
· exact hq.symm ▸ congr_arg _ (Function.update_self (Quotient.mk'' g) g Quotient.out)
· exact Eq.trans (congr_arg _ (Function.update_of_ne hq g Quotient.out)) q.out_eq'
/-- Given two subgroups `H' ⊆ H`, there exists a left transversal to `H'` inside `H`. -/
@[to_additive "Given two subgroups `H' ⊆ H`, there exists a transversal to `H'` inside `H`"]
lemma exists_left_transversal_of_le {H' H : Subgroup G} (h : H' ≤ H) :
∃ S : Set G, S * H' = H ∧ Nat.card S * Nat.card H' = Nat.card H := by
let H'' : Subgroup H := H'.comap H.subtype
have : H' = H''.map H.subtype := by simp [H'', h]
rw [this]
obtain ⟨S, cmem, -⟩ := H''.exists_isComplement_left 1
refine ⟨H.subtype '' S, ?_, ?_⟩
· have : H.subtype '' (S * H'') = H.subtype '' S * H''.map H.subtype := image_mul H.subtype
rw [← this, cmem.mul_eq]
simp [Set.ext_iff]
· rw [← cmem.card_mul_card]
refine congr_arg₂ (· * ·) ?_ ?_ <;>
exact Nat.card_congr (Equiv.Set.image _ _ <| subtype_injective H).symm
/-- Given two subgroups `H' ⊆ H`, there exists a right transversal to `H'` inside `H`. -/
@[to_additive "Given two subgroups `H' ⊆ H`, there exists a transversal to `H'` inside `H`"]
lemma exists_right_transversal_of_le {H' H : Subgroup G} (h : H' ≤ H) :
∃ S : Set G, H' * S = H ∧ Nat.card H' * Nat.card S = Nat.card H := by
let H'' : Subgroup H := H'.comap H.subtype
have : H' = H''.map H.subtype := by simp [H'', h]
rw [this]
obtain ⟨S, cmem, -⟩ := H''.exists_isComplement_right 1
refine ⟨H.subtype '' S, ?_, ?_⟩
· have : H.subtype '' (H'' * S) = H''.map H.subtype * H.subtype '' S := image_mul H.subtype
rw [← this, cmem.mul_eq]
simp [Set.ext_iff]
· have : Nat.card H'' * Nat.card S = Nat.card H := cmem.card_mul_card
rw [← this]
refine congr_arg₂ (· * ·) ?_ ?_ <;>
exact Nat.card_congr (Equiv.Set.image _ _ <| subtype_injective H).symm
namespace IsComplement
/-- The equivalence `G ≃ S × T`, such that the inverse is `(*) : S × T → G` -/
noncomputable def equiv {S T : Set G} (hST : IsComplement S T) : G ≃ S × T :=
(Equiv.ofBijective (fun x : S × T => x.1.1 * x.2.1) hST).symm
variable (hST : IsComplement S T) (hHT : IsComplement H T) (hSK : IsComplement S K)
@[simp] theorem equiv_symm_apply (x : S × T) : (hST.equiv.symm x : G) = x.1.1 * x.2.1 := rfl
@[simp]
theorem equiv_fst_mul_equiv_snd (g : G) : ↑(hST.equiv g).fst * (hST.equiv g).snd = g :=
(Equiv.ofBijective (fun x : S × T => x.1.1 * x.2.1) hST).right_inv g
theorem equiv_fst_eq_mul_inv (g : G) : ↑(hST.equiv g).fst = g * ((hST.equiv g).snd : G)⁻¹ :=
eq_mul_inv_of_mul_eq (hST.equiv_fst_mul_equiv_snd g)
theorem equiv_snd_eq_inv_mul (g : G) : ↑(hST.equiv g).snd = ((hST.equiv g).fst : G)⁻¹ * g :=
eq_inv_mul_of_mul_eq (hST.equiv_fst_mul_equiv_snd g)
theorem equiv_fst_eq_iff_leftCosetEquivalence {g₁ g₂ : G} :
(hSK.equiv g₁).fst = (hSK.equiv g₂).fst ↔ LeftCosetEquivalence K g₁ g₂ := by
rw [LeftCosetEquivalence, leftCoset_eq_iff]
constructor
· intro h
rw [← hSK.equiv_fst_mul_equiv_snd g₂, ← hSK.equiv_fst_mul_equiv_snd g₁, ← h,
mul_inv_rev, ← mul_assoc, inv_mul_cancel_right, ← coe_inv, ← coe_mul]
exact Subtype.property _
· intro h
apply (isComplement_iff_existsUnique_inv_mul_mem.1 hSK g₁).unique
· -- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644
rw [equiv_fst_eq_mul_inv]; simp
· rw [SetLike.mem_coe, ← mul_mem_cancel_right h]
-- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644
rw [equiv_fst_eq_mul_inv]; simp [equiv_fst_eq_mul_inv, ← mul_assoc]
theorem equiv_snd_eq_iff_rightCosetEquivalence {g₁ g₂ : G} :
(hHT.equiv g₁).snd = (hHT.equiv g₂).snd ↔ RightCosetEquivalence H g₁ g₂ := by
rw [RightCosetEquivalence, rightCoset_eq_iff]
constructor
· intro h
rw [← hHT.equiv_fst_mul_equiv_snd g₂, ← hHT.equiv_fst_mul_equiv_snd g₁, ← h,
mul_inv_rev, mul_assoc, mul_inv_cancel_left, ← coe_inv, ← coe_mul]
exact Subtype.property _
· intro h
apply (isComplement_iff_existsUnique_mul_inv_mem.1 hHT g₁).unique
· -- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644
rw [equiv_snd_eq_inv_mul]; simp
· rw [SetLike.mem_coe, ← mul_mem_cancel_left h]
-- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644
rw [equiv_snd_eq_inv_mul, mul_assoc]; simp
theorem leftCosetEquivalence_equiv_fst (g : G) :
LeftCosetEquivalence K g ((hSK.equiv g).fst : G) := by
-- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644
rw [equiv_fst_eq_mul_inv]; simp [LeftCosetEquivalence, leftCoset_eq_iff]
theorem rightCosetEquivalence_equiv_snd (g : G) :
RightCosetEquivalence H g ((hHT.equiv g).snd : G) := by
-- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644
rw [RightCosetEquivalence, rightCoset_eq_iff, equiv_snd_eq_inv_mul]; simp
theorem equiv_fst_eq_self_of_mem_of_one_mem {g : G} (h1 : 1 ∈ T) (hg : g ∈ S) :
(hST.equiv g).fst = ⟨g, hg⟩ := by
have : hST.equiv.symm (⟨g, hg⟩, ⟨1, h1⟩) = g := by
rw [equiv, Equiv.ofBijective]; simp
conv_lhs => rw [← this, Equiv.apply_symm_apply]
theorem equiv_snd_eq_self_of_mem_of_one_mem {g : G} (h1 : 1 ∈ S) (hg : g ∈ T) :
(hST.equiv g).snd = ⟨g, hg⟩ := by
have : hST.equiv.symm (⟨1, h1⟩, ⟨g, hg⟩) = g := by
rw [equiv, Equiv.ofBijective]; simp
conv_lhs => rw [← this, Equiv.apply_symm_apply]
theorem equiv_snd_eq_one_of_mem_of_one_mem {g : G} (h1 : 1 ∈ T) (hg : g ∈ S) :
(hST.equiv g).snd = ⟨1, h1⟩ := by
ext
rw [equiv_snd_eq_inv_mul, equiv_fst_eq_self_of_mem_of_one_mem _ h1 hg, inv_mul_cancel]
theorem equiv_fst_eq_one_of_mem_of_one_mem {g : G} (h1 : 1 ∈ S) (hg : g ∈ T) :
(hST.equiv g).fst = ⟨1, h1⟩ := by
ext
rw [equiv_fst_eq_mul_inv, equiv_snd_eq_self_of_mem_of_one_mem _ h1 hg, mul_inv_cancel]
theorem equiv_mul_right (g : G) (k : K) :
hSK.equiv (g * k) = ((hSK.equiv g).fst, (hSK.equiv g).snd * k) := by
have : (hSK.equiv (g * k)).fst = (hSK.equiv g).fst :=
hSK.equiv_fst_eq_iff_leftCosetEquivalence.2
(by simp [LeftCosetEquivalence, leftCoset_eq_iff])
ext
· rw [this]
· rw [coe_mul, equiv_snd_eq_inv_mul, this, equiv_snd_eq_inv_mul, mul_assoc]
theorem equiv_mul_right_of_mem {g k : G} (h : k ∈ K) :
hSK.equiv (g * k) = ((hSK.equiv g).fst, (hSK.equiv g).snd * ⟨k, h⟩) :=
equiv_mul_right _ g ⟨k, h⟩
theorem equiv_mul_left (h : H) (g : G) :
hHT.equiv (h * g) = (h * (hHT.equiv g).fst, (hHT.equiv g).snd) := by
have : (hHT.equiv (h * g)).2 = (hHT.equiv g).2 := hHT.equiv_snd_eq_iff_rightCosetEquivalence.2 ?_
· ext
· rw [coe_mul, equiv_fst_eq_mul_inv, this, equiv_fst_eq_mul_inv, mul_assoc]
· rw [this]
· simp [RightCosetEquivalence, ← smul_smul]
theorem equiv_mul_left_of_mem {h g : G} (hh : h ∈ H) :
hHT.equiv (h * g) = (⟨h, hh⟩ * (hHT.equiv g).fst, (hHT.equiv g).snd) :=
equiv_mul_left _ ⟨h, hh⟩ g
theorem equiv_one (hs1 : 1 ∈ S) (ht1 : 1 ∈ T) :
hST.equiv 1 = (⟨1, hs1⟩, ⟨1, ht1⟩) := by
rw [Equiv.apply_eq_iff_eq_symm_apply]; simp [equiv]
theorem equiv_fst_eq_self_iff_mem {g : G} (h1 : 1 ∈ T) :
((hST.equiv g).fst : G) = g ↔ g ∈ S := by
constructor
· intro h
rw [← h]
exact Subtype.prop _
· intro h
rw [hST.equiv_fst_eq_self_of_mem_of_one_mem h1 h]
theorem equiv_snd_eq_self_iff_mem {g : G} (h1 : 1 ∈ S) :
((hST.equiv g).snd : G) = g ↔ g ∈ T := by
constructor
· intro h
rw [← h]
exact Subtype.prop _
· intro h
rw [hST.equiv_snd_eq_self_of_mem_of_one_mem h1 h]
theorem coe_equiv_fst_eq_one_iff_mem {g : G} (h1 : 1 ∈ S) :
((hST.equiv g).fst : G) = 1 ↔ g ∈ T := by
rw [equiv_fst_eq_mul_inv, mul_inv_eq_one, eq_comm, equiv_snd_eq_self_iff_mem _ h1]
theorem coe_equiv_snd_eq_one_iff_mem {g : G} (h1 : 1 ∈ T) :
((hST.equiv g).snd : G) = 1 ↔ g ∈ S := by
rw [equiv_snd_eq_inv_mul, inv_mul_eq_one, equiv_fst_eq_self_iff_mem _ h1]
/-- A left transversal is in bijection with left cosets. -/
@[to_additive "A left transversal is in bijection with left cosets."]
noncomputable def leftQuotientEquiv (hS : IsComplement S H) : G ⧸ H ≃ S :=
(Equiv.ofBijective _ (isComplement_subgroup_right_iff_bijective.mp hS)).symm
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemLeftTransversals.toEquiv := leftQuotientEquiv
/-- A left transversal is finite iff the subgroup has finite index. -/
@[to_additive "A left transversal is finite iff the subgroup has finite index."]
theorem finite_left_iff (h : IsComplement S H) : Finite S ↔ H.FiniteIndex := by
rw [← h.leftQuotientEquiv.finite_iff]
exact ⟨fun _ ↦ finiteIndex_of_finite_quotient, fun _ ↦ finite_quotient_of_finiteIndex⟩
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemLeftTransversals.finite_iff := finite_left_iff
@[to_additive]
lemma finite_left [H.FiniteIndex] (hS : IsComplement S H) : S.Finite := hS.finite_left_iff.2 ‹_›
@[to_additive]
theorem quotientGroupMk_leftQuotientEquiv (hS : IsComplement S H) (q : G ⧸ H) :
Quotient.mk'' (leftQuotientEquiv hS q : G) = q :=
hS.leftQuotientEquiv.symm_apply_apply q
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemLeftTransversals.mk''_toEquiv := quotientGroupMk_leftQuotientEquiv
@[to_additive]
theorem leftQuotientEquiv_apply {f : G ⧸ H → G} (hf : ∀ q, (f q : G ⧸ H) = q) (q : G ⧸ H) :
(leftQuotientEquiv (isComplement_range_left hf) q : G) = f q := by
refine (Subtype.ext_iff.mp ?_).trans (Subtype.coe_mk (f q) ⟨q, rfl⟩)
exact (leftQuotientEquiv (isComplement_range_left hf)).apply_eq_iff_eq_symm_apply.mpr (hf q).symm
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemLeftTransversals.toEquiv_apply := leftQuotientEquiv_apply
/-- A left transversal can be viewed as a function mapping each element of the group
to the chosen representative from that left coset. -/
@[to_additive "A left transversal can be viewed as a function mapping each element of the group
to the chosen representative from that left coset."]
noncomputable def toLeftFun (hS : IsComplement S H) : G → S := leftQuotientEquiv hS ∘ Quotient.mk''
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemLeftTransversals.toFun := toLeftFun
@[to_additive]
theorem inv_toLeftFun_mul_mem (hS : IsComplement S H) (g : G) :
(toLeftFun hS g : G)⁻¹ * g ∈ H :=
QuotientGroup.leftRel_apply.mp <| Quotient.exact' <| quotientGroupMk_leftQuotientEquiv _ _
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemLeftTransversals.inv_toFun_mul_mem := inv_toLeftFun_mul_mem
@[to_additive]
theorem inv_mul_toLeftFun_mem (hS : IsComplement S H) (g : G) :
g⁻¹ * toLeftFun hS g ∈ H :=
(congr_arg (· ∈ H) (by rw [mul_inv_rev, inv_inv])).mp (H.inv_mem (inv_toLeftFun_mul_mem hS g))
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemLeftTransversals.inv_mul_toFun_mem := inv_mul_toLeftFun_mem
/-- A right transversal is in bijection with right cosets. -/
@[to_additive "A right transversal is in bijection with right cosets."]
noncomputable def rightQuotientEquiv (hT : IsComplement H T) :
Quotient (QuotientGroup.rightRel H) ≃ T :=
(Equiv.ofBijective _ (isComplement_subgroup_left_iff_bijective.mp hT)).symm
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemRightTransversals.toEquiv := rightQuotientEquiv
/-- A right transversal is finite iff the subgroup has finite index. -/
@[to_additive "A right transversal is finite iff the subgroup has finite index."]
theorem finite_right_iff (h : IsComplement H T) : Finite T ↔ H.FiniteIndex := by
rw [← h.rightQuotientEquiv.finite_iff,
(QuotientGroup.quotientRightRelEquivQuotientLeftRel H).finite_iff]
exact ⟨fun _ ↦ finiteIndex_of_finite_quotient, fun _ ↦ finite_quotient_of_finiteIndex⟩
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemRightTransversals.finite_iff := finite_right_iff
@[to_additive]
lemma finite_right [H.FiniteIndex] (hT : IsComplement H T) : T.Finite := hT.finite_right_iff.2 ‹_›
@[to_additive]
theorem mk''_rightQuotientEquiv (hT : IsComplement H T)
(q : Quotient (QuotientGroup.rightRel H)) : Quotient.mk'' (rightQuotientEquiv hT q : G) = q :=
(rightQuotientEquiv hT).symm_apply_apply q
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemRightTransversals.mk''_toEquiv := mk''_rightQuotientEquiv
@[to_additive]
theorem rightQuotientEquiv_apply {f : Quotient (QuotientGroup.rightRel H) → G}
(hf : ∀ q, Quotient.mk'' (f q) = q) (q : Quotient (QuotientGroup.rightRel H)) :
(rightQuotientEquiv (isComplement_range_right hf) q : G) = f q := by
refine (Subtype.ext_iff.mp ?_).trans (Subtype.coe_mk (f q) ⟨q, rfl⟩)
exact (rightQuotientEquiv (isComplement_range_right hf)).apply_eq_iff_eq_symm_apply.2 (hf q).symm
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemRightTransversals.toEquiv_apply := rightQuotientEquiv_apply
/-- A right transversal can be viewed as a function mapping each element of the group
to the chosen representative from that right coset. -/
@[to_additive "A right transversal can be viewed as a function mapping each element of the group
to the chosen representative from that right coset."]
noncomputable def toRightFun (hT : IsComplement H T) : G → T := rightQuotientEquiv hT ∘ .mk''
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemRightTransversals.toFun := toRightFun
@[to_additive]
theorem mul_inv_toRightFun_mem (hT : IsComplement H T) (g : G) :
g * (toRightFun hT g : G)⁻¹ ∈ H :=
QuotientGroup.rightRel_apply.mp <| Quotient.exact' <| mk''_rightQuotientEquiv _ _
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemRighTransversals.mul_inv_toFun_mem := mul_inv_toRightFun_mem
@[to_additive]
theorem toRightFun_mul_inv_mem (hT : IsComplement H T) (g : G) :
(toRightFun hT g : G) * g⁻¹ ∈ H :=
(congr_arg (· ∈ H) (by rw [mul_inv_rev, inv_inv])).mp (H.inv_mem (mul_inv_toRightFun_mem hT g))
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemRighTransversals.toFun_mul_inv_mem := toRightFun_mul_inv_mem
end IsComplement
section Action
open Pointwise MulAction MemLeftTransversals
/-- The collection of left transversals of a subgroup -/
@[to_additive "The collection of left transversals of a subgroup."]
abbrev LeftTransversal (H : Subgroup G) := {S : Set G // IsComplement S H}
/-- The collection of right transversals of a subgroup -/
@[to_additive "The collection of right transversals of a subgroup."]
abbrev RightTransversal (H : Subgroup G) := {T : Set G // IsComplement H T}
variable {F : Type*} [Group F] [MulAction F G] [QuotientAction F H]
@[to_additive]
noncomputable instance : MulAction F H.LeftTransversal where
smul f T :=
⟨f • (T : Set G), by
refine isComplement_iff_existsUnique_inv_mul_mem.mpr fun g => ?_
obtain ⟨t, ht1, ht2⟩ := isComplement_iff_existsUnique_inv_mul_mem.mp T.2 (f⁻¹ • g)
refine ⟨⟨f • (t : G), Set.smul_mem_smul_set t.2⟩, ?_, ?_⟩
· exact smul_inv_smul f g ▸ QuotientAction.inv_mul_mem f ht1
· rintro ⟨-, t', ht', rfl⟩ h
replace h := QuotientAction.inv_mul_mem f⁻¹ h
simp only [Subtype.ext_iff, Subtype.coe_mk, smul_left_cancel_iff, inv_smul_smul] at h ⊢
exact Subtype.ext_iff.mp (ht2 ⟨t', ht'⟩ h)⟩
one_smul T := Subtype.ext (one_smul F (T : Set G))
mul_smul f₁ f₂ T := Subtype.ext (mul_smul f₁ f₂ (T : Set G))
@[to_additive]
theorem smul_toLeftFun (f : F) (S : H.LeftTransversal) (g : G) :
(f • (S.2.toLeftFun g : G)) = (f • S).2.toLeftFun (f • g) :=
Subtype.ext_iff.mp <| @ExistsUnique.unique (↥(f • (S : Set G))) (fun s => (↑s)⁻¹ * f • g ∈ H)
(isComplement_iff_existsUnique_inv_mul_mem.mp (f • S).2 (f • g))
⟨f • (S.2.toLeftFun g : G), Set.smul_mem_smul_set (Subtype.coe_prop _)⟩
((f • S).2.toLeftFun (f • g))
(QuotientAction.inv_mul_mem f (S.2.inv_toLeftFun_mul_mem g))
((f • S).2.inv_toLeftFun_mul_mem (f • g))
@[to_additive]
theorem smul_leftQuotientEquiv (f : F) (S : H.LeftTransversal) (q : G ⧸ H) :
f • (S.2.leftQuotientEquiv q : G) = (f • S).2.leftQuotientEquiv (f • q) :=
Quotient.inductionOn' q fun g => smul_toLeftFun f S g
@[to_additive]
theorem smul_apply_eq_smul_apply_inv_smul (f : F) (S : H.LeftTransversal) (q : G ⧸ H) :
((f • S).2.leftQuotientEquiv q : G) = f • (S.2.leftQuotientEquiv (f⁻¹ • q) : G) := by
rw [smul_leftQuotientEquiv, smul_inv_smul]
end Action
@[to_additive]
instance : Inhabited H.LeftTransversal :=
⟨⟨Set.range Quotient.out, isComplement_range_left Quotient.out_eq'⟩⟩
@[to_additive]
instance : Inhabited H.RightTransversal :=
⟨⟨Set.range Quotient.out, isComplement_range_right Quotient.out_eq'⟩⟩
theorem IsComplement'.isCompl (h : IsComplement' H K) : IsCompl H K := by
refine
⟨disjoint_iff_inf_le.mpr fun g ⟨p, q⟩ =>
let x : H × K := ⟨⟨g, p⟩, 1⟩
let y : H × K := ⟨1, g, q⟩
Subtype.ext_iff.mp
(Prod.ext_iff.mp (show x = y from h.1 ((mul_one g).trans (one_mul g).symm))).1,
codisjoint_iff_le_sup.mpr fun g _ => ?_⟩
obtain ⟨⟨h, k⟩, rfl⟩ := h.2 g
exact Subgroup.mul_mem_sup h.2 k.2
theorem IsComplement'.sup_eq_top (h : IsComplement' H K) : H ⊔ K = ⊤ :=
h.isCompl.sup_eq_top
theorem IsComplement'.disjoint (h : IsComplement' H K) : Disjoint H K :=
h.isCompl.disjoint
theorem IsComplement'.index_eq_card (h : IsComplement' H K) : K.index = Nat.card H :=
h.card_left.symm
/-- If `H` and `K` are complementary with `K` normal, then `G ⧸ K` is isomorphic to `H`. -/
@[simps!]
noncomputable def IsComplement'.QuotientMulEquiv [K.Normal] (h : H.IsComplement' K) :
G ⧸ K ≃* H :=
MulEquiv.symm
{ h.leftQuotientEquiv.symm with
map_mul' := fun _ _ ↦ rfl }
theorem IsComplement.card_mul (h : IsComplement S T) :
Nat.card S * Nat.card T = Nat.card G :=
(Nat.card_prod _ _).symm.trans (Nat.card_eq_of_bijective _ h)
theorem IsComplement'.card_mul (h : IsComplement' H K) :
Nat.card H * Nat.card K = Nat.card G :=
IsComplement.card_mul h
theorem isComplement'_of_disjoint_and_mul_eq_univ (h1 : Disjoint H K)
(h2 : ↑H * ↑K = (Set.univ : Set G)) : IsComplement' H K := by
refine ⟨mul_injective_of_disjoint h1, fun g => ?_⟩
obtain ⟨h, hh, k, hk, hg⟩ := Set.eq_univ_iff_forall.mp h2 g
exact ⟨(⟨h, hh⟩, ⟨k, hk⟩), hg⟩
theorem isComplement'_of_card_mul_and_disjoint [Finite G]
(h1 : Nat.card H * Nat.card K = Nat.card G) (h2 : Disjoint H K) :
IsComplement' H K :=
(Nat.bijective_iff_injective_and_card _).mpr
⟨mul_injective_of_disjoint h2, (Nat.card_prod H K).trans h1⟩
theorem isComplement'_iff_card_mul_and_disjoint [Finite G] :
IsComplement' H K ↔ Nat.card H * Nat.card K = Nat.card G ∧ Disjoint H K :=
⟨fun h => ⟨h.card_mul, h.disjoint⟩, fun h => isComplement'_of_card_mul_and_disjoint h.1 h.2⟩
theorem isComplement'_of_coprime [Finite G]
(h1 : Nat.card H * Nat.card K = Nat.card G)
(h2 : Nat.Coprime (Nat.card H) (Nat.card K)) : IsComplement' H K :=
isComplement'_of_card_mul_and_disjoint h1 (disjoint_iff.mpr (inf_eq_bot_of_coprime h2))
theorem isComplement'_stabilizer {α : Type*} [MulAction G α] (a : α)
(h1 : ∀ h : H, h • a = a → h = 1) (h2 : ∀ g : G, ∃ h : H, h • g • a = a) :
IsComplement' H (MulAction.stabilizer G a) := by
| refine isComplement_iff_existsUnique.mpr fun g => ?_
obtain ⟨h, hh⟩ := h2 g
have hh' : (↑h * g) • a = a := by rwa [mul_smul]
refine ⟨⟨h⁻¹, h * g, hh'⟩, inv_mul_cancel_left ↑h g, ?_⟩
rintro ⟨h', g, hg : g • a = a⟩ rfl
specialize h1 (h * h') (by rwa [mul_smul, smul_def h', ← hg, ← mul_smul, hg])
refine Prod.ext (eq_inv_of_mul_eq_one_right h1) (Subtype.ext ?_)
rwa [Subtype.ext_iff, coe_one, coe_mul, ← right_eq_mul, mul_assoc (↑h) (↑h') g] at h1
end Subgroup
| Mathlib/GroupTheory/Complement.lean | 828 | 839 |
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.LinearAlgebra.AffineSpace.AffineMap
import Mathlib.Topology.Algebra.Module.LinearMap
/-!
# Continuous affine maps.
This file defines a type of bundled continuous affine maps.
Note that the definition and basic properties established here require minimal assumptions, and do
not even assume compatibility between the topological and algebraic structures. Of course it is
necessary to assume some compatibility in order to obtain a useful theory. Such a theory is
developed elsewhere for affine spaces modelled on _normed_ vector spaces, but not yet for general
topological affine spaces (since we have not defined these yet).
## Main definitions:
* `ContinuousAffineMap`
## Notation:
We introduce the notation `P →ᴬ[R] Q` for `ContinuousAffineMap R P Q`. Note that this is parallel
to the notation `E →L[R] F` for `ContinuousLinearMap R E F`.
-/
/-- A continuous map of affine spaces. -/
structure ContinuousAffineMap (R : Type*) {V W : Type*} (P Q : Type*) [Ring R] [AddCommGroup V]
[Module R V] [TopologicalSpace P] [AddTorsor V P] [AddCommGroup W] [Module R W]
[TopologicalSpace Q] [AddTorsor W Q] extends P →ᵃ[R] Q where
cont : Continuous toFun
/-- A continuous map of affine spaces. -/
notation:25 P " →ᴬ[" R "] " Q => ContinuousAffineMap R P Q
namespace ContinuousAffineMap
variable {R V W P Q : Type*} [Ring R]
variable [AddCommGroup V] [Module R V] [TopologicalSpace P] [AddTorsor V P]
variable [AddCommGroup W] [Module R W] [TopologicalSpace Q] [AddTorsor W Q]
instance : Coe (P →ᴬ[R] Q) (P →ᵃ[R] Q) :=
⟨toAffineMap⟩
attribute [coe] ContinuousAffineMap.toAffineMap
theorem toAffineMap_injective {f g : P →ᴬ[R] Q} (h : (f : P →ᵃ[R] Q) = (g : P →ᵃ[R] Q)) :
f = g := by
cases f
cases g
congr
instance : FunLike (P →ᴬ[R] Q) P Q where
coe f := f.toAffineMap
coe_injective' _ _ h := toAffineMap_injective <| DFunLike.coe_injective h
instance : ContinuousMapClass (P →ᴬ[R] Q) P Q where
map_continuous := cont
theorem toFun_eq_coe (f : P →ᴬ[R] Q) : f.toFun = ⇑f := rfl
theorem coe_injective : @Function.Injective (P →ᴬ[R] Q) (P → Q) (⇑) :=
DFunLike.coe_injective
@[ext]
theorem ext {f g : P →ᴬ[R] Q} (h : ∀ x, f x = g x) : f = g :=
DFunLike.ext _ _ h
theorem congr_fun {f g : P →ᴬ[R] Q} (h : f = g) (x : P) : f x = g x :=
DFunLike.congr_fun h _
/-- Forgetting its algebraic properties, a continuous affine map is a continuous map. -/
def toContinuousMap (f : P →ᴬ[R] Q) : C(P, Q) :=
⟨f, f.cont⟩
instance : CoeHead (P →ᴬ[R] Q) C(P, Q) :=
⟨toContinuousMap⟩
@[simp]
theorem toContinuousMap_coe (f : P →ᴬ[R] Q) : f.toContinuousMap = ↑f := rfl
@[simp, norm_cast]
theorem coe_toAffineMap (f : P →ᴬ[R] Q) : ((f : P →ᵃ[R] Q) : P → Q) = f := rfl
@[simp, norm_cast]
theorem coe_to_continuousMap (f : P →ᴬ[R] Q) : ((f : C(P, Q)) : P → Q) = f := rfl
theorem to_continuousMap_injective {f g : P →ᴬ[R] Q} (h : (f : C(P, Q)) = (g : C(P, Q))) :
f = g := by
ext a
exact ContinuousMap.congr_fun h a
@[norm_cast]
theorem coe_toAffineMap_mk (f : P →ᵃ[R] Q) (h) : ((⟨f, h⟩ : P →ᴬ[R] Q) : P →ᵃ[R] Q) = f := rfl
@[norm_cast]
theorem coe_continuousMap_mk (f : P →ᵃ[R] Q) (h) : ((⟨f, h⟩ : P →ᴬ[R] Q) : C(P, Q)) = ⟨f, h⟩ := rfl
@[simp]
theorem coe_mk (f : P →ᵃ[R] Q) (h) : ((⟨f, h⟩ : P →ᴬ[R] Q) : P → Q) = f := rfl
@[simp]
theorem mk_coe (f : P →ᴬ[R] Q) (h) : (⟨(f : P →ᵃ[R] Q), h⟩ : P →ᴬ[R] Q) = f := by
ext
rfl
@[continuity]
protected theorem continuous (f : P →ᴬ[R] Q) : Continuous f := f.2
variable (R P)
/-- The constant map is a continuous affine map. -/
def const (q : Q) : P →ᴬ[R] Q :=
{ AffineMap.const R P q with
toFun := AffineMap.const R P q
cont := continuous_const }
@[simp]
theorem coe_const (q : Q) : (const R P q : P → Q) = Function.const P q := rfl
noncomputable instance : Inhabited (P →ᴬ[R] Q) :=
⟨const R P <| Nonempty.some (by infer_instance : Nonempty Q)⟩
|
variable {R P} {W₂ Q₂ : Type*}
variable [AddCommGroup W₂] [Module R W₂] [TopologicalSpace Q₂] [AddTorsor W₂ Q₂]
| Mathlib/Topology/Algebra/ContinuousAffineMap.lean | 127 | 129 |
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition
import Mathlib.LinearAlgebra.GeneralLinearGroup
import Mathlib.LinearAlgebra.Matrix.Reindex
import Mathlib.Tactic.FieldSimp
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.LinearAlgebra.Matrix.Basis
/-!
# Determinant of families of vectors
This file defines the determinant of an endomorphism, and of a family of vectors
with respect to some basis. For the determinant of a matrix, see the file
`LinearAlgebra.Matrix.Determinant`.
## Main definitions
In the list below, and in all this file, `R` is a commutative ring (semiring
is sometimes enough), `M` and its variations are `R`-modules, `ι`, `κ`, `n` and `m` are finite
types used for indexing.
* `Basis.det`: the determinant of a family of vectors with respect to a basis,
as a multilinear map
* `LinearMap.det`: the determinant of an endomorphism `f : End R M` as a
multiplicative homomorphism (if `M` does not have a finite `R`-basis, the
result is `1` instead)
* `LinearEquiv.det`: the determinant of an isomorphism `f : M ≃ₗ[R] M` as a
multiplicative homomorphism (if `M` does not have a finite `R`-basis, the
result is `1` instead)
## Tags
basis, det, determinant
-/
noncomputable section
open Matrix LinearMap Submodule Set Function
universe u v w
variable {R : Type*} [CommRing R]
variable {M : Type*} [AddCommGroup M] [Module R M]
variable {M' : Type*} [AddCommGroup M'] [Module R M']
variable {ι : Type*} [DecidableEq ι] [Fintype ι]
variable (e : Basis ι R M)
section Conjugate
variable {A : Type*} [CommRing A]
variable {m n : Type*}
/-- If `R^m` and `R^n` are linearly equivalent, then `m` and `n` are also equivalent. -/
def equivOfPiLEquivPi {R : Type*} [Finite m] [Finite n] [CommRing R] [Nontrivial R]
(e : (m → R) ≃ₗ[R] n → R) : m ≃ n :=
Basis.indexEquiv (Basis.ofEquivFun e.symm) (Pi.basisFun _ _)
namespace Matrix
variable [Fintype m] [Fintype n]
/-- If `M` and `M'` are each other's inverse matrices, they are square matrices up to
equivalence of types. -/
def indexEquivOfInv [Nontrivial A] [DecidableEq m] [DecidableEq n] {M : Matrix m n A}
{M' : Matrix n m A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : m ≃ n :=
equivOfPiLEquivPi (toLin'OfInv hMM' hM'M)
theorem det_comm [DecidableEq n] (M N : Matrix n n A) : det (M * N) = det (N * M) := by
rw [det_mul, det_mul, mul_comm]
/-- If there exists a two-sided inverse `M'` for `M` (indexed differently),
then `det (N * M) = det (M * N)`. -/
theorem det_comm' [DecidableEq m] [DecidableEq n] {M : Matrix n m A} {N : Matrix m n A}
{M' : Matrix m n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : det (M * N) = det (N * M) := by
nontriviality A
-- Although `m` and `n` are different a priori, we will show they have the same cardinality.
-- This turns the problem into one for square matrices, which is easy.
let e := indexEquivOfInv hMM' hM'M
rw [← det_submatrix_equiv_self e, ← submatrix_mul_equiv _ _ _ (Equiv.refl n) _, det_comm,
submatrix_mul_equiv, Equiv.coe_refl, submatrix_id_id]
/-- If `M'` is a two-sided inverse for `M` (indexed differently), `det (M * N * M') = det N`.
See `Matrix.det_conj` and `Matrix.det_conj'` for the case when `M' = M⁻¹` or vice versa. -/
theorem det_conj_of_mul_eq_one [DecidableEq m] [DecidableEq n] {M : Matrix m n A}
{M' : Matrix n m A} {N : Matrix n n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) :
det (M * N * M') = det N := by
rw [← det_comm' hM'M hMM', ← Matrix.mul_assoc, hM'M, Matrix.one_mul]
end Matrix
end Conjugate
namespace LinearMap
/-! ### Determinant of a linear map -/
variable {A : Type*} [CommRing A] [Module A M]
variable {κ : Type*} [Fintype κ]
/-- The determinant of `LinearMap.toMatrix` does not depend on the choice of basis. -/
theorem det_toMatrix_eq_det_toMatrix [DecidableEq κ] (b : Basis ι A M) (c : Basis κ A M)
(f : M →ₗ[A] M) : det (LinearMap.toMatrix b b f) = det (LinearMap.toMatrix c c f) := by
rw [← linearMap_toMatrix_mul_basis_toMatrix c b c, ← basis_toMatrix_mul_linearMap_toMatrix b c b,
Matrix.det_conj_of_mul_eq_one] <;>
rw [Basis.toMatrix_mul_toMatrix, Basis.toMatrix_self]
/-- The determinant of an endomorphism given a basis.
See `LinearMap.det` for a version that populates the basis non-computably.
Although the `Trunc (Basis ι A M)` parameter makes it slightly more convenient to switch bases,
there is no good way to generalize over universe parameters, so we can't fully state in `detAux`'s
type that it does not depend on the choice of basis. Instead you can use the `detAux_def''` lemma,
or avoid mentioning a basis at all using `LinearMap.det`.
-/
irreducible_def detAux : Trunc (Basis ι A M) → (M →ₗ[A] M) →* A :=
Trunc.lift
(fun b : Basis ι A M => detMonoidHom.comp (toMatrixAlgEquiv b : (M →ₗ[A] M) →* Matrix ι ι A))
fun b c => MonoidHom.ext <| det_toMatrix_eq_det_toMatrix b c
/-- Unfold lemma for `detAux`.
See also `detAux_def''` which allows you to vary the basis.
-/
theorem detAux_def' (b : Basis ι A M) (f : M →ₗ[A] M) :
LinearMap.detAux (Trunc.mk b) f = Matrix.det (LinearMap.toMatrix b b f) := by
rw [detAux]
rfl
theorem detAux_def'' {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (tb : Trunc <| Basis ι A M)
(b' : Basis ι' A M) (f : M →ₗ[A] M) :
LinearMap.detAux tb f = Matrix.det (LinearMap.toMatrix b' b' f) := by
induction tb using Trunc.induction_on with
| h b => rw [detAux_def', det_toMatrix_eq_det_toMatrix b b']
@[simp]
theorem detAux_id (b : Trunc <| Basis ι A M) : LinearMap.detAux b LinearMap.id = 1 :=
(LinearMap.detAux b).map_one
@[simp]
theorem detAux_comp (b : Trunc <| Basis ι A M) (f g : M →ₗ[A] M) :
LinearMap.detAux b (f.comp g) = LinearMap.detAux b f * LinearMap.detAux b g :=
(LinearMap.detAux b).map_mul f g
section
open scoped Classical in
-- Discourage the elaborator from unfolding `det` and producing a huge term by marking it
-- as irreducible.
/-- The determinant of an endomorphism independent of basis.
If there is no finite basis on `M`, the result is `1` instead.
-/
protected irreducible_def det : (M →ₗ[A] M) →* A :=
if H : ∃ s : Finset M, Nonempty (Basis s A M) then LinearMap.detAux (Trunc.mk H.choose_spec.some)
else 1
open scoped Classical in
theorem coe_det [DecidableEq M] :
⇑(LinearMap.det : (M →ₗ[A] M) →* A) =
if H : ∃ s : Finset M, Nonempty (Basis s A M) then
LinearMap.detAux (Trunc.mk H.choose_spec.some)
else 1 := by
ext
rw [LinearMap.det_def]
split_ifs
· congr -- use the correct `DecidableEq` instance
rfl
end
-- Auxiliary lemma, the `simp` normal form goes in the other direction
-- (using `LinearMap.det_toMatrix`)
theorem det_eq_det_toMatrix_of_finset [DecidableEq M] {s : Finset M} (b : Basis s A M)
(f : M →ₗ[A] M) : LinearMap.det f = Matrix.det (LinearMap.toMatrix b b f) := by
have : ∃ s : Finset M, Nonempty (Basis s A M) := ⟨s, ⟨b⟩⟩
rw [LinearMap.coe_det, dif_pos, detAux_def'' _ b] <;> assumption
@[simp]
theorem det_toMatrix (b : Basis ι A M) (f : M →ₗ[A] M) :
Matrix.det (toMatrix b b f) = LinearMap.det f := by
haveI := Classical.decEq M
rw [det_eq_det_toMatrix_of_finset b.reindexFinsetRange,
det_toMatrix_eq_det_toMatrix b b.reindexFinsetRange]
@[simp]
theorem det_toMatrix' {ι : Type*} [Fintype ι] [DecidableEq ι] (f : (ι → A) →ₗ[A] ι → A) :
Matrix.det (LinearMap.toMatrix' f) = LinearMap.det f := by simp [← toMatrix_eq_toMatrix']
@[simp]
theorem det_toLin (b : Basis ι R M) (f : Matrix ι ι R) :
LinearMap.det (Matrix.toLin b b f) = f.det := by
rw [← LinearMap.det_toMatrix b, LinearMap.toMatrix_toLin]
@[simp]
theorem det_toLin' (f : Matrix ι ι R) : LinearMap.det (Matrix.toLin' f) = Matrix.det f := by
simp only [← toLin_eq_toLin', det_toLin]
/-- To show `P (LinearMap.det f)` it suffices to consider `P (Matrix.det (toMatrix _ _ f))` and
`P 1`. -/
@[elab_as_elim]
theorem det_cases [DecidableEq M] {P : A → Prop} (f : M →ₗ[A] M)
(hb : ∀ (s : Finset M) (b : Basis s A M), P (Matrix.det (toMatrix b b f))) (h1 : P 1) :
P (LinearMap.det f) := by
classical
if H : ∃ s : Finset M, Nonempty (Basis s A M) then
obtain ⟨s, ⟨b⟩⟩ := H
rw [← det_toMatrix b]
exact hb s b
else
rwa [LinearMap.det_def, dif_neg H]
@[simp]
theorem det_comp (f g : M →ₗ[A] M) :
LinearMap.det (f.comp g) = LinearMap.det f * LinearMap.det g :=
LinearMap.det.map_mul f g
@[simp]
theorem det_id : LinearMap.det (LinearMap.id : M →ₗ[A] M) = 1 :=
LinearMap.det.map_one
/-- Multiplying a map by a scalar `c` multiplies its determinant by `c ^ dim M`. -/
@[simp]
theorem det_smul [Module.Free A M] (c : A) (f : M →ₗ[A] M) :
LinearMap.det (c • f) = c ^ Module.finrank A M * LinearMap.det f := by
nontriviality A
by_cases H : ∃ s : Finset M, Nonempty (Basis s A M)
· have : Module.Finite A M := by
rcases H with ⟨s, ⟨hs⟩⟩
exact Module.Finite.of_basis hs
simp only [← det_toMatrix (Module.finBasis A M), LinearEquiv.map_smul,
Fintype.card_fin, Matrix.det_smul]
· classical
have : Module.finrank A M = 0 := finrank_eq_zero_of_not_exists_basis H
simp [coe_det, H, this]
theorem det_zero' {ι : Type*} [Finite ι] [Nonempty ι] (b : Basis ι A M) :
LinearMap.det (0 : M →ₗ[A] M) = 0 := by
haveI := Classical.decEq ι
cases nonempty_fintype ι
rwa [← det_toMatrix b, LinearEquiv.map_zero, det_zero]
/-- In a finite-dimensional vector space, the zero map has determinant `1` in dimension `0`,
and `0` otherwise. We give a formula that also works in infinite dimension, where we define
the determinant to be `1`. -/
@[simp]
theorem det_zero [Module.Free A M] :
LinearMap.det (0 : M →ₗ[A] M) = (0 : A) ^ Module.finrank A M := by
simp only [← zero_smul A (1 : M →ₗ[A] M), det_smul, mul_one, MonoidHom.map_one]
theorem det_eq_one_of_not_module_finite (h : ¬Module.Finite R M) (f : M →ₗ[R] M) : f.det = 1 := by
rw [LinearMap.det, dif_neg, MonoidHom.one_apply]
exact fun ⟨_, ⟨b⟩⟩ ↦ h (Module.Finite.of_basis b)
theorem det_eq_one_of_subsingleton [Subsingleton M] (f : M →ₗ[R] M) :
LinearMap.det (f : M →ₗ[R] M) = 1 := by
have b : Basis (Fin 0) R M := Basis.empty M
rw [← f.det_toMatrix b]
exact Matrix.det_isEmpty
theorem det_eq_one_of_finrank_eq_zero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M]
[Module 𝕜 M] (h : Module.finrank 𝕜 M = 0) (f : M →ₗ[𝕜] M) :
LinearMap.det (f : M →ₗ[𝕜] M) = 1 := by
classical
refine @LinearMap.det_cases M _ 𝕜 _ _ _ (fun t => t = 1) f ?_ rfl
intro s b
have : IsEmpty s := by
rw [← Fintype.card_eq_zero_iff]
exact (Module.finrank_eq_card_basis b).symm.trans h
exact Matrix.det_isEmpty
/-- Conjugating a linear map by a linear equiv does not change its determinant. -/
@[simp]
theorem det_conj {N : Type*} [AddCommGroup N] [Module A N] (f : M →ₗ[A] M) (e : M ≃ₗ[A] N) :
LinearMap.det ((e : M →ₗ[A] N) ∘ₗ f ∘ₗ (e.symm : N →ₗ[A] M)) = LinearMap.det f := by
classical
by_cases H : ∃ s : Finset M, Nonempty (Basis s A M)
· rcases H with ⟨s, ⟨b⟩⟩
rw [← det_toMatrix b f, ← det_toMatrix (b.map e), toMatrix_comp (b.map e) b (b.map e),
toMatrix_comp (b.map e) b b, ← Matrix.mul_assoc, Matrix.det_conj_of_mul_eq_one]
· rw [← toMatrix_comp, LinearEquiv.comp_coe, e.symm_trans_self, LinearEquiv.refl_toLinearMap,
toMatrix_id]
· rw [← toMatrix_comp, LinearEquiv.comp_coe, e.self_trans_symm, LinearEquiv.refl_toLinearMap,
toMatrix_id]
· have H' : ¬∃ t : Finset N, Nonempty (Basis t A N) := by
contrapose! H
rcases H with ⟨s, ⟨b⟩⟩
exact ⟨_, ⟨(b.map e.symm).reindexFinsetRange⟩⟩
simp only [coe_det, H, H', MonoidHom.one_apply, dif_neg, not_false_eq_true]
/-- If a linear map is invertible, so is its determinant. -/
theorem isUnit_det {A : Type*} [CommRing A] [Module A M] (f : M →ₗ[A] M) (hf : IsUnit f) :
IsUnit (LinearMap.det f) := by
obtain ⟨g, hg⟩ : ∃ g, f.comp g = 1 := hf.exists_right_inv
have : LinearMap.det f * LinearMap.det g = 1 := by
simp only [← LinearMap.det_comp, hg, MonoidHom.map_one]
exact isUnit_of_mul_eq_one _ _ this
/-- If a linear map has determinant different from `1`, then the space is finite-dimensional. -/
theorem finiteDimensional_of_det_ne_one {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] (f : M →ₗ[𝕜] M)
(hf : LinearMap.det f ≠ 1) : FiniteDimensional 𝕜 M := by
by_cases H : ∃ s : Finset M, Nonempty (Basis s 𝕜 M)
· rcases H with ⟨s, ⟨hs⟩⟩
exact FiniteDimensional.of_fintype_basis hs
· classical simp [LinearMap.coe_det, H] at hf
/-- If the determinant of a map vanishes, then the map is not onto. -/
theorem range_lt_top_of_det_eq_zero {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] {f : M →ₗ[𝕜] M}
(hf : LinearMap.det f = 0) : LinearMap.range f < ⊤ := by
have : FiniteDimensional 𝕜 M := by simp [f.finiteDimensional_of_det_ne_one, hf]
contrapose hf
simp only [lt_top_iff_ne_top, Classical.not_not, ← isUnit_iff_range_eq_top] at hf
exact isUnit_iff_ne_zero.1 (f.isUnit_det hf)
/-- If the determinant of a map vanishes, then the map is not injective. -/
theorem bot_lt_ker_of_det_eq_zero {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] {f : M →ₗ[𝕜] M}
(hf : LinearMap.det f = 0) : ⊥ < LinearMap.ker f := by
have : FiniteDimensional 𝕜 M := by simp [f.finiteDimensional_of_det_ne_one, hf]
contrapose hf
simp only [bot_lt_iff_ne_bot, Classical.not_not, ← isUnit_iff_ker_eq_bot] at hf
exact isUnit_iff_ne_zero.1 (f.isUnit_det hf)
/-- When the function is over the base ring, the determinant is the evaluation at `1`. -/
@[simp] lemma det_ring (f : R →ₗ[R] R) : f.det = f 1 := by
simp [← det_toMatrix (Basis.singleton Unit R)]
lemma det_mulLeft (a : R) : (mulLeft R a).det = a := by simp
lemma det_mulRight (a : R) : (mulRight R a).det = a := by simp
theorem det_prodMap [Module.Free R M] [Module.Free R M'] [Module.Finite R M] [Module.Finite R M']
(f : Module.End R M) (f' : Module.End R M') :
(prodMap f f').det = f.det * f'.det := by
let b := Module.Free.chooseBasis R M
let b' := Module.Free.chooseBasis R M'
rw [← det_toMatrix (b.prod b'), ← det_toMatrix b, ← det_toMatrix b', toMatrix_prodMap,
det_fromBlocks_zero₂₁, det_toMatrix]
omit [DecidableEq ι] in
theorem det_pi [Module.Free R M] [Module.Finite R M] (f : ι → M →ₗ[R] M) :
(LinearMap.pi (fun i ↦ (f i).comp (LinearMap.proj i))).det = ∏ i, (f i).det := by
classical
let b := Module.Free.chooseBasis R M
let B := (Pi.basis (fun _ : ι ↦ b)).reindex <|
(Equiv.sigmaEquivProd _ _).trans (Equiv.prodComm _ _)
simp_rw [← LinearMap.det_toMatrix B, ← LinearMap.det_toMatrix b]
have : ((LinearMap.toMatrix B B) (LinearMap.pi fun i ↦ f i ∘ₗ LinearMap.proj i)) =
Matrix.blockDiagonal (fun i ↦ LinearMap.toMatrix b b (f i)) := by
ext ⟨i₁, i₂⟩ ⟨j₁, j₂⟩
unfold B
simp_rw [LinearMap.toMatrix_apply', Matrix.blockDiagonal_apply, Basis.coe_reindex,
Function.comp_apply, Basis.repr_reindex_apply, Equiv.symm_trans_apply, Equiv.prodComm_symm,
Equiv.prodComm_apply, Equiv.sigmaEquivProd_symm_apply, Prod.swap_prod_mk, Pi.basis_apply,
Pi.basis_repr, LinearMap.pi_apply, LinearMap.coe_comp, Function.comp_apply,
LinearMap.toMatrix_apply', LinearMap.coe_proj, Function.eval, Pi.single_apply]
split_ifs with h
· rw [h]
· simp only [map_zero, Finsupp.coe_zero, Pi.zero_apply]
rw [this, Matrix.det_blockDiagonal]
end LinearMap
namespace LinearEquiv
/-- On a `LinearEquiv`, the domain of `LinearMap.det` can be promoted to `Rˣ`. -/
protected def det : (M ≃ₗ[R] M) →* Rˣ :=
(Units.map (LinearMap.det : (M →ₗ[R] M) →* R)).comp
(LinearMap.GeneralLinearGroup.generalLinearEquiv R M).symm.toMonoidHom
@[simp]
theorem coe_det (f : M ≃ₗ[R] M) : ↑(LinearEquiv.det f) = LinearMap.det (f : M →ₗ[R] M) :=
rfl
@[simp]
theorem coe_inv_det (f : M ≃ₗ[R] M) : ↑(LinearEquiv.det f)⁻¹ = LinearMap.det (f.symm : M →ₗ[R] M) :=
rfl
@[simp]
theorem det_refl : LinearEquiv.det (LinearEquiv.refl R M) = 1 :=
Units.ext <| LinearMap.det_id
@[simp]
theorem det_trans (f g : M ≃ₗ[R] M) :
LinearEquiv.det (f.trans g) = LinearEquiv.det g * LinearEquiv.det f :=
map_mul _ g f
@[simp]
theorem det_symm (f : M ≃ₗ[R] M) : LinearEquiv.det f.symm = LinearEquiv.det f⁻¹ :=
map_inv _ f
/-- Conjugating a linear equiv by a linear equiv does not change its determinant. -/
@[simp]
theorem det_conj (f : M ≃ₗ[R] M) (e : M ≃ₗ[R] M') :
LinearEquiv.det ((e.symm.trans f).trans e) = LinearEquiv.det f := by
rw [← Units.eq_iff, coe_det, coe_det, ← comp_coe, ← comp_coe, LinearMap.det_conj]
attribute [irreducible] LinearEquiv.det
end LinearEquiv
/-- The determinants of a `LinearEquiv` and its inverse multiply to 1. -/
@[simp]
theorem LinearEquiv.det_mul_det_symm {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) :
LinearMap.det (f : M →ₗ[A] M) * LinearMap.det (f.symm : M →ₗ[A] M) = 1 := by
simp [← LinearMap.det_comp]
/-- The determinants of a `LinearEquiv` and its inverse multiply to 1. -/
@[simp]
theorem LinearEquiv.det_symm_mul_det {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) :
LinearMap.det (f.symm : M →ₗ[A] M) * LinearMap.det (f : M →ₗ[A] M) = 1 := by
simp [← LinearMap.det_comp]
-- Cannot be stated using `LinearMap.det` because `f` is not an endomorphism.
theorem LinearEquiv.isUnit_det (f : M ≃ₗ[R] M') (v : Basis ι R M) (v' : Basis ι R M') :
IsUnit (LinearMap.toMatrix v v' f).det := by
apply isUnit_det_of_left_inverse
simpa using (LinearMap.toMatrix_comp v v' v f.symm f).symm
/-- Specialization of `LinearEquiv.isUnit_det` -/
theorem LinearEquiv.isUnit_det' {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) :
IsUnit (LinearMap.det (f : M →ₗ[A] M)) :=
isUnit_of_mul_eq_one _ _ f.det_mul_det_symm
/-- The determinant of `f.symm` is the inverse of that of `f` when `f` is a linear equiv. -/
theorem LinearEquiv.det_coe_symm {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] (f : M ≃ₗ[𝕜] M) :
LinearMap.det (f.symm : M →ₗ[𝕜] M) = (LinearMap.det (f : M →ₗ[𝕜] M))⁻¹ := by
field_simp [IsUnit.ne_zero f.isUnit_det']
/-- Builds a linear equivalence from a linear map whose determinant in some bases is a unit. -/
@[simps]
def LinearEquiv.ofIsUnitDet {f : M →ₗ[R] M'} {v : Basis ι R M} {v' : Basis ι R M'}
(h : IsUnit (LinearMap.toMatrix v v' f).det) : M ≃ₗ[R] M' where
toFun := f
map_add' := f.map_add
map_smul' := f.map_smul
invFun := toLin v' v (toMatrix v v' f)⁻¹
left_inv x :=
calc toLin v' v (toMatrix v v' f)⁻¹ (f x)
_ = toLin v v ((toMatrix v v' f)⁻¹ * toMatrix v v' f) x := by
rw [toLin_mul v v' v, toLin_toMatrix, LinearMap.comp_apply]
_ = x := by simp [h]
right_inv x :=
calc f (toLin v' v (toMatrix v v' f)⁻¹ x)
_ = toLin v' v' (toMatrix v v' f * (toMatrix v v' f)⁻¹) x := by
rw [toLin_mul v' v v', LinearMap.comp_apply, toLin_toMatrix v v']
_ = x := by simp [h]
@[simp]
theorem LinearEquiv.coe_ofIsUnitDet {f : M →ₗ[R] M'} {v : Basis ι R M} {v' : Basis ι R M'}
(h : IsUnit (LinearMap.toMatrix v v' f).det) :
(LinearEquiv.ofIsUnitDet h : M →ₗ[R] M') = f := by
ext x
rfl
/-- Builds a linear equivalence from a linear map on a finite-dimensional vector space whose
determinant is nonzero. -/
abbrev LinearMap.equivOfDetNeZero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M] [Module 𝕜 M]
[FiniteDimensional 𝕜 M] (f : M →ₗ[𝕜] M) (hf : LinearMap.det f ≠ 0) : M ≃ₗ[𝕜] M :=
have : IsUnit (LinearMap.toMatrix (Module.finBasis 𝕜 M)
(Module.finBasis 𝕜 M) f).det := by
rw [LinearMap.det_toMatrix]
exact isUnit_iff_ne_zero.2 hf
LinearEquiv.ofIsUnitDet this
theorem LinearMap.associated_det_of_eq_comp (e : M ≃ₗ[R] M) (f f' : M →ₗ[R] M)
(h : ∀ x, f x = f' (e x)) : Associated (LinearMap.det f) (LinearMap.det f') := by
suffices Associated (LinearMap.det (f' ∘ₗ ↑e)) (LinearMap.det f') by
convert this using 2
ext x
exact h x
rw [← mul_one (LinearMap.det f'), LinearMap.det_comp]
exact Associated.mul_left _ (associated_one_iff_isUnit.mpr e.isUnit_det')
theorem LinearMap.associated_det_comp_equiv {N : Type*} [AddCommGroup N] [Module R N]
(f : N →ₗ[R] M) (e e' : M ≃ₗ[R] N) :
Associated (LinearMap.det (f ∘ₗ ↑e)) (LinearMap.det (f ∘ₗ ↑e')) := by
refine LinearMap.associated_det_of_eq_comp (e.trans e'.symm) _ _ ?_
intro x
simp only [LinearMap.comp_apply, LinearEquiv.coe_coe, LinearEquiv.trans_apply,
LinearEquiv.apply_symm_apply]
/-- The determinant of a family of vectors with respect to some basis, as an alternating
multilinear map. -/
nonrec def Basis.det : M [⋀^ι]→ₗ[R] R where
toMultilinearMap :=
MultilinearMap.mk' (fun v ↦ det (e.toMatrix v))
(fun v i x y ↦ by
simp only [e.toMatrix_update, map_add, Finsupp.coe_add, det_updateCol_add])
(fun u i c x ↦ by
simp only [e.toMatrix_update, Algebra.id.smul_eq_mul, LinearEquiv.map_smul]
apply det_updateCol_smul)
map_eq_zero_of_eq' := by
intro v i j h hij
dsimp
rw [← Function.update_eq_self i v, h, ← det_transpose, e.toMatrix_update, ← updateRow_transpose,
← e.toMatrix_transpose_apply]
apply det_zero_of_row_eq hij
rw [updateRow_ne hij.symm, updateRow_self]
theorem Basis.det_apply (v : ι → M) : e.det v = Matrix.det (e.toMatrix v) :=
rfl
theorem Basis.det_self : e.det e = 1 := by simp [e.det_apply]
@[simp]
theorem Basis.det_isEmpty [IsEmpty ι] : e.det = AlternatingMap.constOfIsEmpty R M ι 1 := by
ext v
exact Matrix.det_isEmpty
/-- `Basis.det` is not the zero map. -/
theorem Basis.det_ne_zero [Nontrivial R] : e.det ≠ 0 := fun h => by simpa [h] using e.det_self
theorem Basis.smul_det {G} [Group G] [DistribMulAction G M] [SMulCommClass G R M]
(g : G) (v : ι → M) :
(g • e).det v = e.det (g⁻¹ • v) := by
simp_rw [det_apply, toMatrix_smul_left]
theorem is_basis_iff_det {v : ι → M} :
LinearIndependent R v ∧ span R (Set.range v) = ⊤ ↔ IsUnit (e.det v) := by
constructor
· rintro ⟨hli, hspan⟩
set v' := Basis.mk hli hspan.ge
rw [e.det_apply]
convert LinearEquiv.isUnit_det (LinearEquiv.refl R M) v' e using 2
ext i j
simp [v']
· intro h
rw [Basis.det_apply, Basis.toMatrix_eq_toMatrix_constr] at h
set v' := Basis.map e (LinearEquiv.ofIsUnitDet h) with v'_def
have : ⇑v' = v := by
ext i
rw [v'_def, Basis.map_apply, LinearEquiv.ofIsUnitDet_apply, e.constr_basis]
rw [← this]
exact ⟨v'.linearIndependent, v'.span_eq⟩
theorem Basis.isUnit_det (e' : Basis ι R M) : IsUnit (e.det e') :=
(is_basis_iff_det e).mp ⟨e'.linearIndependent, e'.span_eq⟩
/-- Any alternating map to `R` where `ι` has the cardinality of a basis equals the determinant
map with respect to that basis, multiplied by the value of that alternating map on that basis. -/
theorem AlternatingMap.eq_smul_basis_det (f : M [⋀^ι]→ₗ[R] R) : f = f e • e.det := by
refine Basis.ext_alternating e fun i h => ?_
let σ : Equiv.Perm ι := Equiv.ofBijective i (Finite.injective_iff_bijective.1 h)
change f (e ∘ σ) = (f e • e.det) (e ∘ σ)
simp [AlternatingMap.map_perm, Basis.det_self]
@[simp]
theorem AlternatingMap.map_basis_eq_zero_iff {ι : Type*} [Finite ι] (e : Basis ι R M)
(f : M [⋀^ι]→ₗ[R] R) : f e = 0 ↔ f = 0 :=
⟨fun h => by
cases nonempty_fintype ι
letI := Classical.decEq ι
simpa [h] using f.eq_smul_basis_det e,
fun h => h.symm ▸ AlternatingMap.zero_apply _⟩
theorem AlternatingMap.map_basis_ne_zero_iff {ι : Type*} [Finite ι] (e : Basis ι R M)
(f : M [⋀^ι]→ₗ[R] R) : f e ≠ 0 ↔ f ≠ 0 :=
not_congr <| f.map_basis_eq_zero_iff e
variable {A : Type*} [CommRing A] [Module A M]
@[simp]
theorem Basis.det_comp (e : Basis ι A M) (f : M →ₗ[A] M) (v : ι → M) :
e.det (f ∘ v) = (LinearMap.det f) * e.det v := by
rw [Basis.det_apply, Basis.det_apply, ← f.det_toMatrix e, ← Matrix.det_mul,
e.toMatrix_eq_toMatrix_constr (f ∘ v), e.toMatrix_eq_toMatrix_constr v, ← toMatrix_comp,
e.constr_comp]
@[simp]
theorem Basis.det_comp_basis [Module A M'] (b : Basis ι A M) (b' : Basis ι A M') (f : M →ₗ[A] M') :
b'.det (f ∘ b) = LinearMap.det (f ∘ₗ (b'.equiv b (Equiv.refl ι) : M' →ₗ[A] M)) := by
rw [Basis.det_apply, ← LinearMap.det_toMatrix b', LinearMap.toMatrix_comp _ b, Matrix.det_mul,
LinearMap.toMatrix_basis_equiv, Matrix.det_one, mul_one]
congr 1; ext i j
rw [Basis.toMatrix_apply, LinearMap.toMatrix_apply, Function.comp_apply]
@[simp]
theorem Basis.det_basis (b : Basis ι A M) (b' : Basis ι A M) :
LinearMap.det (b'.equiv b (Equiv.refl ι)).toLinearMap = b'.det b :=
(b.det_comp_basis b' (LinearMap.id)).symm
theorem Basis.det_inv (b : Basis ι A M) (b' : Basis ι A M) :
(b.isUnit_det b').unit⁻¹ = b'.det b := by
rw [← Units.mul_eq_one_iff_inv_eq, IsUnit.unit_spec, ← Basis.det_basis, ← Basis.det_basis]
exact LinearEquiv.det_mul_det_symm _
theorem Basis.det_reindex {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (b : Basis ι R M) (v : ι' → M)
(e : ι ≃ ι') : (b.reindex e).det v = b.det (v ∘ e) := by
rw [Basis.det_apply, Basis.toMatrix_reindex', det_reindexAlgEquiv, Basis.det_apply]
theorem Basis.det_reindex' {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (b : Basis ι R M)
(e : ι ≃ ι') : (b.reindex e).det = b.det.domDomCongr e :=
| AlternatingMap.ext fun _ => Basis.det_reindex _ _ _
theorem Basis.det_reindex_symm {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (b : Basis ι R M)
(v : ι → M) (e : ι' ≃ ι) : (b.reindex e.symm).det (v ∘ e) = b.det v := by
rw [Basis.det_reindex, Function.comp_assoc, e.self_comp_symm, Function.comp_id]
| Mathlib/LinearAlgebra/Determinant.lean | 601 | 606 |
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Order.Atoms
import Mathlib.Order.OrderIsoNat
import Mathlib.Order.RelIso.Set
import Mathlib.Order.SupClosed
import Mathlib.Order.SupIndep
import Mathlib.Order.Zorn
import Mathlib.Data.Finset.Order
import Mathlib.Order.Interval.Set.OrderIso
import Mathlib.Data.Finite.Set
import Mathlib.Tactic.TFAE
/-!
# Compactness properties for complete lattices
For complete lattices, there are numerous equivalent ways to express the fact that the relation `>`
is well-founded. In this file we define three especially-useful characterisations and provide
proofs that they are indeed equivalent to well-foundedness.
## Main definitions
* `CompleteLattice.IsSupClosedCompact`
* `CompleteLattice.IsSupFiniteCompact`
* `CompleteLattice.IsCompactElement`
* `IsCompactlyGenerated`
## Main results
The main result is that the following four conditions are equivalent for a complete lattice:
* `well_founded (>)`
* `CompleteLattice.IsSupClosedCompact`
* `CompleteLattice.IsSupFiniteCompact`
* `∀ k, CompleteLattice.IsCompactElement k`
This is demonstrated by means of the following four lemmas:
* `CompleteLattice.WellFounded.isSupFiniteCompact`
* `CompleteLattice.IsSupFiniteCompact.isSupClosedCompact`
* `CompleteLattice.IsSupClosedCompact.wellFounded`
* `CompleteLattice.isSupFiniteCompact_iff_all_elements_compact`
We also show well-founded lattices are compactly generated
(`CompleteLattice.isCompactlyGenerated_of_wellFounded`).
## References
- [G. Călugăreanu, *Lattice Concepts of Module Theory*][calugareanu]
## Tags
complete lattice, well-founded, compact
-/
open Set
variable {ι : Sort*} {α : Type*} [CompleteLattice α] {f : ι → α}
namespace CompleteLattice
variable (α)
/-- A compactness property for a complete lattice is that any `sup`-closed non-empty subset
contains its `sSup`. -/
def IsSupClosedCompact : Prop :=
∀ (s : Set α) (_ : s.Nonempty), SupClosed s → sSup s ∈ s
/-- A compactness property for a complete lattice is that any subset has a finite subset with the
same `sSup`. -/
def IsSupFiniteCompact : Prop :=
∀ s : Set α, ∃ t : Finset α, ↑t ⊆ s ∧ sSup s = t.sup id
/-- An element `k` of a complete lattice is said to be compact if any set with `sSup`
above `k` has a finite subset with `sSup` above `k`. Such an element is also called
"finite" or "S-compact". -/
def IsCompactElement {α : Type*} [CompleteLattice α] (k : α) :=
∀ s : Set α, k ≤ sSup s → ∃ t : Finset α, ↑t ⊆ s ∧ k ≤ t.sup id
theorem isCompactElement_iff.{u} {α : Type u} [CompleteLattice α] (k : α) :
CompleteLattice.IsCompactElement k ↔
∀ (ι : Type u) (s : ι → α), k ≤ iSup s → ∃ t : Finset ι, k ≤ t.sup s := by
classical
constructor
· intro H ι s hs
obtain ⟨t, ht, ht'⟩ := H (Set.range s) hs
have : ∀ x : t, ∃ i, s i = x := fun x => ht x.prop
choose f hf using this
refine ⟨Finset.univ.image f, ht'.trans ?_⟩
rw [Finset.sup_le_iff]
intro b hb
rw [← show s (f ⟨b, hb⟩) = id b from hf _]
exact Finset.le_sup (Finset.mem_image_of_mem f <| Finset.mem_univ (Subtype.mk b hb))
· intro H s hs
obtain ⟨t, ht⟩ :=
H s Subtype.val
(by
delta iSup
rwa [Subtype.range_coe])
refine ⟨t.image Subtype.val, by simp, ht.trans ?_⟩
rw [Finset.sup_le_iff]
exact fun x hx => @Finset.le_sup _ _ _ _ _ id _ (Finset.mem_image_of_mem Subtype.val hx)
/-- An element `k` is compact if and only if any directed set with `sSup` above
`k` already got above `k` at some point in the set. -/
theorem isCompactElement_iff_le_of_directed_sSup_le (k : α) :
IsCompactElement k ↔
∀ s : Set α, s.Nonempty → DirectedOn (· ≤ ·) s → k ≤ sSup s → ∃ x : α, x ∈ s ∧ k ≤ x := by
classical
constructor
· intro hk s hne hdir hsup
obtain ⟨t, ht⟩ := hk s hsup
-- certainly every element of t is below something in s, since ↑t ⊆ s.
have t_below_s : ∀ x ∈ t, ∃ y ∈ s, x ≤ y := fun x hxt => ⟨x, ht.left hxt, le_rfl⟩
obtain ⟨x, ⟨hxs, hsupx⟩⟩ := Finset.sup_le_of_le_directed s hne hdir t t_below_s
exact ⟨x, ⟨hxs, le_trans ht.right hsupx⟩⟩
· intro hk s hsup
-- Consider the set of finite joins of elements of the (plain) set s.
let S : Set α := { x | ∃ t : Finset α, ↑t ⊆ s ∧ x = t.sup id }
-- S is directed, nonempty, and still has sup above k.
have dir_US : DirectedOn (· ≤ ·) S := by
rintro x ⟨c, hc⟩ y ⟨d, hd⟩
use x ⊔ y
constructor
· use c ∪ d
constructor
· simp only [hc.left, hd.left, Set.union_subset_iff, Finset.coe_union, and_self_iff]
· simp only [hc.right, hd.right, Finset.sup_union]
simp only [and_self_iff, le_sup_left, le_sup_right]
have sup_S : sSup s ≤ sSup S := by
apply sSup_le_sSup
intro x hx
use {x}
simpa only [and_true, id, Finset.coe_singleton, eq_self_iff_true,
Finset.sup_singleton, Set.singleton_subset_iff]
have Sne : S.Nonempty := by
suffices ⊥ ∈ S from Set.nonempty_of_mem this
use ∅
simp only [Set.empty_subset, Finset.coe_empty, Finset.sup_empty, eq_self_iff_true,
and_self_iff]
-- Now apply the defn of compact and finish.
obtain ⟨j, ⟨hjS, hjk⟩⟩ := hk S Sne dir_US (le_trans hsup sup_S)
obtain ⟨t, ⟨htS, htsup⟩⟩ := hjS
use t
exact ⟨htS, by rwa [← htsup]⟩
theorem IsCompactElement.exists_finset_of_le_iSup {k : α} (hk : IsCompactElement k) {ι : Type*}
(f : ι → α) (h : k ≤ ⨆ i, f i) : ∃ s : Finset ι, k ≤ ⨆ i ∈ s, f i := by
classical
let g : Finset ι → α := fun s => ⨆ i ∈ s, f i
have h1 : DirectedOn (· ≤ ·) (Set.range g) := by
rintro - ⟨s, rfl⟩ - ⟨t, rfl⟩
exact
⟨g (s ∪ t), ⟨s ∪ t, rfl⟩, iSup_le_iSup_of_subset Finset.subset_union_left,
iSup_le_iSup_of_subset Finset.subset_union_right⟩
have h2 : k ≤ sSup (Set.range g) :=
h.trans
(iSup_le fun i =>
le_sSup_of_le ⟨{i}, rfl⟩
(le_iSup_of_le i (le_iSup_of_le (Finset.mem_singleton_self i) le_rfl)))
obtain ⟨-, ⟨s, rfl⟩, hs⟩ :=
(isCompactElement_iff_le_of_directed_sSup_le α k).mp hk (Set.range g) (Set.range_nonempty g)
h1 h2
exact ⟨s, hs⟩
/-- A compact element `k` has the property that any directed set lying strictly below `k` has
its `sSup` strictly below `k`. -/
theorem IsCompactElement.directed_sSup_lt_of_lt {α : Type*} [CompleteLattice α] {k : α}
(hk : IsCompactElement k) {s : Set α} (hemp : s.Nonempty) (hdir : DirectedOn (· ≤ ·) s)
(hbelow : ∀ x ∈ s, x < k) : sSup s < k := by
rw [isCompactElement_iff_le_of_directed_sSup_le] at hk
by_contra h
have sSup' : sSup s ≤ k := sSup_le s k fun s hs => (hbelow s hs).le
replace sSup : sSup s = k := eq_iff_le_not_lt.mpr ⟨sSup', h⟩
obtain ⟨x, hxs, hkx⟩ := hk s hemp hdir sSup.symm.le
obtain hxk := hbelow x hxs
exact hxk.ne (hxk.le.antisymm hkx)
theorem isCompactElement_finsetSup {α β : Type*} [CompleteLattice α] {f : β → α} (s : Finset β)
(h : ∀ x ∈ s, IsCompactElement (f x)) : IsCompactElement (s.sup f) := by
classical
rw [isCompactElement_iff_le_of_directed_sSup_le]
intro d hemp hdir hsup
rw [← Function.id_comp f]
rw [← Finset.sup_image]
apply Finset.sup_le_of_le_directed d hemp hdir
rintro x hx
obtain ⟨p, ⟨hps, rfl⟩⟩ := Finset.mem_image.mp hx
specialize h p hps
rw [isCompactElement_iff_le_of_directed_sSup_le] at h
specialize h d hemp hdir (le_trans (Finset.le_sup hps) hsup)
simpa only [exists_prop]
theorem WellFoundedGT.isSupFiniteCompact [WellFoundedGT α] :
IsSupFiniteCompact α := fun s => by
let S := { x | ∃ t : Finset α, ↑t ⊆ s ∧ t.sup id = x }
obtain ⟨m, ⟨t, ⟨ht₁, rfl⟩⟩, hm⟩ := wellFounded_gt.has_min S ⟨⊥, ∅, by simp⟩
refine ⟨t, ht₁, (sSup_le _ _ fun y hy => ?_).antisymm ?_⟩
· classical
rw [eq_of_le_of_not_lt (Finset.sup_mono (t.subset_insert y))
(hm _ ⟨insert y t, by simp [Set.insert_subset_iff, hy, ht₁]⟩)]
simp
· rw [Finset.sup_id_eq_sSup]
exact sSup_le_sSup ht₁
theorem IsSupFiniteCompact.isSupClosedCompact (h : IsSupFiniteCompact α) :
IsSupClosedCompact α := by
intro s hne hsc; obtain ⟨t, ht₁, ht₂⟩ := h s; clear h
rcases t.eq_empty_or_nonempty with h | h
· subst h
rw [Finset.sup_empty] at ht₂
rw [ht₂]
simp [eq_singleton_bot_of_sSup_eq_bot_of_nonempty ht₂ hne]
· rw [ht₂]
exact hsc.finsetSup_mem h ht₁
theorem IsSupClosedCompact.wellFoundedGT (h : IsSupClosedCompact α) :
WellFoundedGT α where
wf := by
refine RelEmbedding.wellFounded_iff_no_descending_seq.mpr ⟨fun a => ?_⟩
suffices sSup (Set.range a) ∈ Set.range a by
obtain ⟨n, hn⟩ := Set.mem_range.mp this
have h' : sSup (Set.range a) < a (n + 1) := by
change _ > _
simp [← hn, a.map_rel_iff]
apply lt_irrefl (a (n + 1))
apply lt_of_le_of_lt _ h'
apply le_sSup
apply Set.mem_range_self
apply h (Set.range a)
· use a 37
apply Set.mem_range_self
· rintro x ⟨m, hm⟩ y ⟨n, hn⟩
use m ⊔ n
rw [← hm, ← hn]
apply RelHomClass.map_sup a
theorem isSupFiniteCompact_iff_all_elements_compact :
IsSupFiniteCompact α ↔ ∀ k : α, IsCompactElement k := by
refine ⟨fun h k s hs => ?_, fun h s => ?_⟩
· obtain ⟨t, ⟨hts, htsup⟩⟩ := h s
use t, hts
rwa [← htsup]
· obtain ⟨t, ⟨hts, htsup⟩⟩ := h (sSup s) s (by rfl)
have : sSup s = t.sup id := by
suffices t.sup id ≤ sSup s by apply le_antisymm <;> assumption
simp only [id, Finset.sup_le_iff]
intro x hx
exact le_sSup _ _ (hts hx)
exact ⟨t, hts, this⟩
open List in
theorem wellFoundedGT_characterisations : List.TFAE
[WellFoundedGT α, IsSupFiniteCompact α, IsSupClosedCompact α, ∀ k : α, IsCompactElement k] := by
tfae_have 1 → 2 := @WellFoundedGT.isSupFiniteCompact α _
tfae_have 2 → 3 := IsSupFiniteCompact.isSupClosedCompact α
tfae_have 3 → 1 := IsSupClosedCompact.wellFoundedGT α
tfae_have 2 ↔ 4 := isSupFiniteCompact_iff_all_elements_compact α
tfae_finish
theorem wellFoundedGT_iff_isSupFiniteCompact :
WellFoundedGT α ↔ IsSupFiniteCompact α :=
(wellFoundedGT_characterisations α).out 0 1
theorem isSupFiniteCompact_iff_isSupClosedCompact : IsSupFiniteCompact α ↔ IsSupClosedCompact α :=
(wellFoundedGT_characterisations α).out 1 2
theorem isSupClosedCompact_iff_wellFoundedGT :
IsSupClosedCompact α ↔ WellFoundedGT α :=
(wellFoundedGT_characterisations α).out 2 0
alias ⟨_, IsSupFiniteCompact.wellFoundedGT⟩ := wellFoundedGT_iff_isSupFiniteCompact
alias ⟨_, IsSupClosedCompact.isSupFiniteCompact⟩ := isSupFiniteCompact_iff_isSupClosedCompact
alias ⟨_, WellFoundedGT.isSupClosedCompact⟩ := isSupClosedCompact_iff_wellFoundedGT
end CompleteLattice
theorem WellFoundedGT.finite_of_sSupIndep [WellFoundedGT α] {s : Set α}
(hs : sSupIndep s) : s.Finite := by
classical
refine Set.not_infinite.mp fun contra => ?_
obtain ⟨t, ht₁, ht₂⟩ := CompleteLattice.WellFoundedGT.isSupFiniteCompact α s
replace contra : ∃ x : α, x ∈ s ∧ x ≠ ⊥ ∧ x ∉ t := by
have : (s \ (insert ⊥ t : Finset α)).Infinite := contra.diff (Finset.finite_toSet _)
obtain ⟨x, hx₁, hx₂⟩ := this.nonempty
exact ⟨x, hx₁, by simpa [not_or] using hx₂⟩
obtain ⟨x, hx₀, hx₁, hx₂⟩ := contra
replace hs : x ⊓ sSup s = ⊥ := by
have := hs.mono (by simp [ht₁, hx₀, -Set.union_singleton] : ↑t ∪ {x} ≤ s) (by simp : x ∈ _)
simpa [Disjoint, hx₂, ← t.sup_id_eq_sSup, ← ht₂] using this.eq_bot
apply hx₁
rw [← hs, eq_comm, inf_eq_left]
exact le_sSup hx₀
@[deprecated (since := "2024-11-24")]
alias CompleteLattice.WellFoundedGT.finite_of_setIndependent := WellFoundedGT.finite_of_sSupIndep
theorem WellFoundedGT.finite_ne_bot_of_iSupIndep [WellFoundedGT α]
{ι : Type*} {t : ι → α} (ht : iSupIndep t) : Set.Finite {i | t i ≠ ⊥} := by
refine Finite.of_finite_image (Finite.subset ?_ (image_subset_range t _)) ht.injOn
exact WellFoundedGT.finite_of_sSupIndep ht.sSupIndep_range
@[deprecated (since := "2024-11-24")]
alias CompleteLattice.WellFoundedGT.finite_ne_bot_of_independent :=
WellFoundedGT.finite_ne_bot_of_iSupIndep
theorem WellFoundedGT.finite_of_iSupIndep [WellFoundedGT α] {ι : Type*}
{t : ι → α} (ht : iSupIndep t) (h_ne_bot : ∀ i, t i ≠ ⊥) : Finite ι :=
haveI := (WellFoundedGT.finite_of_sSupIndep ht.sSupIndep_range).to_subtype
Finite.of_injective_finite_range (ht.injective h_ne_bot)
@[deprecated (since := "2024-11-24")]
alias CompleteLattice.WellFoundedGT.finite_of_independent := WellFoundedGT.finite_of_iSupIndep
theorem WellFoundedLT.finite_of_sSupIndep [WellFoundedLT α] {s : Set α}
(hs : sSupIndep s) : s.Finite := by
by_contra inf
let e := (Infinite.diff inf <| finite_singleton ⊥).to_subtype.natEmbedding
let a n := ⨆ i ≥ n, (e i).1
have sup_le n : (e n).1 ⊔ a (n + 1) ≤ a n := sup_le_iff.mpr ⟨le_iSup₂_of_le n le_rfl le_rfl,
iSup₂_le fun i hi ↦ le_iSup₂_of_le i (n.le_succ.trans hi) le_rfl⟩
have lt n : a (n + 1) < a n := (Disjoint.right_lt_sup_of_left_ne_bot
((hs (e n).2.1).mono_right <| iSup₂_le fun i hi ↦ le_sSup ?_) (e n).2.2).trans_le (sup_le n)
· exact (RelEmbedding.natGT a lt).not_wellFounded_of_decreasing_seq wellFounded_lt
exact ⟨(e i).2.1, fun h ↦ n.lt_succ_self.not_le <| hi.trans_eq <| e.2 <| Subtype.val_injective h⟩
@[deprecated (since := "2024-11-24")]
alias CompleteLattice.WellFoundedLT.finite_of_setIndependent := WellFoundedLT.finite_of_sSupIndep
theorem WellFoundedLT.finite_ne_bot_of_iSupIndep [WellFoundedLT α]
{ι : Type*} {t : ι → α} (ht : iSupIndep t) : Set.Finite {i | t i ≠ ⊥} := by
refine Finite.of_finite_image (Finite.subset ?_ (image_subset_range t _)) ht.injOn
exact WellFoundedLT.finite_of_sSupIndep ht.sSupIndep_range
@[deprecated (since := "2024-11-24")]
alias CompleteLattice.WellFoundedLT.finite_ne_bot_of_independent :=
WellFoundedLT.finite_ne_bot_of_iSupIndep
theorem WellFoundedLT.finite_of_iSupIndep [WellFoundedLT α] {ι : Type*}
{t : ι → α} (ht : iSupIndep t) (h_ne_bot : ∀ i, t i ≠ ⊥) : Finite ι :=
haveI := (WellFoundedLT.finite_of_sSupIndep ht.sSupIndep_range).to_subtype
Finite.of_injective_finite_range (ht.injective h_ne_bot)
@[deprecated (since := "2024-11-24")]
alias CompleteLattice.WellFoundedLT.finite_of_independent := WellFoundedLT.finite_of_iSupIndep
/-- A complete lattice is said to be compactly generated if any
element is the `sSup` of compact elements. -/
class IsCompactlyGenerated (α : Type*) [CompleteLattice α] : Prop where
/-- In a compactly generated complete lattice,
every element is the `sSup` of some set of compact elements. -/
exists_sSup_eq : ∀ x : α, ∃ s : Set α, (∀ x ∈ s, CompleteLattice.IsCompactElement x) ∧ sSup s = x
section
variable [IsCompactlyGenerated α] {a : α} {s : Set α}
@[simp]
theorem sSup_compact_le_eq (b) :
sSup { c : α | CompleteLattice.IsCompactElement c ∧ c ≤ b } = b := by
rcases IsCompactlyGenerated.exists_sSup_eq b with ⟨s, hs, rfl⟩
exact le_antisymm (sSup_le fun c hc => hc.2) (sSup_le_sSup fun c cs => ⟨hs c cs, le_sSup cs⟩)
@[simp]
theorem sSup_compact_eq_top : sSup { a : α | CompleteLattice.IsCompactElement a } = ⊤ := by
| refine Eq.trans (congr rfl (Set.ext fun x => ?_)) (sSup_compact_le_eq ⊤)
exact (and_iff_left le_top).symm
theorem le_iff_compact_le_imp {a b : α} :
a ≤ b ↔ ∀ c : α, CompleteLattice.IsCompactElement c → c ≤ a → c ≤ b :=
⟨fun ab _ _ ca => le_trans ca ab, fun h => by
rw [← sSup_compact_le_eq a, ← sSup_compact_le_eq b]
exact sSup_le_sSup fun c hc => ⟨hc.1, h c hc.1 hc.2⟩⟩
/-- This property is sometimes referred to as `α` being upper continuous. -/
theorem DirectedOn.inf_sSup_eq (h : DirectedOn (· ≤ ·) s) : a ⊓ sSup s = ⨆ b ∈ s, a ⊓ b :=
le_antisymm
(by
rw [le_iff_compact_le_imp]
| Mathlib/Order/CompactlyGenerated/Basic.lean | 367 | 380 |
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Eric Wieser
-/
import Mathlib.GroupTheory.OrderOfElement
import Mathlib.RingTheory.Ideal.Maps
import Mathlib.RingTheory.Ideal.Nonunits
import Mathlib.RingTheory.Ideal.Quotient.Defs
/-!
# Characteristic of quotients rings
-/
universe u v
namespace CharP
theorem ker_intAlgebraMap_eq_span
{R : Type*} [Ring R] (p : ℕ) [CharP R p] :
RingHom.ker (algebraMap ℤ R) = Ideal.span {(p : ℤ)} := by
ext a
simp [CharP.intCast_eq_zero_iff R p, Ideal.mem_span_singleton]
theorem quotient (R : Type u) [CommRing R] (p : ℕ) [hp1 : Fact p.Prime] (hp2 : ↑p ∈ nonunits R) :
CharP (R ⧸ (Ideal.span ({(p : R)} : Set R) : Ideal R)) p :=
have hp0 : (p : R ⧸ (Ideal.span {(p : R)} : Ideal R)) = 0 :=
map_natCast (Ideal.Quotient.mk (Ideal.span {(p : R)} : Ideal R)) p ▸
Ideal.Quotient.eq_zero_iff_mem.2 (Ideal.subset_span <| Set.mem_singleton _)
ringChar.of_eq <|
Or.resolve_left ((Nat.dvd_prime hp1.1).1 <| ringChar.dvd hp0) fun h1 =>
hp2 <|
isUnit_iff_dvd_one.2 <|
Ideal.mem_span_singleton.1 <|
Ideal.Quotient.eq_zero_iff_mem.1 <|
| @Subsingleton.elim _ (@CharOne.subsingleton _ _ (ringChar.of_eq h1)) _ _
/-- If an ideal does not contain any coercions of natural numbers other than zero, then its quotient
inherits the characteristic of the underlying ring. -/
theorem quotient' {R : Type*} [CommRing R] (p : ℕ) [CharP R p] (I : Ideal R)
(h : ∀ x : ℕ, (x : R) ∈ I → (x : R) = 0) : CharP (R ⧸ I) p :=
⟨fun x => by
| Mathlib/Algebra/CharP/Quotient.lean | 37 | 43 |
/-
Copyright (c) 2022 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Algebra.Group.Subsemigroup.Operations
import Mathlib.Algebra.MonoidAlgebra.Support
import Mathlib.Order.Filter.Extr
/-!
# Lemmas about the `sup` and `inf` of the support of `AddMonoidAlgebra`
## TODO
The current plan is to state and prove lemmas about `Finset.sup (Finsupp.support f) D` with a
"generic" degree/weight function `D` from the grading Type `A` to a somewhat ordered Type `B`.
Next, the general lemmas get specialized for some yet-to-be-defined `degree`s.
-/
variable {R R' A T B ι : Type*}
namespace AddMonoidAlgebra
/-!
# sup-degree and inf-degree of an `AddMonoidAlgebra`
Let `R` be a semiring and let `A` be a `SemilatticeSup`.
For an element `f : R[A]`, this file defines
* `AddMonoidAlgebra.supDegree`: the sup-degree taking values in `WithBot A`,
* `AddMonoidAlgebra.infDegree`: the inf-degree taking values in `WithTop A`.
If the grading type `A` is a linearly ordered additive monoid, then these two notions of degree
coincide with the standard one:
* the sup-degree is the maximum of the exponents of the monomials that appear with non-zero
coefficient in `f`, or `⊥`, if `f = 0`;
* the inf-degree is the minimum of the exponents of the monomials that appear with non-zero
coefficient in `f`, or `⊤`, if `f = 0`.
The main results are
* `AddMonoidAlgebra.supDegree_mul_le`:
the sup-degree of a product is at most the sum of the sup-degrees,
* `AddMonoidAlgebra.le_infDegree_mul`:
the inf-degree of a product is at least the sum of the inf-degrees,
* `AddMonoidAlgebra.supDegree_add_le`:
the sup-degree of a sum is at most the sup of the sup-degrees,
* `AddMonoidAlgebra.le_infDegree_add`:
the inf-degree of a sum is at least the inf of the inf-degrees.
## Implementation notes
The current plan is to state and prove lemmas about `Finset.sup (Finsupp.support f) D` with a
"generic" degree/weight function `D` from the grading Type `A` to a somewhat ordered Type `B`.
Next, the general lemmas get specialized twice:
* once for `supDegree` (essentially a simple application) and
* once for `infDegree` (a simple application, via `OrderDual`).
These final lemmas are the ones that likely get used the most. The generic lemmas about
`Finset.support.sup` may not be used directly much outside of this file.
To see this in action, you can look at the triple
`(sup_support_mul_le, maxDegree_mul_le, le_minDegree_mul)`.
-/
section GeneralResultsAssumingSemilatticeSup
variable [SemilatticeSup B] [OrderBot B] [SemilatticeInf T] [OrderTop T]
section Semiring
variable [Semiring R]
section ExplicitDegrees
/-!
In this section, we use `degb` and `degt` to denote "degree functions" on `A` with values in
a type with *b*ot or *t*op respectively.
-/
variable (degb : A → B) (degt : A → T) (f g : R[A])
theorem sup_support_add_le :
(f + g).support.sup degb ≤ f.support.sup degb ⊔ g.support.sup degb := by
classical
exact (Finset.sup_mono Finsupp.support_add).trans_eq Finset.sup_union
theorem le_inf_support_add : f.support.inf degt ⊓ g.support.inf degt ≤ (f + g).support.inf degt :=
sup_support_add_le (fun a : A => OrderDual.toDual (degt a)) f g
end ExplicitDegrees
section AddOnly
variable [Add A] [Add B] [Add T] [AddLeftMono B] [AddRightMono B]
[AddLeftMono T] [AddRightMono T]
theorem sup_support_mul_le {degb : A → B} (degbm : ∀ {a b}, degb (a + b) ≤ degb a + degb b)
(f g : R[A]) :
(f * g).support.sup degb ≤ f.support.sup degb + g.support.sup degb := by
classical
exact (Finset.sup_mono <| support_mul _ _).trans <| Finset.sup_add_le.2 fun _fd fds _gd gds ↦
degbm.trans <| add_le_add (Finset.le_sup fds) (Finset.le_sup gds)
theorem le_inf_support_mul {degt : A → T} (degtm : ∀ {a b}, degt a + degt b ≤ degt (a + b))
(f g : R[A]) :
f.support.inf degt + g.support.inf degt ≤ (f * g).support.inf degt :=
sup_support_mul_le (B := Tᵒᵈ) degtm f g
end AddOnly
section AddMonoids
variable [AddMonoid A] [AddMonoid B] [AddLeftMono B] [AddRightMono B]
[AddMonoid T] [AddLeftMono T] [AddRightMono T]
{degb : A → B} {degt : A → T}
theorem sup_support_list_prod_le (degb0 : degb 0 ≤ 0)
(degbm : ∀ a b, degb (a + b) ≤ degb a + degb b) :
∀ l : List R[A],
l.prod.support.sup degb ≤ (l.map fun f : R[A] => f.support.sup degb).sum
| [] => by
rw [List.map_nil, Finset.sup_le_iff, List.prod_nil, List.sum_nil]
exact fun a ha => by rwa [Finset.mem_singleton.mp (Finsupp.support_single_subset ha)]
| f::fs => by
rw [List.prod_cons, List.map_cons, List.sum_cons]
exact (sup_support_mul_le (@fun a b => degbm a b) _ _).trans
(add_le_add_left (sup_support_list_prod_le degb0 degbm fs) _)
theorem le_inf_support_list_prod (degt0 : 0 ≤ degt 0)
(degtm : ∀ a b, degt a + degt b ≤ degt (a + b)) (l : List R[A]) :
(l.map fun f : R[A] => f.support.inf degt).sum ≤ l.prod.support.inf degt := by
refine OrderDual.ofDual_le_ofDual.mpr ?_
refine sup_support_list_prod_le ?_ ?_ l
· refine (OrderDual.ofDual_le_ofDual.mp ?_)
exact degt0
· refine (fun a b => OrderDual.ofDual_le_ofDual.mp ?_)
exact degtm a b
theorem sup_support_pow_le (degb0 : degb 0 ≤ 0) (degbm : ∀ a b, degb (a + b) ≤ degb a + degb b)
(n : ℕ) (f : R[A]) : (f ^ n).support.sup degb ≤ n • f.support.sup degb := by
rw [← List.prod_replicate, ← List.sum_replicate]
refine (sup_support_list_prod_le degb0 degbm _).trans_eq ?_
rw [List.map_replicate]
theorem le_inf_support_pow (degt0 : 0 ≤ degt 0) (degtm : ∀ a b, degt a + degt b ≤ degt (a + b))
(n : ℕ) (f : R[A]) : n • f.support.inf degt ≤ (f ^ n).support.inf degt := by
refine OrderDual.ofDual_le_ofDual.mpr <| sup_support_pow_le (OrderDual.ofDual_le_ofDual.mp ?_)
(fun a b => OrderDual.ofDual_le_ofDual.mp ?_) n f
· exact degt0
· exact degtm _ _
end AddMonoids
end Semiring
section CommutativeLemmas
variable [CommSemiring R] [AddCommMonoid A] [AddCommMonoid B] [AddLeftMono B] [AddRightMono B]
[AddCommMonoid T] [AddLeftMono T] [AddRightMono T]
{degb : A → B} {degt : A → T}
theorem sup_support_multiset_prod_le (degb0 : degb 0 ≤ 0)
(degbm : ∀ a b, degb (a + b) ≤ degb a + degb b) (m : Multiset R[A]) :
m.prod.support.sup degb ≤ (m.map fun f : R[A] => f.support.sup degb).sum := by
induction m using Quot.inductionOn
rw [Multiset.quot_mk_to_coe'', Multiset.map_coe, Multiset.sum_coe, Multiset.prod_coe]
exact sup_support_list_prod_le degb0 degbm _
theorem le_inf_support_multiset_prod (degt0 : 0 ≤ degt 0)
(degtm : ∀ a b, degt a + degt b ≤ degt (a + b)) (m : Multiset R[A]) :
(m.map fun f : R[A] => f.support.inf degt).sum ≤ m.prod.support.inf degt := by
refine OrderDual.ofDual_le_ofDual.mpr <|
sup_support_multiset_prod_le (OrderDual.ofDual_le_ofDual.mp ?_)
(fun a b => OrderDual.ofDual_le_ofDual.mp ?_) m
· exact degt0
· exact degtm _ _
theorem sup_support_finset_prod_le (degb0 : degb 0 ≤ 0)
(degbm : ∀ a b, degb (a + b) ≤ degb a + degb b) (s : Finset ι) (f : ι → R[A]) :
(∏ i ∈ s, f i).support.sup degb ≤ ∑ i ∈ s, (f i).support.sup degb :=
(sup_support_multiset_prod_le degb0 degbm _).trans_eq <| congr_arg _ <| Multiset.map_map _ _ _
theorem le_inf_support_finset_prod (degt0 : 0 ≤ degt 0)
(degtm : ∀ a b, degt a + degt b ≤ degt (a + b)) (s : Finset ι) (f : ι → R[A]) :
(∑ i ∈ s, (f i).support.inf degt) ≤ (∏ i ∈ s, f i).support.inf degt :=
le_of_eq_of_le (by rw [Multiset.map_map]; rfl) (le_inf_support_multiset_prod degt0 degtm _)
end CommutativeLemmas
end GeneralResultsAssumingSemilatticeSup
/-! ### Shorthands for special cases
Note that these definitions are reducible, in order to make it easier to apply the more generic
lemmas above. -/
section Degrees
variable [Semiring R] [Ring R']
section SupDegree
variable [SemilatticeSup B] [OrderBot B] (D : A → B)
/-- Let `R` be a semiring, let `A` be an `AddZeroClass`, let `B` be an `OrderBot`,
and let `D : A → B` be a "degree" function.
For an element `f : R[A]`, the element `supDegree f : B` is the supremum of all the elements in the
support of `f`, or `⊥` if `f` is zero.
Often, the Type `B` is `WithBot A`,
If, further, `A` has a linear order, then this notion coincides with the usual one,
using the maximum of the exponents.
If `A := σ →₀ ℕ` then `R[A] = MvPolynomial σ R`, and if we equip `σ` with a linear order then
the induced linear order on `Lex A` equips `MvPolynomial` ring with a
[monomial order](https://en.wikipedia.org/wiki/Monomial_order) (i.e. a linear order on `A`, the
type of (monic) monomials in `R[A]`, that respects addition). We make use of this monomial order
by taking `D := toLex`, and different monomial orders could be accessed via different type
synonyms once they are added. -/
abbrev supDegree (f : R[A]) : B :=
f.support.sup D
variable {D}
theorem supDegree_add_le {f g : R[A]} :
(f + g).supDegree D ≤ (f.supDegree D) ⊔ (g.supDegree D) :=
sup_support_add_le D f g
@[simp]
theorem supDegree_neg {f : R'[A]} :
(-f).supDegree D = f.supDegree D := by
rw [supDegree, supDegree, Finsupp.support_neg]
theorem supDegree_sub_le {f g : R'[A]} :
(f - g).supDegree D ≤ f.supDegree D ⊔ g.supDegree D := by
rw [sub_eq_add_neg, ← supDegree_neg (f := g)]; apply supDegree_add_le
theorem supDegree_sum_le {ι} {s : Finset ι} {f : ι → R[A]} :
(∑ i ∈ s, f i).supDegree D ≤ s.sup (fun i => (f i).supDegree D) := by
classical
| exact (Finset.sup_mono Finsupp.support_finset_sum).trans_eq (Finset.sup_biUnion _ _)
theorem supDegree_single_ne_zero (a : A) {r : R} (hr : r ≠ 0) :
| Mathlib/Algebra/MonoidAlgebra/Degree.lean | 244 | 246 |
/-
Copyright (c) 2024 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.Lie.Semisimple.Defs
import Mathlib.LinearAlgebra.BilinearForm.Orthogonal
/-!
# Lie algebras with non-degenerate invariant bilinear forms are semisimple
In this file we prove that a finite-dimensional Lie algebra over a field is semisimple
if it does not have non-trivial abelian ideals and it admits a
non-degenerate reflexive invariant bilinear form.
Here a form is *invariant* if it invariant under the Lie bracket
in the sense that `⁅x, Φ⁆ = 0` for all `x` or equivalently, `Φ ⁅x, y⁆ z = Φ x ⁅y, z⁆`.
## Main results
* `LieAlgebra.InvariantForm.orthogonal`: given a Lie submodule `N` of a Lie module `M`,
we define its orthogonal complement with respect to a non-degenerate invariant bilinear form `Φ`
as the Lie ideal of elements `x` such that `Φ n x = 0` for all `n ∈ N`.
* `LieAlgebra.InvariantForm.isSemisimple_of_nondegenerate`: the main result of this file;
a finite-dimensional Lie algebra over a field is semisimple
if it does not have non-trivial abelian ideals and admits
a non-degenerate invariant reflexive bilinear form.
## References
We follow the short and excellent paper [dieudonne1953].
-/
namespace LieAlgebra
namespace InvariantForm
section ring
variable {R L M : Type*}
variable [CommRing R] [LieRing L]
variable [AddCommGroup M] [Module R M] [LieRingModule L M]
variable (Φ : LinearMap.BilinForm R M) (hΦ_nondeg : Φ.Nondegenerate)
variable (L) in
/--
A bilinear form on a Lie module `M` of a Lie algebra `L` is *invariant* if
for all `x : L` and `y z : M` the condition `Φ ⁅x, y⁆ z = -Φ y ⁅x, z⁆` holds.
-/
def _root_.LinearMap.BilinForm.lieInvariant : Prop :=
∀ (x : L) (y z : M), Φ ⁅x, y⁆ z = -Φ y ⁅x, z⁆
lemma _root_.LinearMap.BilinForm.lieInvariant_iff [LieAlgebra R L] [LieModule R L M] :
Φ.lieInvariant L ↔ Φ ∈ LieModule.maxTrivSubmodule R L (LinearMap.BilinForm R M) := by
refine ⟨fun h x ↦ ?_, fun h x y z ↦ ?_⟩
· ext y z
rw [LieHom.lie_apply, LinearMap.sub_apply, Module.Dual.lie_apply, LinearMap.zero_apply,
LinearMap.zero_apply, h, sub_self]
· replace h := LinearMap.congr_fun₂ (h x) y z
simp only [LieHom.lie_apply, LinearMap.sub_apply, Module.Dual.lie_apply,
LinearMap.zero_apply, sub_eq_zero] at h
simp [← h]
/--
The orthogonal complement of a Lie submodule `N` with respect to an invariant bilinear form `Φ` is
the Lie submodule of elements `y` such that `Φ x y = 0` for all `x ∈ N`.
-/
@[simps!]
def orthogonal (hΦ_inv : Φ.lieInvariant L) (N : LieSubmodule R L M) : LieSubmodule R L M where
__ := Φ.orthogonal N
lie_mem {x y} := by
suffices (∀ n ∈ N, Φ n y = 0) → ∀ n ∈ N, Φ n ⁅x, y⁆ = 0 by
simpa only [LinearMap.BilinForm.isOrtho_def, -- and some default simp lemmas
AddSubsemigroup.mem_carrier, AddSubmonoid.mem_toSubsemigroup, Submodule.mem_toAddSubmonoid,
LinearMap.BilinForm.mem_orthogonal_iff, LieSubmodule.mem_toSubmodule]
intro H a ha
rw [← neg_eq_zero, ← hΦ_inv]
exact H _ <| N.lie_mem ha
variable (hΦ_inv : Φ.lieInvariant L)
@[simp]
lemma orthogonal_toSubmodule (N : LieSubmodule R L M) :
(orthogonal Φ hΦ_inv N).toSubmodule = Φ.orthogonal N.toSubmodule := rfl
lemma mem_orthogonal (N : LieSubmodule R L M) (y : M) :
y ∈ orthogonal Φ hΦ_inv N ↔ ∀ x ∈ N, Φ x y = 0 := by
simp [orthogonal, LinearMap.BilinForm.isOrtho_def, LinearMap.BilinForm.mem_orthogonal_iff]
| variable [LieAlgebra R L]
lemma orthogonal_disjoint
(Φ : LinearMap.BilinForm R L) (hΦ_nondeg : Φ.Nondegenerate) (hΦ_inv : Φ.lieInvariant L)
-- TODO: replace the following assumption by a typeclass assumption `[HasNonAbelianAtoms]`
(hL : ∀ I : LieIdeal R L, IsAtom I → ¬IsLieAbelian I)
(I : LieIdeal R L) (hI : IsAtom I) :
Disjoint I (orthogonal Φ hΦ_inv I) := by
rw [disjoint_iff, ← hI.lt_iff, lt_iff_le_and_ne]
suffices ¬I ≤ orthogonal Φ hΦ_inv I by simpa
intro contra
apply hI.1
rw [eq_bot_iff, ← lie_eq_self_of_isAtom_of_nonabelian I hI (hL I hI),
LieSubmodule.lieIdeal_oper_eq_span, LieSubmodule.lieSpan_le]
rintro _ ⟨x, y, rfl⟩
simp only [LieSubmodule.bot_coe, Set.mem_singleton_iff]
apply hΦ_nondeg
intro z
rw [hΦ_inv, neg_eq_zero]
| Mathlib/Algebra/Lie/InvariantForm.lean | 90 | 108 |
/-
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.Adjunction.FullyFaithful
import Mathlib.CategoryTheory.Functor.EpiMono
import Mathlib.CategoryTheory.HomCongr
/-!
# Reflective functors
Basic properties of reflective functors, especially those relating to their essential image.
Note properties of reflective functors relating to limits and colimits are included in
`Mathlib.CategoryTheory.Monad.Limits`.
-/
universe v₁ v₂ v₃ u₁ u₂ u₃
noncomputable section
namespace CategoryTheory
open Category Adjunction
variable {C : Type u₁} {D : Type u₂} {E : Type u₃}
variable [Category.{v₁} C] [Category.{v₂} D] [Category.{v₃} E]
/--
A functor is *reflective*, or *a reflective inclusion*, if it is fully faithful and right adjoint.
-/
class Reflective (R : D ⥤ C) extends R.Full, R.Faithful where
/-- a choice of a left adjoint to `R` -/
L : C ⥤ D
/-- `R` is a right adjoint -/
adj : L ⊣ R
variable (i : D ⥤ C)
/-- The reflector `C ⥤ D` when `R : D ⥤ C` is reflective. -/
def reflector [Reflective i] : C ⥤ D := Reflective.L (R := i)
/-- The adjunction `reflector i ⊣ i` when `i` is reflective. -/
def reflectorAdjunction [Reflective i] : reflector i ⊣ i := Reflective.adj
instance [Reflective i] : i.IsRightAdjoint := ⟨_, ⟨reflectorAdjunction i⟩⟩
instance [Reflective i] : (reflector i).IsLeftAdjoint := ⟨_, ⟨reflectorAdjunction i⟩⟩
/-- A reflective functor is fully faithful. -/
def Functor.fullyFaithfulOfReflective [Reflective i] : i.FullyFaithful :=
(reflectorAdjunction i).fullyFaithfulROfIsIsoCounit
-- TODO: This holds more generally for idempotent adjunctions, not just reflective adjunctions.
/-- For a reflective functor `i` (with left adjoint `L`), with unit `η`, we have `η_iL = iL η`.
-/
theorem unit_obj_eq_map_unit [Reflective i] (X : C) :
(reflectorAdjunction i).unit.app (i.obj ((reflector i).obj X)) =
i.map ((reflector i).map ((reflectorAdjunction i).unit.app X)) := by
rw [← cancel_mono (i.map ((reflectorAdjunction i).counit.app ((reflector i).obj X))),
← i.map_comp]
simp
/--
When restricted to objects in `D` given by `i : D ⥤ C`, the unit is an isomorphism. In other words,
`η_iX` is an isomorphism for any `X` in `D`.
More generally this applies to objects essentially in the reflective subcategory, see
`Functor.essImage.unit_isIso`.
-/
example [Reflective i] {B : D} : IsIso ((reflectorAdjunction i).unit.app (i.obj B)) :=
inferInstance
variable {i}
/-- If `A` is essentially in the image of a reflective functor `i`, then `η_A` is an isomorphism.
This gives that the "witness" for `A` being in the essential image can instead be given as the
reflection of `A`, with the isomorphism as `η_A`.
(For any `B` in the reflective subcategory, we automatically have that `ε_B` is an iso.)
-/
theorem Functor.essImage.unit_isIso [Reflective i] {A : C} (h : i.essImage A) :
IsIso ((reflectorAdjunction i).unit.app A) := by
rwa [isIso_unit_app_iff_mem_essImage]
/-- If `η_A` is a split monomorphism, then `A` is in the reflective subcategory. -/
theorem mem_essImage_of_unit_isSplitMono [Reflective i] {A : C}
[IsSplitMono ((reflectorAdjunction i).unit.app A)] : i.essImage A := by
let η : 𝟭 C ⟶ reflector i ⋙ i := (reflectorAdjunction i).unit
haveI : IsIso (η.app (i.obj ((reflector i).obj A))) :=
Functor.essImage.unit_isIso ((i.obj_mem_essImage _))
have : Epi (η.app A) := by
refine @epi_of_epi _ _ _ _ _ (retraction (η.app A)) (η.app A) ?_
rw [show retraction _ ≫ η.app A = _ from η.naturality (retraction (η.app A))]
apply epi_comp (η.app (i.obj ((reflector i).obj A)))
haveI := isIso_of_epi_of_isSplitMono (η.app A)
exact (reflectorAdjunction i).mem_essImage_of_unit_isIso A
/-- Composition of reflective functors. -/
instance Reflective.comp (F : C ⥤ D) (G : D ⥤ E) [Reflective F] [Reflective G] :
Reflective (F ⋙ G) where
L := reflector G ⋙ reflector F
adj := (reflectorAdjunction G).comp (reflectorAdjunction F)
/-- (Implementation) Auxiliary definition for `unitCompPartialBijective`. -/
def unitCompPartialBijectiveAux [Reflective i] (A : C) (B : D) :
(A ⟶ i.obj B) ≃ (i.obj ((reflector i).obj A) ⟶ i.obj B) :=
((reflectorAdjunction i).homEquiv _ _).symm.trans
(Functor.FullyFaithful.ofFullyFaithful i).homEquiv
/-- The description of the inverse of the bijection `unitCompPartialBijectiveAux`. -/
theorem unitCompPartialBijectiveAux_symm_apply [Reflective i] {A : C} {B : D}
(f : i.obj ((reflector i).obj A) ⟶ i.obj B) :
(unitCompPartialBijectiveAux _ _).symm f = (reflectorAdjunction i).unit.app A ≫ f := by
simp [unitCompPartialBijectiveAux, Adjunction.homEquiv_unit]
/-- If `i` has a reflector `L`, then the function `(i.obj (L.obj A) ⟶ B) → (A ⟶ B)` given by
precomposing with `η.app A` is a bijection provided `B` is in the essential image of `i`.
That is, the function `fun (f : i.obj (L.obj A) ⟶ B) ↦ η.app A ≫ f` is bijective,
| as long as `B` is in the essential image of `i`.
This definition gives an equivalence: the key property that the inverse can be described
nicely is shown in `unitCompPartialBijective_symm_apply`.
| Mathlib/CategoryTheory/Adjunction/Reflective.lean | 121 | 124 |
/-
Copyright (c) 2022 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.Calculus.SmoothSeries
import Mathlib.Analysis.Calculus.BumpFunction.InnerProduct
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.InnerProductSpace.EuclideanDist
import Mathlib.Data.Set.Pointwise.Support
import Mathlib.MeasureTheory.Measure.Haar.NormedSpace
import Mathlib.MeasureTheory.Measure.Haar.Unique
/-!
# Bump functions in finite-dimensional vector spaces
Let `E` be a finite-dimensional real normed vector space. We show that any open set `s` in `E` is
exactly the support of a smooth function taking values in `[0, 1]`,
in `IsOpen.exists_smooth_support_eq`.
Then we use this construction to construct bump functions with nice behavior, by convolving
the indicator function of `closedBall 0 1` with a function as above with `s = ball 0 D`.
-/
noncomputable section
open Set Metric TopologicalSpace Function Asymptotics MeasureTheory Module
ContinuousLinearMap Filter MeasureTheory.Measure Bornology
open scoped Pointwise Topology NNReal Convolution ContDiff
variable {E : Type*} [NormedAddCommGroup E]
section
variable [NormedSpace ℝ E] [FiniteDimensional ℝ E]
/-- If a set `s` is a neighborhood of `x`, then there exists a smooth function `f` taking
values in `[0, 1]`, supported in `s` and with `f x = 1`. -/
theorem exists_smooth_tsupport_subset {s : Set E} {x : E} (hs : s ∈ 𝓝 x) :
∃ f : E → ℝ,
tsupport f ⊆ s ∧ HasCompactSupport f ∧ ContDiff ℝ ∞ f ∧ range f ⊆ Icc 0 1 ∧ f x = 1 := by
obtain ⟨d : ℝ, d_pos : 0 < d, hd : Euclidean.closedBall x d ⊆ s⟩ :=
Euclidean.nhds_basis_closedBall.mem_iff.1 hs
let c : ContDiffBump (toEuclidean x) :=
{ rIn := d / 2
rOut := d
rIn_pos := half_pos d_pos
rIn_lt_rOut := half_lt_self d_pos }
let f : E → ℝ := c ∘ toEuclidean
have f_supp : f.support ⊆ Euclidean.ball x d := by
intro y hy
have : toEuclidean y ∈ Function.support c := by
simpa only [Function.mem_support, Function.comp_apply, Ne] using hy
rwa [c.support_eq] at this
have f_tsupp : tsupport f ⊆ Euclidean.closedBall x d := by
rw [tsupport, ← Euclidean.closure_ball _ d_pos.ne']
exact closure_mono f_supp
refine ⟨f, f_tsupp.trans hd, ?_, ?_, ?_, ?_⟩
· refine isCompact_of_isClosed_isBounded isClosed_closure ?_
have : IsBounded (Euclidean.closedBall x d) := Euclidean.isCompact_closedBall.isBounded
refine this.subset (Euclidean.isClosed_closedBall.closure_subset_iff.2 ?_)
exact f_supp.trans Euclidean.ball_subset_closedBall
· apply c.contDiff.comp
exact ContinuousLinearEquiv.contDiff _
· rintro t ⟨y, rfl⟩
exact ⟨c.nonneg, c.le_one⟩
· apply c.one_of_mem_closedBall
apply mem_closedBall_self
exact (half_pos d_pos).le
/-- Given an open set `s` in a finite-dimensional real normed vector space, there exists a smooth
function with values in `[0, 1]` whose support is exactly `s`. -/
theorem IsOpen.exists_smooth_support_eq {s : Set E} (hs : IsOpen s) :
∃ f : E → ℝ, f.support = s ∧ ContDiff ℝ ∞ f ∧ Set.range f ⊆ Set.Icc 0 1 := by
/- For any given point `x` in `s`, one can construct a smooth function with support in `s` and
nonzero at `x`. By second-countability, it follows that we may cover `s` with the supports of
countably many such functions, say `g i`.
Then `∑ i, r i • g i` will be the desired function if `r i` is a sequence of positive numbers
tending quickly enough to zero. Indeed, this ensures that, for any `k ≤ i`, the `k`-th
derivative of `r i • g i` is bounded by a prescribed (summable) sequence `u i`. From this, the
summability of the series and of its successive derivatives follows. -/
rcases eq_empty_or_nonempty s with (rfl | h's)
· exact
⟨fun _ => 0, Function.support_zero, contDiff_const, by
simp only [range_const, singleton_subset_iff, left_mem_Icc, zero_le_one]⟩
let ι := { f : E → ℝ // f.support ⊆ s ∧ HasCompactSupport f ∧ ContDiff ℝ ∞ f ∧ range f ⊆ Icc 0 1 }
obtain ⟨T, T_count, hT⟩ : ∃ T : Set ι, T.Countable ∧ ⋃ f ∈ T, support (f : E → ℝ) = s := by
have : ⋃ f : ι, (f : E → ℝ).support = s := by
refine Subset.antisymm (iUnion_subset fun f => f.2.1) ?_
intro x hx
rcases exists_smooth_tsupport_subset (hs.mem_nhds hx) with ⟨f, hf⟩
let g : ι := ⟨f, (subset_tsupport f).trans hf.1, hf.2.1, hf.2.2.1, hf.2.2.2.1⟩
have : x ∈ support (g : E → ℝ) := by
simp only [g, hf.2.2.2.2, Subtype.coe_mk, mem_support, Ne, one_ne_zero,
not_false_iff]
exact mem_iUnion_of_mem _ this
simp_rw [← this]
apply isOpen_iUnion_countable
rintro ⟨f, hf⟩
exact hf.2.2.1.continuous.isOpen_support
obtain ⟨g0, hg⟩ : ∃ g0 : ℕ → ι, T = range g0 := by
apply Countable.exists_eq_range T_count
rcases eq_empty_or_nonempty T with (rfl | hT)
· simp only [ι, iUnion_false, iUnion_empty] at hT
simp only [← hT, mem_empty_iff_false, iUnion_of_empty, iUnion_empty, Set.not_nonempty_empty]
at h's
· exact hT
let g : ℕ → E → ℝ := fun n => (g0 n).1
have g_s : ∀ n, support (g n) ⊆ s := fun n => (g0 n).2.1
have s_g : ∀ x ∈ s, ∃ n, x ∈ support (g n) := fun x hx ↦ by
rw [← hT] at hx
obtain ⟨i, iT, hi⟩ : ∃ i ∈ T, x ∈ support (i : E → ℝ) := by
simpa only [mem_iUnion, exists_prop] using hx
rw [hg, mem_range] at iT
rcases iT with ⟨n, hn⟩
rw [← hn] at hi
exact ⟨n, hi⟩
have g_smooth : ∀ n, ContDiff ℝ ∞ (g n) := fun n => (g0 n).2.2.2.1
have g_comp_supp : ∀ n, HasCompactSupport (g n) := fun n => (g0 n).2.2.1
have g_nonneg : ∀ n x, 0 ≤ g n x := fun n x => ((g0 n).2.2.2.2 (mem_range_self x)).1
obtain ⟨δ, δpos, c, δc, c_lt⟩ :
∃ δ : ℕ → ℝ≥0, (∀ i : ℕ, 0 < δ i) ∧ ∃ c : NNReal, HasSum δ c ∧ c < 1 :=
NNReal.exists_pos_sum_of_countable one_ne_zero ℕ
have : ∀ n : ℕ, ∃ r : ℝ, 0 < r ∧ ∀ i ≤ n, ∀ x, ‖iteratedFDeriv ℝ i (r • g n) x‖ ≤ δ n := by
intro n
have : ∀ i, ∃ R, ∀ x, ‖iteratedFDeriv ℝ i (fun x => g n x) x‖ ≤ R := by
intro i
have : BddAbove (range fun x => ‖iteratedFDeriv ℝ i (fun x : E => g n x) x‖) := by
apply ((g_smooth n).continuous_iteratedFDeriv
(mod_cast le_top)).norm.bddAbove_range_of_hasCompactSupport
apply HasCompactSupport.comp_left _ norm_zero
apply (g_comp_supp n).iteratedFDeriv
rcases this with ⟨R, hR⟩
exact ⟨R, fun x => hR (mem_range_self _)⟩
choose R hR using this
let M := max (((Finset.range (n + 1)).image R).max' (by simp)) 1
have δnpos : 0 < δ n := δpos n
have IR : ∀ i ≤ n, R i ≤ M := by
intro i hi
refine le_trans ?_ (le_max_left _ _)
apply Finset.le_max'
apply Finset.mem_image_of_mem
simp only [Finset.mem_range]
omega
refine ⟨M⁻¹ * δ n, by positivity, fun i hi x => ?_⟩
calc
‖iteratedFDeriv ℝ i ((M⁻¹ * δ n) • g n) x‖ = ‖(M⁻¹ * δ n) • iteratedFDeriv ℝ i (g n) x‖ := by
rw [iteratedFDeriv_const_smul_apply]
exact (g_smooth n).contDiffAt.of_le (mod_cast le_top)
_ = M⁻¹ * δ n * ‖iteratedFDeriv ℝ i (g n) x‖ := by
rw [norm_smul _ (iteratedFDeriv ℝ i (g n) x), Real.norm_of_nonneg]; positivity
_ ≤ M⁻¹ * δ n * M := by gcongr; exact (hR i x).trans (IR i hi)
_ = δ n := by field_simp
choose r rpos hr using this
have S : ∀ x, Summable fun n => (r n • g n) x := fun x ↦ by
refine .of_nnnorm_bounded _ δc.summable fun n => ?_
rw [← NNReal.coe_le_coe, coe_nnnorm]
simpa only [norm_iteratedFDeriv_zero] using hr n 0 (zero_le n) x
refine ⟨fun x => ∑' n, (r n • g n) x, ?_, ?_, ?_⟩
· apply Subset.antisymm
· intro x hx
simp only [Pi.smul_apply, Algebra.id.smul_eq_mul, mem_support, Ne] at hx
contrapose! hx
have : ∀ n, g n x = 0 := by
intro n
contrapose! hx
exact g_s n hx
simp only [this, mul_zero, tsum_zero]
· intro x hx
obtain ⟨n, hn⟩ : ∃ n, x ∈ support (g n) := s_g x hx
have I : 0 < r n * g n x := mul_pos (rpos n) (lt_of_le_of_ne (g_nonneg n x) (Ne.symm hn))
exact ne_of_gt ((S x).tsum_pos (fun i => mul_nonneg (rpos i).le (g_nonneg i x)) n I)
· refine
contDiff_tsum_of_eventually (fun n => (g_smooth n).const_smul (r n))
(fun k _ => (NNReal.hasSum_coe.2 δc).summable) ?_
intro i _
simp only [Nat.cofinite_eq_atTop, Pi.smul_apply, Algebra.id.smul_eq_mul,
Filter.eventually_atTop]
exact ⟨i, fun n hn x => hr _ _ hn _⟩
· rintro - ⟨y, rfl⟩
refine ⟨tsum_nonneg fun n => mul_nonneg (rpos n).le (g_nonneg n y), le_trans ?_ c_lt.le⟩
have A : HasSum (fun n => (δ n : ℝ)) c := NNReal.hasSum_coe.2 δc
simp only [Pi.smul_apply, smul_eq_mul, NNReal.val_eq_coe, ← A.tsum_eq]
apply Summable.tsum_le_tsum _ (S y) A.summable
intro n
apply (le_abs_self _).trans
simpa only [norm_iteratedFDeriv_zero] using hr n 0 (zero_le n) y
end
section
namespace ExistsContDiffBumpBase
/-- An auxiliary function to construct partitions of unity on finite-dimensional real vector spaces.
It is the characteristic function of the closed unit ball. -/
def φ : E → ℝ :=
(closedBall (0 : E) 1).indicator fun _ => (1 : ℝ)
variable [NormedSpace ℝ E] [FiniteDimensional ℝ E]
section HelperDefinitions
variable (E)
theorem u_exists :
∃ u : E → ℝ,
ContDiff ℝ ∞ u ∧ (∀ x, u x ∈ Icc (0 : ℝ) 1) ∧ support u = ball 0 1 ∧ ∀ x, u (-x) = u x := by
have A : IsOpen (ball (0 : E) 1) := isOpen_ball
obtain ⟨f, f_support, f_smooth, f_range⟩ :
∃ f : E → ℝ, f.support = ball (0 : E) 1 ∧ ContDiff ℝ ∞ f ∧ Set.range f ⊆ Set.Icc 0 1 :=
A.exists_smooth_support_eq
have B : ∀ x, f x ∈ Icc (0 : ℝ) 1 := fun x => f_range (mem_range_self x)
refine ⟨fun x => (f x + f (-x)) / 2, ?_, ?_, ?_, ?_⟩
· exact (f_smooth.add (f_smooth.comp contDiff_neg)).div_const _
· intro x
simp only [mem_Icc]
constructor
· linarith [(B x).1, (B (-x)).1]
· linarith [(B x).2, (B (-x)).2]
· refine support_eq_iff.2 ⟨fun x hx => ?_, fun x hx => ?_⟩
· apply ne_of_gt
have : 0 < f x := by
apply lt_of_le_of_ne (B x).1 (Ne.symm _)
rwa [← f_support] at hx
linarith [(B (-x)).1]
· have I1 : x ∉ support f := by rwa [f_support]
have I2 : -x ∉ support f := by
rw [f_support]
simpa using hx
simp only [mem_support, Classical.not_not] at I1 I2
simp only [I1, I2, add_zero, zero_div]
· intro x; simp only [add_comm, neg_neg]
variable {E} in
/-- An auxiliary function to construct partitions of unity on finite-dimensional real vector spaces,
which is smooth, symmetric, and with support equal to the unit ball. -/
def u (x : E) : ℝ :=
Classical.choose (u_exists E) x
theorem u_smooth : ContDiff ℝ ∞ (u : E → ℝ) :=
(Classical.choose_spec (u_exists E)).1
theorem u_continuous : Continuous (u : E → ℝ) :=
(u_smooth E).continuous
theorem u_support : support (u : E → ℝ) = ball 0 1 :=
(Classical.choose_spec (u_exists E)).2.2.1
theorem u_compact_support : HasCompactSupport (u : E → ℝ) := by
rw [hasCompactSupport_def, u_support, closure_ball (0 : E) one_ne_zero]
exact isCompact_closedBall _ _
variable {E}
theorem u_nonneg (x : E) : 0 ≤ u x :=
((Classical.choose_spec (u_exists E)).2.1 x).1
theorem u_le_one (x : E) : u x ≤ 1 :=
((Classical.choose_spec (u_exists E)).2.1 x).2
theorem u_neg (x : E) : u (-x) = u x :=
(Classical.choose_spec (u_exists E)).2.2.2 x
variable [MeasurableSpace E] [BorelSpace E]
local notation "μ" => MeasureTheory.Measure.addHaar
variable (E) in
theorem u_int_pos : 0 < ∫ x : E, u x ∂μ := by
refine (integral_pos_iff_support_of_nonneg u_nonneg ?_).mpr ?_
· exact (u_continuous E).integrable_of_hasCompactSupport (u_compact_support E)
· rw [u_support]; exact measure_ball_pos _ _ zero_lt_one
/-- An auxiliary function to construct partitions of unity on finite-dimensional real vector spaces,
which is smooth, symmetric, with support equal to the ball of radius `D` and integral `1`. -/
def w (D : ℝ) (x : E) : ℝ :=
((∫ x : E, u x ∂μ) * |D| ^ finrank ℝ E)⁻¹ • u (D⁻¹ • x)
theorem w_def (D : ℝ) :
(w D : E → ℝ) = fun x => ((∫ x : E, u x ∂μ) * |D| ^ finrank ℝ E)⁻¹ • u (D⁻¹ • x) := by
ext1 x; rfl
theorem w_nonneg (D : ℝ) (x : E) : 0 ≤ w D x := by
apply mul_nonneg _ (u_nonneg _)
apply inv_nonneg.2
apply mul_nonneg (u_int_pos E).le
norm_cast
apply pow_nonneg (abs_nonneg D)
theorem w_mul_φ_nonneg (D : ℝ) (x y : E) : 0 ≤ w D y * φ (x - y) :=
mul_nonneg (w_nonneg D y) (indicator_nonneg (by simp only [zero_le_one, imp_true_iff]) _)
variable (E)
theorem w_integral {D : ℝ} (Dpos : 0 < D) : ∫ x : E, w D x ∂μ = 1 := by
simp_rw [w, integral_smul]
rw [integral_comp_inv_smul_of_nonneg μ (u : E → ℝ) Dpos.le, abs_of_nonneg Dpos.le, mul_comm]
field_simp [(u_int_pos E).ne']
theorem w_support {D : ℝ} (Dpos : 0 < D) : support (w D : E → ℝ) = ball 0 D := by
have B : D • ball (0 : E) 1 = ball 0 D := by
rw [smul_unitBall Dpos.ne', Real.norm_of_nonneg Dpos.le]
have C : D ^ finrank ℝ E ≠ 0 := by
norm_cast
exact pow_ne_zero _ Dpos.ne'
simp only [w_def, Algebra.id.smul_eq_mul, support_mul, support_inv, univ_inter,
support_comp_inv_smul₀ Dpos.ne', u_support, B, support_const (u_int_pos E).ne', support_const C,
abs_of_nonneg Dpos.le]
theorem w_compact_support {D : ℝ} (Dpos : 0 < D) : HasCompactSupport (w D : E → ℝ) := by
rw [hasCompactSupport_def, w_support E Dpos, closure_ball (0 : E) Dpos.ne']
exact isCompact_closedBall _ _
variable {E}
/-- An auxiliary function to construct partitions of unity on finite-dimensional real vector spaces.
It is the convolution between a smooth function of integral `1` supported in the ball of radius `D`,
with the indicator function of the closed unit ball. Therefore, it is smooth, equal to `1` on the
ball of radius `1 - D`, with support equal to the ball of radius `1 + D`. -/
def y (D : ℝ) : E → ℝ :=
w D ⋆[lsmul ℝ ℝ, μ] φ
theorem y_neg (D : ℝ) (x : E) : y D (-x) = y D x := by
apply convolution_neg_of_neg_eq
· filter_upwards with x
simp only [w_def, Real.rpow_natCast, mul_inv_rev, smul_neg, u_neg, smul_eq_mul, forall_const]
· filter_upwards with x
simp only [φ, indicator, mem_closedBall, dist_zero_right, norm_neg, forall_const]
theorem y_eq_one_of_mem_closedBall {D : ℝ} {x : E} (Dpos : 0 < D)
(hx : x ∈ closedBall (0 : E) (1 - D)) : y D x = 1 := by
change (w D ⋆[lsmul ℝ ℝ, μ] φ) x = 1
have B : ∀ y : E, y ∈ ball x D → φ y = 1 := by
have C : ball x D ⊆ ball 0 1 := by
apply ball_subset_ball'
simp only [mem_closedBall] at hx
linarith only [hx]
intro y hy
simp only [φ, indicator, mem_closedBall, ite_eq_left_iff, not_le, zero_ne_one]
intro h'y
linarith only [mem_ball.1 (C hy), h'y]
have Bx : φ x = 1 := B _ (mem_ball_self Dpos)
have B' : ∀ y, y ∈ ball x D → φ y = φ x := by rw [Bx]; exact B
rw [convolution_eq_right' _ (le_of_eq (w_support E Dpos)) B']
simp only [lsmul_apply, Algebra.id.smul_eq_mul, integral_mul_const, w_integral E Dpos, Bx,
one_mul]
theorem y_eq_zero_of_not_mem_ball {D : ℝ} {x : E} (Dpos : 0 < D) (hx : x ∉ ball (0 : E) (1 + D)) :
y D x = 0 := by
change (w D ⋆[lsmul ℝ ℝ, μ] φ) x = 0
have B : ∀ y, y ∈ ball x D → φ y = 0 := by
intro y hy
simp only [φ, indicator, mem_closedBall_zero_iff, ite_eq_right_iff, one_ne_zero]
intro h'y
have C : ball y D ⊆ ball 0 (1 + D) := by
apply ball_subset_ball'
rw [← dist_zero_right] at h'y
linarith only [h'y]
exact hx (C (mem_ball_comm.1 hy))
have Bx : φ x = 0 := B _ (mem_ball_self Dpos)
have B' : ∀ y, y ∈ ball x D → φ y = φ x := by rw [Bx]; exact B
rw [convolution_eq_right' _ (le_of_eq (w_support E Dpos)) B']
simp only [lsmul_apply, Algebra.id.smul_eq_mul, Bx, mul_zero, integral_const]
theorem y_nonneg (D : ℝ) (x : E) : 0 ≤ y D x :=
integral_nonneg (w_mul_φ_nonneg D x)
theorem y_le_one {D : ℝ} (x : E) (Dpos : 0 < D) : y D x ≤ 1 := by
have A : (w D ⋆[lsmul ℝ ℝ, μ] φ) x ≤ (w D ⋆[lsmul ℝ ℝ, μ] 1) x := by
apply
convolution_mono_right_of_nonneg _ (w_nonneg D) (indicator_le_self' fun x _ => zero_le_one)
fun _ => zero_le_one
refine ((w_compact_support E Dpos).convolutionExists_left _ ?_
(locallyIntegrable_const (1 : ℝ)) x).integrable
exact continuous_const.mul ((u_continuous E).comp (continuous_id.const_smul _))
have B : (w D ⋆[lsmul ℝ ℝ, μ] fun _ => (1 : ℝ)) x = 1 := by
simp only [convolution, ContinuousLinearMap.map_smul, mul_inv_rev, coe_smul', mul_one,
lsmul_apply, Algebra.id.smul_eq_mul, integral_const_mul, w_integral E Dpos, Pi.smul_apply]
exact A.trans (le_of_eq B)
theorem y_pos_of_mem_ball {D : ℝ} {x : E} (Dpos : 0 < D) (D_lt_one : D < 1)
(hx : x ∈ ball (0 : E) (1 + D)) : 0 < y D x := by
simp only [mem_ball_zero_iff] at hx
refine (integral_pos_iff_support_of_nonneg (w_mul_φ_nonneg D x) ?_).2 ?_
· have F_comp : HasCompactSupport (w D) := w_compact_support E Dpos
have B : LocallyIntegrable (φ : E → ℝ) μ :=
(locallyIntegrable_const _).indicator measurableSet_closedBall
have C : Continuous (w D : E → ℝ) :=
continuous_const.mul ((u_continuous E).comp (continuous_id.const_smul _))
exact (F_comp.convolutionExists_left (lsmul ℝ ℝ : ℝ →L[ℝ] ℝ →L[ℝ] ℝ) C B x).integrable
· set z := (D / (1 + D)) • x with hz
have B : 0 < 1 + D := by linarith
have C : ball z (D * (1 + D - ‖x‖) / (1 + D)) ⊆ support fun y : E => w D y * φ (x - y) := by
intro y hy
simp only [support_mul, w_support E Dpos]
simp only [φ, mem_inter_iff, mem_support, Ne, indicator_apply_eq_zero,
mem_closedBall_zero_iff, one_ne_zero, not_forall, not_false_iff, exists_prop, and_true]
constructor
· apply ball_subset_ball' _ hy
simp only [hz, norm_smul, abs_of_nonneg Dpos.le, abs_of_nonneg B.le, dist_zero_right,
Real.norm_eq_abs, abs_div]
simp only [div_le_iff₀ B, field_simps]
ring_nf
rfl
· have ID : ‖D / (1 + D) - 1‖ = 1 / (1 + D) := by
rw [Real.norm_of_nonpos]
· simp only [B.ne', Ne, not_false_iff, mul_one, neg_sub, add_tsub_cancel_right,
field_simps]
· simp only [B.ne', Ne, not_false_iff, mul_one, field_simps]
apply div_nonpos_of_nonpos_of_nonneg _ B.le
linarith only
rw [← mem_closedBall_iff_norm']
apply closedBall_subset_closedBall' _ (ball_subset_closedBall hy)
rw [← one_smul ℝ x, dist_eq_norm, hz, ← sub_smul, one_smul, norm_smul, ID]
simp only [B.ne', div_le_iff₀ B, field_simps]
nlinarith only [hx, D_lt_one]
apply lt_of_lt_of_le _ (measure_mono C)
| apply measure_ball_pos
exact div_pos (mul_pos Dpos (by linarith only [hx])) B
variable (E)
theorem y_smooth : ContDiffOn ℝ ∞ (uncurry y) (Ioo (0 : ℝ) 1 ×ˢ (univ : Set E)) := by
have hs : IsOpen (Ioo (0 : ℝ) (1 : ℝ)) := isOpen_Ioo
have hk : IsCompact (closedBall (0 : E) 1) := ProperSpace.isCompact_closedBall _ _
refine contDiffOn_convolution_left_with_param (lsmul ℝ ℝ) hs hk ?_ ?_ ?_
· rintro p x hp hx
simp only [w, mul_inv_rev, Algebra.id.smul_eq_mul, mul_eq_zero, inv_eq_zero]
right
contrapose! hx
have : p⁻¹ • x ∈ support u := mem_support.2 hx
simp only [u_support, norm_smul, mem_ball_zero_iff, Real.norm_eq_abs, abs_inv,
abs_of_nonneg hp.1.le, ← div_eq_inv_mul, div_lt_one hp.1] at this
rw [mem_closedBall_zero_iff]
exact this.le.trans hp.2.le
· exact (locallyIntegrable_const _).indicator measurableSet_closedBall
· apply ContDiffOn.mul
· norm_cast
refine
(contDiffOn_const.mul ?_).inv fun x hx =>
ne_of_gt (mul_pos (u_int_pos E) (pow_pos (abs_pos_of_pos hx.1.1) (finrank ℝ E)))
apply ContDiffOn.pow
simp_rw [← Real.norm_eq_abs]
apply ContDiffOn.norm ℝ
· exact contDiffOn_fst
· intro x hx; exact ne_of_gt hx.1.1
· apply (u_smooth E).comp_contDiffOn
exact ContDiffOn.smul (contDiffOn_fst.inv fun x hx => ne_of_gt hx.1.1) contDiffOn_snd
theorem y_support {D : ℝ} (Dpos : 0 < D) (D_lt_one : D < 1) :
support (y D : E → ℝ) = ball (0 : E) (1 + D) :=
support_eq_iff.2
⟨fun _ hx => (y_pos_of_mem_ball Dpos D_lt_one hx).ne', fun _ hx =>
y_eq_zero_of_not_mem_ball Dpos hx⟩
variable {E}
end HelperDefinitions
| Mathlib/Analysis/Calculus/BumpFunction/FiniteDimension.lean | 421 | 461 |
/-
Copyright (c) 2020 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash, Antoine Labelle
-/
import Mathlib.LinearAlgebra.Dual.Lemmas
import Mathlib.LinearAlgebra.Matrix.ToLin
/-!
# Contractions
Given modules $M, N$ over a commutative ring $R$, this file defines the natural linear maps:
$M^* \otimes M \to R$, $M \otimes M^* \to R$, and $M^* \otimes N → Hom(M, N)$, as well as proving
some basic properties of these maps.
## Tags
contraction, dual module, tensor product
-/
suppress_compilation
variable {ι : Type*} (R M N P Q : Type*)
-- Porting note: we need high priority for this to fire first; not the case in ML3
attribute [local ext high] TensorProduct.ext
section Contraction
open TensorProduct LinearMap Matrix Module
open TensorProduct
section CommSemiring
variable [CommSemiring R]
variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] [AddCommMonoid Q]
variable [Module R M] [Module R N] [Module R P] [Module R Q]
variable [DecidableEq ι] [Fintype ι] (b : Basis ι R M)
/-- The natural left-handed pairing between a module and its dual. -/
def contractLeft : Module.Dual R M ⊗[R] M →ₗ[R] R :=
(uncurry _ _ _ _).toFun LinearMap.id
/-- The natural right-handed pairing between a module and its dual. -/
def contractRight : M ⊗[R] Module.Dual R M →ₗ[R] R :=
(uncurry _ _ _ _).toFun (LinearMap.flip LinearMap.id)
/-- The natural map associating a linear map to the tensor product of two modules. -/
def dualTensorHom : Module.Dual R M ⊗[R] N →ₗ[R] M →ₗ[R] N :=
let M' := Module.Dual R M
(uncurry R M' N (M →ₗ[R] N) : _ → M' ⊗ N →ₗ[R] M →ₗ[R] N) LinearMap.smulRightₗ
variable {R M N P Q}
@[simp]
theorem contractLeft_apply (f : Module.Dual R M) (m : M) : contractLeft R M (f ⊗ₜ m) = f m :=
rfl
@[simp]
theorem contractRight_apply (f : Module.Dual R M) (m : M) : contractRight R M (m ⊗ₜ f) = f m :=
rfl
@[simp]
theorem dualTensorHom_apply (f : Module.Dual R M) (m : M) (n : N) :
dualTensorHom R M N (f ⊗ₜ n) m = f m • n :=
rfl
@[simp]
theorem transpose_dualTensorHom (f : Module.Dual R M) (m : M) :
Dual.transpose (R := R) (dualTensorHom R M M (f ⊗ₜ m)) =
dualTensorHom R _ _ (Dual.eval R M m ⊗ₜ f) := by
ext f' m'
simp only [Dual.transpose_apply, coe_comp, Function.comp_apply, dualTensorHom_apply,
LinearMap.map_smulₛₗ, RingHom.id_apply, Algebra.id.smul_eq_mul, Dual.eval_apply,
LinearMap.smul_apply]
exact mul_comm _ _
@[simp]
theorem dualTensorHom_prodMap_zero (f : Module.Dual R M) (p : P) :
((dualTensorHom R M P) (f ⊗ₜ[R] p)).prodMap (0 : N →ₗ[R] Q) =
dualTensorHom R (M × N) (P × Q) ((f ∘ₗ fst R M N) ⊗ₜ inl R P Q p) := by
ext <;>
simp only [coe_comp, coe_inl, Function.comp_apply, prodMap_apply, dualTensorHom_apply,
fst_apply, Prod.smul_mk, LinearMap.zero_apply, smul_zero]
@[simp]
theorem zero_prodMap_dualTensorHom (g : Module.Dual R N) (q : Q) :
(0 : M →ₗ[R] P).prodMap ((dualTensorHom R N Q) (g ⊗ₜ[R] q)) =
dualTensorHom R (M × N) (P × Q) ((g ∘ₗ snd R M N) ⊗ₜ inr R P Q q) := by
ext <;>
simp only [coe_comp, coe_inr, Function.comp_apply, prodMap_apply, dualTensorHom_apply,
snd_apply, Prod.smul_mk, LinearMap.zero_apply, smul_zero]
theorem map_dualTensorHom (f : Module.Dual R M) (p : P) (g : Module.Dual R N) (q : Q) :
TensorProduct.map (dualTensorHom R M P (f ⊗ₜ[R] p)) (dualTensorHom R N Q (g ⊗ₜ[R] q)) =
dualTensorHom R (M ⊗[R] N) (P ⊗[R] Q) (dualDistrib R M N (f ⊗ₜ g) ⊗ₜ[R] p ⊗ₜ[R] q) := by
ext m n
simp only [compr₂_apply, mk_apply, map_tmul, dualTensorHom_apply, dualDistrib_apply, ←
smul_tmul_smul]
@[simp]
theorem comp_dualTensorHom (f : Module.Dual R M) (n : N) (g : Module.Dual R N) (p : P) :
dualTensorHom R N P (g ⊗ₜ[R] p) ∘ₗ dualTensorHom R M N (f ⊗ₜ[R] n) =
g n • dualTensorHom R M P (f ⊗ₜ p) := by
ext m
simp only [coe_comp, Function.comp_apply, dualTensorHom_apply, LinearMap.map_smul,
RingHom.id_apply, LinearMap.smul_apply]
rw [smul_comm]
/-- As a matrix, `dualTensorHom` evaluated on a basis element of `M* ⊗ N` is a matrix with a
single one and zeros elsewhere -/
theorem toMatrix_dualTensorHom {m : Type*} {n : Type*} [Fintype m] [Finite n] [DecidableEq m]
[DecidableEq n] (bM : Basis m R M) (bN : Basis n R N) (j : m) (i : n) :
toMatrix bM bN (dualTensorHom R M N (bM.coord j ⊗ₜ bN i)) = stdBasisMatrix i j 1 := by
ext i' j'
by_cases hij : i = i' ∧ j = j' <;>
simp [LinearMap.toMatrix_apply, Finsupp.single_eq_pi_single, hij]
rw [and_iff_not_or_not, Classical.not_not] at hij
rcases hij with hij | hij <;> simp [hij]
end CommSemiring
section CommRing
variable [CommRing R]
variable [AddCommGroup M] [AddCommGroup N] [AddCommGroup P] [AddCommGroup Q]
variable [Module R M] [Module R N] [Module R P] [Module R Q]
variable [DecidableEq ι] [Fintype ι] (b : Basis ι R M)
variable {R M N P Q}
/-- If `M` is free, the natural linear map $M^* ⊗ N → Hom(M, N)$ is an equivalence. This function
provides this equivalence in return for a basis of `M`. -/
-- We manually create simp-lemmas because `@[simps]` generates a malformed lemma
noncomputable def dualTensorHomEquivOfBasis : Module.Dual R M ⊗[R] N ≃ₗ[R] M →ₗ[R] N :=
LinearEquiv.ofLinear (dualTensorHom R M N)
(∑ i, TensorProduct.mk R _ N (b.dualBasis i) ∘ₗ (LinearMap.applyₗ (R := R) (b i)))
(by
ext f m
simp only [applyₗ_apply_apply, coeFn_sum, dualTensorHom_apply, mk_apply, id_coe, _root_.id,
Fintype.sum_apply, Function.comp_apply, Basis.coe_dualBasis, coe_comp, Basis.coord_apply, ←
f.map_smul, _root_.map_sum (dualTensorHom R M N), ← _root_.map_sum f, b.sum_repr])
(by
ext f m
simp only [applyₗ_apply_apply, coeFn_sum, dualTensorHom_apply, mk_apply, id_coe, _root_.id,
Fintype.sum_apply, Function.comp_apply, Basis.coe_dualBasis, coe_comp, compr₂_apply,
tmul_smul, smul_tmul', ← sum_tmul, Basis.sum_dual_apply_smul_coord])
@[simp]
theorem dualTensorHomEquivOfBasis_apply (x : Module.Dual R M ⊗[R] N) :
dualTensorHomEquivOfBasis b x = dualTensorHom R M N x := by
ext; rfl
@[simp]
theorem dualTensorHomEquivOfBasis_toLinearMap :
(dualTensorHomEquivOfBasis b).toLinearMap = dualTensorHom R M N :=
rfl
@[simp]
theorem dualTensorHomEquivOfBasis_symm_cancel_left (x : Module.Dual R M ⊗[R] N) :
(dualTensorHomEquivOfBasis b).symm (dualTensorHom R M N x) = x := by
rw [← dualTensorHomEquivOfBasis_apply b,
LinearEquiv.symm_apply_apply <| dualTensorHomEquivOfBasis (N := N) b]
@[simp]
theorem dualTensorHomEquivOfBasis_symm_cancel_right (x : M →ₗ[R] N) :
dualTensorHom R M N ((dualTensorHomEquivOfBasis b).symm x) = x := by
rw [← dualTensorHomEquivOfBasis_apply b, LinearEquiv.apply_symm_apply]
variable (R M N P Q)
variable [Module.Free R M] [Module.Finite R M]
/-- If `M` is finite free, the natural map $M^* ⊗ N → Hom(M, N)$ is an
equivalence. -/
@[simp]
noncomputable def dualTensorHomEquiv : Module.Dual R M ⊗[R] N ≃ₗ[R] M →ₗ[R] N :=
dualTensorHomEquivOfBasis (Module.Free.chooseBasis R M)
end CommRing
end Contraction
section HomTensorHom
open TensorProduct
open Module TensorProduct LinearMap
section CommRing
variable [CommRing R]
variable [AddCommGroup M] [AddCommGroup N] [AddCommGroup P] [AddCommGroup Q]
variable [Module R M] [Module R N] [Module R P] [Module R Q]
variable [Free R M] [Module.Finite R M] [Free R N] [Module.Finite R N]
/-- When `M` is a finite free module, the map `lTensorHomToHomLTensor` is an equivalence. Note
that `lTensorHomEquivHomLTensor` is not defined directly in terms of
`lTensorHomToHomLTensor`, but the equivalence between the two is given by
`lTensorHomEquivHomLTensor_toLinearMap` and `lTensorHomEquivHomLTensor_apply`. -/
noncomputable def lTensorHomEquivHomLTensor : P ⊗[R] (M →ₗ[R] Q) ≃ₗ[R] M →ₗ[R] P ⊗[R] Q :=
congr (LinearEquiv.refl R P) (dualTensorHomEquiv R M Q).symm ≪≫ₗ
TensorProduct.leftComm R P _ Q ≪≫ₗ
dualTensorHomEquiv R M _
/-- When `M` is a finite free module, the map `rTensorHomToHomRTensor` is an equivalence. Note
that `rTensorHomEquivHomRTensor` is not defined directly in terms of
`rTensorHomToHomRTensor`, but the equivalence between the two is given by
`rTensorHomEquivHomRTensor_toLinearMap` and `rTensorHomEquivHomRTensor_apply`. -/
noncomputable def rTensorHomEquivHomRTensor : (M →ₗ[R] P) ⊗[R] Q ≃ₗ[R] M →ₗ[R] P ⊗[R] Q :=
congr (dualTensorHomEquiv R M P).symm (LinearEquiv.refl R Q) ≪≫ₗ TensorProduct.assoc R _ P Q ≪≫ₗ
dualTensorHomEquiv R M _
@[simp]
theorem lTensorHomEquivHomLTensor_toLinearMap :
(lTensorHomEquivHomLTensor R M P Q).toLinearMap = lTensorHomToHomLTensor R M P Q := by
let e := congr (LinearEquiv.refl R P) (dualTensorHomEquiv R M Q)
have h : Function.Surjective e.toLinearMap := e.surjective
refine (cancel_right h).1 ?_
ext f q m
simp only [e, lTensorHomEquivHomLTensor, dualTensorHomEquiv, LinearEquiv.comp_coe, compr₂_apply,
mk_apply, LinearEquiv.coe_coe, LinearEquiv.trans_apply, congr_tmul, LinearEquiv.refl_apply,
dualTensorHomEquivOfBasis_apply, dualTensorHomEquivOfBasis_symm_cancel_left, leftComm_tmul,
dualTensorHom_apply, coe_comp, Function.comp_apply, lTensorHomToHomLTensor_apply, tmul_smul]
@[simp]
theorem rTensorHomEquivHomRTensor_toLinearMap :
(rTensorHomEquivHomRTensor R M P Q).toLinearMap = rTensorHomToHomRTensor R M P Q := by
let e := congr (dualTensorHomEquiv R M P) (LinearEquiv.refl R Q)
have h : Function.Surjective e.toLinearMap := e.surjective
refine (cancel_right h).1 ?_
ext f p q m
simp only [e, rTensorHomEquivHomRTensor, dualTensorHomEquiv, compr₂_apply, mk_apply, coe_comp,
LinearEquiv.coe_toLinearMap, Function.comp_apply, map_tmul, LinearEquiv.coe_coe,
dualTensorHomEquivOfBasis_apply, LinearEquiv.trans_apply, congr_tmul,
dualTensorHomEquivOfBasis_symm_cancel_left, LinearEquiv.refl_apply, assoc_tmul,
dualTensorHom_apply, rTensorHomToHomRTensor_apply, smul_tmul']
variable {R M N P Q}
@[simp]
theorem lTensorHomEquivHomLTensor_apply (x : P ⊗[R] (M →ₗ[R] Q)) :
lTensorHomEquivHomLTensor R M P Q x = lTensorHomToHomLTensor R M P Q x := by
rw [← LinearEquiv.coe_toLinearMap, lTensorHomEquivHomLTensor_toLinearMap]
@[simp]
theorem rTensorHomEquivHomRTensor_apply (x : (M →ₗ[R] P) ⊗[R] Q) :
rTensorHomEquivHomRTensor R M P Q x = rTensorHomToHomRTensor R M P Q x := by
rw [← LinearEquiv.coe_toLinearMap, rTensorHomEquivHomRTensor_toLinearMap]
variable (R M N P Q)
/-- When `M` and `N` are free `R` modules, the map `homTensorHomMap` is an equivalence. Note that
`homTensorHomEquiv` is not defined directly in terms of `homTensorHomMap`, but the equivalence
between the two is given by `homTensorHomEquiv_toLinearMap` and `homTensorHomEquiv_apply`.
-/
noncomputable def homTensorHomEquiv : (M →ₗ[R] P) ⊗[R] (N →ₗ[R] Q) ≃ₗ[R] M ⊗[R] N →ₗ[R] P ⊗[R] Q :=
rTensorHomEquivHomRTensor R M P _ ≪≫ₗ
(LinearEquiv.refl R M).arrowCongr (lTensorHomEquivHomLTensor R N _ Q) ≪≫ₗ
lift.equiv R M N _
|
@[simp]
theorem homTensorHomEquiv_toLinearMap :
(homTensorHomEquiv R M N P Q).toLinearMap = homTensorHomMap R M N P Q := by
ext m n
simp only [homTensorHomEquiv, compr₂_apply, mk_apply, LinearEquiv.coe_toLinearMap,
LinearEquiv.trans_apply, lift.equiv_apply, LinearEquiv.arrowCongr_apply, LinearEquiv.refl_symm,
LinearEquiv.refl_apply, rTensorHomEquivHomRTensor_apply, lTensorHomEquivHomLTensor_apply,
lTensorHomToHomLTensor_apply, rTensorHomToHomRTensor_apply, homTensorHomMap_apply,
map_tmul]
variable {R M N P Q}
| Mathlib/LinearAlgebra/Contraction.lean | 260 | 271 |
/-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
-- Some proofs and docs came from mathlib3 `src/algebra/commute.lean` (c) Neil Strickland
import Mathlib.Algebra.Group.Defs
import Mathlib.Order.Defs.Unbundled
/-!
# Semiconjugate elements of a semigroup
## Main definitions
We say that `x` is semiconjugate to `y` by `a` (`SemiconjBy a x y`), if `a * x = y * a`.
In this file we provide operations on `SemiconjBy _ _ _`.
In the names of these operations, we treat `a` as the “left” argument, and both `x` and `y` as
“right” arguments. This way most names in this file agree with the names of the corresponding lemmas
for `Commute a b = SemiconjBy a b b`. As a side effect, some lemmas have only `_right` version.
Lean does not immediately recognise these terms as equations, so for rewriting we need syntax like
`rw [(h.pow_right 5).eq]` rather than just `rw [h.pow_right 5]`.
This file provides only basic operations (`mul_left`, `mul_right`, `inv_right` etc). Other
operations (`pow_right`, field inverse etc) are in the files that define corresponding notions.
-/
assert_not_exists MonoidWithZero DenselyOrdered
variable {S M G : Type*}
/-- `x` is semiconjugate to `y` by `a`, if `a * x = y * a`. -/
@[to_additive "`x` is additive semiconjugate to `y` by `a` if `a + x = y + a`"]
def SemiconjBy [Mul M] (a x y : M) : Prop :=
a * x = y * a
namespace SemiconjBy
/-- Equality behind `SemiconjBy a x y`; useful for rewriting. -/
@[to_additive "Equality behind `AddSemiconjBy a x y`; useful for rewriting."]
protected theorem eq [Mul S] {a x y : S} (h : SemiconjBy a x y) : a * x = y * a :=
h
section Semigroup
variable [Semigroup S] {a b x y z x' y' : S}
/-- If `a` semiconjugates `x` to `y` and `x'` to `y'`,
then it semiconjugates `x * x'` to `y * y'`. -/
@[to_additive (attr := simp) "If `a` semiconjugates `x` to `y` and `x'` to `y'`,
then it semiconjugates `x + x'` to `y + y'`."]
theorem mul_right (h : SemiconjBy a x y) (h' : SemiconjBy a x' y') :
SemiconjBy a (x * x') (y * y') := by
unfold SemiconjBy
-- TODO this could be done using `assoc_rw` if/when this is ported to mathlib4
rw [← mul_assoc, h.eq, mul_assoc, h'.eq, ← mul_assoc]
/-- If `b` semiconjugates `x` to `y` and `a` semiconjugates `y` to `z`, then `a * b`
semiconjugates `x` to `z`. -/
@[to_additive "If `b` semiconjugates `x` to `y` and `a` semiconjugates `y` to `z`, then `a + b`
semiconjugates `x` to `z`."]
theorem mul_left (ha : SemiconjBy a y z) (hb : SemiconjBy b x y) : SemiconjBy (a * b) x z := by
unfold SemiconjBy
rw [mul_assoc, hb.eq, ← mul_assoc, ha.eq, mul_assoc]
/-- The relation “there exists an element that semiconjugates `a` to `b`” on a semigroup
is transitive. -/
@[to_additive "The relation “there exists an element that semiconjugates `a` to `b`” on an additive
semigroup is transitive."]
protected theorem transitive : Transitive fun a b : S ↦ ∃ c, SemiconjBy c a b
| _, _, _, ⟨x, hx⟩, ⟨y, hy⟩ => ⟨y * x, hy.mul_left hx⟩
end Semigroup
section MulOneClass
variable [MulOneClass M]
/-- Any element semiconjugates `1` to `1`. -/
@[to_additive (attr := simp) "Any element semiconjugates `0` to `0`."]
theorem one_right (a : M) : SemiconjBy a 1 1 := by rw [SemiconjBy, mul_one, one_mul]
/-- One semiconjugates any element to itself. -/
@[to_additive (attr := simp) "Zero semiconjugates any element to itself."]
theorem one_left (x : M) : SemiconjBy 1 x x :=
Eq.symm <| one_right x
/-- The relation “there exists an element that semiconjugates `a` to `b`” on a monoid (or, more
generally, on `MulOneClass` type) is reflexive. -/
@[to_additive "The relation “there exists an element that semiconjugates `a` to `b`” on an additive
monoid (or, more generally, on an `AddZeroClass` type) is reflexive."]
protected theorem reflexive : Reflexive fun a b : M ↦ ∃ c, SemiconjBy c a b
| a => ⟨1, one_left a⟩
end MulOneClass
section Monoid
variable [Monoid M]
@[to_additive (attr := simp)]
theorem pow_right {a x y : M} (h : SemiconjBy a x y) (n : ℕ) : SemiconjBy a (x ^ n) (y ^ n) := by
induction n with
| zero =>
rw [pow_zero, pow_zero]
exact SemiconjBy.one_right _
| succ n ih =>
rw [pow_succ, pow_succ]
exact ih.mul_right h
end Monoid
section Group
variable [Group G]
/-- `a` semiconjugates `x` to `a * x * a⁻¹`. -/
@[to_additive "`a` semiconjugates `x` to `a + x + -a`."]
theorem conj_mk (a x : G) : SemiconjBy a x (a * x * a⁻¹) := by
unfold SemiconjBy; rw [mul_assoc, inv_mul_cancel, mul_one]
@[to_additive (attr := simp)]
theorem conj_iff {a x y b : G} :
SemiconjBy (b * a * b⁻¹) (b * x * b⁻¹) (b * y * b⁻¹) ↔ SemiconjBy a x y := by
unfold SemiconjBy
simp only [← mul_assoc, inv_mul_cancel_right]
repeat rw [mul_assoc]
rw [mul_left_cancel_iff, ← mul_assoc, ← mul_assoc, mul_right_cancel_iff]
end Group
end SemiconjBy
@[to_additive (attr := simp)]
theorem semiconjBy_iff_eq [CancelCommMonoid M] {a x y : M} : SemiconjBy a x y ↔ x = y :=
⟨fun h => mul_left_cancel (h.trans (mul_comm _ _)), fun h => by rw [h, SemiconjBy, mul_comm]⟩
| Mathlib/Algebra/Group/Semiconj/Defs.lean | 159 | 160 | |
/-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Yaël Dillies
-/
import Mathlib.Algebra.Order.Monoid.Defs
import Mathlib.Data.Set.MulAntidiagonal
import Mathlib.Algebra.Group.Pointwise.Set.Basic
/-! # Multiplication antidiagonal as a `Finset`.
We construct the `Finset` of all pairs
of an element in `s` and an element in `t` that multiply to `a`,
given that `s` and `t` are well-ordered. -/
namespace Set
open Pointwise
variable {α : Type*} {s t : Set α}
@[to_additive]
theorem IsPWO.mul [CommMonoid α] [PartialOrder α] [IsOrderedCancelMonoid α]
(hs : s.IsPWO) (ht : t.IsPWO) : IsPWO (s * t) := by
rw [← image_mul_prod]
exact (hs.prod ht).image_of_monotone (monotone_fst.mul' monotone_snd)
variable [CommMonoid α] [LinearOrder α] [IsOrderedCancelMonoid α]
@[to_additive]
theorem IsWF.mul (hs : s.IsWF) (ht : t.IsWF) : IsWF (s * t) :=
(hs.isPWO.mul ht.isPWO).isWF
@[to_additive]
theorem IsWF.min_mul (hs : s.IsWF) (ht : t.IsWF) (hsn : s.Nonempty) (htn : t.Nonempty) :
(hs.mul ht).min (hsn.mul htn) = hs.min hsn * ht.min htn := by
refine le_antisymm (IsWF.min_le _ _ (mem_mul.2 ⟨_, hs.min_mem _, _, ht.min_mem _, rfl⟩)) ?_
rw [IsWF.le_min_iff]
| rintro _ ⟨x, hx, y, hy, rfl⟩
exact mul_le_mul' (hs.min_le _ hx) (ht.min_le _ hy)
end Set
namespace Finset
| Mathlib/Data/Finset/MulAntidiagonal.lean | 40 | 45 |
/-
Copyright (c) 2021 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.Algebra.Homology.HomologicalComplex
/-!
# Homological complexes supported in a single degree
We define `single V j c : V ⥤ HomologicalComplex V c`,
which constructs complexes in `V` of shape `c`, supported in degree `j`.
In `ChainComplex.toSingle₀Equiv` we characterize chain maps to an
`ℕ`-indexed complex concentrated in degree 0; they are equivalent to
`{ f : C.X 0 ⟶ X // C.d 1 0 ≫ f = 0 }`.
(This is useful translating between a projective resolution and
an augmented exact complex of projectives.)
-/
open CategoryTheory Category Limits ZeroObject
universe v u
variable (V : Type u) [Category.{v} V] [HasZeroMorphisms V] [HasZeroObject V]
namespace HomologicalComplex
variable {ι : Type*} [DecidableEq ι] (c : ComplexShape ι)
/-- The functor `V ⥤ HomologicalComplex V c` creating a chain complex supported in a single degree.
-/
noncomputable def single (j : ι) : V ⥤ HomologicalComplex V c where
obj A :=
{ X := fun i => if i = j then A else 0
d := fun _ _ => 0 }
map f :=
{ f := fun i => if h : i = j then eqToHom (by dsimp; rw [if_pos h]) ≫ f ≫
eqToHom (by dsimp; rw [if_pos h]) else 0 }
map_id A := by
ext
dsimp
split_ifs with h
· subst h
simp
· #adaptation_note /-- nightly-2024-03-07
the previous sensible proof `rw [if_neg h]; simp` fails with "motive not type correct".
The following is horrible. -/
convert (id_zero (C := V)).symm
all_goals simp [if_neg h]
map_comp f g := by
ext
dsimp
split_ifs with h
· subst h
simp
· simp
variable {V}
@[simp]
lemma single_obj_X_self (j : ι) (A : V) :
((single V c j).obj A).X j = A := if_pos rfl
lemma isZero_single_obj_X (j : ι) (A : V) (i : ι) (hi : i ≠ j) :
IsZero (((single V c j).obj A).X i) := by
dsimp [single]
rw [if_neg hi]
exact Limits.isZero_zero V
/-- The object in degree `i` of `(single V c h).obj A` is just `A` when `i = j`. -/
noncomputable def singleObjXIsoOfEq (j : ι) (A : V) (i : ι) (hi : i = j) :
((single V c j).obj A).X i ≅ A :=
eqToIso (by subst hi; simp [single])
/-- The object in degree `j` of `(single V c h).obj A` is just `A`. -/
noncomputable def singleObjXSelf (j : ι) (A : V) : ((single V c j).obj A).X j ≅ A :=
singleObjXIsoOfEq c j A j rfl
@[simp]
lemma single_obj_d (j : ι) (A : V) (k l : ι) :
((single V c j).obj A).d k l = 0 := rfl
@[reassoc]
theorem single_map_f_self (j : ι) {A B : V} (f : A ⟶ B) :
((single V c j).map f).f j = (singleObjXSelf c j A).hom ≫
f ≫ (singleObjXSelf c j B).inv := by
dsimp [single]
rw [dif_pos rfl]
rfl
variable (V)
/-- The natural isomorphism `single V c j ⋙ eval V c j ≅ 𝟭 V`. -/
@[simps!]
noncomputable def singleCompEvalIsoSelf (j : ι) : single V c j ⋙ eval V c j ≅ 𝟭 V :=
NatIso.ofComponents (singleObjXSelf c j) (fun {A B} f => by simp [single_map_f_self])
lemma isZero_single_comp_eval (j i : ι) (hi : i ≠ j) : IsZero (single V c j ⋙ eval V c i) :=
Functor.isZero _ (fun _ ↦ isZero_single_obj_X c _ _ _ hi)
variable {V c}
@[ext]
lemma from_single_hom_ext {K : HomologicalComplex V c} {j : ι} {A : V}
{f g : (single V c j).obj A ⟶ K} (hfg : f.f j = g.f j) : f = g := by
ext i
by_cases h : i = j
· subst h
exact hfg
· apply (isZero_single_obj_X c j A i h).eq_of_src
@[ext]
lemma to_single_hom_ext {K : HomologicalComplex V c} {j : ι} {A : V}
{f g : K ⟶ (single V c j).obj A} (hfg : f.f j = g.f j) : f = g := by
ext i
by_cases h : i = j
· subst h
exact hfg
· apply (isZero_single_obj_X c j A i h).eq_of_tgt
instance (j : ι) : (single V c j).Faithful where
map_injective {A B f g} w := by
rw [← cancel_mono (singleObjXSelf c j B).inv,
← cancel_epi (singleObjXSelf c j A).hom, ← single_map_f_self,
← single_map_f_self, w]
instance (j : ι) : (single V c j).Full where
map_surjective {A B} f :=
⟨(singleObjXSelf c j A).inv ≫ f.f j ≫ (singleObjXSelf c j B).hom, by
ext
simp [single_map_f_self]⟩
/-- Constructor for morphisms to a single homological complex. -/
noncomputable def mkHomToSingle {K : HomologicalComplex V c} {j : ι} {A : V} (φ : K.X j ⟶ A)
(hφ : ∀ (i : ι), c.Rel i j → K.d i j ≫ φ = 0) :
K ⟶ (single V c j).obj A where
f i :=
if hi : i = j
then (K.XIsoOfEq hi).hom ≫ φ ≫ (singleObjXIsoOfEq c j A i hi).inv
else 0
comm' i k hik := by
dsimp
rw [comp_zero]
split_ifs with hk
· subst hk
simp only [XIsoOfEq_rfl, Iso.refl_hom, id_comp, reassoc_of% hφ i hik, zero_comp]
· apply (isZero_single_obj_X c j A k hk).eq_of_tgt
@[simp]
lemma mkHomToSingle_f {K : HomologicalComplex V c} {j : ι} {A : V} (φ : K.X j ⟶ A)
(hφ : ∀ (i : ι), c.Rel i j → K.d i j ≫ φ = 0) :
(mkHomToSingle φ hφ).f j = φ ≫ (singleObjXSelf c j A).inv := by
dsimp [mkHomToSingle]
rw [dif_pos rfl, id_comp]
rfl
/-- Constructor for morphisms from a single homological complex. -/
noncomputable def mkHomFromSingle {K : HomologicalComplex V c} {j : ι} {A : V} (φ : A ⟶ K.X j)
(hφ : ∀ (k : ι), c.Rel j k → φ ≫ K.d j k = 0) :
(single V c j).obj A ⟶ K where
f i :=
if hi : i = j
then (singleObjXIsoOfEq c j A i hi).hom ≫ φ ≫ (K.XIsoOfEq hi).inv
else 0
comm' i k hik := by
dsimp
rw [zero_comp]
split_ifs with hi
· subst hi
simp only [XIsoOfEq_rfl, Iso.refl_inv, comp_id, assoc, hφ k hik, comp_zero]
· apply (isZero_single_obj_X c j A i hi).eq_of_src
@[simp]
lemma mkHomFromSingle_f {K : HomologicalComplex V c} {j : ι} {A : V} (φ : A ⟶ K.X j)
(hφ : ∀ (k : ι), c.Rel j k → φ ≫ K.d j k = 0) :
(mkHomFromSingle φ hφ).f j = (singleObjXSelf c j A).hom ≫ φ := by
dsimp [mkHomFromSingle]
rw [dif_pos rfl, comp_id]
rfl
instance (j : ι) : (single V c j).PreservesZeroMorphisms where
end HomologicalComplex
namespace ChainComplex
/-- The functor `V ⥤ ChainComplex V ℕ` creating a chain complex supported in degree zero. -/
noncomputable abbrev single₀ : V ⥤ ChainComplex V ℕ :=
HomologicalComplex.single V (ComplexShape.down ℕ) 0
variable {V}
@[simp]
lemma single₀_obj_zero (A : V) :
((single₀ V).obj A).X 0 = A := rfl
@[simp]
lemma single₀_map_f_zero {A B : V} (f : A ⟶ B) :
((single₀ V).map f).f 0 = f := by
rw [HomologicalComplex.single_map_f_self]
dsimp [HomologicalComplex.singleObjXSelf, HomologicalComplex.singleObjXIsoOfEq]
rw [comp_id, id_comp]
@[simp]
lemma single₀ObjXSelf (X : V) :
HomologicalComplex.singleObjXSelf (ComplexShape.down ℕ) 0 X = Iso.refl _ := rfl
/-- Morphisms from an `ℕ`-indexed chain complex `C`
to a single object chain complex with `X` concentrated in degree 0
are the same as morphisms `f : C.X 0 ⟶ X` such that `C.d 1 0 ≫ f = 0`.
-/
@[simps apply_coe]
noncomputable def toSingle₀Equiv (C : ChainComplex V ℕ) (X : V) :
(C ⟶ (single₀ V).obj X) ≃ { f : C.X 0 ⟶ X // C.d 1 0 ≫ f = 0 } where
toFun φ := ⟨φ.f 0, by rw [← φ.comm 1 0, HomologicalComplex.single_obj_d, comp_zero]⟩
invFun f := HomologicalComplex.mkHomToSingle f.1 (fun i hi => by
obtain rfl : i = 1 := by simpa using hi.symm
exact f.2)
left_inv φ := by aesop_cat
right_inv f := by simp
@[simp]
lemma toSingle₀Equiv_symm_apply_f_zero {C : ChainComplex V ℕ} {X : V}
(f : C.X 0 ⟶ X) (hf : C.d 1 0 ≫ f = 0) :
((toSingle₀Equiv C X).symm ⟨f, hf⟩).f 0 = f := by
simp [toSingle₀Equiv]
/-- Morphisms from a single object chain complex with `X` concentrated in degree 0
to an `ℕ`-indexed chain complex `C` are the same as morphisms `f : X → C.X 0`.
-/
@[simps apply]
noncomputable def fromSingle₀Equiv (C : ChainComplex V ℕ) (X : V) :
((single₀ V).obj X ⟶ C) ≃ (X ⟶ C.X 0) where
toFun f := f.f 0
invFun f := HomologicalComplex.mkHomFromSingle f (fun i hi => by simp at hi)
left_inv := by aesop_cat
right_inv := by aesop_cat
@[simp]
lemma fromSingle₀Equiv_symm_apply_f_zero
{C : ChainComplex V ℕ} {X : V} (f : X ⟶ C.X 0) :
((fromSingle₀Equiv C X).symm f).f 0 = f := by
simp [fromSingle₀Equiv]
@[simp]
lemma fromSingle₀Equiv_symm_apply_f_succ
{C : ChainComplex V ℕ} {X : V} (f : X ⟶ C.X 0) (n : ℕ) :
((fromSingle₀Equiv C X).symm f).f (n + 1) = 0 := rfl
end ChainComplex
namespace CochainComplex
/-- The functor `V ⥤ CochainComplex V ℕ` creating a cochain complex supported in degree zero. -/
noncomputable abbrev single₀ : V ⥤ CochainComplex V ℕ :=
HomologicalComplex.single V (ComplexShape.up ℕ) 0
variable {V}
@[simp]
lemma single₀_obj_zero (A : V) :
((single₀ V).obj A).X 0 = A := rfl
@[simp]
lemma single₀_map_f_zero {A B : V} (f : A ⟶ B) :
((single₀ V).map f).f 0 = f := by
rw [HomologicalComplex.single_map_f_self]
dsimp [HomologicalComplex.singleObjXSelf, HomologicalComplex.singleObjXIsoOfEq]
rw [comp_id, id_comp]
@[simp]
lemma single₀ObjXSelf (X : V) :
HomologicalComplex.singleObjXSelf (ComplexShape.up ℕ) 0 X = Iso.refl _ := rfl
/-- Morphisms from a single object cochain complex with `X` concentrated in degree 0
to an `ℕ`-indexed cochain complex `C`
are the same as morphisms `f : X ⟶ C.X 0` such that `f ≫ C.d 0 1 = 0`. -/
@[simps apply_coe]
noncomputable def fromSingle₀Equiv (C : CochainComplex V ℕ) (X : V) :
((single₀ V).obj X ⟶ C) ≃ { f : X ⟶ C.X 0 // f ≫ C.d 0 1 = 0 } where
toFun φ := ⟨φ.f 0, by rw [φ.comm 0 1, HomologicalComplex.single_obj_d, zero_comp]⟩
invFun f := HomologicalComplex.mkHomFromSingle f.1 (fun i hi => by
obtain rfl : i = 1 := by simpa using hi.symm
exact f.2)
left_inv φ := by aesop_cat
right_inv := by aesop_cat
@[simp]
lemma fromSingle₀Equiv_symm_apply_f_zero {C : CochainComplex V ℕ} {X : V}
(f : X ⟶ C.X 0) (hf : f ≫ C.d 0 1 = 0) :
((fromSingle₀Equiv C X).symm ⟨f, hf⟩).f 0 = f := by
simp [fromSingle₀Equiv]
/-- Morphisms to a single object cochain complex with `X` concentrated in degree 0
| to an `ℕ`-indexed cochain complex `C` are the same as morphisms `f : C.X 0 ⟶ X`.
-/
@[simps apply]
noncomputable def toSingle₀Equiv (C : CochainComplex V ℕ) (X : V) :
(C ⟶ (single₀ V).obj X) ≃ (C.X 0 ⟶ X) where
| Mathlib/Algebra/Homology/Single.lean | 298 | 302 |
/-
Copyright (c) 2020 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Determinant
import Mathlib.Algebra.ContinuedFractions.Computation.CorrectnessTerminating
import Mathlib.Algebra.Order.Ring.Basic
import Mathlib.Data.Nat.Fib.Basic
import Mathlib.Tactic.Monotonicity
/-!
# Approximations for Continued Fraction Computations (`GenContFract.of`)
## Summary
This file contains useful approximations for the values involved in the continued fractions
computation `GenContFract.of`. In particular, we show that the generalized continued fraction given
by `GenContFract.of` in fact is a (regular) continued fraction.
Moreover, we derive some upper bounds for the error term when computing a continued fraction up a
given position, i.e. bounds for the term
`|v - (GenContFract.of v).convs n|`. The derived bounds will show us that the error term indeed gets
smaller. As a corollary, we will be able to show that `(GenContFract.of v).convs` converges to `v`
in `Algebra.ContinuedFractions.Computation.ApproximationCorollaries`.
## Main Theorems
- `GenContFract.of_partNum_eq_one`: shows that all partial numerators `aᵢ` are
equal to one.
- `GenContFract.exists_int_eq_of_partDen`: shows that all partial denominators
`bᵢ` correspond to an integer.
- `GenContFract.of_one_le_get?_partDen`: shows that `1 ≤ bᵢ`.
- `ContFract.of` returns the regular continued fraction of a value.
- `GenContFract.succ_nth_fib_le_of_nthDen`: shows that the `n`th denominator
`Bₙ` is greater than or equal to the `n + 1`th fibonacci number `Nat.fib (n + 1)`.
- `GenContFract.le_of_succ_get?_den`: shows that `bₙ * Bₙ ≤ Bₙ₊₁`, where `bₙ` is
the `n`th partial denominator of the continued fraction.
- `GenContFract.abs_sub_convs_le`: shows that
`|v - Aₙ / Bₙ| ≤ 1 / (Bₙ * Bₙ₊₁)`, where `Aₙ` is the `n`th partial numerator.
## References
- [*Hardy, GH and Wright, EM and Heath-Brown, Roger and Silverman, Joseph*][hardy2008introduction]
-/
open GenContFract
open GenContFract (of)
open Int
variable {K : Type*} {v : K} {n : ℕ} [Field K] [LinearOrder K] [IsStrictOrderedRing K] [FloorRing K]
namespace GenContFract
namespace IntFractPair
/-!
We begin with some lemmas about the stream of `IntFractPair`s, which presumably are not
of great interest for the end user.
-/
/-- Shows that the fractional parts of the stream are in `[0,1)`. -/
theorem nth_stream_fr_nonneg_lt_one {ifp_n : IntFractPair K}
(nth_stream_eq : IntFractPair.stream v n = some ifp_n) : 0 ≤ ifp_n.fr ∧ ifp_n.fr < 1 := by
cases n with
| zero =>
have : IntFractPair.of v = ifp_n := by injection nth_stream_eq
rw [← this, IntFractPair.of]
exact ⟨fract_nonneg _, fract_lt_one _⟩
| succ =>
rcases succ_nth_stream_eq_some_iff.1 nth_stream_eq with ⟨_, _, _, ifp_of_eq_ifp_n⟩
rw [← ifp_of_eq_ifp_n, IntFractPair.of]
exact ⟨fract_nonneg _, fract_lt_one _⟩
/-- Shows that the fractional parts of the stream are nonnegative. -/
theorem nth_stream_fr_nonneg {ifp_n : IntFractPair K}
(nth_stream_eq : IntFractPair.stream v n = some ifp_n) : 0 ≤ ifp_n.fr :=
(nth_stream_fr_nonneg_lt_one nth_stream_eq).left
/-- Shows that the fractional parts of the stream are smaller than one. -/
theorem nth_stream_fr_lt_one {ifp_n : IntFractPair K}
(nth_stream_eq : IntFractPair.stream v n = some ifp_n) : ifp_n.fr < 1 :=
(nth_stream_fr_nonneg_lt_one nth_stream_eq).right
/-- Shows that the integer parts of the stream are at least one. -/
theorem one_le_succ_nth_stream_b {ifp_succ_n : IntFractPair K}
(succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n) : 1 ≤ ifp_succ_n.b := by
obtain ⟨ifp_n, nth_stream_eq, stream_nth_fr_ne_zero, ⟨-⟩⟩ :
∃ ifp_n, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr ≠ 0
∧ IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n :=
succ_nth_stream_eq_some_iff.1 succ_nth_stream_eq
rw [IntFractPair.of, le_floor, cast_one, one_le_inv₀
((nth_stream_fr_nonneg nth_stream_eq).lt_of_ne' stream_nth_fr_ne_zero)]
exact (nth_stream_fr_lt_one nth_stream_eq).le
omit [IsStrictOrderedRing K] in
/--
Shows that the `n + 1`th integer part `bₙ₊₁` of the stream is smaller or equal than the inverse of
the `n`th fractional part `frₙ` of the stream.
This result is straight-forward as `bₙ₊₁` is defined as the floor of `1 / frₙ`.
-/
theorem succ_nth_stream_b_le_nth_stream_fr_inv {ifp_n ifp_succ_n : IntFractPair K}
(nth_stream_eq : IntFractPair.stream v n = some ifp_n)
(succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n) :
(ifp_succ_n.b : K) ≤ ifp_n.fr⁻¹ := by
suffices (⌊ifp_n.fr⁻¹⌋ : K) ≤ ifp_n.fr⁻¹ by
obtain ⟨_, ifp_n_fr⟩ := ifp_n
have : ifp_n_fr ≠ 0 := by
intro h
simp [h, IntFractPair.stream, nth_stream_eq] at succ_nth_stream_eq
have : IntFractPair.of ifp_n_fr⁻¹ = ifp_succ_n := by
simpa [this, IntFractPair.stream, nth_stream_eq, Option.coe_def] using succ_nth_stream_eq
rwa [← this]
exact floor_le ifp_n.fr⁻¹
end IntFractPair
/-!
Next we translate above results about the stream of `IntFractPair`s to the computed continued
fraction `GenContFract.of`.
-/
/-- Shows that the integer parts of the continued fraction are at least one. -/
theorem of_one_le_get?_partDen {b : K}
(nth_partDen_eq : (of v).partDens.get? n = some b) : 1 ≤ b := by
obtain ⟨gp_n, nth_s_eq, ⟨-⟩⟩ : ∃ gp_n, (of v).s.get? n = some gp_n ∧ gp_n.b = b :=
exists_s_b_of_partDen nth_partDen_eq
obtain ⟨ifp_n, succ_nth_stream_eq, ifp_n_b_eq_gp_n_b⟩ :
∃ ifp, IntFractPair.stream v (n + 1) = some ifp ∧ (ifp.b : K) = gp_n.b :=
IntFractPair.exists_succ_get?_stream_of_gcf_of_get?_eq_some nth_s_eq
rw [← ifp_n_b_eq_gp_n_b]
exact mod_cast IntFractPair.one_le_succ_nth_stream_b succ_nth_stream_eq
/--
Shows that the partial numerators `aᵢ` of the continued fraction are equal to one and the partial
denominators `bᵢ` correspond to integers.
-/
theorem of_partNum_eq_one_and_exists_int_partDen_eq {gp : GenContFract.Pair K}
(nth_s_eq : (of v).s.get? n = some gp) : gp.a = 1 ∧ ∃ z : ℤ, gp.b = (z : K) := by
obtain ⟨ifp, stream_succ_nth_eq, -⟩ : ∃ ifp, IntFractPair.stream v (n + 1) = some ifp ∧ _ :=
IntFractPair.exists_succ_get?_stream_of_gcf_of_get?_eq_some nth_s_eq
have : gp = ⟨1, ifp.b⟩ := by
have : (of v).s.get? n = some ⟨1, ifp.b⟩ :=
get?_of_eq_some_of_succ_get?_intFractPair_stream stream_succ_nth_eq
have : some gp = some ⟨1, ifp.b⟩ := by rwa [nth_s_eq] at this
injection this
simp [this]
/-- Shows that the partial numerators `aᵢ` are equal to one. -/
theorem of_partNum_eq_one {a : K} (nth_partNum_eq : (of v).partNums.get? n = some a) :
a = 1 := by
obtain ⟨gp, nth_s_eq, gp_a_eq_a_n⟩ : ∃ gp, (of v).s.get? n = some gp ∧ gp.a = a :=
exists_s_a_of_partNum nth_partNum_eq
have : gp.a = 1 := (of_partNum_eq_one_and_exists_int_partDen_eq nth_s_eq).left
rwa [gp_a_eq_a_n] at this
/-- Shows that the partial denominators `bᵢ` correspond to an integer. -/
theorem exists_int_eq_of_partDen {b : K}
(nth_partDen_eq : (of v).partDens.get? n = some b) : ∃ z : ℤ, b = (z : K) := by
obtain ⟨gp, nth_s_eq, gp_b_eq_b_n⟩ : ∃ gp, (of v).s.get? n = some gp ∧ gp.b = b :=
exists_s_b_of_partDen nth_partDen_eq
have : ∃ z : ℤ, gp.b = (z : K) := (of_partNum_eq_one_and_exists_int_partDen_eq nth_s_eq).right
rwa [gp_b_eq_b_n] at this
end GenContFract
variable (v)
theorem GenContFract.of_isSimpContFract :
(of v).IsSimpContFract := fun _ _ nth_partNum_eq =>
of_partNum_eq_one nth_partNum_eq
/-- Creates the simple continued fraction of a value. -/
nonrec def SimpContFract.of : SimpContFract K :=
⟨of v, GenContFract.of_isSimpContFract v⟩
theorem SimpContFract.of_isContFract :
(SimpContFract.of v).IsContFract := fun _ _ nth_partDen_eq =>
lt_of_lt_of_le zero_lt_one (of_one_le_get?_partDen nth_partDen_eq)
/-- Creates the continued fraction of a value. -/
def ContFract.of : ContFract K :=
⟨SimpContFract.of v, SimpContFract.of_isContFract v⟩
variable {v}
namespace GenContFract
/-!
One of our next goals is to show that `bₙ * Bₙ ≤ Bₙ₊₁`. For this, we first show that the partial
denominators `Bₙ` are bounded from below by the fibonacci sequence `Nat.fib`. This then implies that
`0 ≤ Bₙ` and hence `Bₙ₊₂ = bₙ₊₁ * Bₙ₊₁ + Bₙ ≥ bₙ₊₁ * Bₙ₊₁ + 0 = bₙ₊₁ * Bₙ₊₁`.
-/
-- open `Nat` as we will make use of fibonacci numbers.
open Nat
theorem fib_le_of_contsAux_b :
n ≤ 1 ∨ ¬(of v).TerminatedAt (n - 2) → (fib n : K) ≤ ((of v).contsAux n).b :=
Nat.strong_induction_on n
(by
intro n IH hyp
rcases n with (_ | _ | n)
· simp [fib_add_two, contsAux] -- case n = 0
· simp [fib_add_two, contsAux] -- case n = 1
· let g := of v -- case 2 ≤ n
have : ¬n + 2 ≤ 1 := by omega
have not_terminatedAt_n : ¬g.TerminatedAt n := Or.resolve_left hyp this
obtain ⟨gp, s_ppred_nth_eq⟩ : ∃ gp, g.s.get? n = some gp :=
Option.ne_none_iff_exists'.mp not_terminatedAt_n
set pconts := g.contsAux (n + 1) with pconts_eq
set ppconts := g.contsAux n with ppconts_eq
-- use the recurrence of `contsAux`
simp only [Nat.succ_eq_add_one, Nat.add_assoc, Nat.reduceAdd]
suffices (fib n : K) + fib (n + 1) ≤ gp.a * ppconts.b + gp.b * pconts.b by
simpa [g, fib_add_two, add_comm, contsAux_recurrence s_ppred_nth_eq ppconts_eq pconts_eq]
-- make use of the fact that `gp.a = 1`
suffices (fib n : K) + fib (n + 1) ≤ ppconts.b + gp.b * pconts.b by
simpa [of_partNum_eq_one <| partNum_eq_s_a s_ppred_nth_eq]
have not_terminatedAt_pred_n : ¬g.TerminatedAt (n - 1) :=
mt (terminated_stable <| Nat.sub_le n 1) not_terminatedAt_n
have not_terminatedAt_ppred_n : ¬TerminatedAt g (n - 2) :=
mt (terminated_stable (n - 1).pred_le) not_terminatedAt_pred_n
-- use the IH to get the inequalities for `pconts` and `ppconts`
have ppred_nth_fib_le_ppconts_B : (fib n : K) ≤ ppconts.b :=
IH n (lt_trans (Nat.lt.base n) <| Nat.lt.base <| n + 1) (Or.inr not_terminatedAt_ppred_n)
suffices (fib (n + 1) : K) ≤ gp.b * pconts.b by
solve_by_elim [_root_.add_le_add ppred_nth_fib_le_ppconts_B]
-- finally use the fact that `1 ≤ gp.b` to solve the goal
suffices 1 * (fib (n + 1) : K) ≤ gp.b * pconts.b by rwa [one_mul] at this
have one_le_gp_b : (1 : K) ≤ gp.b :=
of_one_le_get?_partDen (partDen_eq_s_b s_ppred_nth_eq)
have : (0 : K) ≤ fib (n + 1) := mod_cast (fib (n + 1)).zero_le
have : (0 : K) ≤ gp.b := le_trans zero_le_one one_le_gp_b
mono
· norm_num
· tauto)
/-- Shows that the `n`th denominator is greater than or equal to the `n + 1`th fibonacci number,
that is `Nat.fib (n + 1) ≤ Bₙ`. -/
theorem succ_nth_fib_le_of_nth_den (hyp : n = 0 ∨ ¬(of v).TerminatedAt (n - 1)) :
(fib (n + 1) : K) ≤ (of v).dens n := by
rw [den_eq_conts_b, nth_cont_eq_succ_nth_contAux]
have : n + 1 ≤ 1 ∨ ¬(of v).TerminatedAt (n - 1) := by
cases n with
| zero => exact Or.inl <| le_refl 1
| succ n => exact Or.inr (Or.resolve_left hyp n.succ_ne_zero)
exact fib_le_of_contsAux_b this
/-! As a simple consequence, we can now derive that all denominators are nonnegative. -/
theorem zero_le_of_contsAux_b : 0 ≤ ((of v).contsAux n).b := by
let g := of v
induction n with
| zero => rfl
| succ n IH =>
rcases Decidable.em <| g.TerminatedAt (n - 1) with terminated | not_terminated
· -- terminating case
rcases n with - | n
· simp [zero_le_one]
· have : g.contsAux (n + 2) = g.contsAux (n + 1) :=
contsAux_stable_step_of_terminated terminated
simp only [g, this, IH]
· -- non-terminating case
calc
(0 : K) ≤ fib (n + 1) := mod_cast (n + 1).fib.zero_le
_ ≤ ((of v).contsAux (n + 1)).b := fib_le_of_contsAux_b (Or.inr not_terminated)
/-- Shows that all denominators are nonnegative. -/
theorem zero_le_of_den : 0 ≤ (of v).dens n := by
rw [den_eq_conts_b, nth_cont_eq_succ_nth_contAux]; exact zero_le_of_contsAux_b
theorem le_of_succ_succ_get?_contsAux_b {b : K}
(nth_partDen_eq : (of v).partDens.get? n = some b) :
b * ((of v).contsAux <| n + 1).b ≤ ((of v).contsAux <| n + 2).b := by
obtain ⟨gp_n, nth_s_eq, rfl⟩ : ∃ gp_n, (of v).s.get? n = some gp_n ∧ gp_n.b = b :=
exists_s_b_of_partDen nth_partDen_eq
simp [of_partNum_eq_one (partNum_eq_s_a nth_s_eq), zero_le_of_contsAux_b,
GenContFract.contsAux_recurrence nth_s_eq rfl rfl]
/-- Shows that `bₙ * Bₙ ≤ Bₙ₊₁`, where `bₙ` is the `n`th partial denominator and `Bₙ₊₁` and `Bₙ` are
the `n + 1`th and `n`th denominator of the continued fraction. -/
theorem le_of_succ_get?_den {b : K}
(nth_partDenom_eq : (of v).partDens.get? n = some b) :
b * (of v).dens n ≤ (of v).dens (n + 1) := by
rw [den_eq_conts_b, nth_cont_eq_succ_nth_contAux]
exact le_of_succ_succ_get?_contsAux_b nth_partDenom_eq
/-- Shows that the sequence of denominators is monotone, that is `Bₙ ≤ Bₙ₊₁`. -/
theorem of_den_mono : (of v).dens n ≤ (of v).dens (n + 1) := by
let g := of v
rcases Decidable.em <| g.partDens.TerminatedAt n with terminated | not_terminated
· have : g.partDens.get? n = none := by rwa [Stream'.Seq.TerminatedAt] at terminated
have : g.TerminatedAt n :=
terminatedAt_iff_partDen_none.2 (by rwa [Stream'.Seq.TerminatedAt] at terminated)
have : g.dens (n + 1) = g.dens n :=
dens_stable_of_terminated n.le_succ this
rw [this]
· obtain ⟨b, nth_partDen_eq⟩ : ∃ b, g.partDens.get? n = some b :=
Option.ne_none_iff_exists'.mp not_terminated
have : 1 ≤ b := of_one_le_get?_partDen nth_partDen_eq
calc
g.dens n ≤ b * g.dens n := by
simpa using mul_le_mul_of_nonneg_right this zero_le_of_den
_ ≤ g.dens (n + 1) := le_of_succ_get?_den nth_partDen_eq
section ErrorTerm
/-!
### Approximation of Error Term
Next we derive some approximations for the error term when computing a continued fraction up a given
position, i.e. bounds for the term `|v - (GenContFract.of v).convs n|`.
-/
/-- This lemma follows from the finite correctness proof, the determinant equality, and
by simplifying the difference. -/
theorem sub_convs_eq {ifp : IntFractPair K}
(stream_nth_eq : IntFractPair.stream v n = some ifp) :
let g := of v
let B := (g.contsAux (n + 1)).b
let pB := (g.contsAux n).b
v - g.convs n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB)) := by
-- set up some shorthand notation
let g := of v
let conts := g.contsAux (n + 1)
let pred_conts := g.contsAux n
have g_finite_correctness :
v = GenContFract.compExactValue pred_conts conts ifp.fr :=
compExactValue_correctness_of_stream_eq_some stream_nth_eq
obtain (ifp_fr_eq_zero | ifp_fr_ne_zero) := eq_or_ne ifp.fr 0
· suffices v - g.convs n = 0 by simpa [ifp_fr_eq_zero]
replace g_finite_correctness : v = g.convs n := by
simpa [GenContFract.compExactValue, ifp_fr_eq_zero] using g_finite_correctness
exact sub_eq_zero.2 g_finite_correctness
· -- more shorthand notation
let A := conts.a
let B := conts.b
let pA := pred_conts.a
let pB := pred_conts.b
-- first, let's simplify the goal as `ifp.fr ≠ 0`
suffices v - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB)) by simpa [ifp_fr_ne_zero]
-- now we can unfold `g.compExactValue` to derive the following equality for `v`
replace g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) := by
simpa [GenContFract.compExactValue, ifp_fr_ne_zero, nextConts, nextNum, nextDen, add_comm]
using g_finite_correctness
-- let's rewrite this equality for `v` in our goal
suffices
(pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB)) by
rwa [g_finite_correctness]
-- To continue, we need use the determinant equality. So let's derive the needed hypothesis.
have n_eq_zero_or_not_terminatedAt_pred_n : n = 0 ∨ ¬g.TerminatedAt (n - 1) := by
rcases n with - | n'
· simp
· have : IntFractPair.stream v (n' + 1) ≠ none := by simp [stream_nth_eq]
have : ¬g.TerminatedAt n' :=
(not_congr of_terminatedAt_n_iff_succ_nth_intFractPair_stream_eq_none).2 this
exact Or.inr this
have determinant_eq : pA * B - pB * A = (-1) ^ n :=
(SimpContFract.of v).determinant_aux n_eq_zero_or_not_terminatedAt_pred_n
-- now all we got to do is to rewrite this equality in our goal and re-arrange terms;
-- however, for this, we first have to derive quite a few tedious inequalities.
have pB_ineq : (fib n : K) ≤ pB :=
haveI : n ≤ 1 ∨ ¬g.TerminatedAt (n - 2) := by
rcases n_eq_zero_or_not_terminatedAt_pred_n with n_eq_zero | not_terminatedAt_pred_n
· simp [n_eq_zero]
· exact Or.inr <| mt (terminated_stable (n - 1).pred_le) not_terminatedAt_pred_n
fib_le_of_contsAux_b this
have B_ineq : (fib (n + 1) : K) ≤ B :=
haveI : n + 1 ≤ 1 ∨ ¬g.TerminatedAt (n + 1 - 2) := by
rcases n_eq_zero_or_not_terminatedAt_pred_n with n_eq_zero | not_terminatedAt_pred_n
· simp [n_eq_zero, le_refl]
· exact Or.inr not_terminatedAt_pred_n
fib_le_of_contsAux_b this
have zero_lt_B : 0 < B := B_ineq.trans_lt' <| cast_pos.2 <| fib_pos.2 n.succ_pos
have : 0 ≤ pB := (cast_nonneg _).trans pB_ineq
have : 0 < ifp.fr :=
ifp_fr_ne_zero.lt_of_le' <| IntFractPair.nth_stream_fr_nonneg stream_nth_eq
have : pB + ifp.fr⁻¹ * B ≠ 0 := by positivity
-- finally, let's do the rewriting
calc
(pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B =
((pA + ifp.fr⁻¹ * A) * B - (pB + ifp.fr⁻¹ * B) * A) / ((pB + ifp.fr⁻¹ * B) * B) := by
rw [div_sub_div _ _ this zero_lt_B.ne']
_ = (pA * B + ifp.fr⁻¹ * A * B - (pB * A + ifp.fr⁻¹ * B * A)) / _ := by repeat' rw [add_mul]
_ = (pA * B - pB * A) / ((pB + ifp.fr⁻¹ * B) * B) := by ring
_ = (-1) ^ n / ((pB + ifp.fr⁻¹ * B) * B) := by rw [determinant_eq]
_ = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB)) := by ac_rfl
/-- Shows that `|v - Aₙ / Bₙ| ≤ 1 / (Bₙ * Bₙ₊₁)`. -/
theorem abs_sub_convs_le (not_terminatedAt_n : ¬(of v).TerminatedAt n) :
|v - (of v).convs n| ≤ 1 / ((of v).dens n * ((of v).dens <| n + 1)) := by
-- shorthand notation
let g := of v
let nextConts := g.contsAux (n + 2)
set conts := contsAux g (n + 1) with conts_eq
set pred_conts := contsAux g n with pred_conts_eq
-- change the goal to something more readable
change |v - convs g n| ≤ 1 / (conts.b * nextConts.b)
obtain ⟨gp, s_nth_eq⟩ : ∃ gp, g.s.get? n = some gp :=
Option.ne_none_iff_exists'.1 not_terminatedAt_n
have gp_a_eq_one : gp.a = 1 := of_partNum_eq_one (partNum_eq_s_a s_nth_eq)
-- unfold the recurrence relation for `nextConts.b`
have nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b := by
simp [nextConts, contsAux_recurrence s_nth_eq pred_conts_eq conts_eq, gp_a_eq_one,
pred_conts_eq.symm, conts_eq.symm, add_comm]
let den := conts.b * (pred_conts.b + gp.b * conts.b)
suffices |v - g.convs n| ≤ 1 / den by rw [nextConts_b_eq]; congr 1
obtain ⟨ifp_succ_n, succ_nth_stream_eq, ifp_succ_n_b_eq_gp_b⟩ :
∃ ifp_succ_n, IntFractPair.stream v (n + 1) = some ifp_succ_n ∧ (ifp_succ_n.b : K) = gp.b :=
IntFractPair.exists_succ_get?_stream_of_gcf_of_get?_eq_some s_nth_eq
obtain ⟨ifp_n, stream_nth_eq, stream_nth_fr_ne_zero, if_of_eq_ifp_succ_n⟩ :
∃ ifp_n, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr ≠ 0
∧ IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n :=
IntFractPair.succ_nth_stream_eq_some_iff.1 succ_nth_stream_eq
let den' := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
-- now we can use `sub_convs_eq` to simplify our goal
suffices |(-1) ^ n / den'| ≤ 1 / den by
have : v - g.convs n = (-1) ^ n / den' := by
-- apply `sub_convs_eq` and simplify the result
have tmp := sub_convs_eq stream_nth_eq
simp only [stream_nth_fr_ne_zero, conts_eq.symm, pred_conts_eq.symm, if_false] at tmp
rw [tmp]
ring
rwa [this]
-- derive some tedious inequalities that we need to rewrite our goal
have nextConts_b_ineq : (fib (n + 2) : K) ≤ pred_conts.b + gp.b * conts.b := by
have : (fib (n + 2) : K) ≤ nextConts.b :=
fib_le_of_contsAux_b (Or.inr not_terminatedAt_n)
rwa [nextConts_b_eq] at this
have conts_b_ineq : (fib (n + 1) : K) ≤ conts.b :=
haveI : ¬g.TerminatedAt (n - 1) := mt (terminated_stable n.pred_le) not_terminatedAt_n
fib_le_of_contsAux_b <| Or.inr this
have zero_lt_conts_b : 0 < conts.b :=
conts_b_ineq.trans_lt' <| mod_cast fib_pos.2 n.succ_pos
-- `den'` is positive, so we can remove `|⬝|` from our goal
suffices 1 / den' ≤ 1 / den by
have : |(-1) ^ n / den'| = 1 / den' := by
suffices 1 / |den'| = 1 / den' by rwa [abs_div, abs_neg_one_pow n]
have : 0 < den' := by
have : 0 ≤ pred_conts.b :=
haveI : (fib n : K) ≤ pred_conts.b :=
haveI : ¬g.TerminatedAt (n - 2) :=
mt (terminated_stable (n.sub_le 2)) not_terminatedAt_n
fib_le_of_contsAux_b <| Or.inr this
le_trans (mod_cast (fib n).zero_le) this
have : 0 < ifp_n.fr⁻¹ :=
haveI zero_le_ifp_n_fract : 0 ≤ ifp_n.fr :=
IntFractPair.nth_stream_fr_nonneg stream_nth_eq
inv_pos.2 (lt_of_le_of_ne zero_le_ifp_n_fract stream_nth_fr_ne_zero.symm)
positivity
rw [abs_of_pos this]
rwa [this]
suffices 0 < den ∧ den ≤ den' from div_le_div_of_nonneg_left zero_le_one this.1 this.2
constructor
· have : 0 < pred_conts.b + gp.b * conts.b :=
nextConts_b_ineq.trans_lt' <| mod_cast fib_pos.2 <| succ_pos _
solve_by_elim [mul_pos]
· -- we can cancel multiplication by `conts.b` and addition with `pred_conts.b`
suffices gp.b * conts.b ≤ ifp_n.fr⁻¹ * conts.b from
(mul_le_mul_left zero_lt_conts_b).2 <| (add_le_add_iff_left pred_conts.b).2 this
suffices (ifp_succ_n.b : K) * conts.b ≤ ifp_n.fr⁻¹ * conts.b by rwa [← ifp_succ_n_b_eq_gp_b]
have : (ifp_succ_n.b : K) ≤ ifp_n.fr⁻¹ :=
IntFractPair.succ_nth_stream_b_le_nth_stream_fr_inv stream_nth_eq succ_nth_stream_eq
have : 0 ≤ conts.b := le_of_lt zero_lt_conts_b
gcongr; exact this
/-- Shows that `|v - Aₙ / Bₙ| ≤ 1 / (bₙ * Bₙ * Bₙ)`. This bound is worse than the one shown in
`GenContFract.abs_sub_convs_le`, but sometimes it is easier to apply and
sufficient for one's use case.
-/
theorem abs_sub_convergents_le' {b : K}
(nth_partDen_eq : (of v).partDens.get? n = some b) :
|v - (of v).convs n| ≤ 1 / (b * (of v).dens n * (of v).dens n) := by
have not_terminatedAt_n : ¬(of v).TerminatedAt n := by
simp [terminatedAt_iff_partDen_none, nth_partDen_eq]
refine (abs_sub_convs_le not_terminatedAt_n).trans ?_
-- One can show that `0 < (GenContFract.of v).dens n` but it's easier
-- to consider the case `(GenContFract.of v).dens n = 0`.
rcases (zero_le_of_den (K := K)).eq_or_gt with
((hB : (GenContFract.of v).dens n = 0) | hB)
· simp only [hB, mul_zero, zero_mul, div_zero, le_refl]
· apply one_div_le_one_div_of_le
· have : 0 < b := zero_lt_one.trans_le (of_one_le_get?_partDen nth_partDen_eq)
apply_rules [mul_pos]
· conv_rhs => rw [mul_comm]
exact mul_le_mul_of_nonneg_right (le_of_succ_get?_den nth_partDen_eq) hB.le
end ErrorTerm
end GenContFract
| Mathlib/Algebra/ContinuedFractions/Computation/Approximations.lean | 537 | 552 | |
/-
Copyright (c) 2021 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.Algebra.Order.Field.Power
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.RingTheory.Polynomial.Bernstein
import Mathlib.Topology.ContinuousMap.Polynomial
import Mathlib.Topology.ContinuousMap.Compact
/-!
# Bernstein approximations and Weierstrass' theorem
We prove that the Bernstein approximations
```
∑ k : Fin (n+1), f (k/n : ℝ) * n.choose k * x^k * (1-x)^(n-k)
```
for a continuous function `f : C([0,1], ℝ)` converge uniformly to `f` as `n` tends to infinity.
Our proof follows [Richard Beals' *Analysis, an introduction*][beals-analysis], §7D.
The original proof, due to [Bernstein](bernstein1912) in 1912, is probabilistic,
and relies on Bernoulli's theorem,
which gives bounds for how quickly the observed frequencies in a
Bernoulli trial approach the underlying probability.
The proof here does not directly rely on Bernoulli's theorem,
but can also be given a probabilistic account.
* Consider a weighted coin which with probability `x` produces heads,
and with probability `1-x` produces tails.
* The value of `bernstein n k x` is the probability that
such a coin gives exactly `k` heads in a sequence of `n` tosses.
* If such an appearance of `k` heads results in a payoff of `f(k / n)`,
the `n`-th Bernstein approximation for `f` evaluated at `x` is the expected payoff.
* The main estimate in the proof bounds the probability that
the observed frequency of heads differs from `x` by more than some `δ`,
obtaining a bound of `(4 * n * δ^2)⁻¹`, irrespective of `x`.
* This ensures that for `n` large, the Bernstein approximation is (uniformly) close to the
payoff function `f`.
(You don't need to think in these terms to follow the proof below: it's a giant `calc` block!)
This result proves Weierstrass' theorem that polynomials are dense in `C([0,1], ℝ)`,
although we defer an abstract statement of this until later.
-/
noncomputable section
open scoped BoundedContinuousFunction unitInterval
/-- The Bernstein polynomials, as continuous functions on `[0,1]`.
-/
def bernstein (n ν : ℕ) : C(I, ℝ) :=
(bernsteinPolynomial ℝ n ν).toContinuousMapOn I
@[simp]
theorem bernstein_apply (n ν : ℕ) (x : I) :
bernstein n ν x = (n.choose ν : ℝ) * (x : ℝ) ^ ν * (1 - (x : ℝ)) ^ (n - ν) := by
dsimp [bernstein, Polynomial.toContinuousMapOn, Polynomial.toContinuousMap, bernsteinPolynomial]
simp
|
theorem bernstein_nonneg {n ν : ℕ} {x : I} : 0 ≤ bernstein n ν x := by
simp only [bernstein_apply]
have h₁ : (0 : ℝ) ≤ x := by unit_interval
| Mathlib/Analysis/SpecialFunctions/Bernstein.lean | 61 | 64 |
/-
Copyright (c) 2022 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Topology.MetricSpace.HausdorffDistance
/-!
# Topological study of spaces `Π (n : ℕ), E n`
When `E n` are topological spaces, the space `Π (n : ℕ), E n` is naturally a topological space
(with the product topology). When `E n` are uniform spaces, it also inherits a uniform structure.
However, it does not inherit a canonical metric space structure of the `E n`. Nevertheless, one
can put a noncanonical metric space structure (or rather, several of them). This is done in this
file.
## Main definitions and results
One can define a combinatorial distance on `Π (n : ℕ), E n`, as follows:
* `PiNat.cylinder x n` is the set of points `y` with `x i = y i` for `i < n`.
* `PiNat.firstDiff x y` is the first index at which `x i ≠ y i`.
* `PiNat.dist x y` is equal to `(1/2) ^ (firstDiff x y)`. It defines a distance
on `Π (n : ℕ), E n`, compatible with the topology when the `E n` have the discrete topology.
* `PiNat.metricSpace`: the metric space structure, given by this distance. Not registered as an
instance. This space is a complete metric space.
* `PiNat.metricSpaceOfDiscreteUniformity`: the same metric space structure, but adjusting the
uniformity defeqness when the `E n` already have the discrete uniformity. Not registered as an
instance
* `PiNat.metricSpaceNatNat`: the particular case of `ℕ → ℕ`, not registered as an instance.
These results are used to construct continuous functions on `Π n, E n`:
* `PiNat.exists_retraction_of_isClosed`: given a nonempty closed subset `s` of `Π (n : ℕ), E n`,
there exists a retraction onto `s`, i.e., a continuous map from the whole space to `s`
restricting to the identity on `s`.
* `exists_nat_nat_continuous_surjective_of_completeSpace`: given any nonempty complete metric
space with second-countable topology, there exists a continuous surjection from `ℕ → ℕ` onto
this space.
One can also put distances on `Π (i : ι), E i` when the spaces `E i` are metric spaces (not discrete
in general), and `ι` is countable.
* `PiCountable.dist` is the distance on `Π i, E i` given by
`dist x y = ∑' i, min (1/2)^(encode i) (dist (x i) (y i))`.
* `PiCountable.metricSpace` is the corresponding metric space structure, adjusted so that
the uniformity is definitionally the product uniformity. Not registered as an instance.
-/
noncomputable section
open Topology TopologicalSpace Set Metric Filter Function
attribute [local simp] pow_le_pow_iff_right₀ one_lt_two inv_le_inv₀ zero_le_two zero_lt_two
variable {E : ℕ → Type*}
namespace PiNat
/-! ### The firstDiff function -/
open Classical in
/-- In a product space `Π n, E n`, then `firstDiff x y` is the first index at which `x` and `y`
differ. If `x = y`, then by convention we set `firstDiff x x = 0`. -/
irreducible_def firstDiff (x y : ∀ n, E n) : ℕ :=
if h : x ≠ y then Nat.find (ne_iff.1 h) else 0
theorem apply_firstDiff_ne {x y : ∀ n, E n} (h : x ≠ y) :
x (firstDiff x y) ≠ y (firstDiff x y) := by
rw [firstDiff_def, dif_pos h]
classical
exact Nat.find_spec (ne_iff.1 h)
| theorem apply_eq_of_lt_firstDiff {x y : ∀ n, E n} {n : ℕ} (hn : n < firstDiff x y) : x n = y n := by
rw [firstDiff_def] at hn
split_ifs at hn with h
· convert Nat.find_min (ne_iff.1 h) hn
| Mathlib/Topology/MetricSpace/PiNat.lean | 74 | 77 |
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes, Daniel Weber
-/
import Batteries.Data.Nat.Gcd
import Mathlib.Algebra.GroupWithZero.Associated
import Mathlib.Algebra.Ring.Divisibility.Basic
import Mathlib.Algebra.Ring.Int.Defs
import Mathlib.Data.ENat.Basic
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `emultiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity a b`: a `ℕ`-valued version of `multiplicity`, defaulting for `1` instead of `⊤`.
The reason for using `1` as a default value instead of `0` is to have `multiplicity_eq_zero_iff`.
* `FiniteMultiplicity a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
assert_not_exists Field
variable {α β : Type*}
open Nat
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
abbrev FiniteMultiplicity [Monoid α] (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
@[deprecated (since := "2024-11-30")] alias multiplicity.Finite := FiniteMultiplicity
open scoped Classical in
/-- `emultiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as an `ℕ∞`. If `∀ n, a ^ n ∣ b` then it returns `⊤`. -/
noncomputable def emultiplicity [Monoid α] (a b : α) : ℕ∞ :=
if h : FiniteMultiplicity a b then Nat.find h else ⊤
/-- A `ℕ`-valued version of `emultiplicity`, returning `1` instead of `⊤`. -/
noncomputable def multiplicity [Monoid α] (a b : α) : ℕ :=
(emultiplicity a b).untopD 1
section Monoid
variable [Monoid α] [Monoid β] {a b : α}
@[simp]
theorem emultiplicity_eq_top :
emultiplicity a b = ⊤ ↔ ¬FiniteMultiplicity a b := by
simp [emultiplicity]
theorem emultiplicity_lt_top {a b : α} : emultiplicity a b < ⊤ ↔ FiniteMultiplicity a b := by
simp [lt_top_iff_ne_top, emultiplicity_eq_top]
theorem finiteMultiplicity_iff_emultiplicity_ne_top :
FiniteMultiplicity a b ↔ emultiplicity a b ≠ ⊤ := by simp
@[deprecated (since := "2024-11-30")]
alias finite_iff_emultiplicity_ne_top := finiteMultiplicity_iff_emultiplicity_ne_top
alias ⟨FiniteMultiplicity.emultiplicity_ne_top, _⟩ := finite_iff_emultiplicity_ne_top
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.emultiplicity_ne_top := FiniteMultiplicity.emultiplicity_ne_top
@[deprecated (since := "2024-11-08")]
alias Finite.emultiplicity_ne_top := FiniteMultiplicity.emultiplicity_ne_top
theorem finiteMultiplicity_of_emultiplicity_eq_natCast {n : ℕ} (h : emultiplicity a b = n) :
FiniteMultiplicity a b := by
by_contra! nh
rw [← emultiplicity_eq_top, h] at nh
trivial
@[deprecated (since := "2024-11-30")]
alias finite_of_emultiplicity_eq_natCast := finiteMultiplicity_of_emultiplicity_eq_natCast
theorem multiplicity_eq_of_emultiplicity_eq_some {n : ℕ} (h : emultiplicity a b = n) :
multiplicity a b = n := by
simp [multiplicity, h]
rfl
theorem emultiplicity_ne_of_multiplicity_ne {n : ℕ} :
multiplicity a b ≠ n → emultiplicity a b ≠ n :=
mt multiplicity_eq_of_emultiplicity_eq_some
theorem FiniteMultiplicity.emultiplicity_eq_multiplicity (h : FiniteMultiplicity a b) :
emultiplicity a b = multiplicity a b := by
cases hm : emultiplicity a b
· simp [h] at hm
rw [multiplicity_eq_of_emultiplicity_eq_some hm]
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.emultiplicity_eq_multiplicity :=
FiniteMultiplicity.emultiplicity_eq_multiplicity
theorem FiniteMultiplicity.emultiplicity_eq_iff_multiplicity_eq {n : ℕ}
(h : FiniteMultiplicity a b) : emultiplicity a b = n ↔ multiplicity a b = n := by
simp [h.emultiplicity_eq_multiplicity]
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.emultiplicity_eq_iff_multiplicity_eq :=
FiniteMultiplicity.emultiplicity_eq_iff_multiplicity_eq
theorem emultiplicity_eq_iff_multiplicity_eq_of_ne_one {n : ℕ} (h : n ≠ 1) :
emultiplicity a b = n ↔ multiplicity a b = n := by
constructor
· exact multiplicity_eq_of_emultiplicity_eq_some
· intro h₂
simpa [multiplicity, WithTop.untopD_eq_iff, h] using h₂
theorem emultiplicity_eq_zero_iff_multiplicity_eq_zero :
emultiplicity a b = 0 ↔ multiplicity a b = 0 :=
emultiplicity_eq_iff_multiplicity_eq_of_ne_one zero_ne_one
@[simp]
theorem multiplicity_eq_one_of_not_finiteMultiplicity (h : ¬FiniteMultiplicity a b) :
multiplicity a b = 1 := by
simp [multiplicity, emultiplicity_eq_top.2 h]
| @[deprecated (since := "2024-11-30")]
alias multiplicity_eq_one_of_not_finite :=
multiplicity_eq_one_of_not_finiteMultiplicity
@[simp]
theorem multiplicity_le_emultiplicity :
| Mathlib/RingTheory/Multiplicity.lean | 129 | 134 |
/-
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
theorem rpow_lt_one_of_one_lt_of_neg {x : ℝ≥0} {z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 :=
Real.rpow_lt_one_of_one_lt_of_neg hx hz
theorem rpow_le_one_of_one_le_of_nonpos {x : ℝ≥0} {z : ℝ} (hx : 1 ≤ x) (hz : z ≤ 0) : x ^ z ≤ 1 :=
Real.rpow_le_one_of_one_le_of_nonpos hx hz
theorem one_lt_rpow {x : ℝ≥0} {z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x ^ z :=
Real.one_lt_rpow hx hz
theorem one_le_rpow {x : ℝ≥0} {z : ℝ} (h : 1 ≤ x) (h₁ : 0 ≤ z) : 1 ≤ x ^ z :=
Real.one_le_rpow h h₁
theorem one_lt_rpow_of_pos_of_lt_one_of_neg {x : ℝ≥0} {z : ℝ} (hx1 : 0 < x) (hx2 : x < 1)
(hz : z < 0) : 1 < x ^ z :=
Real.one_lt_rpow_of_pos_of_lt_one_of_neg hx1 hx2 hz
theorem one_le_rpow_of_pos_of_le_one_of_nonpos {x : ℝ≥0} {z : ℝ} (hx1 : 0 < x) (hx2 : x ≤ 1)
(hz : z ≤ 0) : 1 ≤ x ^ z :=
Real.one_le_rpow_of_pos_of_le_one_of_nonpos hx1 hx2 hz
theorem rpow_le_self_of_le_one {x : ℝ≥0} {z : ℝ} (hx : x ≤ 1) (h_one_le : 1 ≤ z) : x ^ z ≤ x := by
rcases eq_bot_or_bot_lt x with (rfl | (h : 0 < x))
· have : z ≠ 0 := by linarith
simp [this]
nth_rw 2 [← NNReal.rpow_one x]
exact NNReal.rpow_le_rpow_of_exponent_ge h hx h_one_le
theorem rpow_left_injective {x : ℝ} (hx : x ≠ 0) : Function.Injective fun y : ℝ≥0 => y ^ x :=
fun y z hyz => by simpa only [rpow_inv_rpow_self hx] using congr_arg (fun y => y ^ (1 / x)) hyz
theorem rpow_eq_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x ^ z = y ^ z ↔ x = y :=
(rpow_left_injective hz).eq_iff
theorem rpow_left_surjective {x : ℝ} (hx : x ≠ 0) : Function.Surjective fun y : ℝ≥0 => y ^ x :=
fun y => ⟨y ^ x⁻¹, by simp_rw [← rpow_mul, inv_mul_cancel₀ hx, rpow_one]⟩
theorem rpow_left_bijective {x : ℝ} (hx : x ≠ 0) : Function.Bijective fun y : ℝ≥0 => y ^ x :=
⟨rpow_left_injective hx, rpow_left_surjective hx⟩
theorem eq_rpow_inv_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x = y ^ z⁻¹ ↔ x ^ z = y := by
rw [← rpow_eq_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz]
theorem rpow_inv_eq_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x ^ z⁻¹ = y ↔ x = y ^ z := by
rw [← rpow_eq_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz]
@[simp] lemma rpow_rpow_inv {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y) ^ y⁻¹ = x := by
rw [← rpow_mul, mul_inv_cancel₀ hy, rpow_one]
@[simp] lemma rpow_inv_rpow {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y⁻¹) ^ y = x := by
rw [← rpow_mul, inv_mul_cancel₀ hy, rpow_one]
theorem pow_rpow_inv_natCast (x : ℝ≥0) {n : ℕ} (hn : n ≠ 0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by
rw [← NNReal.coe_inj, coe_rpow, NNReal.coe_pow]
exact Real.pow_rpow_inv_natCast x.2 hn
theorem rpow_inv_natCast_pow (x : ℝ≥0) {n : ℕ} (hn : n ≠ 0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by
rw [← NNReal.coe_inj, NNReal.coe_pow, coe_rpow]
exact Real.rpow_inv_natCast_pow x.2 hn
theorem _root_.Real.toNNReal_rpow_of_nonneg {x y : ℝ} (hx : 0 ≤ x) :
Real.toNNReal (x ^ y) = Real.toNNReal x ^ y := by
nth_rw 1 [← Real.coe_toNNReal x hx]
rw [← NNReal.coe_rpow, Real.toNNReal_coe]
theorem strictMono_rpow_of_pos {z : ℝ} (h : 0 < z) : StrictMono fun x : ℝ≥0 => x ^ z :=
fun x y hxy => by simp only [NNReal.rpow_lt_rpow hxy h, coe_lt_coe]
theorem monotone_rpow_of_nonneg {z : ℝ} (h : 0 ≤ z) : Monotone fun x : ℝ≥0 => x ^ z :=
h.eq_or_lt.elim (fun h0 => h0 ▸ by simp only [rpow_zero, monotone_const]) fun h0 =>
(strictMono_rpow_of_pos h0).monotone
/-- Bundles `fun x : ℝ≥0 => x ^ y` into an order isomorphism when `y : ℝ` is positive,
where the inverse is `fun x : ℝ≥0 => x ^ (1 / y)`. -/
@[simps! apply]
def orderIsoRpow (y : ℝ) (hy : 0 < y) : ℝ≥0 ≃o ℝ≥0 :=
(strictMono_rpow_of_pos hy).orderIsoOfRightInverse (fun x => x ^ y) (fun x => x ^ (1 / y))
fun x => by
dsimp
rw [← rpow_mul, one_div_mul_cancel hy.ne.symm, rpow_one]
theorem orderIsoRpow_symm_eq (y : ℝ) (hy : 0 < y) :
(orderIsoRpow y hy).symm = orderIsoRpow (1 / y) (one_div_pos.2 hy) := by
simp only [orderIsoRpow, one_div_one_div]; rfl
theorem _root_.Real.nnnorm_rpow_of_nonneg {x y : ℝ} (hx : 0 ≤ x) : ‖x ^ y‖₊ = ‖x‖₊ ^ y := by
ext; exact Real.norm_rpow_of_nonneg hx
end NNReal
namespace ENNReal
/-- The real power function `x^y` on extended nonnegative reals, defined for `x : ℝ≥0∞` and
`y : ℝ` as the restriction of the real power function if `0 < x < ⊤`, and with the natural values
for `0` and `⊤` (i.e., `0 ^ x = 0` for `x > 0`, `1` for `x = 0` and `⊤` for `x < 0`, and
`⊤ ^ x = 1 / 0 ^ x`). -/
noncomputable def rpow : ℝ≥0∞ → ℝ → ℝ≥0∞
| some x, y => if x = 0 ∧ y < 0 then ⊤ else (x ^ y : ℝ≥0)
| none, y => if 0 < y then ⊤ else if y = 0 then 1 else 0
noncomputable instance : Pow ℝ≥0∞ ℝ :=
⟨rpow⟩
@[simp]
theorem rpow_eq_pow (x : ℝ≥0∞) (y : ℝ) : rpow x y = x ^ y :=
rfl
@[simp]
theorem rpow_zero {x : ℝ≥0∞} : x ^ (0 : ℝ) = 1 := by
cases x <;>
· dsimp only [(· ^ ·), Pow.pow, rpow]
simp [lt_irrefl]
theorem top_rpow_def (y : ℝ) : (⊤ : ℝ≥0∞) ^ y = if 0 < y then ⊤ else if y = 0 then 1 else 0 :=
rfl
@[simp]
theorem top_rpow_of_pos {y : ℝ} (h : 0 < y) : (⊤ : ℝ≥0∞) ^ y = ⊤ := by simp [top_rpow_def, h]
@[simp]
theorem top_rpow_of_neg {y : ℝ} (h : y < 0) : (⊤ : ℝ≥0∞) ^ y = 0 := by
simp [top_rpow_def, asymm h, ne_of_lt h]
@[simp]
theorem zero_rpow_of_pos {y : ℝ} (h : 0 < y) : (0 : ℝ≥0∞) ^ y = 0 := by
rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe]
dsimp only [(· ^ ·), rpow, Pow.pow]
simp [h, asymm h, ne_of_gt h]
@[simp]
theorem zero_rpow_of_neg {y : ℝ} (h : y < 0) : (0 : ℝ≥0∞) ^ y = ⊤ := by
rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe]
dsimp only [(· ^ ·), rpow, Pow.pow]
simp [h, ne_of_gt h]
theorem zero_rpow_def (y : ℝ) : (0 : ℝ≥0∞) ^ y = if 0 < y then 0 else if y = 0 then 1 else ⊤ := by
rcases lt_trichotomy (0 : ℝ) y with (H | rfl | H)
· simp [H, ne_of_gt, zero_rpow_of_pos, lt_irrefl]
· simp [lt_irrefl]
· simp [H, asymm H, ne_of_lt, zero_rpow_of_neg]
@[simp]
theorem zero_rpow_mul_self (y : ℝ) : (0 : ℝ≥0∞) ^ y * (0 : ℝ≥0∞) ^ y = (0 : ℝ≥0∞) ^ y := by
rw [zero_rpow_def]
split_ifs
exacts [zero_mul _, one_mul _, top_mul_top]
@[norm_cast]
theorem coe_rpow_of_ne_zero {x : ℝ≥0} (h : x ≠ 0) (y : ℝ) : (↑(x ^ y) : ℝ≥0∞) = x ^ y := by
rw [← ENNReal.some_eq_coe]
dsimp only [(· ^ ·), Pow.pow, rpow]
simp [h]
@[norm_cast]
theorem coe_rpow_of_nonneg (x : ℝ≥0) {y : ℝ} (h : 0 ≤ y) : ↑(x ^ y) = (x : ℝ≥0∞) ^ y := by
by_cases hx : x = 0
· rcases le_iff_eq_or_lt.1 h with (H | H)
· simp [hx, H.symm]
· simp [hx, zero_rpow_of_pos H, NNReal.zero_rpow (ne_of_gt H)]
· exact coe_rpow_of_ne_zero hx _
theorem coe_rpow_def (x : ℝ≥0) (y : ℝ) :
(x : ℝ≥0∞) ^ y = if x = 0 ∧ y < 0 then ⊤ else ↑(x ^ y) :=
rfl
theorem rpow_ofNNReal {M : ℝ≥0} {P : ℝ} (hP : 0 ≤ P) : (M : ℝ≥0∞) ^ P = ↑(M ^ P) := by
rw [ENNReal.coe_rpow_of_nonneg _ hP, ← ENNReal.rpow_eq_pow]
@[simp]
theorem rpow_one (x : ℝ≥0∞) : x ^ (1 : ℝ) = x := by
cases x
· exact dif_pos zero_lt_one
· change ite _ _ _ = _
simp only [NNReal.rpow_one, some_eq_coe, ite_eq_right_iff, top_ne_coe, and_imp]
exact fun _ => zero_le_one.not_lt
@[simp]
theorem one_rpow (x : ℝ) : (1 : ℝ≥0∞) ^ x = 1 := by
rw [← coe_one, ← coe_rpow_of_ne_zero one_ne_zero]
simp
@[simp]
theorem rpow_eq_zero_iff {x : ℝ≥0∞} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ 0 < y ∨ x = ⊤ ∧ y < 0 := by
cases x with
| top =>
rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt]
| coe x =>
by_cases h : x = 0
· rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt]
· simp [← coe_rpow_of_ne_zero h, h]
lemma rpow_eq_zero_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y = 0 ↔ x = 0 := by
simp [hy, hy.not_lt]
@[simp]
theorem rpow_eq_top_iff {x : ℝ≥0∞} {y : ℝ} : x ^ y = ⊤ ↔ x = 0 ∧ y < 0 ∨ x = ⊤ ∧ 0 < y := by
cases x with
| top =>
rcases lt_trichotomy y 0 with (H | H | H) <;>
| simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt]
| coe x =>
by_cases h : x = 0
· rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt]
· simp [← coe_rpow_of_ne_zero h, h]
theorem rpow_eq_top_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y = ⊤ ↔ x = ⊤ := by
simp [rpow_eq_top_iff, hy, asymm hy]
| Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean | 543 | 551 |
/-
Copyright (c) 2022 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import Mathlib.Data.List.Induction
import Mathlib.Data.List.TakeWhile
/-!
# Dropping or taking from lists on the right
Taking or removing element from the tail end of a list
## Main definitions
- `rdrop n`: drop `n : ℕ` elements from the tail
- `rtake n`: take `n : ℕ` elements from the tail
- `rdropWhile p`: remove all the elements from the tail of a list until it finds the first element
for which `p : α → Bool` returns false. This element and everything before is returned.
- `rtakeWhile p`: Returns the longest terminal segment of a list for which `p : α → Bool` returns
true.
## Implementation detail
The two predicate-based methods operate by performing the regular "from-left" operation on
`List.reverse`, followed by another `List.reverse`, so they are not the most performant.
The other two rely on `List.length l` so they still traverse the list twice. One could construct
another function that takes a `L : ℕ` and use `L - n`. Under a proof condition that
`L = l.length`, the function would do the right thing.
-/
-- Make sure we don't import algebra
assert_not_exists Monoid
variable {α : Type*} (p : α → Bool) (l : List α) (n : ℕ)
namespace List
/-- Drop `n` elements from the tail end of a list. -/
def rdrop : List α :=
l.take (l.length - n)
@[simp]
theorem rdrop_nil : rdrop ([] : List α) n = [] := by simp [rdrop]
@[simp]
theorem rdrop_zero : rdrop l 0 = l := by simp [rdrop]
theorem rdrop_eq_reverse_drop_reverse : l.rdrop n = reverse (l.reverse.drop n) := by
rw [rdrop]
induction' l using List.reverseRecOn with xs x IH generalizing n
· simp
· cases n
· simp [take_append]
· simp [take_append_eq_append_take, IH]
@[simp]
theorem rdrop_concat_succ (x : α) : rdrop (l ++ [x]) (n + 1) = rdrop l n := by
simp [rdrop_eq_reverse_drop_reverse]
/-- Take `n` elements from the tail end of a list. -/
def rtake : List α :=
l.drop (l.length - n)
@[simp]
theorem rtake_nil : rtake ([] : List α) n = [] := by simp [rtake]
@[simp]
theorem rtake_zero : rtake l 0 = [] := by simp [rtake]
theorem rtake_eq_reverse_take_reverse : l.rtake n = reverse (l.reverse.take n) := by
rw [rtake]
induction' l using List.reverseRecOn with xs x IH generalizing n
· simp
· cases n
· exact drop_length
· simp [drop_append_eq_append_drop, IH]
@[simp]
theorem rtake_concat_succ (x : α) : rtake (l ++ [x]) (n + 1) = rtake l n ++ [x] := by
simp [rtake_eq_reverse_take_reverse]
/-- Drop elements from the tail end of a list that satisfy `p : α → Bool`.
Implemented naively via `List.reverse` -/
def rdropWhile : List α :=
reverse (l.reverse.dropWhile p)
@[simp]
theorem rdropWhile_nil : rdropWhile p ([] : List α) = [] := by simp [rdropWhile, dropWhile]
theorem rdropWhile_concat (x : α) :
rdropWhile p (l ++ [x]) = if p x then rdropWhile p l else l ++ [x] := by
simp only [rdropWhile, dropWhile, reverse_append, reverse_singleton, singleton_append]
split_ifs with h <;> simp [h]
@[simp]
theorem rdropWhile_concat_pos (x : α) (h : p x) : rdropWhile p (l ++ [x]) = rdropWhile p l := by
rw [rdropWhile_concat, if_pos h]
@[simp]
theorem rdropWhile_concat_neg (x : α) (h : ¬p x) : rdropWhile p (l ++ [x]) = l ++ [x] := by
rw [rdropWhile_concat, if_neg h]
|
theorem rdropWhile_singleton (x : α) : rdropWhile p [x] = if p x then [] else [x] := by
rw [← nil_append [x], rdropWhile_concat, rdropWhile_nil]
| Mathlib/Data/List/DropRight.lean | 105 | 108 |
/-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.Order.Ring.Nat
import Mathlib.Data.List.Chain
/-!
# List of booleans
In this file we prove lemmas about the number of `false`s and `true`s in a list of booleans. First
we prove that the number of `false`s plus the number of `true` equals the length of the list. Then
we prove that in a list with alternating `true`s and `false`s, the number of `true`s differs from
the number of `false`s by at most one. We provide several versions of these statements.
-/
namespace List
@[simp]
theorem count_not_add_count (l : List Bool) (b : Bool) : count (!b) l + count b l = length l := by
have := length_eq_countP_add_countP (l := l) (· == !b)
aesop (add simp this)
@[simp]
theorem count_add_count_not (l : List Bool) (b : Bool) : count b l + count (!b) l = length l := by
rw [add_comm, count_not_add_count]
@[simp]
theorem count_false_add_count_true (l : List Bool) : count false l + count true l = length l :=
count_not_add_count l true
@[simp]
theorem count_true_add_count_false (l : List Bool) : count true l + count false l = length l :=
count_not_add_count l false
theorem Chain.count_not :
∀ {b : Bool} {l : List Bool}, Chain (· ≠ ·) b l → count (!b) l = count b l + length l % 2
| _, [], _h => rfl
| b, x :: l, h => by
obtain rfl : b = !x := Bool.eq_not_iff.2 (rel_of_chain_cons h)
rw [Bool.not_not, count_cons_self, count_cons_of_ne x.not_ne_self.symm,
Chain.count_not (chain_of_chain_cons h), length, add_assoc, Nat.mod_two_add_succ_mod_two]
namespace Chain'
variable {l : List Bool}
theorem count_not_eq_count (hl : Chain' (· ≠ ·) l) (h2 : Even (length l)) (b : Bool) :
count (!b) l = count b l := by
rcases l with - | ⟨x, l⟩
· rfl
rw [length_cons, Nat.even_add_one, Nat.not_even_iff] at h2
suffices count (!x) (x :: l) = count x (x :: l) by
cases b <;> cases x <;> (try exact this) <;> exact this.symm
rw [count_cons_of_ne x.not_ne_self.symm, hl.count_not, h2, count_cons_self]
theorem count_false_eq_count_true (hl : Chain' (· ≠ ·) l) (h2 : Even (length l)) :
count false l = count true l :=
hl.count_not_eq_count h2 true
theorem count_not_le_count_add_one (hl : Chain' (· ≠ ·) l) (b : Bool) :
count (!b) l ≤ count b l + 1 := by
rcases l with - | ⟨x, l⟩
· exact zero_le _
obtain rfl | rfl : b = x ∨ b = !x := by simp only [Bool.eq_not_iff, em]
· rw [count_cons_of_ne b.not_ne_self.symm, count_cons_self, hl.count_not, add_assoc]
exact add_le_add_left (Nat.mod_lt _ two_pos).le _
· rw [Bool.not_not, count_cons_self, count_cons_of_ne x.not_ne_self.symm, hl.count_not]
exact add_le_add_right (le_add_right le_rfl) _
theorem count_false_le_count_true_add_one (hl : Chain' (· ≠ ·) l) :
count false l ≤ count true l + 1 :=
hl.count_not_le_count_add_one true
theorem count_true_le_count_false_add_one (hl : Chain' (· ≠ ·) l) :
count true l ≤ count false l + 1 :=
| hl.count_not_le_count_add_one false
theorem two_mul_count_bool_of_even (hl : Chain' (· ≠ ·) l) (h2 : Even (length l)) (b : Bool) :
2 * count b l = length l := by
rw [← count_not_add_count l b, hl.count_not_eq_count h2, two_mul]
theorem two_mul_count_bool_eq_ite (hl : Chain' (· ≠ ·) l) (b : Bool) :
2 * count b l =
if Even (length l) then length l else
| Mathlib/Data/Bool/Count.lean | 79 | 87 |
/-
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.NumberTheory.EulerProduct.ExpLog
import Mathlib.NumberTheory.LSeries.Dirichlet
/-!
# The Euler Product for the Riemann Zeta Function and Dirichlet L-Series
The first main result of this file is the Euler Product formula for the Riemann ζ function
$$\prod_p \frac{1}{1 - p^{-s}}
= \lim_{n \to \infty} \prod_{p < n} \frac{1}{1 - p^{-s}} = \zeta(s)$$
for $s$ with real part $> 1$ ($p$ runs through the primes).
`riemannZeta_eulerProduct` is the second equality above. There are versions
`riemannZeta_eulerProduct_hasProd` and `riemannZeta_eulerProduct_tprod` in terms of `HasProd`
and `tprod`, respectively.
The second result is `dirichletLSeries_eulerProduct` (with variants
`dirichletLSeries_eulerProduct_hasProd` and `dirichletLSeries_eulerProduct_tprod`),
which is the analogous statement for Dirichlet L-series.
-/
open Complex
variable {s : ℂ}
/-- When `s ≠ 0`, the map `n ↦ n^(-s)` is completely multiplicative and vanishes at zero. -/
noncomputable
def riemannZetaSummandHom (hs : s ≠ 0) : ℕ →*₀ ℂ where
toFun n := (n : ℂ) ^ (-s)
map_zero' := by simp [hs]
map_one' := by simp
map_mul' m n := by
simpa only [Nat.cast_mul, ofReal_natCast]
using mul_cpow_ofReal_nonneg m.cast_nonneg n.cast_nonneg _
/-- When `χ` is a Dirichlet character and `s ≠ 0`, the map `n ↦ χ n * n^(-s)` is completely
multiplicative and vanishes at zero. -/
noncomputable
def dirichletSummandHom {n : ℕ} (χ : DirichletCharacter ℂ n) (hs : s ≠ 0) : ℕ →*₀ ℂ where
toFun n := χ n * (n : ℂ) ^ (-s)
map_zero' := by simp [hs]
map_one' := by simp
map_mul' m n := by
simp_rw [← ofReal_natCast]
simpa only [Nat.cast_mul, IsUnit.mul_iff, not_and, map_mul, ofReal_mul,
mul_cpow_ofReal_nonneg m.cast_nonneg n.cast_nonneg _]
using mul_mul_mul_comm ..
/-- When `s.re > 1`, the map `n ↦ n^(-s)` is norm-summable. -/
lemma summable_riemannZetaSummand (hs : 1 < s.re) :
Summable (fun n ↦ ‖riemannZetaSummandHom (ne_zero_of_one_lt_re hs) n‖) := by
simp only [riemannZetaSummandHom, MonoidWithZeroHom.coe_mk, ZeroHom.coe_mk]
convert Real.summable_nat_rpow_inv.mpr hs with n
rw [← ofReal_natCast,
norm_cpow_eq_rpow_re_of_nonneg (Nat.cast_nonneg n) <| re_neg_ne_zero_of_one_lt_re hs,
neg_re, Real.rpow_neg <| Nat.cast_nonneg n]
lemma tsum_riemannZetaSummand (hs : 1 < s.re) :
∑' (n : ℕ), riemannZetaSummandHom (ne_zero_of_one_lt_re hs) n = riemannZeta s := by
have hsum := summable_riemannZetaSummand hs
rw [zeta_eq_tsum_one_div_nat_add_one_cpow hs, hsum.of_norm.tsum_eq_zero_add, map_zero, zero_add]
simp only [riemannZetaSummandHom, cpow_neg, MonoidWithZeroHom.coe_mk, ZeroHom.coe_mk,
Nat.cast_add, Nat.cast_one, one_div]
/-- When `s.re > 1`, the map `n ↦ χ(n) * n^(-s)` is norm-summable. -/
lemma summable_dirichletSummand {N : ℕ} (χ : DirichletCharacter ℂ N) (hs : 1 < s.re) :
Summable (fun n ↦ ‖dirichletSummandHom χ (ne_zero_of_one_lt_re hs) n‖) := by
simp only [dirichletSummandHom, MonoidWithZeroHom.coe_mk, ZeroHom.coe_mk, norm_mul]
exact (summable_riemannZetaSummand hs).of_nonneg_of_le (fun _ ↦ by positivity)
(fun n ↦ mul_le_of_le_one_left (norm_nonneg _) <| χ.norm_le_one n)
open scoped LSeries.notation in
lemma tsum_dirichletSummand {N : ℕ} (χ : DirichletCharacter ℂ N) (hs : 1 < s.re) :
∑' (n : ℕ), dirichletSummandHom χ (ne_zero_of_one_lt_re hs) n = L ↗χ s := by
simp only [dirichletSummandHom, cpow_neg, MonoidWithZeroHom.coe_mk, ZeroHom.coe_mk, LSeries,
LSeries.term_of_ne_zero' (ne_zero_of_one_lt_re hs), div_eq_mul_inv]
open Filter Nat Topology EulerProduct
/-- The Euler product for the Riemann ζ function, valid for `s.re > 1`.
This version is stated in terms of `HasProd`. -/
theorem riemannZeta_eulerProduct_hasProd (hs : 1 < s.re) :
HasProd (fun p : Primes ↦ (1 - (p : ℂ) ^ (-s))⁻¹) (riemannZeta s) := by
rw [← tsum_riemannZetaSummand hs]
apply eulerProduct_completely_multiplicative_hasProd <| summable_riemannZetaSummand hs
/-- The Euler product for the Riemann ζ function, valid for `s.re > 1`.
| This version is stated in terms of `tprod`. -/
theorem riemannZeta_eulerProduct_tprod (hs : 1 < s.re) :
∏' p : Primes, (1 - (p : ℂ) ^ (-s))⁻¹ = riemannZeta s :=
(riemannZeta_eulerProduct_hasProd hs).tprod_eq
| Mathlib/NumberTheory/EulerProduct/DirichletLSeries.lean | 91 | 94 |
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov, Heather Macbeth
-/
import Mathlib.MeasureTheory.Function.SimpleFunc
import Mathlib.MeasureTheory.Constructions.BorelSpace.Metrizable
/-!
# Density of simple functions
Show that each Borel measurable function can be approximated pointwise
by a sequence of simple functions.
## Main definitions
* `MeasureTheory.SimpleFunc.nearestPt (e : ℕ → α) (N : ℕ) : α →ₛ ℕ`: the `SimpleFunc` sending
each `x : α` to the point `e k` which is the nearest to `x` among `e 0`, ..., `e N`.
* `MeasureTheory.SimpleFunc.approxOn (f : β → α) (hf : Measurable f) (s : Set α) (y₀ : α)
(h₀ : y₀ ∈ s) [SeparableSpace s] (n : ℕ) : β →ₛ α` : a simple function that takes values in `s`
and approximates `f`.
## Main results
* `tendsto_approxOn` (pointwise convergence): If `f x ∈ s`, then the sequence of simple
approximations `MeasureTheory.SimpleFunc.approxOn f hf s y₀ h₀ n`, evaluated at `x`,
tends to `f x` as `n` tends to `∞`.
## Notations
* `α →ₛ β` (local notation): the type of simple functions `α → β`.
-/
open Set Function Filter TopologicalSpace ENNReal EMetric Finset
open Topology ENNReal MeasureTheory
variable {α β ι E F 𝕜 : Type*}
noncomputable section
namespace MeasureTheory
local infixr:25 " →ₛ " => SimpleFunc
namespace SimpleFunc
/-! ### Pointwise approximation by simple functions -/
variable [MeasurableSpace α] [PseudoEMetricSpace α] [OpensMeasurableSpace α]
/-- `nearestPtInd e N x` is the index `k` such that `e k` is the nearest point to `x` among the
points `e 0`, ..., `e N`. If more than one point are at the same distance from `x`, then
`nearestPtInd e N x` returns the least of their indexes. -/
noncomputable def nearestPtInd (e : ℕ → α) : ℕ → α →ₛ ℕ
| 0 => const α 0
| N + 1 =>
piecewise (⋂ k ≤ N, { x | edist (e (N + 1)) x < edist (e k) x })
(MeasurableSet.iInter fun _ =>
MeasurableSet.iInter fun _ =>
measurableSet_lt measurable_edist_right measurable_edist_right)
(const α <| N + 1) (nearestPtInd e N)
/-- `nearestPt e N x` is the nearest point to `x` among the points `e 0`, ..., `e N`. If more than
one point are at the same distance from `x`, then `nearestPt e N x` returns the point with the
least possible index. -/
noncomputable def nearestPt (e : ℕ → α) (N : ℕ) : α →ₛ α :=
(nearestPtInd e N).map e
@[simp]
theorem nearestPtInd_zero (e : ℕ → α) : nearestPtInd e 0 = const α 0 :=
rfl
@[simp]
theorem nearestPt_zero (e : ℕ → α) : nearestPt e 0 = const α (e 0) :=
rfl
theorem nearestPtInd_succ (e : ℕ → α) (N : ℕ) (x : α) :
nearestPtInd e (N + 1) x =
if ∀ k ≤ N, edist (e (N + 1)) x < edist (e k) x then N + 1 else nearestPtInd e N x := by
simp only [nearestPtInd, coe_piecewise, Set.piecewise]
congr
simp
theorem nearestPtInd_le (e : ℕ → α) (N : ℕ) (x : α) : nearestPtInd e N x ≤ N := by
induction' N with N ihN; · simp
simp only [nearestPtInd_succ]
split_ifs
exacts [le_rfl, ihN.trans N.le_succ]
theorem edist_nearestPt_le (e : ℕ → α) (x : α) {k N : ℕ} (hk : k ≤ N) :
edist (nearestPt e N x) x ≤ edist (e k) x := by
induction' N with N ihN generalizing k
· simp [nonpos_iff_eq_zero.1 hk, le_refl]
· simp only [nearestPt, nearestPtInd_succ, map_apply]
split_ifs with h
· rcases hk.eq_or_lt with (rfl | hk)
exacts [le_rfl, (h k (Nat.lt_succ_iff.1 hk)).le]
· push_neg at h
| rcases h with ⟨l, hlN, hxl⟩
rcases hk.eq_or_lt with (rfl | hk)
exacts [(ihN hlN).trans hxl, ihN (Nat.lt_succ_iff.1 hk)]
theorem tendsto_nearestPt {e : ℕ → α} {x : α} (hx : x ∈ closure (range e)) :
Tendsto (fun N => nearestPt e N x) atTop (𝓝 x) := by
refine (atTop_basis.tendsto_iff nhds_basis_eball).2 fun ε hε => ?_
rcases EMetric.mem_closure_iff.1 hx ε hε with ⟨_, ⟨N, rfl⟩, hN⟩
rw [edist_comm] at hN
exact ⟨N, trivial, fun n hn => (edist_nearestPt_le e x hn).trans_lt hN⟩
variable [MeasurableSpace β] {f : β → α}
| Mathlib/MeasureTheory/Function/SimpleFuncDense.lean | 102 | 113 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Ring.Associated
import Mathlib.Algebra.Star.Unitary
import Mathlib.RingTheory.PrincipalIdealDomain
import Mathlib.Tactic.Ring
import Mathlib.Algebra.EuclideanDomain.Int
/-! # ℤ[√d]
The ring of integers adjoined with a square root of `d : ℤ`.
After defining the norm, we show that it is a linearly ordered commutative ring,
as well as an integral domain.
We provide the universal property, that ring homomorphisms `ℤ√d →+* R` correspond
to choices of square roots of `d` in `R`.
-/
/-- The ring of integers adjoined with a square root of `d`.
These have the form `a + b √d` where `a b : ℤ`. The components
are called `re` and `im` by analogy to the negative `d` case. -/
@[ext]
structure Zsqrtd (d : ℤ) where
/-- Component of the integer not multiplied by `√d` -/
re : ℤ
/-- Component of the integer multiplied by `√d` -/
im : ℤ
deriving DecidableEq
@[inherit_doc] prefix:100 "ℤ√" => Zsqrtd
namespace Zsqrtd
section
variable {d : ℤ}
/-- Convert an integer to a `ℤ√d` -/
def ofInt (n : ℤ) : ℤ√d :=
⟨n, 0⟩
theorem ofInt_re (n : ℤ) : (ofInt n : ℤ√d).re = n :=
rfl
theorem ofInt_im (n : ℤ) : (ofInt n : ℤ√d).im = 0 :=
rfl
/-- The zero of the ring -/
instance : Zero (ℤ√d) :=
⟨ofInt 0⟩
@[simp]
theorem zero_re : (0 : ℤ√d).re = 0 :=
rfl
@[simp]
theorem zero_im : (0 : ℤ√d).im = 0 :=
rfl
instance : Inhabited (ℤ√d) :=
⟨0⟩
/-- The one of the ring -/
instance : One (ℤ√d) :=
⟨ofInt 1⟩
@[simp]
theorem one_re : (1 : ℤ√d).re = 1 :=
rfl
@[simp]
theorem one_im : (1 : ℤ√d).im = 0 :=
rfl
/-- The representative of `√d` in the ring -/
def sqrtd : ℤ√d :=
⟨0, 1⟩
@[simp]
theorem sqrtd_re : (sqrtd : ℤ√d).re = 0 :=
rfl
@[simp]
theorem sqrtd_im : (sqrtd : ℤ√d).im = 1 :=
rfl
/-- Addition of elements of `ℤ√d` -/
instance : Add (ℤ√d) :=
⟨fun z w => ⟨z.1 + w.1, z.2 + w.2⟩⟩
@[simp]
theorem add_def (x y x' y' : ℤ) : (⟨x, y⟩ + ⟨x', y'⟩ : ℤ√d) = ⟨x + x', y + y'⟩ :=
rfl
@[simp]
theorem add_re (z w : ℤ√d) : (z + w).re = z.re + w.re :=
rfl
@[simp]
theorem add_im (z w : ℤ√d) : (z + w).im = z.im + w.im :=
rfl
/-- Negation in `ℤ√d` -/
instance : Neg (ℤ√d) :=
⟨fun z => ⟨-z.1, -z.2⟩⟩
@[simp]
theorem neg_re (z : ℤ√d) : (-z).re = -z.re :=
rfl
@[simp]
theorem neg_im (z : ℤ√d) : (-z).im = -z.im :=
rfl
/-- Multiplication in `ℤ√d` -/
instance : Mul (ℤ√d) :=
⟨fun z w => ⟨z.1 * w.1 + d * z.2 * w.2, z.1 * w.2 + z.2 * w.1⟩⟩
@[simp]
theorem mul_re (z w : ℤ√d) : (z * w).re = z.re * w.re + d * z.im * w.im :=
rfl
@[simp]
theorem mul_im (z w : ℤ√d) : (z * w).im = z.re * w.im + z.im * w.re :=
rfl
instance addCommGroup : AddCommGroup (ℤ√d) := by
refine
{ add := (· + ·)
zero := (0 : ℤ√d)
sub := fun a b => a + -b
neg := Neg.neg
nsmul := @nsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩
zsmul := @zsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩ ⟨Neg.neg⟩ (@nsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩)
add_assoc := ?_
zero_add := ?_
add_zero := ?_
neg_add_cancel := ?_
add_comm := ?_ } <;>
intros <;>
ext <;>
simp [add_comm, add_left_comm]
@[simp]
theorem sub_re (z w : ℤ√d) : (z - w).re = z.re - w.re :=
rfl
@[simp]
theorem sub_im (z w : ℤ√d) : (z - w).im = z.im - w.im :=
rfl
instance addGroupWithOne : AddGroupWithOne (ℤ√d) :=
{ Zsqrtd.addCommGroup with
natCast := fun n => ofInt n
intCast := ofInt
one := 1 }
instance commRing : CommRing (ℤ√d) := by
refine
{ Zsqrtd.addGroupWithOne with
mul := (· * ·)
npow := @npowRec (ℤ√d) ⟨1⟩ ⟨(· * ·)⟩,
add_comm := ?_
left_distrib := ?_
right_distrib := ?_
zero_mul := ?_
mul_zero := ?_
mul_assoc := ?_
one_mul := ?_
mul_one := ?_
mul_comm := ?_ } <;>
intros <;>
ext <;>
simp <;>
ring
instance : AddMonoid (ℤ√d) := by infer_instance
instance : Monoid (ℤ√d) := by infer_instance
instance : CommMonoid (ℤ√d) := by infer_instance
instance : CommSemigroup (ℤ√d) := by infer_instance
instance : Semigroup (ℤ√d) := by infer_instance
instance : AddCommSemigroup (ℤ√d) := by infer_instance
instance : AddSemigroup (ℤ√d) := by infer_instance
instance : CommSemiring (ℤ√d) := by infer_instance
instance : Semiring (ℤ√d) := by infer_instance
instance : Ring (ℤ√d) := by infer_instance
instance : Distrib (ℤ√d) := by infer_instance
/-- Conjugation in `ℤ√d`. The conjugate of `a + b √d` is `a - b √d`. -/
instance : Star (ℤ√d) where
star z := ⟨z.1, -z.2⟩
@[simp]
theorem star_mk (x y : ℤ) : star (⟨x, y⟩ : ℤ√d) = ⟨x, -y⟩ :=
rfl
@[simp]
theorem star_re (z : ℤ√d) : (star z).re = z.re :=
rfl
@[simp]
theorem star_im (z : ℤ√d) : (star z).im = -z.im :=
rfl
instance : StarRing (ℤ√d) where
star_involutive _ := Zsqrtd.ext rfl (neg_neg _)
star_mul a b := by ext <;> simp <;> ring
star_add _ _ := Zsqrtd.ext rfl (neg_add _ _)
-- Porting note: proof was `by decide`
instance nontrivial : Nontrivial (ℤ√d) :=
⟨⟨0, 1, Zsqrtd.ext_iff.not.mpr (by simp)⟩⟩
@[simp]
theorem natCast_re (n : ℕ) : (n : ℤ√d).re = n :=
rfl
@[simp]
theorem ofNat_re (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℤ√d).re = n :=
rfl
@[simp]
theorem natCast_im (n : ℕ) : (n : ℤ√d).im = 0 :=
rfl
@[simp]
theorem ofNat_im (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℤ√d).im = 0 :=
rfl
theorem natCast_val (n : ℕ) : (n : ℤ√d) = ⟨n, 0⟩ :=
rfl
@[simp]
theorem intCast_re (n : ℤ) : (n : ℤ√d).re = n := by cases n <;> rfl
@[simp]
theorem intCast_im (n : ℤ) : (n : ℤ√d).im = 0 := by cases n <;> rfl
theorem intCast_val (n : ℤ) : (n : ℤ√d) = ⟨n, 0⟩ := by ext <;> simp
instance : CharZero (ℤ√d) where cast_injective m n := by simp [Zsqrtd.ext_iff]
@[simp]
theorem ofInt_eq_intCast (n : ℤ) : (ofInt n : ℤ√d) = n := by ext <;> simp [ofInt_re, ofInt_im]
@[simp]
theorem nsmul_val (n : ℕ) (x y : ℤ) : (n : ℤ√d) * ⟨x, y⟩ = ⟨n * x, n * y⟩ := by ext <;> simp
@[simp]
theorem smul_val (n x y : ℤ) : (n : ℤ√d) * ⟨x, y⟩ = ⟨n * x, n * y⟩ := by ext <;> simp
theorem smul_re (a : ℤ) (b : ℤ√d) : (↑a * b).re = a * b.re := by simp
theorem smul_im (a : ℤ) (b : ℤ√d) : (↑a * b).im = a * b.im := by simp
@[simp]
theorem muld_val (x y : ℤ) : sqrtd (d := d) * ⟨x, y⟩ = ⟨d * y, x⟩ := by ext <;> simp
@[simp]
theorem dmuld : sqrtd (d := d) * sqrtd (d := d) = d := by ext <;> simp
@[simp]
theorem smuld_val (n x y : ℤ) : sqrtd * (n : ℤ√d) * ⟨x, y⟩ = ⟨d * n * y, n * x⟩ := by ext <;> simp
theorem decompose {x y : ℤ} : (⟨x, y⟩ : ℤ√d) = x + sqrtd (d := d) * y := by ext <;> simp
theorem mul_star {x y : ℤ} : (⟨x, y⟩ * star ⟨x, y⟩ : ℤ√d) = x * x - d * y * y := by
ext <;> simp [sub_eq_add_neg, mul_comm]
theorem intCast_dvd (z : ℤ) (a : ℤ√d) : ↑z ∣ a ↔ z ∣ a.re ∧ z ∣ a.im := by
constructor
· rintro ⟨x, rfl⟩
simp only [add_zero, intCast_re, zero_mul, mul_im, dvd_mul_right, and_self_iff,
mul_re, mul_zero, intCast_im]
· rintro ⟨⟨r, hr⟩, ⟨i, hi⟩⟩
use ⟨r, i⟩
rw [smul_val, Zsqrtd.ext_iff]
exact ⟨hr, hi⟩
@[simp, norm_cast]
theorem intCast_dvd_intCast (a b : ℤ) : (a : ℤ√d) ∣ b ↔ a ∣ b := by
rw [intCast_dvd]
constructor
· rintro ⟨hre, -⟩
rwa [intCast_re] at hre
· rw [intCast_re, intCast_im]
exact fun hc => ⟨hc, dvd_zero a⟩
protected theorem eq_of_smul_eq_smul_left {a : ℤ} {b c : ℤ√d} (ha : a ≠ 0) (h : ↑a * b = a * c) :
b = c := by
rw [Zsqrtd.ext_iff] at h ⊢
apply And.imp _ _ h <;> simpa only [smul_re, smul_im] using mul_left_cancel₀ ha
section Gcd
theorem gcd_eq_zero_iff (a : ℤ√d) : Int.gcd a.re a.im = 0 ↔ a = 0 := by
simp only [Int.gcd_eq_zero_iff, Zsqrtd.ext_iff, eq_self_iff_true, zero_im, zero_re]
theorem gcd_pos_iff (a : ℤ√d) : 0 < Int.gcd a.re a.im ↔ a ≠ 0 :=
pos_iff_ne_zero.trans <| not_congr a.gcd_eq_zero_iff
theorem isCoprime_of_dvd_isCoprime {a b : ℤ√d} (hcoprime : IsCoprime a.re a.im) (hdvd : b ∣ a) :
IsCoprime b.re b.im := by
apply isCoprime_of_dvd
· rintro ⟨hre, him⟩
obtain rfl : b = 0 := Zsqrtd.ext hre him
rw [zero_dvd_iff] at hdvd
simp [hdvd, zero_im, zero_re, not_isCoprime_zero_zero] at hcoprime
· rintro z hz - hzdvdu hzdvdv
apply hz
obtain ⟨ha, hb⟩ : z ∣ a.re ∧ z ∣ a.im := by
rw [← intCast_dvd]
apply dvd_trans _ hdvd
rw [intCast_dvd]
exact ⟨hzdvdu, hzdvdv⟩
exact hcoprime.isUnit_of_dvd' ha hb
@[deprecated (since := "2025-01-23")] alias coprime_of_dvd_coprime := isCoprime_of_dvd_isCoprime
theorem exists_coprime_of_gcd_pos {a : ℤ√d} (hgcd : 0 < Int.gcd a.re a.im) :
∃ b : ℤ√d, a = ((Int.gcd a.re a.im : ℤ) : ℤ√d) * b ∧ IsCoprime b.re b.im := by
obtain ⟨re, im, H1, Hre, Him⟩ := Int.exists_gcd_one hgcd
rw [mul_comm] at Hre Him
refine ⟨⟨re, im⟩, ?_, ?_⟩
· rw [smul_val, ← Hre, ← Him]
· rw [Int.isCoprime_iff_gcd_eq_one, H1]
end Gcd
/-- Read `SqLe a c b d` as `a √c ≤ b √d` -/
def SqLe (a c b d : ℕ) : Prop :=
c * a * a ≤ d * b * b
theorem sqLe_of_le {c d x y z w : ℕ} (xz : z ≤ x) (yw : y ≤ w) (xy : SqLe x c y d) : SqLe z c w d :=
le_trans (mul_le_mul (Nat.mul_le_mul_left _ xz) xz (Nat.zero_le _) (Nat.zero_le _)) <|
le_trans xy (mul_le_mul (Nat.mul_le_mul_left _ yw) yw (Nat.zero_le _) (Nat.zero_le _))
theorem sqLe_add_mixed {c d x y z w : ℕ} (xy : SqLe x c y d) (zw : SqLe z c w d) :
c * (x * z) ≤ d * (y * w) :=
Nat.mul_self_le_mul_self_iff.1 <| by
simpa [mul_comm, mul_left_comm] using mul_le_mul xy zw (Nat.zero_le _) (Nat.zero_le _)
theorem sqLe_add {c d x y z w : ℕ} (xy : SqLe x c y d) (zw : SqLe z c w d) :
SqLe (x + z) c (y + w) d := by
have xz := sqLe_add_mixed xy zw
simp? [SqLe, mul_assoc] at xy zw says simp only [SqLe, mul_assoc] at xy zw
simp [SqLe, mul_add, mul_comm, mul_left_comm, add_le_add, *]
theorem sqLe_cancel {c d x y z w : ℕ} (zw : SqLe y d x c) (h : SqLe (x + z) c (y + w) d) :
SqLe z c w d := by
apply le_of_not_gt
intro l
refine not_le_of_gt ?_ h
simp only [SqLe, mul_add, mul_comm, mul_left_comm, add_assoc, gt_iff_lt]
have hm := sqLe_add_mixed zw (le_of_lt l)
simp only [SqLe, mul_assoc, gt_iff_lt] at l zw
exact
lt_of_le_of_lt (add_le_add_right zw _)
(add_lt_add_left (add_lt_add_of_le_of_lt hm (add_lt_add_of_le_of_lt hm l)) _)
theorem sqLe_smul {c d x y : ℕ} (n : ℕ) (xy : SqLe x c y d) : SqLe (n * x) c (n * y) d := by
simpa [SqLe, mul_left_comm, mul_assoc] using Nat.mul_le_mul_left (n * n) xy
theorem sqLe_mul {d x y z w : ℕ} :
(SqLe x 1 y d → SqLe z 1 w d → SqLe (x * w + y * z) d (x * z + d * y * w) 1) ∧
(SqLe x 1 y d → SqLe w d z 1 → SqLe (x * z + d * y * w) 1 (x * w + y * z) d) ∧
(SqLe y d x 1 → SqLe z 1 w d → SqLe (x * z + d * y * w) 1 (x * w + y * z) d) ∧
(SqLe y d x 1 → SqLe w d z 1 → SqLe (x * w + y * z) d (x * z + d * y * w) 1) := by
refine ⟨?_, ?_, ?_, ?_⟩ <;>
· intro xy zw
have :=
Int.mul_nonneg (sub_nonneg_of_le (Int.ofNat_le_ofNat_of_le xy))
(sub_nonneg_of_le (Int.ofNat_le_ofNat_of_le zw))
refine Int.le_of_ofNat_le_ofNat (le_of_sub_nonneg ?_)
convert this using 1
simp only [one_mul, Int.natCast_add, Int.natCast_mul]
ring
open Int in
/-- "Generalized" `nonneg`. `nonnegg c d x y` means `a √c + b √d ≥ 0`;
we are interested in the case `c = 1` but this is more symmetric -/
def Nonnegg (c d : ℕ) : ℤ → ℤ → Prop
| (a : ℕ), (b : ℕ) => True
| (a : ℕ), -[b+1] => SqLe (b + 1) c a d
| -[a+1], (b : ℕ) => SqLe (a + 1) d b c
| -[_+1], -[_+1] => False
theorem nonnegg_comm {c d : ℕ} {x y : ℤ} : Nonnegg c d x y = Nonnegg d c y x := by
cases x <;> cases y <;> rfl
theorem nonnegg_neg_pos {c d} : ∀ {a b : ℕ}, Nonnegg c d (-a) b ↔ SqLe a d b c
| 0, b => ⟨by simp [SqLe, Nat.zero_le], fun _ => trivial⟩
| a + 1, b => by rfl
theorem nonnegg_pos_neg {c d} {a b : ℕ} : Nonnegg c d a (-b) ↔ SqLe b c a d := by
rw [nonnegg_comm]; exact nonnegg_neg_pos
open Int in
theorem nonnegg_cases_right {c d} {a : ℕ} :
∀ {b : ℤ}, (∀ x : ℕ, b = -x → SqLe x c a d) → Nonnegg c d a b
| (b : Nat), _ => trivial
| -[b+1], h => h (b + 1) rfl
theorem nonnegg_cases_left {c d} {b : ℕ} {a : ℤ} (h : ∀ x : ℕ, a = -x → SqLe x d b c) :
Nonnegg c d a b :=
cast nonnegg_comm (nonnegg_cases_right h)
section Norm
/-- The norm of an element of `ℤ[√d]`. -/
def norm (n : ℤ√d) : ℤ :=
n.re * n.re - d * n.im * n.im
theorem norm_def (n : ℤ√d) : n.norm = n.re * n.re - d * n.im * n.im :=
rfl
@[simp]
theorem norm_zero : norm (0 : ℤ√d) = 0 := by simp [norm]
@[simp]
theorem norm_one : norm (1 : ℤ√d) = 1 := by simp [norm]
@[simp]
theorem norm_intCast (n : ℤ) : norm (n : ℤ√d) = n * n := by simp [norm]
@[simp]
theorem norm_natCast (n : ℕ) : norm (n : ℤ√d) = n * n :=
norm_intCast n
@[simp]
theorem norm_mul (n m : ℤ√d) : norm (n * m) = norm n * norm m := by
simp only [norm, mul_im, mul_re]
ring
/-- `norm` as a `MonoidHom`. -/
def normMonoidHom : ℤ√d →* ℤ where
toFun := norm
map_mul' := norm_mul
map_one' := norm_one
theorem norm_eq_mul_conj (n : ℤ√d) : (norm n : ℤ√d) = n * star n := by
ext <;> simp [norm, star, mul_comm, sub_eq_add_neg]
@[simp]
theorem norm_neg (x : ℤ√d) : (-x).norm = x.norm :=
(Int.cast_inj (α := ℤ√d)).1 <| by simp [norm_eq_mul_conj]
@[simp]
theorem norm_conj (x : ℤ√d) : (star x).norm = x.norm :=
(Int.cast_inj (α := ℤ√d)).1 <| by simp [norm_eq_mul_conj, mul_comm]
theorem norm_nonneg (hd : d ≤ 0) (n : ℤ√d) : 0 ≤ n.norm :=
add_nonneg (mul_self_nonneg _)
(by
rw [mul_assoc, neg_mul_eq_neg_mul]
exact mul_nonneg (neg_nonneg.2 hd) (mul_self_nonneg _))
theorem norm_eq_one_iff {x : ℤ√d} : x.norm.natAbs = 1 ↔ IsUnit x :=
⟨fun h =>
isUnit_iff_dvd_one.2 <|
(le_total 0 (norm x)).casesOn
(fun hx =>
⟨star x, by
rwa [← Int.natCast_inj, Int.natAbs_of_nonneg hx, ← @Int.cast_inj (ℤ√d) _ _,
| norm_eq_mul_conj, eq_comm] at h⟩)
fun hx =>
| Mathlib/NumberTheory/Zsqrtd/Basic.lean | 481 | 482 |
/-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Jujian Zhang
-/
import Mathlib.Algebra.GroupWithZero.Subgroup
import Mathlib.Algebra.Order.Group.Action
import Mathlib.LinearAlgebra.Finsupp.Supported
import Mathlib.LinearAlgebra.Span.Basic
/-! # Pointwise instances on `Submodule`s
This file provides:
* `Submodule.pointwiseNeg`
and the actions
* `Submodule.pointwiseDistribMulAction`
* `Submodule.pointwiseMulActionWithZero`
which matches the action of `Set.mulActionSet`.
This file also provides:
* `Submodule.pointwiseSetSMulSubmodule`: for `R`-module `M`, a `s : Set R` can act on
`N : Submodule R M` by defining `s • N` to be the smallest submodule containing all `a • n`
where `a ∈ s` and `n ∈ N`.
These actions are available in the `Pointwise` locale.
## Implementation notes
For an `R`-module `M`, the action of a subset of `R` acting on a submodule of `M` introduced in
section `set_acting_on_submodules` does not have a counterpart in the files
`Mathlib.Algebra.Group.Submonoid.Pointwise` and `Mathlib.Algebra.GroupWithZero.Submonoid.Pointwise`.
Other than section `set_acting_on_submodules`, most of the lemmas in this file are direct copies of
lemmas from the file `Mathlib.Algebra.Group.Submonoid.Pointwise`.
-/
assert_not_exists Ideal
variable {α : Type*} {R : Type*} {M : Type*}
open Pointwise
namespace Submodule
section Neg
section Semiring
variable [Semiring R] [AddCommGroup M] [Module R M]
/-- The submodule with every element negated. Note if `R` is a ring and not just a semiring, this
is a no-op, as shown by `Submodule.neg_eq_self`.
Recall that When `R` is the semiring corresponding to the nonnegative elements of `R'`,
`Submodule R' M` is the type of cones of `M`. This instance reflects such cones about `0`.
This is available as an instance in the `Pointwise` locale. -/
protected def pointwiseNeg : Neg (Submodule R M) where
neg p :=
{ -p.toAddSubmonoid with
smul_mem' := fun r m hm => Set.mem_neg.2 <| smul_neg r m ▸ p.smul_mem r <| Set.mem_neg.1 hm }
scoped[Pointwise] attribute [instance] Submodule.pointwiseNeg
open Pointwise
@[simp]
theorem coe_set_neg (S : Submodule R M) : ↑(-S) = -(S : Set M) :=
rfl
@[simp]
theorem neg_toAddSubmonoid (S : Submodule R M) : (-S).toAddSubmonoid = -S.toAddSubmonoid :=
rfl
@[simp]
theorem mem_neg {g : M} {S : Submodule R M} : g ∈ -S ↔ -g ∈ S :=
Iff.rfl
/-- `Submodule.pointwiseNeg` is involutive.
This is available as an instance in the `Pointwise` locale. -/
protected def involutivePointwiseNeg : InvolutiveNeg (Submodule R M) where
neg := Neg.neg
neg_neg _S := SetLike.coe_injective <| neg_neg _
scoped[Pointwise] attribute [instance] Submodule.involutivePointwiseNeg
@[simp]
theorem neg_le_neg (S T : Submodule R M) : -S ≤ -T ↔ S ≤ T :=
SetLike.coe_subset_coe.symm.trans Set.neg_subset_neg
theorem neg_le (S T : Submodule R M) : -S ≤ T ↔ S ≤ -T :=
SetLike.coe_subset_coe.symm.trans Set.neg_subset
/-- `Submodule.pointwiseNeg` as an order isomorphism. -/
def negOrderIso : Submodule R M ≃o Submodule R M where
toEquiv := Equiv.neg _
map_rel_iff' := @neg_le_neg _ _ _ _ _
theorem span_neg_eq_neg (s : Set M) : span R (-s) = -span R s := by
apply le_antisymm
· rw [span_le, coe_set_neg, ← Set.neg_subset, neg_neg]
exact subset_span
· rw [neg_le, span_le, coe_set_neg, ← Set.neg_subset]
exact subset_span
@[deprecated (since := "2025-04-08")]
alias closure_neg := span_neg_eq_neg
@[simp]
theorem neg_inf (S T : Submodule R M) : -(S ⊓ T) = -S ⊓ -T := rfl
@[simp]
theorem neg_sup (S T : Submodule R M) : -(S ⊔ T) = -S ⊔ -T :=
(negOrderIso : Submodule R M ≃o Submodule R M).map_sup S T
@[simp]
theorem neg_bot : -(⊥ : Submodule R M) = ⊥ :=
SetLike.coe_injective <| (Set.neg_singleton 0).trans <| congr_arg _ neg_zero
@[simp]
theorem neg_top : -(⊤ : Submodule R M) = ⊤ :=
SetLike.coe_injective <| Set.neg_univ
@[simp]
theorem neg_iInf {ι : Sort*} (S : ι → Submodule R M) : (-⨅ i, S i) = ⨅ i, -S i :=
(negOrderIso : Submodule R M ≃o Submodule R M).map_iInf _
@[simp]
theorem neg_iSup {ι : Sort*} (S : ι → Submodule R M) : (-⨆ i, S i) = ⨆ i, -S i :=
(negOrderIso : Submodule R M ≃o Submodule R M).map_iSup _
end Semiring
open Pointwise
@[simp]
theorem neg_eq_self [Ring R] [AddCommGroup M] [Module R M] (p : Submodule R M) : -p = p :=
ext fun _ => p.neg_mem_iff
end Neg
variable [Semiring R] [AddCommMonoid M] [Module R M]
instance pointwiseZero : Zero (Submodule R M) where
zero := ⊥
instance pointwiseAdd : Add (Submodule R M) where
add := (· ⊔ ·)
instance pointwiseAddCommMonoid : AddCommMonoid (Submodule R M) where
add_assoc := sup_assoc
zero_add := bot_sup_eq
add_zero := sup_bot_eq
add_comm := sup_comm
nsmul := nsmulRec
@[simp]
theorem add_eq_sup (p q : Submodule R M) : p + q = p ⊔ q :=
rfl
@[simp]
theorem zero_eq_bot : (0 : Submodule R M) = ⊥ :=
rfl
instance : IsOrderedAddMonoid (Submodule R M) :=
{ add_le_add_left := fun _a _b => sup_le_sup_left }
instance : CanonicallyOrderedAdd (Submodule R M) where
exists_add_of_le := @fun _a b h => ⟨b, (sup_eq_right.2 h).symm⟩
le_self_add := fun _a _b => le_sup_left
section
variable [Monoid α] [DistribMulAction α M] [SMulCommClass α R M]
/-- The action on a submodule corresponding to applying the action to every element.
This is available as an instance in the `Pointwise` locale. -/
protected def pointwiseDistribMulAction : DistribMulAction α (Submodule R M) where
smul a S := S.map (DistribMulAction.toLinearMap R M a : M →ₗ[R] M)
one_smul S :=
(congr_arg (fun f : Module.End R M => S.map f) (LinearMap.ext <| one_smul α)).trans S.map_id
mul_smul _a₁ _a₂ S :=
(congr_arg (fun f : Module.End R M => S.map f) (LinearMap.ext <| mul_smul _ _)).trans
(S.map_comp _ _)
smul_zero _a := map_bot _
smul_add _a _S₁ _S₂ := map_sup _ _ _
scoped[Pointwise] attribute [instance] Submodule.pointwiseDistribMulAction
open Pointwise
@[simp]
theorem coe_pointwise_smul (a : α) (S : Submodule R M) : ↑(a • S) = a • (S : Set M) :=
rfl
@[simp]
theorem pointwise_smul_toAddSubmonoid (a : α) (S : Submodule R M) :
(a • S).toAddSubmonoid = a • S.toAddSubmonoid :=
rfl
@[simp]
theorem pointwise_smul_toAddSubgroup {R M : Type*} [Ring R] [AddCommGroup M] [DistribMulAction α M]
[Module R M] [SMulCommClass α R M] (a : α) (S : Submodule R M) :
(a • S).toAddSubgroup = a • S.toAddSubgroup :=
rfl
theorem mem_smul_pointwise_iff_exists (m : M) (a : α) (S : Submodule R M) :
m ∈ a • S ↔ ∃ b ∈ S, a • b = m :=
Set.mem_smul_set
theorem smul_mem_pointwise_smul (m : M) (a : α) (S : Submodule R M) : m ∈ S → a • m ∈ a • S :=
(Set.smul_mem_smul_set : _ → _ ∈ a • (S : Set M))
instance : CovariantClass α (Submodule R M) HSMul.hSMul LE.le :=
⟨fun _ _ => map_mono⟩
/-- See also `Submodule.smul_bot`. -/
@[simp]
theorem smul_bot' (a : α) : a • (⊥ : Submodule R M) = ⊥ :=
map_bot _
/-- See also `Submodule.smul_sup`. -/
theorem smul_sup' (a : α) (S T : Submodule R M) : a • (S ⊔ T) = a • S ⊔ a • T :=
map_sup _ _ _
theorem smul_span (a : α) (s : Set M) : a • span R s = span R (a • s) :=
map_span _ _
lemma smul_def (a : α) (S : Submodule R M) : a • S = span R (a • S : Set M) := by simp [← smul_span]
theorem span_smul (a : α) (s : Set M) : span R (a • s) = a • span R s :=
Eq.symm (span_image _).symm
instance pointwiseCentralScalar [DistribMulAction αᵐᵒᵖ M] [SMulCommClass αᵐᵒᵖ R M]
[IsCentralScalar α M] : IsCentralScalar α (Submodule R M) :=
⟨fun _a S => (congr_arg fun f : Module.End R M => S.map f) <| LinearMap.ext <| op_smul_eq_smul _⟩
@[simp]
theorem smul_le_self_of_tower {α : Type*} [Monoid α] [SMul α R] [DistribMulAction α M]
[SMulCommClass α R M] [IsScalarTower α R M] (a : α) (S : Submodule R M) : a • S ≤ S := by
rintro y ⟨x, hx, rfl⟩
exact smul_of_tower_mem _ a hx
end
section
variable [Semiring α] [Module α M] [SMulCommClass α R M]
/-- The action on a submodule corresponding to applying the action to every element.
This is available as an instance in the `Pointwise` locale.
This is a stronger version of `Submodule.pointwiseDistribMulAction`. Note that `add_smul` does
not hold so this cannot be stated as a `Module`. -/
protected def pointwiseMulActionWithZero : MulActionWithZero α (Submodule R M) :=
{ Submodule.pointwiseDistribMulAction with
zero_smul := fun S =>
(congr_arg (fun f : M →ₗ[R] M => S.map f) (LinearMap.ext <| zero_smul α)).trans S.map_zero }
scoped[Pointwise] attribute [instance] Submodule.pointwiseMulActionWithZero
end
/-!
### Sets acting on Submodules
Let `R` be a (semi)ring and `M` an `R`-module. Let `S` be a monoid which acts on `M` distributively,
then subsets of `S` can act on submodules of `M`.
For subset `s ⊆ S` and submodule `N ≤ M`, we define `s • N` to be the smallest submodule containing
all `r • n` where `r ∈ s` and `n ∈ N`.
#### Results
For arbitrary monoids `S` acting distributively on `M`, there is an induction principle for `s • N`:
To prove `P` holds for all `s • N`, it is enough
to prove:
- for all `r ∈ s` and `n ∈ N`, `P (r • n)`;
- for all `r` and `m ∈ s • N`, `P (r • n)`;
- for all `m₁, m₂`, `P m₁` and `P m₂` implies `P (m₁ + m₂)`;
- `P 0`.
To invoke this induction principle, use `induction x, hx using Submodule.set_smul_inductionOn` where
`x : M` and `hx : x ∈ s • N`
When we consider subset of `R` acting on `M`
- `Submodule.pointwiseSetDistribMulAction` : the action described above is distributive.
- `Submodule.mem_set_smul` : `x ∈ s • N` iff `x` can be written as `r₀ n₀ + ... + rₖ nₖ` where
`rᵢ ∈ s` and `nᵢ ∈ N`.
- `Submodule.coe_span_smul`: `s • N` is the same as `⟨s⟩ • N` where `⟨s⟩` is the ideal spanned
by `s`.
#### Notes
- If we assume the addition on subsets of `R` is the `⊔` and subtraction `⊓` i.e. use `SetSemiring`,
then this action actually gives a module structure on submodules of `M` over subsets of `R`.
- If we generalize so that `r • N` makes sense for all `r : S`, then `Submodule.singleton_set_smul`
and `Submodule.singleton_set_smul` can be generalized as well.
-/
section set_acting_on_submodules
variable {S : Type*} [Monoid S]
variable [DistribMulAction S M]
/--
Let `s ⊆ R` be a set and `N ≤ M` be a submodule, then `s • N` is the smallest submodule containing
all `r • n` where `r ∈ s` and `n ∈ N`.
-/
protected def pointwiseSetSMul : SMul (Set S) (Submodule R M) where
smul s N := sInf { p | ∀ ⦃r : S⦄ ⦃n : M⦄, r ∈ s → n ∈ N → r • n ∈ p }
scoped[Pointwise] attribute [instance] Submodule.pointwiseSetSMul
variable (sR : Set R) (s : Set S) (N : Submodule R M)
lemma mem_set_smul_def (x : M) :
x ∈ s • N ↔
x ∈ sInf { p : Submodule R M | ∀ ⦃r : S⦄ {n : M}, r ∈ s → n ∈ N → r • n ∈ p } := Iff.rfl
variable {s N} in
@[aesop safe]
lemma mem_set_smul_of_mem_mem {r : S} {m : M} (mem1 : r ∈ s) (mem2 : m ∈ N) :
r • m ∈ s • N := by
rw [mem_set_smul_def, mem_sInf]
exact fun _ h => h mem1 mem2
lemma set_smul_le (p : Submodule R M)
(closed_under_smul : ∀ ⦃r : S⦄ ⦃n : M⦄, r ∈ s → n ∈ N → r • n ∈ p) :
s • N ≤ p :=
sInf_le closed_under_smul
lemma set_smul_le_iff (p : Submodule R M) :
s • N ≤ p ↔
∀ ⦃r : S⦄ ⦃n : M⦄, r ∈ s → n ∈ N → r • n ∈ p := by
fconstructor
· intro h r n hr hn
exact h <| mem_set_smul_of_mem_mem hr hn
· apply set_smul_le
lemma set_smul_eq_of_le (p : Submodule R M)
(closed_under_smul : ∀ ⦃r : S⦄ ⦃n : M⦄, r ∈ s → n ∈ N → r • n ∈ p)
(le : p ≤ s • N) :
s • N = p :=
le_antisymm (set_smul_le s N p closed_under_smul) le
instance : CovariantClass (Set S) (Submodule R M) HSMul.hSMul LE.le :=
⟨fun _ _ _ le => set_smul_le _ _ _ fun _ _ hr hm => mem_set_smul_of_mem_mem (mem1 := hr)
(mem2 := le hm)⟩
|
lemma set_smul_mono_left {s t : Set S} (le : s ≤ t) :
s • N ≤ t • N :=
set_smul_le _ _ _ fun _ _ hr hm => mem_set_smul_of_mem_mem (mem1 := le hr)
(mem2 := hm)
| Mathlib/Algebra/Module/Submodule/Pointwise.lean | 355 | 359 |
/-
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))
| Mathlib/AlgebraicGeometry/EllipticCurve/Group.lean | 297 | 305 |
/-
Copyright (c) 2020 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Computation.Basic
import Mathlib.Algebra.ContinuedFractions.Translations
import Mathlib.Algebra.Order.Floor.Ring
/-!
# Basic Translation Lemmas Between Structures Defined for Computing Continued Fractions
## Summary
This is a collection of simple lemmas between the different structures used for the computation
of continued fractions defined in `Mathlib.Algebra.ContinuedFractions.Computation.Basic`.
The file consists of three sections:
1. Recurrences and inversion lemmas for `IntFractPair.stream`: these lemmas give us inversion
rules and recurrences for the computation of the stream of integer and fractional parts of
a value.
2. Translation lemmas for the head term: these lemmas show us that the head term of the computed
continued fraction of a value `v` is `⌊v⌋` and how this head term is moved along the structures
used in the computation process.
3. Translation lemmas for the sequence: these lemmas show how the sequences of the involved
structures (`IntFractPair.stream`, `IntFractPair.seq1`, and `GenContFract.of`) are connected,
i.e. how the values are moved along the structures and the termination of one sequence implies
the termination of another sequence.
## Main Theorems
- `succ_nth_stream_eq_some_iff` gives as a recurrence to compute the `n + 1`th value of the sequence
of integer and fractional parts of a value in case of non-termination.
- `succ_nth_stream_eq_none_iff` gives as a recurrence to compute the `n + 1`th value of the sequence
of integer and fractional parts of a value in case of termination.
- `get?_of_eq_some_of_succ_get?_intFractPair_stream` and
`get?_of_eq_some_of_get?_intFractPair_stream_fr_ne_zero` show how the entries of the sequence
of the computed continued fraction can be obtained from the stream of integer and fractional
parts.
-/
assert_not_exists Finset
namespace GenContFract
open GenContFract (of)
-- Fix a discrete linear ordered division ring with `floor` function and a value `v`.
variable {K : Type*} [DivisionRing K] [LinearOrder K] [FloorRing K] {v : K}
namespace IntFractPair
/-!
### Recurrences and Inversion Lemmas for `IntFractPair.stream`
Here we state some lemmas that give us inversion rules and recurrences for the computation of the
stream of integer and fractional parts of a value.
-/
theorem stream_zero (v : K) : IntFractPair.stream v 0 = some (IntFractPair.of v) :=
rfl
variable {n : ℕ}
theorem stream_eq_none_of_fr_eq_zero {ifp_n : IntFractPair K}
(stream_nth_eq : IntFractPair.stream v n = some ifp_n) (nth_fr_eq_zero : ifp_n.fr = 0) :
IntFractPair.stream v (n + 1) = none := by
obtain ⟨_, fr⟩ := ifp_n
change fr = 0 at nth_fr_eq_zero
simp [IntFractPair.stream, stream_nth_eq, nth_fr_eq_zero]
/-- Gives a recurrence to compute the `n + 1`th value of the sequence of integer and fractional
parts of a value in case of termination.
-/
theorem succ_nth_stream_eq_none_iff :
IntFractPair.stream v (n + 1) = none ↔
IntFractPair.stream v n = none ∨ ∃ ifp, IntFractPair.stream v n = some ifp ∧ ifp.fr = 0 := by
rw [IntFractPair.stream]
cases IntFractPair.stream v n <;> simp [imp_false]
/-- Gives a recurrence to compute the `n + 1`th value of the sequence of integer and fractional
parts of a value in case of non-termination.
-/
theorem succ_nth_stream_eq_some_iff {ifp_succ_n : IntFractPair K} :
IntFractPair.stream v (n + 1) = some ifp_succ_n ↔
∃ ifp_n : IntFractPair K,
IntFractPair.stream v n = some ifp_n ∧
ifp_n.fr ≠ 0 ∧ IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n := by
simp [IntFractPair.stream, ite_eq_iff, Option.bind_eq_some_iff]
/-- An easier to use version of one direction of
`GenContFract.IntFractPair.succ_nth_stream_eq_some_iff`. -/
theorem stream_succ_of_some {p : IntFractPair K} (h : IntFractPair.stream v n = some p)
(h' : p.fr ≠ 0) : IntFractPair.stream v (n + 1) = some (IntFractPair.of p.fr⁻¹) :=
succ_nth_stream_eq_some_iff.mpr ⟨p, h, h', rfl⟩
/-- The stream of `IntFractPair`s of an integer stops after the first term.
-/
theorem stream_succ_of_int [IsStrictOrderedRing K] (a : ℤ) (n : ℕ) :
IntFractPair.stream (a : K) (n + 1) = none := by
induction n with
| zero =>
refine IntFractPair.stream_eq_none_of_fr_eq_zero (IntFractPair.stream_zero (a : K)) ?_
simp only [IntFractPair.of, Int.fract_intCast]
| succ n ih => exact IntFractPair.succ_nth_stream_eq_none_iff.mpr (Or.inl ih)
theorem exists_succ_nth_stream_of_fr_zero {ifp_succ_n : IntFractPair K}
(stream_succ_nth_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n)
(succ_nth_fr_eq_zero : ifp_succ_n.fr = 0) :
∃ ifp_n : IntFractPair K, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr⁻¹ = ⌊ifp_n.fr⁻¹⌋ := by
-- get the witness from `succ_nth_stream_eq_some_iff` and prove that it has the additional
-- properties
rcases succ_nth_stream_eq_some_iff.mp stream_succ_nth_eq with
⟨ifp_n, seq_nth_eq, _, rfl⟩
refine ⟨ifp_n, seq_nth_eq, ?_⟩
simpa only [IntFractPair.of, Int.fract, sub_eq_zero] using succ_nth_fr_eq_zero
/-- A recurrence relation that expresses the `(n+1)`th term of the stream of `IntFractPair`s
of `v` for non-integer `v` in terms of the `n`th term of the stream associated to
the inverse of the fractional part of `v`.
-/
theorem stream_succ (h : Int.fract v ≠ 0) (n : ℕ) :
IntFractPair.stream v (n + 1) = IntFractPair.stream (Int.fract v)⁻¹ n := by
induction n with
| zero =>
have H : (IntFractPair.of v).fr = Int.fract v := by simp [IntFractPair.of]
rw [stream_zero, stream_succ_of_some (stream_zero v) (ne_of_eq_of_ne H h), H]
| succ n ih =>
rcases eq_or_ne (IntFractPair.stream (Int.fract v)⁻¹ n) none with hnone | hsome
· rw [hnone] at ih
rw [succ_nth_stream_eq_none_iff.mpr (Or.inl hnone),
succ_nth_stream_eq_none_iff.mpr (Or.inl ih)]
· obtain ⟨p, hp⟩ := Option.ne_none_iff_exists'.mp hsome
rw [hp] at ih
rcases eq_or_ne p.fr 0 with hz | hnz
· rw [stream_eq_none_of_fr_eq_zero hp hz, stream_eq_none_of_fr_eq_zero ih hz]
· rw [stream_succ_of_some hp hnz, stream_succ_of_some ih hnz]
end IntFractPair
section Head
/-!
### Translation of the Head Term
Here we state some lemmas that show us that the head term of the computed continued fraction of a
value `v` is `⌊v⌋` and how this head term is moved along the structures used in the computation
process.
-/
/-- The head term of the sequence with head of `v` is just the integer part of `v`. -/
@[simp]
theorem IntFractPair.seq1_fst_eq_of : (IntFractPair.seq1 v).fst = IntFractPair.of v :=
rfl
theorem of_h_eq_intFractPair_seq1_fst_b : (of v).h = (IntFractPair.seq1 v).fst.b := by
cases aux_seq_eq : IntFractPair.seq1 v
simp [of, aux_seq_eq]
/-- The head term of the gcf of `v` is `⌊v⌋`. -/
@[simp]
theorem of_h_eq_floor : (of v).h = ⌊v⌋ := by
simp [of_h_eq_intFractPair_seq1_fst_b, IntFractPair.of]
end Head
section sequence
/-!
### Translation of the Sequences
Here we state some lemmas that show how the sequences of the involved structures
(`IntFractPair.stream`, `IntFractPair.seq1`, and `GenContFract.of`) are connected, i.e. how the
values are moved along the structures and how the termination of one sequence implies the
termination of another sequence.
-/
variable {n : ℕ}
theorem IntFractPair.get?_seq1_eq_succ_get?_stream :
(IntFractPair.seq1 v).snd.get? n = (IntFractPair.stream v) (n + 1) :=
rfl
section Termination
/-!
#### Translation of the Termination of the Sequences
Let's first show how the termination of one sequence implies the termination of another sequence.
-/
theorem of_terminatedAt_iff_intFractPair_seq1_terminatedAt :
(of v).TerminatedAt n ↔ (IntFractPair.seq1 v).snd.TerminatedAt n :=
Option.map_eq_none_iff
theorem of_terminatedAt_n_iff_succ_nth_intFractPair_stream_eq_none :
(of v).TerminatedAt n ↔ IntFractPair.stream v (n + 1) = none := by
rw [of_terminatedAt_iff_intFractPair_seq1_terminatedAt, Stream'.Seq.TerminatedAt,
IntFractPair.get?_seq1_eq_succ_get?_stream]
end Termination
section Values
/-!
#### Translation of the Values of the Sequence
Now let's show how the values of the sequences correspond to one another.
-/
theorem IntFractPair.exists_succ_get?_stream_of_gcf_of_get?_eq_some {gp_n : Pair K}
(s_nth_eq : (of v).s.get? n = some gp_n) :
∃ ifp : IntFractPair K, IntFractPair.stream v (n + 1) = some ifp ∧ (ifp.b : K) = gp_n.b := by
obtain ⟨ifp, stream_succ_nth_eq, gp_n_eq⟩ :
∃ ifp, IntFractPair.stream v (n + 1) = some ifp ∧ Pair.mk 1 (ifp.b : K) = gp_n := by
unfold of IntFractPair.seq1 at s_nth_eq
simpa [Stream'.Seq.get?_tail, Stream'.Seq.map_get?] using s_nth_eq
cases gp_n_eq
simp_all only [Option.some.injEq, exists_eq_left']
/-- Shows how the entries of the sequence of the computed continued fraction can be obtained by the
integer parts of the stream of integer and fractional parts.
-/
theorem get?_of_eq_some_of_succ_get?_intFractPair_stream {ifp_succ_n : IntFractPair K}
(stream_succ_nth_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n) :
(of v).s.get? n = some ⟨1, ifp_succ_n.b⟩ := by
unfold of IntFractPair.seq1
simp [Stream'.Seq.map_tail, Stream'.Seq.get?_tail, Stream'.Seq.map_get?, stream_succ_nth_eq]
/-- Shows how the entries of the sequence of the computed continued fraction can be obtained by the
fractional parts of the stream of integer and fractional parts.
-/
theorem get?_of_eq_some_of_get?_intFractPair_stream_fr_ne_zero {ifp_n : IntFractPair K}
(stream_nth_eq : IntFractPair.stream v n = some ifp_n) (nth_fr_ne_zero : ifp_n.fr ≠ 0) :
(of v).s.get? n = some ⟨1, (IntFractPair.of ifp_n.fr⁻¹).b⟩ :=
have : IntFractPair.stream v (n + 1) = some (IntFractPair.of ifp_n.fr⁻¹) := by
cases ifp_n
simp only [IntFractPair.stream, Nat.add_eq, add_zero, stream_nth_eq, Option.some_bind,
ite_eq_right_iff]
intro; contradiction
get?_of_eq_some_of_succ_get?_intFractPair_stream this
open Int IntFractPair
theorem of_s_head_aux (v : K) : (of v).s.get? 0 = (IntFractPair.stream v 1).bind (some ∘ fun p =>
{ a := 1
b := p.b }) := by
rw [of, IntFractPair.seq1]
simp only [of, Stream'.Seq.map_tail, Stream'.Seq.map, Stream'.Seq.tail, Stream'.Seq.head,
Stream'.Seq.get?, Stream'.map]
rw [← Stream'.get_succ, Stream'.get, Option.map.eq_def]
split <;> simp_all only [Option.some_bind, Option.none_bind, Function.comp_apply]
/-- This gives the first pair of coefficients of the continued fraction of a non-integer `v`.
-/
theorem of_s_head (h : fract v ≠ 0) : (of v).s.head = some ⟨1, ⌊(fract v)⁻¹⌋⟩ := by
change (of v).s.get? 0 = _
rw [of_s_head_aux, stream_succ_of_some (stream_zero v) h, Option.bind]
rfl
variable (K)
variable [IsStrictOrderedRing K]
/-- If `a` is an integer, then the coefficient sequence of its continued fraction is empty.
-/
theorem of_s_of_int (a : ℤ) : (of (a : K)).s = Stream'.Seq.nil :=
haveI h : ∀ n, (of (a : K)).s.get? n = none := by
intro n
induction n with
| zero => rw [of_s_head_aux, stream_succ_of_int, Option.bind]
| | succ n ih => exact (of (a : K)).s.prop ih
Stream'.Seq.ext fun n => (h n).trans (Stream'.Seq.get?_nil n).symm
variable {K} (v)
| Mathlib/Algebra/ContinuedFractions/Computation/Translations.lean | 275 | 278 |
/-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Algebra.CharP.Lemmas
import Mathlib.GroupTheory.OrderOfElement
/-!
# Lemmas about rings of characteristic two
This file contains results about `CharP R 2`, in the `CharTwo` namespace.
The lemmas in this file with a `_sq` suffix are just special cases of the `_pow_char` lemmas
elsewhere, with a shorter name for ease of discovery, and no need for a `[Fact (Prime 2)]` argument.
-/
assert_not_exists Algebra LinearMap
variable {R ι : Type*}
namespace CharTwo
section AddMonoidWithOne
variable [AddMonoidWithOne R]
theorem two_eq_zero [CharP R 2] : (2 : R) = 0 := by
rw [← Nat.cast_two, CharP.cast_eq_zero]
/-- The only hypotheses required to build a `CharP R 2` instance are `1 ≠ 0` and `2 = 0`. -/
theorem of_one_ne_zero_of_two_eq_zero (h₁ : (1 : R) ≠ 0) (h₂ : (2 : R) = 0) : CharP R 2 where
cast_eq_zero_iff n := by
obtain hn | hn := Nat.even_or_odd n
· simp_rw [hn.two_dvd, iff_true]
exact natCast_eq_zero_of_even_of_two_eq_zero hn h₂
· simp_rw [hn.not_two_dvd_nat, iff_false]
rwa [natCast_eq_one_of_odd_of_two_eq_zero hn h₂]
end AddMonoidWithOne
section Semiring
variable [Semiring R] [CharP R 2]
@[scoped simp]
theorem add_self_eq_zero (x : R) : x + x = 0 := by rw [← two_smul R x, two_eq_zero, zero_smul]
@[scoped simp]
protected theorem two_nsmul (x : R) : 2 • x = 0 := by rw [two_smul, add_self_eq_zero]
end Semiring
section Ring
variable [Ring R] [CharP R 2]
@[scoped simp]
theorem neg_eq (x : R) : -x = x := by
rw [neg_eq_iff_add_eq_zero, add_self_eq_zero]
theorem neg_eq' : Neg.neg = (id : R → R) :=
funext neg_eq
| @[scoped simp]
theorem sub_eq_add (x y : R) : x - y = x + y := by rw [sub_eq_add_neg, neg_eq]
| Mathlib/Algebra/CharP/Two.lean | 65 | 66 |
/-
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.Algebra.Polynomial.Bivariate
import Mathlib.AlgebraicGeometry.EllipticCurve.Weierstrass
import Mathlib.AlgebraicGeometry.EllipticCurve.VariableChange
/-!
# Affine coordinates for Weierstrass curves
This file defines the type of points on a Weierstrass curve as an inductive, consisting of the point
at infinity and affine points satisfying a Weierstrass equation with a nonsingular condition. This
file also defines the negation and addition operations of the group law for this type, and proves
that they respect the Weierstrass equation and the nonsingular condition. The fact that they form an
abelian group is proven in `Mathlib/AlgebraicGeometry/EllipticCurve/Group.lean`.
## Mathematical background
Let `W` be a Weierstrass curve over a field `F` with coefficients `aᵢ`. An *affine point*
on `W` is a tuple `(x, y)` of elements in `R` satisfying the *Weierstrass equation* `W(X, Y) = 0` in
*affine coordinates*, where `W(X, Y) := Y² + a₁XY + a₃Y - (X³ + a₂X² + a₄X + a₆)`. It is
*nonsingular* if its partial derivatives `W_X(x, y)` and `W_Y(x, y)` do not vanish simultaneously.
The nonsingular affine points on `W` can be given negation and addition operations defined by a
secant-and-tangent process.
* Given a nonsingular affine point `P`, its *negation* `-P` is defined to be the unique third
nonsingular point of intersection between `W` and the vertical line through `P`.
Explicitly, if `P` is `(x, y)`, then `-P` is `(x, -y - a₁x - a₃)`.
* Given two nonsingular affine points `P` and `Q`, their *addition* `P + Q` is defined to be the
negation of the unique third nonsingular point of intersection between `W` and the line `L`
through `P` and `Q`. Explicitly, let `P` be `(x₁, y₁)` and let `Q` be `(x₂, y₂)`.
* If `x₁ = x₂` and `y₁ = -y₂ - a₁x₂ - a₃`, then `L` is vertical.
* If `x₁ = x₂` and `y₁ ≠ -y₂ - a₁x₂ - a₃`, then `L` is the tangent of `W` at `P = Q`, and has
slope `ℓ := (3x₁² + 2a₂x₁ + a₄ - a₁y₁) / (2y₁ + a₁x₁ + a₃)`.
* Otherwise `x₁ ≠ x₂`, then `L` is the secant of `W` through `P` and `Q`, and has slope
`ℓ := (y₁ - y₂) / (x₁ - x₂)`.
In the last two cases, the `X`-coordinate of `P + Q` is then the unique third solution of the
equation obtained by substituting the line `Y = ℓ(X - x₁) + y₁` into the Weierstrass equation,
and can be written down explicitly as `x := ℓ² + a₁ℓ - a₂ - x₁ - x₂` by inspecting the
coefficients of `X²`. The `Y`-coordinate of `P + Q`, after applying the final negation that maps
`Y` to `-Y - a₁X - a₃`, is precisely `y := -(ℓ(x - x₁) + y₁) - a₁x - a₃`.
The type of nonsingular points `W⟮F⟯` in affine coordinates is an inductive, consisting of the
unique point at infinity `𝓞` and nonsingular affine points `(x, y)`. Then `W⟮F⟯` can be endowed with
a group law, with `𝓞` as the identity nonsingular point, which is uniquely determined by these
formulae.
## Main definitions
* `WeierstrassCurve.Affine.Equation`: the Weierstrass equation of an affine Weierstrass curve.
* `WeierstrassCurve.Affine.Nonsingular`: the nonsingular condition on an affine Weierstrass curve.
* `WeierstrassCurve.Affine.Point`: a nonsingular rational point on an affine Weierstrass curve.
* `WeierstrassCurve.Affine.Point.neg`: the negation operation on an affine Weierstrass curve.
* `WeierstrassCurve.Affine.Point.add`: the addition operation on an affine Weierstrass curve.
## Main statements
* `WeierstrassCurve.Affine.equation_neg`: negation preserves the Weierstrass equation.
* `WeierstrassCurve.Affine.equation_add`: addition preserves the Weierstrass equation.
* `WeierstrassCurve.Affine.nonsingular_neg`: negation preserves the nonsingular condition.
* `WeierstrassCurve.Affine.nonsingular_add`: addition preserves the nonsingular condition.
* `WeierstrassCurve.Affine.nonsingular_of_Δ_ne_zero`: an affine Weierstrass curve is nonsingular at
every point if its discriminant is non-zero.
* `WeierstrassCurve.Affine.nonsingular`: an affine elliptic curve is nonsingular at every point.
## Notations
* `W⟮K⟯`: the group of nonsingular rational points on `W` base changed to `K`.
## References
[J Silverman, *The Arithmetic of Elliptic Curves*][silverman2009]
## Tags
elliptic curve, rational point, affine coordinates
-/
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 "derivative_simp" : tactic =>
`(tactic| simp only [derivative_C, derivative_X, derivative_X_pow, derivative_neg, derivative_add,
derivative_sub, derivative_mul, derivative_sq])
local macro "eval_simp" : tactic =>
`(tactic| simp only [eval_C, eval_X, eval_neg, eval_add, eval_sub, eval_mul, eval_pow, evalEval])
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, map_C, map_X, Polynomial.map_neg, Polynomial.map_add, Polynomial.map_sub,
Polynomial.map_mul, Polynomial.map_pow, Polynomial.map_div, coe_mapRingHom,
WeierstrassCurve.map])
universe r s u v w
/-! ## Weierstrass curves -/
namespace WeierstrassCurve
variable {R : Type r} {S : Type s} {A F : Type u} {B K : Type v} {L : Type w}
variable (R) in
/-- An abbreviation for a Weierstrass curve in affine coordinates. -/
abbrev Affine : Type r :=
WeierstrassCurve R
/-- The conversion from a Weierstrass curve to affine coordinates. -/
abbrev toAffine (W : WeierstrassCurve R) : Affine R :=
W
namespace Affine
variable [CommRing R] [CommRing S] [CommRing A] [CommRing B] [Field F] [Field K] [Field L]
{W' : Affine R} {W : Affine F}
section Equation
/-! ### Weierstrass equations -/
variable (W') in
/-- The polynomial `W(X, Y) := Y² + a₁XY + a₃Y - (X³ + a₂X² + a₄X + a₆)` associated to a Weierstrass
curve `W` over a ring `R` in affine coordinates.
For ease of polynomial manipulation, this is represented as a term of type `R[X][X]`, where the
inner variable represents `X` and the outer variable represents `Y`. For clarity, the alternative
notations `Y` and `R[X][Y]` are provided in the `Polynomial.Bivariate` scope to represent the outer
variable and the bivariate polynomial ring `R[X][X]` respectively. -/
noncomputable def polynomial : R[X][Y] :=
Y ^ 2 + C (C W'.a₁ * X + C W'.a₃) * Y - C (X ^ 3 + C W'.a₂ * X ^ 2 + C W'.a₄ * X + C W'.a₆)
lemma polynomial_eq : W'.polynomial = Cubic.toPoly
⟨0, 1, Cubic.toPoly ⟨0, 0, W'.a₁, W'.a₃⟩, Cubic.toPoly ⟨-1, -W'.a₂, -W'.a₄, -W'.a₆⟩⟩ := by
simp only [polynomial, Cubic.toPoly]
C_simp
ring1
lemma polynomial_ne_zero [Nontrivial R] : W'.polynomial ≠ 0 := by
rw [polynomial_eq]
exact Cubic.ne_zero_of_b_ne_zero one_ne_zero
@[simp]
lemma degree_polynomial [Nontrivial R] : W'.polynomial.degree = 2 := by
rw [polynomial_eq]
exact Cubic.degree_of_b_ne_zero' one_ne_zero
@[simp]
lemma natDegree_polynomial [Nontrivial R] : W'.polynomial.natDegree = 2 := by
rw [polynomial_eq]
exact Cubic.natDegree_of_b_ne_zero' one_ne_zero
lemma monic_polynomial : W'.polynomial.Monic := by
nontriviality R
simpa only [polynomial_eq] using Cubic.monic_of_b_eq_one'
lemma irreducible_polynomial [IsDomain R] : Irreducible W'.polynomial := by
by_contra h
rcases (monic_polynomial.not_irreducible_iff_exists_add_mul_eq_coeff natDegree_polynomial).mp h
with ⟨f, g, h0, h1⟩
simp only [polynomial_eq, Cubic.coeff_eq_c, Cubic.coeff_eq_d] at h0 h1
apply_fun degree at h0 h1
rw [Cubic.degree_of_a_ne_zero' <| neg_ne_zero.mpr <| one_ne_zero' R, degree_mul] at h0
apply (h1.symm.le.trans Cubic.degree_of_b_eq_zero').not_lt
rcases Nat.WithBot.add_eq_three_iff.mp h0.symm with h | h | h | h
iterate 2 rw [degree_add_eq_right_of_degree_lt] <;> simp only [h] <;> decide
iterate 2 rw [degree_add_eq_left_of_degree_lt] <;> simp only [h] <;> decide
lemma evalEval_polynomial (x y : R) : W'.polynomial.evalEval x y =
y ^ 2 + W'.a₁ * x * y + W'.a₃ * y - (x ^ 3 + W'.a₂ * x ^ 2 + W'.a₄ * x + W'.a₆) := by
simp only [polynomial]
eval_simp
rw [add_mul, ← add_assoc]
@[simp]
lemma evalEval_polynomial_zero : W'.polynomial.evalEval 0 0 = -W'.a₆ := by
simp only [evalEval_polynomial, zero_add, zero_sub, mul_zero, zero_pow <| Nat.succ_ne_zero _]
variable (W') in
/-- The proposition that an affine point `(x, y)` lies in a Weierstrass curve `W`.
In other words, it satisfies the Weierstrass equation `W(X, Y) = 0`. -/
def Equation (x y : R) : Prop :=
W'.polynomial.evalEval x y = 0
lemma equation_iff' (x y : R) : W'.Equation x y ↔
y ^ 2 + W'.a₁ * x * y + W'.a₃ * y - (x ^ 3 + W'.a₂ * x ^ 2 + W'.a₄ * x + W'.a₆) = 0 := by
rw [Equation, evalEval_polynomial]
lemma equation_iff (x y : R) : W'.Equation x y ↔
y ^ 2 + W'.a₁ * x * y + W'.a₃ * y = x ^ 3 + W'.a₂ * x ^ 2 + W'.a₄ * x + W'.a₆ := by
rw [equation_iff', sub_eq_zero]
@[simp]
lemma equation_zero : W'.Equation 0 0 ↔ W'.a₆ = 0 := by
rw [Equation, evalEval_polynomial_zero, neg_eq_zero]
lemma equation_iff_variableChange (x y : R) :
W'.Equation x y ↔ (VariableChange.mk 1 x 0 y • W').toAffine.Equation 0 0 := by
rw [equation_iff', ← neg_eq_zero, equation_zero, variableChange_a₆, inv_one, Units.val_one]
congr! 1
ring1
end Equation
section Nonsingular
/-! ### Nonsingular Weierstrass equations -/
variable (W') in
/-- The partial derivative `W_X(X, Y)` with respect to `X` of the polynomial `W(X, Y)` associated to
a Weierstrass curve `W` in affine coordinates. -/
-- TODO: define this in terms of `Polynomial.derivative`.
noncomputable def polynomialX : R[X][Y] :=
C (C W'.a₁) * Y - C (C 3 * X ^ 2 + C (2 * W'.a₂) * X + C W'.a₄)
lemma evalEval_polynomialX (x y : R) :
W'.polynomialX.evalEval x y = W'.a₁ * y - (3 * x ^ 2 + 2 * W'.a₂ * x + W'.a₄) := by
simp only [polynomialX]
eval_simp
@[simp]
lemma evalEval_polynomialX_zero : W'.polynomialX.evalEval 0 0 = -W'.a₄ := by
simp only [evalEval_polynomialX, zero_add, zero_sub, mul_zero, zero_pow <| Nat.succ_ne_zero _]
variable (W') in
/-- The partial derivative `W_Y(X, Y)` with respect to `Y` of the polynomial `W(X, Y)` associated to
a Weierstrass curve `W` in affine coordinates. -/
-- TODO: define this in terms of `Polynomial.derivative`.
noncomputable def polynomialY : R[X][Y] :=
C (C 2) * Y + C (C W'.a₁ * X + C W'.a₃)
lemma evalEval_polynomialY (x y : R) : W'.polynomialY.evalEval x y = 2 * y + W'.a₁ * x + W'.a₃ := by
simp only [polynomialY]
eval_simp
rw [← add_assoc]
@[simp]
lemma evalEval_polynomialY_zero : W'.polynomialY.evalEval 0 0 = W'.a₃ := by
simp only [evalEval_polynomialY, zero_add, mul_zero]
variable (W') in
/-- The proposition that an affine point `(x, y)` on a Weierstrass curve `W` is nonsingular.
In other words, either `W_X(x, y) ≠ 0` or `W_Y(x, y) ≠ 0`.
Note that this definition is only mathematically accurate for fields. -/
-- TODO: generalise this definition to be mathematically accurate for a larger class of rings.
def Nonsingular (x y : R) : Prop :=
W'.Equation x y ∧ (W'.polynomialX.evalEval x y ≠ 0 ∨ W'.polynomialY.evalEval x y ≠ 0)
lemma nonsingular_iff' (x y : R) : W'.Nonsingular x y ↔ W'.Equation x y ∧
(W'.a₁ * y - (3 * x ^ 2 + 2 * W'.a₂ * x + W'.a₄) ≠ 0 ∨ 2 * y + W'.a₁ * x + W'.a₃ ≠ 0) := by
rw [Nonsingular, equation_iff', evalEval_polynomialX, evalEval_polynomialY]
lemma nonsingular_iff (x y : R) : W'.Nonsingular x y ↔ W'.Equation x y ∧
(W'.a₁ * y ≠ 3 * x ^ 2 + 2 * W'.a₂ * x + W'.a₄ ∨ y ≠ -y - W'.a₁ * x - W'.a₃) := by
rw [nonsingular_iff', sub_ne_zero, ← sub_ne_zero (a := y)]
congr! 3
ring1
@[simp]
lemma nonsingular_zero : W'.Nonsingular 0 0 ↔ W'.a₆ = 0 ∧ (W'.a₃ ≠ 0 ∨ W'.a₄ ≠ 0) := by
rw [Nonsingular, equation_zero, evalEval_polynomialX_zero, neg_ne_zero, evalEval_polynomialY_zero,
or_comm]
lemma nonsingular_iff_variableChange (x y : R) :
W'.Nonsingular x y ↔ (VariableChange.mk 1 x 0 y • W').toAffine.Nonsingular 0 0 := by
rw [nonsingular_iff', equation_iff_variableChange, equation_zero, ← neg_ne_zero, or_comm,
nonsingular_zero, variableChange_a₃, variableChange_a₄, inv_one, Units.val_one]
simp only [variableChange_def]
congr! 3 <;> ring1
private lemma equation_zero_iff_nonsingular_zero_of_Δ_ne_zero (hΔ : W'.Δ ≠ 0) :
W'.Equation 0 0 ↔ W'.Nonsingular 0 0 := by
simp only [equation_zero, nonsingular_zero, iff_self_and]
contrapose! hΔ
simp only [b₂, b₄, b₆, b₈, Δ, hΔ]
ring1
/-- A Weierstrass curve is nonsingular at every point if its discriminant is non-zero. -/
lemma equation_iff_nonsingular_of_Δ_ne_zero {x y : R} (hΔ : W'.Δ ≠ 0) :
W'.Equation x y ↔ W'.Nonsingular x y := by
rw [equation_iff_variableChange, nonsingular_iff_variableChange,
equation_zero_iff_nonsingular_zero_of_Δ_ne_zero <| by
rwa [variableChange_Δ, inv_one, Units.val_one, one_pow, one_mul]]
/-- An elliptic curve is nonsingular at every point. -/
lemma equation_iff_nonsingular [Nontrivial R] [W'.IsElliptic] {x y : R} :
W'.toAffine.Equation x y ↔ W'.toAffine.Nonsingular x y :=
W'.toAffine.equation_iff_nonsingular_of_Δ_ne_zero <| W'.coe_Δ' ▸ W'.Δ'.ne_zero
@[deprecated (since := "2025-03-01")] alias nonsingular_zero_of_Δ_ne_zero :=
equation_iff_nonsingular_of_Δ_ne_zero
@[deprecated (since := "2025-03-01")] alias nonsingular_of_Δ_ne_zero :=
equation_iff_nonsingular_of_Δ_ne_zero
@[deprecated (since := "2025-03-01")] alias nonsingular := equation_iff_nonsingular
end Nonsingular
section Ring
/-! ### Group operation polynomials over a ring -/
variable (W') in
/-- The negation polynomial `-Y - a₁X - a₃` associated to the negation of a nonsingular affine point
on a Weierstrass curve. -/
noncomputable def negPolynomial : R[X][Y] :=
-(Y : R[X][Y]) - C (C W'.a₁ * X + C W'.a₃)
lemma Y_sub_polynomialY : Y - W'.polynomialY = W'.negPolynomial := by
rw [polynomialY, negPolynomial]
C_simp
ring1
lemma Y_sub_negPolynomial : Y - W'.negPolynomial = W'.polynomialY := by
rw [← Y_sub_polynomialY, sub_sub_cancel]
variable (W') in
/-- The `Y`-coordinate of `-(x, y)` for a nonsingular affine point `(x, y)` on a Weierstrass curve
`W`.
This depends on `W`, and has argument order: `x`, `y`. -/
@[simp]
def negY (x y : R) : R :=
-y - W'.a₁ * x - W'.a₃
lemma negY_negY (x y : R) : W'.negY x (W'.negY x y) = y := by
simp only [negY]
ring1
lemma evalEval_negPolynomial (x y : R) : W'.negPolynomial.evalEval x y = W'.negY x y := by
rw [negY, sub_sub, negPolynomial]
eval_simp
@[deprecated (since := "2025-03-05")] alias eval_negPolynomial := evalEval_negPolynomial
/-- The line polynomial `ℓ(X - x) + y` associated to the line `Y = ℓ(X - x) + y` that passes through
a nonsingular affine point `(x, y)` on a Weierstrass curve `W` with a slope of `ℓ`.
This does not depend on `W`, and has argument order: `x`, `y`, `ℓ`. -/
noncomputable def linePolynomial (x y ℓ : R) : R[X] :=
C ℓ * (X - C x) + C y
variable (W') in
/-- The addition polynomial obtained by substituting the line `Y = ℓ(X - x) + y` into the polynomial
`W(X, Y)` associated to a Weierstrass curve `W`. If such a line intersects `W` at another
nonsingular affine point `(x', y')` on `W`, then the roots of this polynomial are precisely `x`,
`x'`, and the `X`-coordinate of the addition of `(x, y)` and `(x', y')`.
This depends on `W`, and has argument order: `x`, `y`, `ℓ`. -/
noncomputable def addPolynomial (x y ℓ : R) : R[X] :=
W'.polynomial.eval <| linePolynomial x y ℓ
lemma C_addPolynomial (x y ℓ : R) : C (W'.addPolynomial x y ℓ) =
(Y - C (linePolynomial x y ℓ)) * (W'.negPolynomial - C (linePolynomial x y ℓ)) +
W'.polynomial := by
rw [addPolynomial, linePolynomial, polynomial, negPolynomial]
eval_simp
C_simp
ring1
lemma addPolynomial_eq (x y ℓ : R) : W'.addPolynomial x y ℓ = -Cubic.toPoly
⟨1, -ℓ ^ 2 - W'.a₁ * ℓ + W'.a₂,
2 * x * ℓ ^ 2 + (W'.a₁ * x - 2 * y - W'.a₃) * ℓ + (-W'.a₁ * y + W'.a₄),
-x ^ 2 * ℓ ^ 2 + (2 * x * y + W'.a₃ * x) * ℓ - (y ^ 2 + W'.a₃ * y - W'.a₆)⟩ := by
rw [addPolynomial, linePolynomial, polynomial, Cubic.toPoly]
eval_simp
C_simp
ring1
variable (W') in
/-- The `X`-coordinate of `(x₁, y₁) + (x₂, y₂)` for two nonsingular affine points `(x₁, y₁)` and
`(x₂, y₂)` on a Weierstrass curve `W`, where the line through them has a slope of `ℓ`.
This depends on `W`, and has argument order: `x₁`, `x₂`, `ℓ`. -/
@[simp]
def addX (x₁ x₂ ℓ : R) : R :=
ℓ ^ 2 + W'.a₁ * ℓ - W'.a₂ - x₁ - x₂
variable (W') in
/-- The `Y`-coordinate of `-((x₁, y₁) + (x₂, y₂))` for two nonsingular affine points `(x₁, y₁)` and
`(x₂, y₂)` on a Weierstrass curve `W`, where the line through them has a slope of `ℓ`.
This depends on `W`, and has argument order: `x₁`, `x₂`, `y₁`, `ℓ`. -/
@[simp]
def negAddY (x₁ x₂ y₁ ℓ : R) : R :=
ℓ * (W'.addX x₁ x₂ ℓ - x₁) + y₁
variable (W') in
/-- The `Y`-coordinate of `(x₁, y₁) + (x₂, y₂)` for two nonsingular affine points `(x₁, y₁)` and
`(x₂, y₂)` on a Weierstrass curve `W`, where the line through them has a slope of `ℓ`.
This depends on `W`, and has argument order: `x₁`, `x₂`, `y₁`, `ℓ`. -/
@[simp]
def addY (x₁ x₂ y₁ ℓ : R) : R :=
W'.negY (W'.addX x₁ x₂ ℓ) (W'.negAddY x₁ x₂ y₁ ℓ)
lemma equation_neg (x y : R) : W'.Equation x (W'.negY x y) ↔ W'.Equation x y := by
rw [equation_iff, equation_iff, negY]
congr! 1
ring1
@[deprecated (since := "2025-02-01")] alias equation_neg_of := equation_neg
@[deprecated (since := "2025-02-01")] alias equation_neg_iff := equation_neg
lemma nonsingular_neg (x y : R) : W'.Nonsingular x (W'.negY x y) ↔ W'.Nonsingular x y := by
rw [nonsingular_iff, equation_neg, ← negY, negY_negY, ← @ne_comm _ y, nonsingular_iff]
exact and_congr_right' <| (iff_congr not_and_or.symm not_and_or.symm).mpr <|
not_congr <| and_congr_left fun h => by rw [← h]
@[deprecated (since := "2025-02-01")] alias nonsingular_neg_of := nonsingular_neg
@[deprecated (since := "2025-02-01")] alias nonsingular_neg_iff := nonsingular_neg
lemma equation_add_iff (x₁ x₂ y₁ ℓ : R) : W'.Equation (W'.addX x₁ x₂ ℓ) (W'.negAddY x₁ x₂ y₁ ℓ) ↔
(W'.addPolynomial x₁ y₁ ℓ).eval (W'.addX x₁ x₂ ℓ) = 0 := by
rw [Equation, negAddY, addPolynomial, linePolynomial, polynomial]
eval_simp
lemma nonsingular_negAdd_of_eval_derivative_ne_zero {x₁ x₂ y₁ ℓ : R}
(hx' : W'.Equation (W'.addX x₁ x₂ ℓ) (W'.negAddY x₁ x₂ y₁ ℓ))
(hx : (W'.addPolynomial x₁ y₁ ℓ).derivative.eval (W'.addX x₁ x₂ ℓ) ≠ 0) :
W'.Nonsingular (W'.addX x₁ x₂ ℓ) (W'.negAddY x₁ x₂ y₁ ℓ) := by
rw [Nonsingular, and_iff_right hx', negAddY, polynomialX, polynomialY]
eval_simp
contrapose! hx
rw [addPolynomial, linePolynomial, polynomial]
eval_simp
derivative_simp
simp only [zero_add, add_zero, sub_zero, zero_mul, mul_one]
eval_simp
linear_combination (norm := (norm_num1; ring1)) hx.left + ℓ * hx.right
end Ring
section Field
/-! ### Group operation polynomials over a field -/
open Classical in
variable (W) in
/-- The slope of the line through two nonsingular affine points `(x₁, y₁)` and `(x₂, y₂)` on a
Weierstrass curve `W`.
If `x₁ ≠ x₂`, then this line is the secant of `W` through `(x₁, y₁)` and `(x₂, y₂)`, and has slope
`(y₁ - y₂) / (x₁ - x₂)`. Otherwise, if `y₁ ≠ -y₁ - a₁x₁ - a₃`, then this line is the tangent of `W`
at `(x₁, y₁) = (x₂, y₂)`, and has slope `(3x₁² + 2a₂x₁ + a₄ - a₁y₁) / (2y₁ + a₁x₁ + a₃)`. Otherwise,
this line is vertical, in which case this returns the value `0`.
This depends on `W`, and has argument order: `x₁`, `x₂`, `y₁`, `y₂`. -/
noncomputable def slope (x₁ x₂ y₁ y₂ : F) : F :=
if x₁ = x₂ then if y₁ = W.negY x₂ y₂ then 0
else (3 * x₁ ^ 2 + 2 * W.a₂ * x₁ + W.a₄ - W.a₁ * y₁) / (y₁ - W.negY x₁ y₁)
else (y₁ - y₂) / (x₁ - x₂)
@[simp]
lemma slope_of_Y_eq {x₁ x₂ y₁ y₂ : F} (hx : x₁ = x₂) (hy : y₁ = W.negY x₂ y₂) :
W.slope x₁ x₂ y₁ y₂ = 0 := by
rw [slope, if_pos hx, if_pos hy]
@[simp]
lemma slope_of_Y_ne {x₁ x₂ y₁ y₂ : F} (hx : x₁ = x₂) (hy : y₁ ≠ W.negY x₂ y₂) :
W.slope x₁ x₂ y₁ y₂ =
(3 * x₁ ^ 2 + 2 * W.a₂ * x₁ + W.a₄ - W.a₁ * y₁) / (y₁ - W.negY x₁ y₁) := by
rw [slope, if_pos hx, if_neg hy]
@[simp]
lemma slope_of_X_ne {x₁ x₂ y₁ y₂ : F} (hx : x₁ ≠ x₂) :
W.slope x₁ x₂ y₁ y₂ = (y₁ - y₂) / (x₁ - x₂) := by
rw [slope, if_neg hx]
lemma slope_of_Y_ne_eq_evalEval {x₁ x₂ y₁ y₂ : F} (hx : x₁ = x₂) (hy : y₁ ≠ W.negY x₂ y₂) :
W.slope x₁ x₂ y₁ y₂ = -W.polynomialX.evalEval x₁ y₁ / W.polynomialY.evalEval x₁ y₁ := by
rw [slope_of_Y_ne hx hy, evalEval_polynomialX, neg_sub]
congr 1
rw [negY, evalEval_polynomialY]
ring1
@[deprecated (since := "2025-03-05")] alias slope_of_Y_ne_eq_eval := slope_of_Y_ne_eq_evalEval
lemma Y_eq_of_X_eq {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂)
(hx : x₁ = x₂) : y₁ = y₂ ∨ y₁ = W.negY x₂ y₂ := by
rw [equation_iff] at h₁ h₂
rw [← sub_eq_zero, ← sub_eq_zero (a := y₁), ← mul_eq_zero, negY]
linear_combination (norm := (rw [hx]; ring1)) h₁ - h₂
lemma Y_eq_of_Y_ne {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂) (hx : x₁ = x₂)
(hy : y₁ ≠ W.negY x₂ y₂) : y₁ = y₂ :=
(Y_eq_of_X_eq h₁ h₂ hx).resolve_right hy
lemma 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₂)) : W.addPolynomial x₁ y₁ (W.slope x₁ x₂ y₁ y₂) =
-((X - C x₁) * (X - C x₂) * (X - C (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂))) := by
rw [addPolynomial_eq, neg_inj, Cubic.prod_X_sub_C_eq, Cubic.toPoly_injective]
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⟩
rw [equation_iff] at h₁ h₂
rw [slope_of_Y_ne rfl hy]
rw [negY, ← sub_ne_zero] at hy
ext
· rfl
· simp only [addX]
ring1
· field_simp [hy]
ring1
· linear_combination (norm := (field_simp [hy]; ring1)) -h₁
· rw [equation_iff] at h₁ h₂
rw [slope_of_X_ne hx]
rw [← sub_eq_zero] at hx
ext
· rfl
· simp only [addX]
ring1
· apply mul_right_injective₀ hx
linear_combination (norm := (field_simp [hx]; ring1)) h₂ - h₁
· apply mul_right_injective₀ hx
linear_combination (norm := (field_simp [hx]; ring1)) x₂ * h₁ - x₁ * h₂
/-- The negated addition of two affine points in `W` on a sloped line lies in `W`. -/
lemma equation_negAdd {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂)
(hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : W.Equation
(W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.negAddY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) := by
rw [equation_add_iff, addPolynomial_slope h₁ h₂ hxy]
eval_simp
rw [neg_eq_zero, sub_self, mul_zero]
/-- The addition of two affine points in `W` on a sloped line lies in `W`. -/
lemma equation_add {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂)
(hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) :
W.Equation (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.addY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) :=
(equation_neg ..).mpr <| equation_negAdd h₁ h₂ hxy
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₂)) : C (W.addPolynomial x₁ y₁ <| W.slope x₁ x₂ y₁ y₂) =
-(C (X - C x₁) * C (X - C x₂) * C (X - C (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂))) := by
rw [addPolynomial_slope h₁ h₂ hxy]
map_simp
lemma derivative_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₂)) :
derivative (W.addPolynomial x₁ y₁ <| W.slope x₁ x₂ y₁ y₂) =
-((X - C x₁) * (X - C x₂) + (X - C x₁) * (X - C (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂)) +
(X - C x₂) * (X - C (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂))) := by
rw [addPolynomial_slope h₁ h₂ hxy]
derivative_simp
ring1
/-- The negated addition of two nonsingular affine points in `W` on a sloped line is nonsingular. -/
lemma nonsingular_negAdd {x₁ x₂ y₁ y₂ : F} (h₁ : W.Nonsingular x₁ y₁) (h₂ : W.Nonsingular x₂ y₂)
(hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : W.Nonsingular
(W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.negAddY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) := by
by_cases hx₁ : W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂) = x₁
· rwa [negAddY, hx₁, sub_self, mul_zero, zero_add]
· by_cases hx₂ : W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂) = x₂
· by_cases hx : x₁ = x₂
· subst hx
contradiction
· rwa [negAddY, ← neg_sub, mul_neg, hx₂, slope_of_X_ne hx,
div_mul_cancel₀ _ <| sub_ne_zero_of_ne hx, neg_sub, sub_add_cancel]
· apply nonsingular_negAdd_of_eval_derivative_ne_zero <| equation_negAdd h₁.left h₂.left hxy
rw [derivative_addPolynomial_slope h₁.left h₂.left hxy]
eval_simp
simp only [neg_ne_zero, sub_self, mul_zero, add_zero]
exact mul_ne_zero (sub_ne_zero_of_ne hx₁) (sub_ne_zero_of_ne hx₂)
/-- The addition of two nonsingular affine points in `W` on a sloped line is nonsingular. -/
lemma nonsingular_add {x₁ x₂ y₁ y₂ : F} (h₁ : W.Nonsingular x₁ y₁) (h₂ : W.Nonsingular x₂ y₂)
(hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) :
W.Nonsingular (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.addY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) :=
(nonsingular_neg ..).mpr <| nonsingular_negAdd h₁ h₂ hxy
/-- The formula `x(P₁ + P₂) = x(P₁ - P₂) - ψ(P₁)ψ(P₂) / (x(P₂) - x(P₁))²`,
where `ψ(x,y) = 2y + a₁x + a₃`. -/
lemma addX_eq_addX_negY_sub {x₁ x₂ : F} (y₁ y₂ : F) (hx : x₁ ≠ x₂) :
W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂) = W.addX x₁ x₂ (W.slope x₁ x₂ y₁ <| W.negY x₂ y₂) -
(y₁ - W.negY x₁ y₁) * (y₂ - W.negY x₂ y₂) / (x₂ - x₁) ^ 2 := by
simp_rw [slope_of_X_ne hx, addX, negY, ← neg_sub x₁, neg_sq]
field_simp [sub_ne_zero.mpr hx]
ring1
/-- The formula `y(P₁)(x(P₂) - x(P₃)) + y(P₂)(x(P₃) - x(P₁)) + y(P₃)(x(P₁) - x(P₂)) = 0`,
assuming that `P₁ + P₂ + P₃ = O`. -/
lemma cyclic_sum_Y_mul_X_sub_X {x₁ x₂ : F} (y₁ y₂ : F) (hx : x₁ ≠ x₂) :
let x₃ := W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂)
y₁ * (x₂ - x₃) + y₂ * (x₃ - x₁) + W.negAddY x₁ x₂ y₁ (W.slope x₁ x₂ y₁ y₂) * (x₁ - x₂) = 0 := by
simp_rw [slope_of_X_ne hx, negAddY, addX]
field_simp [sub_ne_zero.mpr hx]
ring1
/-- The formula `ψ(P₁ + P₂) = (ψ(P₂)(x(P₁) - x(P₃)) - ψ(P₁)(x(P₂) - x(P₃))) / (x(P₂) - x(P₁))`,
where `ψ(x,y) = 2y + a₁x + a₃`. -/
lemma addY_sub_negY_addY {x₁ x₂ : F} (y₁ y₂ : F) (hx : x₁ ≠ x₂) :
let x₃ := W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂)
let y₃ := W.addY x₁ x₂ y₁ (W.slope x₁ x₂ y₁ y₂)
y₃ - W.negY x₃ y₃ =
((y₂ - W.negY x₂ y₂) * (x₁ - x₃) - (y₁ - W.negY x₁ y₁) * (x₂ - x₃)) / (x₂ - x₁) := by
simp_rw [addY, negY, eq_div_iff (sub_ne_zero.mpr hx.symm)]
linear_combination (norm := ring1) 2 * cyclic_sum_Y_mul_X_sub_X y₁ y₂ hx
end Field
section Group
/-! ### Nonsingular points -/
variable (W') in
/-- A nonsingular point on a Weierstrass curve `W` in affine coordinates. This is either the unique
point at infinity `WeierstrassCurve.Affine.Point.zero` or a nonsingular affine point
`WeierstrassCurve.Affine.Point.some (x, y)` satisfying the Weierstrass equation of `W`. -/
inductive Point
| zero
| some {x y : R} (h : W'.Nonsingular x y)
/-- For an algebraic extension `S` of a ring `R`, the type of nonsingular `S`-points on a
Weierstrass curve `W` over `R` in affine coordinates. -/
scoped notation3:max W' "⟮" S "⟯" => Affine.Point <| baseChange W' S
namespace Point
/-! ### Group operations -/
instance : Inhabited W'.Point :=
⟨.zero⟩
instance : Zero W'.Point :=
⟨.zero⟩
lemma zero_def : 0 = (.zero : W'.Point) :=
rfl
lemma some_ne_zero {x y : R} (h : W'.Nonsingular x y) : Point.some h ≠ 0 := by
rintro (_ | _)
/-- The negation of a nonsingular point on a Weierstrass curve in affine coordinates.
Given a nonsingular point `P` in affine coordinates, use `-P` instead of `neg P`. -/
def neg : W'.Point → W'.Point
| 0 => 0
| some h => some <| (nonsingular_neg ..).mpr h
instance : Neg W'.Point :=
⟨neg⟩
lemma neg_def (P : W'.Point) : -P = P.neg :=
rfl
@[simp]
lemma neg_zero : (-0 : W'.Point) = 0 :=
rfl
@[simp]
lemma neg_some {x y : R} (h : W'.Nonsingular x y) : -some h = some ((nonsingular_neg ..).mpr h) :=
rfl
instance : InvolutiveNeg W'.Point where
neg_neg := by
rintro (_ | _)
· rfl
· simp only [neg_some, negY_negY]
open Classical in
/-- The addition of two nonsingular points on a Weierstrass curve in affine coordinates.
Given two nonsingular points `P` and `Q` in affine coordinates, use `P + Q` instead of `add P Q`. -/
noncomputable def add : W.Point → W.Point → W.Point
| 0, P => P
| P, 0 => P
| @some _ _ _ x₁ y₁ h₁, @some _ _ _ x₂ y₂ h₂ =>
if hxy : x₁ = x₂ ∧ y₁ = W.negY x₂ y₂ then 0 else some <| nonsingular_add h₁ h₂ hxy
noncomputable instance : Add W.Point :=
⟨add⟩
noncomputable instance : AddZeroClass W.Point :=
⟨by rintro (_ | _) <;> rfl, by rintro (_ | _) <;> rfl⟩
lemma add_def (P Q : W.Point) : P + Q = P.add Q :=
rfl
lemma add_some {x₁ x₂ y₁ y₂ : F} (hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) {h₁ : W.Nonsingular x₁ y₁}
{h₂ : W.Nonsingular x₂ y₂} : some h₁ + some h₂ = some (nonsingular_add h₁ h₂ hxy) := by
simp only [add_def, add, dif_neg hxy]
@[deprecated (since := "2025-02-28")] alias add_of_imp := add_some
@[simp]
lemma add_of_Y_eq {x₁ x₂ y₁ y₂ : F} {h₁ : W.Nonsingular x₁ y₁} {h₂ : W.Nonsingular x₂ y₂}
(hx : x₁ = x₂) (hy : y₁ = W.negY x₂ y₂) : some h₁ + some h₂ = 0 := by
simpa only [add_def, add] using dif_pos ⟨hx, hy⟩
@[simp]
lemma add_self_of_Y_eq {x₁ y₁ : F} {h₁ : W.Nonsingular x₁ y₁} (hy : y₁ = W.negY x₁ y₁) :
some h₁ + some h₁ = 0 :=
add_of_Y_eq rfl hy
@[simp]
lemma add_of_Y_ne {x₁ x₂ y₁ y₂ : F} {h₁ : W.Nonsingular x₁ y₁} {h₂ : W.Nonsingular x₂ y₂}
(hy : y₁ ≠ W.negY x₂ y₂) :
some h₁ + some h₂ = some (nonsingular_add h₁ h₂ fun hxy => hy hxy.right) :=
add_some fun hxy => hy hxy.right
lemma add_of_Y_ne' {x₁ x₂ y₁ y₂ : F} {h₁ : W.Nonsingular x₁ y₁} {h₂ : W.Nonsingular x₂ y₂}
(hy : y₁ ≠ W.negY x₂ y₂) :
some h₁ + some h₂ = -some (nonsingular_negAdd h₁ h₂ fun hxy => hy hxy.right) :=
add_of_Y_ne hy
@[simp]
lemma add_self_of_Y_ne {x₁ y₁ : F} {h₁ : W.Nonsingular x₁ y₁} (hy : y₁ ≠ W.negY x₁ y₁) :
some h₁ + some h₁ = some (nonsingular_add h₁ h₁ fun hxy => hy hxy.right) :=
add_of_Y_ne hy
lemma add_self_of_Y_ne' {x₁ y₁ : F} {h₁ : W.Nonsingular x₁ y₁} (hy : y₁ ≠ W.negY x₁ y₁) :
some h₁ + some h₁ = -some (nonsingular_negAdd h₁ h₁ fun hxy => hy hxy.right) :=
add_of_Y_ne hy
@[simp]
lemma add_of_X_ne {x₁ x₂ y₁ y₂ : F} {h₁ : W.Nonsingular x₁ y₁} {h₂ : W.Nonsingular x₂ y₂}
(hx : x₁ ≠ x₂) : some h₁ + some h₂ = some (nonsingular_add h₁ h₂ fun hxy => hx hxy.left) :=
add_some fun hxy => hx hxy.left
lemma add_of_X_ne' {x₁ x₂ y₁ y₂ : F} {h₁ : W.Nonsingular x₁ y₁} {h₂ : W.Nonsingular x₂ y₂}
(hx : x₁ ≠ x₂) : some h₁ + some h₂ = -some (nonsingular_negAdd h₁ h₂ fun hxy => hx hxy.left) :=
add_of_X_ne hx
end Point
end Group
section Map
/-! ### Maps across ring homomorphisms -/
variable (f : R →+* S) (x y x₁ y₁ x₂ y₂ ℓ : R)
lemma map_polynomial : (W'.map f).toAffine.polynomial = W'.polynomial.map (mapRingHom f) := by
simp only [polynomial]
map_simp
lemma evalEval_baseChange_polynomial :
(W'.baseChange R[X][Y]).toAffine.polynomial.evalEval (C X) Y = W'.polynomial := by
rw [map_polynomial, evalEval, eval_map, eval_C_X_eval₂_map_C_X]
@[deprecated (since := "2025-03-05")] alias evalEval_baseChange_polynomial_X_Y :=
evalEval_baseChange_polynomial
variable {x y} in
lemma Equation.map {x y : R} (h : W'.Equation x y) : (W'.map f).toAffine.Equation (f x) (f y) := by
rw [Equation, map_polynomial, map_mapRingHom_evalEval, h, map_zero]
variable {f} in
lemma map_equation (hf : Function.Injective f) :
(W'.map f).toAffine.Equation (f x) (f y) ↔ W'.Equation x y := by
simp only [Equation, map_polynomial, map_mapRingHom_evalEval, map_eq_zero_iff f hf]
lemma map_polynomialX : (W'.map f).toAffine.polynomialX = W'.polynomialX.map (mapRingHom f) := by
simp only [polynomialX]
map_simp
lemma map_polynomialY : (W'.map f).toAffine.polynomialY = W'.polynomialY.map (mapRingHom f) := by
simp only [polynomialY]
map_simp
variable {f} in
lemma map_nonsingular (hf : Function.Injective f) :
(W'.map f).toAffine.Nonsingular (f x) (f y) ↔ W'.Nonsingular x y := by
simp only [Nonsingular, evalEval, map_equation _ _ hf, map_polynomialX, map_polynomialY,
map_mapRingHom_evalEval, map_ne_zero_iff f hf]
lemma map_negPolynomial :
(W'.map f).toAffine.negPolynomial = W'.negPolynomial.map (mapRingHom f) := by
simp only [negPolynomial]
map_simp
lemma map_negY : (W'.map f).toAffine.negY (f x) (f y) = f (W'.negY x y) := by
simp only [negY]
map_simp
lemma map_linePolynomial : linePolynomial (f x) (f y) (f ℓ) = (linePolynomial x y ℓ).map f := by
simp only [linePolynomial]
map_simp
lemma map_addPolynomial :
(W'.map f).toAffine.addPolynomial (f x) (f y) (f ℓ) = (W'.addPolynomial x y ℓ).map f := by
rw [addPolynomial, map_polynomial, eval_map, linePolynomial, addPolynomial, ← coe_mapRingHom,
← eval₂_hom, linePolynomial]
map_simp
lemma map_addX : (W'.map f).toAffine.addX (f x₁) (f x₂) (f ℓ) = f (W'.addX x₁ x₂ ℓ) := by
simp only [addX]
map_simp
lemma map_negAddY :
(W'.map f).toAffine.negAddY (f x₁) (f x₂) (f y₁) (f ℓ) = f (W'.negAddY x₁ x₂ y₁ ℓ) := by
simp only [negAddY, map_addX]
map_simp
lemma map_addY :
(W'.map f).toAffine.addY (f x₁) (f x₂) (f y₁) (f ℓ) = f (W'.toAffine.addY x₁ x₂ y₁ ℓ) := by
simp only [addY, map_negAddY, map_addX, map_negY]
lemma map_slope (f : F →+* K) (x₁ x₂ y₁ y₂ : F) :
(W.map f).toAffine.slope (f x₁) (f x₂) (f y₁) (f y₂) = f (W.slope x₁ x₂ y₁ y₂) := by
by_cases hx : x₁ = x₂
· by_cases hy : y₁ = W.negY x₂ y₂
· rw [slope_of_Y_eq (congr_arg f hx) <| by rw [hy, map_negY], slope_of_Y_eq hx hy, map_zero]
· rw [slope_of_Y_ne (congr_arg f hx) <| map_negY f x₂ y₂ ▸ fun h => hy <| f.injective h,
map_negY, slope_of_Y_ne hx hy]
map_simp
· rw [slope_of_X_ne fun h => hx <| f.injective h, slope_of_X_ne hx]
map_simp
end Map
section BaseChange
/-! ### Base changes across algebra homomorphisms -/
variable [Algebra R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] [Algebra R B] [Algebra S B]
[IsScalarTower R S B] (f : A →ₐ[S] B) (x y x₁ y₁ x₂ y₂ ℓ : A)
lemma baseChange_polynomial : (W'.baseChange B).toAffine.polynomial =
(W'.baseChange A).toAffine.polynomial.map (mapRingHom f) := by
rw [← map_polynomial, map_baseChange]
variable {x y} in
lemma Equation.baseChange (h : (W'.baseChange A).toAffine.Equation x y) :
(W'.baseChange B).toAffine.Equation (f x) (f y) := by
convert Equation.map f.toRingHom h using 1
rw [AlgHom.toRingHom_eq_coe, map_baseChange]
variable {f} in
lemma baseChange_equation (hf : Function.Injective f) :
(W'.baseChange B).toAffine.Equation (f x) (f y) ↔ (W'.baseChange A).toAffine.Equation x y := by
rw [← map_equation _ _ hf, AlgHom.toRingHom_eq_coe, map_baseChange, RingHom.coe_coe]
lemma baseChange_polynomialX : (W'.baseChange B).toAffine.polynomialX =
(W'.baseChange A).toAffine.polynomialX.map (mapRingHom f) := by
rw [← map_polynomialX, map_baseChange]
lemma baseChange_polynomialY : (W'.baseChange B).toAffine.polynomialY =
(W'.baseChange A).toAffine.polynomialY.map (mapRingHom f) := by
rw [← map_polynomialY, map_baseChange]
variable {f} in
lemma baseChange_nonsingular (hf : Function.Injective f) :
(W'.baseChange B).toAffine.Nonsingular (f x) (f y) ↔
(W'.baseChange A).toAffine.Nonsingular x y := by
rw [← map_nonsingular _ _ hf, AlgHom.toRingHom_eq_coe, map_baseChange, RingHom.coe_coe]
lemma baseChange_negPolynomial : (W'.baseChange B).toAffine.negPolynomial =
(W'.baseChange A).toAffine.negPolynomial.map (mapRingHom f) := by
rw [← map_negPolynomial, map_baseChange]
lemma baseChange_negY :
(W'.baseChange B).toAffine.negY (f x) (f y) = f ((W'.baseChange A).toAffine.negY x y) := by
rw [← RingHom.coe_coe, ← map_negY, map_baseChange]
lemma baseChange_addPolynomial : (W'.baseChange B).toAffine.addPolynomial (f x) (f y) (f ℓ) =
((W'.baseChange A).toAffine.addPolynomial x y ℓ).map f := by
rw [← RingHom.coe_coe, ← map_addPolynomial, map_baseChange]
lemma baseChange_addX : (W'.baseChange B).toAffine.addX (f x₁) (f x₂) (f ℓ) =
f ((W'.baseChange A).toAffine.addX x₁ x₂ ℓ) := by
rw [← RingHom.coe_coe, ← map_addX, map_baseChange]
lemma baseChange_negAddY : (W'.baseChange B).toAffine.negAddY (f x₁) (f x₂) (f y₁) (f ℓ) =
f ((W'.baseChange A).toAffine.negAddY x₁ x₂ y₁ ℓ) := by
rw [← RingHom.coe_coe, ← map_negAddY, map_baseChange]
lemma baseChange_addY : (W'.baseChange B).toAffine.addY (f x₁) (f x₂) (f y₁) (f ℓ) =
f ((W'.baseChange A).toAffine.addY x₁ x₂ y₁ ℓ) := by
rw [← RingHom.coe_coe, ← map_addY, map_baseChange]
lemma baseChange_slope [Algebra R F] [Algebra S F] [IsScalarTower R S F] [Algebra R K] [Algebra S K]
[IsScalarTower R S K] (f : F →ₐ[S] K) (x₁ x₂ y₁ y₂ : F) :
(W'.baseChange K).toAffine.slope (f x₁) (f x₂) (f y₁) (f y₂) =
f ((W'.baseChange F).toAffine.slope x₁ x₂ y₁ y₂) := by
rw [← RingHom.coe_coe, ← map_slope, map_baseChange]
end BaseChange
namespace Point
variable [Algebra R S] [Algebra R F] [Algebra S F] [IsScalarTower R S F] [Algebra R K] [Algebra S K]
[IsScalarTower R S K] [Algebra R L] [Algebra S L] [IsScalarTower R S L] (f : F →ₐ[S] K)
(g : K →ₐ[S] L)
/-- The group homomorphism from `W⟮F⟯` to `W⟮K⟯` induced by an algebra homomorphism `f : F →ₐ[S] K`,
where `W` is defined over a subring of a ring `S`, and `F` and `K` are field extensions of `S`. -/
def map : W'⟮F⟯ →+ W'⟮K⟯ where
toFun P := match P with
| 0 => 0
| some h => some <| (baseChange_nonsingular _ _ f.injective).mpr h
map_zero' := rfl
map_add' := by
rintro (_ | @⟨x₁, y₁, _⟩) (_ | @⟨x₂, y₂, _⟩)
any_goals rfl
by_cases hxy : x₁ = x₂ ∧ y₁ = (W'.baseChange F).toAffine.negY x₂ y₂
· simp only [add_of_Y_eq hxy.left hxy.right]
rw [add_of_Y_eq (congr_arg _ hxy.left) <| by rw [hxy.right, baseChange_negY]]
· simp only [add_some hxy, ← baseChange_addX, ← baseChange_addY, ← baseChange_slope]
rw [add_some fun h => hxy ⟨f.injective h.1, f.injective (W'.baseChange_negY f .. ▸ h).2⟩]
@[deprecated (since := "2025-03-01")] alias mapFun := map
lemma map_zero : map f (0 : W'⟮F⟯) = 0 :=
rfl
lemma map_some {x y : F} (h : (W'.baseChange F).toAffine.Nonsingular x y) :
map f (some h) = some ((W'.baseChange_nonsingular _ _ f.injective).mpr h) :=
rfl
lemma map_id (P : W'⟮F⟯) : map (Algebra.ofId F F) P = P := by
cases P <;> rfl
lemma map_map (P : W'⟮F⟯) : map g (map f P) = map (g.comp f) P := by
cases P <;> rfl
lemma map_injective : Function.Injective <| map (W' := W') f := by
rintro (_ | _) (_ | _) h
any_goals contradiction
· rfl
· simpa only [some.injEq] using ⟨f.injective (some.inj h).left, f.injective (some.inj h).right⟩
variable (F K) in
/-- The group homomorphism from `W⟮F⟯` to `W⟮K⟯` induced by the base change from `F` to `K`, where
`W` is defined over a subring of a ring `S`, and `F` and `K` are field extensions of `S`. -/
abbrev baseChange [Algebra F K] [IsScalarTower R F K] : W'⟮F⟯ →+ W'⟮K⟯ :=
map <| Algebra.ofId F K
lemma map_baseChange [Algebra F K] [IsScalarTower R F K] [Algebra F L] [IsScalarTower R F L]
(f : K →ₐ[F] L) (P : W'⟮F⟯) : map f (baseChange F K P) = baseChange F L P := by
have : Subsingleton (F →ₐ[F] L) := inferInstance
convert map_map (Algebra.ofId F K) f P
end Point
end Affine
end WeierstrassCurve
| Mathlib/AlgebraicGeometry/EllipticCurve/Affine.lean | 1,050 | 1,051 | |
/-
Copyright (c) 2020 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne, Sébastien Gouëzel
-/
import Mathlib.Analysis.NormedSpace.IndicatorFunction
import Mathlib.Data.Fintype.Order
import Mathlib.MeasureTheory.Function.AEEqFun
import Mathlib.MeasureTheory.Function.LpSeminorm.Defs
import Mathlib.MeasureTheory.Function.SpecialFunctions.Basic
import Mathlib.MeasureTheory.Integral.Lebesgue.Countable
import Mathlib.MeasureTheory.Integral.Lebesgue.Sub
/-!
# Basic theorems about ℒp space
-/
noncomputable section
open TopologicalSpace MeasureTheory Filter
open scoped NNReal ENNReal Topology ComplexConjugate
variable {α ε ε' E F G : Type*} {m m0 : MeasurableSpace α} {p : ℝ≥0∞} {q : ℝ} {μ ν : Measure α}
[NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G] [ENorm ε] [ENorm ε']
namespace MeasureTheory
section Lp
section Top
theorem MemLp.eLpNorm_lt_top [TopologicalSpace ε] {f : α → ε} (hfp : MemLp f p μ) :
eLpNorm f p μ < ∞ :=
hfp.2
@[deprecated (since := "2025-02-21")]
alias Memℒp.eLpNorm_lt_top := MemLp.eLpNorm_lt_top
theorem MemLp.eLpNorm_ne_top [TopologicalSpace ε] {f : α → ε} (hfp : MemLp f p μ) :
eLpNorm f p μ ≠ ∞ :=
ne_of_lt hfp.2
@[deprecated (since := "2025-02-21")]
alias Memℒp.eLpNorm_ne_top := MemLp.eLpNorm_ne_top
theorem lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top {f : α → ε} (hq0_lt : 0 < q)
(hfq : eLpNorm' f q μ < ∞) : ∫⁻ a, ‖f a‖ₑ ^ q ∂μ < ∞ := by
rw [lintegral_rpow_enorm_eq_rpow_eLpNorm' hq0_lt]
exact ENNReal.rpow_lt_top_of_nonneg (le_of_lt hq0_lt) (ne_of_lt hfq)
@[deprecated (since := "2025-01-17")]
alias lintegral_rpow_nnnorm_lt_top_of_eLpNorm'_lt_top' :=
lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top
theorem lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top {f : α → ε} (hp_ne_zero : p ≠ 0)
(hp_ne_top : p ≠ ∞) (hfp : eLpNorm f p μ < ∞) : ∫⁻ a, ‖f a‖ₑ ^ p.toReal ∂μ < ∞ := by
apply lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top
· exact ENNReal.toReal_pos hp_ne_zero hp_ne_top
· simpa [eLpNorm_eq_eLpNorm' hp_ne_zero hp_ne_top] using hfp
@[deprecated (since := "2025-01-17")]
alias lintegral_rpow_nnnorm_lt_top_of_eLpNorm_lt_top :=
lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top
theorem eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top {f : α → ε} (hp_ne_zero : p ≠ 0)
(hp_ne_top : p ≠ ∞) : eLpNorm f p μ < ∞ ↔ ∫⁻ a, (‖f a‖ₑ) ^ p.toReal ∂μ < ∞ :=
⟨lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top hp_ne_zero hp_ne_top, by
intro h
have hp' := ENNReal.toReal_pos hp_ne_zero hp_ne_top
have : 0 < 1 / p.toReal := div_pos zero_lt_one hp'
simpa [eLpNorm_eq_lintegral_rpow_enorm hp_ne_zero hp_ne_top] using
ENNReal.rpow_lt_top_of_nonneg (le_of_lt this) (ne_of_lt h)⟩
@[deprecated (since := "2025-02-04")] alias
eLpNorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top := eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top
end Top
section Zero
@[simp]
theorem eLpNorm'_exponent_zero {f : α → ε} : eLpNorm' f 0 μ = 1 := by
rw [eLpNorm', div_zero, ENNReal.rpow_zero]
@[simp]
theorem eLpNorm_exponent_zero {f : α → ε} : eLpNorm f 0 μ = 0 := by simp [eLpNorm]
@[simp]
theorem memLp_zero_iff_aestronglyMeasurable [TopologicalSpace ε] {f : α → ε} :
MemLp f 0 μ ↔ AEStronglyMeasurable f μ := by simp [MemLp, eLpNorm_exponent_zero]
@[deprecated (since := "2025-02-21")]
alias memℒp_zero_iff_aestronglyMeasurable := memLp_zero_iff_aestronglyMeasurable
section ENormedAddMonoid
variable {ε : Type*} [TopologicalSpace ε] [ENormedAddMonoid ε]
@[simp]
theorem eLpNorm'_zero (hp0_lt : 0 < q) : eLpNorm' (0 : α → ε) q μ = 0 := by
simp [eLpNorm'_eq_lintegral_enorm, hp0_lt]
@[simp]
theorem eLpNorm'_zero' (hq0_ne : q ≠ 0) (hμ : μ ≠ 0) : eLpNorm' (0 : α → ε) q μ = 0 := by
rcases le_or_lt 0 q with hq0 | hq_neg
· exact eLpNorm'_zero (lt_of_le_of_ne hq0 hq0_ne.symm)
· simp [eLpNorm'_eq_lintegral_enorm, ENNReal.rpow_eq_zero_iff, hμ, hq_neg]
@[simp]
theorem eLpNormEssSup_zero : eLpNormEssSup (0 : α → ε) μ = 0 := by
simp [eLpNormEssSup, ← bot_eq_zero', essSup_const_bot]
@[simp]
theorem eLpNorm_zero : eLpNorm (0 : α → ε) p μ = 0 := by
by_cases h0 : p = 0
· simp [h0]
by_cases h_top : p = ∞
· simp only [h_top, eLpNorm_exponent_top, eLpNormEssSup_zero]
rw [← Ne] at h0
simp [eLpNorm_eq_eLpNorm' h0 h_top, ENNReal.toReal_pos h0 h_top]
@[simp]
theorem eLpNorm_zero' : eLpNorm (fun _ : α => (0 : ε)) p μ = 0 := eLpNorm_zero
@[simp] lemma MemLp.zero : MemLp (0 : α → ε) p μ :=
⟨aestronglyMeasurable_zero, by rw [eLpNorm_zero]; exact ENNReal.coe_lt_top⟩
@[simp] lemma MemLp.zero' : MemLp (fun _ : α => (0 : ε)) p μ := MemLp.zero
@[deprecated (since := "2025-02-21")]
alias Memℒp.zero' := MemLp.zero'
@[deprecated (since := "2025-01-21")] alias zero_memℒp := MemLp.zero
@[deprecated (since := "2025-01-21")] alias zero_mem_ℒp := MemLp.zero'
variable [MeasurableSpace α]
theorem eLpNorm'_measure_zero_of_pos {f : α → ε} (hq_pos : 0 < q) :
eLpNorm' f q (0 : Measure α) = 0 := by simp [eLpNorm', hq_pos]
theorem eLpNorm'_measure_zero_of_exponent_zero {f : α → ε} : eLpNorm' f 0 (0 : Measure α) = 1 := by
simp [eLpNorm']
theorem eLpNorm'_measure_zero_of_neg {f : α → ε} (hq_neg : q < 0) :
eLpNorm' f q (0 : Measure α) = ∞ := by simp [eLpNorm', hq_neg]
end ENormedAddMonoid
@[simp]
theorem eLpNormEssSup_measure_zero {f : α → ε} : eLpNormEssSup f (0 : Measure α) = 0 := by
simp [eLpNormEssSup]
@[simp]
theorem eLpNorm_measure_zero {f : α → ε} : eLpNorm f p (0 : Measure α) = 0 := by
by_cases h0 : p = 0
· simp [h0]
by_cases h_top : p = ∞
· simp [h_top]
rw [← Ne] at h0
simp [eLpNorm_eq_eLpNorm' h0 h_top, eLpNorm', ENNReal.toReal_pos h0 h_top]
section ContinuousENorm
variable {ε : Type*} [TopologicalSpace ε] [ContinuousENorm ε]
@[simp] lemma memLp_measure_zero {f : α → ε} : MemLp f p (0 : Measure α) := by
simp [MemLp]
@[deprecated (since := "2025-02-21")]
alias memℒp_measure_zero := memLp_measure_zero
end ContinuousENorm
end Zero
section Neg
@[simp]
theorem eLpNorm'_neg (f : α → F) (q : ℝ) (μ : Measure α) : eLpNorm' (-f) q μ = eLpNorm' f q μ := by
simp [eLpNorm'_eq_lintegral_enorm]
@[simp]
theorem eLpNorm_neg (f : α → F) (p : ℝ≥0∞) (μ : Measure α) : eLpNorm (-f) p μ = eLpNorm f p μ := by
by_cases h0 : p = 0
· simp [h0]
by_cases h_top : p = ∞
· simp [h_top, eLpNormEssSup_eq_essSup_enorm]
simp [eLpNorm_eq_eLpNorm' h0 h_top]
lemma eLpNorm_sub_comm (f g : α → E) (p : ℝ≥0∞) (μ : Measure α) :
eLpNorm (f - g) p μ = eLpNorm (g - f) p μ := by simp [← eLpNorm_neg (f := f - g)]
theorem MemLp.neg {f : α → E} (hf : MemLp f p μ) : MemLp (-f) p μ :=
⟨AEStronglyMeasurable.neg hf.1, by simp [hf.right]⟩
@[deprecated (since := "2025-02-21")]
alias Memℒp.neg := MemLp.neg
theorem memLp_neg_iff {f : α → E} : MemLp (-f) p μ ↔ MemLp f p μ :=
⟨fun h => neg_neg f ▸ h.neg, MemLp.neg⟩
@[deprecated (since := "2025-02-21")]
alias memℒp_neg_iff := memLp_neg_iff
end Neg
section Const
variable {ε' ε'' : Type*} [TopologicalSpace ε'] [ContinuousENorm ε']
[TopologicalSpace ε''] [ENormedAddMonoid ε'']
theorem eLpNorm'_const (c : ε) (hq_pos : 0 < q) :
eLpNorm' (fun _ : α => c) q μ = ‖c‖ₑ * μ Set.univ ^ (1 / q) := by
rw [eLpNorm'_eq_lintegral_enorm, lintegral_const,
ENNReal.mul_rpow_of_nonneg _ _ (by simp [hq_pos.le] : 0 ≤ 1 / q)]
congr
rw [← ENNReal.rpow_mul]
suffices hq_cancel : q * (1 / q) = 1 by rw [hq_cancel, ENNReal.rpow_one]
rw [one_div, mul_inv_cancel₀ (ne_of_lt hq_pos).symm]
-- Generalising this to ENormedAddMonoid requires a case analysis whether ‖c‖ₑ = ⊤,
-- and will happen in a future PR.
theorem eLpNorm'_const' [IsFiniteMeasure μ] (c : F) (hc_ne_zero : c ≠ 0) (hq_ne_zero : q ≠ 0) :
eLpNorm' (fun _ : α => c) q μ = ‖c‖ₑ * μ Set.univ ^ (1 / q) := by
rw [eLpNorm'_eq_lintegral_enorm, lintegral_const,
ENNReal.mul_rpow_of_ne_top _ (measure_ne_top μ Set.univ)]
· congr
rw [← ENNReal.rpow_mul]
suffices hp_cancel : q * (1 / q) = 1 by rw [hp_cancel, ENNReal.rpow_one]
rw [one_div, mul_inv_cancel₀ hq_ne_zero]
· rw [Ne, ENNReal.rpow_eq_top_iff, not_or, not_and_or, not_and_or]
simp [hc_ne_zero]
theorem eLpNormEssSup_const (c : ε) (hμ : μ ≠ 0) : eLpNormEssSup (fun _ : α => c) μ = ‖c‖ₑ := by
rw [eLpNormEssSup_eq_essSup_enorm, essSup_const _ hμ]
theorem eLpNorm'_const_of_isProbabilityMeasure (c : ε) (hq_pos : 0 < q) [IsProbabilityMeasure μ] :
eLpNorm' (fun _ : α => c) q μ = ‖c‖ₑ := by simp [eLpNorm'_const c hq_pos, measure_univ]
theorem eLpNorm_const (c : ε) (h0 : p ≠ 0) (hμ : μ ≠ 0) :
eLpNorm (fun _ : α => c) p μ = ‖c‖ₑ * μ Set.univ ^ (1 / ENNReal.toReal p) := by
by_cases h_top : p = ∞
· simp [h_top, eLpNormEssSup_const c hμ]
simp [eLpNorm_eq_eLpNorm' h0 h_top, eLpNorm'_const, ENNReal.toReal_pos h0 h_top]
theorem eLpNorm_const' (c : ε) (h0 : p ≠ 0) (h_top : p ≠ ∞) :
eLpNorm (fun _ : α => c) p μ = ‖c‖ₑ * μ Set.univ ^ (1 / ENNReal.toReal p) := by
simp [eLpNorm_eq_eLpNorm' h0 h_top, eLpNorm'_const, ENNReal.toReal_pos h0 h_top]
-- NB. If ‖c‖ₑ = ∞ and μ is finite, this claim is false: the right has side is true,
-- but the left hand side is false (as the norm is infinite).
theorem eLpNorm_const_lt_top_iff_enorm {c : ε''} (hc' : ‖c‖ₑ ≠ ∞)
{p : ℝ≥0∞} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) :
eLpNorm (fun _ : α ↦ c) p μ < ∞ ↔ c = 0 ∨ μ Set.univ < ∞ := by
have hp : 0 < p.toReal := ENNReal.toReal_pos hp_ne_zero hp_ne_top
by_cases hμ : μ = 0
· simp only [hμ, Measure.coe_zero, Pi.zero_apply, or_true, ENNReal.zero_lt_top,
eLpNorm_measure_zero]
by_cases hc : c = 0
· simp only [hc, true_or, eq_self_iff_true, ENNReal.zero_lt_top, eLpNorm_zero']
rw [eLpNorm_const' c hp_ne_zero hp_ne_top]
obtain hμ_top | hμ_ne_top := eq_or_ne (μ .univ) ∞
· simp [hc, hμ_top, hp]
rw [ENNReal.mul_lt_top_iff]
simpa [hμ, hc, hμ_ne_top, hμ_ne_top.lt_top, hc, hc'.lt_top] using
ENNReal.rpow_lt_top_of_nonneg (inv_nonneg.mpr hp.le) hμ_ne_top
theorem eLpNorm_const_lt_top_iff {p : ℝ≥0∞} {c : F} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) :
eLpNorm (fun _ : α => c) p μ < ∞ ↔ c = 0 ∨ μ Set.univ < ∞ :=
eLpNorm_const_lt_top_iff_enorm enorm_ne_top hp_ne_zero hp_ne_top
theorem memLp_const_enorm {c : ε'} (hc : ‖c‖ₑ ≠ ⊤) [IsFiniteMeasure μ] :
MemLp (fun _ : α ↦ c) p μ := by
refine ⟨aestronglyMeasurable_const, ?_⟩
by_cases h0 : p = 0
· simp [h0]
by_cases hμ : μ = 0
· simp [hμ]
rw [eLpNorm_const c h0 hμ]
exact ENNReal.mul_lt_top hc.lt_top (ENNReal.rpow_lt_top_of_nonneg (by simp)
(measure_ne_top μ Set.univ))
theorem memLp_const (c : E) [IsFiniteMeasure μ] : MemLp (fun _ : α => c) p μ :=
memLp_const_enorm enorm_ne_top
@[deprecated (since := "2025-02-21")]
alias memℒp_const := memLp_const
theorem memLp_top_const_enorm {c : ε'} (hc : ‖c‖ₑ ≠ ⊤) :
MemLp (fun _ : α ↦ c) ∞ μ :=
⟨aestronglyMeasurable_const, by by_cases h : μ = 0 <;> simp [eLpNorm_const _, h, hc.lt_top]⟩
theorem memLp_top_const (c : E) : MemLp (fun _ : α => c) ∞ μ :=
memLp_top_const_enorm enorm_ne_top
@[deprecated (since := "2025-02-21")]
alias memℒp_top_const := memLp_top_const
theorem memLp_const_iff_enorm
{p : ℝ≥0∞} {c : ε''} (hc : ‖c‖ₑ ≠ ⊤) (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) :
MemLp (fun _ : α ↦ c) p μ ↔ c = 0 ∨ μ Set.univ < ∞ := by
simp_all [MemLp, aestronglyMeasurable_const,
eLpNorm_const_lt_top_iff_enorm hc hp_ne_zero hp_ne_top]
theorem memLp_const_iff {p : ℝ≥0∞} {c : E} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) :
MemLp (fun _ : α => c) p μ ↔ c = 0 ∨ μ Set.univ < ∞ :=
memLp_const_iff_enorm enorm_ne_top hp_ne_zero hp_ne_top
@[deprecated (since := "2025-02-21")]
alias memℒp_const_iff := memLp_const_iff
end Const
variable {f : α → F}
lemma eLpNorm'_mono_enorm_ae {f : α → ε} {g : α → ε'} (hq : 0 ≤ q) (h : ∀ᵐ x ∂μ, ‖f x‖ₑ ≤ ‖g x‖ₑ) :
eLpNorm' f q μ ≤ eLpNorm' g q μ := by
simp only [eLpNorm'_eq_lintegral_enorm]
gcongr ?_ ^ (1/q)
refine lintegral_mono_ae (h.mono fun x hx => ?_)
gcongr
lemma eLpNorm'_mono_nnnorm_ae {f : α → F} {g : α → G} (hq : 0 ≤ q) (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) :
eLpNorm' f q μ ≤ eLpNorm' g q μ := by
simp only [eLpNorm'_eq_lintegral_enorm]
gcongr ?_ ^ (1/q)
refine lintegral_mono_ae (h.mono fun x hx => ?_)
dsimp [enorm]
gcongr
theorem eLpNorm'_mono_ae {f : α → F} {g : α → G} (hq : 0 ≤ q) (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) :
eLpNorm' f q μ ≤ eLpNorm' g q μ :=
eLpNorm'_mono_enorm_ae hq (by simpa only [enorm_le_iff_norm_le] using h)
theorem eLpNorm'_congr_enorm_ae {f g : α → ε} (hfg : ∀ᵐ x ∂μ, ‖f x‖ₑ = ‖g x‖ₑ) :
eLpNorm' f q μ = eLpNorm' g q μ := by
have : (‖f ·‖ₑ ^ q) =ᵐ[μ] (‖g ·‖ₑ ^ q) := hfg.mono fun x hx ↦ by simp [hx]
simp only [eLpNorm'_eq_lintegral_enorm, lintegral_congr_ae this]
theorem eLpNorm'_congr_nnnorm_ae {f g : α → F} (hfg : ∀ᵐ x ∂μ, ‖f x‖₊ = ‖g x‖₊) :
eLpNorm' f q μ = eLpNorm' g q μ := by
have : (‖f ·‖ₑ ^ q) =ᵐ[μ] (‖g ·‖ₑ ^ q) := hfg.mono fun x hx ↦ by simp [enorm, hx]
simp only [eLpNorm'_eq_lintegral_enorm, lintegral_congr_ae this]
theorem eLpNorm'_congr_norm_ae {f g : α → F} (hfg : ∀ᵐ x ∂μ, ‖f x‖ = ‖g x‖) :
eLpNorm' f q μ = eLpNorm' g q μ :=
eLpNorm'_congr_nnnorm_ae <| hfg.mono fun _x hx => NNReal.eq hx
theorem eLpNorm'_congr_ae {f g : α → ε} (hfg : f =ᵐ[μ] g) : eLpNorm' f q μ = eLpNorm' g q μ :=
eLpNorm'_congr_enorm_ae (hfg.fun_comp _)
theorem eLpNormEssSup_congr_ae {f g : α → ε} (hfg : f =ᵐ[μ] g) :
eLpNormEssSup f μ = eLpNormEssSup g μ :=
essSup_congr_ae (hfg.fun_comp enorm)
theorem eLpNormEssSup_mono_enorm_ae {f g : α → ε} (hfg : ∀ᵐ x ∂μ, ‖f x‖ₑ ≤ ‖g x‖ₑ) :
eLpNormEssSup f μ ≤ eLpNormEssSup g μ :=
essSup_mono_ae <| hfg
theorem eLpNormEssSup_mono_nnnorm_ae {f g : α → F} (hfg : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) :
eLpNormEssSup f μ ≤ eLpNormEssSup g μ :=
essSup_mono_ae <| hfg.mono fun _x hx => ENNReal.coe_le_coe.mpr hx
theorem eLpNorm_mono_enorm_ae {f : α → ε} {g : α → ε'} (h : ∀ᵐ x ∂μ, ‖f x‖ₑ ≤ ‖g x‖ₑ) :
eLpNorm f p μ ≤ eLpNorm g p μ := by
simp only [eLpNorm]
split_ifs
· exact le_rfl
· exact essSup_mono_ae h
· exact eLpNorm'_mono_enorm_ae ENNReal.toReal_nonneg h
theorem eLpNorm_mono_nnnorm_ae {f : α → F} {g : α → G} (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) :
eLpNorm f p μ ≤ eLpNorm g p μ := by
simp only [eLpNorm]
split_ifs
· exact le_rfl
· exact essSup_mono_ae (h.mono fun x hx => ENNReal.coe_le_coe.mpr hx)
· exact eLpNorm'_mono_nnnorm_ae ENNReal.toReal_nonneg h
theorem eLpNorm_mono_ae {f : α → F} {g : α → G} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) :
eLpNorm f p μ ≤ eLpNorm g p μ :=
eLpNorm_mono_enorm_ae (by simpa only [enorm_le_iff_norm_le] using h)
theorem eLpNorm_mono_ae' {ε' : Type*} [ENorm ε']
{f : α → ε} {g : α → ε'} (h : ∀ᵐ x ∂μ, ‖f x‖ₑ ≤ ‖g x‖ₑ) :
eLpNorm f p μ ≤ eLpNorm g p μ :=
eLpNorm_mono_enorm_ae (by simpa only [enorm_le_iff_norm_le] using h)
theorem eLpNorm_mono_ae_real {f : α → F} {g : α → ℝ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ g x) :
eLpNorm f p μ ≤ eLpNorm g p μ :=
eLpNorm_mono_ae <| h.mono fun _x hx =>
hx.trans ((le_abs_self _).trans (Real.norm_eq_abs _).symm.le)
theorem eLpNorm_mono_enorm {f : α → ε} {g : α → ε'} (h : ∀ x, ‖f x‖ₑ ≤ ‖g x‖ₑ) :
eLpNorm f p μ ≤ eLpNorm g p μ :=
eLpNorm_mono_enorm_ae (Eventually.of_forall h)
theorem eLpNorm_mono_nnnorm {f : α → F} {g : α → G} (h : ∀ x, ‖f x‖₊ ≤ ‖g x‖₊) :
eLpNorm f p μ ≤ eLpNorm g p μ :=
eLpNorm_mono_nnnorm_ae (Eventually.of_forall h)
theorem eLpNorm_mono {f : α → F} {g : α → G} (h : ∀ x, ‖f x‖ ≤ ‖g x‖) :
eLpNorm f p μ ≤ eLpNorm g p μ :=
eLpNorm_mono_ae (Eventually.of_forall h)
theorem eLpNorm_mono_real {f : α → F} {g : α → ℝ} (h : ∀ x, ‖f x‖ ≤ g x) :
eLpNorm f p μ ≤ eLpNorm g p μ :=
eLpNorm_mono_ae_real (Eventually.of_forall h)
theorem eLpNormEssSup_le_of_ae_enorm_bound {f : α → ε} {C : ℝ≥0∞} (hfC : ∀ᵐ x ∂μ, ‖f x‖ₑ ≤ C) :
eLpNormEssSup f μ ≤ C :=
essSup_le_of_ae_le C hfC
theorem eLpNormEssSup_le_of_ae_nnnorm_bound {f : α → F} {C : ℝ≥0} (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) :
eLpNormEssSup f μ ≤ C :=
essSup_le_of_ae_le (C : ℝ≥0∞) <| hfC.mono fun _x hx => ENNReal.coe_le_coe.mpr hx
theorem eLpNormEssSup_le_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) :
eLpNormEssSup f μ ≤ ENNReal.ofReal C :=
eLpNormEssSup_le_of_ae_nnnorm_bound <| hfC.mono fun _x hx => hx.trans C.le_coe_toNNReal
theorem eLpNormEssSup_lt_top_of_ae_enorm_bound {f : α → ε} {C : ℝ≥0} (hfC : ∀ᵐ x ∂μ, ‖f x‖ₑ ≤ C) :
eLpNormEssSup f μ < ∞ :=
(eLpNormEssSup_le_of_ae_enorm_bound hfC).trans_lt ENNReal.coe_lt_top
theorem eLpNormEssSup_lt_top_of_ae_nnnorm_bound {f : α → F} {C : ℝ≥0} (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) :
eLpNormEssSup f μ < ∞ :=
(eLpNormEssSup_le_of_ae_nnnorm_bound hfC).trans_lt ENNReal.coe_lt_top
theorem eLpNormEssSup_lt_top_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) :
eLpNormEssSup f μ < ∞ :=
(eLpNormEssSup_le_of_ae_bound hfC).trans_lt ENNReal.ofReal_lt_top
theorem eLpNorm_le_of_ae_enorm_bound {ε} [TopologicalSpace ε] [ENormedAddMonoid ε]
{f : α → ε} {C : ℝ≥0∞} (hfC : ∀ᵐ x ∂μ, ‖f x‖ₑ ≤ C) :
eLpNorm f p μ ≤ C • μ Set.univ ^ p.toReal⁻¹ := by
rcases eq_zero_or_neZero μ with rfl | hμ
· simp
by_cases hp : p = 0
· simp [hp]
have : ∀ᵐ x ∂μ, ‖f x‖ₑ ≤ ‖C‖ₑ := hfC.mono fun x hx ↦ hx.trans (Preorder.le_refl C)
refine (eLpNorm_mono_enorm_ae this).trans_eq ?_
rw [eLpNorm_const _ hp (NeZero.ne μ), one_div, enorm_eq_self, smul_eq_mul]
theorem eLpNorm_le_of_ae_nnnorm_bound {f : α → F} {C : ℝ≥0} (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) :
eLpNorm f p μ ≤ C • μ Set.univ ^ p.toReal⁻¹ := by
rcases eq_zero_or_neZero μ with rfl | hμ
· simp
by_cases hp : p = 0
· simp [hp]
have : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖(C : ℝ)‖₊ := hfC.mono fun x hx => hx.trans_eq C.nnnorm_eq.symm
refine (eLpNorm_mono_ae this).trans_eq ?_
rw [eLpNorm_const _ hp (NeZero.ne μ), C.enorm_eq, one_div, ENNReal.smul_def, smul_eq_mul]
theorem eLpNorm_le_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) :
eLpNorm f p μ ≤ μ Set.univ ^ p.toReal⁻¹ * ENNReal.ofReal C := by
rw [← mul_comm]
exact eLpNorm_le_of_ae_nnnorm_bound (hfC.mono fun x hx => hx.trans C.le_coe_toNNReal)
theorem eLpNorm_congr_enorm_ae {f : α → ε} {g : α → ε'} (hfg : ∀ᵐ x ∂μ, ‖f x‖ₑ = ‖g x‖ₑ) :
eLpNorm f p μ = eLpNorm g p μ :=
le_antisymm (eLpNorm_mono_enorm_ae <| EventuallyEq.le hfg)
(eLpNorm_mono_enorm_ae <| (EventuallyEq.symm hfg).le)
theorem eLpNorm_congr_nnnorm_ae {f : α → F} {g : α → G} (hfg : ∀ᵐ x ∂μ, ‖f x‖₊ = ‖g x‖₊) :
eLpNorm f p μ = eLpNorm g p μ :=
le_antisymm (eLpNorm_mono_nnnorm_ae <| EventuallyEq.le hfg)
(eLpNorm_mono_nnnorm_ae <| (EventuallyEq.symm hfg).le)
theorem eLpNorm_congr_norm_ae {f : α → F} {g : α → G} (hfg : ∀ᵐ x ∂μ, ‖f x‖ = ‖g x‖) :
eLpNorm f p μ = eLpNorm g p μ :=
eLpNorm_congr_nnnorm_ae <| hfg.mono fun _x hx => NNReal.eq hx
open scoped symmDiff in
theorem eLpNorm_indicator_sub_indicator (s t : Set α) (f : α → E) :
eLpNorm (s.indicator f - t.indicator f) p μ = eLpNorm ((s ∆ t).indicator f) p μ :=
eLpNorm_congr_norm_ae <| ae_of_all _ fun x ↦ by simp [Set.apply_indicator_symmDiff norm_neg]
@[simp]
theorem eLpNorm'_norm {f : α → F} : eLpNorm' (fun a => ‖f a‖) q μ = eLpNorm' f q μ := by
simp [eLpNorm'_eq_lintegral_enorm]
@[simp]
theorem eLpNorm'_enorm {f : α → ε} : eLpNorm' (fun a => ‖f a‖ₑ) q μ = eLpNorm' f q μ := by
simp [eLpNorm'_eq_lintegral_enorm]
@[simp]
theorem eLpNorm_norm (f : α → F) : eLpNorm (fun x => ‖f x‖) p μ = eLpNorm f p μ :=
eLpNorm_congr_norm_ae <| Eventually.of_forall fun _ => norm_norm _
@[simp]
theorem eLpNorm_enorm (f : α → ε) : eLpNorm (fun x ↦ ‖f x‖ₑ) p μ = eLpNorm f p μ :=
eLpNorm_congr_enorm_ae <| Eventually.of_forall fun _ => enorm_enorm _
theorem eLpNorm'_norm_rpow (f : α → F) (p q : ℝ) (hq_pos : 0 < q) :
eLpNorm' (fun x => ‖f x‖ ^ q) p μ = eLpNorm' f (p * q) μ ^ q := by
simp_rw [eLpNorm', ← ENNReal.rpow_mul, ← one_div_mul_one_div, one_div,
mul_assoc, inv_mul_cancel₀ hq_pos.ne.symm, mul_one, ← ofReal_norm_eq_enorm,
Real.norm_eq_abs, abs_eq_self.mpr (Real.rpow_nonneg (norm_nonneg _) _), mul_comm p,
← ENNReal.ofReal_rpow_of_nonneg (norm_nonneg _) hq_pos.le, ENNReal.rpow_mul]
theorem eLpNorm_norm_rpow (f : α → F) (hq_pos : 0 < q) :
eLpNorm (fun x => ‖f x‖ ^ q) p μ = eLpNorm f (p * ENNReal.ofReal q) μ ^ q := by
by_cases h0 : p = 0
· simp [h0, ENNReal.zero_rpow_of_pos hq_pos]
by_cases hp_top : p = ∞
· simp only [hp_top, eLpNorm_exponent_top, ENNReal.top_mul', hq_pos.not_le,
ENNReal.ofReal_eq_zero, if_false, eLpNorm_exponent_top, eLpNormEssSup_eq_essSup_enorm]
have h_rpow : essSup (‖‖f ·‖ ^ q‖ₑ) μ = essSup (‖f ·‖ₑ ^ q) μ := by
congr
ext1 x
conv_rhs => rw [← enorm_norm]
rw [← Real.enorm_rpow_of_nonneg (norm_nonneg _) hq_pos.le]
rw [h_rpow]
have h_rpow_mono := ENNReal.strictMono_rpow_of_pos hq_pos
have h_rpow_surj := (ENNReal.rpow_left_bijective hq_pos.ne.symm).2
let iso := h_rpow_mono.orderIsoOfSurjective _ h_rpow_surj
exact (iso.essSup_apply (fun x => ‖f x‖ₑ) μ).symm
rw [eLpNorm_eq_eLpNorm' h0 hp_top, eLpNorm_eq_eLpNorm' _ _]
swap
· refine mul_ne_zero h0 ?_
rwa [Ne, ENNReal.ofReal_eq_zero, not_le]
swap; · exact ENNReal.mul_ne_top hp_top ENNReal.ofReal_ne_top
rw [ENNReal.toReal_mul, ENNReal.toReal_ofReal hq_pos.le]
exact eLpNorm'_norm_rpow f p.toReal q hq_pos
theorem eLpNorm_congr_ae {f g : α → ε} (hfg : f =ᵐ[μ] g) : eLpNorm f p μ = eLpNorm g p μ :=
eLpNorm_congr_enorm_ae <| hfg.mono fun _x hx => hx ▸ rfl
theorem memLp_congr_ae [TopologicalSpace ε] {f g : α → ε} (hfg : f =ᵐ[μ] g) :
MemLp f p μ ↔ MemLp g p μ := by
simp only [MemLp, eLpNorm_congr_ae hfg, aestronglyMeasurable_congr hfg]
@[deprecated (since := "2025-02-21")]
alias memℒp_congr_ae := memLp_congr_ae
theorem MemLp.ae_eq [TopologicalSpace ε] {f g : α → ε} (hfg : f =ᵐ[μ] g) (hf_Lp : MemLp f p μ) :
MemLp g p μ :=
(memLp_congr_ae hfg).1 hf_Lp
@[deprecated (since := "2025-02-21")]
alias Memℒp.ae_eq := MemLp.ae_eq
theorem MemLp.of_le {f : α → E} {g : α → F} (hg : MemLp g p μ) (hf : AEStronglyMeasurable f μ)
(hfg : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) : MemLp f p μ :=
⟨hf, (eLpNorm_mono_ae hfg).trans_lt hg.eLpNorm_lt_top⟩
@[deprecated (since := "2025-02-21")] alias Memℒp.of_le := MemLp.of_le
alias MemLp.mono := MemLp.of_le
@[deprecated (since := "2025-02-21")] alias Memℒp.mono := MemLp.mono
theorem MemLp.mono' {f : α → E} {g : α → ℝ} (hg : MemLp g p μ) (hf : AEStronglyMeasurable f μ)
(h : ∀ᵐ a ∂μ, ‖f a‖ ≤ g a) : MemLp f p μ :=
hg.mono hf <| h.mono fun _x hx => le_trans hx (le_abs_self _)
@[deprecated (since := "2025-02-21")]
alias Memℒp.mono' := MemLp.mono'
theorem MemLp.congr_norm {f : α → E} {g : α → F} (hf : MemLp f p μ) (hg : AEStronglyMeasurable g μ)
(h : ∀ᵐ a ∂μ, ‖f a‖ = ‖g a‖) : MemLp g p μ :=
hf.mono hg <| EventuallyEq.le <| EventuallyEq.symm h
@[deprecated (since := "2025-02-21")]
alias Memℒp.congr_norm := MemLp.congr_norm
theorem memLp_congr_norm {f : α → E} {g : α → F} (hf : AEStronglyMeasurable f μ)
(hg : AEStronglyMeasurable g μ) (h : ∀ᵐ a ∂μ, ‖f a‖ = ‖g a‖) : MemLp f p μ ↔ MemLp g p μ :=
⟨fun h2f => h2f.congr_norm hg h, fun h2g => h2g.congr_norm hf <| EventuallyEq.symm h⟩
@[deprecated (since := "2025-02-21")]
alias memℒp_congr_norm := memLp_congr_norm
theorem memLp_top_of_bound {f : α → E} (hf : AEStronglyMeasurable f μ) (C : ℝ)
(hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : MemLp f ∞ μ :=
⟨hf, by
rw [eLpNorm_exponent_top]
exact eLpNormEssSup_lt_top_of_ae_bound hfC⟩
@[deprecated (since := "2025-02-21")]
alias memℒp_top_of_bound := memLp_top_of_bound
theorem MemLp.of_bound [IsFiniteMeasure μ] {f : α → E} (hf : AEStronglyMeasurable f μ) (C : ℝ)
(hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : MemLp f p μ :=
(memLp_const C).of_le hf (hfC.mono fun _x hx => le_trans hx (le_abs_self _))
@[deprecated (since := "2025-02-21")]
alias Memℒp.of_bound := MemLp.of_bound
theorem memLp_of_bounded [IsFiniteMeasure μ]
{a b : ℝ} {f : α → ℝ} (h : ∀ᵐ x ∂μ, f x ∈ Set.Icc a b)
(hX : AEStronglyMeasurable f μ) (p : ENNReal) : MemLp f p μ :=
have ha : ∀ᵐ x ∂μ, a ≤ f x := h.mono fun ω h => h.1
have hb : ∀ᵐ x ∂μ, f x ≤ b := h.mono fun ω h => h.2
(memLp_const (max |a| |b|)).mono' hX (by filter_upwards [ha, hb] with x using abs_le_max_abs_abs)
@[deprecated (since := "2025-02-21")]
alias memℒp_of_bounded := memLp_of_bounded
@[gcongr, mono]
theorem eLpNorm'_mono_measure (f : α → ε) (hμν : ν ≤ μ) (hq : 0 ≤ q) :
eLpNorm' f q ν ≤ eLpNorm' f q μ := by
simp_rw [eLpNorm']
gcongr
exact lintegral_mono' hμν le_rfl
@[gcongr, mono]
theorem eLpNormEssSup_mono_measure (f : α → ε) (hμν : ν ≪ μ) :
eLpNormEssSup f ν ≤ eLpNormEssSup f μ := by
simp_rw [eLpNormEssSup]
exact essSup_mono_measure hμν
@[gcongr, mono]
theorem eLpNorm_mono_measure (f : α → ε) (hμν : ν ≤ μ) : eLpNorm f p ν ≤ eLpNorm f p μ := by
by_cases hp0 : p = 0
· simp [hp0]
by_cases hp_top : p = ∞
· simp [hp_top, eLpNormEssSup_mono_measure f (Measure.absolutelyContinuous_of_le hμν)]
simp_rw [eLpNorm_eq_eLpNorm' hp0 hp_top]
exact eLpNorm'_mono_measure f hμν ENNReal.toReal_nonneg
theorem MemLp.mono_measure [TopologicalSpace ε] {f : α → ε} (hμν : ν ≤ μ) (hf : MemLp f p μ) :
MemLp f p ν :=
⟨hf.1.mono_measure hμν, (eLpNorm_mono_measure f hμν).trans_lt hf.2⟩
@[deprecated (since := "2025-02-21")]
alias Memℒp.mono_measure := MemLp.mono_measure
section Indicator
variable {ε : Type*} [TopologicalSpace ε] [ENormedAddMonoid ε]
| {c : ε} {hf : AEStronglyMeasurable f μ} {s : Set α}
lemma eLpNorm_indicator_eq_eLpNorm_restrict {f : α → ε} {s : Set α} (hs : MeasurableSet s) :
eLpNorm (s.indicator f) p μ = eLpNorm f p (μ.restrict s) := by
by_cases hp_zero : p = 0
· simp only [hp_zero, eLpNorm_exponent_zero]
by_cases hp_top : p = ∞
· simp_rw [hp_top, eLpNorm_exponent_top, eLpNormEssSup_eq_essSup_enorm,
enorm_indicator_eq_indicator_enorm, ENNReal.essSup_indicator_eq_essSup_restrict hs]
simp_rw [eLpNorm_eq_lintegral_rpow_enorm hp_zero hp_top]
suffices (∫⁻ x, (‖s.indicator f x‖ₑ) ^ p.toReal ∂μ) =
∫⁻ x in s, ‖f x‖ₑ ^ p.toReal ∂μ by rw [this]
rw [← lintegral_indicator hs]
congr
simp_rw [enorm_indicator_eq_indicator_enorm]
| Mathlib/MeasureTheory/Function/LpSeminorm/Basic.lean | 634 | 648 |
/-
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]
theorem realize_restrictVar' [DecidableEq α] {t : L.Term α} {s : Set α} (h : ↑t.varFinset ⊆ s)
{v : α → M} : (t.restrictVar (Set.inclusion h)).realize (v ∘ (↑)) = t.realize v :=
realize_restrictVar _ (by simp)
theorem realize_restrictVarLeft [DecidableEq α] {γ : Type*} {t : L.Term (α ⊕ γ)}
{f : t.varFinsetLeft → β}
{xs : β ⊕ γ → M} (xs' : α → M) (hxs' : ∀ a, xs (Sum.inl (f a)) = xs' a) :
(t.restrictVarLeft f).realize xs = t.realize (Sum.elim xs' (xs ∘ Sum.inr)) := by
induction t with
| var a => cases a <;> simp [restrictVarLeft, hxs']
| func _ _ ih =>
exact congr rfl (funext fun i => ih i (by simp [hxs']))
/-- A special case of `realize_restrictVarLeft`, included because we can add the `simp` attribute
to it -/
@[simp]
theorem realize_restrictVarLeft' [DecidableEq α] {γ : Type*} {t : L.Term (α ⊕ γ)} {s : Set α}
(h : ↑t.varFinsetLeft ⊆ s) {v : α → M} {xs : γ → M} :
(t.restrictVarLeft (Set.inclusion h)).realize (Sum.elim (v ∘ (↑)) xs) =
t.realize (Sum.elim v xs) :=
realize_restrictVarLeft _ (by simp)
@[simp]
theorem realize_constantsToVars [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M]
{t : L[[α]].Term β} {v : β → M} :
t.constantsToVars.realize (Sum.elim (fun a => ↑(L.con a)) v) = t.realize v := by
induction t with
| var => simp
| @func n f ts ih =>
cases n
· cases f
· simp only [realize, ih, constantsOn, constantsOnFunc, constantsToVars]
-- Porting note: below lemma does not work with simp for some reason
rw [withConstants_funMap_sumInl]
· simp only [realize, constantsToVars, Sum.elim_inl, funMap_eq_coe_constants]
rfl
· obtain - | f := f
· simp only [realize, ih, constantsOn, constantsOnFunc, constantsToVars]
-- Porting note: below lemma does not work with simp for some reason
rw [withConstants_funMap_sumInl]
· exact isEmptyElim f
@[simp]
theorem realize_varsToConstants [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M]
{t : L.Term (α ⊕ β)} {v : β → M} :
t.varsToConstants.realize v = t.realize (Sum.elim (fun a => ↑(L.con a)) v) := by
induction t with
| var ab => rcases ab with a | b <;> simp [Language.con]
| func f ts ih =>
simp only [realize, constantsOn, constantsOnFunc, ih, varsToConstants]
-- Porting note: below lemma does not work with simp for some reason
rw [withConstants_funMap_sumInl]
theorem realize_constantsVarsEquivLeft [L[[α]].Structure M]
[(lhomWithConstants L α).IsExpansionOn M] {n} {t : L[[α]].Term (β ⊕ (Fin n))} {v : β → M}
{xs : Fin n → M} :
(constantsVarsEquivLeft t).realize (Sum.elim (Sum.elim (fun a => ↑(L.con a)) v) xs) =
t.realize (Sum.elim v xs) := by
simp only [constantsVarsEquivLeft, realize_relabel, Equiv.coe_trans, Function.comp_apply,
constantsVarsEquiv_apply, relabelEquiv_symm_apply]
refine _root_.trans ?_ realize_constantsToVars
rcongr x
rcases x with (a | (b | i)) <;> simp
end Term
namespace LHom
@[simp]
theorem realize_onTerm [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (t : L.Term α)
(v : α → M) : (φ.onTerm t).realize v = t.realize v := by
induction t with
| var => rfl
| func f ts ih => simp only [Term.realize, LHom.onTerm, LHom.map_onFunction, ih]
end LHom
@[simp]
theorem HomClass.realize_term {F : Type*} [FunLike F M N] [HomClass L F M N]
(g : F) {t : L.Term α} {v : α → M} :
t.realize (g ∘ v) = g (t.realize v) := by
induction t
· rfl
· rw [Term.realize, Term.realize, HomClass.map_fun]
refine congr rfl ?_
ext x
simp [*]
variable {n : ℕ}
namespace BoundedFormula
open Term
/-- A bounded formula can be evaluated as true or false by giving values to each free variable. -/
def Realize : ∀ {l} (_f : L.BoundedFormula α l) (_v : α → M) (_xs : Fin l → M), Prop
| _, falsum, _v, _xs => False
| _, equal t₁ t₂, v, xs => t₁.realize (Sum.elim v xs) = t₂.realize (Sum.elim v xs)
| _, rel R ts, v, xs => RelMap R fun i => (ts i).realize (Sum.elim v xs)
| _, imp f₁ f₂, v, xs => Realize f₁ v xs → Realize f₂ v xs
| _, all f, v, xs => ∀ x : M, Realize f v (snoc xs x)
variable {l : ℕ} {φ ψ : L.BoundedFormula α l} {θ : L.BoundedFormula α l.succ}
variable {v : α → M} {xs : Fin l → M}
@[simp]
theorem realize_bot : (⊥ : L.BoundedFormula α l).Realize v xs ↔ False :=
Iff.rfl
@[simp]
theorem realize_not : φ.not.Realize v xs ↔ ¬φ.Realize v xs :=
Iff.rfl
@[simp]
theorem realize_bdEqual (t₁ t₂ : L.Term (α ⊕ (Fin l))) :
(t₁.bdEqual t₂).Realize v xs ↔ t₁.realize (Sum.elim v xs) = t₂.realize (Sum.elim v xs) :=
Iff.rfl
@[simp]
theorem realize_top : (⊤ : L.BoundedFormula α l).Realize v xs ↔ True := by simp [Top.top]
@[simp]
theorem realize_inf : (φ ⊓ ψ).Realize v xs ↔ φ.Realize v xs ∧ ψ.Realize v xs := by
simp [Inf.inf, Realize]
@[simp]
theorem realize_foldr_inf (l : List (L.BoundedFormula α n)) (v : α → M) (xs : Fin n → M) :
(l.foldr (· ⊓ ·) ⊤).Realize v xs ↔ ∀ φ ∈ l, BoundedFormula.Realize φ v xs := by
induction' l with φ l ih
· simp
· simp [ih]
@[simp]
theorem realize_imp : (φ.imp ψ).Realize v xs ↔ φ.Realize v xs → ψ.Realize v xs := by
simp only [Realize]
@[simp]
theorem realize_rel {k : ℕ} {R : L.Relations k} {ts : Fin k → L.Term _} :
(R.boundedFormula ts).Realize v xs ↔ RelMap R fun i => (ts i).realize (Sum.elim v xs) :=
Iff.rfl
@[simp]
theorem realize_rel₁ {R : L.Relations 1} {t : L.Term _} :
(R.boundedFormula₁ t).Realize v xs ↔ RelMap R ![t.realize (Sum.elim v xs)] := by
rw [Relations.boundedFormula₁, realize_rel, iff_eq_eq]
refine congr rfl (funext fun _ => ?_)
simp only [Matrix.cons_val_fin_one]
@[simp]
theorem realize_rel₂ {R : L.Relations 2} {t₁ t₂ : L.Term _} :
(R.boundedFormula₂ t₁ t₂).Realize v xs ↔
RelMap R ![t₁.realize (Sum.elim v xs), t₂.realize (Sum.elim v xs)] := by
rw [Relations.boundedFormula₂, realize_rel, iff_eq_eq]
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]
@[simp]
theorem realize_sup : (φ ⊔ ψ).Realize v xs ↔ φ.Realize v xs ∨ ψ.Realize v xs := by
simp only [realize, max, realize_not, eq_iff_iff]
tauto
@[simp]
theorem realize_foldr_sup (l : List (L.BoundedFormula α n)) (v : α → M) (xs : Fin n → M) :
(l.foldr (· ⊔ ·) ⊥).Realize v xs ↔ ∃ φ ∈ l, BoundedFormula.Realize φ v xs := by
induction' l with φ l ih
· simp
· simp_rw [List.foldr_cons, realize_sup, ih, List.mem_cons, or_and_right, exists_or,
exists_eq_left]
@[simp]
theorem realize_all : (all θ).Realize v xs ↔ ∀ a : M, θ.Realize v (Fin.snoc xs a) :=
Iff.rfl
@[simp]
theorem realize_ex : θ.ex.Realize v xs ↔ ∃ a : M, θ.Realize v (Fin.snoc xs a) := by
rw [BoundedFormula.ex, realize_not, realize_all, not_forall]
simp_rw [realize_not, Classical.not_not]
@[simp]
theorem realize_iff : (φ.iff ψ).Realize v xs ↔ (φ.Realize v xs ↔ ψ.Realize v xs) := by
simp only [BoundedFormula.iff, realize_inf, realize_imp, and_imp, ← iff_def]
theorem realize_castLE_of_eq {m n : ℕ} (h : m = n) {h' : m ≤ n} {φ : L.BoundedFormula α m}
{v : α → M} {xs : Fin n → M} : (φ.castLE h').Realize v xs ↔ φ.Realize v (xs ∘ Fin.cast h) := by
subst h
simp only [castLE_rfl, cast_refl, OrderIso.coe_refl, Function.comp_id]
theorem realize_mapTermRel_id [L'.Structure M]
{ft : ∀ n, L.Term (α ⊕ (Fin n)) → L'.Term (β ⊕ (Fin n))}
{fr : ∀ n, L.Relations n → L'.Relations n} {n} {φ : L.BoundedFormula α n} {v : α → M}
{v' : β → M} {xs : Fin n → M}
(h1 :
∀ (n) (t : L.Term (α ⊕ (Fin n))) (xs : Fin n → M),
(ft n t).realize (Sum.elim v' xs) = t.realize (Sum.elim v xs))
(h2 : ∀ (n) (R : L.Relations n) (x : Fin n → M), RelMap (fr n R) x = RelMap R x) :
(φ.mapTermRel ft fr fun _ => id).Realize v' xs ↔ φ.Realize v xs := by
induction φ with
| falsum => rfl
| equal => simp [mapTermRel, Realize, h1]
| rel => simp [mapTermRel, Realize, h1, h2]
| imp _ _ ih1 ih2 => simp [mapTermRel, Realize, ih1, ih2]
| all _ ih => simp only [mapTermRel, Realize, ih, id]
theorem realize_mapTermRel_add_castLe [L'.Structure M] {k : ℕ}
{ft : ∀ n, L.Term (α ⊕ (Fin n)) → L'.Term (β ⊕ (Fin (k + n)))}
{fr : ∀ n, L.Relations n → L'.Relations n} {n} {φ : L.BoundedFormula α n}
(v : ∀ {n}, (Fin (k + n) → M) → α → M) {v' : β → M} (xs : Fin (k + n) → M)
(h1 :
∀ (n) (t : L.Term (α ⊕ (Fin n))) (xs' : Fin (k + n) → M),
(ft n t).realize (Sum.elim v' xs') = t.realize (Sum.elim (v xs') (xs' ∘ Fin.natAdd _)))
(h2 : ∀ (n) (R : L.Relations n) (x : Fin n → M), RelMap (fr n R) x = RelMap R x)
(hv : ∀ (n) (xs : Fin (k + n) → M) (x : M), @v (n + 1) (snoc xs x : Fin _ → M) = v xs) :
(φ.mapTermRel ft fr fun _ => castLE (add_assoc _ _ _).symm.le).Realize v' xs ↔
φ.Realize (v xs) (xs ∘ Fin.natAdd _) := by
induction φ with
| falsum => rfl
| equal => simp [mapTermRel, Realize, h1]
| rel => simp [mapTermRel, Realize, h1, h2]
| imp _ _ ih1 ih2 => simp [mapTermRel, Realize, ih1, ih2]
| all _ ih => simp [mapTermRel, Realize, ih, hv]
@[simp]
theorem realize_relabel {m n : ℕ} {φ : L.BoundedFormula α n} {g : α → β ⊕ (Fin m)} {v : β → M}
{xs : Fin (m + n) → M} :
(φ.relabel g).Realize v xs ↔
φ.Realize (Sum.elim v (xs ∘ Fin.castAdd n) ∘ g) (xs ∘ Fin.natAdd m) := by
apply realize_mapTermRel_add_castLe <;> simp
theorem realize_liftAt {n n' m : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + n') → M}
(hmn : m + n' ≤ n + 1) :
(φ.liftAt n' m).Realize v xs ↔
φ.Realize v (xs ∘ fun i => if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') := by
rw [liftAt]
induction φ with
| falsum => simp [mapTermRel, Realize]
| equal => simp [mapTermRel, Realize, realize_rel, realize_liftAt, Sum.elim_comp_map]
| rel => simp [mapTermRel, Realize, realize_rel, realize_liftAt, Sum.elim_comp_map]
| imp _ _ ih1 ih2 => simp only [mapTermRel, Realize, ih1 hmn, ih2 hmn]
| @all k _ ih3 =>
have h : k + 1 + n' = k + n' + 1 := by rw [add_assoc, add_comm 1 n', ← add_assoc]
simp only [mapTermRel, Realize, realize_castLE_of_eq h, ih3 (hmn.trans k.succ.le_succ)]
refine forall_congr' fun x => iff_eq_eq.mpr (congr rfl (funext (Fin.lastCases ?_ fun i => ?_)))
· simp only [Function.comp_apply, val_last, snoc_last]
refine (congr rfl (Fin.ext ?_)).trans (snoc_last _ _)
split_ifs <;> dsimp; omega
· simp only [Function.comp_apply, Fin.snoc_castSucc]
refine (congr rfl (Fin.ext ?_)).trans (snoc_castSucc _ _ _)
simp only [coe_castSucc, coe_cast]
split_ifs <;> simp
theorem realize_liftAt_one {n m : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + 1) → M}
(hmn : m ≤ n) :
(φ.liftAt 1 m).Realize v xs ↔
φ.Realize v (xs ∘ fun i => if ↑i < m then castSucc i else i.succ) := by
simp [realize_liftAt (add_le_add_right hmn 1), castSucc]
@[simp]
theorem realize_liftAt_one_self {n : ℕ} {φ : L.BoundedFormula α n} {v : α → M}
{xs : Fin (n + 1) → M} : (φ.liftAt 1 n).Realize v xs ↔ φ.Realize v (xs ∘ castSucc) := by
rw [realize_liftAt_one (refl n), iff_eq_eq]
refine congr rfl (congr rfl (funext fun i => ?_))
rw [if_pos i.is_lt]
@[simp]
theorem realize_subst {φ : L.BoundedFormula α n} {tf : α → L.Term β} {v : β → M} {xs : Fin n → M} :
(φ.subst tf).Realize v xs ↔ φ.Realize (fun a => (tf a).realize v) xs :=
realize_mapTermRel_id
(fun n t x => by
rw [Term.realize_subst]
rcongr a
cases a
· simp only [Sum.elim_inl, Function.comp_apply, Term.realize_relabel, Sum.elim_comp_inl]
· rfl)
(by simp)
theorem realize_restrictFreeVar [DecidableEq α] {n : ℕ} {φ : L.BoundedFormula α n}
{f : φ.freeVarFinset → β} {v : β → M} {xs : Fin n → M}
(v' : α → M) (hv' : ∀ a, v (f a) = v' a) :
(φ.restrictFreeVar f).Realize v xs ↔ φ.Realize v' xs := by
induction φ with
| falsum => rfl
| equal =>
simp only [Realize, restrictFreeVar, freeVarFinset.eq_2]
rw [realize_restrictVarLeft v' (by simp [hv']), realize_restrictVarLeft v' (by simp [hv'])]
simp [Function.comp_apply]
| rel =>
simp only [Realize, freeVarFinset.eq_3, Finset.biUnion_val, restrictFreeVar]
congr!
rw [realize_restrictVarLeft v' (by simp [hv'])]
simp [Function.comp_apply]
| imp _ _ ih1 ih2 =>
simp only [Realize, restrictFreeVar, freeVarFinset.eq_4]
rw [ih1, ih2] <;> simp [hv']
| all _ ih3 =>
simp only [restrictFreeVar, Realize]
refine forall_congr' (fun _ => ?_)
rw [ih3]; simp [hv']
/-- A special case of `realize_restrictFreeVar`, included because we can add the `simp` attribute
to it -/
@[simp]
theorem realize_restrictFreeVar' [DecidableEq α] {n : ℕ} {φ : L.BoundedFormula α n} {s : Set α}
(h : ↑φ.freeVarFinset ⊆ s) {v : α → M} {xs : Fin n → M} :
(φ.restrictFreeVar (Set.inclusion h)).Realize (v ∘ (↑)) xs ↔ φ.Realize v xs :=
realize_restrictFreeVar _ (by simp)
theorem realize_constantsVarsEquiv [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M]
{n} {φ : L[[α]].BoundedFormula β n} {v : β → M} {xs : Fin n → M} :
(constantsVarsEquiv φ).Realize (Sum.elim (fun a => ↑(L.con a)) v) xs ↔ φ.Realize v xs := by
refine realize_mapTermRel_id (fun n t xs => realize_constantsVarsEquivLeft) fun n R xs => ?_
-- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
erw [← (lhomWithConstants L α).map_onRelation
(Equiv.sumEmpty (L.Relations n) ((constantsOn α).Relations n) R) xs]
rcongr
obtain - | R := R
· simp
· exact isEmptyElim R
@[simp]
theorem realize_relabelEquiv {g : α ≃ β} {k} {φ : L.BoundedFormula α k} {v : β → M}
{xs : Fin k → M} : (relabelEquiv g φ).Realize v xs ↔ φ.Realize (v ∘ g) xs := by
simp only [relabelEquiv, mapTermRelEquiv_apply, Equiv.coe_refl]
refine realize_mapTermRel_id (fun n t xs => ?_) fun _ _ _ => rfl
simp only [relabelEquiv_apply, Term.realize_relabel]
refine congr (congr rfl ?_) rfl
ext (i | i) <;> rfl
variable [Nonempty M]
theorem realize_all_liftAt_one_self {n : ℕ} {φ : L.BoundedFormula α n} {v : α → M}
{xs : Fin n → M} : (φ.liftAt 1 n).all.Realize v xs ↔ φ.Realize v xs := by
inhabit M
simp only [realize_all, realize_liftAt_one_self]
refine ⟨fun h => ?_, fun h a => ?_⟩
· refine (congr rfl (funext fun i => ?_)).mp (h default)
simp
· refine (congr rfl (funext fun i => ?_)).mp h
simp
end BoundedFormula
namespace LHom
open BoundedFormula
@[simp]
theorem realize_onBoundedFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] {n : ℕ}
(ψ : L.BoundedFormula α n) {v : α → M} {xs : Fin n → M} :
(φ.onBoundedFormula ψ).Realize v xs ↔ ψ.Realize v xs := by
induction ψ with
| falsum => rfl
| equal => simp only [onBoundedFormula, realize_bdEqual, realize_onTerm]; rfl
| rel =>
simp only [onBoundedFormula, realize_rel, LHom.map_onRelation,
Function.comp_apply, realize_onTerm]
rfl
| imp _ _ ih1 ih2 => simp only [onBoundedFormula, ih1, ih2, realize_imp]
| all _ ih3 => simp only [onBoundedFormula, ih3, realize_all]
end LHom
namespace Formula
/-- A formula can be evaluated as true or false by giving values to each free variable. -/
nonrec def Realize (φ : L.Formula α) (v : α → M) : Prop :=
φ.Realize v default
variable {φ ψ : L.Formula α} {v : α → M}
@[simp]
theorem realize_not : φ.not.Realize v ↔ ¬φ.Realize v :=
Iff.rfl
@[simp]
theorem realize_bot : (⊥ : L.Formula α).Realize v ↔ False :=
Iff.rfl
@[simp]
theorem realize_top : (⊤ : L.Formula α).Realize v ↔ True :=
BoundedFormula.realize_top
@[simp]
theorem realize_inf : (φ ⊓ ψ).Realize v ↔ φ.Realize v ∧ ψ.Realize v :=
BoundedFormula.realize_inf
@[simp]
theorem realize_imp : (φ.imp ψ).Realize v ↔ φ.Realize v → ψ.Realize v :=
BoundedFormula.realize_imp
@[simp]
theorem realize_rel {k : ℕ} {R : L.Relations k} {ts : Fin k → L.Term α} :
(R.formula ts).Realize v ↔ RelMap R fun i => (ts i).realize v :=
BoundedFormula.realize_rel.trans (by simp)
@[simp]
theorem realize_rel₁ {R : L.Relations 1} {t : L.Term _} :
(R.formula₁ t).Realize v ↔ RelMap R ![t.realize v] := by
rw [Relations.formula₁, realize_rel, iff_eq_eq]
refine congr rfl (funext fun _ => ?_)
simp only [Matrix.cons_val_fin_one]
@[simp]
theorem realize_rel₂ {R : L.Relations 2} {t₁ t₂ : L.Term _} :
(R.formula₂ t₁ t₂).Realize v ↔ RelMap R ![t₁.realize v, t₂.realize v] := by
rw [Relations.formula₂, realize_rel, iff_eq_eq]
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]
@[simp]
theorem realize_sup : (φ ⊔ ψ).Realize v ↔ φ.Realize v ∨ ψ.Realize v :=
BoundedFormula.realize_sup
@[simp]
theorem realize_iff : (φ.iff ψ).Realize v ↔ (φ.Realize v ↔ ψ.Realize v) :=
BoundedFormula.realize_iff
@[simp]
theorem realize_relabel {φ : L.Formula α} {g : α → β} {v : β → M} :
(φ.relabel g).Realize v ↔ φ.Realize (v ∘ g) := by
rw [Realize, Realize, relabel, BoundedFormula.realize_relabel, iff_eq_eq, Fin.castAdd_zero]
exact congr rfl (funext finZeroElim)
theorem realize_relabel_sumInr (φ : L.Formula (Fin n)) {v : Empty → M} {x : Fin n → M} :
(BoundedFormula.relabel Sum.inr φ).Realize v x ↔ φ.Realize x := by
rw [BoundedFormula.realize_relabel, Formula.Realize, Sum.elim_comp_inr, Fin.castAdd_zero,
cast_refl, Function.comp_id,
Subsingleton.elim (x ∘ (natAdd n : Fin 0 → Fin n)) default]
@[deprecated (since := "2025-02-21")] alias realize_relabel_sum_inr := realize_relabel_sumInr
@[simp]
theorem realize_equal {t₁ t₂ : L.Term α} {x : α → M} :
(t₁.equal t₂).Realize x ↔ t₁.realize x = t₂.realize x := by simp [Term.equal, Realize]
@[simp]
theorem realize_graph {f : L.Functions n} {x : Fin n → M} {y : M} :
(Formula.graph f).Realize (Fin.cons y x : _ → M) ↔ funMap f x = y := by
simp only [Formula.graph, Term.realize, realize_equal, Fin.cons_zero, Fin.cons_succ]
rw [eq_comm]
theorem boundedFormula_realize_eq_realize (φ : L.Formula α) (x : α → M) (y : Fin 0 → M) :
BoundedFormula.Realize φ x y ↔ φ.Realize x := by
rw [Formula.Realize, iff_iff_eq]
congr
ext i; exact Fin.elim0 i
end Formula
@[simp]
theorem LHom.realize_onFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (ψ : L.Formula α)
{v : α → M} : (φ.onFormula ψ).Realize v ↔ ψ.Realize v :=
φ.realize_onBoundedFormula ψ
@[simp]
theorem LHom.setOf_realize_onFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M]
(ψ : L.Formula α) : (setOf (φ.onFormula ψ).Realize : Set (α → M)) = setOf ψ.Realize := by
ext
simp
variable (M)
/-- A sentence can be evaluated as true or false in a structure. -/
nonrec def Sentence.Realize (φ : L.Sentence) : Prop :=
φ.Realize (default : _ → M)
-- input using \|= or \vDash, but not using \models
@[inherit_doc Sentence.Realize]
infixl:51 " ⊨ " => Sentence.Realize
@[simp]
theorem Sentence.realize_not {φ : L.Sentence} : M ⊨ φ.not ↔ ¬M ⊨ φ :=
Iff.rfl
namespace Formula
@[simp]
theorem realize_equivSentence_symm_con [L[[α]].Structure M]
[(L.lhomWithConstants α).IsExpansionOn M] (φ : L[[α]].Sentence) :
((equivSentence.symm φ).Realize fun a => (L.con a : M)) ↔ φ.Realize M := by
simp only [equivSentence, _root_.Equiv.symm_symm, Equiv.coe_trans, Realize,
BoundedFormula.realize_relabelEquiv, Function.comp]
refine _root_.trans ?_ BoundedFormula.realize_constantsVarsEquiv
rw [iff_iff_eq]
congr with (_ | a)
· simp
· cases a
@[simp]
theorem realize_equivSentence [L[[α]].Structure M] [(L.lhomWithConstants α).IsExpansionOn M]
(φ : L.Formula α) : (equivSentence φ).Realize M ↔ φ.Realize fun a => (L.con a : M) := by
rw [← realize_equivSentence_symm_con M (equivSentence φ), _root_.Equiv.symm_apply_apply]
theorem realize_equivSentence_symm (φ : L[[α]].Sentence) (v : α → M) :
(equivSentence.symm φ).Realize v ↔
@Sentence.Realize _ M (@Language.withConstantsStructure L M _ α (constantsOn.structure v))
φ :=
letI := constantsOn.structure v
realize_equivSentence_symm_con M φ
end Formula
@[simp]
theorem LHom.realize_onSentence [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M]
(ψ : L.Sentence) : M ⊨ φ.onSentence ψ ↔ M ⊨ ψ :=
φ.realize_onFormula ψ
variable (L)
/-- The complete theory of a structure `M` is the set of all sentences `M` satisfies. -/
def completeTheory : L.Theory :=
{ φ | M ⊨ φ }
variable (N)
/-- Two structures are elementarily equivalent when they satisfy the same sentences. -/
def ElementarilyEquivalent : Prop :=
L.completeTheory M = L.completeTheory N
@[inherit_doc FirstOrder.Language.ElementarilyEquivalent]
scoped[FirstOrder]
notation:25 A " ≅[" L "] " B:50 => FirstOrder.Language.ElementarilyEquivalent L A B
variable {L} {M} {N}
@[simp]
theorem mem_completeTheory {φ : Sentence L} : φ ∈ L.completeTheory M ↔ M ⊨ φ :=
Iff.rfl
theorem elementarilyEquivalent_iff : M ≅[L] N ↔ ∀ φ : L.Sentence, M ⊨ φ ↔ N ⊨ φ := by
simp only [ElementarilyEquivalent, Set.ext_iff, completeTheory, Set.mem_setOf_eq]
variable (M)
/-- A model of a theory is a structure in which every sentence is realized as true. -/
class Theory.Model (T : L.Theory) : Prop where
realize_of_mem : ∀ φ ∈ T, M ⊨ φ
-- input using \|= or \vDash, but not using \models
@[inherit_doc Theory.Model]
infixl:51 " ⊨ " => Theory.Model
variable {M} (T : L.Theory)
@[simp default - 10]
theorem Theory.model_iff : M ⊨ T ↔ ∀ φ ∈ T, M ⊨ φ :=
⟨fun h => h.realize_of_mem, fun h => ⟨h⟩⟩
theorem Theory.realize_sentence_of_mem [M ⊨ T] {φ : L.Sentence} (h : φ ∈ T) : M ⊨ φ :=
Theory.Model.realize_of_mem φ h
@[simp]
theorem LHom.onTheory_model [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (T : L.Theory) :
M ⊨ φ.onTheory T ↔ M ⊨ T := by simp [Theory.model_iff, LHom.onTheory]
variable {T}
instance model_empty : M ⊨ (∅ : L.Theory) :=
⟨fun φ hφ => (Set.not_mem_empty φ hφ).elim⟩
namespace Theory
theorem Model.mono {T' : L.Theory} (_h : M ⊨ T') (hs : T ⊆ T') : M ⊨ T :=
⟨fun _φ hφ => T'.realize_sentence_of_mem (hs hφ)⟩
theorem Model.union {T' : L.Theory} (h : M ⊨ T) (h' : M ⊨ T') : M ⊨ T ∪ T' := by
simp only [model_iff, Set.mem_union] at *
exact fun φ hφ => hφ.elim (h _) (h' _)
@[simp]
theorem model_union_iff {T' : L.Theory} : M ⊨ T ∪ T' ↔ M ⊨ T ∧ M ⊨ T' :=
⟨fun h => ⟨h.mono Set.subset_union_left, h.mono Set.subset_union_right⟩, fun h =>
h.1.union h.2⟩
@[simp]
theorem model_singleton_iff {φ : L.Sentence} : M ⊨ ({φ} : L.Theory) ↔ M ⊨ φ := by simp
theorem model_insert_iff {φ : L.Sentence} : M ⊨ insert φ T ↔ M ⊨ φ ∧ M ⊨ T := by
rw [Set.insert_eq, model_union_iff, model_singleton_iff]
theorem model_iff_subset_completeTheory : M ⊨ T ↔ T ⊆ L.completeTheory M :=
T.model_iff
theorem completeTheory.subset [MT : M ⊨ T] : T ⊆ L.completeTheory M :=
model_iff_subset_completeTheory.1 MT
end Theory
instance model_completeTheory : M ⊨ L.completeTheory M :=
Theory.model_iff_subset_completeTheory.2 (subset_refl _)
variable (M N)
theorem realize_iff_of_model_completeTheory [N ⊨ L.completeTheory M] (φ : L.Sentence) :
N ⊨ φ ↔ M ⊨ φ := by
refine ⟨fun h => ?_, (L.completeTheory M).realize_sentence_of_mem⟩
| contrapose! h
rw [← Sentence.realize_not] at *
exact (L.completeTheory M).realize_sentence_of_mem (mem_completeTheory.2 h)
variable {M N}
namespace BoundedFormula
@[simp]
theorem realize_alls {φ : L.BoundedFormula α n} {v : α → M} :
| Mathlib/ModelTheory/Semantics.lean | 732 | 741 |
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Algebra.GroupWithZero.Divisibility
import Mathlib.Algebra.Ring.Rat
import Mathlib.Algebra.Ring.Int.Parity
import Mathlib.Data.PNat.Defs
/-!
# Further lemmas for the Rational Numbers
-/
namespace Rat
theorem num_dvd (a) {b : ℤ} (b0 : b ≠ 0) : (a /. b).num ∣ a := by
rcases e : a /. b with ⟨n, d, h, c⟩
rw [Rat.mk'_eq_divInt, divInt_eq_iff b0 (mod_cast h)] at e
refine Int.natAbs_dvd.1 <| Int.dvd_natAbs.1 <| Int.natCast_dvd_natCast.2 <|
c.dvd_of_dvd_mul_right ?_
have := congr_arg Int.natAbs e
simp only [Int.natAbs_mul, Int.natAbs_natCast] at this; simp [this]
theorem den_dvd (a b : ℤ) : ((a /. b).den : ℤ) ∣ b := by
by_cases b0 : b = 0; · simp [b0]
rcases e : a /. b with ⟨n, d, h, c⟩
rw [mk'_eq_divInt, divInt_eq_iff b0 (ne_of_gt (Int.natCast_pos.2 (Nat.pos_of_ne_zero h)))] at e
refine Int.dvd_natAbs.1 <| Int.natCast_dvd_natCast.2 <| c.symm.dvd_of_dvd_mul_left ?_
rw [← Int.natAbs_mul, ← Int.natCast_dvd_natCast, Int.dvd_natAbs, ← e]; simp
theorem num_den_mk {q : ℚ} {n d : ℤ} (hd : d ≠ 0) (qdf : q = n /. d) :
∃ c : ℤ, n = c * q.num ∧ d = c * q.den := by
obtain rfl | hn := eq_or_ne n 0
· simp [qdf]
have : q.num * d = n * ↑q.den := by
refine (divInt_eq_iff ?_ hd).mp ?_
· exact Int.natCast_ne_zero.mpr (Rat.den_nz _)
· rwa [num_divInt_den]
have hqdn : q.num ∣ n := by
rw [qdf]
exact Rat.num_dvd _ hd
refine ⟨n / q.num, ?_, ?_⟩
· rw [Int.ediv_mul_cancel hqdn]
· refine Int.eq_mul_div_of_mul_eq_mul_of_dvd_left ?_ hqdn this
rw [qdf]
exact Rat.num_ne_zero.2 ((divInt_ne_zero hd).mpr hn)
theorem num_mk (n d : ℤ) : (n /. d).num = d.sign * n / n.gcd d := by
have (m : ℕ) : Int.natAbs (m + 1) = m + 1 := by
rw [← Nat.cast_one, ← Nat.cast_add, Int.natAbs_cast]
rcases d with ((_ | _) | _) <;>
rw [← Int.tdiv_eq_ediv_of_dvd] <;>
simp [divInt, mkRat, Rat.normalize, Nat.succPNat, Int.sign, Int.gcd,
Int.zero_ediv, Int.ofNat_dvd_left, Nat.gcd_dvd_left, this]
theorem den_mk (n d : ℤ) : (n /. d).den = if d = 0 then 1 else d.natAbs / n.gcd d := by
have (m : ℕ) : Int.natAbs (m + 1) = m + 1 := by
rw [← Nat.cast_one, ← Nat.cast_add, Int.natAbs_cast]
rcases d with ((_ | _) | _) <;>
simp [divInt, mkRat, Rat.normalize, Nat.succPNat, Int.sign, Int.gcd,
if_neg (Nat.cast_add_one_ne_zero _), this]
theorem add_den_dvd_lcm (q₁ q₂ : ℚ) : (q₁ + q₂).den ∣ q₁.den.lcm q₂.den := by
rw [add_def, normalize_eq, Nat.div_dvd_iff_dvd_mul (Nat.gcd_dvd_right _ _)
(Nat.gcd_ne_zero_right (by simp)), ← Nat.gcd_mul_lcm,
mul_dvd_mul_iff_right (Nat.lcm_ne_zero (by simp) (by simp)), Nat.dvd_gcd_iff]
refine ⟨?_, dvd_mul_right _ _⟩
rw [← Int.natCast_dvd_natCast, Int.dvd_natAbs]
apply Int.dvd_add
<;> apply dvd_mul_of_dvd_right <;> rw [Int.natCast_dvd_natCast]
<;> [exact Nat.gcd_dvd_right _ _; exact Nat.gcd_dvd_left _ _]
theorem add_den_dvd (q₁ q₂ : ℚ) : (q₁ + q₂).den ∣ q₁.den * q₂.den := by
rw [add_def, normalize_eq]
apply Nat.div_dvd_of_dvd
apply Nat.gcd_dvd_right
theorem mul_den_dvd (q₁ q₂ : ℚ) : (q₁ * q₂).den ∣ q₁.den * q₂.den := by
rw [mul_def, normalize_eq]
apply Nat.div_dvd_of_dvd
apply Nat.gcd_dvd_right
theorem mul_num (q₁ q₂ : ℚ) :
(q₁ * q₂).num = q₁.num * q₂.num / Nat.gcd (q₁.num * q₂.num).natAbs (q₁.den * q₂.den) := by
rw [mul_def, normalize_eq]
theorem mul_den (q₁ q₂ : ℚ) :
(q₁ * q₂).den =
q₁.den * q₂.den / Nat.gcd (q₁.num * q₂.num).natAbs (q₁.den * q₂.den) := by
rw [mul_def, normalize_eq]
theorem mul_self_num (q : ℚ) : (q * q).num = q.num * q.num := by
rw [mul_num, Int.natAbs_mul, Nat.Coprime.gcd_eq_one, Int.ofNat_one, Int.ediv_one]
exact (q.reduced.mul_right q.reduced).mul (q.reduced.mul_right q.reduced)
theorem mul_self_den (q : ℚ) : (q * q).den = q.den * q.den := by
rw [Rat.mul_den, Int.natAbs_mul, Nat.Coprime.gcd_eq_one, Nat.div_one]
exact (q.reduced.mul_right q.reduced).mul (q.reduced.mul_right q.reduced)
theorem add_num_den (q r : ℚ) :
q + r = (q.num * r.den + q.den * r.num : ℤ) /. (↑q.den * ↑r.den : ℤ) := by
have hqd : (q.den : ℤ) ≠ 0 := Int.natCast_ne_zero_iff_pos.2 q.den_pos
have hrd : (r.den : ℤ) ≠ 0 := Int.natCast_ne_zero_iff_pos.2 r.den_pos
conv_lhs => rw [← num_divInt_den q, ← num_divInt_den r, divInt_add_divInt _ _ hqd hrd]
rw [mul_comm r.num q.den]
theorem isSquare_iff {q : ℚ} : IsSquare q ↔ IsSquare q.num ∧ IsSquare q.den := by
constructor
· rintro ⟨qr, rfl⟩
rw [Rat.mul_self_num, mul_self_den]
simp only [IsSquare.mul_self, and_self]
· rintro ⟨⟨nr, hnr⟩, ⟨dr, hdr⟩⟩
refine ⟨nr / dr, ?_⟩
rw [div_mul_div_comm, ← Int.cast_mul, ← Nat.cast_mul, ← hnr, ← hdr, num_div_den]
@[norm_cast, simp]
theorem isSquare_natCast_iff {n : ℕ} : IsSquare (n : ℚ) ↔ IsSquare n := by
simp_rw [isSquare_iff, num_natCast, den_natCast, IsSquare.one, and_true, Int.isSquare_natCast_iff]
@[norm_cast, simp]
theorem isSquare_intCast_iff {z : ℤ} : IsSquare (z : ℚ) ↔ IsSquare z := by
simp_rw [isSquare_iff, intCast_num, intCast_den, IsSquare.one, and_true]
@[simp]
theorem isSquare_ofNat_iff {n : ℕ} :
IsSquare (ofNat(n) : ℚ) ↔ IsSquare (OfNat.ofNat n : ℕ) :=
isSquare_natCast_iff
section Casts
theorem exists_eq_mul_div_num_and_eq_mul_div_den (n : ℤ) {d : ℤ} (d_ne_zero : d ≠ 0) :
∃ c : ℤ, n = c * ((n : ℚ) / d).num ∧ (d : ℤ) = c * ((n : ℚ) / d).den :=
haveI : (n : ℚ) / d = Rat.divInt n d := by rw [← Rat.divInt_eq_div]
Rat.num_den_mk d_ne_zero this
theorem mul_num_den' (q r : ℚ) :
(q * r).num * q.den * r.den = q.num * r.num * (q * r).den := by
let s := q.num * r.num /. (q.den * r.den : ℤ)
have hs : (q.den * r.den : ℤ) ≠ 0 := Int.natCast_ne_zero_iff_pos.mpr (Nat.mul_pos q.pos r.pos)
obtain ⟨c, ⟨c_mul_num, c_mul_den⟩⟩ :=
exists_eq_mul_div_num_and_eq_mul_div_den (q.num * r.num) hs
rw [c_mul_num, mul_assoc, mul_comm]
nth_rw 1 [c_mul_den]
rw [Int.mul_assoc, Int.mul_assoc, mul_eq_mul_left_iff, or_iff_not_imp_right]
intro
have h : _ = s := divInt_mul_divInt q.num r.num (mod_cast q.den_ne_zero) (mod_cast r.den_ne_zero)
rw [num_divInt_den, num_divInt_den] at h
rw [h, mul_comm, ← Rat.eq_iff_mul_eq_mul, ← divInt_eq_div]
theorem add_num_den' (q r : ℚ) :
(q + r).num * q.den * r.den = (q.num * r.den + r.num * q.den) * (q + r).den := by
let s := divInt (q.num * r.den + r.num * q.den) (q.den * r.den : ℤ)
have hs : (q.den * r.den : ℤ) ≠ 0 := Int.natCast_ne_zero_iff_pos.mpr (Nat.mul_pos q.pos r.pos)
obtain ⟨c, ⟨c_mul_num, c_mul_den⟩⟩ :=
exists_eq_mul_div_num_and_eq_mul_div_den (q.num * r.den + r.num * q.den) hs
rw [c_mul_num, mul_assoc, mul_comm]
nth_rw 1 [c_mul_den]
repeat rw [Int.mul_assoc]
apply mul_eq_mul_left_iff.2
rw [or_iff_not_imp_right]
intro
have h : _ = s := divInt_add_divInt q.num r.num (mod_cast q.den_ne_zero) (mod_cast r.den_ne_zero)
rw [num_divInt_den, num_divInt_den] at h
rw [h]
rw [mul_comm]
apply Rat.eq_iff_mul_eq_mul.mp
rw [← divInt_eq_div]
theorem substr_num_den' (q r : ℚ) :
(q - r).num * q.den * r.den = (q.num * r.den - r.num * q.den) * (q - r).den := by
rw [sub_eq_add_neg, sub_eq_add_neg, ← neg_mul, ← num_neg_eq_neg_num, ← den_neg_eq_den r,
add_num_den' q (-r)]
end Casts
protected theorem inv_neg (q : ℚ) : (-q)⁻¹ = -q⁻¹ := by
rw [← num_divInt_den q]
simp only [Rat.neg_divInt, Rat.inv_divInt', eq_self_iff_true, Rat.divInt_neg]
theorem num_div_eq_of_coprime {a b : ℤ} (hb0 : 0 < b) (h : Nat.Coprime a.natAbs b.natAbs) :
(a / b : ℚ).num = a := by
lift b to ℕ using hb0.le
simp only [Int.natAbs_natCast, Int.ofNat_pos] at h hb0
rw [← Rat.divInt_eq_div, ← mk_eq_divInt _ _ hb0.ne' h]
theorem den_div_eq_of_coprime {a b : ℤ} (hb0 : 0 < b) (h : Nat.Coprime a.natAbs b.natAbs) :
((a / b : ℚ).den : ℤ) = b := by
lift b to ℕ using hb0.le
simp only [Int.natAbs_natCast, Int.ofNat_pos] at h hb0
rw [← Rat.divInt_eq_div, ← mk_eq_divInt _ _ hb0.ne' h]
theorem div_int_inj {a b c d : ℤ} (hb0 : 0 < b) (hd0 : 0 < d) (h1 : Nat.Coprime a.natAbs b.natAbs)
(h2 : Nat.Coprime c.natAbs d.natAbs) (h : (a : ℚ) / b = (c : ℚ) / d) : a = c ∧ b = d := by
apply And.intro
· rw [← num_div_eq_of_coprime hb0 h1, h, num_div_eq_of_coprime hd0 h2]
· rw [← den_div_eq_of_coprime hb0 h1, h, den_div_eq_of_coprime hd0 h2]
@[norm_cast]
theorem intCast_div_self (n : ℤ) : ((n / n : ℤ) : ℚ) = n / n := by
by_cases hn : n = 0
· subst hn
simp only [Int.cast_zero, Int.zero_tdiv, zero_div, Int.ediv_zero]
· have : (n : ℚ) ≠ 0 := by rwa [← coe_int_inj] at hn
simp only [Int.ediv_self hn, Int.cast_one, Ne, not_false_iff, div_self this]
@[norm_cast]
theorem natCast_div_self (n : ℕ) : ((n / n : ℕ) : ℚ) = n / n :=
intCast_div_self n
theorem intCast_div (a b : ℤ) (h : b ∣ a) : ((a / b : ℤ) : ℚ) = a / b := by
rcases h with ⟨c, rfl⟩
| rw [mul_comm b, Int.mul_ediv_assoc c (dvd_refl b), Int.cast_mul,
intCast_div_self, Int.cast_mul, mul_div_assoc]
theorem natCast_div (a b : ℕ) (h : b ∣ a) : ((a / b : ℕ) : ℚ) = a / b :=
intCast_div a b (Int.ofNat_dvd.mpr h)
| Mathlib/Data/Rat/Lemmas.lean | 216 | 220 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov
-/
import Mathlib.Order.Filter.Tendsto
import Mathlib.Data.Set.Accumulate
import Mathlib.Topology.Bornology.Basic
import Mathlib.Topology.ContinuousOn
import Mathlib.Topology.Ultrafilter
import Mathlib.Topology.Defs.Ultrafilter
/-!
# Compact sets and compact spaces
## Main results
* `isCompact_univ_pi`: **Tychonov's theorem** - an arbitrary product of compact sets
is compact.
-/
open Set Filter Topology TopologicalSpace Function
universe u v
variable {X : Type u} {Y : Type v} {ι : Type*}
variable [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X} {f : X → Y}
-- compact sets
section Compact
lemma IsCompact.exists_clusterPt (hs : IsCompact s) {f : Filter X} [NeBot f] (hf : f ≤ 𝓟 s) :
∃ x ∈ s, ClusterPt x f := hs hf
lemma IsCompact.exists_mapClusterPt {ι : Type*} (hs : IsCompact s) {f : Filter ι} [NeBot f]
{u : ι → X} (hf : Filter.map u f ≤ 𝓟 s) :
∃ x ∈ s, MapClusterPt x f u := hs hf
lemma IsCompact.exists_clusterPt_of_frequently {l : Filter X} (hs : IsCompact s)
(hl : ∃ᶠ x in l, x ∈ s) : ∃ a ∈ s, ClusterPt a l :=
let ⟨a, has, ha⟩ := @hs _ (frequently_mem_iff_neBot.mp hl) inf_le_right
⟨a, has, ha.mono inf_le_left⟩
lemma IsCompact.exists_mapClusterPt_of_frequently {l : Filter ι} {f : ι → X} (hs : IsCompact s)
(hf : ∃ᶠ x in l, f x ∈ s) : ∃ a ∈ s, MapClusterPt a l f :=
hs.exists_clusterPt_of_frequently hf
/-- The complement to a compact set belongs to a filter `f` if it belongs to each filter
`𝓝 x ⊓ f`, `x ∈ s`. -/
theorem IsCompact.compl_mem_sets (hs : IsCompact s) {f : Filter X} (hf : ∀ x ∈ s, sᶜ ∈ 𝓝 x ⊓ f) :
sᶜ ∈ f := by
contrapose! hf
simp only [not_mem_iff_inf_principal_compl, compl_compl, inf_assoc] at hf ⊢
exact @hs _ hf inf_le_right
/-- The complement to a compact set belongs to a filter `f` if each `x ∈ s` has a neighborhood `t`
within `s` such that `tᶜ` belongs to `f`. -/
theorem IsCompact.compl_mem_sets_of_nhdsWithin (hs : IsCompact s) {f : Filter X}
(hf : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, tᶜ ∈ f) : sᶜ ∈ f := by
refine hs.compl_mem_sets fun x hx => ?_
rcases hf x hx with ⟨t, ht, hst⟩
replace ht := mem_inf_principal.1 ht
apply mem_inf_of_inter ht hst
rintro x ⟨h₁, h₂⟩ hs
exact h₂ (h₁ hs)
/-- If `p : Set X → Prop` is stable under restriction and union, and each point `x`
of a compact set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/
@[elab_as_elim]
theorem IsCompact.induction_on (hs : IsCompact s) {p : Set X → Prop} (he : p ∅)
(hmono : ∀ ⦃s t⦄, s ⊆ t → p t → p s) (hunion : ∀ ⦃s t⦄, p s → p t → p (s ∪ t))
(hnhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, p t) : p s := by
let f : Filter X := comk p he (fun _t ht _s hsub ↦ hmono hsub ht) (fun _s hs _t ht ↦ hunion hs ht)
have : sᶜ ∈ f := hs.compl_mem_sets_of_nhdsWithin (by simpa [f] using hnhds)
rwa [← compl_compl s]
/-- The intersection of a compact set and a closed set is a compact set. -/
theorem IsCompact.inter_right (hs : IsCompact s) (ht : IsClosed t) : IsCompact (s ∩ t) := by
intro f hnf hstf
obtain ⟨x, hsx, hx⟩ : ∃ x ∈ s, ClusterPt x f :=
hs (le_trans hstf (le_principal_iff.2 inter_subset_left))
have : x ∈ t := ht.mem_of_nhdsWithin_neBot <|
hx.mono <| le_trans hstf (le_principal_iff.2 inter_subset_right)
exact ⟨x, ⟨hsx, this⟩, hx⟩
/-- The intersection of a closed set and a compact set is a compact set. -/
theorem IsCompact.inter_left (ht : IsCompact t) (hs : IsClosed s) : IsCompact (s ∩ t) :=
inter_comm t s ▸ ht.inter_right hs
/-- The set difference of a compact set and an open set is a compact set. -/
theorem IsCompact.diff (hs : IsCompact s) (ht : IsOpen t) : IsCompact (s \ t) :=
hs.inter_right (isClosed_compl_iff.mpr ht)
/-- A closed subset of a compact set is a compact set. -/
theorem IsCompact.of_isClosed_subset (hs : IsCompact s) (ht : IsClosed t) (h : t ⊆ s) :
IsCompact t :=
inter_eq_self_of_subset_right h ▸ hs.inter_right ht
theorem IsCompact.image_of_continuousOn {f : X → Y} (hs : IsCompact s) (hf : ContinuousOn f s) :
IsCompact (f '' s) := by
intro l lne ls
have : NeBot (l.comap f ⊓ 𝓟 s) :=
comap_inf_principal_neBot_of_image_mem lne (le_principal_iff.1 ls)
obtain ⟨x, hxs, hx⟩ : ∃ x ∈ s, ClusterPt x (l.comap f ⊓ 𝓟 s) := @hs _ this inf_le_right
haveI := hx.neBot
use f x, mem_image_of_mem f hxs
have : Tendsto f (𝓝 x ⊓ (comap f l ⊓ 𝓟 s)) (𝓝 (f x) ⊓ l) := by
convert (hf x hxs).inf (@tendsto_comap _ _ f l) using 1
rw [nhdsWithin]
ac_rfl
exact this.neBot
theorem IsCompact.image {f : X → Y} (hs : IsCompact s) (hf : Continuous f) : IsCompact (f '' s) :=
hs.image_of_continuousOn hf.continuousOn
theorem IsCompact.adherence_nhdset {f : Filter X} (hs : IsCompact s) (hf₂ : f ≤ 𝓟 s)
(ht₁ : IsOpen t) (ht₂ : ∀ x ∈ s, ClusterPt x f → x ∈ t) : t ∈ f :=
Classical.by_cases mem_of_eq_bot fun (this : f ⊓ 𝓟 tᶜ ≠ ⊥) =>
let ⟨x, hx, (hfx : ClusterPt x <| f ⊓ 𝓟 tᶜ)⟩ := @hs _ ⟨this⟩ <| inf_le_of_left_le hf₂
have : x ∈ t := ht₂ x hx hfx.of_inf_left
have : tᶜ ∩ t ∈ 𝓝[tᶜ] x := inter_mem_nhdsWithin _ (IsOpen.mem_nhds ht₁ this)
have A : 𝓝[tᶜ] x = ⊥ := empty_mem_iff_bot.1 <| compl_inter_self t ▸ this
have : 𝓝[tᶜ] x ≠ ⊥ := hfx.of_inf_right.ne
absurd A this
theorem isCompact_iff_ultrafilter_le_nhds :
IsCompact s ↔ ∀ f : Ultrafilter X, ↑f ≤ 𝓟 s → ∃ x ∈ s, ↑f ≤ 𝓝 x := by
refine (forall_neBot_le_iff ?_).trans ?_
· rintro f g hle ⟨x, hxs, hxf⟩
exact ⟨x, hxs, hxf.mono hle⟩
· simp only [Ultrafilter.clusterPt_iff]
alias ⟨IsCompact.ultrafilter_le_nhds, _⟩ := isCompact_iff_ultrafilter_le_nhds
theorem isCompact_iff_ultrafilter_le_nhds' :
IsCompact s ↔ ∀ f : Ultrafilter X, s ∈ f → ∃ x ∈ s, ↑f ≤ 𝓝 x := by
simp only [isCompact_iff_ultrafilter_le_nhds, le_principal_iff, Ultrafilter.mem_coe]
alias ⟨IsCompact.ultrafilter_le_nhds', _⟩ := isCompact_iff_ultrafilter_le_nhds'
/-- If a compact set belongs to a filter and this filter has a unique cluster point `y` in this set,
then the filter is less than or equal to `𝓝 y`. -/
lemma IsCompact.le_nhds_of_unique_clusterPt (hs : IsCompact s) {l : Filter X} {y : X}
(hmem : s ∈ l) (h : ∀ x ∈ s, ClusterPt x l → x = y) : l ≤ 𝓝 y := by
refine le_iff_ultrafilter.2 fun f hf ↦ ?_
rcases hs.ultrafilter_le_nhds' f (hf hmem) with ⟨x, hxs, hx⟩
convert ← hx
exact h x hxs (.mono (.of_le_nhds hx) hf)
/-- If values of `f : Y → X` belong to a compact set `s` eventually along a filter `l`
and `y` is a unique `MapClusterPt` for `f` along `l` in `s`,
then `f` tends to `𝓝 y` along `l`. -/
lemma IsCompact.tendsto_nhds_of_unique_mapClusterPt {Y} {l : Filter Y} {y : X} {f : Y → X}
(hs : IsCompact s) (hmem : ∀ᶠ x in l, f x ∈ s) (h : ∀ x ∈ s, MapClusterPt x l f → x = y) :
Tendsto f l (𝓝 y) :=
hs.le_nhds_of_unique_clusterPt (mem_map.2 hmem) h
/-- For every open directed cover of a compact set, there exists a single element of the
cover which itself includes the set. -/
theorem IsCompact.elim_directed_cover {ι : Type v} [hι : Nonempty ι] (hs : IsCompact s)
(U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) (hdU : Directed (· ⊆ ·) U) :
∃ i, s ⊆ U i :=
hι.elim fun i₀ =>
IsCompact.induction_on hs ⟨i₀, empty_subset _⟩ (fun _ _ hs ⟨i, hi⟩ => ⟨i, hs.trans hi⟩)
(fun _ _ ⟨i, hi⟩ ⟨j, hj⟩ =>
let ⟨k, hki, hkj⟩ := hdU i j
⟨k, union_subset (Subset.trans hi hki) (Subset.trans hj hkj)⟩)
fun _x hx =>
let ⟨i, hi⟩ := mem_iUnion.1 (hsU hx)
⟨U i, mem_nhdsWithin_of_mem_nhds (IsOpen.mem_nhds (hUo i) hi), i, Subset.refl _⟩
/-- For every open cover of a compact set, there exists a finite subcover. -/
theorem IsCompact.elim_finite_subcover {ι : Type v} (hs : IsCompact s) (U : ι → Set X)
(hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) : ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i :=
hs.elim_directed_cover _ (fun _ => isOpen_biUnion fun i _ => hUo i)
(iUnion_eq_iUnion_finset U ▸ hsU)
(directed_of_isDirected_le fun _ _ h => biUnion_subset_biUnion_left h)
lemma IsCompact.elim_nhds_subcover_nhdsSet' (hs : IsCompact s) (U : ∀ x ∈ s, Set X)
(hU : ∀ x hx, U x hx ∈ 𝓝 x) : ∃ t : Finset s, (⋃ x ∈ t, U x.1 x.2) ∈ 𝓝ˢ s := by
rcases hs.elim_finite_subcover (fun x : s ↦ interior (U x x.2)) (fun _ ↦ isOpen_interior)
fun x hx ↦ mem_iUnion.2 ⟨⟨x, hx⟩, mem_interior_iff_mem_nhds.2 <| hU _ _⟩ with ⟨t, hst⟩
refine ⟨t, mem_nhdsSet_iff_forall.2 fun x hx ↦ ?_⟩
rcases mem_iUnion₂.1 (hst hx) with ⟨y, hyt, hy⟩
refine mem_of_superset ?_ (subset_biUnion_of_mem hyt)
exact mem_interior_iff_mem_nhds.1 hy
lemma IsCompact.elim_nhds_subcover_nhdsSet (hs : IsCompact s) {U : X → Set X}
(hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ t : Finset X, (∀ x ∈ t, x ∈ s) ∧ (⋃ x ∈ t, U x) ∈ 𝓝ˢ s := by
let ⟨t, ht⟩ := hs.elim_nhds_subcover_nhdsSet' (fun x _ => U x) hU
classical
exact ⟨t.image (↑), fun x hx =>
let ⟨y, _, hyx⟩ := Finset.mem_image.1 hx
hyx ▸ y.2,
by rwa [Finset.set_biUnion_finset_image]⟩
theorem IsCompact.elim_nhds_subcover' (hs : IsCompact s) (U : ∀ x ∈ s, Set X)
(hU : ∀ x (hx : x ∈ s), U x ‹x ∈ s› ∈ 𝓝 x) : ∃ t : Finset s, s ⊆ ⋃ x ∈ t, U (x : s) x.2 :=
(hs.elim_nhds_subcover_nhdsSet' U hU).imp fun _ ↦ subset_of_mem_nhdsSet
theorem IsCompact.elim_nhds_subcover (hs : IsCompact s) (U : X → Set X) (hU : ∀ x ∈ s, U x ∈ 𝓝 x) :
∃ t : Finset X, (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x :=
(hs.elim_nhds_subcover_nhdsSet hU).imp fun _ h ↦ h.imp_right subset_of_mem_nhdsSet
theorem IsCompact.elim_nhdsWithin_subcover' (hs : IsCompact s) (U : ∀ x ∈ s, Set X)
(hU : ∀ x (hx : x ∈ s), U x hx ∈ 𝓝[s] x) : ∃ t : Finset s, s ⊆ ⋃ x ∈ t, U x x.2 := by
choose V V_nhds hV using fun x hx => mem_nhdsWithin_iff_exists_mem_nhds_inter.1 (hU x hx)
refine (hs.elim_nhds_subcover' V V_nhds).imp fun t ht =>
subset_trans ?_ (iUnion₂_mono fun x _ => hV x x.2)
simpa [← iUnion_inter, ← iUnion_coe_set]
theorem IsCompact.elim_nhdsWithin_subcover (hs : IsCompact s) (U : X → Set X)
(hU : ∀ x ∈ s, U x ∈ 𝓝[s] x) : ∃ t : Finset X, (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x := by
choose! V V_nhds hV using fun x hx => mem_nhdsWithin_iff_exists_mem_nhds_inter.1 (hU x hx)
refine (hs.elim_nhds_subcover V V_nhds).imp fun t ⟨t_sub_s, ht⟩ =>
⟨t_sub_s, subset_trans ?_ (iUnion₂_mono fun x hx => hV x (t_sub_s x hx))⟩
simpa [← iUnion_inter]
/-- The neighborhood filter of a compact set is disjoint with a filter `l` if and only if the
neighborhood filter of each point of this set is disjoint with `l`. -/
theorem IsCompact.disjoint_nhdsSet_left {l : Filter X} (hs : IsCompact s) :
Disjoint (𝓝ˢ s) l ↔ ∀ x ∈ s, Disjoint (𝓝 x) l := by
refine ⟨fun h x hx => h.mono_left <| nhds_le_nhdsSet hx, fun H => ?_⟩
choose! U hxU hUl using fun x hx => (nhds_basis_opens x).disjoint_iff_left.1 (H x hx)
choose hxU hUo using hxU
rcases hs.elim_nhds_subcover U fun x hx => (hUo x hx).mem_nhds (hxU x hx) with ⟨t, hts, hst⟩
refine (hasBasis_nhdsSet _).disjoint_iff_left.2
⟨⋃ x ∈ t, U x, ⟨isOpen_biUnion fun x hx => hUo x (hts x hx), hst⟩, ?_⟩
rw [compl_iUnion₂, biInter_finset_mem]
exact fun x hx => hUl x (hts x hx)
/-- A filter `l` is disjoint with the neighborhood filter of a compact set if and only if it is
disjoint with the neighborhood filter of each point of this set. -/
theorem IsCompact.disjoint_nhdsSet_right {l : Filter X} (hs : IsCompact s) :
Disjoint l (𝓝ˢ s) ↔ ∀ x ∈ s, Disjoint l (𝓝 x) := by
simpa only [disjoint_comm] using hs.disjoint_nhdsSet_left
-- TODO: reformulate using `Disjoint`
/-- For every directed family of closed sets whose intersection avoids a compact set,
there exists a single element of the family which itself avoids this compact set. -/
theorem IsCompact.elim_directed_family_closed {ι : Type v} [Nonempty ι] (hs : IsCompact s)
(t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅)
(hdt : Directed (· ⊇ ·) t) : ∃ i : ι, s ∩ t i = ∅ :=
let ⟨t, ht⟩ :=
hs.elim_directed_cover (compl ∘ t) (fun i => (htc i).isOpen_compl)
(by
simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_iUnion, exists_prop,
mem_inter_iff, not_and, mem_iInter, mem_compl_iff] using hst)
(hdt.mono_comp _ fun _ _ => compl_subset_compl.mpr)
⟨t, by
simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_iUnion, exists_prop,
mem_inter_iff, not_and, mem_iInter, mem_compl_iff] using ht⟩
-- TODO: reformulate using `Disjoint`
/-- For every family of closed sets whose intersection avoids a compact set,
there exists a finite subfamily whose intersection avoids this compact set. -/
theorem IsCompact.elim_finite_subfamily_closed {ι : Type v} (hs : IsCompact s)
(t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅) :
∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅ :=
hs.elim_directed_family_closed _ (fun _ ↦ isClosed_biInter fun _ _ ↦ htc _)
(by rwa [← iInter_eq_iInter_finset])
(directed_of_isDirected_le fun _ _ h ↦ biInter_subset_biInter_left h)
/-- To show that a compact set intersects the intersection of a family of closed sets,
it is sufficient to show that it intersects every finite subfamily. -/
theorem IsCompact.inter_iInter_nonempty {ι : Type v} (hs : IsCompact s) (t : ι → Set X)
(htc : ∀ i, IsClosed (t i)) (hst : ∀ u : Finset ι, (s ∩ ⋂ i ∈ u, t i).Nonempty) :
(s ∩ ⋂ i, t i).Nonempty := by
contrapose! hst
exact hs.elim_finite_subfamily_closed t htc hst
/-- Cantor's intersection theorem for `iInter`:
the intersection of a directed family of nonempty compact closed sets is nonempty. -/
theorem IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed
{ι : Type v} [hι : Nonempty ι] (t : ι → Set X) (htd : Directed (· ⊇ ·) t)
(htn : ∀ i, (t i).Nonempty) (htc : ∀ i, IsCompact (t i)) (htcl : ∀ i, IsClosed (t i)) :
(⋂ i, t i).Nonempty := by
let i₀ := hι.some
suffices (t i₀ ∩ ⋂ i, t i).Nonempty by
rwa [inter_eq_right.mpr (iInter_subset _ i₀)] at this
simp only [nonempty_iff_ne_empty] at htn ⊢
apply mt ((htc i₀).elim_directed_family_closed t htcl)
push_neg
simp only [← nonempty_iff_ne_empty] at htn ⊢
refine ⟨htd, fun i => ?_⟩
rcases htd i₀ i with ⟨j, hji₀, hji⟩
exact (htn j).mono (subset_inter hji₀ hji)
/-- Cantor's intersection theorem for `sInter`:
the intersection of a directed family of nonempty compact closed sets is nonempty. -/
theorem IsCompact.nonempty_sInter_of_directed_nonempty_isCompact_isClosed
{S : Set (Set X)} [hS : Nonempty S] (hSd : DirectedOn (· ⊇ ·) S) (hSn : ∀ U ∈ S, U.Nonempty)
(hSc : ∀ U ∈ S, IsCompact U) (hScl : ∀ U ∈ S, IsClosed U) : (⋂₀ S).Nonempty := by
rw [sInter_eq_iInter]
exact IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed _
(DirectedOn.directed_val hSd) (fun i ↦ hSn i i.2) (fun i ↦ hSc i i.2) (fun i ↦ hScl i i.2)
/-- Cantor's intersection theorem for sequences indexed by `ℕ`:
the intersection of a decreasing sequence of nonempty compact closed sets is nonempty. -/
theorem IsCompact.nonempty_iInter_of_sequence_nonempty_isCompact_isClosed (t : ℕ → Set X)
(htd : ∀ i, t (i + 1) ⊆ t i) (htn : ∀ i, (t i).Nonempty) (ht0 : IsCompact (t 0))
(htcl : ∀ i, IsClosed (t i)) : (⋂ i, t i).Nonempty :=
have tmono : Antitone t := antitone_nat_of_succ_le htd
have htd : Directed (· ⊇ ·) t := tmono.directed_ge
have : ∀ i, t i ⊆ t 0 := fun i => tmono <| Nat.zero_le i
have htc : ∀ i, IsCompact (t i) := fun i => ht0.of_isClosed_subset (htcl i) (this i)
IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed t htd htn htc htcl
/-- For every open cover of a compact set, there exists a finite subcover. -/
theorem IsCompact.elim_finite_subcover_image {b : Set ι} {c : ι → Set X} (hs : IsCompact s)
(hc₁ : ∀ i ∈ b, IsOpen (c i)) (hc₂ : s ⊆ ⋃ i ∈ b, c i) :
∃ b', b' ⊆ b ∧ Set.Finite b' ∧ s ⊆ ⋃ i ∈ b', c i := by
simp only [Subtype.forall', biUnion_eq_iUnion] at hc₁ hc₂
rcases hs.elim_finite_subcover (fun i => c i : b → Set X) hc₁ hc₂ with ⟨d, hd⟩
refine ⟨Subtype.val '' d.toSet, ?_, d.finite_toSet.image _, ?_⟩
· simp
· rwa [biUnion_image]
/-- A set `s` is compact if for every open cover of `s`, there exists a finite subcover. -/
theorem isCompact_of_finite_subcover
(h : ∀ {ι : Type u} (U : ι → Set X), (∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) →
∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i) :
IsCompact s := fun f hf hfs => by
contrapose! h
simp only [ClusterPt, not_neBot, ← disjoint_iff, SetCoe.forall',
(nhds_basis_opens _).disjoint_iff_left] at h
choose U hU hUf using h
refine ⟨s, U, fun x => (hU x).2, fun x hx => mem_iUnion.2 ⟨⟨x, hx⟩, (hU _).1⟩, fun t ht => ?_⟩
refine compl_not_mem (le_principal_iff.1 hfs) ?_
refine mem_of_superset ((biInter_finset_mem t).2 fun x _ => hUf x) ?_
rw [subset_compl_comm, compl_iInter₂]
simpa only [compl_compl]
-- TODO: reformulate using `Disjoint`
/-- A set `s` is compact if for every family of closed sets whose intersection avoids `s`,
there exists a finite subfamily whose intersection avoids `s`. -/
theorem isCompact_of_finite_subfamily_closed
(h : ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ →
∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅) :
IsCompact s :=
isCompact_of_finite_subcover fun U hUo hsU => by
rw [← disjoint_compl_right_iff_subset, compl_iUnion, disjoint_iff] at hsU
rcases h (fun i => (U i)ᶜ) (fun i => (hUo _).isClosed_compl) hsU with ⟨t, ht⟩
refine ⟨t, ?_⟩
rwa [← disjoint_compl_right_iff_subset, compl_iUnion₂, disjoint_iff]
/-- A set `s` is compact if and only if
for every open cover of `s`, there exists a finite subcover. -/
theorem isCompact_iff_finite_subcover :
IsCompact s ↔ ∀ {ι : Type u} (U : ι → Set X),
(∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) → ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i :=
⟨fun hs => hs.elim_finite_subcover, isCompact_of_finite_subcover⟩
/-- A set `s` is compact if and only if
for every family of closed sets whose intersection avoids `s`,
there exists a finite subfamily whose intersection avoids `s`. -/
theorem isCompact_iff_finite_subfamily_closed :
IsCompact s ↔ ∀ {ι : Type u} (t : ι → Set X),
(∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ → ∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅ :=
⟨fun hs => hs.elim_finite_subfamily_closed, isCompact_of_finite_subfamily_closed⟩
/-- If `s : Set (X × Y)` belongs to `𝓝 x ×ˢ l` for all `x` from a compact set `K`,
then it belongs to `(𝓝ˢ K) ×ˢ l`,
i.e., there exist an open `U ⊇ K` and `t ∈ l` such that `U ×ˢ t ⊆ s`. -/
theorem IsCompact.mem_nhdsSet_prod_of_forall {K : Set X} {Y} {l : Filter Y} {s : Set (X × Y)}
(hK : IsCompact K) (hs : ∀ x ∈ K, s ∈ 𝓝 x ×ˢ l) : s ∈ (𝓝ˢ K) ×ˢ l := by
refine hK.induction_on (by simp) (fun t t' ht hs ↦ ?_) (fun t t' ht ht' ↦ ?_) fun x hx ↦ ?_
· exact prod_mono (nhdsSet_mono ht) le_rfl hs
· simp [sup_prod, *]
· rcases ((nhds_basis_opens _).prod l.basis_sets).mem_iff.1 (hs x hx)
with ⟨⟨u, v⟩, ⟨⟨hx, huo⟩, hv⟩, hs⟩
refine ⟨u, nhdsWithin_le_nhds (huo.mem_nhds hx), mem_of_superset ?_ hs⟩
exact prod_mem_prod (huo.mem_nhdsSet.2 Subset.rfl) hv
theorem IsCompact.nhdsSet_prod_eq_biSup {K : Set X} (hK : IsCompact K) {Y} (l : Filter Y) :
(𝓝ˢ K) ×ˢ l = ⨆ x ∈ K, 𝓝 x ×ˢ l :=
le_antisymm (fun s hs ↦ hK.mem_nhdsSet_prod_of_forall <| by simpa using hs)
(iSup₂_le fun _ hx ↦ prod_mono (nhds_le_nhdsSet hx) le_rfl)
theorem IsCompact.prod_nhdsSet_eq_biSup {K : Set Y} (hK : IsCompact K) {X} (l : Filter X) :
l ×ˢ (𝓝ˢ K) = ⨆ y ∈ K, l ×ˢ 𝓝 y := by
simp only [prod_comm (f := l), hK.nhdsSet_prod_eq_biSup, map_iSup]
/-- If `s : Set (X × Y)` belongs to `l ×ˢ 𝓝 y` for all `y` from a compact set `K`,
then it belongs to `l ×ˢ (𝓝ˢ K)`,
i.e., there exist `t ∈ l` and an open `U ⊇ K` such that `t ×ˢ U ⊆ s`. -/
theorem IsCompact.mem_prod_nhdsSet_of_forall {K : Set Y} {X} {l : Filter X} {s : Set (X × Y)}
(hK : IsCompact K) (hs : ∀ y ∈ K, s ∈ l ×ˢ 𝓝 y) : s ∈ l ×ˢ 𝓝ˢ K :=
(hK.prod_nhdsSet_eq_biSup l).symm ▸ by simpa using hs
-- TODO: Is there a way to prove directly the `inf` version and then deduce the `Prod` one ?
-- That would seem a bit more natural.
theorem IsCompact.nhdsSet_inf_eq_biSup {K : Set X} (hK : IsCompact K) (l : Filter X) :
(𝓝ˢ K) ⊓ l = ⨆ x ∈ K, 𝓝 x ⊓ l := by
have : ∀ f : Filter X, f ⊓ l = comap (fun x ↦ (x, x)) (f ×ˢ l) := fun f ↦ by
simpa only [comap_prod] using congrArg₂ (· ⊓ ·) comap_id.symm comap_id.symm
simp_rw [this, ← comap_iSup, hK.nhdsSet_prod_eq_biSup]
theorem IsCompact.inf_nhdsSet_eq_biSup {K : Set X} (hK : IsCompact K) (l : Filter X) :
l ⊓ (𝓝ˢ K) = ⨆ x ∈ K, l ⊓ 𝓝 x := by
simp only [inf_comm l, hK.nhdsSet_inf_eq_biSup]
/-- If `s : Set X` belongs to `𝓝 x ⊓ l` for all `x` from a compact set `K`,
then it belongs to `(𝓝ˢ K) ⊓ l`,
i.e., there exist an open `U ⊇ K` and `T ∈ l` such that `U ∩ T ⊆ s`. -/
theorem IsCompact.mem_nhdsSet_inf_of_forall {K : Set X} {l : Filter X} {s : Set X}
(hK : IsCompact K) (hs : ∀ x ∈ K, s ∈ 𝓝 x ⊓ l) : s ∈ (𝓝ˢ K) ⊓ l :=
(hK.nhdsSet_inf_eq_biSup l).symm ▸ by simpa using hs
/-- If `s : Set S` belongs to `l ⊓ 𝓝 x` for all `x` from a compact set `K`,
then it belongs to `l ⊓ (𝓝ˢ K)`,
i.e., there exist `T ∈ l` and an open `U ⊇ K` such that `T ∩ U ⊆ s`. -/
theorem IsCompact.mem_inf_nhdsSet_of_forall {K : Set X} {l : Filter X} {s : Set X}
(hK : IsCompact K) (hs : ∀ y ∈ K, s ∈ l ⊓ 𝓝 y) : s ∈ l ⊓ 𝓝ˢ K :=
(hK.inf_nhdsSet_eq_biSup l).symm ▸ by simpa using hs
/-- To show that `∀ y ∈ K, P x y` holds for `x` close enough to `x₀` when `K` is compact,
it is sufficient to show that for all `y₀ ∈ K` there `P x y` holds for `(x, y)` close enough
to `(x₀, y₀)`.
Provided for backwards compatibility,
see `IsCompact.mem_prod_nhdsSet_of_forall` for a stronger statement.
-/
theorem IsCompact.eventually_forall_of_forall_eventually {x₀ : X} {K : Set Y} (hK : IsCompact K)
{P : X → Y → Prop} (hP : ∀ y ∈ K, ∀ᶠ z : X × Y in 𝓝 (x₀, y), P z.1 z.2) :
∀ᶠ x in 𝓝 x₀, ∀ y ∈ K, P x y := by
simp only [nhds_prod_eq, ← eventually_iSup, ← hK.prod_nhdsSet_eq_biSup] at hP
exact hP.curry.mono fun _ h ↦ h.self_of_nhdsSet
theorem isCompact_empty : IsCompact (∅ : Set X) := fun _f hnf hsf =>
Not.elim hnf.ne <| empty_mem_iff_bot.1 <| le_principal_iff.1 hsf
theorem isCompact_singleton {x : X} : IsCompact ({x} : Set X) := fun _ hf hfa =>
⟨x, rfl, ClusterPt.of_le_nhds'
(hfa.trans <| by simpa only [principal_singleton] using pure_le_nhds x) hf⟩
theorem Set.Subsingleton.isCompact (hs : s.Subsingleton) : IsCompact s :=
Subsingleton.induction_on hs isCompact_empty fun _ => isCompact_singleton
theorem Set.Finite.isCompact_biUnion {s : Set ι} {f : ι → Set X} (hs : s.Finite)
(hf : ∀ i ∈ s, IsCompact (f i)) : IsCompact (⋃ i ∈ s, f i) :=
isCompact_iff_ultrafilter_le_nhds'.2 fun l hl => by
rw [Ultrafilter.finite_biUnion_mem_iff hs] at hl
rcases hl with ⟨i, his, hi⟩
rcases (hf i his).ultrafilter_le_nhds _ (le_principal_iff.2 hi) with ⟨x, hxi, hlx⟩
exact ⟨x, mem_iUnion₂.2 ⟨i, his, hxi⟩, hlx⟩
theorem Finset.isCompact_biUnion (s : Finset ι) {f : ι → Set X} (hf : ∀ i ∈ s, IsCompact (f i)) :
IsCompact (⋃ i ∈ s, f i) :=
s.finite_toSet.isCompact_biUnion hf
theorem isCompact_accumulate {K : ℕ → Set X} (hK : ∀ n, IsCompact (K n)) (n : ℕ) :
IsCompact (Accumulate K n) :=
(finite_le_nat n).isCompact_biUnion fun k _ => hK k
theorem Set.Finite.isCompact_sUnion {S : Set (Set X)} (hf : S.Finite) (hc : ∀ s ∈ S, IsCompact s) :
IsCompact (⋃₀ S) := by
rw [sUnion_eq_biUnion]; exact hf.isCompact_biUnion hc
theorem isCompact_iUnion {ι : Sort*} {f : ι → Set X} [Finite ι] (h : ∀ i, IsCompact (f i)) :
IsCompact (⋃ i, f i) :=
(finite_range f).isCompact_sUnion <| forall_mem_range.2 h
@[simp] theorem Set.Finite.isCompact (hs : s.Finite) : IsCompact s :=
biUnion_of_singleton s ▸ hs.isCompact_biUnion fun _ _ => isCompact_singleton
theorem IsCompact.finite_of_discrete [DiscreteTopology X] (hs : IsCompact s) : s.Finite := by
have : ∀ x : X, ({x} : Set X) ∈ 𝓝 x := by simp [nhds_discrete]
rcases hs.elim_nhds_subcover (fun x => {x}) fun x _ => this x with ⟨t, _, hst⟩
simp only [← t.set_biUnion_coe, biUnion_of_singleton] at hst
exact t.finite_toSet.subset hst
theorem isCompact_iff_finite [DiscreteTopology X] : IsCompact s ↔ s.Finite :=
⟨fun h => h.finite_of_discrete, fun h => h.isCompact⟩
theorem IsCompact.union (hs : IsCompact s) (ht : IsCompact t) : IsCompact (s ∪ t) := by
rw [union_eq_iUnion]; exact isCompact_iUnion fun b => by cases b <;> assumption
protected theorem IsCompact.insert (hs : IsCompact s) (a) : IsCompact (insert a s) :=
isCompact_singleton.union hs
-- TODO: reformulate using `𝓝ˢ`
/-- If `V : ι → Set X` is a decreasing family of closed compact sets then any neighborhood of
`⋂ i, V i` contains some `V i`. We assume each `V i` is compact *and* closed because `X` is
not assumed to be Hausdorff. See `exists_subset_nhd_of_compact` for version assuming this. -/
theorem exists_subset_nhds_of_isCompact' [Nonempty ι] {V : ι → Set X}
(hV : Directed (· ⊇ ·) V) (hV_cpct : ∀ i, IsCompact (V i)) (hV_closed : ∀ i, IsClosed (V i))
{U : Set X} (hU : ∀ x ∈ ⋂ i, V i, U ∈ 𝓝 x) : ∃ i, V i ⊆ U := by
obtain ⟨W, hsubW, W_op, hWU⟩ := exists_open_set_nhds hU
suffices ∃ i, V i ⊆ W from this.imp fun i hi => hi.trans hWU
by_contra! H
replace H : ∀ i, (V i ∩ Wᶜ).Nonempty := fun i => Set.inter_compl_nonempty_iff.mpr (H i)
have : (⋂ i, V i ∩ Wᶜ).Nonempty := by
refine
IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed _ (fun i j => ?_) H
(fun i => (hV_cpct i).inter_right W_op.isClosed_compl) fun i =>
(hV_closed i).inter W_op.isClosed_compl
rcases hV i j with ⟨k, hki, hkj⟩
refine ⟨k, ⟨fun x => ?_, fun x => ?_⟩⟩ <;> simp only [and_imp, mem_inter_iff, mem_compl_iff] <;>
tauto
have : ¬⋂ i : ι, V i ⊆ W := by simpa [← iInter_inter, inter_compl_nonempty_iff]
contradiction
namespace Filter
theorem hasBasis_cocompact : (cocompact X).HasBasis IsCompact compl :=
hasBasis_biInf_principal'
(fun s hs t ht =>
⟨s ∪ t, hs.union ht, compl_subset_compl.2 subset_union_left,
compl_subset_compl.2 subset_union_right⟩)
⟨∅, isCompact_empty⟩
theorem mem_cocompact : s ∈ cocompact X ↔ ∃ t, IsCompact t ∧ tᶜ ⊆ s :=
hasBasis_cocompact.mem_iff
theorem mem_cocompact' : s ∈ cocompact X ↔ ∃ t, IsCompact t ∧ sᶜ ⊆ t :=
mem_cocompact.trans <| exists_congr fun _ => and_congr_right fun _ => compl_subset_comm
theorem _root_.IsCompact.compl_mem_cocompact (hs : IsCompact s) : sᶜ ∈ Filter.cocompact X :=
hasBasis_cocompact.mem_of_mem hs
theorem cocompact_le_cofinite : cocompact X ≤ cofinite := fun s hs =>
compl_compl s ▸ hs.isCompact.compl_mem_cocompact
theorem cocompact_eq_cofinite (X : Type*) [TopologicalSpace X] [DiscreteTopology X] :
cocompact X = cofinite := by
simp only [cocompact, hasBasis_cofinite.eq_biInf, isCompact_iff_finite]
/-- A filter is disjoint from the cocompact filter if and only if it contains a compact set. -/
theorem disjoint_cocompact_left (f : Filter X) :
Disjoint (Filter.cocompact X) f ↔ ∃ K ∈ f, IsCompact K := by
simp_rw [hasBasis_cocompact.disjoint_iff_left, compl_compl]
tauto
/-- A filter is disjoint from the cocompact filter if and only if it contains a compact set. -/
theorem disjoint_cocompact_right (f : Filter X) :
Disjoint f (Filter.cocompact X) ↔ ∃ K ∈ f, IsCompact K := by
simp_rw [hasBasis_cocompact.disjoint_iff_right, compl_compl]
tauto
theorem Tendsto.isCompact_insert_range_of_cocompact {f : X → Y} {y}
(hf : Tendsto f (cocompact X) (𝓝 y)) (hfc : Continuous f) : IsCompact (insert y (range f)) := by
intro l hne hle
by_cases hy : ClusterPt y l
· exact ⟨y, Or.inl rfl, hy⟩
simp only [clusterPt_iff_nonempty, not_forall, ← not_disjoint_iff_nonempty_inter, not_not] at hy
rcases hy with ⟨s, hsy, t, htl, hd⟩
rcases mem_cocompact.1 (hf hsy) with ⟨K, hKc, hKs⟩
have : f '' K ∈ l := by
filter_upwards [htl, le_principal_iff.1 hle] with y hyt hyf
rcases hyf with (rfl | ⟨x, rfl⟩)
exacts [(hd.le_bot ⟨mem_of_mem_nhds hsy, hyt⟩).elim,
mem_image_of_mem _ (not_not.1 fun hxK => hd.le_bot ⟨hKs hxK, hyt⟩)]
rcases hKc.image hfc (le_principal_iff.2 this) with ⟨y, hy, hyl⟩
exact ⟨y, Or.inr <| image_subset_range _ _ hy, hyl⟩
theorem Tendsto.isCompact_insert_range_of_cofinite {f : ι → X} {x} (hf : Tendsto f cofinite (𝓝 x)) :
IsCompact (insert x (range f)) := by
letI : TopologicalSpace ι := ⊥; haveI h : DiscreteTopology ι := ⟨rfl⟩
rw [← cocompact_eq_cofinite ι] at hf
exact hf.isCompact_insert_range_of_cocompact continuous_of_discreteTopology
theorem Tendsto.isCompact_insert_range {f : ℕ → X} {x} (hf : Tendsto f atTop (𝓝 x)) :
IsCompact (insert x (range f)) :=
Filter.Tendsto.isCompact_insert_range_of_cofinite <| Nat.cofinite_eq_atTop.symm ▸ hf
theorem hasBasis_coclosedCompact :
(Filter.coclosedCompact X).HasBasis (fun s => IsClosed s ∧ IsCompact s) compl := by
simp only [Filter.coclosedCompact, iInf_and']
refine hasBasis_biInf_principal' ?_ ⟨∅, isClosed_empty, isCompact_empty⟩
rintro s ⟨hs₁, hs₂⟩ t ⟨ht₁, ht₂⟩
exact ⟨s ∪ t, ⟨⟨hs₁.union ht₁, hs₂.union ht₂⟩, compl_subset_compl.2 subset_union_left,
compl_subset_compl.2 subset_union_right⟩⟩
/-- A set belongs to `coclosedCompact` if and only if the closure of its complement is compact. -/
theorem mem_coclosedCompact_iff :
s ∈ coclosedCompact X ↔ IsCompact (closure sᶜ) := by
refine hasBasis_coclosedCompact.mem_iff.trans ⟨?_, fun h ↦ ?_⟩
· rintro ⟨t, ⟨htcl, htco⟩, hst⟩
exact htco.of_isClosed_subset isClosed_closure <|
closure_minimal (compl_subset_comm.2 hst) htcl
· exact ⟨closure sᶜ, ⟨isClosed_closure, h⟩, compl_subset_comm.2 subset_closure⟩
/-- Complement of a set belongs to `coclosedCompact` if and only if its closure is compact. -/
theorem compl_mem_coclosedCompact : sᶜ ∈ coclosedCompact X ↔ IsCompact (closure s) := by
rw [mem_coclosedCompact_iff, compl_compl]
theorem cocompact_le_coclosedCompact : cocompact X ≤ coclosedCompact X :=
iInf_mono fun _ => le_iInf fun _ => le_rfl
end Filter
theorem IsCompact.compl_mem_coclosedCompact_of_isClosed (hs : IsCompact s) (hs' : IsClosed s) :
sᶜ ∈ Filter.coclosedCompact X :=
hasBasis_coclosedCompact.mem_of_mem ⟨hs', hs⟩
namespace Bornology
variable (X) in
/-- Sets that are contained in a compact set form a bornology. Its `cobounded` filter is
`Filter.cocompact`. See also `Bornology.relativelyCompact` the bornology of sets with compact
closure. -/
def inCompact : Bornology X where
cobounded' := Filter.cocompact X
le_cofinite' := Filter.cocompact_le_cofinite
theorem inCompact.isBounded_iff : @IsBounded _ (inCompact X) s ↔ ∃ t, IsCompact t ∧ s ⊆ t := by
change sᶜ ∈ Filter.cocompact X ↔ _
rw [Filter.mem_cocompact]
simp
end Bornology
/-- If `s` and `t` are compact sets, then the set neighborhoods filter of `s ×ˢ t`
is the product of set neighborhoods filters for `s` and `t`.
For general sets, only the `≤` inequality holds, see `nhdsSet_prod_le`. -/
theorem IsCompact.nhdsSet_prod_eq {t : Set Y} (hs : IsCompact s) (ht : IsCompact t) :
𝓝ˢ (s ×ˢ t) = 𝓝ˢ s ×ˢ 𝓝ˢ t := by
simp_rw [hs.nhdsSet_prod_eq_biSup, ht.prod_nhdsSet_eq_biSup, nhdsSet, sSup_image, biSup_prod,
nhds_prod_eq]
theorem nhdsSet_prod_le_of_disjoint_cocompact {f : Filter Y} (hs : IsCompact s)
(hf : Disjoint f (Filter.cocompact Y)) :
𝓝ˢ s ×ˢ f ≤ 𝓝ˢ (s ×ˢ Set.univ) := by
obtain ⟨K, hKf, hK⟩ := (disjoint_cocompact_right f).mp hf
calc
𝓝ˢ s ×ˢ f
_ ≤ 𝓝ˢ s ×ˢ 𝓟 K := Filter.prod_mono_right _ (Filter.le_principal_iff.mpr hKf)
_ ≤ 𝓝ˢ s ×ˢ 𝓝ˢ K := Filter.prod_mono_right _ principal_le_nhdsSet
_ = 𝓝ˢ (s ×ˢ K) := (hs.nhdsSet_prod_eq hK).symm
_ ≤ 𝓝ˢ (s ×ˢ Set.univ) := nhdsSet_mono (prod_mono_right le_top)
theorem prod_nhdsSet_le_of_disjoint_cocompact {t : Set Y} {f : Filter X} (ht : IsCompact t)
(hf : Disjoint f (Filter.cocompact X)) :
f ×ˢ 𝓝ˢ t ≤ 𝓝ˢ (Set.univ ×ˢ t) := by
obtain ⟨K, hKf, hK⟩ := (disjoint_cocompact_right f).mp hf
calc
f ×ˢ 𝓝ˢ t
_ ≤ (𝓟 K) ×ˢ 𝓝ˢ t := Filter.prod_mono_left _ (Filter.le_principal_iff.mpr hKf)
_ ≤ 𝓝ˢ K ×ˢ 𝓝ˢ t := Filter.prod_mono_left _ principal_le_nhdsSet
_ = 𝓝ˢ (K ×ˢ t) := (hK.nhdsSet_prod_eq ht).symm
_ ≤ 𝓝ˢ (Set.univ ×ˢ t) := nhdsSet_mono (prod_mono_left le_top)
theorem nhds_prod_le_of_disjoint_cocompact {f : Filter Y} (x : X)
(hf : Disjoint f (Filter.cocompact Y)) :
𝓝 x ×ˢ f ≤ 𝓝ˢ ({x} ×ˢ Set.univ) := by
simpa using nhdsSet_prod_le_of_disjoint_cocompact isCompact_singleton hf
theorem prod_nhds_le_of_disjoint_cocompact {f : Filter X} (y : Y)
(hf : Disjoint f (Filter.cocompact X)) :
f ×ˢ 𝓝 y ≤ 𝓝ˢ (Set.univ ×ˢ {y}) := by
simpa using prod_nhdsSet_le_of_disjoint_cocompact isCompact_singleton hf
/-- If `s` and `t` are compact sets and `n` is an open neighborhood of `s × t`, then there exist
open neighborhoods `u ⊇ s` and `v ⊇ t` such that `u × v ⊆ n`.
See also `IsCompact.nhdsSet_prod_eq`. -/
theorem generalized_tube_lemma (hs : IsCompact s) {t : Set Y} (ht : IsCompact t)
{n : Set (X × Y)} (hn : IsOpen n) (hp : s ×ˢ t ⊆ n) :
∃ (u : Set X) (v : Set Y), IsOpen u ∧ IsOpen v ∧ s ⊆ u ∧ t ⊆ v ∧ u ×ˢ v ⊆ n := by
rw [← hn.mem_nhdsSet, hs.nhdsSet_prod_eq ht,
((hasBasis_nhdsSet _).prod (hasBasis_nhdsSet _)).mem_iff] at hp
rcases hp with ⟨⟨u, v⟩, ⟨⟨huo, hsu⟩, hvo, htv⟩, hn⟩
exact ⟨u, v, huo, hvo, hsu, htv, hn⟩
-- see Note [lower instance priority]
instance (priority := 10) Subsingleton.compactSpace [Subsingleton X] : CompactSpace X :=
⟨subsingleton_univ.isCompact⟩
theorem isCompact_univ_iff : IsCompact (univ : Set X) ↔ CompactSpace X :=
⟨fun h => ⟨h⟩, fun h => h.1⟩
theorem isCompact_univ [h : CompactSpace X] : IsCompact (univ : Set X) :=
h.isCompact_univ
theorem exists_clusterPt_of_compactSpace [CompactSpace X] (f : Filter X) [NeBot f] :
∃ x, ClusterPt x f := by
simpa using isCompact_univ (show f ≤ 𝓟 univ by simp)
nonrec theorem Ultrafilter.le_nhds_lim [CompactSpace X] (F : Ultrafilter X) : ↑F ≤ 𝓝 F.lim := by
rcases isCompact_univ.ultrafilter_le_nhds F (by simp) with ⟨x, -, h⟩
exact le_nhds_lim ⟨x, h⟩
theorem CompactSpace.elim_nhds_subcover [CompactSpace X] (U : X → Set X) (hU : ∀ x, U x ∈ 𝓝 x) :
∃ t : Finset X, ⋃ x ∈ t, U x = ⊤ := by
obtain ⟨t, -, s⟩ := IsCompact.elim_nhds_subcover isCompact_univ U fun x _ => hU x
exact ⟨t, top_unique s⟩
theorem compactSpace_of_finite_subfamily_closed
(h : ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → ⋂ i, t i = ∅ →
∃ u : Finset ι, ⋂ i ∈ u, t i = ∅) :
CompactSpace X where
isCompact_univ := isCompact_of_finite_subfamily_closed fun t => by simpa using h t
theorem IsClosed.isCompact [CompactSpace X] (h : IsClosed s) : IsCompact s :=
isCompact_univ.of_isClosed_subset h (subset_univ _)
/-- If a filter has a unique cluster point `y` in a compact topological space,
then the filter is less than or equal to `𝓝 y`. -/
lemma le_nhds_of_unique_clusterPt [CompactSpace X] {l : Filter X} {y : X}
(h : ∀ x, ClusterPt x l → x = y) : l ≤ 𝓝 y :=
isCompact_univ.le_nhds_of_unique_clusterPt univ_mem fun x _ ↦ h x
/-- If `y` is a unique `MapClusterPt` for `f` along `l`
and the codomain of `f` is a compact space,
then `f` tends to `𝓝 y` along `l`. -/
lemma tendsto_nhds_of_unique_mapClusterPt [CompactSpace X] {Y} {l : Filter Y} {y : X} {f : Y → X}
(h : ∀ x, MapClusterPt x l f → x = y) :
Tendsto f l (𝓝 y) :=
le_nhds_of_unique_clusterPt h
lemma noncompact_univ (X : Type*) [TopologicalSpace X] [NoncompactSpace X] :
¬IsCompact (univ : Set X) :=
NoncompactSpace.noncompact_univ
theorem IsCompact.ne_univ [NoncompactSpace X] (hs : IsCompact s) : s ≠ univ := fun h =>
noncompact_univ X (h ▸ hs)
instance [NoncompactSpace X] : NeBot (Filter.cocompact X) := by
refine Filter.hasBasis_cocompact.neBot_iff.2 fun hs => ?_
contrapose hs; rw [not_nonempty_iff_eq_empty, compl_empty_iff] at hs
rw [hs]; exact noncompact_univ X
@[simp]
theorem Filter.cocompact_eq_bot [CompactSpace X] : Filter.cocompact X = ⊥ :=
Filter.hasBasis_cocompact.eq_bot_iff.mpr ⟨Set.univ, isCompact_univ, Set.compl_univ⟩
instance [NoncompactSpace X] : NeBot (Filter.coclosedCompact X) :=
neBot_of_le Filter.cocompact_le_coclosedCompact
theorem noncompactSpace_of_neBot (_ : NeBot (Filter.cocompact X)) : NoncompactSpace X :=
⟨fun h' => (Filter.nonempty_of_mem h'.compl_mem_cocompact).ne_empty compl_univ⟩
theorem Filter.cocompact_neBot_iff : NeBot (Filter.cocompact X) ↔ NoncompactSpace X :=
⟨noncompactSpace_of_neBot, fun _ => inferInstance⟩
theorem not_compactSpace_iff : ¬CompactSpace X ↔ NoncompactSpace X :=
⟨fun h₁ => ⟨fun h₂ => h₁ ⟨h₂⟩⟩, fun ⟨h₁⟩ ⟨h₂⟩ => h₁ h₂⟩
instance : NoncompactSpace ℤ :=
noncompactSpace_of_neBot <| by simp only [Filter.cocompact_eq_cofinite, Filter.cofinite_neBot]
-- Note: We can't make this into an instance because it loops with `Finite.compactSpace`.
/-- A compact discrete space is finite. -/
theorem finite_of_compact_of_discrete [CompactSpace X] [DiscreteTopology X] : Finite X :=
Finite.of_finite_univ <| isCompact_univ.finite_of_discrete
lemma Set.Infinite.exists_accPt_cofinite_inf_principal_of_subset_isCompact
{K : Set X} (hs : s.Infinite) (hK : IsCompact K) (hsub : s ⊆ K) :
∃ x ∈ K, AccPt x (cofinite ⊓ 𝓟 s) :=
(@hK _ hs.cofinite_inf_principal_neBot (inf_le_right.trans <| principal_mono.2 hsub)).imp
fun x hx ↦ by rwa [accPt_iff_clusterPt, inf_comm, inf_right_comm,
(finite_singleton _).cofinite_inf_principal_compl]
lemma Set.Infinite.exists_accPt_of_subset_isCompact {K : Set X} (hs : s.Infinite)
(hK : IsCompact K) (hsub : s ⊆ K) : ∃ x ∈ K, AccPt x (𝓟 s) :=
let ⟨x, hxK, hx⟩ := hs.exists_accPt_cofinite_inf_principal_of_subset_isCompact hK hsub
⟨x, hxK, hx.mono inf_le_right⟩
lemma Set.Infinite.exists_accPt_cofinite_inf_principal [CompactSpace X] (hs : s.Infinite) :
∃ x, AccPt x (cofinite ⊓ 𝓟 s) := by
simpa only [mem_univ, true_and]
using hs.exists_accPt_cofinite_inf_principal_of_subset_isCompact isCompact_univ s.subset_univ
lemma Set.Infinite.exists_accPt_principal [CompactSpace X] (hs : s.Infinite) : ∃ x, AccPt x (𝓟 s) :=
hs.exists_accPt_cofinite_inf_principal.imp fun _x hx ↦ hx.mono inf_le_right
theorem exists_nhds_ne_neBot (X : Type*) [TopologicalSpace X] [CompactSpace X] [Infinite X] :
∃ z : X, (𝓝[≠] z).NeBot := by
simpa [AccPt] using (@infinite_univ X _).exists_accPt_principal
theorem finite_cover_nhds_interior [CompactSpace X] {U : X → Set X} (hU : ∀ x, U x ∈ 𝓝 x) :
∃ t : Finset X, ⋃ x ∈ t, interior (U x) = univ :=
let ⟨t, ht⟩ := isCompact_univ.elim_finite_subcover (fun x => interior (U x))
(fun _ => isOpen_interior) fun x _ => mem_iUnion.2 ⟨x, mem_interior_iff_mem_nhds.2 (hU x)⟩
⟨t, univ_subset_iff.1 ht⟩
theorem finite_cover_nhds [CompactSpace X] {U : X → Set X} (hU : ∀ x, U x ∈ 𝓝 x) :
∃ t : Finset X, ⋃ x ∈ t, U x = univ :=
let ⟨t, ht⟩ := finite_cover_nhds_interior hU
⟨t, univ_subset_iff.1 <| ht.symm.subset.trans <| iUnion₂_mono fun _ _ => interior_subset⟩
/-- The comap of the cocompact filter on `Y` by a continuous function `f : X → Y` is less than or
equal to the cocompact filter on `X`.
This is a reformulation of the fact that images of compact sets are compact. -/
theorem Filter.comap_cocompact_le {f : X → Y} (hf : Continuous f) :
(Filter.cocompact Y).comap f ≤ Filter.cocompact X := by
rw [(Filter.hasBasis_cocompact.comap f).le_basis_iff Filter.hasBasis_cocompact]
intro t ht
refine ⟨f '' t, ht.image hf, ?_⟩
simpa using t.subset_preimage_image f
/-- If a filter is disjoint from the cocompact filter, so is its image under any continuous
function. -/
theorem disjoint_map_cocompact {g : X → Y} {f : Filter X} (hg : Continuous g)
(hf : Disjoint f (Filter.cocompact X)) : Disjoint (map g f) (Filter.cocompact Y) := by
rw [← Filter.disjoint_comap_iff_map, disjoint_iff_inf_le]
calc
f ⊓ (comap g (cocompact Y))
_ ≤ f ⊓ Filter.cocompact X := inf_le_inf_left f (Filter.comap_cocompact_le hg)
_ = ⊥ := disjoint_iff.mp hf
theorem isCompact_range [CompactSpace X] {f : X → Y} (hf : Continuous f) : IsCompact (range f) := by
rw [← image_univ]; exact isCompact_univ.image hf
theorem isCompact_diagonal [CompactSpace X] : IsCompact (diagonal X) :=
@range_diag X ▸ isCompact_range (continuous_id.prodMk continuous_id)
/-- If `X` is a compact topological space, then `Prod.snd : X × Y → Y` is a closed map. -/
theorem isClosedMap_snd_of_compactSpace [CompactSpace X] :
IsClosedMap (Prod.snd : X × Y → Y) := fun s hs => by
rw [← isOpen_compl_iff, isOpen_iff_mem_nhds]
intro y hy
have : univ ×ˢ {y} ⊆ sᶜ := by
exact fun (x, y') ⟨_, rfl⟩ hs => hy ⟨(x, y'), hs, rfl⟩
rcases generalized_tube_lemma isCompact_univ isCompact_singleton hs.isOpen_compl this
with ⟨U, V, -, hVo, hU, hV, hs⟩
refine mem_nhds_iff.2 ⟨V, ?_, hVo, hV rfl⟩
rintro _ hzV ⟨z, hzs, rfl⟩
exact hs ⟨hU trivial, hzV⟩ hzs
/-- If `Y` is a compact topological space, then `Prod.fst : X × Y → X` is a closed map. -/
theorem isClosedMap_fst_of_compactSpace [CompactSpace Y] : IsClosedMap (Prod.fst : X × Y → X) :=
isClosedMap_snd_of_compactSpace.comp isClosedMap_swap
theorem exists_subset_nhds_of_compactSpace [CompactSpace X] [Nonempty ι]
{V : ι → Set X} (hV : Directed (· ⊇ ·) V) (hV_closed : ∀ i, IsClosed (V i)) {U : Set X}
(hU : ∀ x ∈ ⋂ i, V i, U ∈ 𝓝 x) : ∃ i, V i ⊆ U :=
exists_subset_nhds_of_isCompact' hV (fun i => (hV_closed i).isCompact) hV_closed hU
/-- If `f : X → Y` is an inducing map, the image `f '' s` of a set `s` is compact
if and only if `s` is compact. -/
theorem Topology.IsInducing.isCompact_iff {f : X → Y} (hf : IsInducing f) :
IsCompact s ↔ IsCompact (f '' s) := by
refine ⟨fun hs => hs.image hf.continuous, fun hs F F_ne_bot F_le => ?_⟩
obtain ⟨_, ⟨x, x_in : x ∈ s, rfl⟩, hx : ClusterPt (f x) (map f F)⟩ :=
hs ((map_mono F_le).trans_eq map_principal)
exact ⟨x, x_in, hf.mapClusterPt_iff.1 hx⟩
@[deprecated (since := "2024-10-28")] alias Inducing.isCompact_iff := IsInducing.isCompact_iff
/-- If `f : X → Y` is an embedding, the image `f '' s` of a set `s` is compact
if and only if `s` is compact. -/
theorem Topology.IsEmbedding.isCompact_iff {f : X → Y} (hf : IsEmbedding f) :
IsCompact s ↔ IsCompact (f '' s) := hf.isInducing.isCompact_iff
@[deprecated (since := "2024-10-26")]
alias Embedding.isCompact_iff := IsEmbedding.isCompact_iff
/-- The preimage of a compact set under an inducing map is a compact set. -/
theorem Topology.IsInducing.isCompact_preimage (hf : IsInducing f) (hf' : IsClosed (range f))
{K : Set Y} (hK : IsCompact K) : IsCompact (f ⁻¹' K) := by
replace hK := hK.inter_right hf'
rwa [hf.isCompact_iff, image_preimage_eq_inter_range]
@[deprecated (since := "2024-10-28")]
alias Inducing.isCompact_preimage := IsInducing.isCompact_preimage
lemma Topology.IsInducing.isCompact_preimage_iff {f : X → Y} (hf : IsInducing f) {K : Set Y}
(Kf : K ⊆ range f) : IsCompact (f ⁻¹' K) ↔ IsCompact K := by
rw [hf.isCompact_iff, image_preimage_eq_of_subset Kf]
@[deprecated (since := "2024-10-28")]
alias Inducing.isCompact_preimage_iff := IsInducing.isCompact_preimage_iff
/-- The preimage of a compact set in the image of an inducing map is compact. -/
lemma Topology.IsInducing.isCompact_preimage' (hf : IsInducing f) {K : Set Y}
(hK : IsCompact K) (Kf : K ⊆ range f) : IsCompact (f ⁻¹' K) :=
(hf.isCompact_preimage_iff Kf).2 hK
@[deprecated (since := "2024-10-28")]
alias Inducing.isCompact_preimage' := IsInducing.isCompact_preimage'
/-- The preimage of a compact set under a closed embedding is a compact set. -/
theorem Topology.IsClosedEmbedding.isCompact_preimage (hf : IsClosedEmbedding f)
{K : Set Y} (hK : IsCompact K) : IsCompact (f ⁻¹' K) :=
hf.isInducing.isCompact_preimage (hf.isClosed_range) hK
/-- A closed embedding is proper, ie, inverse images of compact sets are contained in compacts.
Moreover, the preimage of a compact set is compact, see `IsClosedEmbedding.isCompact_preimage`. -/
theorem Topology.IsClosedEmbedding.tendsto_cocompact (hf : IsClosedEmbedding f) :
Tendsto f (Filter.cocompact X) (Filter.cocompact Y) :=
Filter.hasBasis_cocompact.tendsto_right_iff.mpr fun _K hK =>
(hf.isCompact_preimage hK).compl_mem_cocompact
/-- Sets of subtype are compact iff the image under a coercion is. -/
theorem Subtype.isCompact_iff {p : X → Prop} {s : Set { x // p x }} :
IsCompact s ↔ IsCompact ((↑) '' s : Set X) :=
IsEmbedding.subtypeVal.isCompact_iff
theorem isCompact_iff_isCompact_univ : IsCompact s ↔ IsCompact (univ : Set s) := by
rw [Subtype.isCompact_iff, image_univ, Subtype.range_coe]
theorem isCompact_iff_compactSpace : IsCompact s ↔ CompactSpace s :=
isCompact_iff_isCompact_univ.trans isCompact_univ_iff
theorem IsCompact.finite (hs : IsCompact s) (hs' : DiscreteTopology s) : s.Finite :=
finite_coe_iff.mp (@finite_of_compact_of_discrete _ _ (isCompact_iff_compactSpace.mp hs) hs')
theorem exists_nhds_ne_inf_principal_neBot (hs : IsCompact s) (hs' : s.Infinite) :
∃ z ∈ s, (𝓝[≠] z ⊓ 𝓟 s).NeBot :=
hs'.exists_accPt_of_subset_isCompact hs Subset.rfl
protected theorem Topology.IsClosedEmbedding.noncompactSpace [NoncompactSpace X] {f : X → Y}
(hf : IsClosedEmbedding f) : NoncompactSpace Y :=
noncompactSpace_of_neBot hf.tendsto_cocompact.neBot
protected theorem Topology.IsClosedEmbedding.compactSpace [h : CompactSpace Y] {f : X → Y}
(hf : IsClosedEmbedding f) : CompactSpace X :=
⟨by rw [hf.isInducing.isCompact_iff, image_univ]; exact hf.isClosed_range.isCompact⟩
theorem IsCompact.prod {t : Set Y} (hs : IsCompact s) (ht : IsCompact t) :
IsCompact (s ×ˢ t) := by
rw [isCompact_iff_ultrafilter_le_nhds'] at hs ht ⊢
intro f hfs
obtain ⟨x : X, sx : x ∈ s, hx : map Prod.fst f.1 ≤ 𝓝 x⟩ :=
hs (f.map Prod.fst) (mem_map.2 <| mem_of_superset hfs fun x => And.left)
obtain ⟨y : Y, ty : y ∈ t, hy : map Prod.snd f.1 ≤ 𝓝 y⟩ :=
ht (f.map Prod.snd) (mem_map.2 <| mem_of_superset hfs fun x => And.right)
rw [map_le_iff_le_comap] at hx hy
refine ⟨⟨x, y⟩, ⟨sx, ty⟩, ?_⟩
rw [nhds_prod_eq]; exact le_inf hx hy
/-- Finite topological spaces are compact. -/
instance (priority := 100) Finite.compactSpace [Finite X] : CompactSpace X where
isCompact_univ := finite_univ.isCompact
instance ULift.compactSpace [CompactSpace X] : CompactSpace (ULift.{v} X) :=
IsClosedEmbedding.uliftDown.compactSpace
/-- The product of two compact spaces is compact. -/
instance [CompactSpace X] [CompactSpace Y] : CompactSpace (X × Y) :=
⟨by rw [← univ_prod_univ]; exact isCompact_univ.prod isCompact_univ⟩
/-- The disjoint union of two compact spaces is compact. -/
instance [CompactSpace X] [CompactSpace Y] : CompactSpace (X ⊕ Y) :=
⟨by
rw [← range_inl_union_range_inr]
exact (isCompact_range continuous_inl).union (isCompact_range continuous_inr)⟩
instance {X : ι → Type*} [Finite ι] [∀ i, TopologicalSpace (X i)] [∀ i, CompactSpace (X i)] :
CompactSpace (Σi, X i) := by
refine ⟨?_⟩
rw [Sigma.univ]
exact isCompact_iUnion fun i => isCompact_range continuous_sigmaMk
/-- The coproduct of the cocompact filters on two topological spaces is the cocompact filter on
their product. -/
theorem Filter.coprod_cocompact :
(Filter.cocompact X).coprod (Filter.cocompact Y) = Filter.cocompact (X × Y) := by
apply le_antisymm
· exact sup_le (comap_cocompact_le continuous_fst) (comap_cocompact_le continuous_snd)
· refine (hasBasis_cocompact.coprod hasBasis_cocompact).ge_iff.2 fun K hK ↦ ?_
rw [← univ_prod, ← prod_univ, ← compl_prod_eq_union]
exact (hK.1.prod hK.2).compl_mem_cocompact
theorem Prod.noncompactSpace_iff :
NoncompactSpace (X × Y) ↔ NoncompactSpace X ∧ Nonempty Y ∨ Nonempty X ∧ NoncompactSpace Y := by
simp [← Filter.cocompact_neBot_iff, ← Filter.coprod_cocompact, Filter.coprod_neBot_iff]
-- See Note [lower instance priority]
instance (priority := 100) Prod.noncompactSpace_left [NoncompactSpace X] [Nonempty Y] :
NoncompactSpace (X × Y) :=
Prod.noncompactSpace_iff.2 (Or.inl ⟨‹_›, ‹_›⟩)
-- See Note [lower instance priority]
instance (priority := 100) Prod.noncompactSpace_right [Nonempty X] [NoncompactSpace Y] :
NoncompactSpace (X × Y) :=
Prod.noncompactSpace_iff.2 (Or.inr ⟨‹_›, ‹_›⟩)
section Tychonoff
variable {X : ι → Type*} [∀ i, TopologicalSpace (X i)]
/-- **Tychonoff's theorem**: product of compact sets is compact. -/
theorem isCompact_pi_infinite {s : ∀ i, Set (X i)} :
(∀ i, IsCompact (s i)) → IsCompact { x : ∀ i, X i | ∀ i, x i ∈ s i } := by
simp only [isCompact_iff_ultrafilter_le_nhds, nhds_pi, le_pi, le_principal_iff]
intro h f hfs
have : ∀ i : ι, ∃ x, x ∈ s i ∧ Tendsto (Function.eval i) f (𝓝 x) := by
refine fun i => h i (f.map _) (mem_map.2 ?_)
exact mem_of_superset hfs fun x hx => hx i
choose x hx using this
exact ⟨x, fun i => (hx i).left, fun i => (hx i).right⟩
/-- **Tychonoff's theorem** formulated using `Set.pi`: product of compact sets is compact. -/
theorem isCompact_univ_pi {s : ∀ i, Set (X i)} (h : ∀ i, IsCompact (s i)) :
IsCompact (pi univ s) := by
convert isCompact_pi_infinite h
simp only [← mem_univ_pi, setOf_mem_eq]
instance Pi.compactSpace [∀ i, CompactSpace (X i)] : CompactSpace (∀ i, X i) :=
⟨by rw [← pi_univ univ]; exact isCompact_univ_pi fun i => isCompact_univ⟩
instance Function.compactSpace [CompactSpace Y] : CompactSpace (ι → Y) :=
Pi.compactSpace
lemma Pi.isCompact_iff_of_isClosed {s : Set (Π i, X i)} (hs : IsClosed s) :
IsCompact s ↔ ∀ i, IsCompact (eval i '' s) := by
constructor <;> intro H
· exact fun i ↦ H.image <| continuous_apply i
· exact IsCompact.of_isClosed_subset (isCompact_univ_pi H) hs (subset_pi_eval_image univ s)
protected lemma Pi.exists_compact_superset_iff {s : Set (Π i, X i)} :
(∃ K, IsCompact K ∧ s ⊆ K) ↔ ∀ i, ∃ Ki, IsCompact Ki ∧ s ⊆ eval i ⁻¹' Ki := by
constructor
· intro ⟨K, hK, hsK⟩ i
exact ⟨eval i '' K, hK.image <| continuous_apply i, hsK.trans <| K.subset_preimage_image _⟩
· intro H
choose K hK hsK using H
exact ⟨pi univ K, isCompact_univ_pi hK, fun _ hx i _ ↦ hsK i hx⟩
/-- **Tychonoff's theorem** formulated in terms of filters: `Filter.cocompact` on an indexed product
type `Π d, X d` the `Filter.coprodᵢ` of filters `Filter.cocompact` on `X d`. -/
theorem Filter.coprodᵢ_cocompact {X : ι → Type*} [∀ d, TopologicalSpace (X d)] :
(Filter.coprodᵢ fun d => Filter.cocompact (X d)) = Filter.cocompact (∀ d, X d) := by
refine le_antisymm (iSup_le fun i => Filter.comap_cocompact_le (continuous_apply i)) ?_
refine compl_surjective.forall.2 fun s H => ?_
simp only [compl_mem_coprodᵢ, Filter.mem_cocompact, compl_subset_compl, image_subset_iff] at H ⊢
choose K hKc htK using H
exact ⟨Set.pi univ K, isCompact_univ_pi hKc, fun f hf i _ => htK i hf⟩
end Tychonoff
instance Quot.compactSpace {r : X → X → Prop} [CompactSpace X] : CompactSpace (Quot r) :=
⟨by
rw [← range_quot_mk]
exact isCompact_range continuous_quot_mk⟩
instance Quotient.compactSpace {s : Setoid X} [CompactSpace X] : CompactSpace (Quotient s) :=
Quot.compactSpace
theorem IsClosed.exists_minimal_nonempty_closed_subset [CompactSpace X] {S : Set X}
(hS : IsClosed S) (hne : S.Nonempty) :
∃ V : Set X, V ⊆ S ∧ V.Nonempty ∧ IsClosed V ∧
∀ V' : Set X, V' ⊆ V → V'.Nonempty → IsClosed V' → V' = V := by
let opens := { U : Set X | Sᶜ ⊆ U ∧ IsOpen U ∧ Uᶜ.Nonempty }
obtain ⟨U, h⟩ :=
zorn_subset opens fun c hc hz => by
by_cases hcne : c.Nonempty
· obtain ⟨U₀, hU₀⟩ := hcne
haveI : Nonempty { U // U ∈ c } := ⟨⟨U₀, hU₀⟩⟩
obtain ⟨U₀compl, -, -⟩ := hc hU₀
use ⋃₀ c
refine ⟨⟨?_, ?_, ?_⟩, fun U hU _ hx => ⟨U, hU, hx⟩⟩
· exact fun _ hx => ⟨U₀, hU₀, U₀compl hx⟩
· exact isOpen_sUnion fun _ h => (hc h).2.1
· convert_to (⋂ U : { U // U ∈ c }, U.1ᶜ).Nonempty
· ext
simp only [not_exists, exists_prop, not_and, Set.mem_iInter, Subtype.forall,
mem_setOf_eq, mem_compl_iff, mem_sUnion]
apply IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed
· rintro ⟨U, hU⟩ ⟨U', hU'⟩
obtain ⟨V, hVc, hVU, hVU'⟩ := hz.directedOn U hU U' hU'
exact ⟨⟨V, hVc⟩, Set.compl_subset_compl.mpr hVU, Set.compl_subset_compl.mpr hVU'⟩
· exact fun U => (hc U.2).2.2
· exact fun U => (hc U.2).2.1.isClosed_compl.isCompact
· exact fun U => (hc U.2).2.1.isClosed_compl
· use Sᶜ
refine ⟨⟨Set.Subset.refl _, isOpen_compl_iff.mpr hS, ?_⟩, fun U Uc => (hcne ⟨U, Uc⟩).elim⟩
rw [compl_compl]
exact hne
obtain ⟨Uc, Uo, Ucne⟩ := h.prop
refine ⟨Uᶜ, Set.compl_subset_comm.mp Uc, Ucne, Uo.isClosed_compl, ?_⟩
intro V' V'sub V'ne V'cls
have : V'ᶜ = U := by
refine h.eq_of_ge ⟨?_, isOpen_compl_iff.mpr V'cls, ?_⟩ (subset_compl_comm.2 V'sub)
· exact Set.Subset.trans Uc (Set.subset_compl_comm.mp V'sub)
· simp only [compl_compl, V'ne]
rw [← this, compl_compl]
end Compact
| Mathlib/Topology/Compactness/Compact.lean | 1,106 | 1,112 | |
/-
Copyright (c) 2021 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import Mathlib.GroupTheory.Index
/-!
# Complements
In this file we define the complement of a subgroup.
## Main definitions
- `Subgroup.IsComplement S T` where `S` and `T` are subsets of `G` states that every `g : G` can be
written uniquely as a product `s * t` for `s ∈ S`, `t ∈ T`.
- `H.LeftTransversal` where `H` is a subgroup of `G` is the type of all left-complements of `H`,
i.e. the set of all `S : Set G` that contain exactly one element of each left coset of `H`.
- `H.RightTransversal` where `H` is a subgroup of `G` is the set of all right-complements of `H`,
i.e. the set of all `T : Set G` that contain exactly one element of each right coset of `H`.
## Main results
- `isComplement'_of_coprime` : Subgroups of coprime order are complements.
-/
open Function Set
open scoped Pointwise
namespace Subgroup
variable {G : Type*} [Group G] (H K : Subgroup G) (S T : Set G)
/-- `S` and `T` are complements if `(*) : S × T → G` is a bijection.
This notion generalizes left transversals, right transversals, and complementary subgroups. -/
@[to_additive "`S` and `T` are complements if `(+) : S × T → G` is a bijection"]
def IsComplement : Prop :=
Function.Bijective fun x : S × T => x.1.1 * x.2.1
/-- `H` and `K` are complements if `(*) : H × K → G` is a bijection -/
@[to_additive "`H` and `K` are complements if `(+) : H × K → G` is a bijection"]
abbrev IsComplement' :=
IsComplement (H : Set G) (K : Set G)
/-- The set of left-complements of `T : Set G` -/
@[to_additive (attr := deprecated IsComplement (since := "2024-12-18"))
"The set of left-complements of `T : Set G`"]
def leftTransversals : Set (Set G) :=
{ S : Set G | IsComplement S T }
/-- The set of right-complements of `S : Set G` -/
@[to_additive (attr := deprecated IsComplement (since := "2024-12-18"))
"The set of right-complements of `S : Set G`"]
def rightTransversals : Set (Set G) :=
{ T : Set G | IsComplement S T }
variable {H K S T}
@[to_additive]
theorem isComplement'_def : IsComplement' H K ↔ IsComplement (H : Set G) (K : Set G) :=
Iff.rfl
@[to_additive]
theorem isComplement_iff_existsUnique :
IsComplement S T ↔ ∀ g : G, ∃! x : S × T, x.1.1 * x.2.1 = g :=
Function.bijective_iff_existsUnique _
@[to_additive]
theorem IsComplement.existsUnique (h : IsComplement S T) (g : G) :
∃! x : S × T, x.1.1 * x.2.1 = g :=
isComplement_iff_existsUnique.mp h g
@[to_additive]
theorem IsComplement'.symm (h : IsComplement' H K) : IsComplement' K H := by
let ϕ : H × K ≃ K × H :=
Equiv.mk (fun x => ⟨x.2⁻¹, x.1⁻¹⟩) (fun x => ⟨x.2⁻¹, x.1⁻¹⟩)
(fun x => Prod.ext (inv_inv _) (inv_inv _)) fun x => Prod.ext (inv_inv _) (inv_inv _)
let ψ : G ≃ G := Equiv.mk (fun g : G => g⁻¹) (fun g : G => g⁻¹) inv_inv inv_inv
suffices hf : (ψ ∘ fun x : H × K => x.1.1 * x.2.1) = (fun x : K × H => x.1.1 * x.2.1) ∘ ϕ by
rw [isComplement'_def, IsComplement, ← Equiv.bijective_comp ϕ]
apply (congr_arg Function.Bijective hf).mp -- Porting note: This was a `rw` in mathlib3
rwa [ψ.comp_bijective]
exact funext fun x => mul_inv_rev _ _
@[to_additive]
theorem isComplement'_comm : IsComplement' H K ↔ IsComplement' K H :=
⟨IsComplement'.symm, IsComplement'.symm⟩
@[to_additive]
theorem isComplement_univ_singleton {g : G} : IsComplement (univ : Set G) {g} :=
⟨fun ⟨_, _, rfl⟩ ⟨_, _, rfl⟩ h => Prod.ext (Subtype.ext (mul_right_cancel h)) rfl, fun x =>
⟨⟨⟨x * g⁻¹, ⟨⟩⟩, g, rfl⟩, inv_mul_cancel_right x g⟩⟩
@[to_additive]
theorem isComplement_singleton_univ {g : G} : IsComplement ({g} : Set G) univ :=
⟨fun ⟨⟨_, rfl⟩, _⟩ ⟨⟨_, rfl⟩, _⟩ h => Prod.ext rfl (Subtype.ext (mul_left_cancel h)), fun x =>
⟨⟨⟨g, rfl⟩, g⁻¹ * x, ⟨⟩⟩, mul_inv_cancel_left g x⟩⟩
@[to_additive]
theorem isComplement_singleton_left {g : G} : IsComplement {g} S ↔ S = univ := by
refine
⟨fun h => top_le_iff.mp fun x _ => ?_, fun h => (congr_arg _ h).mpr isComplement_singleton_univ⟩
obtain ⟨⟨⟨z, rfl : z = g⟩, y, _⟩, hy⟩ := h.2 (g * x)
rwa [← mul_left_cancel hy]
@[to_additive]
theorem isComplement_singleton_right {g : G} : IsComplement S {g} ↔ S = univ := by
refine
⟨fun h => top_le_iff.mp fun x _ => ?_, fun h => h ▸ isComplement_univ_singleton⟩
obtain ⟨y, hy⟩ := h.2 (x * g)
conv_rhs at hy => rw [← show y.2.1 = g from y.2.2]
rw [← mul_right_cancel hy]
exact y.1.2
@[to_additive]
theorem isComplement_univ_left : IsComplement univ S ↔ ∃ g : G, S = {g} := by
refine
⟨fun h => Set.exists_eq_singleton_iff_nonempty_subsingleton.mpr ⟨?_, fun a ha b hb => ?_⟩, ?_⟩
· obtain ⟨a, _⟩ := h.2 1
exact ⟨a.2.1, a.2.2⟩
· have : (⟨⟨_, mem_top a⁻¹⟩, ⟨a, ha⟩⟩ : (⊤ : Set G) × S) = ⟨⟨_, mem_top b⁻¹⟩, ⟨b, hb⟩⟩ :=
h.1 ((inv_mul_cancel a).trans (inv_mul_cancel b).symm)
exact Subtype.ext_iff.mp (Prod.ext_iff.mp this).2
· rintro ⟨g, rfl⟩
exact isComplement_univ_singleton
@[to_additive]
theorem isComplement_univ_right : IsComplement S univ ↔ ∃ g : G, S = {g} := by
refine
⟨fun h => Set.exists_eq_singleton_iff_nonempty_subsingleton.mpr ⟨?_, fun a ha b hb => ?_⟩, ?_⟩
· obtain ⟨a, _⟩ := h.2 1
exact ⟨a.1.1, a.1.2⟩
· have : (⟨⟨a, ha⟩, ⟨_, mem_top a⁻¹⟩⟩ : S × (⊤ : Set G)) = ⟨⟨b, hb⟩, ⟨_, mem_top b⁻¹⟩⟩ :=
h.1 ((mul_inv_cancel a).trans (mul_inv_cancel b).symm)
exact Subtype.ext_iff.mp (Prod.ext_iff.mp this).1
· rintro ⟨g, rfl⟩
exact isComplement_singleton_univ
@[to_additive]
lemma IsComplement.mul_eq (h : IsComplement S T) : S * T = univ :=
eq_univ_of_forall fun x ↦ by simpa [mem_mul] using (h.existsUnique x).exists
@[to_additive (attr := simp)]
lemma not_isComplement_empty_left : ¬ IsComplement ∅ T :=
fun h ↦ by simpa [eq_comm (a := ∅)] using h.mul_eq
@[to_additive (attr := simp)]
lemma not_isComplement_empty_right : ¬ IsComplement S ∅ :=
fun h ↦ by simpa [eq_comm (a := ∅)] using h.mul_eq
@[to_additive]
lemma IsComplement.nonempty_left (hst : IsComplement S T) : S.Nonempty := by
contrapose! hst; simp [hst]
@[to_additive]
lemma IsComplement.nonempty_right (hst : IsComplement S T) : T.Nonempty := by
contrapose! hst; simp [hst]
@[to_additive] lemma IsComplement.pairwiseDisjoint_smul (hst : IsComplement S T) :
S.PairwiseDisjoint (· • T) := fun a ha b hb hab ↦ disjoint_iff_forall_ne.2 <| by
rintro _ ⟨c, hc, rfl⟩ _ ⟨d, hd, rfl⟩
exact hst.1.ne (a₁ := (⟨a, ha⟩, ⟨c, hc⟩)) (a₂:= (⟨b, hb⟩, ⟨d, hd⟩)) (by simp [hab])
@[to_additive AddSubgroup.IsComplement.card_mul_card]
lemma IsComplement.card_mul_card (h : IsComplement S T) : Nat.card S * Nat.card T = Nat.card G :=
(Nat.card_prod _ _).symm.trans <| Nat.card_congr <| Equiv.ofBijective _ h
@[to_additive]
theorem isComplement'_top_bot : IsComplement' (⊤ : Subgroup G) ⊥ :=
isComplement_univ_singleton
@[to_additive]
theorem isComplement'_bot_top : IsComplement' (⊥ : Subgroup G) ⊤ :=
isComplement_singleton_univ
@[to_additive (attr := simp)]
theorem isComplement'_bot_left : IsComplement' ⊥ H ↔ H = ⊤ :=
isComplement_singleton_left.trans coe_eq_univ
@[to_additive (attr := simp)]
theorem isComplement'_bot_right : IsComplement' H ⊥ ↔ H = ⊤ :=
isComplement_singleton_right.trans coe_eq_univ
@[to_additive (attr := simp)]
theorem isComplement'_top_left : IsComplement' ⊤ H ↔ H = ⊥ :=
isComplement_univ_left.trans coe_eq_singleton
@[to_additive (attr := simp)]
theorem isComplement'_top_right : IsComplement' H ⊤ ↔ H = ⊥ :=
isComplement_univ_right.trans coe_eq_singleton
@[to_additive]
lemma isComplement_iff_existsUnique_inv_mul_mem :
IsComplement S T ↔ ∀ g, ∃! s : S, (s : G)⁻¹ * g ∈ T := by
convert isComplement_iff_existsUnique with g
constructor <;> rintro ⟨x, hx, hx'⟩
· exact ⟨(x, ⟨_, hx⟩), by simp, by aesop⟩
· exact ⟨x.1, by simp [← hx], fun y hy ↦ (Prod.ext_iff.1 <| by simpa using hx' (y, ⟨_, hy⟩)).1⟩
set_option linter.deprecated false in
@[to_additive
(attr := deprecated isComplement_iff_existsUnique_inv_mul_mem (since := "2024-12-18"))]
theorem mem_leftTransversals_iff_existsUnique_inv_mul_mem :
S ∈ leftTransversals T ↔ ∀ g : G, ∃! s : S, (s : G)⁻¹ * g ∈ T := by
rw [leftTransversals, Set.mem_setOf_eq, isComplement_iff_existsUnique]
refine ⟨fun h g => ?_, fun h g => ?_⟩
· obtain ⟨x, h1, h2⟩ := h g
exact
⟨x.1, (congr_arg (· ∈ T) (eq_inv_mul_of_mul_eq h1)).mp x.2.2, fun y hy =>
(Prod.ext_iff.mp (h2 ⟨y, (↑y)⁻¹ * g, hy⟩ (mul_inv_cancel_left ↑y g))).1⟩
· obtain ⟨x, h1, h2⟩ := h g
refine ⟨⟨x, (↑x)⁻¹ * g, h1⟩, mul_inv_cancel_left (↑x) g, fun y hy => ?_⟩
have hf := h2 y.1 ((congr_arg (· ∈ T) (eq_inv_mul_of_mul_eq hy)).mp y.2.2)
exact Prod.ext hf (Subtype.ext (eq_inv_mul_of_mul_eq (hf ▸ hy)))
@[to_additive]
lemma isComplement_iff_existsUnique_mul_inv_mem :
IsComplement S T ↔ ∀ g, ∃! t : T, g * (t : G)⁻¹ ∈ S := by
convert isComplement_iff_existsUnique with g
constructor <;> rintro ⟨x, hx, hx'⟩
· exact ⟨(⟨_, hx⟩, x), by simp, by aesop⟩
· exact ⟨x.2, by simp [← hx], fun y hy ↦ (Prod.ext_iff.1 <| by simpa using hx' (⟨_, hy⟩, y)).2⟩
set_option linter.deprecated false in
@[to_additive
(attr := deprecated isComplement_iff_existsUnique_mul_inv_mem (since := "2024-12-18"))]
theorem mem_rightTransversals_iff_existsUnique_mul_inv_mem :
S ∈ rightTransversals T ↔ ∀ g : G, ∃! s : S, g * (s : G)⁻¹ ∈ T := by
rw [rightTransversals, Set.mem_setOf_eq, isComplement_iff_existsUnique]
refine ⟨fun h g => ?_, fun h g => ?_⟩
· obtain ⟨x, h1, h2⟩ := h g
exact
⟨x.2, (congr_arg (· ∈ T) (eq_mul_inv_of_mul_eq h1)).mp x.1.2, fun y hy =>
(Prod.ext_iff.mp (h2 ⟨⟨g * (↑y)⁻¹, hy⟩, y⟩ (inv_mul_cancel_right g y))).2⟩
· obtain ⟨x, h1, h2⟩ := h g
refine ⟨⟨⟨g * (↑x)⁻¹, h1⟩, x⟩, inv_mul_cancel_right g x, fun y hy => ?_⟩
have hf := h2 y.2 ((congr_arg (· ∈ T) (eq_mul_inv_of_mul_eq hy)).mp y.1.2)
exact Prod.ext (Subtype.ext (eq_mul_inv_of_mul_eq (hf ▸ hy))) hf
@[to_additive]
lemma isComplement_subgroup_right_iff_existsUnique_quotientGroupMk :
IsComplement S H ↔ ∀ q : G ⧸ H, ∃! s : S, QuotientGroup.mk s.1 = q := by
simp_rw [isComplement_iff_existsUnique_inv_mul_mem, SetLike.mem_coe, ← QuotientGroup.eq,
QuotientGroup.forall_mk]
set_option linter.deprecated false in
@[to_additive
(attr := deprecated isComplement_subgroup_right_iff_existsUnique_quotientGroupMk
(since := "2024-12-18"))]
theorem mem_leftTransversals_iff_existsUnique_quotient_mk''_eq :
S ∈ leftTransversals (H : Set G) ↔
∀ q : Quotient (QuotientGroup.leftRel H), ∃! s : S, Quotient.mk'' s.1 = q := by
simp_rw [mem_leftTransversals_iff_existsUnique_inv_mul_mem, SetLike.mem_coe, ←
QuotientGroup.eq]
exact ⟨fun h q => Quotient.inductionOn' q h, fun h g => h (Quotient.mk'' g)⟩
set_option linter.docPrime false in
@[to_additive]
lemma isComplement_subgroup_left_iff_existsUnique_quotientMk'' :
IsComplement H T ↔
∀ q : Quotient (QuotientGroup.rightRel H), ∃! t : T, Quotient.mk'' t.1 = q := by
simp_rw [isComplement_iff_existsUnique_mul_inv_mem, SetLike.mem_coe,
← QuotientGroup.rightRel_apply, ← Quotient.eq'', Quotient.forall]
set_option linter.deprecated false in
@[to_additive
(attr := deprecated isComplement_subgroup_left_iff_existsUnique_quotientMk''
(since := "2024-12-18"))]
theorem mem_rightTransversals_iff_existsUnique_quotient_mk''_eq :
S ∈ rightTransversals (H : Set G) ↔
∀ q : Quotient (QuotientGroup.rightRel H), ∃! s : S, Quotient.mk'' s.1 = q := by
simp_rw [mem_rightTransversals_iff_existsUnique_mul_inv_mem, SetLike.mem_coe, ←
QuotientGroup.rightRel_apply, ← Quotient.eq'']
exact ⟨fun h q => Quotient.inductionOn' q h, fun h g => h (Quotient.mk'' g)⟩
@[to_additive]
lemma isComplement_subgroup_right_iff_bijective :
IsComplement S H ↔ Bijective (S.restrict (QuotientGroup.mk : G → G ⧸ H)) :=
isComplement_subgroup_right_iff_existsUnique_quotientGroupMk.trans
(bijective_iff_existsUnique (S.restrict QuotientGroup.mk)).symm
set_option linter.deprecated false in
@[to_additive
(attr := deprecated isComplement_subgroup_right_iff_bijective (since := "2024-12-18"))]
theorem mem_leftTransversals_iff_bijective :
S ∈ leftTransversals (H : Set G) ↔
Function.Bijective (S.restrict (Quotient.mk'' : G → Quotient (QuotientGroup.leftRel H))) :=
mem_leftTransversals_iff_existsUnique_quotient_mk''_eq.trans
(Function.bijective_iff_existsUnique (S.restrict Quotient.mk'')).symm
@[to_additive]
lemma isComplement_subgroup_left_iff_bijective :
IsComplement H T ↔
Bijective (T.restrict (Quotient.mk'' : G → Quotient (QuotientGroup.rightRel H))) :=
isComplement_subgroup_left_iff_existsUnique_quotientMk''.trans
(bijective_iff_existsUnique (T.restrict Quotient.mk'')).symm
set_option linter.deprecated false in
@[to_additive
(attr := deprecated isComplement_subgroup_left_iff_bijective (since := "2024-12-18"))]
theorem mem_rightTransversals_iff_bijective :
S ∈ rightTransversals (H : Set G) ↔
Function.Bijective (S.restrict (Quotient.mk'' : G → Quotient (QuotientGroup.rightRel H))) :=
mem_rightTransversals_iff_existsUnique_quotient_mk''_eq.trans
(Function.bijective_iff_existsUnique (S.restrict Quotient.mk'')).symm
@[to_additive]
lemma IsComplement.card_left (h : IsComplement S H) : Nat.card S = H.index :=
Nat.card_congr <| .ofBijective _ <| isComplement_subgroup_right_iff_bijective.mp h
set_option linter.deprecated false in
@[to_additive (attr := deprecated IsComplement.card_left (since := "2024-12-18"))]
theorem card_left_transversal (h : S ∈ leftTransversals (H : Set G)) : Nat.card S = H.index :=
Nat.card_congr <| Equiv.ofBijective _ <| mem_leftTransversals_iff_bijective.mp h
@[to_additive]
lemma IsComplement.card_right (h : IsComplement H T) : Nat.card T = H.index :=
Nat.card_congr <| (Equiv.ofBijective _ <| isComplement_subgroup_left_iff_bijective.mp h).trans <|
QuotientGroup.quotientRightRelEquivQuotientLeftRel H
set_option linter.deprecated false in
@[to_additive (attr := deprecated IsComplement.card_right (since := "2024-12-18"))]
theorem card_right_transversal (h : S ∈ rightTransversals (H : Set G)) : Nat.card S = H.index :=
Nat.card_congr <|
(Equiv.ofBijective _ <| mem_rightTransversals_iff_bijective.mp h).trans <|
QuotientGroup.quotientRightRelEquivQuotientLeftRel H
@[to_additive]
lemma isComplement_range_left {f : G ⧸ H → G} (hf : ∀ q, ↑(f q) = q) :
IsComplement (range f) H := by
rw [isComplement_subgroup_right_iff_bijective]
refine ⟨?_, fun q ↦ ⟨⟨f q, q, rfl⟩, hf q⟩⟩
rintro ⟨-, q₁, rfl⟩ ⟨-, q₂, rfl⟩ h
exact Subtype.ext <| congr_arg f <| ((hf q₁).symm.trans h).trans (hf q₂)
set_option linter.deprecated false in
@[to_additive (attr := deprecated isComplement_range_left (since := "2024-12-18"))]
theorem range_mem_leftTransversals {f : G ⧸ H → G} (hf : ∀ q, ↑(f q) = q) :
Set.range f ∈ leftTransversals (H : Set G) :=
mem_leftTransversals_iff_bijective.mpr
⟨by rintro ⟨-, q₁, rfl⟩ ⟨-, q₂, rfl⟩ h
exact Subtype.ext <| congr_arg f <| ((hf q₁).symm.trans h).trans (hf q₂),
fun q => ⟨⟨f q, q, rfl⟩, hf q⟩⟩
@[to_additive]
lemma isComplement_range_right {f : Quotient (QuotientGroup.rightRel H) → G}
(hf : ∀ q, Quotient.mk'' (f q) = q) : IsComplement H (range f) := by
rw [isComplement_subgroup_left_iff_bijective]
refine ⟨?_, fun q ↦ ⟨⟨f q, q, rfl⟩, hf q⟩⟩
rintro ⟨-, q₁, rfl⟩ ⟨-, q₂, rfl⟩ h
exact Subtype.ext <| congr_arg f <| ((hf q₁).symm.trans h).trans (hf q₂)
set_option linter.deprecated false in
@[to_additive (attr := deprecated isComplement_range_right (since := "2024-12-18"))]
theorem range_mem_rightTransversals {f : Quotient (QuotientGroup.rightRel H) → G}
(hf : ∀ q, Quotient.mk'' (f q) = q) : Set.range f ∈ rightTransversals (H : Set G) :=
mem_rightTransversals_iff_bijective.mpr
⟨by rintro ⟨-, q₁, rfl⟩ ⟨-, q₂, rfl⟩ h
exact Subtype.ext <| congr_arg f <| ((hf q₁).symm.trans h).trans (hf q₂),
fun q => ⟨⟨f q, q, rfl⟩, hf q⟩⟩
@[to_additive]
lemma exists_isComplement_left (H : Subgroup G) (g : G) : ∃ S, IsComplement S H ∧ g ∈ S := by
classical
refine ⟨Set.range (Function.update Quotient.out _ g), isComplement_range_left fun q ↦ ?_,
QuotientGroup.mk g, Function.update_self (Quotient.mk'' g) g Quotient.out⟩
by_cases hq : q = Quotient.mk'' g
· exact hq.symm ▸ congr_arg _ (Function.update_self (Quotient.mk'' g) g Quotient.out)
· refine Function.update_of_ne ?_ g Quotient.out ▸ q.out_eq'
exact hq
set_option linter.deprecated false in
@[to_additive (attr := deprecated exists_isComplement_left (since := "2024-12-18"))]
lemma exists_left_transversal (H : Subgroup G) (g : G) :
∃ S ∈ leftTransversals (H : Set G), g ∈ S := by
classical
refine
⟨Set.range (Function.update Quotient.out _ g), range_mem_leftTransversals fun q => ?_,
Quotient.mk'' g, Function.update_self (Quotient.mk'' g) g Quotient.out⟩
by_cases hq : q = Quotient.mk'' g
· exact hq.symm ▸ congr_arg _ (Function.update_self (Quotient.mk'' g) g Quotient.out)
· refine (Function.update_of_ne ?_ g Quotient.out) ▸ q.out_eq'
exact hq
@[to_additive]
lemma exists_isComplement_right (H : Subgroup G) (g : G) :
∃ T, IsComplement H T ∧ g ∈ T := by
classical
refine ⟨Set.range (Function.update Quotient.out _ g), isComplement_range_right fun q ↦ ?_,
Quotient.mk'' g, Function.update_self (Quotient.mk'' g) g Quotient.out⟩
by_cases hq : q = Quotient.mk'' g
· exact hq.symm ▸ congr_arg _ (Function.update_self (Quotient.mk'' g) g Quotient.out)
· refine Function.update_of_ne ?_ g Quotient.out ▸ q.out_eq'
exact hq
set_option linter.deprecated false in
@[to_additive (attr := deprecated exists_isComplement_right (since := "2024-12-18"))]
lemma exists_right_transversal (H : Subgroup G) (g : G) :
∃ S ∈ rightTransversals (H : Set G), g ∈ S := by
classical
refine
⟨Set.range (Function.update Quotient.out _ g), range_mem_rightTransversals fun q => ?_,
Quotient.mk'' g, Function.update_self (Quotient.mk'' g) g Quotient.out⟩
by_cases hq : q = Quotient.mk'' g
· exact hq.symm ▸ congr_arg _ (Function.update_self (Quotient.mk'' g) g Quotient.out)
· exact Eq.trans (congr_arg _ (Function.update_of_ne hq g Quotient.out)) q.out_eq'
/-- Given two subgroups `H' ⊆ H`, there exists a left transversal to `H'` inside `H`. -/
@[to_additive "Given two subgroups `H' ⊆ H`, there exists a transversal to `H'` inside `H`"]
lemma exists_left_transversal_of_le {H' H : Subgroup G} (h : H' ≤ H) :
∃ S : Set G, S * H' = H ∧ Nat.card S * Nat.card H' = Nat.card H := by
let H'' : Subgroup H := H'.comap H.subtype
have : H' = H''.map H.subtype := by simp [H'', h]
rw [this]
obtain ⟨S, cmem, -⟩ := H''.exists_isComplement_left 1
refine ⟨H.subtype '' S, ?_, ?_⟩
· have : H.subtype '' (S * H'') = H.subtype '' S * H''.map H.subtype := image_mul H.subtype
rw [← this, cmem.mul_eq]
simp [Set.ext_iff]
· rw [← cmem.card_mul_card]
refine congr_arg₂ (· * ·) ?_ ?_ <;>
exact Nat.card_congr (Equiv.Set.image _ _ <| subtype_injective H).symm
/-- Given two subgroups `H' ⊆ H`, there exists a right transversal to `H'` inside `H`. -/
@[to_additive "Given two subgroups `H' ⊆ H`, there exists a transversal to `H'` inside `H`"]
lemma exists_right_transversal_of_le {H' H : Subgroup G} (h : H' ≤ H) :
∃ S : Set G, H' * S = H ∧ Nat.card H' * Nat.card S = Nat.card H := by
let H'' : Subgroup H := H'.comap H.subtype
have : H' = H''.map H.subtype := by simp [H'', h]
rw [this]
obtain ⟨S, cmem, -⟩ := H''.exists_isComplement_right 1
refine ⟨H.subtype '' S, ?_, ?_⟩
· have : H.subtype '' (H'' * S) = H''.map H.subtype * H.subtype '' S := image_mul H.subtype
rw [← this, cmem.mul_eq]
simp [Set.ext_iff]
· have : Nat.card H'' * Nat.card S = Nat.card H := cmem.card_mul_card
rw [← this]
refine congr_arg₂ (· * ·) ?_ ?_ <;>
exact Nat.card_congr (Equiv.Set.image _ _ <| subtype_injective H).symm
namespace IsComplement
/-- The equivalence `G ≃ S × T`, such that the inverse is `(*) : S × T → G` -/
noncomputable def equiv {S T : Set G} (hST : IsComplement S T) : G ≃ S × T :=
(Equiv.ofBijective (fun x : S × T => x.1.1 * x.2.1) hST).symm
variable (hST : IsComplement S T) (hHT : IsComplement H T) (hSK : IsComplement S K)
@[simp] theorem equiv_symm_apply (x : S × T) : (hST.equiv.symm x : G) = x.1.1 * x.2.1 := rfl
@[simp]
theorem equiv_fst_mul_equiv_snd (g : G) : ↑(hST.equiv g).fst * (hST.equiv g).snd = g :=
(Equiv.ofBijective (fun x : S × T => x.1.1 * x.2.1) hST).right_inv g
theorem equiv_fst_eq_mul_inv (g : G) : ↑(hST.equiv g).fst = g * ((hST.equiv g).snd : G)⁻¹ :=
eq_mul_inv_of_mul_eq (hST.equiv_fst_mul_equiv_snd g)
theorem equiv_snd_eq_inv_mul (g : G) : ↑(hST.equiv g).snd = ((hST.equiv g).fst : G)⁻¹ * g :=
eq_inv_mul_of_mul_eq (hST.equiv_fst_mul_equiv_snd g)
theorem equiv_fst_eq_iff_leftCosetEquivalence {g₁ g₂ : G} :
(hSK.equiv g₁).fst = (hSK.equiv g₂).fst ↔ LeftCosetEquivalence K g₁ g₂ := by
rw [LeftCosetEquivalence, leftCoset_eq_iff]
constructor
· intro h
rw [← hSK.equiv_fst_mul_equiv_snd g₂, ← hSK.equiv_fst_mul_equiv_snd g₁, ← h,
mul_inv_rev, ← mul_assoc, inv_mul_cancel_right, ← coe_inv, ← coe_mul]
exact Subtype.property _
· intro h
apply (isComplement_iff_existsUnique_inv_mul_mem.1 hSK g₁).unique
· -- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644
rw [equiv_fst_eq_mul_inv]; simp
· rw [SetLike.mem_coe, ← mul_mem_cancel_right h]
-- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644
rw [equiv_fst_eq_mul_inv]; simp [equiv_fst_eq_mul_inv, ← mul_assoc]
theorem equiv_snd_eq_iff_rightCosetEquivalence {g₁ g₂ : G} :
(hHT.equiv g₁).snd = (hHT.equiv g₂).snd ↔ RightCosetEquivalence H g₁ g₂ := by
rw [RightCosetEquivalence, rightCoset_eq_iff]
constructor
· intro h
rw [← hHT.equiv_fst_mul_equiv_snd g₂, ← hHT.equiv_fst_mul_equiv_snd g₁, ← h,
mul_inv_rev, mul_assoc, mul_inv_cancel_left, ← coe_inv, ← coe_mul]
exact Subtype.property _
· intro h
apply (isComplement_iff_existsUnique_mul_inv_mem.1 hHT g₁).unique
· -- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644
rw [equiv_snd_eq_inv_mul]; simp
· rw [SetLike.mem_coe, ← mul_mem_cancel_left h]
-- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644
rw [equiv_snd_eq_inv_mul, mul_assoc]; simp
theorem leftCosetEquivalence_equiv_fst (g : G) :
LeftCosetEquivalence K g ((hSK.equiv g).fst : G) := by
-- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644
rw [equiv_fst_eq_mul_inv]; simp [LeftCosetEquivalence, leftCoset_eq_iff]
theorem rightCosetEquivalence_equiv_snd (g : G) :
RightCosetEquivalence H g ((hHT.equiv g).snd : G) := by
-- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644
rw [RightCosetEquivalence, rightCoset_eq_iff, equiv_snd_eq_inv_mul]; simp
theorem equiv_fst_eq_self_of_mem_of_one_mem {g : G} (h1 : 1 ∈ T) (hg : g ∈ S) :
(hST.equiv g).fst = ⟨g, hg⟩ := by
have : hST.equiv.symm (⟨g, hg⟩, ⟨1, h1⟩) = g := by
rw [equiv, Equiv.ofBijective]; simp
conv_lhs => rw [← this, Equiv.apply_symm_apply]
theorem equiv_snd_eq_self_of_mem_of_one_mem {g : G} (h1 : 1 ∈ S) (hg : g ∈ T) :
(hST.equiv g).snd = ⟨g, hg⟩ := by
have : hST.equiv.symm (⟨1, h1⟩, ⟨g, hg⟩) = g := by
rw [equiv, Equiv.ofBijective]; simp
conv_lhs => rw [← this, Equiv.apply_symm_apply]
theorem equiv_snd_eq_one_of_mem_of_one_mem {g : G} (h1 : 1 ∈ T) (hg : g ∈ S) :
(hST.equiv g).snd = ⟨1, h1⟩ := by
ext
rw [equiv_snd_eq_inv_mul, equiv_fst_eq_self_of_mem_of_one_mem _ h1 hg, inv_mul_cancel]
theorem equiv_fst_eq_one_of_mem_of_one_mem {g : G} (h1 : 1 ∈ S) (hg : g ∈ T) :
(hST.equiv g).fst = ⟨1, h1⟩ := by
ext
rw [equiv_fst_eq_mul_inv, equiv_snd_eq_self_of_mem_of_one_mem _ h1 hg, mul_inv_cancel]
theorem equiv_mul_right (g : G) (k : K) :
hSK.equiv (g * k) = ((hSK.equiv g).fst, (hSK.equiv g).snd * k) := by
have : (hSK.equiv (g * k)).fst = (hSK.equiv g).fst :=
hSK.equiv_fst_eq_iff_leftCosetEquivalence.2
(by simp [LeftCosetEquivalence, leftCoset_eq_iff])
ext
· rw [this]
· rw [coe_mul, equiv_snd_eq_inv_mul, this, equiv_snd_eq_inv_mul, mul_assoc]
theorem equiv_mul_right_of_mem {g k : G} (h : k ∈ K) :
hSK.equiv (g * k) = ((hSK.equiv g).fst, (hSK.equiv g).snd * ⟨k, h⟩) :=
equiv_mul_right _ g ⟨k, h⟩
theorem equiv_mul_left (h : H) (g : G) :
hHT.equiv (h * g) = (h * (hHT.equiv g).fst, (hHT.equiv g).snd) := by
have : (hHT.equiv (h * g)).2 = (hHT.equiv g).2 := hHT.equiv_snd_eq_iff_rightCosetEquivalence.2 ?_
· ext
· rw [coe_mul, equiv_fst_eq_mul_inv, this, equiv_fst_eq_mul_inv, mul_assoc]
· rw [this]
· simp [RightCosetEquivalence, ← smul_smul]
theorem equiv_mul_left_of_mem {h g : G} (hh : h ∈ H) :
hHT.equiv (h * g) = (⟨h, hh⟩ * (hHT.equiv g).fst, (hHT.equiv g).snd) :=
equiv_mul_left _ ⟨h, hh⟩ g
theorem equiv_one (hs1 : 1 ∈ S) (ht1 : 1 ∈ T) :
hST.equiv 1 = (⟨1, hs1⟩, ⟨1, ht1⟩) := by
rw [Equiv.apply_eq_iff_eq_symm_apply]; simp [equiv]
theorem equiv_fst_eq_self_iff_mem {g : G} (h1 : 1 ∈ T) :
((hST.equiv g).fst : G) = g ↔ g ∈ S := by
constructor
· intro h
rw [← h]
exact Subtype.prop _
· intro h
rw [hST.equiv_fst_eq_self_of_mem_of_one_mem h1 h]
theorem equiv_snd_eq_self_iff_mem {g : G} (h1 : 1 ∈ S) :
((hST.equiv g).snd : G) = g ↔ g ∈ T := by
constructor
· intro h
rw [← h]
exact Subtype.prop _
· intro h
rw [hST.equiv_snd_eq_self_of_mem_of_one_mem h1 h]
theorem coe_equiv_fst_eq_one_iff_mem {g : G} (h1 : 1 ∈ S) :
((hST.equiv g).fst : G) = 1 ↔ g ∈ T := by
rw [equiv_fst_eq_mul_inv, mul_inv_eq_one, eq_comm, equiv_snd_eq_self_iff_mem _ h1]
theorem coe_equiv_snd_eq_one_iff_mem {g : G} (h1 : 1 ∈ T) :
((hST.equiv g).snd : G) = 1 ↔ g ∈ S := by
rw [equiv_snd_eq_inv_mul, inv_mul_eq_one, equiv_fst_eq_self_iff_mem _ h1]
/-- A left transversal is in bijection with left cosets. -/
@[to_additive "A left transversal is in bijection with left cosets."]
noncomputable def leftQuotientEquiv (hS : IsComplement S H) : G ⧸ H ≃ S :=
(Equiv.ofBijective _ (isComplement_subgroup_right_iff_bijective.mp hS)).symm
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemLeftTransversals.toEquiv := leftQuotientEquiv
/-- A left transversal is finite iff the subgroup has finite index. -/
@[to_additive "A left transversal is finite iff the subgroup has finite index."]
theorem finite_left_iff (h : IsComplement S H) : Finite S ↔ H.FiniteIndex := by
rw [← h.leftQuotientEquiv.finite_iff]
exact ⟨fun _ ↦ finiteIndex_of_finite_quotient, fun _ ↦ finite_quotient_of_finiteIndex⟩
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemLeftTransversals.finite_iff := finite_left_iff
@[to_additive]
lemma finite_left [H.FiniteIndex] (hS : IsComplement S H) : S.Finite := hS.finite_left_iff.2 ‹_›
@[to_additive]
theorem quotientGroupMk_leftQuotientEquiv (hS : IsComplement S H) (q : G ⧸ H) :
Quotient.mk'' (leftQuotientEquiv hS q : G) = q :=
hS.leftQuotientEquiv.symm_apply_apply q
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemLeftTransversals.mk''_toEquiv := quotientGroupMk_leftQuotientEquiv
@[to_additive]
theorem leftQuotientEquiv_apply {f : G ⧸ H → G} (hf : ∀ q, (f q : G ⧸ H) = q) (q : G ⧸ H) :
(leftQuotientEquiv (isComplement_range_left hf) q : G) = f q := by
refine (Subtype.ext_iff.mp ?_).trans (Subtype.coe_mk (f q) ⟨q, rfl⟩)
exact (leftQuotientEquiv (isComplement_range_left hf)).apply_eq_iff_eq_symm_apply.mpr (hf q).symm
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemLeftTransversals.toEquiv_apply := leftQuotientEquiv_apply
|
/-- A left transversal can be viewed as a function mapping each element of the group
to the chosen representative from that left coset. -/
| Mathlib/GroupTheory/Complement.lean | 616 | 618 |
/-
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.Order.Group.Finset
import Mathlib.Algebra.Polynomial.Derivative
import Mathlib.Algebra.Polynomial.Eval.SMul
import Mathlib.Algebra.Polynomial.Roots
import Mathlib.RingTheory.EuclideanDomain
import Mathlib.RingTheory.UniqueFactorizationDomain.NormalizedFactors
/-!
# Theory of univariate polynomials
This file starts looking like the ring theory of $R[X]$
-/
noncomputable section
open Polynomial
namespace Polynomial
universe u v w y z
variable {R : Type u} {S : Type v} {k : Type y} {A : Type z} {a b : R} {n : ℕ}
section CommRing
variable [CommRing R]
theorem rootMultiplicity_sub_one_le_derivative_rootMultiplicity_of_ne_zero
(p : R[X]) (t : R) (hnezero : derivative p ≠ 0) :
p.rootMultiplicity t - 1 ≤ p.derivative.rootMultiplicity t :=
(le_rootMultiplicity_iff hnezero).2 <|
pow_sub_one_dvd_derivative_of_pow_dvd (p.pow_rootMultiplicity_dvd t)
theorem derivative_rootMultiplicity_of_root_of_mem_nonZeroDivisors
{p : R[X]} {t : R} (hpt : Polynomial.IsRoot p t)
(hnzd : (p.rootMultiplicity t : R) ∈ nonZeroDivisors R) :
(derivative p).rootMultiplicity t = p.rootMultiplicity t - 1 := by
by_cases h : p = 0
· simp only [h, map_zero, rootMultiplicity_zero]
obtain ⟨g, hp, hndvd⟩ := p.exists_eq_pow_rootMultiplicity_mul_and_not_dvd h t
set m := p.rootMultiplicity t
have hm : m - 1 + 1 = m := Nat.sub_add_cancel <| (rootMultiplicity_pos h).2 hpt
have hndvd : ¬(X - C t) ^ m ∣ derivative p := by
rw [hp, derivative_mul, dvd_add_left (dvd_mul_right _ _),
derivative_X_sub_C_pow, ← hm, pow_succ, hm, mul_comm (C _), mul_assoc,
dvd_cancel_left_mem_nonZeroDivisors (monic_X_sub_C t |>.pow _ |>.mem_nonZeroDivisors)]
rw [dvd_iff_isRoot, IsRoot] at hndvd ⊢
rwa [eval_mul, eval_C, mul_left_mem_nonZeroDivisors_eq_zero_iff hnzd]
have hnezero : derivative p ≠ 0 := fun h ↦ hndvd (by rw [h]; exact dvd_zero _)
exact le_antisymm (by rwa [rootMultiplicity_le_iff hnezero, hm])
(rootMultiplicity_sub_one_le_derivative_rootMultiplicity_of_ne_zero _ t hnezero)
theorem isRoot_iterate_derivative_of_lt_rootMultiplicity {p : R[X]} {t : R} {n : ℕ}
(hn : n < p.rootMultiplicity t) : (derivative^[n] p).IsRoot t :=
dvd_iff_isRoot.mp <| (dvd_pow_self _ <| Nat.sub_ne_zero_of_lt hn).trans
(pow_sub_dvd_iterate_derivative_of_pow_dvd _ <| p.pow_rootMultiplicity_dvd t)
open Finset in
theorem eval_iterate_derivative_rootMultiplicity {p : R[X]} {t : R} :
(derivative^[p.rootMultiplicity t] p).eval t =
(p.rootMultiplicity t).factorial • (p /ₘ (X - C t) ^ p.rootMultiplicity t).eval t := by
set m := p.rootMultiplicity t with hm
conv_lhs => rw [← p.pow_mul_divByMonic_rootMultiplicity_eq t, ← hm]
rw [iterate_derivative_mul, eval_finset_sum, sum_eq_single_of_mem _ (mem_range.mpr m.succ_pos)]
· rw [m.choose_zero_right, one_smul, eval_mul, m.sub_zero, iterate_derivative_X_sub_pow_self,
eval_natCast, nsmul_eq_mul]; rfl
· intro b hb hb0
rw [iterate_derivative_X_sub_pow, eval_smul, eval_mul, eval_smul, eval_pow,
Nat.sub_sub_self (mem_range_succ_iff.mp hb), eval_sub, eval_X, eval_C, sub_self,
zero_pow hb0, smul_zero, zero_mul, smul_zero]
theorem lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors
{p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t)
(hnzd : (n.factorial : R) ∈ nonZeroDivisors R) :
n < p.rootMultiplicity t := by
by_contra! h'
replace hroot := hroot _ h'
simp only [IsRoot, eval_iterate_derivative_rootMultiplicity] at hroot
obtain ⟨q, hq⟩ := Nat.cast_dvd_cast (α := R) <| Nat.factorial_dvd_factorial h'
rw [hq, mul_mem_nonZeroDivisors] at hnzd
rw [nsmul_eq_mul, mul_left_mem_nonZeroDivisors_eq_zero_iff hnzd.1] at hroot
exact eval_divByMonic_pow_rootMultiplicity_ne_zero t h hroot
theorem lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors'
{p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t)
(hnzd : ∀ m ≤ n, m ≠ 0 → (m : R) ∈ nonZeroDivisors R) :
n < p.rootMultiplicity t := by
apply lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hroot
clear hroot
induction n with
| zero =>
simp only [Nat.factorial_zero, Nat.cast_one]
exact Submonoid.one_mem _
| succ n ih =>
rw [Nat.factorial_succ, Nat.cast_mul, mul_mem_nonZeroDivisors]
exact ⟨hnzd _ le_rfl n.succ_ne_zero, ih fun m h ↦ hnzd m (h.trans n.le_succ)⟩
theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors
{p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hnzd : (n.factorial : R) ∈ nonZeroDivisors R) :
n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t :=
⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| hm.trans_lt hn,
fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hr hnzd⟩
theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors'
{p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hnzd : ∀ m ≤ n, m ≠ 0 → (m : R) ∈ nonZeroDivisors R) :
n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t :=
⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| Nat.lt_of_le_of_lt hm hn,
fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors' h hr hnzd⟩
theorem one_lt_rootMultiplicity_iff_isRoot_iterate_derivative
{p : R[X]} {t : R} (h : p ≠ 0) :
1 < p.rootMultiplicity t ↔ ∀ m ≤ 1, (derivative^[m] p).IsRoot t :=
lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors h
(by rw [Nat.factorial_one, Nat.cast_one]; exact Submonoid.one_mem _)
theorem one_lt_rootMultiplicity_iff_isRoot
{p : R[X]} {t : R} (h : p ≠ 0) :
1 < p.rootMultiplicity t ↔ p.IsRoot t ∧ (derivative p).IsRoot t := by
rw [one_lt_rootMultiplicity_iff_isRoot_iterate_derivative h]
refine ⟨fun h ↦ ⟨h 0 (by norm_num), h 1 (by norm_num)⟩, fun ⟨h0, h1⟩ m hm ↦ ?_⟩
obtain (_|_|m) := m
exacts [h0, h1, by omega]
end CommRing
section IsDomain
variable [CommRing R] [IsDomain R]
theorem one_lt_rootMultiplicity_iff_isRoot_gcd
[GCDMonoid R[X]] {p : R[X]} {t : R} (h : p ≠ 0) :
1 < p.rootMultiplicity t ↔ (gcd p (derivative p)).IsRoot t := by
simp_rw [one_lt_rootMultiplicity_iff_isRoot h, ← dvd_iff_isRoot, dvd_gcd_iff]
theorem derivative_rootMultiplicity_of_root [CharZero R] {p : R[X]} {t : R} (hpt : p.IsRoot t) :
p.derivative.rootMultiplicity t = p.rootMultiplicity t - 1 := by
by_cases h : p = 0
· rw [h, map_zero, rootMultiplicity_zero]
exact derivative_rootMultiplicity_of_root_of_mem_nonZeroDivisors hpt <|
mem_nonZeroDivisors_of_ne_zero <| Nat.cast_ne_zero.2 ((rootMultiplicity_pos h).2 hpt).ne'
theorem rootMultiplicity_sub_one_le_derivative_rootMultiplicity [CharZero R] (p : R[X]) (t : R) :
p.rootMultiplicity t - 1 ≤ p.derivative.rootMultiplicity t := by
by_cases h : p.IsRoot t
· exact (derivative_rootMultiplicity_of_root h).symm.le
· rw [rootMultiplicity_eq_zero h, zero_tsub]
exact zero_le _
theorem lt_rootMultiplicity_of_isRoot_iterate_derivative
[CharZero R] {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t) :
n < p.rootMultiplicity t :=
lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hroot <|
mem_nonZeroDivisors_of_ne_zero <| Nat.cast_ne_zero.2 <| Nat.factorial_ne_zero n
theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative
[CharZero R] {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) :
n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t :=
⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| Nat.lt_of_le_of_lt hm hn,
fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative h hr⟩
/-- A sufficient condition for the set of roots of a nonzero polynomial `f` to be a subset of the
set of roots of `g` is that `f` divides `f.derivative * g`. Over an algebraically closed field of
characteristic zero, this is also a necessary condition.
See `isRoot_of_isRoot_iff_dvd_derivative_mul` -/
theorem isRoot_of_isRoot_of_dvd_derivative_mul [CharZero R] {f g : R[X]} (hf0 : f ≠ 0)
(hfd : f ∣ f.derivative * g) {a : R} (haf : f.IsRoot a) : g.IsRoot a := by
rcases hfd with ⟨r, hr⟩
have hdf0 : derivative f ≠ 0 := by
contrapose! haf
rw [eq_C_of_derivative_eq_zero haf] at hf0 ⊢
exact not_isRoot_C _ _ <| C_ne_zero.mp hf0
by_contra hg
have hdfg0 : f.derivative * g ≠ 0 := mul_ne_zero hdf0 (by rintro rfl; simp at hg)
have hr' := congr_arg (rootMultiplicity a) hr
rw [rootMultiplicity_mul hdfg0, derivative_rootMultiplicity_of_root haf,
rootMultiplicity_eq_zero hg, add_zero, rootMultiplicity_mul (hr ▸ hdfg0), add_comm,
Nat.sub_eq_iff_eq_add (Nat.succ_le_iff.2 ((rootMultiplicity_pos hf0).2 haf))] at hr'
omega
section NormalizationMonoid
variable [NormalizationMonoid R]
instance instNormalizationMonoid : NormalizationMonoid R[X] where
| normUnit p :=
⟨C ↑(normUnit p.leadingCoeff), C ↑(normUnit p.leadingCoeff)⁻¹, by
| Mathlib/Algebra/Polynomial/FieldDivision.lean | 197 | 198 |
/-
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 _)]
| Mathlib/Analysis/SpecialFunctions/Pow/Asymptotics.lean | 132 | 137 |
/-
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 α}
| Mathlib/Topology/MetricSpace/Thickening.lean | 270 | 274 |
/-
Copyright (c) 2024 Jz Pan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jz Pan
-/
import Mathlib.LinearAlgebra.Dimension.Finite
import Mathlib.LinearAlgebra.Dimension.Constructions
/-!
# Some results on free modules over rings satisfying strong rank condition
This file contains some results on free modules over rings satisfying strong rank condition.
Most of them are generalized from the same result assuming the base ring being division ring,
and are moved from the files `Mathlib/LinearAlgebra/Dimension/DivisionRing.lean`
and `Mathlib/LinearAlgebra/FiniteDimensional.lean`.
-/
open Cardinal Module Module Set Submodule
universe u v
section Module
variable {K : Type u} {V : Type v} [Ring K] [StrongRankCondition K] [AddCommGroup V] [Module K V]
/-- The `ι` indexed basis on `V`, where `ι` is an empty type and `V` is zero-dimensional.
See also `Module.finBasis`.
-/
noncomputable def Basis.ofRankEqZero [Module.Free K V] {ι : Type*} [IsEmpty ι]
(hV : Module.rank K V = 0) : Basis ι K V :=
haveI : Subsingleton V := by
obtain ⟨_, b⟩ := Module.Free.exists_basis (R := K) (M := V)
haveI := mk_eq_zero_iff.1 (hV ▸ b.mk_eq_rank'')
exact b.repr.toEquiv.subsingleton
Basis.empty _
@[simp]
theorem Basis.ofRankEqZero_apply [Module.Free K V] {ι : Type*} [IsEmpty ι]
(hV : Module.rank K V = 0) (i : ι) : Basis.ofRankEqZero hV i = 0 := rfl
theorem le_rank_iff_exists_linearIndependent [Module.Free K V] {c : Cardinal} :
c ≤ Module.rank K V ↔ ∃ s : Set V, #s = c ∧ LinearIndepOn K id s := by
haveI := nontrivial_of_invariantBasisNumber K
constructor
· intro h
obtain ⟨κ, t'⟩ := Module.Free.exists_basis (R := K) (M := V)
let t := t'.reindexRange
have : LinearIndepOn K id (Set.range t') := by
convert t.linearIndependent.linearIndepOn_id
ext
simp [t]
rw [← t.mk_eq_rank'', le_mk_iff_exists_subset] at h
rcases h with ⟨s, hst, hsc⟩
exact ⟨s, hsc, this.mono hst⟩
· rintro ⟨s, rfl, si⟩
exact si.cardinal_le_rank
theorem le_rank_iff_exists_linearIndependent_finset
[Module.Free K V] {n : ℕ} : ↑n ≤ Module.rank K V ↔
∃ s : Finset V, s.card = n ∧ LinearIndependent K ((↑) : ↥(s : Set V) → V) := by
simp only [le_rank_iff_exists_linearIndependent, mk_set_eq_nat_iff_finset]
constructor
· rintro ⟨s, ⟨t, rfl, rfl⟩, si⟩
exact ⟨t, rfl, si⟩
· rintro ⟨s, rfl, si⟩
exact ⟨s, ⟨s, rfl, rfl⟩, si⟩
/-- A vector space has dimension at most `1` if and only if there is a
single vector of which all vectors are multiples. -/
theorem rank_le_one_iff [Module.Free K V] :
Module.rank K V ≤ 1 ↔ ∃ v₀ : V, ∀ v, ∃ r : K, r • v₀ = v := by
obtain ⟨κ, b⟩ := Module.Free.exists_basis (R := K) (M := V)
constructor
· intro hd
rw [← b.mk_eq_rank'', le_one_iff_subsingleton] at hd
rcases isEmpty_or_nonempty κ with hb | ⟨⟨i⟩⟩
· use 0
have h' : ∀ v : V, v = 0 := by
simpa [range_eq_empty, Submodule.eq_bot_iff] using b.span_eq.symm
intro v
simp [h' v]
· use b i
have h' : (K ∙ b i) = ⊤ :=
(subsingleton_range b).eq_singleton_of_mem (mem_range_self i) ▸ b.span_eq
intro v
have hv : v ∈ (⊤ : Submodule K V) := mem_top
rwa [← h', mem_span_singleton] at hv
· rintro ⟨v₀, hv₀⟩
have h : (K ∙ v₀) = ⊤ := by
ext
simp [mem_span_singleton, hv₀]
rw [← rank_top, ← h]
refine (rank_span_le _).trans_eq ?_
simp
/-- A vector space has dimension `1` if and only if there is a
single non-zero vector of which all vectors are multiples. -/
theorem rank_eq_one_iff [Module.Free K V] :
Module.rank K V = 1 ↔ ∃ v₀ : V, v₀ ≠ 0 ∧ ∀ v, ∃ r : K, r • v₀ = v := by
haveI := nontrivial_of_invariantBasisNumber K
refine ⟨fun h ↦ ?_, fun ⟨v₀, h, hv⟩ ↦ (rank_le_one_iff.2 ⟨v₀, hv⟩).antisymm ?_⟩
· obtain ⟨v₀, hv⟩ := rank_le_one_iff.1 h.le
refine ⟨v₀, fun hzero ↦ ?_, hv⟩
simp_rw [hzero, smul_zero, exists_const] at hv
haveI : Subsingleton V := .intro fun _ _ ↦ by simp_rw [← hv]
exact one_ne_zero (h ▸ rank_subsingleton' K V)
· by_contra H
rw [not_le, lt_one_iff_zero] at H
obtain ⟨κ, b⟩ := Module.Free.exists_basis (R := K) (M := V)
haveI := mk_eq_zero_iff.1 (H ▸ b.mk_eq_rank'')
haveI := b.repr.toEquiv.subsingleton
exact h (Subsingleton.elim _ _)
/-- A submodule has dimension at most `1` if and only if there is a
single vector in the submodule such that the submodule is contained in
its span. -/
theorem rank_submodule_le_one_iff (s : Submodule K V) [Module.Free K s] :
Module.rank K s ≤ 1 ↔ ∃ v₀ ∈ s, s ≤ K ∙ v₀ := by
simp_rw [rank_le_one_iff, le_span_singleton_iff]
constructor
· rintro ⟨⟨v₀, hv₀⟩, h⟩
use v₀, hv₀
intro v hv
obtain ⟨r, hr⟩ := h ⟨v, hv⟩
use r
rwa [Subtype.ext_iff, coe_smul] at hr
· rintro ⟨v₀, hv₀, h⟩
use ⟨v₀, hv₀⟩
rintro ⟨v, hv⟩
obtain ⟨r, hr⟩ := h v hv
use r
rwa [Subtype.ext_iff, coe_smul]
/-- A submodule has dimension `1` if and only if there is a
single non-zero vector in the submodule such that the submodule is contained in
its span. -/
theorem rank_submodule_eq_one_iff (s : Submodule K V) [Module.Free K s] :
Module.rank K s = 1 ↔ ∃ v₀ ∈ s, v₀ ≠ 0 ∧ s ≤ K ∙ v₀ := by
simp_rw [rank_eq_one_iff, le_span_singleton_iff]
refine ⟨fun ⟨⟨v₀, hv₀⟩, H, h⟩ ↦ ⟨v₀, hv₀, fun h' ↦ by
simp only [h', ne_eq] at H; exact H rfl, fun v hv ↦ ?_⟩,
| fun ⟨v₀, hv₀, H, h⟩ ↦ ⟨⟨v₀, hv₀⟩,
fun h' ↦ H (by rwa [AddSubmonoid.mk_eq_zero] at h'), fun ⟨v, hv⟩ ↦ ?_⟩⟩
· obtain ⟨r, hr⟩ := h ⟨v, hv⟩
exact ⟨r, by rwa [Subtype.ext_iff, coe_smul] at hr⟩
· obtain ⟨r, hr⟩ := h v hv
exact ⟨r, by rwa [Subtype.ext_iff, coe_smul]⟩
/-- A submodule has dimension at most `1` if and only if there is a
single vector, not necessarily in the submodule, such that the
| Mathlib/LinearAlgebra/Dimension/FreeAndStrongRankCondition.lean | 145 | 153 |
/-
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.ContMDiff.Defs
/-!
## Basic properties of `C^n` functions between manifolds
In this file, we show that standard operations on `C^n` maps between manifolds are `C^n` :
* `ContMDiffOn.comp` gives the invariance of the `Cⁿ` property under composition
* `contMDiff_id` gives the smoothness of the identity
* `contMDiff_const` gives the smoothness of constant functions
* `contMDiff_inclusion` shows that the inclusion between open sets of a topological space is `C^n`
* `contMDiff_isOpenEmbedding` shows that if `M` has a `ChartedSpace` structure induced by an open
embedding `e : M → H`, then `e` is `C^n`.
## Tags
chain rule, manifolds, higher derivative
-/
open Filter Function Set Topology
open scoped Manifold ContDiff
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
-- declare the prerequisites for a charted space `M` over the pair `(E, H)`.
{E : Type*}
[NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H]
{I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M]
-- declare the prerequisites for a charted space `M'` over the pair `(E', H')`.
{E' : Type*}
[NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H']
{I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M']
-- declare the prerequisites for a charted space `M''` over the pair `(E'', H'')`.
{E'' : Type*}
[NormedAddCommGroup E''] [NormedSpace 𝕜 E''] {H'' : Type*} [TopologicalSpace H'']
{I'' : ModelWithCorners 𝕜 E'' H''} {M'' : Type*} [TopologicalSpace M'']
section ChartedSpace
variable [ChartedSpace H M] [ChartedSpace H' M'] [ChartedSpace H'' M'']
-- declare functions, sets, points and smoothness indices
{f : M → M'} {s : Set M} {x : M} {n : WithTop ℕ∞}
/-! ### Regularity of the composition of `C^n` functions between manifolds -/
section Composition
/-- The composition of `C^n` functions within domains at points is `C^n`. -/
theorem ContMDiffWithinAt.comp {t : Set M'} {g : M' → M''} (x : M)
(hg : ContMDiffWithinAt I' I'' n g t (f x)) (hf : ContMDiffWithinAt I I' n f s x)
(st : MapsTo f s t) : ContMDiffWithinAt I I'' n (g ∘ f) s x := by
rw [contMDiffWithinAt_iff] at hg hf ⊢
refine ⟨hg.1.comp hf.1 st, ?_⟩
set e := extChartAt I x
set e' := extChartAt I' (f x)
have : e' (f x) = (writtenInExtChartAt I I' x f) (e x) := by simp only [e, e', mfld_simps]
rw [this] at hg
have A : ∀ᶠ y in 𝓝[e.symm ⁻¹' s ∩ range I] e x, f (e.symm y) ∈ t ∧ f (e.symm y) ∈ e'.source := by
simp only [e, ← map_extChartAt_nhdsWithin, eventually_map]
filter_upwards [hf.1.tendsto (extChartAt_source_mem_nhds (I := I') (f x)),
inter_mem_nhdsWithin s (extChartAt_source_mem_nhds (I := I) x)]
rintro x' (hfx' : f x' ∈ e'.source) ⟨hx's, hx'⟩
simp only [e, e.map_source hx', true_and, e.left_inv hx', st hx's, *]
refine ((hg.2.comp _ (hf.2.mono inter_subset_right)
((mapsTo_preimage _ _).mono_left inter_subset_left)).mono_of_mem_nhdsWithin
(inter_mem ?_ self_mem_nhdsWithin)).congr_of_eventuallyEq ?_ ?_
· filter_upwards [A]
rintro x' ⟨ht, hfx'⟩
simp only [*, e, e',mem_preimage, writtenInExtChartAt, (· ∘ ·), mem_inter_iff, e'.left_inv,
true_and]
exact mem_range_self _
· filter_upwards [A]
rintro x' ⟨-, hfx'⟩
simp only [*, e, e', (· ∘ ·), writtenInExtChartAt, e'.left_inv]
· simp only [e, e', writtenInExtChartAt, (· ∘ ·), mem_extChartAt_source,
e.left_inv, e'.left_inv]
/-- See note [comp_of_eq lemmas] -/
theorem ContMDiffWithinAt.comp_of_eq {t : Set M'} {g : M' → M''} {x : M} {y : M'}
(hg : ContMDiffWithinAt I' I'' n g t y) (hf : ContMDiffWithinAt I I' n f s x)
(st : MapsTo f s t) (hx : f x = y) : ContMDiffWithinAt I I'' n (g ∘ f) s x := by
subst hx; exact hg.comp x hf st
@[deprecated (since := "2024-11-20")] alias SmoothWithinAt.comp := ContMDiffWithinAt.comp
/-- The composition of `C^n` functions on domains is `C^n`. -/
theorem ContMDiffOn.comp {t : Set M'} {g : M' → M''} (hg : ContMDiffOn I' I'' n g t)
(hf : ContMDiffOn I I' n f s) (st : s ⊆ f ⁻¹' t) : ContMDiffOn I I'' n (g ∘ f) s := fun x hx =>
(hg _ (st hx)).comp x (hf x hx) st
@[deprecated (since := "2024-11-20")] alias SmoothOn.comp := ContMDiffOn.comp
/-- The composition of `C^n` functions on domains is `C^n`. -/
theorem ContMDiffOn.comp' {t : Set M'} {g : M' → M''} (hg : ContMDiffOn I' I'' n g t)
(hf : ContMDiffOn I I' n f s) : ContMDiffOn I I'' n (g ∘ f) (s ∩ f ⁻¹' t) :=
hg.comp (hf.mono inter_subset_left) inter_subset_right
@[deprecated (since := "2024-11-20")] alias SmoothOn.comp' := ContMDiffOn.comp'
/-- The composition of `C^n` functions is `C^n`. -/
theorem ContMDiff.comp {g : M' → M''} (hg : ContMDiff I' I'' n g) (hf : ContMDiff I I' n f) :
ContMDiff I I'' n (g ∘ f) := by
rw [← contMDiffOn_univ] at hf hg ⊢
exact hg.comp hf subset_preimage_univ
@[deprecated (since := "2024-11-20")] alias Smooth.comp := ContMDiff.comp
/-- The composition of `C^n` functions within domains at points is `C^n`. -/
theorem ContMDiffWithinAt.comp' {t : Set M'} {g : M' → M''} (x : M)
(hg : ContMDiffWithinAt I' I'' n g t (f x)) (hf : ContMDiffWithinAt I I' n f s x) :
ContMDiffWithinAt I I'' n (g ∘ f) (s ∩ f ⁻¹' t) x :=
hg.comp x (hf.mono inter_subset_left) inter_subset_right
@[deprecated (since := "2024-11-20")] alias SmoothWithinAt.comp' := ContMDiffWithinAt.comp'
/-- `g ∘ f` is `C^n` within `s` at `x` if `g` is `C^n` at `f x` and
`f` is `C^n` within `s` at `x`. -/
theorem ContMDiffAt.comp_contMDiffWithinAt {g : M' → M''} (x : M)
(hg : ContMDiffAt I' I'' n g (f x)) (hf : ContMDiffWithinAt I I' n f s x) :
ContMDiffWithinAt I I'' n (g ∘ f) s x :=
hg.comp x hf (mapsTo_univ _ _)
@[deprecated (since := "2024-11-20")]
alias SmoothAt.comp_smoothWithinAt := ContMDiffAt.comp_contMDiffWithinAt
/-- The composition of `C^n` functions at points is `C^n`. -/
nonrec theorem ContMDiffAt.comp {g : M' → M''} (x : M) (hg : ContMDiffAt I' I'' n g (f x))
(hf : ContMDiffAt I I' n f x) : ContMDiffAt I I'' n (g ∘ f) x :=
hg.comp x hf (mapsTo_univ _ _)
/-- See note [comp_of_eq lemmas] -/
theorem ContMDiffAt.comp_of_eq {g : M' → M''} {x : M} {y : M'} (hg : ContMDiffAt I' I'' n g y)
(hf : ContMDiffAt I I' n f x) (hx : f x = y) : ContMDiffAt I I'' n (g ∘ f) x := by
subst hx; exact hg.comp x hf
@[deprecated (since := "2024-11-20")] alias SmoothAt.comp := ContMDiffAt.comp
theorem ContMDiff.comp_contMDiffOn {f : M → M'} {g : M' → M''} {s : Set M}
(hg : ContMDiff I' I'' n g) (hf : ContMDiffOn I I' n f s) : ContMDiffOn I I'' n (g ∘ f) s :=
hg.contMDiffOn.comp hf Set.subset_preimage_univ
@[deprecated (since := "2024-11-20")] alias Smooth.comp_smoothOn := ContMDiff.comp_contMDiffOn
theorem ContMDiffOn.comp_contMDiff {t : Set M'} {g : M' → M''} (hg : ContMDiffOn I' I'' n g t)
(hf : ContMDiff I I' n f) (ht : ∀ x, f x ∈ t) : ContMDiff I I'' n (g ∘ f) :=
contMDiffOn_univ.mp <| hg.comp hf.contMDiffOn fun x _ => ht x
@[deprecated (since := "2024-11-20")] alias SmoothOn.comp_smooth := ContMDiffOn.comp_contMDiff
end Composition
/-! ### The identity is `C^n` -/
section id
theorem contMDiff_id : ContMDiff I I n (id : M → M) :=
ContMDiff.of_le
((contDiffWithinAt_localInvariantProp ⊤).liftProp_id contDiffWithinAtProp_id) le_top
@[deprecated (since := "2024-11-20")] alias smooth_id := contMDiff_id
theorem contMDiffOn_id : ContMDiffOn I I n (id : M → M) s :=
contMDiff_id.contMDiffOn
@[deprecated (since := "2024-11-20")] alias smoothOn_id := contMDiffOn_id
theorem contMDiffAt_id : ContMDiffAt I I n (id : M → M) x :=
contMDiff_id.contMDiffAt
@[deprecated (since := "2024-11-20")] alias smoothAt_id := contMDiffAt_id
theorem contMDiffWithinAt_id : ContMDiffWithinAt I I n (id : M → M) s x :=
contMDiffAt_id.contMDiffWithinAt
@[deprecated (since := "2024-11-20")] alias smoothWithinAt_id := contMDiffWithinAt_id
end id
/-! ### Constants are `C^n` -/
section const
variable {c : M'}
theorem contMDiff_const : ContMDiff I I' n fun _ : M => c := by
intro x
refine ⟨continuousWithinAt_const, ?_⟩
simp only [ContDiffWithinAtProp, Function.comp_def]
exact contDiffWithinAt_const
@[to_additive]
theorem contMDiff_one [One M'] : ContMDiff I I' n (1 : M → M') := by
simp only [Pi.one_def, contMDiff_const]
@[deprecated (since := "2024-11-20")] alias smooth_const := contMDiff_const
@[deprecated (since := "2024-11-20")] alias smooth_one := contMDiff_one
@[deprecated (since := "2024-11-20")] alias smooth_zero := contMDiff_zero
theorem contMDiffOn_const : ContMDiffOn I I' n (fun _ : M => c) s :=
contMDiff_const.contMDiffOn
@[to_additive]
theorem contMDiffOn_one [One M'] : ContMDiffOn I I' n (1 : M → M') s :=
contMDiff_one.contMDiffOn
@[deprecated (since := "2024-11-20")] alias smoothOn_const := contMDiffOn_const
@[deprecated (since := "2024-11-20")] alias smoothOn_one := contMDiffOn_one
@[deprecated (since := "2024-11-20")] alias smoothOn_zero := contMDiffOn_zero
theorem contMDiffAt_const : ContMDiffAt I I' n (fun _ : M => c) x :=
contMDiff_const.contMDiffAt
@[to_additive]
theorem contMDiffAt_one [One M'] : ContMDiffAt I I' n (1 : M → M') x :=
contMDiff_one.contMDiffAt
@[deprecated (since := "2024-11-20")] alias smoothAt_const := contMDiffAt_const
@[deprecated (since := "2024-11-20")] alias smoothAt_one := contMDiffAt_one
@[deprecated (since := "2024-11-20")] alias smoothAt_zero := contMDiffAt_zero
theorem contMDiffWithinAt_const : ContMDiffWithinAt I I' n (fun _ : M => c) s x :=
contMDiffAt_const.contMDiffWithinAt
@[to_additive]
theorem contMDiffWithinAt_one [One M'] : ContMDiffWithinAt I I' n (1 : M → M') s x :=
contMDiffAt_const.contMDiffWithinAt
@[deprecated (since := "2024-11-20")] alias smoothWithinAt_const := contMDiffWithinAt_const
@[deprecated (since := "2024-11-20")] alias smoothWithinAt_one := contMDiffWithinAt_one
@[deprecated (since := "2024-11-20")] alias smoothWithinAt_zero := contMDiffWithinAt_zero
@[nontriviality]
theorem contMDiff_of_subsingleton [Subsingleton M'] : ContMDiff I I' n f := by
intro x
rw [Subsingleton.elim f fun _ => (f x)]
exact contMDiffAt_const
@[nontriviality]
theorem contMDiffAt_of_subsingleton [Subsingleton M'] : ContMDiffAt I I' n f x :=
contMDiff_of_subsingleton.contMDiffAt
@[nontriviality]
theorem contMDiffWithinAt_of_subsingleton [Subsingleton M'] : ContMDiffWithinAt I I' n f s x :=
contMDiffAt_of_subsingleton.contMDiffWithinAt
| @[nontriviality]
theorem contMDiffOn_of_subsingleton [Subsingleton M'] : ContMDiffOn I I' n f s :=
| Mathlib/Geometry/Manifold/ContMDiff/Basic.lean | 252 | 253 |
/-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.NumberTheory.Zsqrtd.GaussianInt
import Mathlib.NumberTheory.LegendreSymbol.Basic
import Mathlib.Analysis.Normed.Ring.Lemmas
/-!
# Facts about the gaussian integers relying on quadratic reciprocity.
## Main statements
`prime_iff_mod_four_eq_three_of_nat_prime`
A prime natural number is prime in `ℤ[i]` if and only if it is `3` mod `4`
-/
open Zsqrtd Complex
open scoped ComplexConjugate
local notation "ℤ[i]" => GaussianInt
namespace GaussianInt
open PrincipalIdealRing
theorem mod_four_eq_three_of_nat_prime_of_prime (p : ℕ) [hp : Fact p.Prime]
(hpi : Prime (p : ℤ[i])) : p % 4 = 3 :=
hp.1.eq_two_or_odd.elim
(fun hp2 => by
have := hpi.irreducible.isUnit_or_isUnit (a := ⟨1, 1⟩) (b := ⟨1, -1⟩)
simp [hp2, Zsqrtd.ext_iff, ← norm_eq_one_iff, norm_def] at this)
fun hp1 =>
by_contradiction fun hp3 : p % 4 ≠ 3 => by
have hp41 : p % 4 = 1 := by omega
let ⟨k, hk⟩ := (ZMod.exists_sq_eq_neg_one_iff (p := p)).2 <| by rw [hp41]; decide
obtain ⟨k, k_lt_p, rfl⟩ : ∃ (k' : ℕ) (_ : k' < p), (k' : ZMod p) = k := by
exact ⟨k.val, k.val_lt, ZMod.natCast_zmod_val k⟩
have hpk : p ∣ k ^ 2 + 1 := by
rw [pow_two, ← CharP.cast_eq_zero_iff (ZMod p) p, Nat.cast_add, Nat.cast_mul, Nat.cast_one,
← hk, neg_add_cancel]
have hkmul : (k ^ 2 + 1 : ℤ[i]) = ⟨k, 1⟩ * ⟨k, -1⟩ := by ext <;> simp [sq]
have hkltp : 1 + k * k < p * p :=
calc
1 + k * k ≤ k + k * k := by
apply add_le_add_right
exact (Nat.pos_of_ne_zero fun (hk0 : k = 0) => by clear_aux_decl; simp_all [pow_succ'])
_ = k * (k + 1) := by simp [add_comm, mul_add]
_ < p * p := mul_lt_mul k_lt_p k_lt_p (Nat.succ_pos _) (Nat.zero_le _)
have hpk₁ : ¬(p : ℤ[i]) ∣ ⟨k, -1⟩ := fun ⟨x, hx⟩ =>
lt_irrefl (p * x : ℤ[i]).norm.natAbs <|
calc
(norm (p * x : ℤ[i])).natAbs = (Zsqrtd.norm ⟨k, -1⟩).natAbs := by rw [hx]
_ < (norm (p : ℤ[i])).natAbs := by simpa [add_comm, Zsqrtd.norm] using hkltp
_ ≤ (norm (p * x : ℤ[i])).natAbs :=
norm_le_norm_mul_left _ fun hx0 =>
show (-1 : ℤ) ≠ 0 by decide <| by simpa [hx0] using congr_arg Zsqrtd.im hx
have hpk₂ : ¬(p : ℤ[i]) ∣ ⟨k, 1⟩ := fun ⟨x, hx⟩ =>
lt_irrefl (p * x : ℤ[i]).norm.natAbs <|
calc
(norm (p * x : ℤ[i])).natAbs = (Zsqrtd.norm ⟨k, 1⟩).natAbs := by rw [hx]
_ < (norm (p : ℤ[i])).natAbs := by simpa [add_comm, Zsqrtd.norm] using hkltp
_ ≤ (norm (p * x : ℤ[i])).natAbs :=
norm_le_norm_mul_left _ fun hx0 =>
show (1 : ℤ) ≠ 0 by decide <| by simpa [hx0] using congr_arg Zsqrtd.im hx
obtain ⟨y, hy⟩ := hpk
have := hpi.2.2 ⟨k, 1⟩ ⟨k, -1⟩ ⟨y, by rw [← hkmul, ← Nat.cast_mul p, ← hy]; simp⟩
clear_aux_decl
tauto
theorem prime_of_nat_prime_of_mod_four_eq_three (p : ℕ) [Fact p.Prime] (hp3 : p % 4 = 3) :
Prime (p : ℤ[i]) :=
irreducible_iff_prime.1 <|
by_contradiction fun hpi =>
let ⟨a, b, hab⟩ := sq_add_sq_of_nat_prime_of_not_irreducible p hpi
have : ∀ a b : ZMod 4, a ^ 2 + b ^ 2 ≠ (p : ZMod 4) := by
rw [← ZMod.natCast_mod p 4, hp3]; decide
this a b (hab ▸ by simp)
/-- A prime natural number is prime in `ℤ[i]` if and only if it is `3` mod `4` -/
theorem prime_iff_mod_four_eq_three_of_nat_prime (p : ℕ) [Fact p.Prime] :
| Prime (p : ℤ[i]) ↔ p % 4 = 3 :=
⟨mod_four_eq_three_of_nat_prime_of_prime p, prime_of_nat_prime_of_mod_four_eq_three p⟩
end GaussianInt
| Mathlib/NumberTheory/Zsqrtd/QuadraticReciprocity.lean | 86 | 93 |
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Bhavik Mehta
-/
import Mathlib.CategoryTheory.Comma.Over.Basic
import Mathlib.CategoryTheory.Discrete.Basic
import Mathlib.CategoryTheory.EpiMono
import Mathlib.CategoryTheory.Limits.Shapes.Terminal
/-!
# Binary (co)products
We define a category `WalkingPair`, which is the index category
for a binary (co)product diagram. A convenience method `pair X Y`
constructs the functor from the walking pair, hitting the given objects.
We define `prod X Y` and `coprod X Y` as limits and colimits of such functors.
Typeclasses `HasBinaryProducts` and `HasBinaryCoproducts` assert the existence
of (co)limits shaped as walking pairs.
We include lemmas for simplifying equations involving projections and coprojections, and define
braiding and associating isomorphisms, and the product comparison morphism.
## References
* [Stacks: Products of pairs](https://stacks.math.columbia.edu/tag/001R)
* [Stacks: coproducts of pairs](https://stacks.math.columbia.edu/tag/04AN)
-/
universe v v₁ u u₁ u₂
open CategoryTheory
namespace CategoryTheory.Limits
/-- The type of objects for the diagram indexing a binary (co)product. -/
inductive WalkingPair : Type
| left
| right
deriving DecidableEq, Inhabited
open WalkingPair
/-- The equivalence swapping left and right.
-/
def WalkingPair.swap : WalkingPair ≃ WalkingPair where
toFun
| left => right
| right => left
invFun
| left => right
| right => left
left_inv j := by cases j <;> rfl
right_inv j := by cases j <;> rfl
@[simp]
theorem WalkingPair.swap_apply_left : WalkingPair.swap left = right :=
rfl
@[simp]
theorem WalkingPair.swap_apply_right : WalkingPair.swap right = left :=
rfl
@[simp]
theorem WalkingPair.swap_symm_apply_tt : WalkingPair.swap.symm left = right :=
rfl
@[simp]
theorem WalkingPair.swap_symm_apply_ff : WalkingPair.swap.symm right = left :=
rfl
/-- An equivalence from `WalkingPair` to `Bool`, sometimes useful when reindexing limits.
-/
def WalkingPair.equivBool : WalkingPair ≃ Bool where
toFun
| left => true
| right => false
-- to match equiv.sum_equiv_sigma_bool
invFun b := Bool.recOn b right left
left_inv j := by cases j <;> rfl
right_inv b := by cases b <;> rfl
@[simp]
theorem WalkingPair.equivBool_apply_left : WalkingPair.equivBool left = true :=
rfl
@[simp]
theorem WalkingPair.equivBool_apply_right : WalkingPair.equivBool right = false :=
rfl
@[simp]
theorem WalkingPair.equivBool_symm_apply_true : WalkingPair.equivBool.symm true = left :=
rfl
@[simp]
theorem WalkingPair.equivBool_symm_apply_false : WalkingPair.equivBool.symm false = right :=
rfl
variable {C : Type u}
/-- The function on the walking pair, sending the two points to `X` and `Y`. -/
def pairFunction (X Y : C) : WalkingPair → C := fun j => WalkingPair.casesOn j X Y
@[simp]
theorem pairFunction_left (X Y : C) : pairFunction X Y left = X :=
rfl
@[simp]
theorem pairFunction_right (X Y : C) : pairFunction X Y right = Y :=
rfl
variable [Category.{v} C]
/-- The diagram on the walking pair, sending the two points to `X` and `Y`. -/
def pair (X Y : C) : Discrete WalkingPair ⥤ C :=
Discrete.functor fun j => WalkingPair.casesOn j X Y
@[simp]
theorem pair_obj_left (X Y : C) : (pair X Y).obj ⟨left⟩ = X :=
rfl
@[simp]
theorem pair_obj_right (X Y : C) : (pair X Y).obj ⟨right⟩ = Y :=
rfl
section
variable {F G : Discrete WalkingPair ⥤ C} (f : F.obj ⟨left⟩ ⟶ G.obj ⟨left⟩)
(g : F.obj ⟨right⟩ ⟶ G.obj ⟨right⟩)
attribute [local aesop safe tactic (rule_sets := [CategoryTheory])]
CategoryTheory.Discrete.discreteCases
/-- The natural transformation between two functors out of the
walking pair, specified by its components. -/
def mapPair : F ⟶ G where
app
| ⟨left⟩ => f
| ⟨right⟩ => g
naturality := fun ⟨X⟩ ⟨Y⟩ ⟨⟨u⟩⟩ => by aesop_cat
@[simp]
theorem mapPair_left : (mapPair f g).app ⟨left⟩ = f :=
rfl
@[simp]
theorem mapPair_right : (mapPair f g).app ⟨right⟩ = g :=
rfl
/-- The natural isomorphism between two functors out of the walking pair, specified by its
components. -/
@[simps!]
def mapPairIso (f : F.obj ⟨left⟩ ≅ G.obj ⟨left⟩) (g : F.obj ⟨right⟩ ≅ G.obj ⟨right⟩) : F ≅ G :=
NatIso.ofComponents (fun j ↦ match j with
| ⟨left⟩ => f
| ⟨right⟩ => g)
(fun ⟨⟨u⟩⟩ => by aesop_cat)
end
/-- Every functor out of the walking pair is naturally isomorphic (actually, equal) to a `pair` -/
@[simps!]
def diagramIsoPair (F : Discrete WalkingPair ⥤ C) :
F ≅ pair (F.obj ⟨WalkingPair.left⟩) (F.obj ⟨WalkingPair.right⟩) :=
mapPairIso (Iso.refl _) (Iso.refl _)
section
variable {D : Type u₁} [Category.{v₁} D]
/-- The natural isomorphism between `pair X Y ⋙ F` and `pair (F.obj X) (F.obj Y)`. -/
def pairComp (X Y : C) (F : C ⥤ D) : pair X Y ⋙ F ≅ pair (F.obj X) (F.obj Y) :=
diagramIsoPair _
end
/-- A binary fan is just a cone on a diagram indexing a product. -/
abbrev BinaryFan (X Y : C) :=
Cone (pair X Y)
/-- The first projection of a binary fan. -/
abbrev BinaryFan.fst {X Y : C} (s : BinaryFan X Y) :=
s.π.app ⟨WalkingPair.left⟩
/-- The second projection of a binary fan. -/
abbrev BinaryFan.snd {X Y : C} (s : BinaryFan X Y) :=
s.π.app ⟨WalkingPair.right⟩
@[simp]
theorem BinaryFan.π_app_left {X Y : C} (s : BinaryFan X Y) : s.π.app ⟨WalkingPair.left⟩ = s.fst :=
rfl
@[simp]
theorem BinaryFan.π_app_right {X Y : C} (s : BinaryFan X Y) : s.π.app ⟨WalkingPair.right⟩ = s.snd :=
rfl
/-- Constructs an isomorphism of `BinaryFan`s out of an isomorphism of the tips that commutes with
the projections. -/
def BinaryFan.ext {A B : C} {c c' : BinaryFan A B} (e : c.pt ≅ c'.pt)
(h₁ : c.fst = e.hom ≫ c'.fst) (h₂ : c.snd = e.hom ≫ c'.snd) : c ≅ c' :=
Cones.ext e (fun j => by rcases j with ⟨⟨⟩⟩ <;> assumption)
@[simp]
lemma BinaryFan.ext_hom_hom {A B : C} {c c' : BinaryFan A B} (e : c.pt ≅ c'.pt)
(h₁ : c.fst = e.hom ≫ c'.fst) (h₂ : c.snd = e.hom ≫ c'.snd) :
(ext e h₁ h₂).hom.hom = e.hom := rfl
/-- A convenient way to show that a binary fan is a limit. -/
def BinaryFan.IsLimit.mk {X Y : C} (s : BinaryFan X Y)
(lift : ∀ {T : C} (_ : T ⟶ X) (_ : T ⟶ Y), T ⟶ s.pt)
(hl₁ : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y), lift f g ≫ s.fst = f)
(hl₂ : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y), lift f g ≫ s.snd = g)
(uniq :
∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y) (m : T ⟶ s.pt) (_ : m ≫ s.fst = f) (_ : m ≫ s.snd = g),
m = lift f g) :
IsLimit s :=
Limits.IsLimit.mk (fun t => lift (BinaryFan.fst t) (BinaryFan.snd t))
(by
rintro t (rfl | rfl)
· exact hl₁ _ _
· exact hl₂ _ _)
fun _ _ h => uniq _ _ _ (h ⟨WalkingPair.left⟩) (h ⟨WalkingPair.right⟩)
theorem BinaryFan.IsLimit.hom_ext {W X Y : C} {s : BinaryFan X Y} (h : IsLimit s) {f g : W ⟶ s.pt}
(h₁ : f ≫ s.fst = g ≫ s.fst) (h₂ : f ≫ s.snd = g ≫ s.snd) : f = g :=
h.hom_ext fun j => Discrete.recOn j fun j => WalkingPair.casesOn j h₁ h₂
/-- A binary cofan is just a cocone on a diagram indexing a coproduct. -/
abbrev BinaryCofan (X Y : C) := Cocone (pair X Y)
/-- The first inclusion of a binary cofan. -/
abbrev BinaryCofan.inl {X Y : C} (s : BinaryCofan X Y) := s.ι.app ⟨WalkingPair.left⟩
/-- The second inclusion of a binary cofan. -/
abbrev BinaryCofan.inr {X Y : C} (s : BinaryCofan X Y) := s.ι.app ⟨WalkingPair.right⟩
/-- Constructs an isomorphism of `BinaryCofan`s out of an isomorphism of the tips that commutes with
the injections. -/
def BinaryCofan.ext {A B : C} {c c' : BinaryCofan A B} (e : c.pt ≅ c'.pt)
(h₁ : c.inl ≫ e.hom = c'.inl) (h₂ : c.inr ≫ e.hom = c'.inr) : c ≅ c' :=
Cocones.ext e (fun j => by rcases j with ⟨⟨⟩⟩ <;> assumption)
@[simp]
lemma BinaryCofan.ext_hom_hom {A B : C} {c c' : BinaryCofan A B} (e : c.pt ≅ c'.pt)
(h₁ : c.inl ≫ e.hom = c'.inl) (h₂ : c.inr ≫ e.hom = c'.inr) :
(ext e h₁ h₂).hom.hom = e.hom := rfl
@[simp]
theorem BinaryCofan.ι_app_left {X Y : C} (s : BinaryCofan X Y) :
s.ι.app ⟨WalkingPair.left⟩ = s.inl := rfl
@[simp]
theorem BinaryCofan.ι_app_right {X Y : C} (s : BinaryCofan X Y) :
s.ι.app ⟨WalkingPair.right⟩ = s.inr := rfl
/-- A convenient way to show that a binary cofan is a colimit. -/
def BinaryCofan.IsColimit.mk {X Y : C} (s : BinaryCofan X Y)
(desc : ∀ {T : C} (_ : X ⟶ T) (_ : Y ⟶ T), s.pt ⟶ T)
(hd₁ : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T), s.inl ≫ desc f g = f)
(hd₂ : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T), s.inr ≫ desc f g = g)
(uniq :
∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T) (m : s.pt ⟶ T) (_ : s.inl ≫ m = f) (_ : s.inr ≫ m = g),
m = desc f g) :
IsColimit s :=
Limits.IsColimit.mk (fun t => desc (BinaryCofan.inl t) (BinaryCofan.inr t))
(by
rintro t (rfl | rfl)
· exact hd₁ _ _
· exact hd₂ _ _)
fun _ _ h => uniq _ _ _ (h ⟨WalkingPair.left⟩) (h ⟨WalkingPair.right⟩)
theorem BinaryCofan.IsColimit.hom_ext {W X Y : C} {s : BinaryCofan X Y} (h : IsColimit s)
{f g : s.pt ⟶ W} (h₁ : s.inl ≫ f = s.inl ≫ g) (h₂ : s.inr ≫ f = s.inr ≫ g) : f = g :=
h.hom_ext fun j => Discrete.recOn j fun j => WalkingPair.casesOn j h₁ h₂
variable {X Y : C}
section
attribute [local aesop safe tactic (rule_sets := [CategoryTheory])]
CategoryTheory.Discrete.discreteCases
-- Porting note: would it be okay to use this more generally?
attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Eq
/-- A binary fan with vertex `P` consists of the two projections `π₁ : P ⟶ X` and `π₂ : P ⟶ Y`. -/
@[simps pt]
def BinaryFan.mk {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : BinaryFan X Y where
pt := P
π := { app := fun | { as := j } => match j with | left => π₁ | right => π₂ }
/-- A binary cofan with vertex `P` consists of the two inclusions `ι₁ : X ⟶ P` and `ι₂ : Y ⟶ P`. -/
@[simps pt]
def BinaryCofan.mk {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : BinaryCofan X Y where
pt := P
ι := { app := fun | { as := j } => match j with | left => ι₁ | right => ι₂ }
end
@[simp]
theorem BinaryFan.mk_fst {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : (BinaryFan.mk π₁ π₂).fst = π₁ :=
rfl
@[simp]
theorem BinaryFan.mk_snd {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : (BinaryFan.mk π₁ π₂).snd = π₂ :=
rfl
@[simp]
theorem BinaryCofan.mk_inl {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : (BinaryCofan.mk ι₁ ι₂).inl = ι₁ :=
rfl
@[simp]
theorem BinaryCofan.mk_inr {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : (BinaryCofan.mk ι₁ ι₂).inr = ι₂ :=
rfl
/-- Every `BinaryFan` is isomorphic to an application of `BinaryFan.mk`. -/
def isoBinaryFanMk {X Y : C} (c : BinaryFan X Y) : c ≅ BinaryFan.mk c.fst c.snd :=
Cones.ext (Iso.refl _) fun ⟨l⟩ => by cases l; repeat simp
/-- Every `BinaryFan` is isomorphic to an application of `BinaryFan.mk`. -/
def isoBinaryCofanMk {X Y : C} (c : BinaryCofan X Y) : c ≅ BinaryCofan.mk c.inl c.inr :=
Cocones.ext (Iso.refl _) fun ⟨l⟩ => by cases l; repeat simp
/-- This is a more convenient formulation to show that a `BinaryFan` constructed using
`BinaryFan.mk` is a limit cone.
-/
def BinaryFan.isLimitMk {W : C} {fst : W ⟶ X} {snd : W ⟶ Y} (lift : ∀ s : BinaryFan X Y, s.pt ⟶ W)
(fac_left : ∀ s : BinaryFan X Y, lift s ≫ fst = s.fst)
(fac_right : ∀ s : BinaryFan X Y, lift s ≫ snd = s.snd)
(uniq :
∀ (s : BinaryFan X Y) (m : s.pt ⟶ W) (_ : m ≫ fst = s.fst) (_ : m ≫ snd = s.snd),
m = lift s) :
IsLimit (BinaryFan.mk fst snd) :=
{ lift := lift
fac := fun s j => by
rcases j with ⟨⟨⟩⟩
exacts [fac_left s, fac_right s]
uniq := fun s m w => uniq s m (w ⟨WalkingPair.left⟩) (w ⟨WalkingPair.right⟩) }
/-- This is a more convenient formulation to show that a `BinaryCofan` constructed using
`BinaryCofan.mk` is a colimit cocone.
-/
def BinaryCofan.isColimitMk {W : C} {inl : X ⟶ W} {inr : Y ⟶ W}
(desc : ∀ s : BinaryCofan X Y, W ⟶ s.pt)
(fac_left : ∀ s : BinaryCofan X Y, inl ≫ desc s = s.inl)
(fac_right : ∀ s : BinaryCofan X Y, inr ≫ desc s = s.inr)
(uniq :
∀ (s : BinaryCofan X Y) (m : W ⟶ s.pt) (_ : inl ≫ m = s.inl) (_ : inr ≫ m = s.inr),
m = desc s) :
IsColimit (BinaryCofan.mk inl inr) :=
{ desc := desc
fac := fun s j => by
rcases j with ⟨⟨⟩⟩
exacts [fac_left s, fac_right s]
uniq := fun s m w => uniq s m (w ⟨WalkingPair.left⟩) (w ⟨WalkingPair.right⟩) }
/-- If `s` is a limit binary fan over `X` and `Y`, then every pair of morphisms `f : W ⟶ X` and
`g : W ⟶ Y` induces a morphism `l : W ⟶ s.pt` satisfying `l ≫ s.fst = f` and `l ≫ s.snd = g`.
-/
@[simps]
def BinaryFan.IsLimit.lift' {W X Y : C} {s : BinaryFan X Y} (h : IsLimit s) (f : W ⟶ X)
(g : W ⟶ Y) : { l : W ⟶ s.pt // l ≫ s.fst = f ∧ l ≫ s.snd = g } :=
⟨h.lift <| BinaryFan.mk f g, h.fac _ _, h.fac _ _⟩
/-- If `s` is a colimit binary cofan over `X` and `Y`,, then every pair of morphisms `f : X ⟶ W` and
`g : Y ⟶ W` induces a morphism `l : s.pt ⟶ W` satisfying `s.inl ≫ l = f` and `s.inr ≫ l = g`.
-/
@[simps]
def BinaryCofan.IsColimit.desc' {W X Y : C} {s : BinaryCofan X Y} (h : IsColimit s) (f : X ⟶ W)
(g : Y ⟶ W) : { l : s.pt ⟶ W // s.inl ≫ l = f ∧ s.inr ≫ l = g } :=
⟨h.desc <| BinaryCofan.mk f g, h.fac _ _, h.fac _ _⟩
/-- Binary products are symmetric. -/
def BinaryFan.isLimitFlip {X Y : C} {c : BinaryFan X Y} (hc : IsLimit c) :
IsLimit (BinaryFan.mk c.snd c.fst) :=
BinaryFan.isLimitMk (fun s => hc.lift (BinaryFan.mk s.snd s.fst)) (fun _ => hc.fac _ _)
(fun _ => hc.fac _ _) fun s _ e₁ e₂ =>
BinaryFan.IsLimit.hom_ext hc
(e₂.trans (hc.fac (BinaryFan.mk s.snd s.fst) ⟨WalkingPair.left⟩).symm)
(e₁.trans (hc.fac (BinaryFan.mk s.snd s.fst) ⟨WalkingPair.right⟩).symm)
theorem BinaryFan.isLimit_iff_isIso_fst {X Y : C} (h : IsTerminal Y) (c : BinaryFan X Y) :
Nonempty (IsLimit c) ↔ IsIso c.fst := by
constructor
· rintro ⟨H⟩
obtain ⟨l, hl, -⟩ := BinaryFan.IsLimit.lift' H (𝟙 X) (h.from X)
exact
⟨⟨l,
BinaryFan.IsLimit.hom_ext H (by simpa [hl, -Category.comp_id] using Category.comp_id _)
(h.hom_ext _ _),
hl⟩⟩
· intro
exact
⟨BinaryFan.IsLimit.mk _ (fun f _ => f ≫ inv c.fst) (fun _ _ => by simp)
(fun _ _ => h.hom_ext _ _) fun _ _ _ e _ => by simp [← e]⟩
theorem BinaryFan.isLimit_iff_isIso_snd {X Y : C} (h : IsTerminal X) (c : BinaryFan X Y) :
Nonempty (IsLimit c) ↔ IsIso c.snd := by
refine Iff.trans ?_ (BinaryFan.isLimit_iff_isIso_fst h (BinaryFan.mk c.snd c.fst))
exact
⟨fun h => ⟨BinaryFan.isLimitFlip h.some⟩, fun h =>
⟨(BinaryFan.isLimitFlip h.some).ofIsoLimit (isoBinaryFanMk c).symm⟩⟩
/-- If `X' ≅ X`, then `X × Y` also is the product of `X'` and `Y`. -/
noncomputable def BinaryFan.isLimitCompLeftIso {X Y X' : C} (c : BinaryFan X Y) (f : X ⟶ X')
[IsIso f] (h : IsLimit c) : IsLimit (BinaryFan.mk (c.fst ≫ f) c.snd) := by
fapply BinaryFan.isLimitMk
· exact fun s => h.lift (BinaryFan.mk (s.fst ≫ inv f) s.snd)
· intro s -- Porting note: simp timed out here
simp only [Category.comp_id,BinaryFan.π_app_left,IsIso.inv_hom_id,
BinaryFan.mk_fst,IsLimit.fac_assoc,eq_self_iff_true,Category.assoc]
· intro s -- Porting note: simp timed out here
simp only [BinaryFan.π_app_right,BinaryFan.mk_snd,eq_self_iff_true,IsLimit.fac]
· intro s m e₁ e₂
-- Porting note: simpa timed out here also
apply BinaryFan.IsLimit.hom_ext h
· simpa only
[BinaryFan.π_app_left,BinaryFan.mk_fst,Category.assoc,IsLimit.fac,IsIso.eq_comp_inv]
· simpa only [BinaryFan.π_app_right,BinaryFan.mk_snd,IsLimit.fac]
/-- If `Y' ≅ Y`, then `X x Y` also is the product of `X` and `Y'`. -/
noncomputable def BinaryFan.isLimitCompRightIso {X Y Y' : C} (c : BinaryFan X Y) (f : Y ⟶ Y')
[IsIso f] (h : IsLimit c) : IsLimit (BinaryFan.mk c.fst (c.snd ≫ f)) :=
BinaryFan.isLimitFlip <| BinaryFan.isLimitCompLeftIso _ f (BinaryFan.isLimitFlip h)
/-- Binary coproducts are symmetric. -/
def BinaryCofan.isColimitFlip {X Y : C} {c : BinaryCofan X Y} (hc : IsColimit c) :
IsColimit (BinaryCofan.mk c.inr c.inl) :=
BinaryCofan.isColimitMk (fun s => hc.desc (BinaryCofan.mk s.inr s.inl)) (fun _ => hc.fac _ _)
(fun _ => hc.fac _ _) fun s _ e₁ e₂ =>
BinaryCofan.IsColimit.hom_ext hc
(e₂.trans (hc.fac (BinaryCofan.mk s.inr s.inl) ⟨WalkingPair.left⟩).symm)
(e₁.trans (hc.fac (BinaryCofan.mk s.inr s.inl) ⟨WalkingPair.right⟩).symm)
theorem BinaryCofan.isColimit_iff_isIso_inl {X Y : C} (h : IsInitial Y) (c : BinaryCofan X Y) :
Nonempty (IsColimit c) ↔ IsIso c.inl := by
constructor
· rintro ⟨H⟩
obtain ⟨l, hl, -⟩ := BinaryCofan.IsColimit.desc' H (𝟙 X) (h.to X)
refine ⟨⟨l, hl, BinaryCofan.IsColimit.hom_ext H (?_) (h.hom_ext _ _)⟩⟩
rw [Category.comp_id]
have e : (inl c ≫ l) ≫ inl c = 𝟙 X ≫ inl c := congrArg (·≫inl c) hl
rwa [Category.assoc,Category.id_comp] at e
· intro
exact
⟨BinaryCofan.IsColimit.mk _ (fun f _ => inv c.inl ≫ f)
(fun _ _ => IsIso.hom_inv_id_assoc _ _) (fun _ _ => h.hom_ext _ _) fun _ _ _ e _ =>
(IsIso.eq_inv_comp _).mpr e⟩
theorem BinaryCofan.isColimit_iff_isIso_inr {X Y : C} (h : IsInitial X) (c : BinaryCofan X Y) :
Nonempty (IsColimit c) ↔ IsIso c.inr := by
refine Iff.trans ?_ (BinaryCofan.isColimit_iff_isIso_inl h (BinaryCofan.mk c.inr c.inl))
exact
⟨fun h => ⟨BinaryCofan.isColimitFlip h.some⟩, fun h =>
⟨(BinaryCofan.isColimitFlip h.some).ofIsoColimit (isoBinaryCofanMk c).symm⟩⟩
/-- If `X' ≅ X`, then `X ⨿ Y` also is the coproduct of `X'` and `Y`. -/
noncomputable def BinaryCofan.isColimitCompLeftIso {X Y X' : C} (c : BinaryCofan X Y) (f : X' ⟶ X)
[IsIso f] (h : IsColimit c) : IsColimit (BinaryCofan.mk (f ≫ c.inl) c.inr) := by
fapply BinaryCofan.isColimitMk
· exact fun s => h.desc (BinaryCofan.mk (inv f ≫ s.inl) s.inr)
· intro s
-- Porting note: simp timed out here too
simp only [IsColimit.fac,BinaryCofan.ι_app_left,eq_self_iff_true,
Category.assoc,BinaryCofan.mk_inl,IsIso.hom_inv_id_assoc]
· intro s
-- Porting note: simp timed out here too
simp only [IsColimit.fac,BinaryCofan.ι_app_right,eq_self_iff_true,BinaryCofan.mk_inr]
· intro s m e₁ e₂
apply BinaryCofan.IsColimit.hom_ext h
· rw [← cancel_epi f]
-- Porting note: simp timed out here too
simpa only [IsColimit.fac,BinaryCofan.ι_app_left,eq_self_iff_true,
Category.assoc,BinaryCofan.mk_inl,IsIso.hom_inv_id_assoc] using e₁
-- Porting note: simp timed out here too
· simpa only [IsColimit.fac,BinaryCofan.ι_app_right,eq_self_iff_true,BinaryCofan.mk_inr]
/-- If `Y' ≅ Y`, then `X ⨿ Y` also is the coproduct of `X` and `Y'`. -/
noncomputable def BinaryCofan.isColimitCompRightIso {X Y Y' : C} (c : BinaryCofan X Y) (f : Y' ⟶ Y)
[IsIso f] (h : IsColimit c) : IsColimit (BinaryCofan.mk c.inl (f ≫ c.inr)) :=
BinaryCofan.isColimitFlip <| BinaryCofan.isColimitCompLeftIso _ f (BinaryCofan.isColimitFlip h)
/-- An abbreviation for `HasLimit (pair X Y)`. -/
abbrev HasBinaryProduct (X Y : C) :=
HasLimit (pair X Y)
/-- An abbreviation for `HasColimit (pair X Y)`. -/
abbrev HasBinaryCoproduct (X Y : C) :=
HasColimit (pair X Y)
/-- If we have a product of `X` and `Y`, we can access it using `prod X Y` or
`X ⨯ Y`. -/
noncomputable abbrev prod (X Y : C) [HasBinaryProduct X Y] :=
limit (pair X Y)
/-- If we have a coproduct of `X` and `Y`, we can access it using `coprod X Y` or
`X ⨿ Y`. -/
noncomputable abbrev coprod (X Y : C) [HasBinaryCoproduct X Y] :=
colimit (pair X Y)
/-- Notation for the product -/
notation:20 X " ⨯ " Y:20 => prod X Y
/-- Notation for the coproduct -/
notation:20 X " ⨿ " Y:20 => coprod X Y
/-- The projection map to the first component of the product. -/
noncomputable abbrev prod.fst {X Y : C} [HasBinaryProduct X Y] : X ⨯ Y ⟶ X :=
limit.π (pair X Y) ⟨WalkingPair.left⟩
/-- The projection map to the second component of the product. -/
noncomputable abbrev prod.snd {X Y : C} [HasBinaryProduct X Y] : X ⨯ Y ⟶ Y :=
limit.π (pair X Y) ⟨WalkingPair.right⟩
/-- The inclusion map from the first component of the coproduct. -/
noncomputable abbrev coprod.inl {X Y : C} [HasBinaryCoproduct X Y] : X ⟶ X ⨿ Y :=
colimit.ι (pair X Y) ⟨WalkingPair.left⟩
/-- The inclusion map from the second component of the coproduct. -/
noncomputable abbrev coprod.inr {X Y : C} [HasBinaryCoproduct X Y] : Y ⟶ X ⨿ Y :=
colimit.ι (pair X Y) ⟨WalkingPair.right⟩
/-- The binary fan constructed from the projection maps is a limit. -/
noncomputable def prodIsProd (X Y : C) [HasBinaryProduct X Y] :
IsLimit (BinaryFan.mk (prod.fst : X ⨯ Y ⟶ X) prod.snd) :=
(limit.isLimit _).ofIsoLimit (Cones.ext (Iso.refl _) (fun ⟨u⟩ => by
cases u
· dsimp; simp only [Category.id_comp]; rfl
· dsimp; simp only [Category.id_comp]; rfl
))
/-- The binary cofan constructed from the coprojection maps is a colimit. -/
noncomputable def coprodIsCoprod (X Y : C) [HasBinaryCoproduct X Y] :
IsColimit (BinaryCofan.mk (coprod.inl : X ⟶ X ⨿ Y) coprod.inr) :=
(colimit.isColimit _).ofIsoColimit (Cocones.ext (Iso.refl _) (fun ⟨u⟩ => by
cases u
· dsimp; simp only [Category.comp_id]
· dsimp; simp only [Category.comp_id]
))
@[ext 1100]
theorem prod.hom_ext {W X Y : C} [HasBinaryProduct X Y] {f g : W ⟶ X ⨯ Y}
(h₁ : f ≫ prod.fst = g ≫ prod.fst) (h₂ : f ≫ prod.snd = g ≫ prod.snd) : f = g :=
BinaryFan.IsLimit.hom_ext (limit.isLimit _) h₁ h₂
@[ext 1100]
theorem coprod.hom_ext {W X Y : C} [HasBinaryCoproduct X Y] {f g : X ⨿ Y ⟶ W}
(h₁ : coprod.inl ≫ f = coprod.inl ≫ g) (h₂ : coprod.inr ≫ f = coprod.inr ≫ g) : f = g :=
BinaryCofan.IsColimit.hom_ext (colimit.isColimit _) h₁ h₂
/-- If the product of `X` and `Y` exists, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y`
induces a morphism `prod.lift f g : W ⟶ X ⨯ Y`. -/
noncomputable abbrev prod.lift {W X Y : C} [HasBinaryProduct X Y]
(f : W ⟶ X) (g : W ⟶ Y) : W ⟶ X ⨯ Y :=
limit.lift _ (BinaryFan.mk f g)
/-- diagonal arrow of the binary product in the category `fam I` -/
noncomputable abbrev diag (X : C) [HasBinaryProduct X X] : X ⟶ X ⨯ X :=
prod.lift (𝟙 _) (𝟙 _)
/-- If the coproduct of `X` and `Y` exists, then every pair of morphisms `f : X ⟶ W` and
`g : Y ⟶ W` induces a morphism `coprod.desc f g : X ⨿ Y ⟶ W`. -/
noncomputable abbrev coprod.desc {W X Y : C} [HasBinaryCoproduct X Y]
(f : X ⟶ W) (g : Y ⟶ W) : X ⨿ Y ⟶ W :=
colimit.desc _ (BinaryCofan.mk f g)
/-- codiagonal arrow of the binary coproduct -/
noncomputable abbrev codiag (X : C) [HasBinaryCoproduct X X] : X ⨿ X ⟶ X :=
coprod.desc (𝟙 _) (𝟙 _)
@[reassoc]
theorem prod.lift_fst {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) :
prod.lift f g ≫ prod.fst = f :=
limit.lift_π _ _
@[reassoc]
theorem prod.lift_snd {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) :
prod.lift f g ≫ prod.snd = g :=
limit.lift_π _ _
@[reassoc]
theorem coprod.inl_desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) :
coprod.inl ≫ coprod.desc f g = f :=
colimit.ι_desc _ _
@[reassoc]
theorem coprod.inr_desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) :
coprod.inr ≫ coprod.desc f g = g :=
colimit.ι_desc _ _
instance prod.mono_lift_of_mono_left {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y)
[Mono f] : Mono (prod.lift f g) :=
mono_of_mono_fac <| prod.lift_fst _ _
instance prod.mono_lift_of_mono_right {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y)
[Mono g] : Mono (prod.lift f g) :=
mono_of_mono_fac <| prod.lift_snd _ _
instance coprod.epi_desc_of_epi_left {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W)
[Epi f] : Epi (coprod.desc f g) :=
epi_of_epi_fac <| coprod.inl_desc _ _
instance coprod.epi_desc_of_epi_right {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W)
[Epi g] : Epi (coprod.desc f g) :=
epi_of_epi_fac <| coprod.inr_desc _ _
/-- If the product of `X` and `Y` exists, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y`
induces a morphism `l : W ⟶ X ⨯ Y` satisfying `l ≫ Prod.fst = f` and `l ≫ Prod.snd = g`. -/
noncomputable def prod.lift' {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) :
{ l : W ⟶ X ⨯ Y // l ≫ prod.fst = f ∧ l ≫ prod.snd = g } :=
⟨prod.lift f g, prod.lift_fst _ _, prod.lift_snd _ _⟩
/-- If the coproduct of `X` and `Y` exists, then every pair of morphisms `f : X ⟶ W` and
`g : Y ⟶ W` induces a morphism `l : X ⨿ Y ⟶ W` satisfying `coprod.inl ≫ l = f` and
`coprod.inr ≫ l = g`. -/
noncomputable def coprod.desc' {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) :
{ l : X ⨿ Y ⟶ W // coprod.inl ≫ l = f ∧ coprod.inr ≫ l = g } :=
⟨coprod.desc f g, coprod.inl_desc _ _, coprod.inr_desc _ _⟩
/-- If the products `W ⨯ X` and `Y ⨯ Z` exist, then every pair of morphisms `f : W ⟶ Y` and
`g : X ⟶ Z` induces a morphism `prod.map f g : W ⨯ X ⟶ Y ⨯ Z`. -/
noncomputable def prod.map {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z]
(f : W ⟶ Y) (g : X ⟶ Z) : W ⨯ X ⟶ Y ⨯ Z :=
limMap (mapPair f g)
/-- If the coproducts `W ⨿ X` and `Y ⨿ Z` exist, then every pair of morphisms `f : W ⟶ Y` and
`g : W ⟶ Z` induces a morphism `coprod.map f g : W ⨿ X ⟶ Y ⨿ Z`. -/
noncomputable def coprod.map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z]
(f : W ⟶ Y) (g : X ⟶ Z) : W ⨿ X ⟶ Y ⨿ Z :=
colimMap (mapPair f g)
noncomputable section ProdLemmas
-- Making the reassoc version of this a simp lemma seems to be more harmful than helpful.
@[reassoc, simp]
theorem prod.comp_lift {V W X Y : C} [HasBinaryProduct X Y] (f : V ⟶ W) (g : W ⟶ X) (h : W ⟶ Y) :
f ≫ prod.lift g h = prod.lift (f ≫ g) (f ≫ h) := by ext <;> simp
theorem prod.comp_diag {X Y : C} [HasBinaryProduct Y Y] (f : X ⟶ Y) :
f ≫ diag Y = prod.lift f f := by simp
@[reassoc (attr := simp)]
theorem prod.map_fst {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) : prod.map f g ≫ prod.fst = prod.fst ≫ f :=
limMap_π _ _
@[reassoc (attr := simp)]
theorem prod.map_snd {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) : prod.map f g ≫ prod.snd = prod.snd ≫ g :=
limMap_π _ _
@[simp]
theorem prod.map_id_id {X Y : C} [HasBinaryProduct X Y] : prod.map (𝟙 X) (𝟙 Y) = 𝟙 _ := by
ext <;> simp
@[simp]
theorem prod.lift_fst_snd {X Y : C} [HasBinaryProduct X Y] :
prod.lift prod.fst prod.snd = 𝟙 (X ⨯ Y) := by ext <;> simp
@[reassoc (attr := simp)]
theorem prod.lift_map {V W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : V ⟶ W)
(g : V ⟶ X) (h : W ⟶ Y) (k : X ⟶ Z) :
prod.lift f g ≫ prod.map h k = prod.lift (f ≫ h) (g ≫ k) := by ext <;> simp
@[simp]
theorem prod.lift_fst_comp_snd_comp {W X Y Z : C} [HasBinaryProduct W Y] [HasBinaryProduct X Z]
(g : W ⟶ X) (g' : Y ⟶ Z) : prod.lift (prod.fst ≫ g) (prod.snd ≫ g') = prod.map g g' := by
rw [← prod.lift_map]
simp
-- We take the right hand side here to be simp normal form, as this way composition lemmas for
-- `f ≫ h` and `g ≫ k` can fire (eg `id_comp`) , while `map_fst` and `map_snd` can still work just
-- as well.
@[reassoc (attr := simp)]
theorem prod.map_map {A₁ A₂ A₃ B₁ B₂ B₃ : C} [HasBinaryProduct A₁ B₁] [HasBinaryProduct A₂ B₂]
[HasBinaryProduct A₃ B₃] (f : A₁ ⟶ A₂) (g : B₁ ⟶ B₂) (h : A₂ ⟶ A₃) (k : B₂ ⟶ B₃) :
prod.map f g ≫ prod.map h k = prod.map (f ≫ h) (g ≫ k) := by ext <;> simp
-- TODO: is it necessary to weaken the assumption here?
@[reassoc]
theorem prod.map_swap {A B X Y : C} (f : A ⟶ B) (g : X ⟶ Y)
[HasLimitsOfShape (Discrete WalkingPair) C] :
prod.map (𝟙 X) f ≫ prod.map g (𝟙 B) = prod.map g (𝟙 A) ≫ prod.map (𝟙 Y) f := by simp
@[reassoc]
theorem prod.map_comp_id {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryProduct X W]
[HasBinaryProduct Z W] [HasBinaryProduct Y W] :
prod.map (f ≫ g) (𝟙 W) = prod.map f (𝟙 W) ≫ prod.map g (𝟙 W) := by simp
@[reassoc]
theorem prod.map_id_comp {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryProduct W X]
[HasBinaryProduct W Y] [HasBinaryProduct W Z] :
prod.map (𝟙 W) (f ≫ g) = prod.map (𝟙 W) f ≫ prod.map (𝟙 W) g := by simp
/-- If the products `W ⨯ X` and `Y ⨯ Z` exist, then every pair of isomorphisms `f : W ≅ Y` and
`g : X ≅ Z` induces an isomorphism `prod.mapIso f g : W ⨯ X ≅ Y ⨯ Z`. -/
@[simps]
def prod.mapIso {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ≅ Y)
(g : X ≅ Z) : W ⨯ X ≅ Y ⨯ Z where
hom := prod.map f.hom g.hom
inv := prod.map f.inv g.inv
instance isIso_prod {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) [IsIso f] [IsIso g] : IsIso (prod.map f g) :=
(prod.mapIso (asIso f) (asIso g)).isIso_hom
instance prod.map_mono {C : Type*} [Category C] {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [Mono f]
[Mono g] [HasBinaryProduct W X] [HasBinaryProduct Y Z] : Mono (prod.map f g) :=
⟨fun i₁ i₂ h => by
ext
· rw [← cancel_mono f]
simpa using congr_arg (fun f => f ≫ prod.fst) h
· rw [← cancel_mono g]
simpa using congr_arg (fun f => f ≫ prod.snd) h⟩
@[reassoc]
theorem prod.diag_map {X Y : C} (f : X ⟶ Y) [HasBinaryProduct X X] [HasBinaryProduct Y Y] :
diag X ≫ prod.map f f = f ≫ diag Y := by simp
@[reassoc]
theorem prod.diag_map_fst_snd {X Y : C} [HasBinaryProduct X Y] [HasBinaryProduct (X ⨯ Y) (X ⨯ Y)] :
diag (X ⨯ Y) ≫ prod.map prod.fst prod.snd = 𝟙 (X ⨯ Y) := by simp
@[reassoc]
theorem prod.diag_map_fst_snd_comp [HasLimitsOfShape (Discrete WalkingPair) C] {X X' Y Y' : C}
(g : X ⟶ Y) (g' : X' ⟶ Y') :
diag (X ⨯ X') ≫ prod.map (prod.fst ≫ g) (prod.snd ≫ g') = prod.map g g' := by simp
instance {X : C} [HasBinaryProduct X X] : IsSplitMono (diag X) :=
IsSplitMono.mk' { retraction := prod.fst }
end ProdLemmas
noncomputable section CoprodLemmas
@[reassoc, simp]
theorem coprod.desc_comp {V W X Y : C} [HasBinaryCoproduct X Y] (f : V ⟶ W) (g : X ⟶ V)
(h : Y ⟶ V) : coprod.desc g h ≫ f = coprod.desc (g ≫ f) (h ≫ f) := by
ext <;> simp
theorem coprod.diag_comp {X Y : C} [HasBinaryCoproduct X X] (f : X ⟶ Y) :
codiag X ≫ f = coprod.desc f f := by simp
@[reassoc (attr := simp)]
theorem coprod.inl_map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) : coprod.inl ≫ coprod.map f g = f ≫ coprod.inl :=
ι_colimMap _ _
@[reassoc (attr := simp)]
theorem coprod.inr_map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) : coprod.inr ≫ coprod.map f g = g ≫ coprod.inr :=
ι_colimMap _ _
@[simp]
theorem coprod.map_id_id {X Y : C} [HasBinaryCoproduct X Y] : coprod.map (𝟙 X) (𝟙 Y) = 𝟙 _ := by
ext <;> simp
@[simp]
theorem coprod.desc_inl_inr {X Y : C} [HasBinaryCoproduct X Y] :
coprod.desc coprod.inl coprod.inr = 𝟙 (X ⨿ Y) := by ext <;> simp
-- The simp linter says simp can prove the reassoc version of this lemma.
@[reassoc, simp]
theorem coprod.map_desc {S T U V W : C} [HasBinaryCoproduct U W] [HasBinaryCoproduct T V]
(f : U ⟶ S) (g : W ⟶ S) (h : T ⟶ U) (k : V ⟶ W) :
coprod.map h k ≫ coprod.desc f g = coprod.desc (h ≫ f) (k ≫ g) := by
ext <;> simp
@[simp]
theorem coprod.desc_comp_inl_comp_inr {W X Y Z : C} [HasBinaryCoproduct W Y]
[HasBinaryCoproduct X Z] (g : W ⟶ X) (g' : Y ⟶ Z) :
coprod.desc (g ≫ coprod.inl) (g' ≫ coprod.inr) = coprod.map g g' := by
rw [← coprod.map_desc]; simp
-- We take the right hand side here to be simp normal form, as this way composition lemmas for
-- `f ≫ h` and `g ≫ k` can fire (eg `id_comp`) , while `inl_map` and `inr_map` can still work just
-- as well.
@[reassoc (attr := simp)]
theorem coprod.map_map {A₁ A₂ A₃ B₁ B₂ B₃ : C} [HasBinaryCoproduct A₁ B₁] [HasBinaryCoproduct A₂ B₂]
[HasBinaryCoproduct A₃ B₃] (f : A₁ ⟶ A₂) (g : B₁ ⟶ B₂) (h : A₂ ⟶ A₃) (k : B₂ ⟶ B₃) :
coprod.map f g ≫ coprod.map h k = coprod.map (f ≫ h) (g ≫ k) := by
ext <;> simp
-- I don't think it's a good idea to make any of the following three simp lemmas.
@[reassoc]
theorem coprod.map_swap {A B X Y : C} (f : A ⟶ B) (g : X ⟶ Y)
[HasColimitsOfShape (Discrete WalkingPair) C] :
coprod.map (𝟙 X) f ≫ coprod.map g (𝟙 B) = coprod.map g (𝟙 A) ≫ coprod.map (𝟙 Y) f := by simp
@[reassoc]
theorem coprod.map_comp_id {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryCoproduct Z W]
[HasBinaryCoproduct Y W] [HasBinaryCoproduct X W] :
coprod.map (f ≫ g) (𝟙 W) = coprod.map f (𝟙 W) ≫ coprod.map g (𝟙 W) := by simp
@[reassoc]
theorem coprod.map_id_comp {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryCoproduct W X]
[HasBinaryCoproduct W Y] [HasBinaryCoproduct W Z] :
coprod.map (𝟙 W) (f ≫ g) = coprod.map (𝟙 W) f ≫ coprod.map (𝟙 W) g := by simp
/-- If the coproducts `W ⨿ X` and `Y ⨿ Z` exist, then every pair of isomorphisms `f : W ≅ Y` and
`g : W ≅ Z` induces an isomorphism `coprod.mapIso f g : W ⨿ X ≅ Y ⨿ Z`. -/
@[simps]
def coprod.mapIso {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ≅ Y)
(g : X ≅ Z) : W ⨿ X ≅ Y ⨿ Z where
hom := coprod.map f.hom g.hom
inv := coprod.map f.inv g.inv
instance isIso_coprod {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) [IsIso f] [IsIso g] : IsIso (coprod.map f g) :=
(coprod.mapIso (asIso f) (asIso g)).isIso_hom
instance coprod.map_epi {C : Type*} [Category C] {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [Epi f]
[Epi g] [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] : Epi (coprod.map f g) :=
⟨fun i₁ i₂ h => by
| ext
· rw [← cancel_epi f]
| Mathlib/CategoryTheory/Limits/Shapes/BinaryProducts.lean | 816 | 817 |
/-
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.Analysis.InnerProductSpace.Dual
import Mathlib.Analysis.InnerProductSpace.Orientation
import Mathlib.Data.Complex.FiniteDimensional
import Mathlib.Data.Complex.Orientation
import Mathlib.Tactic.LinearCombination
/-!
# Oriented two-dimensional real inner product spaces
This file defines constructions specific to the geometry of an oriented two-dimensional real inner
product space `E`.
## Main declarations
* `Orientation.areaForm`: an antisymmetric bilinear form `E →ₗ[ℝ] E →ₗ[ℝ] ℝ` (usual notation `ω`).
Morally, when `ω` is evaluated on two vectors, it gives the oriented area of the parallelogram
they span. (But mathlib does not yet have a construction of oriented area, and in fact the
construction of oriented area should pass through `ω`.)
* `Orientation.rightAngleRotation`: an isometric automorphism `E ≃ₗᵢ[ℝ] E` (usual notation `J`).
This automorphism squares to -1. In a later file, rotations (`Orientation.rotation`) are defined,
in such a way that this automorphism is equal to rotation by 90 degrees.
* `Orientation.basisRightAngleRotation`: for a nonzero vector `x` in `E`, the basis `![x, J x]`
for `E`.
* `Orientation.kahler`: a complex-valued real-bilinear map `E →ₗ[ℝ] E →ₗ[ℝ] ℂ`. Its real part is the
inner product and its imaginary part is `Orientation.areaForm`. For vectors `x` and `y` in `E`,
the complex number `o.kahler x y` has modulus `‖x‖ * ‖y‖`. In a later file, oriented angles
(`Orientation.oangle`) are defined, in such a way that the argument of `o.kahler x y` is the
oriented angle from `x` to `y`.
## Main results
* `Orientation.rightAngleRotation_rightAngleRotation`: the identity `J (J x) = - x`
* `Orientation.nonneg_inner_and_areaForm_eq_zero_iff_sameRay`: `x`, `y` are in the same ray, if
and only if `0 ≤ ⟪x, y⟫` and `ω x y = 0`
* `Orientation.kahler_mul`: the identity `o.kahler x a * o.kahler a y = ‖a‖ ^ 2 * o.kahler x y`
* `Complex.areaForm`, `Complex.rightAngleRotation`, `Complex.kahler`: the concrete
interpretations of `areaForm`, `rightAngleRotation`, `kahler` for the oriented real inner
product space `ℂ`
* `Orientation.areaForm_map_complex`, `Orientation.rightAngleRotation_map_complex`,
`Orientation.kahler_map_complex`: given an orientation-preserving isometry from `E` to `ℂ`,
expressions for `areaForm`, `rightAngleRotation`, `kahler` as the pullback of their concrete
interpretations on `ℂ`
## Implementation notes
Notation `ω` for `Orientation.areaForm` and `J` for `Orientation.rightAngleRotation` should be
defined locally in each file which uses them, since otherwise one would need a more cumbersome
notation which mentions the orientation explicitly (something like `ω[o]`). Write
```
local notation "ω" => o.areaForm
local notation "J" => o.rightAngleRotation
```
-/
noncomputable section
open scoped RealInnerProductSpace ComplexConjugate
open Module
lemma FiniteDimensional.of_fact_finrank_eq_two {K V : Type*} [DivisionRing K]
[AddCommGroup V] [Module K V] [Fact (finrank K V = 2)] : FiniteDimensional K V :=
.of_fact_finrank_eq_succ 1
attribute [local instance] FiniteDimensional.of_fact_finrank_eq_two
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [Fact (finrank ℝ E = 2)]
(o : Orientation ℝ E (Fin 2))
namespace Orientation
/-- An antisymmetric bilinear form on an oriented real inner product space of dimension 2 (usual
notation `ω`). When evaluated on two vectors, it gives the oriented area of the parallelogram they
span. -/
irreducible_def areaForm : E →ₗ[ℝ] E →ₗ[ℝ] ℝ := by
let z : E [⋀^Fin 0]→ₗ[ℝ] ℝ ≃ₗ[ℝ] ℝ :=
AlternatingMap.constLinearEquivOfIsEmpty.symm
let y : E [⋀^Fin 1]→ₗ[ℝ] ℝ →ₗ[ℝ] E →ₗ[ℝ] ℝ :=
LinearMap.llcomp ℝ E (E [⋀^Fin 0]→ₗ[ℝ] ℝ) ℝ z ∘ₗ AlternatingMap.curryLeftLinearMap
exact y ∘ₗ AlternatingMap.curryLeftLinearMap (R' := ℝ) o.volumeForm
local notation "ω" => o.areaForm
theorem areaForm_to_volumeForm (x y : E) : ω x y = o.volumeForm ![x, y] := by simp [areaForm]
@[simp]
theorem areaForm_apply_self (x : E) : ω x x = 0 := by
rw [areaForm_to_volumeForm]
refine o.volumeForm.map_eq_zero_of_eq ![x, x] ?_ (?_ : (0 : Fin 2) ≠ 1)
· simp
· norm_num
theorem areaForm_swap (x y : E) : ω x y = -ω y x := by
simp only [areaForm_to_volumeForm]
convert o.volumeForm.map_swap ![y, x] (_ : (0 : Fin 2) ≠ 1)
· ext i
fin_cases i <;> rfl
· norm_num
@[simp]
theorem areaForm_neg_orientation : (-o).areaForm = -o.areaForm := by
ext x y
simp [areaForm_to_volumeForm]
/-- Continuous linear map version of `Orientation.areaForm`, useful for calculus. -/
def areaForm' : E →L[ℝ] E →L[ℝ] ℝ :=
LinearMap.toContinuousLinearMap
(↑(LinearMap.toContinuousLinearMap : (E →ₗ[ℝ] ℝ) ≃ₗ[ℝ] E →L[ℝ] ℝ) ∘ₗ o.areaForm)
@[simp]
theorem areaForm'_apply (x : E) :
o.areaForm' x = LinearMap.toContinuousLinearMap (o.areaForm x) :=
rfl
theorem abs_areaForm_le (x y : E) : |ω x y| ≤ ‖x‖ * ‖y‖ := by
simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.abs_volumeForm_apply_le ![x, y]
theorem areaForm_le (x y : E) : ω x y ≤ ‖x‖ * ‖y‖ := by
simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.volumeForm_apply_le ![x, y]
theorem abs_areaForm_of_orthogonal {x y : E} (h : ⟪x, y⟫ = 0) : |ω x y| = ‖x‖ * ‖y‖ := by
rw [o.areaForm_to_volumeForm, o.abs_volumeForm_apply_of_pairwise_orthogonal]
· simp [Fin.prod_univ_succ]
intro i j hij
fin_cases i <;> fin_cases j
· simp_all
· simpa using h
· simpa [real_inner_comm] using h
· simp_all
theorem areaForm_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F]
[hF : Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) (x y : F) :
(Orientation.map (Fin 2) φ.toLinearEquiv o).areaForm x y =
o.areaForm (φ.symm x) (φ.symm y) := by
have : φ.symm ∘ ![x, y] = ![φ.symm x, φ.symm y] := by
ext i
fin_cases i <;> rfl
simp [areaForm_to_volumeForm, volumeForm_map, this]
/-- The area form is invariant under pullback by a positively-oriented isometric automorphism. -/
theorem areaForm_comp_linearIsometryEquiv (φ : E ≃ₗᵢ[ℝ] E)
(hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) (x y : E) :
o.areaForm (φ x) (φ y) = o.areaForm x y := by
convert o.areaForm_map φ (φ x) (φ y)
· symm
rwa [← o.map_eq_iff_det_pos φ.toLinearEquiv] at hφ
rw [@Fact.out (finrank ℝ E = 2), Fintype.card_fin]
· simp
· simp
/-- Auxiliary construction for `Orientation.rightAngleRotation`, rotation by 90 degrees in an
oriented real inner product space of dimension 2. -/
irreducible_def rightAngleRotationAux₁ : E →ₗ[ℝ] E :=
let to_dual : E ≃ₗ[ℝ] E →ₗ[ℝ] ℝ :=
(InnerProductSpace.toDual ℝ E).toLinearEquiv ≪≫ₗ LinearMap.toContinuousLinearMap.symm
↑to_dual.symm ∘ₗ ω
@[simp]
theorem inner_rightAngleRotationAux₁_left (x y : E) : ⟪o.rightAngleRotationAux₁ x, y⟫ = ω x y := by
simp only [rightAngleRotationAux₁, LinearEquiv.trans_symm, LinearIsometryEquiv.toLinearEquiv_symm,
LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.trans_apply,
LinearIsometryEquiv.coe_toLinearEquiv]
rw [InnerProductSpace.toDual_symm_apply]
norm_cast
@[simp]
theorem inner_rightAngleRotationAux₁_right (x y : E) :
⟪x, o.rightAngleRotationAux₁ y⟫ = -ω x y := by
rw [real_inner_comm]
simp [o.areaForm_swap y x]
/-- Auxiliary construction for `Orientation.rightAngleRotation`, rotation by 90 degrees in an
oriented real inner product space of dimension 2. -/
def rightAngleRotationAux₂ : E →ₗᵢ[ℝ] E :=
{ o.rightAngleRotationAux₁ with
norm_map' := fun x => by
refine le_antisymm ?_ ?_
· rcases eq_or_lt_of_le (norm_nonneg (o.rightAngleRotationAux₁ x)) with h | h
· rw [← h]
positivity
refine le_of_mul_le_mul_right ?_ h
rw [← real_inner_self_eq_norm_mul_norm, o.inner_rightAngleRotationAux₁_left]
exact o.areaForm_le x (o.rightAngleRotationAux₁ x)
· let K : Submodule ℝ E := ℝ ∙ x
have : Nontrivial Kᗮ := by
apply nontrivial_of_finrank_pos (R := ℝ)
have : finrank ℝ K ≤ Finset.card {x} := by
rw [← Set.toFinset_singleton]
exact finrank_span_le_card ({x} : Set E)
have : Finset.card {x} = 1 := Finset.card_singleton x
have : finrank ℝ K + finrank ℝ Kᗮ = finrank ℝ E := K.finrank_add_finrank_orthogonal
have : finrank ℝ E = 2 := Fact.out
omega
obtain ⟨w, hw₀⟩ : ∃ w : Kᗮ, w ≠ 0 := exists_ne 0
have hw' : ⟪x, (w : E)⟫ = 0 := Submodule.mem_orthogonal_singleton_iff_inner_right.mp w.2
have hw : (w : E) ≠ 0 := fun h => hw₀ (Submodule.coe_eq_zero.mp h)
refine le_of_mul_le_mul_right ?_ (by rwa [norm_pos_iff] : 0 < ‖(w : E)‖)
rw [← o.abs_areaForm_of_orthogonal hw']
rw [← o.inner_rightAngleRotationAux₁_left x w]
exact abs_real_inner_le_norm (o.rightAngleRotationAux₁ x) w }
@[simp]
theorem rightAngleRotationAux₁_rightAngleRotationAux₁ (x : E) :
o.rightAngleRotationAux₁ (o.rightAngleRotationAux₁ x) = -x := by
apply ext_inner_left ℝ
intro y
have : ⟪o.rightAngleRotationAux₁ y, o.rightAngleRotationAux₁ x⟫ = ⟪y, x⟫ :=
LinearIsometry.inner_map_map o.rightAngleRotationAux₂ y x
rw [o.inner_rightAngleRotationAux₁_right, ← o.inner_rightAngleRotationAux₁_left, this,
inner_neg_right]
/-- An isometric automorphism of an oriented real inner product space of dimension 2 (usual notation
`J`). This automorphism squares to -1. We will define rotations in such a way that this
automorphism is equal to rotation by 90 degrees. -/
irreducible_def rightAngleRotation : E ≃ₗᵢ[ℝ] E :=
LinearIsometryEquiv.ofLinearIsometry o.rightAngleRotationAux₂ (-o.rightAngleRotationAux₁)
(by ext; simp [rightAngleRotationAux₂]) (by ext; simp [rightAngleRotationAux₂])
local notation "J" => o.rightAngleRotation
@[simp]
theorem inner_rightAngleRotation_left (x y : E) : ⟪J x, y⟫ = ω x y := by
rw [rightAngleRotation]
exact o.inner_rightAngleRotationAux₁_left x y
@[simp]
theorem inner_rightAngleRotation_right (x y : E) : ⟪x, J y⟫ = -ω x y := by
rw [rightAngleRotation]
exact o.inner_rightAngleRotationAux₁_right x y
@[simp]
theorem rightAngleRotation_rightAngleRotation (x : E) : J (J x) = -x := by
rw [rightAngleRotation]
exact o.rightAngleRotationAux₁_rightAngleRotationAux₁ x
@[simp]
theorem rightAngleRotation_symm :
LinearIsometryEquiv.symm J = LinearIsometryEquiv.trans J (LinearIsometryEquiv.neg ℝ) := by
rw [rightAngleRotation]
exact LinearIsometryEquiv.toLinearIsometry_injective rfl
theorem inner_rightAngleRotation_self (x : E) : ⟪J x, x⟫ = 0 := by simp
theorem inner_rightAngleRotation_swap (x y : E) : ⟪x, J y⟫ = -⟪J x, y⟫ := by simp
theorem inner_rightAngleRotation_swap' (x y : E) : ⟪J x, y⟫ = -⟪x, J y⟫ := by
simp [o.inner_rightAngleRotation_swap x y]
theorem inner_comp_rightAngleRotation (x y : E) : ⟪J x, J y⟫ = ⟪x, y⟫ :=
LinearIsometryEquiv.inner_map_map J x y
@[simp]
theorem areaForm_rightAngleRotation_left (x y : E) : ω (J x) y = -⟪x, y⟫ := by
rw [← o.inner_comp_rightAngleRotation, o.inner_rightAngleRotation_right, neg_neg]
@[simp]
theorem areaForm_rightAngleRotation_right (x y : E) : ω x (J y) = ⟪x, y⟫ := by
rw [← o.inner_rightAngleRotation_left, o.inner_comp_rightAngleRotation]
theorem areaForm_comp_rightAngleRotation (x y : E) : ω (J x) (J y) = ω x y := by simp
@[simp]
theorem rightAngleRotation_trans_rightAngleRotation :
LinearIsometryEquiv.trans J J = LinearIsometryEquiv.neg ℝ := by ext; simp
theorem rightAngleRotation_neg_orientation (x : E) :
(-o).rightAngleRotation x = -o.rightAngleRotation x := by
apply ext_inner_right ℝ
intro y
rw [inner_rightAngleRotation_left]
simp
@[simp]
theorem rightAngleRotation_trans_neg_orientation :
(-o).rightAngleRotation = o.rightAngleRotation.trans (LinearIsometryEquiv.neg ℝ) :=
LinearIsometryEquiv.ext <| o.rightAngleRotation_neg_orientation
theorem rightAngleRotation_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F]
[hF : Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) (x : F) :
(Orientation.map (Fin 2) φ.toLinearEquiv o).rightAngleRotation x =
φ (o.rightAngleRotation (φ.symm x)) := by
apply ext_inner_right ℝ
intro y
rw [inner_rightAngleRotation_left]
trans ⟪J (φ.symm x), φ.symm y⟫
· simp [o.areaForm_map]
trans ⟪φ (J (φ.symm x)), φ (φ.symm y)⟫
· rw [φ.inner_map_map]
· simp
/-- `J` commutes with any positively-oriented isometric automorphism. -/
theorem linearIsometryEquiv_comp_rightAngleRotation (φ : E ≃ₗᵢ[ℝ] E)
(hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) (x : E) : φ (J x) = J (φ x) := by
convert (o.rightAngleRotation_map φ (φ x)).symm
· simp
· symm
rwa [← o.map_eq_iff_det_pos φ.toLinearEquiv] at hφ
rw [@Fact.out (finrank ℝ E = 2), Fintype.card_fin]
theorem rightAngleRotation_map' {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F]
[Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) :
(Orientation.map (Fin 2) φ.toLinearEquiv o).rightAngleRotation =
(φ.symm.trans o.rightAngleRotation).trans φ :=
LinearIsometryEquiv.ext <| o.rightAngleRotation_map φ
/-- `J` commutes with any positively-oriented isometric automorphism. -/
theorem linearIsometryEquiv_comp_rightAngleRotation' (φ : E ≃ₗᵢ[ℝ] E)
(hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) :
LinearIsometryEquiv.trans J φ = φ.trans J :=
LinearIsometryEquiv.ext <| o.linearIsometryEquiv_comp_rightAngleRotation φ hφ
/-- For a nonzero vector `x` in an oriented two-dimensional real inner product space `E`,
`![x, J x]` forms an (orthogonal) basis for `E`. -/
def basisRightAngleRotation (x : E) (hx : x ≠ 0) : Basis (Fin 2) ℝ E :=
@basisOfLinearIndependentOfCardEqFinrank ℝ _ _ _ _ _ _ _ ![x, J x]
(linearIndependent_of_ne_zero_of_inner_eq_zero (fun i => by fin_cases i <;> simp [hx])
(by
intro i j hij
fin_cases i <;> fin_cases j <;> simp_all))
(@Fact.out (finrank ℝ E = 2)).symm
@[simp]
theorem coe_basisRightAngleRotation (x : E) (hx : x ≠ 0) :
⇑(o.basisRightAngleRotation x hx) = ![x, J x] :=
coe_basisOfLinearIndependentOfCardEqFinrank _ _
/-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫`. (See
`Orientation.inner_mul_inner_add_areaForm_mul_areaForm` for the "applied" form.) -/
theorem inner_mul_inner_add_areaForm_mul_areaForm' (a x : E) :
⟪a, x⟫ • innerₛₗ ℝ a + ω a x • ω a = ‖a‖ ^ 2 • innerₛₗ ℝ x := by
by_cases ha : a = 0
· simp [ha]
apply (o.basisRightAngleRotation a ha).ext
intro i
fin_cases i
· simp [real_inner_self_eq_norm_sq, mul_comm, real_inner_comm]
· simp [real_inner_self_eq_norm_sq, mul_comm, o.areaForm_swap a x]
/-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫`. -/
theorem inner_mul_inner_add_areaForm_mul_areaForm (a x y : E) :
⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫ :=
congr_arg (fun f : E →ₗ[ℝ] ℝ => f y) (o.inner_mul_inner_add_areaForm_mul_areaForm' a x)
theorem inner_sq_add_areaForm_sq (a b : E) : ⟪a, b⟫ ^ 2 + ω a b ^ 2 = ‖a‖ ^ 2 * ‖b‖ ^ 2 := by
simpa [sq, real_inner_self_eq_norm_sq] using o.inner_mul_inner_add_areaForm_mul_areaForm a b b
/-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y`. (See
`Orientation.inner_mul_areaForm_sub` for the "applied" form.) -/
theorem inner_mul_areaForm_sub' (a x : E) : ⟪a, x⟫ • ω a - ω a x • innerₛₗ ℝ a = ‖a‖ ^ 2 • ω x := by
by_cases ha : a = 0
· simp [ha]
apply (o.basisRightAngleRotation a ha).ext
intro i
fin_cases i
· simp [real_inner_self_eq_norm_sq, mul_comm, o.areaForm_swap a x]
· simp [real_inner_self_eq_norm_sq, mul_comm, real_inner_comm]
/-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y`. -/
theorem inner_mul_areaForm_sub (a x y : E) : ⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y :=
congr_arg (fun f : E →ₗ[ℝ] ℝ => f y) (o.inner_mul_areaForm_sub' a x)
theorem nonneg_inner_and_areaForm_eq_zero_iff_sameRay (x y : E) :
0 ≤ ⟪x, y⟫ ∧ ω x y = 0 ↔ SameRay ℝ x y := by
by_cases hx : x = 0
· simp [hx]
constructor
· let a : ℝ := (o.basisRightAngleRotation x hx).repr y 0
let b : ℝ := (o.basisRightAngleRotation x hx).repr y 1
suffices ↑0 ≤ a * ‖x‖ ^ 2 ∧ b * ‖x‖ ^ 2 = 0 → SameRay ℝ x (a • x + b • J x) by
rw [← (o.basisRightAngleRotation x hx).sum_repr y]
simp only [Fin.sum_univ_succ, coe_basisRightAngleRotation, Matrix.cons_val_zero,
Fin.succ_zero_eq_one', Finset.univ_eq_empty, Finset.sum_empty, areaForm_apply_self,
map_smul, map_add, real_inner_smul_right, inner_add_right, Matrix.cons_val_one,
Matrix.head_cons, Algebra.id.smul_eq_mul, areaForm_rightAngleRotation_right,
mul_zero, add_zero, zero_add, neg_zero, inner_rightAngleRotation_right,
real_inner_self_eq_norm_sq, zero_smul, one_smul]
exact this
rintro ⟨ha, hb⟩
have hx' : 0 < ‖x‖ := by simpa using hx
have ha' : 0 ≤ a := nonneg_of_mul_nonneg_left ha (by positivity)
have hb' : b = 0 := eq_zero_of_ne_zero_of_mul_right_eq_zero (pow_ne_zero 2 hx'.ne') hb
exact (SameRay.sameRay_nonneg_smul_right x ha').add_right <| by simp [hb']
· intro h
obtain ⟨r, hr, rfl⟩ := h.exists_nonneg_left hx
simp only [inner_smul_right, real_inner_self_eq_norm_sq, LinearMap.map_smulₛₗ,
areaForm_apply_self, Algebra.id.smul_eq_mul, mul_zero, eq_self_iff_true, and_true]
positivity
/-- A complex-valued real-bilinear map on an oriented real inner product space of dimension 2. Its
real part is the inner product and its imaginary part is `Orientation.areaForm`.
On `ℂ` with the standard orientation, `kahler w z = conj w * z`; see `Complex.kahler`. -/
def kahler : E →ₗ[ℝ] E →ₗ[ℝ] ℂ :=
LinearMap.llcomp ℝ E ℝ ℂ Complex.ofRealCLM ∘ₗ innerₛₗ ℝ +
LinearMap.llcomp ℝ E ℝ ℂ ((LinearMap.lsmul ℝ ℂ).flip Complex.I) ∘ₗ ω
theorem kahler_apply_apply (x y : E) : o.kahler x y = ⟪x, y⟫ + ω x y • Complex.I :=
rfl
theorem kahler_swap (x y : E) : o.kahler x y = conj (o.kahler y x) := by
simp only [kahler_apply_apply]
rw [real_inner_comm, areaForm_swap]
simp [Complex.conj_ofReal]
@[simp]
theorem kahler_apply_self (x : E) : o.kahler x x = ‖x‖ ^ 2 := by
simp [kahler_apply_apply, real_inner_self_eq_norm_sq]
@[simp]
theorem kahler_rightAngleRotation_left (x y : E) :
o.kahler (J x) y = -Complex.I * o.kahler x y := by
simp only [o.areaForm_rightAngleRotation_left, o.inner_rightAngleRotation_left,
o.kahler_apply_apply, Complex.ofReal_neg, Complex.real_smul]
linear_combination ω x y * Complex.I_sq
@[simp]
theorem kahler_rightAngleRotation_right (x y : E) :
o.kahler x (J y) = Complex.I * o.kahler x y := by
simp only [o.areaForm_rightAngleRotation_right, o.inner_rightAngleRotation_right,
o.kahler_apply_apply, Complex.ofReal_neg, Complex.real_smul]
linear_combination -ω x y * Complex.I_sq
-- @[simp] -- Porting note: simp normal form is `kahler_comp_rightAngleRotation'`
theorem kahler_comp_rightAngleRotation (x y : E) : o.kahler (J x) (J y) = o.kahler x y := by
simp only [kahler_rightAngleRotation_left, kahler_rightAngleRotation_right]
linear_combination -o.kahler x y * Complex.I_sq
theorem kahler_comp_rightAngleRotation' (x y : E) :
-(Complex.I * (Complex.I * o.kahler x y)) = o.kahler x y := by
linear_combination -o.kahler x y * Complex.I_sq
@[simp]
theorem kahler_neg_orientation (x y : E) : (-o).kahler x y = conj (o.kahler x y) := by
simp [kahler_apply_apply, Complex.conj_ofReal]
theorem kahler_mul (a x y : E) : o.kahler x a * o.kahler a y = ‖a‖ ^ 2 * o.kahler x y := by
trans ((‖a‖ ^ 2 :) : ℂ) * o.kahler x y
· apply Complex.ext
· simp only [o.kahler_apply_apply, Complex.add_im, Complex.add_re, Complex.I_im, Complex.I_re,
Complex.mul_im, Complex.mul_re, Complex.ofReal_im, Complex.ofReal_re, Complex.real_smul]
rw [real_inner_comm a x, o.areaForm_swap x a]
linear_combination o.inner_mul_inner_add_areaForm_mul_areaForm a x y
· simp only [o.kahler_apply_apply, Complex.add_im, Complex.add_re, Complex.I_im, Complex.I_re,
Complex.mul_im, Complex.mul_re, Complex.ofReal_im, Complex.ofReal_re, Complex.real_smul]
rw [real_inner_comm a x, o.areaForm_swap x a]
linear_combination o.inner_mul_areaForm_sub a x y
· norm_cast
theorem normSq_kahler (x y : E) : Complex.normSq (o.kahler x y) = ‖x‖ ^ 2 * ‖y‖ ^ 2 := by
simpa [kahler_apply_apply, Complex.normSq, sq] using o.inner_sq_add_areaForm_sq x y
theorem norm_kahler (x y : E) : ‖o.kahler x y‖ = ‖x‖ * ‖y‖ := by
rw [← sq_eq_sq₀, Complex.sq_norm]
· linear_combination o.normSq_kahler x y
· positivity
· positivity
@[deprecated (since := "2025-02-17")] alias abs_kahler := norm_kahler
theorem eq_zero_or_eq_zero_of_kahler_eq_zero {x y : E} (hx : o.kahler x y = 0) : x = 0 ∨ y = 0 := by
have : ‖x‖ * ‖y‖ = 0 := by simpa [hx] using (o.norm_kahler x y).symm
rcases eq_zero_or_eq_zero_of_mul_eq_zero this with h | h
· left
simpa using h
· right
simpa using h
theorem kahler_eq_zero_iff (x y : E) : o.kahler x y = 0 ↔ x = 0 ∨ y = 0 := by
refine ⟨o.eq_zero_or_eq_zero_of_kahler_eq_zero, ?_⟩
rintro (rfl | rfl) <;> simp
theorem kahler_ne_zero {x y : E} (hx : x ≠ 0) (hy : y ≠ 0) : o.kahler x y ≠ 0 := by
apply mt o.eq_zero_or_eq_zero_of_kahler_eq_zero
tauto
theorem kahler_ne_zero_iff (x y : E) : o.kahler x y ≠ 0 ↔ x ≠ 0 ∧ y ≠ 0 := by
refine ⟨?_, fun h => o.kahler_ne_zero h.1 h.2⟩
contrapose
simp only [not_and_or, Classical.not_not, kahler_apply_apply, Complex.real_smul]
rintro (rfl | rfl) <;> simp
theorem kahler_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F]
[hF : Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) (x y : F) :
(Orientation.map (Fin 2) φ.toLinearEquiv o).kahler x y = o.kahler (φ.symm x) (φ.symm y) := by
simp [kahler_apply_apply, areaForm_map]
/-- The bilinear map `kahler` is invariant under pullback by a positively-oriented isometric
automorphism. -/
theorem kahler_comp_linearIsometryEquiv (φ : E ≃ₗᵢ[ℝ] E)
(hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) (x y : E) :
o.kahler (φ x) (φ y) = o.kahler x y := by
simp [kahler_apply_apply, o.areaForm_comp_linearIsometryEquiv φ hφ]
end Orientation
namespace Complex
attribute [local instance] Complex.finrank_real_complex_fact
@[simp]
protected theorem areaForm (w z : ℂ) : Complex.orientation.areaForm w z = (conj w * z).im := by
let o := Complex.orientation
simp only [o, o.areaForm_to_volumeForm,
o.volumeForm_robust Complex.orthonormalBasisOneI rfl, Basis.det_apply, Matrix.det_fin_two,
Basis.toMatrix_apply, toBasis_orthonormalBasisOneI, Matrix.cons_val_zero, coe_basisOneI_repr,
Matrix.cons_val_one, Matrix.head_cons, mul_im, conj_re, conj_im]
ring
@[simp]
protected theorem rightAngleRotation (z : ℂ) :
Complex.orientation.rightAngleRotation z = I * z := by
apply ext_inner_right ℝ
intro w
rw [Orientation.inner_rightAngleRotation_left]
simp only [Complex.areaForm, Complex.inner, mul_re, mul_im, conj_re, conj_im, map_mul, conj_I,
neg_re, neg_im, I_re, I_im]
ring
@[simp]
protected theorem kahler (w z : ℂ) : Complex.orientation.kahler w z = z * conj w := by
rw [Orientation.kahler_apply_apply]
apply Complex.ext <;> simp [mul_comm]
end Complex
namespace Orientation
local notation "ω" => o.areaForm
local notation "J" => o.rightAngleRotation
open Complex
-- Porting note: The instance `finrank_real_complex_fact` cannot be found by synthesis for
| -- `areaForm_map`, `rightAngleRotation_map` and `kahler_map` in the three theorems below,
-- so it has to be provided by unification (i.e. by naming the instance-implicit argument where
-- it belongs and using `(hF := _)`).
/-- The area form on an oriented real inner product space of dimension 2 can be evaluated in terms
| Mathlib/Analysis/InnerProductSpace/TwoDim.lean | 550 | 554 |
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Filippo A. E. Nuccio
-/
import Mathlib.Algebra.EuclideanDomain.Basic
import Mathlib.RingTheory.FractionalIdeal.Basic
import Mathlib.RingTheory.IntegralClosure.IsIntegral.Basic
import Mathlib.RingTheory.LocalRing.Basic
import Mathlib.RingTheory.PrincipalIdealDomain
import Mathlib.Tactic.FieldSimp
/-!
# More operations on fractional ideals
## Main definitions
* `map` is the pushforward of a fractional ideal along an algebra morphism
Let `K` be the localization of `R` at `R⁰ = R \ {0}` (i.e. the field of fractions).
* `FractionalIdeal R⁰ K` is the type of fractional ideals in the field of fractions
* `Div (FractionalIdeal R⁰ K)` instance:
the ideal quotient `I / J` (typically written $I : J$, but a `:` operator cannot be defined)
## Main statement
* `isNoetherian` states that every fractional ideal of a noetherian integral domain is noetherian
## References
* https://en.wikipedia.org/wiki/Fractional_ideal
## Tags
fractional ideal, fractional ideals, invertible ideal
-/
open IsLocalization Pointwise nonZeroDivisors
namespace FractionalIdeal
open Set Submodule
variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P]
variable [Algebra R P]
section
variable {P' : Type*} [CommRing P'] [Algebra R P']
variable {P'' : Type*} [CommRing P''] [Algebra R P'']
theorem _root_.IsFractional.map (g : P →ₐ[R] P') {I : Submodule R P} :
IsFractional S I → IsFractional S (Submodule.map g.toLinearMap I)
| ⟨a, a_nonzero, hI⟩ =>
⟨a, a_nonzero, fun b hb => by
obtain ⟨b', b'_mem, hb'⟩ := Submodule.mem_map.mp hb
rw [AlgHom.toLinearMap_apply] at hb'
obtain ⟨x, hx⟩ := hI b' b'_mem
use x
rw [← g.commutes, hx, map_smul, hb']⟩
/-- `I.map g` is the pushforward of the fractional ideal `I` along the algebra morphism `g` -/
def map (g : P →ₐ[R] P') : FractionalIdeal S P → FractionalIdeal S P' := fun I =>
⟨Submodule.map g.toLinearMap I, I.isFractional.map g⟩
@[simp, norm_cast]
theorem coe_map (g : P →ₐ[R] P') (I : FractionalIdeal S P) :
↑(map g I) = Submodule.map g.toLinearMap I :=
rfl
@[simp]
theorem mem_map {I : FractionalIdeal S P} {g : P →ₐ[R] P'} {y : P'} :
y ∈ I.map g ↔ ∃ x, x ∈ I ∧ g x = y :=
Submodule.mem_map
variable (I J : FractionalIdeal S P) (g : P →ₐ[R] P')
@[simp]
theorem map_id : I.map (AlgHom.id _ _) = I :=
coeToSubmodule_injective (Submodule.map_id (I : Submodule R P))
@[simp]
theorem map_comp (g' : P' →ₐ[R] P'') : I.map (g'.comp g) = (I.map g).map g' :=
coeToSubmodule_injective (Submodule.map_comp g.toLinearMap g'.toLinearMap I)
@[simp, norm_cast]
theorem map_coeIdeal (I : Ideal R) : (I : FractionalIdeal S P).map g = I := by
ext x
simp only [mem_coeIdeal]
constructor
· rintro ⟨_, ⟨y, hy, rfl⟩, rfl⟩
exact ⟨y, hy, (g.commutes y).symm⟩
· rintro ⟨y, hy, rfl⟩
exact ⟨_, ⟨y, hy, rfl⟩, g.commutes y⟩
@[simp]
protected theorem map_one : (1 : FractionalIdeal S P).map g = 1 :=
map_coeIdeal g ⊤
@[simp]
protected theorem map_zero : (0 : FractionalIdeal S P).map g = 0 :=
map_coeIdeal g 0
@[simp]
protected theorem map_add : (I + J).map g = I.map g + J.map g :=
coeToSubmodule_injective (Submodule.map_sup _ _ _)
@[simp]
protected theorem map_mul : (I * J).map g = I.map g * J.map g := by
simp only [mul_def]
exact coeToSubmodule_injective (Submodule.map_mul _ _ _)
@[simp]
theorem map_map_symm (g : P ≃ₐ[R] P') : (I.map (g : P →ₐ[R] P')).map (g.symm : P' →ₐ[R] P) = I := by
rw [← map_comp, g.symm_comp, map_id]
@[simp]
theorem map_symm_map (I : FractionalIdeal S P') (g : P ≃ₐ[R] P') :
(I.map (g.symm : P' →ₐ[R] P)).map (g : P →ₐ[R] P') = I := by
rw [← map_comp, g.comp_symm, map_id]
theorem map_mem_map {f : P →ₐ[R] P'} (h : Function.Injective f) {x : P} {I : FractionalIdeal S P} :
f x ∈ map f I ↔ x ∈ I :=
mem_map.trans ⟨fun ⟨_, hx', x'_eq⟩ => h x'_eq ▸ hx', fun h => ⟨x, h, rfl⟩⟩
theorem map_injective (f : P →ₐ[R] P') (h : Function.Injective f) :
Function.Injective (map f : FractionalIdeal S P → FractionalIdeal S P') := fun _ _ hIJ =>
ext fun _ => (map_mem_map h).symm.trans (hIJ.symm ▸ map_mem_map h)
/-- If `g` is an equivalence, `map g` is an isomorphism -/
def mapEquiv (g : P ≃ₐ[R] P') : FractionalIdeal S P ≃+* FractionalIdeal S P' where
toFun := map g
invFun := map g.symm
map_add' I J := FractionalIdeal.map_add I J _
map_mul' I J := FractionalIdeal.map_mul I J _
left_inv I := by rw [← map_comp, AlgEquiv.symm_comp, map_id]
right_inv I := by rw [← map_comp, AlgEquiv.comp_symm, map_id]
@[simp]
theorem coeFun_mapEquiv (g : P ≃ₐ[R] P') :
(mapEquiv g : FractionalIdeal S P → FractionalIdeal S P') = map g :=
rfl
@[simp]
theorem mapEquiv_apply (g : P ≃ₐ[R] P') (I : FractionalIdeal S P) : mapEquiv g I = map (↑g) I :=
rfl
@[simp]
theorem mapEquiv_symm (g : P ≃ₐ[R] P') :
((mapEquiv g).symm : FractionalIdeal S P' ≃+* _) = mapEquiv g.symm :=
rfl
@[simp]
theorem mapEquiv_refl : mapEquiv AlgEquiv.refl = RingEquiv.refl (FractionalIdeal S P) :=
RingEquiv.ext fun x => by simp
theorem isFractional_span_iff {s : Set P} :
IsFractional S (span R s) ↔ ∃ a ∈ S, ∀ b : P, b ∈ s → IsInteger R (a • b) :=
⟨fun ⟨a, a_mem, h⟩ => ⟨a, a_mem, fun b hb => h b (subset_span hb)⟩, fun ⟨a, a_mem, h⟩ =>
⟨a, a_mem, fun _ hb =>
span_induction (hx := hb) h
(by
rw [smul_zero]
exact isInteger_zero)
(fun x y _ _ hx hy => by
rw [smul_add]
exact isInteger_add hx hy)
fun s x _ hx => by
rw [smul_comm]
exact isInteger_smul hx⟩⟩
theorem isFractional_of_fg [IsLocalization S P] {I : Submodule R P} (hI : I.FG) :
IsFractional S I := by
rcases hI with ⟨I, rfl⟩
rcases exist_integer_multiples_of_finset S I with ⟨⟨s, hs1⟩, hs⟩
rw [isFractional_span_iff]
exact ⟨s, hs1, hs⟩
theorem mem_span_mul_finite_of_mem_mul {I J : FractionalIdeal S P} {x : P} (hx : x ∈ I * J) :
∃ T T' : Finset P, (T : Set P) ⊆ I ∧ (T' : Set P) ⊆ J ∧ x ∈ span R (T * T' : Set P) :=
Submodule.mem_span_mul_finite_of_mem_mul (by simpa using mem_coe.mpr hx)
variable (S) in
theorem coeIdeal_fg (inj : Function.Injective (algebraMap R P)) (I : Ideal R) :
FG ((I : FractionalIdeal S P) : Submodule R P) ↔ I.FG :=
coeSubmodule_fg _ inj _
theorem fg_unit (I : (FractionalIdeal S P)ˣ) : FG (I : Submodule R P) :=
Submodule.fg_unit <| Units.map (coeSubmoduleHom S P).toMonoidHom I
theorem fg_of_isUnit (I : FractionalIdeal S P) (h : IsUnit I) : FG (I : Submodule R P) :=
fg_unit h.unit
theorem _root_.Ideal.fg_of_isUnit (inj : Function.Injective (algebraMap R P)) (I : Ideal R)
(h : IsUnit (I : FractionalIdeal S P)) : I.FG := by
rw [← coeIdeal_fg S inj I]
exact FractionalIdeal.fg_of_isUnit (R := R) I h
variable (S P P')
variable [IsLocalization S P] [IsLocalization S P']
/-- `canonicalEquiv f f'` is the canonical equivalence between the fractional
ideals in `P` and in `P'`, which are both localizations of `R` at `S`. -/
noncomputable irreducible_def canonicalEquiv : FractionalIdeal S P ≃+* FractionalIdeal S P' :=
mapEquiv
{ ringEquivOfRingEquiv P P' (RingEquiv.refl R)
(show S.map _ = S by rw [RingEquiv.toMonoidHom_refl, Submonoid.map_id]) with
commutes' := fun _ => ringEquivOfRingEquiv_eq _ _ }
@[simp]
theorem mem_canonicalEquiv_apply {I : FractionalIdeal S P} {x : P'} :
x ∈ canonicalEquiv S P P' I ↔
∃ y ∈ I,
IsLocalization.map P' (RingHom.id R) (fun y (hy : y ∈ S) => show RingHom.id R y ∈ S from hy)
(y : P) =
x := by
rw [canonicalEquiv, mapEquiv_apply, mem_map]
exact ⟨fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩, fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩⟩
@[simp]
theorem canonicalEquiv_symm : (canonicalEquiv S P P').symm = canonicalEquiv S P' P :=
RingEquiv.ext fun I =>
SetLike.ext_iff.mpr fun x => by
rw [mem_canonicalEquiv_apply, canonicalEquiv, mapEquiv_symm, mapEquiv_apply,
mem_map]
exact ⟨fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩, fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩⟩
theorem canonicalEquiv_flip (I) : canonicalEquiv S P P' (canonicalEquiv S P' P I) = I := by
rw [← canonicalEquiv_symm, RingEquiv.symm_apply_apply]
@[simp]
theorem canonicalEquiv_canonicalEquiv (P'' : Type*) [CommRing P''] [Algebra R P'']
[IsLocalization S P''] (I : FractionalIdeal S P) :
canonicalEquiv S P' P'' (canonicalEquiv S P P' I) = canonicalEquiv S P P'' I := by
ext
simp only [IsLocalization.map_map, RingHomInvPair.comp_eq₂, mem_canonicalEquiv_apply,
exists_prop, exists_exists_and_eq_and]
theorem canonicalEquiv_trans_canonicalEquiv (P'' : Type*) [CommRing P''] [Algebra R P'']
[IsLocalization S P''] :
(canonicalEquiv S P P').trans (canonicalEquiv S P' P'') = canonicalEquiv S P P'' :=
RingEquiv.ext (canonicalEquiv_canonicalEquiv S P P' P'')
@[simp]
theorem canonicalEquiv_coeIdeal (I : Ideal R) : canonicalEquiv S P P' I = I := by
ext
simp [IsLocalization.map_eq]
@[simp]
theorem canonicalEquiv_self : canonicalEquiv S P P = RingEquiv.refl _ := by
rw [← canonicalEquiv_trans_canonicalEquiv S P P]
convert (canonicalEquiv S P P).symm_trans_self
exact (canonicalEquiv_symm S P P).symm
end
section IsFractionRing
/-!
### `IsFractionRing` section
This section concerns fractional ideals in the field of fractions,
i.e. the type `FractionalIdeal R⁰ K` where `IsFractionRing R K`.
-/
variable {K K' : Type*} [Field K] [Field K']
variable [Algebra R K] [IsFractionRing R K] [Algebra R K'] [IsFractionRing R K']
variable {I J : FractionalIdeal R⁰ K} (h : K →ₐ[R] K')
/-- Nonzero fractional ideals contain a nonzero integer. -/
theorem exists_ne_zero_mem_isInteger [Nontrivial R] (hI : I ≠ 0) :
∃ x, x ≠ 0 ∧ algebraMap R K x ∈ I := by
obtain ⟨y : K, y_mem, y_not_mem⟩ :=
SetLike.exists_of_lt (by simpa only using bot_lt_iff_ne_bot.mpr hI)
have y_ne_zero : y ≠ 0 := by simpa using y_not_mem
obtain ⟨z, ⟨x, hx⟩⟩ := exists_integer_multiple R⁰ y
refine ⟨x, ?_, ?_⟩
· rw [Ne, ← @IsFractionRing.to_map_eq_zero_iff R _ K, hx, Algebra.smul_def]
exact mul_ne_zero (IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors z.2) y_ne_zero
· rw [hx]
exact smul_mem _ _ y_mem
theorem map_ne_zero [Nontrivial R] (hI : I ≠ 0) : I.map h ≠ 0 := by
obtain ⟨x, x_ne_zero, hx⟩ := exists_ne_zero_mem_isInteger hI
contrapose! x_ne_zero with map_eq_zero
refine IsFractionRing.to_map_eq_zero_iff.mp (eq_zero_iff.mp map_eq_zero _ (mem_map.mpr ?_))
exact ⟨algebraMap R K x, hx, h.commutes x⟩
@[simp]
theorem map_eq_zero_iff [Nontrivial R] : I.map h = 0 ↔ I = 0 :=
⟨not_imp_not.mp (map_ne_zero _), fun hI => hI.symm ▸ FractionalIdeal.map_zero h⟩
theorem coeIdeal_injective : Function.Injective (fun (I : Ideal R) ↦ (I : FractionalIdeal R⁰ K)) :=
coeIdeal_injective' le_rfl
theorem coeIdeal_inj {I J : Ideal R} :
(I : FractionalIdeal R⁰ K) = (J : FractionalIdeal R⁰ K) ↔ I = J :=
coeIdeal_inj' le_rfl
@[simp]
theorem coeIdeal_eq_zero {I : Ideal R} : (I : FractionalIdeal R⁰ K) = 0 ↔ I = ⊥ :=
coeIdeal_eq_zero' le_rfl
theorem coeIdeal_ne_zero {I : Ideal R} : (I : FractionalIdeal R⁰ K) ≠ 0 ↔ I ≠ ⊥ :=
coeIdeal_ne_zero' le_rfl
@[simp]
theorem coeIdeal_eq_one {I : Ideal R} : (I : FractionalIdeal R⁰ K) = 1 ↔ I = 1 := by
simpa only [Ideal.one_eq_top] using coeIdeal_inj
theorem coeIdeal_ne_one {I : Ideal R} : (I : FractionalIdeal R⁰ K) ≠ 1 ↔ I ≠ 1 :=
not_iff_not.mpr coeIdeal_eq_one
theorem num_eq_zero_iff [Nontrivial R] {I : FractionalIdeal R⁰ K} : I.num = 0 ↔ I = 0 :=
⟨fun h ↦ zero_of_num_eq_bot zero_not_mem_nonZeroDivisors h,
fun h ↦ h ▸ num_zero_eq (IsFractionRing.injective R K)⟩
end IsFractionRing
section Quotient
/-!
### `quotient` section
This section defines the ideal quotient of fractional ideals.
In this section we need that each non-zero `y : R` has an inverse in
the localization, i.e. that the localization is a field. We satisfy this
assumption by taking `S = nonZeroDivisors R`, `R`'s localization at which
is a field because `R` is a domain.
-/
variable {R₁ : Type*} [CommRing R₁] {K : Type*} [Field K]
variable [Algebra R₁ K]
instance : Nontrivial (FractionalIdeal R₁⁰ K) :=
⟨⟨0, 1, fun h =>
have this : (1 : K) ∈ (0 : FractionalIdeal R₁⁰ K) := by
rw [← (algebraMap R₁ K).map_one]
simpa only [h] using coe_mem_one R₁⁰ 1
one_ne_zero ((mem_zero_iff _).mp this)⟩⟩
theorem ne_zero_of_mul_eq_one (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) : I ≠ 0 := fun hI =>
zero_ne_one' (FractionalIdeal R₁⁰ K)
(by
convert h
simp [hI])
variable [IsFractionRing R₁ K] [IsDomain R₁]
theorem _root_.IsFractional.div_of_nonzero {I J : Submodule R₁ K} :
IsFractional R₁⁰ I → IsFractional R₁⁰ J → J ≠ 0 → IsFractional R₁⁰ (I / J)
| ⟨aI, haI, hI⟩, ⟨aJ, haJ, hJ⟩, h => by
obtain ⟨y, mem_J, not_mem_zero⟩ :=
SetLike.exists_of_lt (show 0 < J by simpa only using bot_lt_iff_ne_bot.mpr h)
obtain ⟨y', hy'⟩ := hJ y mem_J
use aI * y'
constructor
· apply (nonZeroDivisors R₁).mul_mem haI (mem_nonZeroDivisors_iff_ne_zero.mpr _)
intro y'_eq_zero
have : algebraMap R₁ K aJ * y = 0 := by
rw [← Algebra.smul_def, ← hy', y'_eq_zero, RingHom.map_zero]
have y_zero :=
(mul_eq_zero.mp this).resolve_left
(mt ((injective_iff_map_eq_zero (algebraMap R₁ K)).1 (IsFractionRing.injective _ _) _)
(mem_nonZeroDivisors_iff_ne_zero.mp haJ))
apply not_mem_zero
simpa
intro b hb
convert hI _ (hb _ (Submodule.smul_mem _ aJ mem_J)) using 1
rw [← hy', mul_comm b, ← Algebra.smul_def, mul_smul]
theorem fractional_div_of_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) :
IsFractional R₁⁰ (I / J : Submodule R₁ K) :=
I.isFractional.div_of_nonzero J.isFractional fun H =>
h <| coeToSubmodule_injective <| H.trans coe_zero.symm
open Classical in
noncomputable instance : Div (FractionalIdeal R₁⁰ K) :=
⟨fun I J => if h : J = 0 then 0 else ⟨I / J, fractional_div_of_nonzero h⟩⟩
variable {I J : FractionalIdeal R₁⁰ K}
@[simp]
theorem div_zero {I : FractionalIdeal R₁⁰ K} : I / 0 = 0 :=
dif_pos rfl
theorem div_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) :
I / J = ⟨I / J, fractional_div_of_nonzero h⟩ :=
dif_neg h
@[simp]
theorem coe_div {I J : FractionalIdeal R₁⁰ K} (hJ : J ≠ 0) :
(↑(I / J) : Submodule R₁ K) = ↑I / (↑J : Submodule R₁ K) :=
congr_arg _ (dif_neg hJ)
theorem mem_div_iff_of_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) {x} :
x ∈ I / J ↔ ∀ y ∈ J, x * y ∈ I := by
rw [div_nonzero h]
exact Submodule.mem_div_iff_forall_mul_mem
theorem mul_one_div_le_one {I : FractionalIdeal R₁⁰ K} : I * (1 / I) ≤ 1 := by
by_cases hI : I = 0
· rw [hI, div_zero, mul_zero]
exact zero_le 1
· rw [← coe_le_coe, coe_mul, coe_div hI, coe_one]
apply Submodule.mul_one_div_le_one
theorem le_self_mul_one_div {I : FractionalIdeal R₁⁰ K} (hI : I ≤ (1 : FractionalIdeal R₁⁰ K)) :
I ≤ I * (1 / I) := by
by_cases hI_nz : I = 0
· rw [hI_nz, div_zero, mul_zero]
· rw [← coe_le_coe, coe_mul, coe_div hI_nz, coe_one]
rw [← coe_le_coe, coe_one] at hI
exact Submodule.le_self_mul_one_div hI
theorem le_div_iff_of_nonzero {I J J' : FractionalIdeal R₁⁰ K} (hJ' : J' ≠ 0) :
I ≤ J / J' ↔ ∀ x ∈ I, ∀ y ∈ J', x * y ∈ J :=
⟨fun h _ hx => (mem_div_iff_of_nonzero hJ').mp (h hx), fun h x hx =>
(mem_div_iff_of_nonzero hJ').mpr (h x hx)⟩
theorem le_div_iff_mul_le {I J J' : FractionalIdeal R₁⁰ K} (hJ' : J' ≠ 0) :
I ≤ J / J' ↔ I * J' ≤ J := by
rw [div_nonzero hJ']
-- Porting note: this used to be { convert; rw }, flipped the order.
rw [← coe_le_coe (I := I * J') (J := J), coe_mul]
exact Submodule.le_div_iff_mul_le
@[simp]
theorem div_one {I : FractionalIdeal R₁⁰ K} : I / 1 = I := by
rw [div_nonzero (one_ne_zero' (FractionalIdeal R₁⁰ K))]
ext
constructor <;> intro h
· simpa using mem_div_iff_forall_mul_mem.mp h 1 ((algebraMap R₁ K).map_one ▸ coe_mem_one R₁⁰ 1)
· apply mem_div_iff_forall_mul_mem.mpr
rintro y ⟨y', _, rfl⟩
-- Porting note: this used to be { convert; rw }, flipped the order.
rw [mul_comm, Algebra.linearMap_apply, ← Algebra.smul_def]
exact Submodule.smul_mem _ y' h
theorem eq_one_div_of_mul_eq_one_right (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) :
J = 1 / I := by
have hI : I ≠ 0 := ne_zero_of_mul_eq_one I J h
suffices h' : I * (1 / I) = 1 from
congr_arg Units.inv <| @Units.ext _ _ (Units.mkOfMulEqOne _ _ h) (Units.mkOfMulEqOne _ _ h') rfl
apply le_antisymm
· apply mul_le.mpr _
intro x hx y hy
rw [mul_comm]
exact (mem_div_iff_of_nonzero hI).mp hy x hx
rw [← h]
apply mul_left_mono I
apply (le_div_iff_of_nonzero hI).mpr _
intro y hy x hx
rw [mul_comm]
exact mul_mem_mul hy hx
theorem mul_div_self_cancel_iff {I : FractionalIdeal R₁⁰ K} : I * (1 / I) = 1 ↔ ∃ J, I * J = 1 :=
⟨fun h => ⟨1 / I, h⟩, fun ⟨J, hJ⟩ => by rwa [← eq_one_div_of_mul_eq_one_right I J hJ]⟩
variable {K' : Type*} [Field K'] [Algebra R₁ K'] [IsFractionRing R₁ K']
@[simp]
protected theorem map_div (I J : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') :
(I / J).map (h : K →ₐ[R₁] K') = I.map h / J.map h := by
by_cases H : J = 0
· rw [H, div_zero, FractionalIdeal.map_zero, div_zero]
· -- Porting note: `simp` wouldn't apply these lemmas so do them manually using `rw`
rw [← coeToSubmodule_inj, div_nonzero H, div_nonzero (map_ne_zero _ H)]
simp [Submodule.map_div]
-- Porting note: doesn't need to be @[simp] because this follows from `map_one` and `map_div`
theorem map_one_div (I : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') :
(1 / I).map (h : K →ₐ[R₁] K') = 1 / I.map h := by
rw [FractionalIdeal.map_div, FractionalIdeal.map_one]
end Quotient
section Field
variable {R₁ K L : Type*} [CommRing R₁] [Field K] [Field L]
variable [Algebra R₁ K] [IsFractionRing R₁ K] [Algebra K L] [IsFractionRing K L]
theorem eq_zero_or_one (I : FractionalIdeal K⁰ L) : I = 0 ∨ I = 1 := by
rw [or_iff_not_imp_left]
intro hI
simp_rw [@SetLike.ext_iff _ _ _ I 1, mem_one_iff]
intro x
constructor
· intro x_mem
obtain ⟨n, d, rfl⟩ := IsLocalization.mk'_surjective K⁰ x
refine ⟨n / d, ?_⟩
rw [map_div₀, IsFractionRing.mk'_eq_div]
· rintro ⟨x, rfl⟩
obtain ⟨y, y_ne, y_mem⟩ := exists_ne_zero_mem_isInteger hI
rw [← div_mul_cancel₀ x y_ne, RingHom.map_mul, ← Algebra.smul_def]
exact smul_mem (M := L) I (x / y) y_mem
theorem eq_zero_or_one_of_isField (hF : IsField R₁) (I : FractionalIdeal R₁⁰ K) : I = 0 ∨ I = 1 :=
letI : Field R₁ := hF.toField
eq_zero_or_one I
end Field
section PrincipalIdeal
variable {R₁ : Type*} [CommRing R₁] {K : Type*} [Field K]
variable [Algebra R₁ K] [IsFractionRing R₁ K]
variable (R₁)
/-- `FractionalIdeal.span_finset R₁ s f` is the fractional ideal of `R₁` generated by `f '' s`. -/
-- Porting note: `@[simps]` generated a `Subtype.val` coercion instead of a
-- `FractionalIdeal.coeToSubmodule` coercion
def spanFinset {ι : Type*} (s : Finset ι) (f : ι → K) : FractionalIdeal R₁⁰ K :=
⟨Submodule.span R₁ (f '' s), by
obtain ⟨a', ha'⟩ := IsLocalization.exist_integer_multiples R₁⁰ s f
refine ⟨a', a'.2, fun x hx => Submodule.span_induction ?_ ?_ ?_ ?_ hx⟩
· rintro _ ⟨i, hi, rfl⟩
exact ha' i hi
· rw [smul_zero]
exact IsLocalization.isInteger_zero
· intro x y _ _ hx hy
rw [smul_add]
exact IsLocalization.isInteger_add hx hy
· intro c x _ hx
rw [smul_comm]
exact IsLocalization.isInteger_smul hx⟩
@[simp] lemma spanFinset_coe {ι : Type*} (s : Finset ι) (f : ι → K) :
(spanFinset R₁ s f : Submodule R₁ K) = Submodule.span R₁ (f '' s) :=
rfl
variable {R₁}
@[simp]
theorem spanFinset_eq_zero {ι : Type*} {s : Finset ι} {f : ι → K} :
spanFinset R₁ s f = 0 ↔ ∀ j ∈ s, f j = 0 := by
simp only [← coeToSubmodule_inj, spanFinset_coe, coe_zero, Submodule.span_eq_bot,
Set.mem_image, Finset.mem_coe, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂]
theorem spanFinset_ne_zero {ι : Type*} {s : Finset ι} {f : ι → K} :
spanFinset R₁ s f ≠ 0 ↔ ∃ j ∈ s, f j ≠ 0 := by simp
open Submodule.IsPrincipal
variable [IsLocalization S P]
theorem isFractional_span_singleton (x : P) : IsFractional S (span R {x} : Submodule R P) :=
let ⟨a, ha⟩ := exists_integer_multiple S x
isFractional_span_iff.mpr ⟨a, a.2, fun _ hx' => (Set.mem_singleton_iff.mp hx').symm ▸ ha⟩
variable (S)
/-- `spanSingleton x` is the fractional ideal generated by `x` if `0 ∉ S` -/
irreducible_def spanSingleton (x : P) : FractionalIdeal S P :=
⟨span R {x}, isFractional_span_singleton x⟩
-- local attribute [semireducible] span_singleton
@[simp]
theorem coe_spanSingleton (x : P) : (spanSingleton S x : Submodule R P) = span R {x} := by
rw [spanSingleton]
rfl
@[simp]
theorem mem_spanSingleton {x y : P} : x ∈ spanSingleton S y ↔ ∃ z : R, z • y = x := by
rw [spanSingleton]
exact Submodule.mem_span_singleton
theorem mem_spanSingleton_self (x : P) : x ∈ spanSingleton S x :=
(mem_spanSingleton S).mpr ⟨1, one_smul _ _⟩
variable (P) in
/-- A version of `FractionalIdeal.den_mul_self_eq_num` in terms of fractional ideals. -/
theorem den_mul_self_eq_num' (I : FractionalIdeal S P) :
spanSingleton S (algebraMap R P I.den) * I = I.num := by
apply coeToSubmodule_injective
dsimp only
rw [coe_mul, ← smul_eq_mul, coe_spanSingleton, smul_eq_mul, Submodule.span_singleton_mul]
convert I.den_mul_self_eq_num using 1
ext
rw [mem_smul_pointwise_iff_exists, mem_smul_pointwise_iff_exists]
simp [smul_eq_mul, Algebra.smul_def, Submonoid.smul_def]
variable {S}
@[simp]
theorem spanSingleton_le_iff_mem {x : P} {I : FractionalIdeal S P} :
spanSingleton S x ≤ I ↔ x ∈ I := by
rw [← coe_le_coe, coe_spanSingleton, Submodule.span_singleton_le_iff_mem, mem_coe]
theorem spanSingleton_eq_spanSingleton [NoZeroSMulDivisors R P] {x y : P} :
spanSingleton S x = spanSingleton S y ↔ ∃ z : Rˣ, z • x = y := by
rw [← Submodule.span_singleton_eq_span_singleton, spanSingleton, spanSingleton]
exact Subtype.mk_eq_mk
theorem eq_spanSingleton_of_principal (I : FractionalIdeal S P) [IsPrincipal (I : Submodule R P)] :
I = spanSingleton S (generator (I : Submodule R P)) := by
-- Porting note: this used to be `coeToSubmodule_injective (span_singleton_generator ↑I).symm`
-- but Lean 4 struggled to unify everything. Turned it into an explicit `rw`.
rw [spanSingleton, ← coeToSubmodule_inj, coe_mk, span_singleton_generator]
theorem isPrincipal_iff (I : FractionalIdeal S P) :
IsPrincipal (I : Submodule R P) ↔ ∃ x, I = spanSingleton S x :=
⟨fun _ => ⟨generator (I : Submodule R P), eq_spanSingleton_of_principal I⟩,
fun ⟨x, hx⟩ => { principal := ⟨x, Eq.trans (congr_arg _ hx) (coe_spanSingleton _ x)⟩ }⟩
@[simp]
theorem spanSingleton_zero : spanSingleton S (0 : P) = 0 := by
ext
simp [Submodule.mem_span_singleton, eq_comm]
theorem spanSingleton_eq_zero_iff {y : P} : spanSingleton S y = 0 ↔ y = 0 :=
⟨fun h =>
span_eq_bot.mp (by simpa using congr_arg Subtype.val h : span R {y} = ⊥) y (mem_singleton y),
fun h => by simp [h]⟩
theorem spanSingleton_ne_zero_iff {y : P} : spanSingleton S y ≠ 0 ↔ y ≠ 0 :=
not_congr spanSingleton_eq_zero_iff
@[simp]
theorem spanSingleton_one : spanSingleton S (1 : P) = 1 := by
ext
refine (mem_spanSingleton S).trans ((exists_congr ?_).trans (mem_one_iff S).symm)
intro x'
rw [Algebra.smul_def, mul_one]
@[simp]
theorem spanSingleton_mul_spanSingleton (x y : P) :
spanSingleton S x * spanSingleton S y = spanSingleton S (x * y) := by
apply coeToSubmodule_injective
simp only [coe_mul, coe_spanSingleton, span_mul_span, singleton_mul_singleton]
@[simp]
theorem spanSingleton_pow (x : P) (n : ℕ) : spanSingleton S x ^ n = spanSingleton S (x ^ n) := by
induction' n with n hn
· rw [pow_zero, pow_zero, spanSingleton_one]
· rw [pow_succ, hn, spanSingleton_mul_spanSingleton, pow_succ]
@[simp]
theorem coeIdeal_span_singleton (x : R) :
(↑(Ideal.span {x} : Ideal R) : FractionalIdeal S P) = spanSingleton S (algebraMap R P x) := by
ext y
refine (mem_coeIdeal S).trans (Iff.trans ?_ (mem_spanSingleton S).symm)
constructor
· rintro ⟨y', hy', rfl⟩
obtain ⟨x', rfl⟩ := Submodule.mem_span_singleton.mp hy'
use x'
rw [smul_eq_mul, RingHom.map_mul, Algebra.smul_def]
· rintro ⟨y', rfl⟩
refine ⟨y' * x, Submodule.mem_span_singleton.mpr ⟨y', rfl⟩, ?_⟩
rw [RingHom.map_mul, Algebra.smul_def]
@[simp]
theorem canonicalEquiv_spanSingleton {P'} [CommRing P'] [Algebra R P'] [IsLocalization S P']
(x : P) :
canonicalEquiv S P P' (spanSingleton S x) =
spanSingleton S
(IsLocalization.map P' (RingHom.id R)
(fun y (hy : y ∈ S) => show RingHom.id R y ∈ S from hy) x) := by
apply SetLike.ext_iff.mpr
intro y
constructor <;> intro h
· rw [mem_spanSingleton]
obtain ⟨x', hx', rfl⟩ := (mem_canonicalEquiv_apply _ _ _).mp h
obtain ⟨z, rfl⟩ := (mem_spanSingleton _).mp hx'
use z
rw [IsLocalization.map_smul, RingHom.id_apply]
· rw [mem_canonicalEquiv_apply]
obtain ⟨z, rfl⟩ := (mem_spanSingleton _).mp h
use z • x
use (mem_spanSingleton _).mpr ⟨z, rfl⟩
simp [IsLocalization.map_smul]
theorem mem_singleton_mul {x y : P} {I : FractionalIdeal S P} :
y ∈ spanSingleton S x * I ↔ ∃ y' ∈ I, y = x * y' := by
constructor
· intro h
refine FractionalIdeal.mul_induction_on h ?_ ?_
· intro x' hx' y' hy'
obtain ⟨a, ha⟩ := (mem_spanSingleton S).mp hx'
use a • y', Submodule.smul_mem (I : Submodule R P) a hy'
rw [← ha, Algebra.mul_smul_comm, Algebra.smul_mul_assoc]
· rintro _ _ ⟨y, hy, rfl⟩ ⟨y', hy', rfl⟩
exact ⟨y + y', Submodule.add_mem (I : Submodule R P) hy hy', (mul_add _ _ _).symm⟩
· rintro ⟨y', hy', rfl⟩
exact mul_mem_mul ((mem_spanSingleton S).mpr ⟨1, one_smul _ _⟩) hy'
variable (K) in
theorem mk'_mul_coeIdeal_eq_coeIdeal {I J : Ideal R₁} {x y : R₁} (hy : y ∈ R₁⁰) :
spanSingleton R₁⁰ (IsLocalization.mk' K x ⟨y, hy⟩) * I = (J : FractionalIdeal R₁⁰ K) ↔
Ideal.span {x} * I = Ideal.span {y} * J := by
have :
spanSingleton R₁⁰ (IsLocalization.mk' _ (1 : R₁) ⟨y, hy⟩) *
spanSingleton R₁⁰ (algebraMap R₁ K y) =
1 := by
rw [spanSingleton_mul_spanSingleton, mul_comm, ← IsLocalization.mk'_eq_mul_mk'_one,
IsLocalization.mk'_self, spanSingleton_one]
let y' : (FractionalIdeal R₁⁰ K)ˣ := Units.mkOfMulEqOne _ _ this
have coe_y' : ↑y' = spanSingleton R₁⁰ (IsLocalization.mk' K (1 : R₁) ⟨y, hy⟩) := rfl
refine Iff.trans ?_ (y'.mul_right_inj.trans coeIdeal_inj)
rw [coe_y', coeIdeal_mul, coeIdeal_span_singleton, coeIdeal_mul, coeIdeal_span_singleton, ←
mul_assoc, spanSingleton_mul_spanSingleton, ← mul_assoc, spanSingleton_mul_spanSingleton,
mul_comm (mk' _ _ _), ← IsLocalization.mk'_eq_mul_mk'_one, mul_comm (mk' _ _ _), ←
IsLocalization.mk'_eq_mul_mk'_one, IsLocalization.mk'_self, spanSingleton_one, one_mul]
theorem spanSingleton_mul_coeIdeal_eq_coeIdeal {I J : Ideal R₁} {z : K} :
spanSingleton R₁⁰ z * (I : FractionalIdeal R₁⁰ K) = J ↔
Ideal.span {((IsLocalization.sec R₁⁰ z).1 : R₁)} * I =
Ideal.span {((IsLocalization.sec R₁⁰ z).2 : R₁)} * J := by
rw [← mk'_mul_coeIdeal_eq_coeIdeal K (IsLocalization.sec R₁⁰ z).2.prop,
IsLocalization.mk'_sec K z]
|
variable [IsDomain R₁]
theorem one_div_spanSingleton (x : K) : 1 / spanSingleton R₁⁰ x = spanSingleton R₁⁰ x⁻¹ := by
| Mathlib/RingTheory/FractionalIdeal/Operations.lean | 715 | 718 |
/-
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, Yury Kudryashov
-/
import Mathlib.Data.Finite.Prod
import Mathlib.Data.Fintype.Pi
import Mathlib.Data.Set.Finite.Lemmas
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Order.Filter.CountablyGenerated
import Mathlib.Order.Filter.Ker
import Mathlib.Order.Filter.Pi
import Mathlib.Order.Filter.Prod
import Mathlib.Order.Filter.AtTopBot.Basic
/-!
# The cofinite filter
In this file we define
`Filter.cofinite`: the filter of sets with finite complement
and prove its basic properties. In particular, we prove that for `ℕ` it is equal to `Filter.atTop`.
## TODO
Define filters for other cardinalities of the complement.
-/
open Set Function
variable {ι α β : Type*} {l : Filter α}
namespace Filter
/-- The cofinite filter is the filter of subsets whose complements are finite. -/
def cofinite : Filter α :=
comk Set.Finite finite_empty (fun _t ht _s hsub ↦ ht.subset hsub) fun _ h _ ↦ h.union
@[simp]
theorem mem_cofinite {s : Set α} : s ∈ @cofinite α ↔ sᶜ.Finite :=
Iff.rfl
@[simp]
theorem eventually_cofinite {p : α → Prop} : (∀ᶠ x in cofinite, p x) ↔ { x | ¬p x }.Finite :=
Iff.rfl
theorem hasBasis_cofinite : HasBasis cofinite (fun s : Set α => s.Finite) compl :=
⟨fun s =>
⟨fun h => ⟨sᶜ, h, (compl_compl s).subset⟩, fun ⟨_t, htf, hts⟩ =>
htf.subset <| compl_subset_comm.2 hts⟩⟩
instance cofinite_neBot [Infinite α] : NeBot (@cofinite α) :=
hasBasis_cofinite.neBot_iff.2 fun hs => hs.infinite_compl.nonempty
@[simp]
theorem cofinite_eq_bot_iff : @cofinite α = ⊥ ↔ Finite α := by
simp [← empty_mem_iff_bot, finite_univ_iff]
@[simp]
theorem cofinite_eq_bot [Finite α] : @cofinite α = ⊥ := cofinite_eq_bot_iff.2 ‹_›
theorem frequently_cofinite_iff_infinite {p : α → Prop} :
(∃ᶠ x in cofinite, p x) ↔ Set.Infinite { x | p x } := by
simp only [Filter.Frequently, eventually_cofinite, not_not, Set.Infinite]
lemma frequently_cofinite_mem_iff_infinite {s : Set α} : (∃ᶠ x in cofinite, x ∈ s) ↔ s.Infinite :=
frequently_cofinite_iff_infinite
alias ⟨_, _root_.Set.Infinite.frequently_cofinite⟩ := frequently_cofinite_mem_iff_infinite
@[simp]
lemma cofinite_inf_principal_neBot_iff {s : Set α} : (cofinite ⊓ 𝓟 s).NeBot ↔ s.Infinite :=
frequently_mem_iff_neBot.symm.trans frequently_cofinite_mem_iff_infinite
alias ⟨_, _root_.Set.Infinite.cofinite_inf_principal_neBot⟩ := cofinite_inf_principal_neBot_iff
theorem _root_.Set.Finite.compl_mem_cofinite {s : Set α} (hs : s.Finite) : sᶜ ∈ @cofinite α :=
mem_cofinite.2 <| (compl_compl s).symm ▸ hs
theorem _root_.Set.Finite.eventually_cofinite_nmem {s : Set α} (hs : s.Finite) :
∀ᶠ x in cofinite, x ∉ s :=
hs.compl_mem_cofinite
theorem _root_.Finset.eventually_cofinite_nmem (s : Finset α) : ∀ᶠ x in cofinite, x ∉ s :=
s.finite_toSet.eventually_cofinite_nmem
theorem _root_.Set.infinite_iff_frequently_cofinite {s : Set α} :
Set.Infinite s ↔ ∃ᶠ x in cofinite, x ∈ s :=
frequently_cofinite_iff_infinite.symm
theorem eventually_cofinite_ne (x : α) : ∀ᶠ a in cofinite, a ≠ x :=
(Set.finite_singleton x).eventually_cofinite_nmem
theorem le_cofinite_iff_compl_singleton_mem : l ≤ cofinite ↔ ∀ x, {x}ᶜ ∈ l := by
refine ⟨fun h x => h (finite_singleton x).compl_mem_cofinite, fun h s (hs : sᶜ.Finite) => ?_⟩
rw [← compl_compl s, ← biUnion_of_singleton sᶜ, compl_iUnion₂, Filter.biInter_mem hs]
exact fun x _ => h x
theorem le_cofinite_iff_eventually_ne : l ≤ cofinite ↔ ∀ x, ∀ᶠ y in l, y ≠ x :=
le_cofinite_iff_compl_singleton_mem
/-- If `α` is a preorder with no top element, then `atTop ≤ cofinite`. -/
theorem atTop_le_cofinite [Preorder α] [NoTopOrder α] : (atTop : Filter α) ≤ cofinite :=
le_cofinite_iff_eventually_ne.mpr eventually_ne_atTop
/-- If `α` is a preorder with no bottom element, then `atBot ≤ cofinite`. -/
theorem atBot_le_cofinite [Preorder α] [NoBotOrder α] : (atBot : Filter α) ≤ cofinite :=
le_cofinite_iff_eventually_ne.mpr eventually_ne_atBot
theorem comap_cofinite_le (f : α → β) : comap f cofinite ≤ cofinite :=
le_cofinite_iff_eventually_ne.mpr fun x =>
mem_comap.2 ⟨{f x}ᶜ, (finite_singleton _).compl_mem_cofinite, fun _ => ne_of_apply_ne f⟩
/-- The coproduct of the cofinite filters on two types is the cofinite filter on their product. -/
theorem coprod_cofinite : (cofinite : Filter α).coprod (cofinite : Filter β) = cofinite :=
Filter.coext fun s => by
simp only [compl_mem_coprod, mem_cofinite, compl_compl, finite_image_fst_and_snd_iff]
theorem coprodᵢ_cofinite {α : ι → Type*} [Finite ι] :
(Filter.coprodᵢ fun i => (cofinite : Filter (α i))) = cofinite :=
Filter.coext fun s => by
simp only [compl_mem_coprodᵢ, mem_cofinite, compl_compl, forall_finite_image_eval_iff]
theorem disjoint_cofinite_left : Disjoint cofinite l ↔ ∃ s ∈ l, Set.Finite s := by
simp [l.basis_sets.disjoint_iff_right]
theorem disjoint_cofinite_right : Disjoint l cofinite ↔ ∃ s ∈ l, Set.Finite s :=
disjoint_comm.trans disjoint_cofinite_left
/-- If `l ≥ Filter.cofinite` is a countably generated filter, then `l.ker` is cocountable. -/
theorem countable_compl_ker [l.IsCountablyGenerated] (h : cofinite ≤ l) : Set.Countable l.kerᶜ := by
rcases exists_antitone_basis l with ⟨s, hs⟩
simp only [hs.ker, iInter_true, compl_iInter]
exact countable_iUnion fun n ↦ Set.Finite.countable <| h <| hs.mem _
/-- If `f` tends to a countably generated filter `l` along `Filter.cofinite`,
then for all but countably many elements, `f x ∈ l.ker`. -/
theorem Tendsto.countable_compl_preimage_ker {f : α → β}
{l : Filter β} [l.IsCountablyGenerated] (h : Tendsto f cofinite l) :
Set.Countable (f ⁻¹' l.ker)ᶜ := by rw [← ker_comap]; exact countable_compl_ker h.le_comap
/-- Given a collection of filters `l i : Filter (α i)` and sets `s i ∈ l i`,
if all but finitely many of `s i` are the whole space,
then their indexed product `Set.pi Set.univ s` belongs to the filter `Filter.pi l`. -/
theorem univ_pi_mem_pi {α : ι → Type*} {s : ∀ i, Set (α i)} {l : ∀ i, Filter (α i)}
(h : ∀ i, s i ∈ l i) (hfin : ∀ᶠ i in cofinite, s i = univ) : univ.pi s ∈ pi l := by
filter_upwards [pi_mem_pi hfin fun i _ ↦ h i] with a ha i _
if hi : s i = univ then
simp [hi]
else
exact ha i hi
/-- Given a family of maps `f i : α i → β i` and a family of filters `l i : Filter (α i)`,
if all but finitely many of `f i` are surjective,
then the indexed product of `f i`s maps the indexed product of the filters `l i`
to the indexed products of their pushforwards under individual `f i`s.
See also `map_piMap_pi_finite` for the case of a finite index type.
-/
theorem map_piMap_pi {α β : ι → Type*} {f : ∀ i, α i → β i}
(hf : ∀ᶠ i in cofinite, Surjective (f i)) (l : ∀ i, Filter (α i)) :
map (Pi.map f) (pi l) = pi fun i ↦ map (f i) (l i) := by
refine le_antisymm (tendsto_piMap_pi fun _ ↦ tendsto_map) ?_
refine ((hasBasis_pi fun i ↦ (l i).basis_sets).map _).ge_iff.2 ?_
rintro ⟨I, s⟩ ⟨hI : I.Finite, hs : ∀ i ∈ I, s i ∈ l i⟩
classical
rw [← univ_pi_piecewise_univ, piMap_image_univ_pi]
refine univ_pi_mem_pi (fun i ↦ ?_) ?_
· by_cases hi : i ∈ I
· simpa [hi] using image_mem_map (hs i hi)
· simp [hi]
| · filter_upwards [hf, hI.compl_mem_cofinite] with i hsurj (hiI : i ∉ I)
simp [hiI, hsurj.range_eq]
| Mathlib/Order/Filter/Cofinite.lean | 173 | 175 |
/-
Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios
-/
import Mathlib.SetTheory.Ordinal.FixedPoint
/-!
# Principal ordinals
We define principal or indecomposable ordinals, and we prove the standard properties about them.
## Main definitions and results
* `Principal`: A principal or indecomposable ordinal under some binary operation. We include 0 and
any other typically excluded edge cases for simplicity.
* `not_bddAbove_principal`: Principal ordinals (under any operation) are unbounded.
* `principal_add_iff_zero_or_omega0_opow`: The main characterization theorem for additive principal
ordinals.
* `principal_mul_iff_le_two_or_omega0_opow_opow`: The main characterization theorem for
multiplicative principal ordinals.
## TODO
* Prove that exponential principal ordinals are 0, 1, 2, ω, or epsilon numbers, i.e. fixed points
of `fun x ↦ ω ^ x`.
-/
universe u
open Order
namespace Ordinal
variable {a b c o : Ordinal.{u}}
section Arbitrary
variable {op : Ordinal → Ordinal → Ordinal}
/-! ### Principal ordinals -/
/-- An ordinal `o` is said to be principal or indecomposable under an operation when the set of
ordinals less than it is closed under that operation. In standard mathematical usage, this term is
almost exclusively used for additive and multiplicative principal ordinals.
For simplicity, we break usual convention and regard `0` as principal. -/
def Principal (op : Ordinal → Ordinal → Ordinal) (o : Ordinal) : Prop :=
∀ ⦃a b⦄, a < o → b < o → op a b < o
theorem principal_swap_iff : Principal (Function.swap op) o ↔ Principal op o := by
constructor <;> exact fun h a b ha hb => h hb ha
theorem not_principal_iff : ¬ Principal op o ↔ ∃ a < o, ∃ b < o, o ≤ op a b := by
simp [Principal]
theorem principal_iff_of_monotone
(h₁ : ∀ a, Monotone (op a)) (h₂ : ∀ a, Monotone (Function.swap op a)) :
Principal op o ↔ ∀ a < o, op a a < o := by
use fun h a ha => h ha ha
intro H a b ha hb
obtain hab | hba := le_or_lt a b
· exact (h₂ b hab).trans_lt <| H b hb
· exact (h₁ a hba.le).trans_lt <| H a ha
theorem not_principal_iff_of_monotone
(h₁ : ∀ a, Monotone (op a)) (h₂ : ∀ a, Monotone (Function.swap op a)) :
¬ Principal op o ↔ ∃ a < o, o ≤ op a a := by
| simp [principal_iff_of_monotone h₁ h₂]
theorem principal_zero : Principal op 0 := fun a _ h =>
(Ordinal.not_lt_zero a h).elim
@[simp]
| Mathlib/SetTheory/Ordinal/Principal.lean | 69 | 74 |
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Order.Filter.Prod
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Order.Filter.Finite
import Mathlib.Order.Filter.Bases.Basic
/-!
# Lift filters along filter and set functions
-/
open Set Filter Function
namespace Filter
variable {α β γ : Type*} {ι : Sort*}
section lift
variable {f f₁ f₂ : Filter α} {g g₁ g₂ : Set α → Filter β}
@[simp]
theorem lift_top (g : Set α → Filter β) : (⊤ : Filter α).lift g = g univ := by simp [Filter.lift]
/-- If `(p : ι → Prop, s : ι → Set α)` is a basis of a filter `f`, `g` is a monotone function
`Set α → Filter γ`, and for each `i`, `(pg : β i → Prop, sg : β i → Set α)` is a basis
of the filter `g (s i)`, then
`(fun (i : ι) (x : β i) ↦ p i ∧ pg i x, fun (i : ι) (x : β i) ↦ sg i x)` is a basis
of the filter `f.lift g`.
This basis is parametrized by `i : ι` and `x : β i`, so in order to formulate this fact using
`Filter.HasBasis` one has to use `Σ i, β i` as the index type, see `Filter.HasBasis.lift`.
This lemma states the corresponding `mem_iff` statement without using a sigma type. -/
theorem HasBasis.mem_lift_iff {ι} {p : ι → Prop} {s : ι → Set α} {f : Filter α}
(hf : f.HasBasis p s) {β : ι → Type*} {pg : ∀ i, β i → Prop} {sg : ∀ i, β i → Set γ}
{g : Set α → Filter γ} (hg : ∀ i, (g <| s i).HasBasis (pg i) (sg i)) (gm : Monotone g)
{s : Set γ} : s ∈ f.lift g ↔ ∃ i, p i ∧ ∃ x, pg i x ∧ sg i x ⊆ s := by
refine (mem_biInf_of_directed ?_ ⟨univ, univ_sets _⟩).trans ?_
· intro t₁ ht₁ t₂ ht₂
exact ⟨t₁ ∩ t₂, inter_mem ht₁ ht₂, gm inter_subset_left, gm inter_subset_right⟩
· simp only [← (hg _).mem_iff]
exact hf.exists_iff fun t₁ t₂ ht H => gm ht H
/-- If `(p : ι → Prop, s : ι → Set α)` is a basis of a filter `f`, `g` is a monotone function
`Set α → Filter γ`, and for each `i`, `(pg : β i → Prop, sg : β i → Set α)` is a basis
of the filter `g (s i)`, then
`(fun (i : ι) (x : β i) ↦ p i ∧ pg i x, fun (i : ι) (x : β i) ↦ sg i x)`
is a basis of the filter `f.lift g`.
This basis is parametrized by `i : ι` and `x : β i`, so in order to formulate this fact using
`has_basis` one has to use `Σ i, β i` as the index type. See also `Filter.HasBasis.mem_lift_iff`
for the corresponding `mem_iff` statement formulated without using a sigma type. -/
theorem HasBasis.lift {ι} {p : ι → Prop} {s : ι → Set α} {f : Filter α} (hf : f.HasBasis p s)
{β : ι → Type*} {pg : ∀ i, β i → Prop} {sg : ∀ i, β i → Set γ} {g : Set α → Filter γ}
(hg : ∀ i, (g (s i)).HasBasis (pg i) (sg i)) (gm : Monotone g) :
(f.lift g).HasBasis (fun i : Σi, β i => p i.1 ∧ pg i.1 i.2) fun i : Σi, β i => sg i.1 i.2 := by
refine ⟨fun t => (hf.mem_lift_iff hg gm).trans ?_⟩
simp [Sigma.exists, and_assoc, exists_and_left]
theorem mem_lift_sets (hg : Monotone g) {s : Set β} : s ∈ f.lift g ↔ ∃ t ∈ f, s ∈ g t :=
(f.basis_sets.mem_lift_iff (fun s => (g s).basis_sets) hg).trans <| by
simp only [id, exists_mem_subset_iff]
theorem sInter_lift_sets (hg : Monotone g) :
⋂₀ { s | s ∈ f.lift g } = ⋂ s ∈ f, ⋂₀ { t | t ∈ g s } := by
simp only [sInter_eq_biInter, mem_setOf_eq, Filter.mem_sets, mem_lift_sets hg, iInter_exists,
iInter_and, @iInter_comm _ (Set β)]
theorem mem_lift {s : Set β} {t : Set α} (ht : t ∈ f) (hs : s ∈ g t) : s ∈ f.lift g :=
le_principal_iff.mp <|
show f.lift g ≤ 𝓟 s from iInf_le_of_le t <| iInf_le_of_le ht <| le_principal_iff.mpr hs
theorem lift_le {f : Filter α} {g : Set α → Filter β} {h : Filter β} {s : Set α} (hs : s ∈ f)
(hg : g s ≤ h) : f.lift g ≤ h :=
iInf₂_le_of_le s hs hg
theorem le_lift {f : Filter α} {g : Set α → Filter β} {h : Filter β} :
h ≤ f.lift g ↔ ∀ s ∈ f, h ≤ g s :=
le_iInf₂_iff
theorem lift_mono (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁.lift g₁ ≤ f₂.lift g₂ :=
iInf_mono fun s => iInf_mono' fun hs => ⟨hf hs, hg s⟩
theorem lift_mono' (hg : ∀ s ∈ f, g₁ s ≤ g₂ s) : f.lift g₁ ≤ f.lift g₂ := iInf₂_mono hg
theorem tendsto_lift {m : γ → β} {l : Filter γ} :
Tendsto m l (f.lift g) ↔ ∀ s ∈ f, Tendsto m l (g s) := by
simp only [Filter.lift, tendsto_iInf]
theorem map_lift_eq {m : β → γ} (hg : Monotone g) : map m (f.lift g) = f.lift (map m ∘ g) :=
have : Monotone (map m ∘ g) := map_mono.comp hg
Filter.ext fun s => by
simp only [mem_lift_sets hg, mem_lift_sets this, exists_prop, mem_map, Function.comp_apply]
theorem comap_lift_eq {m : γ → β} : comap m (f.lift g) = f.lift (comap m ∘ g) := by
simp only [Filter.lift, comap_iInf]; rfl
theorem comap_lift_eq2 {m : β → α} {g : Set β → Filter γ} (hg : Monotone g) :
(comap m f).lift g = f.lift (g ∘ preimage m) :=
le_antisymm (le_iInf₂ fun s hs => iInf₂_le (m ⁻¹' s) ⟨s, hs, Subset.rfl⟩)
(le_iInf₂ fun _s ⟨s', hs', h_sub⟩ => iInf₂_le_of_le s' hs' <| hg h_sub)
theorem lift_map_le {g : Set β → Filter γ} {m : α → β} : (map m f).lift g ≤ f.lift (g ∘ image m) :=
le_lift.2 fun _s hs => lift_le (image_mem_map hs) le_rfl
theorem map_lift_eq2 {g : Set β → Filter γ} {m : α → β} (hg : Monotone g) :
(map m f).lift g = f.lift (g ∘ image m) :=
lift_map_le.antisymm <| le_lift.2 fun _s hs => lift_le hs <| hg <| image_preimage_subset _ _
theorem lift_comm {g : Filter β} {h : Set α → Set β → Filter γ} :
(f.lift fun s => g.lift (h s)) = g.lift fun t => f.lift fun s => h s t :=
le_antisymm
(le_iInf fun i => le_iInf fun hi => le_iInf fun j => le_iInf fun hj =>
| iInf_le_of_le j <| iInf_le_of_le hj <| iInf_le_of_le i <| iInf_le _ hi)
(le_iInf fun i => le_iInf fun hi => le_iInf fun j => le_iInf fun hj =>
| Mathlib/Order/Filter/Lift.lean | 117 | 118 |
/-
Copyright (c) 2021 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz, Joël Riou
-/
import Mathlib.CategoryTheory.Limits.Shapes.Products
import Mathlib.CategoryTheory.Limits.Shapes.Equalizers
import Mathlib.CategoryTheory.Limits.ConeCategory
/-!
# Multi-(co)equalizers
A *multiequalizer* is an equalizer of two morphisms between two products.
Since both products and equalizers are limits, such an object is again a limit.
This file provides the diagram whose limit is indeed such an object.
In fact, it is well-known that any limit can be obtained as a multiequalizer.
The dual construction (multicoequalizers) is also provided.
## Projects
Prove that a multiequalizer can be identified with
an equalizer between products (and analogously for multicoequalizers).
Prove that the limit of any diagram is a multiequalizer (and similarly for colimits).
-/
namespace CategoryTheory.Limits
universe w w' v u
/-- The shape of a multiequalizer diagram. It involves two types `L` and `R`,
and two maps `R → L`. -/
@[nolint checkUnivs]
structure MulticospanShape where
/-- the left type -/
L : Type w
/-- the right type -/
R : Type w'
/-- the first map `R → L` -/
fst : R → L
/-- the second map `R → L` -/
snd : R → L
/-- Given a type `ι`, this is the shape of multiequalizer diagrams corresponding
to situations where we want to equalize two families of maps `U i ⟶ V ⟨i, j⟩`
and `U j ⟶ V ⟨i, j⟩` with `i : ι` and `j : ι`. -/
@[simps]
def MulticospanShape.prod (ι : Type w) : MulticospanShape where
L := ι
R := ι × ι
fst := _root_.Prod.fst
snd := _root_.Prod.snd
/-- The shape of a multicoequalizer diagram. It involves two types `L` and `R`,
and two maps `L → R`. -/
@[nolint checkUnivs]
structure MultispanShape where
/-- the left type -/
L : Type w
/-- the right type -/
R : Type w'
/-- the first map `L → R` -/
fst : L → R
/-- the second map `L → R` -/
snd : L → R
/-- Given a type `ι`, this is the shape of multicoequalizer diagrams corresponding
to situations where we want to coequalize two families of maps `V ⟨i, j⟩ ⟶ U i`
and `V ⟨i, j⟩ ⟶ U j` with `i : ι` and `j : ι`. -/
@[simps]
def MultispanShape.prod (ι : Type w) : MultispanShape where
L := ι × ι
R := ι
fst := _root_.Prod.fst
snd := _root_.Prod.snd
/-- Given a linearly ordered type `ι`, this is the shape of multicoequalizer diagrams
corresponding to situations where we want to coequalize two families of maps
`V ⟨i, j⟩ ⟶ U i` and `V ⟨i, j⟩ ⟶ U j` with `i < j`. -/
@[simps]
def MultispanShape.ofLinearOrder (ι : Type w) [LinearOrder ι] : MultispanShape where
L := {x : ι × ι | x.1 < x.2}
R := ι
fst x := x.1.1
snd x := x.1.2
/-- The type underlying the multiequalizer diagram. -/
inductive WalkingMulticospan (J : MulticospanShape.{w, w'}) : Type max w w'
| left : J.L → WalkingMulticospan J
| right : J.R → WalkingMulticospan J
/-- The type underlying the multiecoqualizer diagram. -/
inductive WalkingMultispan (J : MultispanShape.{w, w'}) : Type max w w'
| left : J.L → WalkingMultispan J
| right : J.R → WalkingMultispan J
namespace WalkingMulticospan
variable {J : MulticospanShape.{w, w'}}
instance [Inhabited J.L] : Inhabited (WalkingMulticospan J) :=
⟨left default⟩
-- Don't generate unnecessary `sizeOf_spec` lemma which the `simpNF` linter will complain about.
set_option genSizeOfSpec false in
/-- Morphisms for `WalkingMulticospan`. -/
inductive Hom : ∀ _ _ : WalkingMulticospan J, Type max w w'
| id (A) : Hom A A
| fst (b) : Hom (left (J.fst b)) (right b)
| snd (b) : Hom (left (J.snd b)) (right b)
instance {a : WalkingMulticospan J} : Inhabited (Hom a a) :=
⟨Hom.id _⟩
/-- Composition of morphisms for `WalkingMulticospan`. -/
def Hom.comp : ∀ {A B C : WalkingMulticospan J} (_ : Hom A B) (_ : Hom B C), Hom A C
| _, _, _, Hom.id X, f => f
| _, _, _, Hom.fst b, Hom.id _ => Hom.fst b
| _, _, _, Hom.snd b, Hom.id _ => Hom.snd b
instance : SmallCategory (WalkingMulticospan J) where
Hom := Hom
id := Hom.id
comp := Hom.comp
id_comp := by
rintro (_ | _) (_ | _) (_ | _ | _) <;> rfl
comp_id := by
rintro (_ | _) (_ | _) (_ | _ | _) <;> rfl
assoc := by
rintro (_ | _) (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) (_ | _ | _) <;> rfl
@[simp]
lemma Hom.id_eq_id (X : WalkingMulticospan J) :
Hom.id X = 𝟙 X := rfl
@[simp]
lemma Hom.comp_eq_comp {X Y Z : WalkingMulticospan J}
(f : X ⟶ Y) (g : Y ⟶ Z) : Hom.comp f g = f ≫ g := rfl
end WalkingMulticospan
namespace WalkingMultispan
variable {J : MultispanShape.{w, w'}}
instance [Inhabited J.L] : Inhabited (WalkingMultispan J) :=
⟨left default⟩
-- Don't generate unnecessary `sizeOf_spec` lemma which the `simpNF` linter will complain about.
set_option genSizeOfSpec false in
/-- Morphisms for `WalkingMultispan`. -/
inductive Hom : ∀ _ _ : WalkingMultispan J, Type max w w'
| id (A) : Hom A A
| fst (a) : Hom (left a) (right (J.fst a))
| snd (a) : Hom (left a) (right (J.snd a))
instance {a : WalkingMultispan J} : Inhabited (Hom a a) :=
⟨Hom.id _⟩
/-- Composition of morphisms for `WalkingMultispan`. -/
def Hom.comp : ∀ {A B C : WalkingMultispan J} (_ : Hom A B) (_ : Hom B C), Hom A C
| _, _, _, Hom.id X, f => f
| _, _, _, Hom.fst a, Hom.id _ => Hom.fst a
| _, _, _, Hom.snd a, Hom.id _ => Hom.snd a
instance : SmallCategory (WalkingMultispan J) where
Hom := Hom
id := Hom.id
comp := Hom.comp
id_comp := by
rintro (_ | _) (_ | _) (_ | _ | _) <;> rfl
comp_id := by
rintro (_ | _) (_ | _) (_ | _ | _) <;> rfl
assoc := by
rintro (_ | _) (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) (_ | _ | _) <;> rfl
@[simp]
lemma Hom.id_eq_id (X : WalkingMultispan J) : Hom.id X = 𝟙 X := rfl
@[simp]
lemma Hom.comp_eq_comp {X Y Z : WalkingMultispan J}
(f : X ⟶ Y) (g : Y ⟶ Z) : Hom.comp f g = f ≫ g := rfl
end WalkingMultispan
/-- This is a structure encapsulating the data necessary to define a `Multicospan`. -/
@[nolint checkUnivs]
structure MulticospanIndex (J : MulticospanShape.{w, w'})
(C : Type u) [Category.{v} C] where
/-- Left map, from `J.L` to `C` -/
left : J.L → C
/-- Right map, from `J.R` to `C` -/
right : J.R → C
/-- A family of maps from `left (J.fst b)` to `right b` -/
fst : ∀ b, left (J.fst b) ⟶ right b
/-- A family of maps from `left (J.snd b)` to `right b` -/
snd : ∀ b, left (J.snd b) ⟶ right b
/-- This is a structure encapsulating the data necessary to define a `Multispan`. -/
@[nolint checkUnivs]
structure MultispanIndex (J : MultispanShape.{w, w'})
(C : Type u) [Category.{v} C] where
/-- Left map, from `J.L` to `C` -/
left : J.L → C
/-- Right map, from `J.R` to `C` -/
right : J.R → C
/-- A family of maps from `left a` to `right (J.fst a)` -/
fst : ∀ a, left a ⟶ right (J.fst a)
/-- A family of maps from `left a` to `right (J.snd a)` -/
snd : ∀ a, left a ⟶ right (J.snd a)
namespace MulticospanIndex
variable {C : Type u} [Category.{v} C] {J : MulticospanShape.{w, w'}}
(I : MulticospanIndex J C)
/-- The multicospan associated to `I : MulticospanIndex`. -/
@[simps]
def multicospan : WalkingMulticospan J ⥤ C where
obj x :=
match x with
| WalkingMulticospan.left a => I.left a
| WalkingMulticospan.right b => I.right b
map {x y} f :=
match x, y, f with
| _, _, WalkingMulticospan.Hom.id x => 𝟙 _
| _, _, WalkingMulticospan.Hom.fst b => I.fst _
| _, _, WalkingMulticospan.Hom.snd b => I.snd _
map_id := by
rintro (_ | _) <;> rfl
map_comp := by
rintro (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) <;> aesop_cat
variable [HasProduct I.left] [HasProduct I.right]
/-- The induced map `∏ᶜ I.left ⟶ ∏ᶜ I.right` via `I.fst`. -/
noncomputable def fstPiMap : ∏ᶜ I.left ⟶ ∏ᶜ I.right :=
Pi.lift fun b => Pi.π I.left (J.fst b) ≫ I.fst b
/-- The induced map `∏ᶜ I.left ⟶ ∏ᶜ I.right` via `I.snd`. -/
noncomputable def sndPiMap : ∏ᶜ I.left ⟶ ∏ᶜ I.right :=
Pi.lift fun b => Pi.π I.left (J.snd b) ≫ I.snd b
@[reassoc (attr := simp)]
theorem fstPiMap_π (b) : I.fstPiMap ≫ Pi.π I.right b = Pi.π I.left _ ≫ I.fst b := by
simp [fstPiMap]
@[reassoc (attr := simp)]
theorem sndPiMap_π (b) : I.sndPiMap ≫ Pi.π I.right b = Pi.π I.left _ ≫ I.snd b := by
simp [sndPiMap]
/-- Taking the multiequalizer over the multicospan index is equivalent to taking the equalizer over
the two morphisms `∏ᶜ I.left ⇉ ∏ᶜ I.right`. This is the diagram of the latter.
-/
@[simps!]
protected noncomputable def parallelPairDiagram :=
parallelPair I.fstPiMap I.sndPiMap
end MulticospanIndex
namespace MultispanIndex
variable {C : Type u} [Category.{v} C] {J : MultispanShape.{w, w'}}
(I : MultispanIndex J C)
/-- The multispan associated to `I : MultispanIndex`. -/
def multispan : WalkingMultispan J ⥤ C where
obj x :=
match x with
| WalkingMultispan.left a => I.left a
| WalkingMultispan.right b => I.right b
map {x y} f :=
match x, y, f with
| _, _, WalkingMultispan.Hom.id x => 𝟙 _
| _, _, WalkingMultispan.Hom.fst b => I.fst _
| _, _, WalkingMultispan.Hom.snd b => I.snd _
map_id := by
rintro (_ | _) <;> rfl
map_comp := by
rintro (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) <;> aesop_cat
@[simp]
theorem multispan_obj_left (a) : I.multispan.obj (WalkingMultispan.left a) = I.left a :=
rfl
@[simp]
theorem multispan_obj_right (b) : I.multispan.obj (WalkingMultispan.right b) = I.right b :=
rfl
@[simp]
theorem multispan_map_fst (a) : I.multispan.map (WalkingMultispan.Hom.fst a) = I.fst a :=
rfl
@[simp]
theorem multispan_map_snd (a) : I.multispan.map (WalkingMultispan.Hom.snd a) = I.snd a :=
rfl
variable [HasCoproduct I.left] [HasCoproduct I.right]
/-- The induced map `∐ I.left ⟶ ∐ I.right` via `I.fst`. -/
noncomputable def fstSigmaMap : ∐ I.left ⟶ ∐ I.right :=
Sigma.desc fun b => I.fst b ≫ Sigma.ι _ (J.fst b)
/-- The induced map `∐ I.left ⟶ ∐ I.right` via `I.snd`. -/
noncomputable def sndSigmaMap : ∐ I.left ⟶ ∐ I.right :=
Sigma.desc fun b => I.snd b ≫ Sigma.ι _ (J.snd b)
@[reassoc (attr := simp)]
theorem ι_fstSigmaMap (b) : Sigma.ι I.left b ≫ I.fstSigmaMap = I.fst b ≫ Sigma.ι I.right _ := by
simp [fstSigmaMap]
@[reassoc (attr := simp)]
theorem ι_sndSigmaMap (b) : Sigma.ι I.left b ≫ I.sndSigmaMap = I.snd b ≫ Sigma.ι I.right _ := by
simp [sndSigmaMap]
/--
Taking the multicoequalizer over the multispan index is equivalent to taking the coequalizer over
the two morphsims `∐ I.left ⇉ ∐ I.right`. This is the diagram of the latter.
-/
protected noncomputable abbrev parallelPairDiagram :=
parallelPair I.fstSigmaMap I.sndSigmaMap
end MultispanIndex
variable {C : Type u} [Category.{v} C]
/-- A multifork is a cone over a multicospan. -/
abbrev Multifork {J : MulticospanShape.{w, w'}} (I : MulticospanIndex J C) :=
Cone I.multicospan
/-- A multicofork is a cocone over a multispan. -/
abbrev Multicofork {J : MultispanShape.{w, w'}} (I : MultispanIndex J C) :=
Cocone I.multispan
namespace Multifork
variable {J : MulticospanShape.{w, w'}} {I : MulticospanIndex J C} (K : Multifork I)
/-- The maps from the cone point of a multifork to the objects on the left. -/
def ι (a : J.L) : K.pt ⟶ I.left a :=
K.π.app (WalkingMulticospan.left _)
@[simp]
theorem app_left_eq_ι (a) : K.π.app (WalkingMulticospan.left a) = K.ι a :=
rfl
@[simp]
theorem app_right_eq_ι_comp_fst (b) :
K.π.app (WalkingMulticospan.right b) = K.ι (J.fst b) ≫ I.fst b := by
rw [← K.w (WalkingMulticospan.Hom.fst b)]
rfl
@[reassoc]
theorem app_right_eq_ι_comp_snd (b) :
K.π.app (WalkingMulticospan.right b) = K.ι (J.snd b) ≫ I.snd b := by
rw [← K.w (WalkingMulticospan.Hom.snd b)]
rfl
@[reassoc (attr := simp)]
theorem hom_comp_ι (K₁ K₂ : Multifork I) (f : K₁ ⟶ K₂) (j : J.L) : f.hom ≫ K₂.ι j = K₁.ι j :=
f.w _
/-- Construct a multifork using a collection `ι` of morphisms. -/
@[simps]
def ofι {J : MulticospanShape.{w, w'}} (I : MulticospanIndex J C)
(P : C) (ι : ∀ a, P ⟶ I.left a)
(w : ∀ b, ι (J.fst b) ≫ I.fst b = ι (J.snd b) ≫ I.snd b) : Multifork I where
pt := P
π :=
{ app := fun x =>
match x with
| WalkingMulticospan.left _ => ι _
| WalkingMulticospan.right b => ι (J.fst b) ≫ I.fst b
naturality := by
rintro (_ | _) (_ | _) (_ | _ | _) <;>
dsimp <;> simp only [Category.id_comp, Category.comp_id]
apply w }
@[reassoc (attr := simp)]
theorem condition (b) : K.ι (J.fst b) ≫ I.fst b = K.ι (J.snd b) ≫ I.snd b := by
rw [← app_right_eq_ι_comp_fst, ← app_right_eq_ι_comp_snd]
/-- This definition provides a convenient way to show that a multifork is a limit. -/
@[simps]
def IsLimit.mk (lift : ∀ E : Multifork I, E.pt ⟶ K.pt)
(fac : ∀ (E : Multifork I) (i : J.L), lift E ≫ K.ι i = E.ι i)
(uniq : ∀ (E : Multifork I) (m : E.pt ⟶ K.pt), (∀ i : J.L, m ≫ K.ι i = E.ι i) → m = lift E) :
IsLimit K :=
{ lift
| fac := by
rintro E (a | b)
· apply fac
· rw [← E.w (WalkingMulticospan.Hom.fst b), ← K.w (WalkingMulticospan.Hom.fst b), ←
Category.assoc]
congr 1
apply fac
| Mathlib/CategoryTheory/Limits/Shapes/Multiequalizer.lean | 393 | 399 |
/-
Copyright (c) 2018 Sean Leather. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sean Leather, Mario Carneiro
-/
import Mathlib.Data.List.Sigma
/-!
# Association Lists
This file defines association lists. An association list is a list where every element consists of
a key and a value, and no two entries have the same key. The type of the value is allowed to be
dependent on the type of the key.
This type dependence is implemented using `Sigma`: The elements of the list are of type `Sigma β`,
for some type index `β`.
## Main definitions
Association lists are represented by the `AList` structure. This file defines this structure and
provides ways to access, modify, and combine `AList`s.
* `AList.keys` returns a list of keys of the alist.
* `AList.membership` returns membership in the set of keys.
* `AList.erase` removes a certain key.
* `AList.insert` adds a key-value mapping to the list.
* `AList.union` combines two association lists.
## References
* <https://en.wikipedia.org/wiki/Association_list>
-/
universe u v w
open List
variable {α : Type u} {β : α → Type v}
/-- `AList β` is a key-value map stored as a `List` (i.e. a linked list).
It is a wrapper around certain `List` functions with the added constraint
that the list have unique keys. -/
structure AList (β : α → Type v) : Type max u v where
/-- The underlying `List` of an `AList` -/
entries : List (Sigma β)
/-- There are no duplicate keys in `entries` -/
nodupKeys : entries.NodupKeys
/-- Given `l : List (Sigma β)`, create a term of type `AList β` by removing
entries with duplicate keys. -/
def List.toAList [DecidableEq α] {β : α → Type v} (l : List (Sigma β)) : AList β where
entries := _
nodupKeys := nodupKeys_dedupKeys l
namespace AList
@[ext]
theorem ext : ∀ {s t : AList β}, s.entries = t.entries → s = t
| ⟨l₁, h₁⟩, ⟨l₂, _⟩, H => by congr
instance [DecidableEq α] [∀ a, DecidableEq (β a)] : DecidableEq (AList β) := fun xs ys => by
rw [AList.ext_iff]; infer_instance
/-! ### keys -/
/-- The list of keys of an association list. -/
def keys (s : AList β) : List α :=
s.entries.keys
theorem keys_nodup (s : AList β) : s.keys.Nodup :=
s.nodupKeys
/-! ### mem -/
/-- The predicate `a ∈ s` means that `s` has a value associated to the key `a`. -/
instance : Membership α (AList β) :=
⟨fun s a => a ∈ s.keys⟩
theorem mem_keys {a : α} {s : AList β} : a ∈ s ↔ a ∈ s.keys :=
Iff.rfl
theorem mem_of_perm {a : α} {s₁ s₂ : AList β} (p : s₁.entries ~ s₂.entries) : a ∈ s₁ ↔ a ∈ s₂ :=
(p.map Sigma.fst).mem_iff
/-! ### empty -/
/-- The empty association list. -/
instance : EmptyCollection (AList β) :=
⟨⟨[], nodupKeys_nil⟩⟩
instance : Inhabited (AList β) :=
⟨∅⟩
@[simp]
theorem not_mem_empty (a : α) : a ∉ (∅ : AList β) :=
not_mem_nil
@[simp]
theorem empty_entries : (∅ : AList β).entries = [] :=
rfl
@[simp]
theorem keys_empty : (∅ : AList β).keys = [] :=
rfl
/-! ### singleton -/
/-- The singleton association list. -/
def singleton (a : α) (b : β a) : AList β :=
⟨[⟨a, b⟩], nodupKeys_singleton _⟩
@[simp]
theorem singleton_entries (a : α) (b : β a) : (singleton a b).entries = [Sigma.mk a b] :=
rfl
@[simp]
theorem keys_singleton (a : α) (b : β a) : (singleton a b).keys = [a] :=
rfl
/-! ### lookup -/
section
variable [DecidableEq α]
/-- Look up the value associated to a key in an association list. -/
def lookup (a : α) (s : AList β) : Option (β a) :=
s.entries.dlookup a
@[simp]
theorem lookup_empty (a) : lookup a (∅ : AList β) = none :=
rfl
theorem lookup_isSome {a : α} {s : AList β} : (s.lookup a).isSome ↔ a ∈ s :=
dlookup_isSome
theorem lookup_eq_none {a : α} {s : AList β} : lookup a s = none ↔ a ∉ s :=
dlookup_eq_none
theorem mem_lookup_iff {a : α} {b : β a} {s : AList β} :
b ∈ lookup a s ↔ Sigma.mk a b ∈ s.entries :=
mem_dlookup_iff s.nodupKeys
theorem perm_lookup {a : α} {s₁ s₂ : AList β} (p : s₁.entries ~ s₂.entries) :
s₁.lookup a = s₂.lookup a :=
perm_dlookup _ s₁.nodupKeys s₂.nodupKeys p
instance (a : α) (s : AList β) : Decidable (a ∈ s) :=
decidable_of_iff _ lookup_isSome
end
theorem keys_subset_keys_of_entries_subset_entries
{s₁ s₂ : AList β} (h : s₁.entries ⊆ s₂.entries) : s₁.keys ⊆ s₂.keys := by
intro k hk
letI : DecidableEq α := Classical.decEq α
have := h (mem_lookup_iff.1 (Option.get_mem (lookup_isSome.2 hk)))
rw [← mem_lookup_iff, Option.mem_def] at this
rw [← mem_keys, ← lookup_isSome, this]
exact Option.isSome_some
/-! ### replace -/
section
variable [DecidableEq α]
/-- Replace a key with a given value in an association list.
If the key is not present it does nothing. -/
def replace (a : α) (b : β a) (s : AList β) : AList β :=
⟨kreplace a b s.entries, (kreplace_nodupKeys a b).2 s.nodupKeys⟩
@[simp]
theorem keys_replace (a : α) (b : β a) (s : AList β) : (replace a b s).keys = s.keys :=
keys_kreplace _ _ _
@[simp]
theorem mem_replace {a a' : α} {b : β a} {s : AList β} : a' ∈ replace a b s ↔ a' ∈ s := by
rw [mem_keys, keys_replace, ← mem_keys]
theorem perm_replace {a : α} {b : β a} {s₁ s₂ : AList β} :
s₁.entries ~ s₂.entries → (replace a b s₁).entries ~ (replace a b s₂).entries :=
Perm.kreplace s₁.nodupKeys
end
/-- Fold a function over the key-value pairs in the map. -/
def foldl {δ : Type w} (f : δ → ∀ a, β a → δ) (d : δ) (m : AList β) : δ :=
m.entries.foldl (fun r a => f r a.1 a.2) d
/-! ### erase -/
section
variable [DecidableEq α]
/-- Erase a key from the map. If the key is not present, do nothing. -/
def erase (a : α) (s : AList β) : AList β :=
⟨s.entries.kerase a, s.nodupKeys.kerase a⟩
@[simp]
theorem keys_erase (a : α) (s : AList β) : (erase a s).keys = s.keys.erase a :=
keys_kerase
@[simp]
theorem mem_erase {a a' : α} {s : AList β} : a' ∈ erase a s ↔ a' ≠ a ∧ a' ∈ s := by
rw [mem_keys, keys_erase, s.keys_nodup.mem_erase_iff, ← mem_keys]
theorem perm_erase {a : α} {s₁ s₂ : AList β} :
s₁.entries ~ s₂.entries → (erase a s₁).entries ~ (erase a s₂).entries :=
Perm.kerase s₁.nodupKeys
@[simp]
theorem lookup_erase (a) (s : AList β) : lookup a (erase a s) = none :=
dlookup_kerase a s.nodupKeys
@[simp]
theorem lookup_erase_ne {a a'} {s : AList β} (h : a ≠ a') : lookup a (erase a' s) = lookup a s :=
dlookup_kerase_ne h
theorem erase_erase (a a' : α) (s : AList β) : (s.erase a).erase a' = (s.erase a').erase a :=
ext <| kerase_kerase
/-! ### insert -/
/-- Insert a key-value pair into an association list and erase any existing pair
with the same key. -/
def insert (a : α) (b : β a) (s : AList β) : AList β :=
⟨kinsert a b s.entries, kinsert_nodupKeys a b s.nodupKeys⟩
@[simp]
theorem entries_insert {a} {b : β a} {s : AList β} :
| (insert a b s).entries = Sigma.mk a b :: kerase a s.entries :=
rfl
| Mathlib/Data/List/AList.lean | 241 | 242 |
/-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Data.Matrix.Kronecker
import Mathlib.LinearAlgebra.Matrix.ToLin
import Mathlib.LinearAlgebra.TensorProduct.Basis
/-!
# Connections between `TensorProduct` and `Matrix`
This file contains results about the matrices corresponding to maps between tensor product types,
where the correspondence is induced by `Basis.tensorProduct`
Notably, `TensorProduct.toMatrix_map` shows that taking the tensor product of linear maps is
equivalent to taking the Kronecker product of their matrix representations.
-/
variable {R : Type*} {M N P M' N' : Type*} {ι κ τ ι' κ' : Type*}
variable [DecidableEq ι] [DecidableEq κ] [DecidableEq τ]
variable [Fintype ι] [Fintype κ] [Fintype τ] [Finite ι'] [Finite κ']
variable [CommRing R]
variable [AddCommGroup M] [AddCommGroup N] [AddCommGroup P]
variable [AddCommGroup M'] [AddCommGroup N']
variable [Module R M] [Module R N] [Module R P] [Module R M'] [Module R N']
variable (bM : Basis ι R M) (bN : Basis κ R N) (bP : Basis τ R P)
variable (bM' : Basis ι' R M') (bN' : Basis κ' R N')
open Kronecker
open Matrix LinearMap
/-- The linear map built from `TensorProduct.map` corresponds to the matrix built from
`Matrix.kronecker`. -/
theorem TensorProduct.toMatrix_map (f : M →ₗ[R] M') (g : N →ₗ[R] N') :
toMatrix (bM.tensorProduct bN) (bM'.tensorProduct bN') (TensorProduct.map f g) =
| toMatrix bM bM' f ⊗ₖ toMatrix bN bN' g := by
ext ⟨i, j⟩ ⟨i', j'⟩
simp_rw [Matrix.kroneckerMap_apply, toMatrix_apply, Basis.tensorProduct_apply,
TensorProduct.map_tmul, Basis.tensorProduct_repr_tmul_apply]
exact mul_comm _ _
| Mathlib/LinearAlgebra/TensorProduct/Matrix.lean | 39 | 44 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.OuterMeasure.Operations
import Mathlib.Analysis.SpecificLimits.Basic
/-!
# Outer measures from functions
Given an arbitrary function `m : Set α → ℝ≥0∞` that sends `∅` to `0` we can define an outer
measure on `α` that on `s` is defined to be the infimum of `∑ᵢ, m (sᵢ)` for all collections of sets
`sᵢ` that cover `s`. This is the unique maximal outer measure that is at most the given function.
Given an outer measure `m`, the Carathéodory-measurable sets are the sets `s` such that
for all sets `t` we have `m t = m (t ∩ s) + m (t \ s)`. This forms a measurable space.
## Main definitions and statements
* `OuterMeasure.boundedBy` is the greatest outer measure that is at most the given function.
If you know that the given function sends `∅` to `0`, then `OuterMeasure.ofFunction` is a
special case.
* `sInf_eq_boundedBy_sInfGen` is a characterization of the infimum of outer measures.
## References
* <https://en.wikipedia.org/wiki/Outer_measure>
* <https://en.wikipedia.org/wiki/Carath%C3%A9odory%27s_criterion>
## Tags
outer measure, Carathéodory-measurable, Carathéodory's criterion
-/
assert_not_exists Basis
noncomputable section
open Set Function Filter
open scoped NNReal Topology ENNReal
namespace MeasureTheory
namespace OuterMeasure
section OfFunction
variable {α : Type*}
/-- Given any function `m` assigning measures to sets satisfying `m ∅ = 0`, there is
a unique maximal outer measure `μ` satisfying `μ s ≤ m s` for all `s : Set α`. -/
protected def ofFunction (m : Set α → ℝ≥0∞) (m_empty : m ∅ = 0) : OuterMeasure α :=
let μ s := ⨅ (f : ℕ → Set α) (_ : s ⊆ ⋃ i, f i), ∑' i, m (f i)
{ measureOf := μ
empty :=
le_antisymm
((iInf_le_of_le fun _ => ∅) <| iInf_le_of_le (empty_subset _) <| by simp [m_empty])
(zero_le _)
mono := fun {_ _} hs => iInf_mono fun _ => iInf_mono' fun hb => ⟨hs.trans hb, le_rfl⟩
iUnion_nat := fun s _ =>
ENNReal.le_of_forall_pos_le_add <| by
intro ε hε (hb : (∑' i, μ (s i)) < ∞)
rcases ENNReal.exists_pos_sum_of_countable (ENNReal.coe_pos.2 hε).ne' ℕ with ⟨ε', hε', hl⟩
refine le_trans ?_ (add_le_add_left (le_of_lt hl) _)
rw [← ENNReal.tsum_add]
choose f hf using
show ∀ i, ∃ f : ℕ → Set α, (s i ⊆ ⋃ i, f i) ∧ (∑' i, m (f i)) < μ (s i) + ε' i by
intro i
have : μ (s i) < μ (s i) + ε' i :=
ENNReal.lt_add_right (ne_top_of_le_ne_top hb.ne <| ENNReal.le_tsum _)
(by simpa using (hε' i).ne')
rcases iInf_lt_iff.mp this with ⟨t, ht⟩
exists t
contrapose! ht
exact le_iInf ht
refine le_trans ?_ (ENNReal.tsum_le_tsum fun i => le_of_lt (hf i).2)
rw [← ENNReal.tsum_prod, ← Nat.pairEquiv.symm.tsum_eq]
refine iInf_le_of_le _ (iInf_le _ ?_)
apply iUnion_subset
intro i
apply Subset.trans (hf i).1
apply iUnion_subset
simp only [Nat.pairEquiv_symm_apply]
rw [iUnion_unpair]
intro j
apply subset_iUnion₂ i }
variable (m : Set α → ℝ≥0∞) (m_empty : m ∅ = 0)
/-- `ofFunction` of a set `s` is the infimum of `∑ᵢ, m (tᵢ)` for all collections of sets
`tᵢ` that cover `s`. -/
theorem ofFunction_apply (s : Set α) :
OuterMeasure.ofFunction m m_empty s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, m (t n) :=
rfl
/-- `ofFunction` of a set `s` is the infimum of `∑ᵢ, m (tᵢ)` for all collections of sets
`tᵢ` that cover `s`, with all `tᵢ` satisfying a predicate `P` such that `m` is infinite for sets
that don't satisfy `P`.
This is similar to `ofFunction_apply`, except that the sets `tᵢ` satisfy `P`.
The hypothesis `m_top` applies in particular to a function of the form `extend m'`. -/
theorem ofFunction_eq_iInf_mem {P : Set α → Prop} (m_top : ∀ s, ¬ P s → m s = ∞) (s : Set α) :
OuterMeasure.ofFunction m m_empty s =
⨅ (t : ℕ → Set α) (_ : ∀ i, P (t i)) (_ : s ⊆ ⋃ i, t i), ∑' i, m (t i) := by
rw [OuterMeasure.ofFunction_apply]
apply le_antisymm
· exact le_iInf fun t ↦ le_iInf fun _ ↦ le_iInf fun h ↦ iInf₂_le _ (by exact h)
· simp_rw [le_iInf_iff]
refine fun t ht_subset ↦ iInf_le_of_le t ?_
by_cases ht : ∀ i, P (t i)
· exact iInf_le_of_le ht (iInf_le_of_le ht_subset le_rfl)
· simp only [ht, not_false_eq_true, iInf_neg, top_le_iff]
push_neg at ht
obtain ⟨i, hti_not_mem⟩ := ht
have hfi_top : m (t i) = ∞ := m_top _ hti_not_mem
exact ENNReal.tsum_eq_top_of_eq_top ⟨i, hfi_top⟩
variable {m m_empty}
theorem ofFunction_le (s : Set α) : OuterMeasure.ofFunction m m_empty s ≤ m s :=
let f : ℕ → Set α := fun i => Nat.casesOn i s fun _ => ∅
iInf_le_of_le f <|
iInf_le_of_le (subset_iUnion f 0) <|
le_of_eq <| tsum_eq_single 0 <| by
rintro (_ | i)
· simp
· simp [f, m_empty]
theorem ofFunction_eq (s : Set α) (m_mono : ∀ ⦃t : Set α⦄, s ⊆ t → m s ≤ m t)
(m_subadd : ∀ s : ℕ → Set α, m (⋃ i, s i) ≤ ∑' i, m (s i)) :
OuterMeasure.ofFunction m m_empty s = m s :=
le_antisymm (ofFunction_le s) <|
le_iInf fun f => le_iInf fun hf => le_trans (m_mono hf) (m_subadd f)
theorem le_ofFunction {μ : OuterMeasure α} :
μ ≤ OuterMeasure.ofFunction m m_empty ↔ ∀ s, μ s ≤ m s :=
⟨fun H s => le_trans (H s) (ofFunction_le s), fun H _ =>
le_iInf fun f =>
le_iInf fun hs =>
le_trans (μ.mono hs) <| le_trans (measure_iUnion_le f) <| ENNReal.tsum_le_tsum fun _ => H _⟩
theorem isGreatest_ofFunction :
IsGreatest { μ : OuterMeasure α | ∀ s, μ s ≤ m s } (OuterMeasure.ofFunction m m_empty) :=
⟨fun _ => ofFunction_le _, fun _ => le_ofFunction.2⟩
theorem ofFunction_eq_sSup : OuterMeasure.ofFunction m m_empty = sSup { μ | ∀ s, μ s ≤ m s } :=
(@isGreatest_ofFunction α m m_empty).isLUB.sSup_eq.symm
/-- If `m u = ∞` for any set `u` that has nonempty intersection both with `s` and `t`, then
`μ (s ∪ t) = μ s + μ t`, where `μ = MeasureTheory.OuterMeasure.ofFunction m m_empty`.
E.g., if `α` is an (e)metric space and `m u = ∞` on any set of diameter `≥ r`, then this lemma
implies that `μ (s ∪ t) = μ s + μ t` on any two sets such that `r ≤ edist x y` for all `x ∈ s`
and `y ∈ t`. -/
theorem ofFunction_union_of_top_of_nonempty_inter {s t : Set α}
(h : ∀ u, (s ∩ u).Nonempty → (t ∩ u).Nonempty → m u = ∞) :
OuterMeasure.ofFunction m m_empty (s ∪ t) =
OuterMeasure.ofFunction m m_empty s + OuterMeasure.ofFunction m m_empty t := by
refine le_antisymm (measure_union_le _ _) (le_iInf₂ fun f hf ↦ ?_)
set μ := OuterMeasure.ofFunction m m_empty
rcases Classical.em (∃ i, (s ∩ f i).Nonempty ∧ (t ∩ f i).Nonempty) with (⟨i, hs, ht⟩ | he)
· calc
μ s + μ t ≤ ∞ := le_top
_ = m (f i) := (h (f i) hs ht).symm
_ ≤ ∑' i, m (f i) := ENNReal.le_tsum i
set I := fun s => { i : ℕ | (s ∩ f i).Nonempty }
have hd : Disjoint (I s) (I t) := disjoint_iff_inf_le.mpr fun i hi => he ⟨i, hi⟩
have hI : ∀ u ⊆ s ∪ t, μ u ≤ ∑' i : I u, μ (f i) := fun u hu =>
calc
μ u ≤ μ (⋃ i : I u, f i) :=
μ.mono fun x hx =>
let ⟨i, hi⟩ := mem_iUnion.1 (hf (hu hx))
mem_iUnion.2 ⟨⟨i, ⟨x, hx, hi⟩⟩, hi⟩
_ ≤ ∑' i : I u, μ (f i) := measure_iUnion_le _
calc
μ s + μ t ≤ (∑' i : I s, μ (f i)) + ∑' i : I t, μ (f i) :=
add_le_add (hI _ subset_union_left) (hI _ subset_union_right)
_ = ∑' i : ↑(I s ∪ I t), μ (f i) :=
(ENNReal.summable.tsum_union_disjoint (f := fun i => μ (f i)) hd ENNReal.summable).symm
_ ≤ ∑' i, μ (f i) :=
(ENNReal.summable.tsum_le_tsum_of_inj (↑) Subtype.coe_injective (fun _ _ => zero_le _)
(fun _ => le_rfl) ENNReal.summable)
_ ≤ ∑' i, m (f i) := ENNReal.tsum_le_tsum fun i => ofFunction_le _
theorem comap_ofFunction {β} (f : β → α) (h : Monotone m ∨ Surjective f) :
comap f (OuterMeasure.ofFunction m m_empty) =
OuterMeasure.ofFunction (fun s => m (f '' s)) (by simp; simp [m_empty]) := by
refine le_antisymm (le_ofFunction.2 fun s => ?_) fun s => ?_
· rw [comap_apply]
apply ofFunction_le
· rw [comap_apply, ofFunction_apply, ofFunction_apply]
refine iInf_mono' fun t => ⟨fun k => f ⁻¹' t k, ?_⟩
refine iInf_mono' fun ht => ?_
rw [Set.image_subset_iff, preimage_iUnion] at ht
refine ⟨ht, ENNReal.tsum_le_tsum fun n => ?_⟩
rcases h with hl | hr
exacts [hl (image_preimage_subset _ _), (congr_arg m (hr.image_preimage (t n))).le]
theorem map_ofFunction_le {β} (f : α → β) :
map f (OuterMeasure.ofFunction m m_empty) ≤
OuterMeasure.ofFunction (fun s => m (f ⁻¹' s)) m_empty :=
le_ofFunction.2 fun s => by
rw [map_apply]
apply ofFunction_le
theorem map_ofFunction {β} {f : α → β} (hf : Injective f) :
map f (OuterMeasure.ofFunction m m_empty) =
OuterMeasure.ofFunction (fun s => m (f ⁻¹' s)) m_empty := by
refine (map_ofFunction_le _).antisymm fun s => ?_
simp only [ofFunction_apply, map_apply, le_iInf_iff]
intro t ht
refine iInf_le_of_le (fun n => (range f)ᶜ ∪ f '' t n) (iInf_le_of_le ?_ ?_)
· rw [← union_iUnion, ← inter_subset, ← image_preimage_eq_inter_range, ← image_iUnion]
exact image_subset _ ht
· refine ENNReal.tsum_le_tsum fun n => le_of_eq ?_
simp [hf.preimage_image]
-- TODO (kmill): change `m (t ∩ s)` to `m (s ∩ t)`
theorem restrict_ofFunction (s : Set α) (hm : Monotone m) :
restrict s (OuterMeasure.ofFunction m m_empty) =
OuterMeasure.ofFunction (fun t => m (t ∩ s)) (by simp; simp [m_empty]) := by
rw [restrict]
simp only [inter_comm _ s, LinearMap.comp_apply]
rw [comap_ofFunction _ (Or.inl hm)]
simp only [map_ofFunction Subtype.coe_injective, Subtype.image_preimage_coe]
theorem smul_ofFunction {c : ℝ≥0∞} (hc : c ≠ ∞) : c • OuterMeasure.ofFunction m m_empty =
OuterMeasure.ofFunction (c • m) (by simp [m_empty]) := by
ext1 s
haveI : Nonempty { t : ℕ → Set α // s ⊆ ⋃ i, t i } := ⟨⟨fun _ => s, subset_iUnion (fun _ => s) 0⟩⟩
simp only [smul_apply, ofFunction_apply, ENNReal.tsum_mul_left, Pi.smul_apply, smul_eq_mul,
iInf_subtype']
rw [ENNReal.mul_iInf fun h => (hc h).elim]
end OfFunction
section BoundedBy
variable {α : Type*} (m : Set α → ℝ≥0∞)
/-- Given any function `m` assigning measures to sets, there is a unique maximal outer measure `μ`
satisfying `μ s ≤ m s` for all `s : Set α`. This is the same as `OuterMeasure.ofFunction`,
except that it doesn't require `m ∅ = 0`. -/
def boundedBy : OuterMeasure α :=
OuterMeasure.ofFunction (fun s => ⨆ _ : s.Nonempty, m s) (by simp [Set.not_nonempty_empty])
variable {m}
theorem boundedBy_le (s : Set α) : boundedBy m s ≤ m s :=
(ofFunction_le _).trans iSup_const_le
theorem boundedBy_eq_ofFunction (m_empty : m ∅ = 0) (s : Set α) :
boundedBy m s = OuterMeasure.ofFunction m m_empty s := by
have : (fun s : Set α => ⨆ _ : s.Nonempty, m s) = m := by
ext1 t
rcases t.eq_empty_or_nonempty with h | h <;> simp [h, Set.not_nonempty_empty, m_empty]
simp [boundedBy, this]
theorem boundedBy_apply (s : Set α) :
boundedBy m s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t),
∑' n, ⨆ _ : (t n).Nonempty, m (t n) := by
simp [boundedBy, ofFunction_apply]
theorem boundedBy_eq (s : Set α) (m_empty : m ∅ = 0) (m_mono : ∀ ⦃t : Set α⦄, s ⊆ t → m s ≤ m t)
(m_subadd : ∀ s : ℕ → Set α, m (⋃ i, s i) ≤ ∑' i, m (s i)) : boundedBy m s = m s := by
rw [boundedBy_eq_ofFunction m_empty, ofFunction_eq s m_mono m_subadd]
@[simp]
theorem boundedBy_eq_self (m : OuterMeasure α) : boundedBy m = m :=
ext fun _ => boundedBy_eq _ measure_empty (fun _ ht => measure_mono ht) measure_iUnion_le
theorem le_boundedBy {μ : OuterMeasure α} : μ ≤ boundedBy m ↔ ∀ s, μ s ≤ m s := by
rw [boundedBy , le_ofFunction, forall_congr']; intro s
rcases s.eq_empty_or_nonempty with h | h <;> simp [h, Set.not_nonempty_empty]
theorem le_boundedBy' {μ : OuterMeasure α} :
μ ≤ boundedBy m ↔ ∀ s : Set α, s.Nonempty → μ s ≤ m s := by
rw [le_boundedBy, forall_congr']
intro s
rcases s.eq_empty_or_nonempty with h | h <;> simp [h]
@[simp]
theorem boundedBy_top : boundedBy (⊤ : Set α → ℝ≥0∞) = ⊤ := by
rw [eq_top_iff, le_boundedBy']
intro s hs
rw [top_apply hs]
exact le_rfl
@[simp]
theorem boundedBy_zero : boundedBy (0 : Set α → ℝ≥0∞) = 0 := by
rw [← coe_bot, eq_bot_iff]
apply boundedBy_le
theorem smul_boundedBy {c : ℝ≥0∞} (hc : c ≠ ∞) : c • boundedBy m = boundedBy (c • m) := by
simp only [boundedBy , smul_ofFunction hc]
congr 1 with s : 1
rcases s.eq_empty_or_nonempty with (rfl | hs) <;> simp [*]
theorem comap_boundedBy {β} (f : β → α)
(h : (Monotone fun s : { s : Set α // s.Nonempty } => m s) ∨ Surjective f) :
comap f (boundedBy m) = boundedBy fun s => m (f '' s) := by
refine (comap_ofFunction _ ?_).trans ?_
· refine h.imp (fun H s t hst => iSup_le fun hs => ?_) id
have ht : t.Nonempty := hs.mono hst
exact (@H ⟨s, hs⟩ ⟨t, ht⟩ hst).trans (le_iSup (fun _ : t.Nonempty => m t) ht)
· dsimp only [boundedBy]
congr with s : 1
rw [image_nonempty]
/-- If `m u = ∞` for any set `u` that has nonempty intersection both with `s` and `t`, then
`μ (s ∪ t) = μ s + μ t`, where `μ = MeasureTheory.OuterMeasure.boundedBy m`.
E.g., if `α` is an (e)metric space and `m u = ∞` on any set of diameter `≥ r`, then this lemma
implies that `μ (s ∪ t) = μ s + μ t` on any two sets such that `r ≤ edist x y` for all `x ∈ s`
and `y ∈ t`. -/
theorem boundedBy_union_of_top_of_nonempty_inter {s t : Set α}
(h : ∀ u, (s ∩ u).Nonempty → (t ∩ u).Nonempty → m u = ∞) :
boundedBy m (s ∪ t) = boundedBy m s + boundedBy m t :=
ofFunction_union_of_top_of_nonempty_inter fun u hs ht =>
top_unique <| (h u hs ht).ge.trans <| le_iSup (fun _ => m u) (hs.mono inter_subset_right)
end BoundedBy
section sInfGen
variable {α : Type*}
/-- Given a set of outer measures, we define a new function that on a set `s` is defined to be the
infimum of `μ(s)` for the outer measures `μ` in the collection. We ensure that this
function is defined to be `0` on `∅`, even if the collection of outer measures is empty.
The outer measure generated by this function is the infimum of the given outer measures. -/
def sInfGen (m : Set (OuterMeasure α)) (s : Set α) : ℝ≥0∞ :=
⨅ (μ : OuterMeasure α) (_ : μ ∈ m), μ s
theorem sInfGen_def (m : Set (OuterMeasure α)) (t : Set α) :
sInfGen m t = ⨅ (μ : OuterMeasure α) (_ : μ ∈ m), μ t :=
rfl
theorem sInf_eq_boundedBy_sInfGen (m : Set (OuterMeasure α)) :
sInf m = OuterMeasure.boundedBy (sInfGen m) := by
refine le_antisymm ?_ ?_
· refine le_boundedBy.2 fun s => le_iInf₂ fun μ hμ => ?_
apply sInf_le hμ
· refine le_sInf ?_
intro μ hμ t
exact le_trans (boundedBy_le t) (iInf₂_le μ hμ)
theorem iSup_sInfGen_nonempty {m : Set (OuterMeasure α)} (h : m.Nonempty) (t : Set α) :
⨆ _ : t.Nonempty, sInfGen m t = ⨅ (μ : OuterMeasure α) (_ : μ ∈ m), μ t := by
rcases t.eq_empty_or_nonempty with (rfl | ht)
· simp [biInf_const h]
· simp [ht, sInfGen_def]
/-- The value of the Infimum of a nonempty set of outer measures on a set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem sInf_apply {m : Set (OuterMeasure α)} {s : Set α} (h : m.Nonempty) :
sInf m s =
⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ (μ : OuterMeasure α) (_ : μ ∈ m), μ (t n) := by
simp_rw [sInf_eq_boundedBy_sInfGen, boundedBy_apply, iSup_sInfGen_nonempty h]
/-- The value of the Infimum of a set of outer measures on a nonempty set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem sInf_apply' {m : Set (OuterMeasure α)} {s : Set α} (h : s.Nonempty) :
sInf m s =
⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ (μ : OuterMeasure α) (_ : μ ∈ m), μ (t n) :=
m.eq_empty_or_nonempty.elim (fun hm => by simp [hm, h]) sInf_apply
/-- The value of the Infimum of a nonempty family of outer measures on a set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem iInf_apply {ι} [Nonempty ι] (m : ι → OuterMeasure α) (s : Set α) :
(⨅ i, m i) s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ i, m i (t n) := by
rw [iInf, sInf_apply (range_nonempty m)]
simp only [iInf_range]
/-- The value of the Infimum of a family of outer measures on a nonempty set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem iInf_apply' {ι} (m : ι → OuterMeasure α) {s : Set α} (hs : s.Nonempty) :
(⨅ i, m i) s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ i, m i (t n) := by
rw [iInf, sInf_apply' hs]
simp only [iInf_range]
/-- The value of the Infimum of a nonempty family of outer measures on a set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem biInf_apply {ι} {I : Set ι} (hI : I.Nonempty) (m : ι → OuterMeasure α) (s : Set α) :
(⨅ i ∈ I, m i) s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ i ∈ I, m i (t n) := by
haveI := hI.to_subtype
simp only [← iInf_subtype'', iInf_apply]
/-- The value of the Infimum of a nonempty family of outer measures on a set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem biInf_apply' {ι} (I : Set ι) (m : ι → OuterMeasure α) {s : Set α} (hs : s.Nonempty) :
(⨅ i ∈ I, m i) s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ i ∈ I, m i (t n) := by
simp only [← iInf_subtype'', iInf_apply' _ hs]
theorem map_iInf_le {ι β} (f : α → β) (m : ι → OuterMeasure α) :
map f (⨅ i, m i) ≤ ⨅ i, map f (m i) :=
(map_mono f).map_iInf_le
theorem comap_iInf {ι β} (f : α → β) (m : ι → OuterMeasure β) :
comap f (⨅ i, m i) = ⨅ i, comap f (m i) := by
refine ext_nonempty fun s hs => ?_
refine ((comap_mono f).map_iInf_le s).antisymm ?_
simp only [comap_apply, iInf_apply' _ hs, iInf_apply' _ (hs.image _), le_iInf_iff,
Set.image_subset_iff, preimage_iUnion]
refine fun t ht => iInf_le_of_le _ (iInf_le_of_le ht <| ENNReal.tsum_le_tsum fun k => ?_)
exact iInf_mono fun i => (m i).mono (image_preimage_subset _ _)
theorem map_iInf {ι β} {f : α → β} (hf : Injective f) (m : ι → OuterMeasure α) :
map f (⨅ i, m i) = restrict (range f) (⨅ i, map f (m i)) := by
refine Eq.trans ?_ (map_comap _ _)
simp only [comap_iInf, comap_map hf]
| theorem map_iInf_comap {ι β} [Nonempty ι] {f : α → β} (m : ι → OuterMeasure β) :
map f (⨅ i, comap f (m i)) = ⨅ i, map f (comap f (m i)) := by
refine (map_iInf_le _ _).antisymm fun s => ?_
simp only [map_apply, comap_apply, iInf_apply, le_iInf_iff]
refine fun t ht => iInf_le_of_le (fun n => f '' t n ∪ (range f)ᶜ) (iInf_le_of_le ?_ ?_)
· rw [← iUnion_union, Set.union_comm, ← inter_subset, ← image_iUnion, ←
image_preimage_eq_inter_range]
exact image_subset _ ht
| Mathlib/MeasureTheory/OuterMeasure/OfFunction.lean | 421 | 428 |
/-
Copyright (c) 2022 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kyle Miller
-/
import Mathlib.Tactic.NormNum
/-! # `norm_num` extension for `Nat.sqrt`
This module defines a `norm_num` extension for `Nat.sqrt`.
-/
namespace Tactic
namespace NormNum
open Qq Lean Elab.Tactic Mathlib.Meta.NormNum
lemma nat_sqrt_helper {x y r : ℕ} (hr : y * y + r = x) (hle : Nat.ble r (2 * y)) :
| Nat.sqrt x = y := by
rw [← hr, ← pow_two]
rw [two_mul] at hle
exact Nat.sqrt_add_eq' _ (Nat.le_of_ble_eq_true hle)
| Mathlib/Tactic/NormNum/NatSqrt.lean | 20 | 24 |
/-
Copyright (c) 2021 Stuart Presnell. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Stuart Presnell
-/
import Mathlib.Data.Nat.PrimeFin
import Mathlib.Data.Nat.Factorization.Defs
import Mathlib.Data.Nat.GCD.BigOperators
import Mathlib.Order.Interval.Finset.Nat
import Mathlib.Tactic.IntervalCases
/-!
# Basic lemmas on prime factorizations
-/
open Finset List Finsupp
namespace Nat
variable {a b m n p : ℕ}
/-! ### Basic facts about factorization -/
/-! ## Lemmas characterising when `n.factorization p = 0` -/
theorem factorization_eq_zero_of_lt {n p : ℕ} (h : n < p) : n.factorization p = 0 :=
Finsupp.not_mem_support_iff.mp (mt le_of_mem_primeFactors (not_le_of_lt h))
@[simp]
theorem factorization_one_right (n : ℕ) : n.factorization 1 = 0 :=
factorization_eq_zero_of_non_prime _ not_prime_one
theorem dvd_of_factorization_pos {n p : ℕ} (hn : n.factorization p ≠ 0) : p ∣ n :=
dvd_of_mem_primeFactorsList <| mem_primeFactors_iff_mem_primeFactorsList.1 <| mem_support_iff.2 hn
theorem factorization_eq_zero_iff_remainder {p r : ℕ} (i : ℕ) (pp : p.Prime) (hr0 : r ≠ 0) :
¬p ∣ r ↔ (p * i + r).factorization p = 0 := by
refine ⟨factorization_eq_zero_of_remainder i, fun h => ?_⟩
rw [factorization_eq_zero_iff] at h
contrapose! h
refine ⟨pp, ?_, ?_⟩
· rwa [← Nat.dvd_add_iff_right (dvd_mul_right p i)]
· contrapose! hr0
exact (add_eq_zero.1 hr0).2
/-- The only numbers with empty prime factorization are `0` and `1` -/
theorem factorization_eq_zero_iff' (n : ℕ) : n.factorization = 0 ↔ n = 0 ∨ n = 1 := by
rw [factorization_eq_primeFactorsList_multiset n]
simp [factorization, AddEquiv.map_eq_zero_iff, Multiset.coe_eq_zero]
/-! ## Lemmas about factorizations of products and powers -/
/-- A product over `n.factorization` can be written as a product over `n.primeFactors`; -/
lemma prod_factorization_eq_prod_primeFactors {β : Type*} [CommMonoid β] (f : ℕ → ℕ → β) :
n.factorization.prod f = ∏ p ∈ n.primeFactors, f p (n.factorization p) := rfl
/-- A product over `n.primeFactors` can be written as a product over `n.factorization`; -/
lemma prod_primeFactors_prod_factorization {β : Type*} [CommMonoid β] (f : ℕ → β) :
∏ p ∈ n.primeFactors, f p = n.factorization.prod (fun p _ ↦ f p) := rfl
/-! ## Lemmas about factorizations of primes and prime powers -/
/-- The multiplicity of prime `p` in `p` is `1` -/
@[simp]
theorem Prime.factorization_self {p : ℕ} (hp : Prime p) : p.factorization p = 1 := by simp [hp]
/-- If the factorization of `n` contains just one number `p` then `n` is a power of `p` -/
theorem eq_pow_of_factorization_eq_single {n p k : ℕ} (hn : n ≠ 0)
(h : n.factorization = Finsupp.single p k) : n = p ^ k := by
rw [← Nat.factorization_prod_pow_eq_self hn, h]
simp
/-- The only prime factor of prime `p` is `p` itself. -/
theorem Prime.eq_of_factorization_pos {p q : ℕ} (hp : Prime p) (h : p.factorization q ≠ 0) :
p = q := by simpa [hp.factorization, single_apply] using h
/-! ### Equivalence between `ℕ+` and `ℕ →₀ ℕ` with support in the primes. -/
theorem eq_factorization_iff {n : ℕ} {f : ℕ →₀ ℕ} (hn : n ≠ 0) (hf : ∀ p ∈ f.support, Prime p) :
f = n.factorization ↔ f.prod (· ^ ·) = n :=
⟨fun h => by rw [h, factorization_prod_pow_eq_self hn], fun h => by
rw [← h, prod_pow_factorization_eq_self hf]⟩
theorem factorizationEquiv_inv_apply {f : ℕ →₀ ℕ} (hf : ∀ p ∈ f.support, Prime p) :
(factorizationEquiv.symm ⟨f, hf⟩).1 = f.prod (· ^ ·) :=
rfl
@[simp]
theorem ordProj_of_not_prime (n p : ℕ) (hp : ¬p.Prime) : ordProj[p] n = 1 := by
simp [factorization_eq_zero_of_non_prime n hp]
@[deprecated (since := "2024-10-24")] alias ord_proj_of_not_prime := ordProj_of_not_prime
@[simp]
theorem ordCompl_of_not_prime (n p : ℕ) (hp : ¬p.Prime) : ordCompl[p] n = n := by
simp [factorization_eq_zero_of_non_prime n hp]
@[deprecated (since := "2024-10-24")] alias ord_compl_of_not_prime := ordCompl_of_not_prime
theorem ordCompl_dvd (n p : ℕ) : ordCompl[p] n ∣ n :=
div_dvd_of_dvd (ordProj_dvd n p)
@[deprecated (since := "2024-10-24")] alias ord_compl_dvd := ordCompl_dvd
theorem ordProj_pos (n p : ℕ) : 0 < ordProj[p] n := by
if pp : p.Prime then simp [pow_pos pp.pos] else simp [pp]
@[deprecated (since := "2024-10-24")] alias ord_proj_pos := ordProj_pos
theorem ordProj_le {n : ℕ} (p : ℕ) (hn : n ≠ 0) : ordProj[p] n ≤ n :=
le_of_dvd hn.bot_lt (Nat.ordProj_dvd n p)
@[deprecated (since := "2024-10-24")] alias ord_proj_le := ordProj_le
theorem ordCompl_pos {n : ℕ} (p : ℕ) (hn : n ≠ 0) : 0 < ordCompl[p] n := by
if pp : p.Prime then
exact Nat.div_pos (ordProj_le p hn) (ordProj_pos n p)
else
simpa [Nat.factorization_eq_zero_of_non_prime n pp] using hn.bot_lt
@[deprecated (since := "2024-10-24")] alias ord_compl_pos := ordCompl_pos
theorem ordCompl_le (n p : ℕ) : ordCompl[p] n ≤ n :=
Nat.div_le_self _ _
@[deprecated (since := "2024-10-24")] alias ord_compl_le := ordCompl_le
theorem ordProj_mul_ordCompl_eq_self (n p : ℕ) : ordProj[p] n * ordCompl[p] n = n :=
Nat.mul_div_cancel' (ordProj_dvd n p)
@[deprecated (since := "2024-10-24")]
alias ord_proj_mul_ord_compl_eq_self := ordProj_mul_ordCompl_eq_self
theorem ordProj_mul {a b : ℕ} (p : ℕ) (ha : a ≠ 0) (hb : b ≠ 0) :
ordProj[p] (a * b) = ordProj[p] a * ordProj[p] b := by
simp [factorization_mul ha hb, pow_add]
@[deprecated (since := "2024-10-24")] alias ord_proj_mul := ordProj_mul
theorem ordCompl_mul (a b p : ℕ) : ordCompl[p] (a * b) = ordCompl[p] a * ordCompl[p] b := by
if ha : a = 0 then simp [ha] else
if hb : b = 0 then simp [hb] else
simp only [ordProj_mul p ha hb]
rw [div_mul_div_comm (ordProj_dvd a p) (ordProj_dvd b p)]
@[deprecated (since := "2024-10-24")] alias ord_compl_mul := ordCompl_mul
/-! ### Factorization and divisibility -/
/-- A crude upper bound on `n.factorization p` -/
theorem factorization_lt {n : ℕ} (p : ℕ) (hn : n ≠ 0) : n.factorization p < n := by
by_cases pp : p.Prime
· exact (Nat.pow_lt_pow_iff_right pp.one_lt).1 <| (ordProj_le p hn).trans_lt <|
Nat.lt_pow_self pp.one_lt
· simpa only [factorization_eq_zero_of_non_prime n pp] using hn.bot_lt
/-- An upper bound on `n.factorization p` -/
theorem factorization_le_of_le_pow {n p b : ℕ} (hb : n ≤ p ^ b) : n.factorization p ≤ b := by
if hn : n = 0 then simp [hn] else
if pp : p.Prime then
exact (Nat.pow_le_pow_iff_right pp.one_lt).1 ((ordProj_le p hn).trans hb)
else
simp [factorization_eq_zero_of_non_prime n pp]
theorem factorization_prime_le_iff_dvd {d n : ℕ} (hd : d ≠ 0) (hn : n ≠ 0) :
(∀ p : ℕ, p.Prime → d.factorization p ≤ n.factorization p) ↔ d ∣ n := by
rw [← factorization_le_iff_dvd hd hn]
refine ⟨fun h p => (em p.Prime).elim (h p) fun hp => ?_, fun h p _ => h p⟩
simp_rw [factorization_eq_zero_of_non_prime _ hp]
rfl
theorem factorization_le_factorization_mul_left {a b : ℕ} (hb : b ≠ 0) :
a.factorization ≤ (a * b).factorization := by
rcases eq_or_ne a 0 with (rfl | ha)
· simp
rw [factorization_le_iff_dvd ha <| mul_ne_zero ha hb]
exact Dvd.intro b rfl
theorem factorization_le_factorization_mul_right {a b : ℕ} (ha : a ≠ 0) :
b.factorization ≤ (a * b).factorization := by
rw [mul_comm]
apply factorization_le_factorization_mul_left ha
theorem Prime.pow_dvd_iff_le_factorization {p k n : ℕ} (pp : Prime p) (hn : n ≠ 0) :
p ^ k ∣ n ↔ k ≤ n.factorization p := by
rw [← factorization_le_iff_dvd (pow_pos pp.pos k).ne' hn, pp.factorization_pow, single_le_iff]
theorem Prime.pow_dvd_iff_dvd_ordProj {p k n : ℕ} (pp : Prime p) (hn : n ≠ 0) :
p ^ k ∣ n ↔ p ^ k ∣ ordProj[p] n := by
rw [pow_dvd_pow_iff_le_right pp.one_lt, pp.pow_dvd_iff_le_factorization hn]
@[deprecated (since := "2024-10-24")]
alias Prime.pow_dvd_iff_dvd_ord_proj := Prime.pow_dvd_iff_dvd_ordProj
theorem Prime.dvd_iff_one_le_factorization {p n : ℕ} (pp : Prime p) (hn : n ≠ 0) :
p ∣ n ↔ 1 ≤ n.factorization p :=
Iff.trans (by simp) (pp.pow_dvd_iff_le_factorization hn)
theorem exists_factorization_lt_of_lt {a b : ℕ} (ha : a ≠ 0) (hab : a < b) :
∃ p : ℕ, a.factorization p < b.factorization p := by
have hb : b ≠ 0 := (ha.bot_lt.trans hab).ne'
contrapose! hab
rw [← Finsupp.le_def, factorization_le_iff_dvd hb ha] at hab
exact le_of_dvd ha.bot_lt hab
@[simp]
theorem factorization_div {d n : ℕ} (h : d ∣ n) :
(n / d).factorization = n.factorization - d.factorization := by
rcases eq_or_ne d 0 with (rfl | hd); · simp [zero_dvd_iff.mp h]
rcases eq_or_ne n 0 with (rfl | hn); · simp [tsub_eq_zero_of_le]
apply add_left_injective d.factorization
simp only
rw [tsub_add_cancel_of_le <| (Nat.factorization_le_iff_dvd hd hn).mpr h, ←
Nat.factorization_mul (Nat.div_pos (Nat.le_of_dvd hn.bot_lt h) hd.bot_lt).ne' hd,
Nat.div_mul_cancel h]
theorem dvd_ordProj_of_dvd {n p : ℕ} (hn : n ≠ 0) (pp : p.Prime) (h : p ∣ n) : p ∣ ordProj[p] n :=
dvd_pow_self p (Prime.factorization_pos_of_dvd pp hn h).ne'
@[deprecated (since := "2024-10-24")] alias dvd_ord_proj_of_dvd := dvd_ordProj_of_dvd
theorem not_dvd_ordCompl {n p : ℕ} (hp : Prime p) (hn : n ≠ 0) : ¬p ∣ ordCompl[p] n := by
rw [Nat.Prime.dvd_iff_one_le_factorization hp (ordCompl_pos p hn).ne']
rw [Nat.factorization_div (Nat.ordProj_dvd n p)]
simp [hp.factorization]
@[deprecated (since := "2024-10-24")] alias not_dvd_ord_compl := not_dvd_ordCompl
theorem coprime_ordCompl {n p : ℕ} (hp : Prime p) (hn : n ≠ 0) : Coprime p (ordCompl[p] n) :=
(or_iff_left (not_dvd_ordCompl hp hn)).mp <| coprime_or_dvd_of_prime hp _
@[deprecated (since := "2024-10-24")] alias coprime_ord_compl := coprime_ordCompl
theorem factorization_ordCompl (n p : ℕ) :
(ordCompl[p] n).factorization = n.factorization.erase p := by
if hn : n = 0 then simp [hn] else
if pp : p.Prime then ?_ else
simp [pp]
ext q
rcases eq_or_ne q p with (rfl | hqp)
· simp only [Finsupp.erase_same, factorization_eq_zero_iff, not_dvd_ordCompl pp hn]
simp
· rw [Finsupp.erase_ne hqp, factorization_div (ordProj_dvd n p)]
simp [pp.factorization, hqp.symm]
@[deprecated (since := "2024-10-24")] alias factorization_ord_compl := factorization_ordCompl
-- `ordCompl[p] n` is the largest divisor of `n` not divisible by `p`.
theorem dvd_ordCompl_of_dvd_not_dvd {p d n : ℕ} (hdn : d ∣ n) (hpd : ¬p ∣ d) :
d ∣ ordCompl[p] n := by
if hn0 : n = 0 then simp [hn0] else
if hd0 : d = 0 then simp [hd0] at hpd else
rw [← factorization_le_iff_dvd hd0 (ordCompl_pos p hn0).ne', factorization_ordCompl]
intro q
if hqp : q = p then
simp [factorization_eq_zero_iff, hqp, hpd]
else
simp [hqp, (factorization_le_iff_dvd hd0 hn0).2 hdn q]
@[deprecated (since := "2024-10-24")]
alias dvd_ord_compl_of_dvd_not_dvd := dvd_ordCompl_of_dvd_not_dvd
/-- If `n` is a nonzero natural number and `p ≠ 1`, then there are natural numbers `e`
and `n'` such that `n'` is not divisible by `p` and `n = p^e * n'`. -/
theorem exists_eq_pow_mul_and_not_dvd {n : ℕ} (hn : n ≠ 0) (p : ℕ) (hp : p ≠ 1) :
∃ e n' : ℕ, ¬p ∣ n' ∧ n = p ^ e * n' :=
let ⟨a', h₁, h₂⟩ :=
(Nat.finiteMultiplicity_iff.mpr ⟨hp, Nat.pos_of_ne_zero hn⟩).exists_eq_pow_mul_and_not_dvd
⟨_, a', h₂, h₁⟩
/-- Any nonzero natural number is the product of an odd part `m` and a power of
two `2 ^ k`. -/
theorem exists_eq_two_pow_mul_odd {n : ℕ} (hn : n ≠ 0) :
∃ k m : ℕ, Odd m ∧ n = 2 ^ k * m :=
let ⟨k, m, hm, hn⟩ := exists_eq_pow_mul_and_not_dvd hn 2 (succ_ne_self 1)
⟨k, m, not_even_iff_odd.1 (mt Even.two_dvd hm), hn⟩
theorem dvd_iff_div_factorization_eq_tsub {d n : ℕ} (hd : d ≠ 0) (hdn : d ≤ n) :
d ∣ n ↔ (n / d).factorization = n.factorization - d.factorization := by
refine ⟨factorization_div, ?_⟩
rcases eq_or_lt_of_le hdn with (rfl | hd_lt_n); · simp
have h1 : n / d ≠ 0 := by simp [*]
intro h
rw [dvd_iff_le_div_mul n d]
by_contra h2
obtain ⟨p, hp⟩ := exists_factorization_lt_of_lt (mul_ne_zero h1 hd) (not_le.mp h2)
rwa [factorization_mul h1 hd, add_apply, ← lt_tsub_iff_right, h, tsub_apply,
lt_self_iff_false] at hp
theorem ordProj_dvd_ordProj_of_dvd {a b : ℕ} (hb0 : b ≠ 0) (hab : a ∣ b) (p : ℕ) :
ordProj[p] a ∣ ordProj[p] b := by
rcases em' p.Prime with (pp | pp); · simp [pp]
rcases eq_or_ne a 0 with (rfl | ha0); · simp
rw [pow_dvd_pow_iff_le_right pp.one_lt]
exact (factorization_le_iff_dvd ha0 hb0).2 hab p
@[deprecated (since := "2024-10-24")]
alias ord_proj_dvd_ord_proj_of_dvd := ordProj_dvd_ordProj_of_dvd
theorem ordProj_dvd_ordProj_iff_dvd {a b : ℕ} (ha0 : a ≠ 0) (hb0 : b ≠ 0) :
(∀ p : ℕ, ordProj[p] a ∣ ordProj[p] b) ↔ a ∣ b := by
refine ⟨fun h => ?_, fun hab p => ordProj_dvd_ordProj_of_dvd hb0 hab p⟩
rw [← factorization_le_iff_dvd ha0 hb0]
intro q
rcases le_or_lt q 1 with (hq_le | hq1)
· interval_cases q <;> simp
exact (pow_dvd_pow_iff_le_right hq1).1 (h q)
@[deprecated (since := "2024-10-24")]
alias ord_proj_dvd_ord_proj_iff_dvd := ordProj_dvd_ordProj_iff_dvd
theorem ordCompl_dvd_ordCompl_of_dvd {a b : ℕ} (hab : a ∣ b) (p : ℕ) :
ordCompl[p] a ∣ ordCompl[p] b := by
rcases em' p.Prime with (pp | pp)
· simp [pp, hab]
rcases eq_or_ne b 0 with (rfl | hb0)
· simp
rcases eq_or_ne a 0 with (rfl | ha0)
· cases hb0 (zero_dvd_iff.1 hab)
have ha := (Nat.div_pos (ordProj_le p ha0) (ordProj_pos a p)).ne'
have hb := (Nat.div_pos (ordProj_le p hb0) (ordProj_pos b p)).ne'
rw [← factorization_le_iff_dvd ha hb, factorization_ordCompl a p, factorization_ordCompl b p]
intro q
rcases eq_or_ne q p with (rfl | hqp)
· simp
simp_rw [erase_ne hqp]
exact (factorization_le_iff_dvd ha0 hb0).2 hab q
@[deprecated (since := "2024-10-24")]
alias ord_compl_dvd_ord_compl_of_dvd := ordCompl_dvd_ordCompl_of_dvd
theorem ordCompl_dvd_ordCompl_iff_dvd (a b : ℕ) :
(∀ p : ℕ, ordCompl[p] a ∣ ordCompl[p] b) ↔ a ∣ b := by
refine ⟨fun h => ?_, fun hab p => ordCompl_dvd_ordCompl_of_dvd hab p⟩
rcases eq_or_ne b 0 with (rfl | hb0)
· simp
if pa : a.Prime then ?_ else simpa [pa] using h a
if pb : b.Prime then ?_ else simpa [pb] using h b
rw [prime_dvd_prime_iff_eq pa pb]
by_contra hab
apply pa.ne_one
rw [← Nat.dvd_one, ← Nat.mul_dvd_mul_iff_left hb0.bot_lt, mul_one]
simpa [Prime.factorization_self pb, Prime.factorization pa, hab] using h b
@[deprecated (since := "2024-10-24")]
alias ord_compl_dvd_ord_compl_iff_dvd := ordCompl_dvd_ordCompl_iff_dvd
theorem dvd_iff_prime_pow_dvd_dvd (n d : ℕ) :
d ∣ n ↔ ∀ p k : ℕ, Prime p → p ^ k ∣ d → p ^ k ∣ n := by
rcases eq_or_ne n 0 with (rfl | hn)
· simp
rcases eq_or_ne d 0 with (rfl | hd)
· simp only [zero_dvd_iff, hn, false_iff, not_forall]
exact ⟨2, n, prime_two, dvd_zero _, mt (le_of_dvd hn.bot_lt) (n.lt_two_pow_self).not_le⟩
refine ⟨fun h p k _ hpkd => dvd_trans hpkd h, ?_⟩
rw [← factorization_prime_le_iff_dvd hd hn]
intro h p pp
simp_rw [← pp.pow_dvd_iff_le_factorization hn]
exact h p _ pp (ordProj_dvd _ _)
theorem prod_primeFactors_dvd (n : ℕ) : ∏ p ∈ n.primeFactors, p ∣ n := by
by_cases hn : n = 0
· subst hn
simp
· simpa [prod_primeFactorsList hn] using (n.primeFactorsList : Multiset ℕ).toFinset_prod_dvd_prod
theorem factorization_gcd {a b : ℕ} (ha_pos : a ≠ 0) (hb_pos : b ≠ 0) :
(gcd a b).factorization = a.factorization ⊓ b.factorization := by
let dfac := a.factorization ⊓ b.factorization
let d := dfac.prod (· ^ ·)
have dfac_prime : ∀ p : ℕ, p ∈ dfac.support → Prime p := by
intro p hp
have : p ∈ a.primeFactorsList ∧ p ∈ b.primeFactorsList := by simpa [dfac] using hp
exact prime_of_mem_primeFactorsList this.1
have h1 : d.factorization = dfac := prod_pow_factorization_eq_self dfac_prime
have hd_pos : d ≠ 0 := (factorizationEquiv.invFun ⟨dfac, dfac_prime⟩).2.ne'
suffices d = gcd a b by rwa [← this]
apply gcd_greatest
· rw [← factorization_le_iff_dvd hd_pos ha_pos, h1]
exact inf_le_left
· rw [← factorization_le_iff_dvd hd_pos hb_pos, h1]
exact inf_le_right
· intro e hea heb
rcases Decidable.eq_or_ne e 0 with (rfl | he_pos)
· simp only [zero_dvd_iff] at hea
contradiction
have hea' := (factorization_le_iff_dvd he_pos ha_pos).mpr hea
have heb' := (factorization_le_iff_dvd he_pos hb_pos).mpr heb
simp [dfac, ← factorization_le_iff_dvd he_pos hd_pos, h1, hea', heb']
theorem factorization_lcm {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) :
(a.lcm b).factorization = a.factorization ⊔ b.factorization := by
rw [← add_right_inj (a.gcd b).factorization, ←
factorization_mul (mt gcd_eq_zero_iff.1 fun h => ha h.1) (lcm_ne_zero ha hb), gcd_mul_lcm,
factorization_gcd ha hb, factorization_mul ha hb]
ext1
exact (min_add_max _ _).symm
variable (a b)
@[simp]
lemma factorizationLCMLeft_zero_left : factorizationLCMLeft 0 b = 1 := by
simp [factorizationLCMLeft]
@[simp]
lemma factorizationLCMLeft_zero_right : factorizationLCMLeft a 0 = 1 := by
simp [factorizationLCMLeft]
@[simp]
lemma factorizationLCRight_zero_left : factorizationLCMRight 0 b = 1 := by
simp [factorizationLCMRight]
@[simp]
lemma factorizationLCMRight_zero_right : factorizationLCMRight a 0 = 1 := by
simp [factorizationLCMRight]
lemma factorizationLCMLeft_pos :
0 < factorizationLCMLeft a b := by
apply Nat.pos_of_ne_zero
rw [factorizationLCMLeft, Finsupp.prod_ne_zero_iff]
intro p _ H
by_cases h : b.factorization p ≤ a.factorization p
· simp only [h, reduceIte, pow_eq_zero_iff', ne_eq] at H
simpa [H.1] using H.2
· simp only [h, reduceIte, one_ne_zero] at H
lemma factorizationLCMRight_pos :
0 < factorizationLCMRight a b := by
apply Nat.pos_of_ne_zero
rw [factorizationLCMRight, Finsupp.prod_ne_zero_iff]
intro p _ H
by_cases h : b.factorization p ≤ a.factorization p
· simp only [h, reduceIte, pow_eq_zero_iff', ne_eq, reduceCtorEq] at H
· simp only [h, ↓reduceIte, pow_eq_zero_iff', ne_eq] at H
simpa [H.1] using H.2
lemma coprime_factorizationLCMLeft_factorizationLCMRight :
(factorizationLCMLeft a b).Coprime (factorizationLCMRight a b) := by
rw [factorizationLCMLeft, factorizationLCMRight]
refine coprime_prod_left_iff.mpr fun p hp ↦ coprime_prod_right_iff.mpr fun q hq ↦ ?_
dsimp only; split_ifs with h h'
any_goals simp only [coprime_one_right_eq_true, coprime_one_left_eq_true]
refine coprime_pow_primes _ _ (prime_of_mem_primeFactors hp) (prime_of_mem_primeFactors hq) ?_
contrapose! h'; rwa [← h']
variable {a b}
lemma factorizationLCMLeft_mul_factorizationLCMRight (ha : a ≠ 0) (hb : b ≠ 0) :
(factorizationLCMLeft a b) * (factorizationLCMRight a b) = lcm a b := by
rw [← factorization_prod_pow_eq_self (lcm_ne_zero ha hb), factorizationLCMLeft,
factorizationLCMRight, ← prod_mul]
congr; ext p n; split_ifs <;> simp
variable (a b)
lemma factorizationLCMLeft_dvd_left : factorizationLCMLeft a b ∣ a := by
rcases eq_or_ne a 0 with rfl | ha
· simp only [dvd_zero]
rcases eq_or_ne b 0 with rfl | hb
· simp [factorizationLCMLeft]
nth_rewrite 2 [← factorization_prod_pow_eq_self ha]
rw [prod_of_support_subset (s := (lcm a b).factorization.support)]
· apply prod_dvd_prod_of_dvd; rintro p -; dsimp only; split_ifs with le
· rw [factorization_lcm ha hb]; apply pow_dvd_pow; exact sup_le le_rfl le
· apply one_dvd
· intro p hp; rw [mem_support_iff] at hp ⊢
rw [factorization_lcm ha hb]; exact (lt_sup_iff.mpr <| .inl <| Nat.pos_of_ne_zero hp).ne'
· intros; rw [pow_zero]
lemma factorizationLCMRight_dvd_right : factorizationLCMRight a b ∣ b := by
rcases eq_or_ne a 0 with rfl | ha
· simp [factorizationLCMRight]
rcases eq_or_ne b 0 with rfl | hb
· simp only [dvd_zero]
nth_rewrite 2 [← factorization_prod_pow_eq_self hb]
rw [prod_of_support_subset (s := (lcm a b).factorization.support)]
· apply Finset.prod_dvd_prod_of_dvd; rintro p -; dsimp only; split_ifs with le
· apply one_dvd
· rw [factorization_lcm ha hb]; apply pow_dvd_pow; exact sup_le (not_le.1 le).le le_rfl
· intro p hp; rw [mem_support_iff] at hp ⊢
rw [factorization_lcm ha hb]; exact (lt_sup_iff.mpr <| .inr <| Nat.pos_of_ne_zero hp).ne'
· intros; rw [pow_zero]
@[to_additive sum_primeFactors_gcd_add_sum_primeFactors_mul]
theorem prod_primeFactors_gcd_mul_prod_primeFactors_mul {β : Type*} [CommMonoid β] (m n : ℕ)
(f : ℕ → β) :
(m.gcd n).primeFactors.prod f * (m * n).primeFactors.prod f =
m.primeFactors.prod f * n.primeFactors.prod f := by
obtain rfl | hm₀ := eq_or_ne m 0
· simp
obtain rfl | hn₀ := eq_or_ne n 0
· simp
· rw [primeFactors_mul hm₀ hn₀, primeFactors_gcd hm₀ hn₀, mul_comm, Finset.prod_union_inter]
theorem setOf_pow_dvd_eq_Icc_factorization {n p : ℕ} (pp : p.Prime) (hn : n ≠ 0) :
{ i : ℕ | i ≠ 0 ∧ p ^ i ∣ n } = Set.Icc 1 (n.factorization p) := by
ext
simp [Nat.lt_succ_iff, one_le_iff_ne_zero, pp.pow_dvd_iff_le_factorization hn]
/-- The set of positive powers of prime `p` that divide `n` is exactly the set of
positive natural numbers up to `n.factorization p`. -/
theorem Icc_factorization_eq_pow_dvd (n : ℕ) {p : ℕ} (pp : Prime p) :
Icc 1 (n.factorization p) = {i ∈ Ico 1 n | p ^ i ∣ n} := by
rcases eq_or_ne n 0 with (rfl | hn)
· simp
ext x
simp only [mem_Icc, Finset.mem_filter, mem_Ico, and_assoc, and_congr_right_iff,
pp.pow_dvd_iff_le_factorization hn, iff_and_self]
exact fun _ H => lt_of_le_of_lt H (factorization_lt p hn)
theorem factorization_eq_card_pow_dvd (n : ℕ) {p : ℕ} (pp : p.Prime) :
n.factorization p = #{i ∈ Ico 1 n | p ^ i ∣ n} := by
simp [← Icc_factorization_eq_pow_dvd n pp]
theorem Ico_filter_pow_dvd_eq {n p b : ℕ} (pp : p.Prime) (hn : n ≠ 0) (hb : n ≤ p ^ b) :
{i ∈ Ico 1 n | p ^ i ∣ n} = {i ∈ Icc 1 b | p ^ i ∣ n} := by
ext x
simp only [Finset.mem_filter, mem_Ico, mem_Icc, and_congr_left_iff, and_congr_right_iff]
rintro h1 -
exact iff_of_true (lt_of_pow_dvd_right hn pp.two_le h1) <|
(Nat.pow_le_pow_iff_right pp.one_lt).1 <| (le_of_dvd hn.bot_lt h1).trans hb
/-! ### Factorization and coprimes -/
/-- If `p` is a prime factor of `a` then the power of `p` in `a` is the same that in `a * b`,
for any `b` coprime to `a`. -/
theorem factorization_eq_of_coprime_left {p a b : ℕ} (hab : Coprime a b)
(hpa : p ∈ a.primeFactorsList) : (a * b).factorization p = a.factorization p := by
rw [factorization_mul_apply_of_coprime hab, ← primeFactorsList_count_eq,
← primeFactorsList_count_eq,
count_eq_zero_of_not_mem (coprime_primeFactorsList_disjoint hab hpa), add_zero]
/-- If `p` is a prime factor of `b` then the power of `p` in `b` is the same that in `a * b`,
for any `a` coprime to `b`. -/
theorem factorization_eq_of_coprime_right {p a b : ℕ} (hab : Coprime a b)
(hpb : p ∈ b.primeFactorsList) : (a * b).factorization p = b.factorization p := by
rw [mul_comm]
exact factorization_eq_of_coprime_left (coprime_comm.mp hab) hpb
/-- Two positive naturals are equal if their prime padic valuations are equal -/
theorem eq_iff_prime_padicValNat_eq (a b : ℕ) (ha : a ≠ 0) (hb : b ≠ 0) :
a = b ↔ ∀ p : ℕ, p.Prime → padicValNat p a = padicValNat p b := by
constructor
· rintro rfl
simp
· intro h
refine eq_of_factorization_eq ha hb fun p => ?_
by_cases pp : p.Prime
· simp [factorization_def, pp, h p pp]
· simp [factorization_eq_zero_of_non_prime, pp]
theorem prod_pow_prime_padicValNat (n : Nat) (hn : n ≠ 0) (m : Nat) (pr : n < m) :
∏ p ∈ range m with p.Prime, p ^ padicValNat p n = n := by
nth_rw 2 [← factorization_prod_pow_eq_self hn]
rw [eq_comm]
apply Finset.prod_subset_one_on_sdiff
· exact fun p hp => Finset.mem_filter.mpr ⟨Finset.mem_range.2 <| pr.trans_le' <|
le_of_mem_primeFactors hp, prime_of_mem_primeFactors hp⟩
· intro p hp
obtain ⟨hp1, hp2⟩ := Finset.mem_sdiff.mp hp
rw [← factorization_def n (Finset.mem_filter.mp hp1).2]
simp [Finsupp.not_mem_support_iff.mp hp2]
· intro p hp
simp [factorization_def n (prime_of_mem_primeFactors hp)]
/-! ### Lemmas about factorizations of particular functions -/
-- TODO: Port lemmas from `Data/Nat/Multiplicity` to here, re-written in terms of `factorization`
/-- Exactly `n / p` naturals in `[1, n]` are multiples of `p`.
See `Nat.card_multiples'` for an alternative spelling of the statement. -/
theorem card_multiples (n p : ℕ) : #{e ∈ range n | p ∣ e + 1} = n / p := by
induction' n with n hn
· simp
simp [Nat.succ_div, add_ite, add_zero, Finset.range_succ, filter_insert, apply_ite card,
card_insert_of_not_mem, hn]
/-- Exactly `n / p` naturals in `(0, n]` are multiples of `p`. -/
theorem Ioc_filter_dvd_card_eq_div (n p : ℕ) : #{x ∈ Ioc 0 n | p ∣ x} = n / p := by
induction' n with n IH
· simp
-- TODO: Golf away `h1` after Yaël PRs a lemma asserting this
have h1 : Ioc 0 n.succ = insert n.succ (Ioc 0 n) := by
rcases n.eq_zero_or_pos with (rfl | hn)
· simp
simp_rw [← Ico_succ_succ, Ico_insert_right (succ_le_succ hn.le), Ico_succ_right]
simp [Nat.succ_div, add_ite, add_zero, h1, filter_insert, apply_ite card, card_insert_eq_ite, IH,
Finset.mem_filter, mem_Ioc, not_le.2 (lt_add_one n)]
/-- There are exactly `⌊N/n⌋` positive multiples of `n` that are `≤ N`.
See `Nat.card_multiples` for a "shifted-by-one" version. -/
lemma card_multiples' (N n : ℕ) : #{k ∈ range N.succ | k ≠ 0 ∧ n ∣ k} = N / n := by
induction N with
| zero => simp [Finset.filter_false_of_mem]
| succ N ih =>
rw [Finset.range_succ, Finset.filter_insert]
by_cases h : n ∣ N.succ
· simp [h, succ_div_of_dvd, ih]
· simp [h, succ_div_of_not_dvd, ih]
end Nat
| Mathlib/Data/Nat/Factorization/Basic.lean | 752 | 764 | |
/-
Copyright (c) 2021 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import Mathlib.Data.List.MinMax
import Mathlib.Algebra.Tropical.Basic
import Mathlib.Order.ConditionallyCompleteLattice.Finset
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
/-!
# Tropicalization of finitary operations
This file provides the "big-op" or notation-based finitary operations on tropicalized types.
This allows easy conversion between sums to Infs and prods to sums. Results here are important
for expressing that evaluation of tropical polynomials are the minimum over a finite piecewise
collection of linear functions.
## Main declarations
* `untrop_sum`
## Implementation notes
No concrete (semi)ring is used here, only ones with inferable order/lattice structure, to support
`Real`, `Rat`, `EReal`, and others (`ERat` is not yet defined).
Minima over `List α` are defined as producing a value in `WithTop α` so proofs about lists do not
directly transfer to minima over multisets or finsets.
-/
variable {R S : Type*}
open Tropical Finset
theorem List.trop_sum [AddMonoid R] (l : List R) : trop l.sum = List.prod (l.map trop) := by
induction' l with hd tl IH
· simp
· simp [← IH]
theorem Multiset.trop_sum [AddCommMonoid R] (s : Multiset R) :
trop s.sum = Multiset.prod (s.map trop) :=
Quotient.inductionOn s (by simpa using List.trop_sum)
theorem trop_sum [AddCommMonoid R] (s : Finset S) (f : S → R) :
trop (∑ i ∈ s, f i) = ∏ i ∈ s, trop (f i) := by
convert Multiset.trop_sum (s.val.map f)
simp only [Multiset.map_map, Function.comp_apply]
rfl
theorem List.untrop_prod [AddMonoid R] (l : List (Tropical R)) :
untrop l.prod = List.sum (l.map untrop) := by
induction' l with hd tl IH
· simp
· simp [← IH]
theorem Multiset.untrop_prod [AddCommMonoid R] (s : Multiset (Tropical R)) :
untrop s.prod = Multiset.sum (s.map untrop) :=
Quotient.inductionOn s (by simpa using List.untrop_prod)
theorem untrop_prod [AddCommMonoid R] (s : Finset S) (f : S → Tropical R) :
untrop (∏ i ∈ s, f i) = ∑ i ∈ s, untrop (f i) := by
convert Multiset.untrop_prod (s.val.map f)
simp only [Multiset.map_map, Function.comp_apply]
rfl
theorem List.trop_minimum [LinearOrder R] (l : List R) :
trop l.minimum = List.sum (l.map (trop ∘ WithTop.some)) := by
induction' l with hd tl IH
· simp
· simp [List.minimum_cons, ← IH]
theorem Multiset.trop_inf [LinearOrder R] [OrderTop R] (s : Multiset R) :
trop s.inf = Multiset.sum (s.map trop) := by
induction' s using Multiset.induction with s x IH
· simp
· simp [← IH]
theorem Finset.trop_inf [LinearOrder R] [OrderTop R] (s : Finset S) (f : S → R) :
trop (s.inf f) = ∑ i ∈ s, trop (f i) := by
convert Multiset.trop_inf (s.val.map f)
simp only [Multiset.map_map, Function.comp_apply]
| rfl
theorem trop_sInf_image [ConditionallyCompleteLinearOrder R] (s : Finset S) (f : S → WithTop R) :
trop (sInf (f '' s)) = ∑ i ∈ s, trop (f i) := by
rcases s.eq_empty_or_nonempty with (rfl | h)
| Mathlib/Algebra/Tropical/BigOperators.lean | 85 | 89 |
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Algebra.Order.Field.Pi
import Mathlib.Algebra.Order.Pi
import Mathlib.Analysis.Normed.Field.Basic
import Mathlib.Analysis.Normed.Group.Pointwise
import Mathlib.Topology.Algebra.Order.UpperLower
import Mathlib.Topology.MetricSpace.Sequences
/-!
# Upper/lower/order-connected sets in normed groups
The topological closure and interior of an upper/lower/order-connected set is an
upper/lower/order-connected set (with the notable exception of the closure of an order-connected
set).
We also prove lemmas specific to `ℝⁿ`. Those are helpful to prove that order-connected sets in `ℝⁿ`
are measurable.
## TODO
Is there a way to generalise `IsClosed.upperClosure_pi`/`IsClosed.lowerClosure_pi` so that they also
apply to `ℝ`, `ℝ × ℝ`, `EuclideanSpace ι ℝ`? `_pi` has been appended to their names to disambiguate
from the other possible lemmas, but we will want there to be a single set of lemmas for all
situations.
-/
open Bornology Function Metric Set
open scoped Pointwise
variable {α ι : Type*}
section NormedOrderedGroup
variable [NormedCommGroup α] [PartialOrder α] [IsOrderedMonoid α] {s : Set α}
@[to_additive IsUpperSet.thickening]
protected theorem IsUpperSet.thickening' (hs : IsUpperSet s) (ε : ℝ) :
IsUpperSet (thickening ε s) := by
rw [← ball_mul_one]
exact hs.mul_left
@[to_additive IsLowerSet.thickening]
protected theorem IsLowerSet.thickening' (hs : IsLowerSet s) (ε : ℝ) :
IsLowerSet (thickening ε s) := by
rw [← ball_mul_one]
exact hs.mul_left
@[to_additive IsUpperSet.cthickening]
protected theorem IsUpperSet.cthickening' (hs : IsUpperSet s) (ε : ℝ) :
IsUpperSet (cthickening ε s) := by
rw [cthickening_eq_iInter_thickening'']
exact isUpperSet_iInter₂ fun δ _ => hs.thickening' _
@[to_additive IsLowerSet.cthickening]
protected theorem IsLowerSet.cthickening' (hs : IsLowerSet s) (ε : ℝ) :
IsLowerSet (cthickening ε s) := by
rw [cthickening_eq_iInter_thickening'']
exact isLowerSet_iInter₂ fun δ _ => hs.thickening' _
@[to_additive upperClosure_interior_subset] lemma upperClosure_interior_subset' (s : Set α) :
(upperClosure (interior s) : Set α) ⊆ interior (upperClosure s) :=
upperClosure_min (interior_mono subset_upperClosure) (upperClosure s).upper.interior
|
@[to_additive lowerClosure_interior_subset] lemma lowerClosure_interior_subset' (s : Set α) :
(lowerClosure (interior s) : Set α) ⊆ interior (lowerClosure s) :=
lowerClosure_min (interior_mono subset_lowerClosure) (lowerClosure s).lower.interior
| Mathlib/Analysis/Normed/Order/UpperLower.lean | 66 | 69 |
/-
Copyright (c) 2023 Dagur Asgeirsson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dagur Asgeirsson
-/
import Mathlib.CategoryTheory.Limits.Shapes.Countable
import Mathlib.Topology.Category.Profinite.AsLimit
import Mathlib.Topology.Category.Profinite.CofilteredLimit
import Mathlib.Topology.ClopenBox
/-!
# Light profinite spaces
We construct the category `LightProfinite` of light profinite topological spaces. These are
implemented as totally disconnected second countable compact Hausdorff spaces.
This file also defines the category `LightDiagram`, which consists of those spaces that can be
written as a sequential limit (in `Profinite`) of finite sets.
We define an equivalence of categories `LightProfinite ≌ LightDiagram` and prove that these are
essentially small categories.
## Implementation
The category `LightProfinite` is defined using the structure `CompHausLike`. See the file
`CompHausLike.Basic` for more information.
-/
/- The basic API for `LightProfinite` is largely copied from the API of `Profinite`;
where possible, try to keep them in sync -/
universe v u
open CategoryTheory Limits Opposite FintypeCat Topology TopologicalSpace CompHausLike
/-- `LightProfinite` is the category of second countable profinite spaces. -/
abbrev LightProfinite := CompHausLike
(fun X ↦ TotallyDisconnectedSpace X ∧ SecondCountableTopology X)
namespace LightProfinite
instance (X : Type*) [TopologicalSpace X]
[TotallyDisconnectedSpace X] [SecondCountableTopology X] : HasProp (fun Y ↦
TotallyDisconnectedSpace Y ∧ SecondCountableTopology Y) X :=
⟨⟨(inferInstance : TotallyDisconnectedSpace X), (inferInstance : SecondCountableTopology X)⟩⟩
/--
Construct a term of `LightProfinite` from a type endowed with the structure of a compact,
Hausdorff, totally disconnected and second countable topological space.
-/
abbrev of (X : Type*) [TopologicalSpace X] [CompactSpace X] [T2Space X]
[TotallyDisconnectedSpace X] [SecondCountableTopology X] : LightProfinite :=
CompHausLike.of _ X
instance : Inhabited LightProfinite :=
⟨LightProfinite.of PEmpty⟩
instance {X : LightProfinite} : TotallyDisconnectedSpace X :=
X.prop.1
instance {X : LightProfinite} : SecondCountableTopology X :=
X.prop.2
end LightProfinite
/-- The fully faithful embedding of `LightProfinite` in `Profinite`. -/
abbrev lightToProfinite : LightProfinite ⥤ Profinite :=
CompHausLike.toCompHausLike (fun _ ↦ inferInstance)
/-- `lightToProfinite` is fully faithful. -/
abbrev lightToProfiniteFullyFaithful : lightToProfinite.FullyFaithful :=
fullyFaithfulToCompHausLike _
/-- The fully faithful embedding of `LightProfinite` in `CompHaus`. -/
abbrev lightProfiniteToCompHaus : LightProfinite ⥤ CompHaus :=
compHausLikeToCompHaus _
/-- The fully faithful embedding of `LightProfinite` in `TopCat`.
This is definitionally the same as the obvious composite. -/
abbrev LightProfinite.toTopCat : LightProfinite ⥤ TopCat :=
CompHausLike.compHausLikeToTop _
section DiscreteTopology
attribute [local instance] FintypeCat.botTopology
attribute [local instance] FintypeCat.discreteTopology
/-- The natural functor from `Fintype` to `LightProfinite`, endowing a finite type with the
discrete topology. -/
@[simps! -isSimp map_hom_apply]
def FintypeCat.toLightProfinite : FintypeCat ⥤ LightProfinite where
obj A := LightProfinite.of A
map f := CompHausLike.ofHom _ ⟨f, by continuity⟩
/-- `FintypeCat.toLightProfinite` is fully faithful. -/
def FintypeCat.toLightProfiniteFullyFaithful : toLightProfinite.FullyFaithful where
preimage f := (f : _ → _)
map_preimage _ := rfl
preimage_map _ := rfl
instance : FintypeCat.toLightProfinite.Faithful :=
FintypeCat.toLightProfiniteFullyFaithful.faithful
instance : FintypeCat.toLightProfinite.Full :=
FintypeCat.toLightProfiniteFullyFaithful.full
instance (X : FintypeCat.{u}) : Fintype (FintypeCat.toLightProfinite.obj X) :=
inferInstanceAs (Fintype X)
instance (X : FintypeCat.{u}) : Fintype (LightProfinite.of X) := inferInstanceAs (Fintype X)
end DiscreteTopology
namespace LightProfinite
instance {J : Type v} [SmallCategory J] (F : J ⥤ LightProfinite.{max u v}) :
TotallyDisconnectedSpace
(CompHaus.limitCone.{v, u} (F ⋙ lightProfiniteToCompHaus)).pt.toTop := by
change TotallyDisconnectedSpace ({ u : ∀ j : J, F.obj j | _ } : Type _)
exact Subtype.totallyDisconnectedSpace
/-- An explicit limit cone for a functor `F : J ⥤ LightProfinite`, for a countable category `J`
defined in terms of `CompHaus.limitCone`, which is defined in terms of `TopCat.limitCone`. -/
def limitCone {J : Type v} [SmallCategory J] [CountableCategory J]
(F : J ⥤ LightProfinite.{max u v}) :
Limits.Cone F where
pt :=
{ toTop := (CompHaus.limitCone.{v, u} (F ⋙ lightProfiniteToCompHaus)).pt.toTop
prop := by
constructor
· infer_instance
· change SecondCountableTopology ({ u : ∀ j : J, F.obj j | _ } : Type _)
apply IsInducing.subtypeVal.secondCountableTopology }
π :=
{ app := (CompHaus.limitCone.{v, u} (F ⋙ lightProfiniteToCompHaus)).π.app
naturality := by
intro j k f
ext ⟨g, p⟩
exact (p f).symm }
/-- The limit cone `LightProfinite.limitCone F` is indeed a limit cone. -/
def limitConeIsLimit {J : Type v} [SmallCategory J] [CountableCategory J]
(F : J ⥤ LightProfinite.{max u v}) :
Limits.IsLimit (limitCone F) where
lift S :=
(CompHaus.limitConeIsLimit.{v, u} (F ⋙ lightProfiniteToCompHaus)).lift
(lightProfiniteToCompHaus.mapCone S)
uniq S _ h := (CompHaus.limitConeIsLimit.{v, u} _).uniq (lightProfiniteToCompHaus.mapCone S) _ h
noncomputable instance createsCountableLimits {J : Type v} [SmallCategory J] [CountableCategory J] :
CreatesLimitsOfShape J lightToProfinite.{max v u} where
CreatesLimit {F} :=
createsLimitOfFullyFaithfulOfIso (limitCone.{v, u} F).pt <|
(Profinite.limitConeIsLimit.{v, u} (F ⋙ lightToProfinite)).conePointUniqueUpToIso
(limit.isLimit _)
instance : HasCountableLimits LightProfinite where
out _ := { has_limit := fun F ↦ ⟨limitCone F, limitConeIsLimit F⟩ }
instance : PreservesLimitsOfShape ℕᵒᵖ (forget LightProfinite.{u}) :=
have : PreservesLimitsOfSize.{0, 0} (forget Profinite.{u}) := preservesLimitsOfSize_shrink _
inferInstanceAs (PreservesLimitsOfShape ℕᵒᵖ (lightToProfinite ⋙ forget Profinite))
variable {X Y : LightProfinite.{u}} (f : X ⟶ Y)
/-- Any morphism of light profinite spaces is a closed map. -/
theorem isClosedMap : IsClosedMap f :=
CompHausLike.isClosedMap _
/-- Any continuous bijection of light profinite spaces induces an isomorphism. -/
theorem isIso_of_bijective (bij : Function.Bijective f) : IsIso f :=
haveI := CompHausLike.isIso_of_bijective (lightProfiniteToCompHaus.map f) bij
isIso_of_fully_faithful lightProfiniteToCompHaus _
/-- Any continuous bijection of light profinite spaces induces an isomorphism. -/
noncomputable def isoOfBijective (bij : Function.Bijective f) : X ≅ Y :=
letI := LightProfinite.isIso_of_bijective f bij
asIso f
instance forget_reflectsIsomorphisms : (forget LightProfinite).ReflectsIsomorphisms := by
constructor
intro A B f hf
rw [isIso_iff_bijective] at hf
exact LightProfinite.isIso_of_bijective _ hf
theorem epi_iff_surjective {X Y : LightProfinite.{u}} (f : X ⟶ Y) :
Epi f ↔ Function.Surjective f := by
constructor
· -- Note: in mathlib3 `contrapose` saw through `Function.Surjective`.
dsimp [Function.Surjective]
contrapose!
rintro ⟨y, hy⟩ hf
let C := Set.range f
have hC : IsClosed C := (isCompact_range f.hom.continuous).isClosed
let U := Cᶜ
have hyU : y ∈ U := by
refine Set.mem_compl ?_
rintro ⟨y', hy'⟩
exact hy y' hy'
have hUy : U ∈ 𝓝 y := hC.compl_mem_nhds hyU
obtain ⟨V, hV, hyV, hVU⟩ := isTopologicalBasis_isClopen.mem_nhds_iff.mp hUy
classical
let Z := of (ULift.{u} <| Fin 2)
let g : Y ⟶ Z := CompHausLike.ofHom _
⟨(LocallyConstant.ofIsClopen hV).map ULift.up, LocallyConstant.continuous _⟩
let h : Y ⟶ Z := CompHausLike.ofHom _ ⟨fun _ => ⟨1⟩, continuous_const⟩
have H : h = g := by
rw [← cancel_epi f]
ext x
dsimp [g, LocallyConstant.ofIsClopen]
rw [ContinuousMap.coe_mk, ContinuousMap.coe_mk, hom_ofHom, ContinuousMap.coe_mk,
Function.comp_apply, if_neg]
refine mt (fun α => hVU α) ?_
simp [U, C]
apply_fun fun e => (e y).down at H
dsimp [g, LocallyConstant.ofIsClopen] at H
rw [ContinuousMap.coe_mk, ContinuousMap.coe_mk, Function.comp_apply, if_pos hyV] at H
exact top_ne_bot H
· rw [← CategoryTheory.epi_iff_surjective]
apply (forget LightProfinite).epi_of_epi_map
instance : lightToProfinite.PreservesEpimorphisms where
preserves f _ := (Profinite.epi_iff_surjective _).mpr ((epi_iff_surjective f).mp inferInstance)
end LightProfinite
/-- A structure containing the data of sequential limit in `Profinite` of finite sets. -/
structure LightDiagram : Type (u+1) where
/-- The indexing diagram. -/
diagram : ℕᵒᵖ ⥤ FintypeCat
/-- The limit cone. -/
cone : Cone (diagram ⋙ FintypeCat.toProfinite.{u})
/-- The limit cone is limiting. -/
isLimit : IsLimit cone
namespace LightDiagram
/-- The underlying `Profinite` of a `LightDiagram`. -/
def toProfinite (S : LightDiagram) : Profinite := S.cone.pt
@[simps!]
instance : Category LightDiagram := InducedCategory.category toProfinite
instance hasForget : ConcreteCategory LightDiagram (fun X Y => C(X.toProfinite, Y.toProfinite)) :=
InducedCategory.concreteCategory toProfinite
end LightDiagram
/-- The fully faithful embedding `LightDiagram ⥤ Profinite` -/
@[simps!]
def lightDiagramToProfinite : LightDiagram ⥤ Profinite := inducedFunctor _
instance : lightDiagramToProfinite.Faithful := show (inducedFunctor _).Faithful from inferInstance
instance : lightDiagramToProfinite.Full := show (inducedFunctor _).Full from inferInstance
namespace LightProfinite
instance (S : LightProfinite) : Countable (Clopens S) := by
rw [TopologicalSpace.Clopens.countable_iff_secondCountable]
infer_instance
instance instCountableDiscreteQuotient (S : LightProfinite) :
Countable (DiscreteQuotient ((lightToProfinite.obj S))) :=
(DiscreteQuotient.finsetClopens_inj S).countable
/-- A profinite space which is light gives rise to a light profinite space. -/
noncomputable def toLightDiagram (S : LightProfinite.{u}) : LightDiagram.{u} where
diagram := IsCofiltered.sequentialFunctor _ ⋙ (lightToProfinite.obj S).fintypeDiagram
cone := (Functor.Initial.limitConeComp (IsCofiltered.sequentialFunctor _)
(lightToProfinite.obj S).lim).cone
isLimit := (Functor.Initial.limitConeComp (IsCofiltered.sequentialFunctor _)
(lightToProfinite.obj S).lim).isLimit
end LightProfinite
/-- The functor part of the equivalence `LightProfinite ≌ LightDiagram` -/
@[simps]
noncomputable def lightProfiniteToLightDiagram : LightProfinite.{u} ⥤ LightDiagram.{u} where
obj X := X.toLightDiagram
map f := f
open scoped Classical in
instance (S : LightDiagram.{u}) : SecondCountableTopology S.cone.pt := by
rw [← TopologicalSpace.Clopens.countable_iff_secondCountable]
refine @Countable.of_equiv _ _ ?_ (LocallyConstant.equivClopens (X := S.cone.pt))
refine @Function.Surjective.countable
(Σ (n : ℕ), LocallyConstant ((S.diagram ⋙ FintypeCat.toProfinite).obj ⟨n⟩) (Fin 2)) _ ?_ ?_ ?_
· apply @instCountableSigma _ _ _ ?_
intro n
refine @Finite.to_countable _ ?_
refine @Finite.of_injective _ ((S.diagram ⋙ FintypeCat.toProfinite).obj ⟨n⟩ → (Fin 2)) ?_ _
LocallyConstant.coe_injective
refine @Pi.finite _ _ ?_ _
simp only [Functor.comp_obj]
exact show (Finite (S.diagram.obj _)) from inferInstance
· exact fun a ↦ a.snd.comap (S.cone.π.app ⟨a.fst⟩).hom
· intro a
obtain ⟨n, g, h⟩ := Profinite.exists_locallyConstant S.cone S.isLimit a
exact ⟨⟨unop n, g⟩, h.symm⟩
/-- The inverse part of the equivalence `LightProfinite ≌ LightDiagram` -/
@[simps obj map]
def lightDiagramToLightProfinite : LightDiagram.{u} ⥤ LightProfinite.{u} where
obj X := LightProfinite.of X.cone.pt
map f := f
/-- The equivalence of categories `LightProfinite ≌ LightDiagram` -/
noncomputable def LightProfinite.equivDiagram : LightProfinite.{u} ≌ LightDiagram.{u} where
functor := lightProfiniteToLightDiagram
inverse := lightDiagramToLightProfinite
unitIso := Iso.refl _
counitIso := NatIso.ofComponents
(fun _ ↦ lightDiagramToProfinite.preimageIso (Iso.refl _)) (by
intro _ _ f
simp only [Functor.comp_obj, lightDiagramToLightProfinite_obj,
lightProfiniteToLightDiagram_obj, Functor.id_obj, Functor.comp_map,
lightDiagramToLightProfinite_map, lightProfiniteToLightDiagram_map,
lightDiagramToProfinite_obj, Functor.preimageIso_hom, Iso.refl_hom, Functor.id_map]
erw [lightDiagramToProfinite.preimage_id, lightDiagramToProfinite.preimage_id,
| Category.comp_id f])
functor_unitIso_comp _ := by simpa using lightDiagramToProfinite.preimage_id
instance : lightProfiniteToLightDiagram.IsEquivalence :=
show LightProfinite.equivDiagram.functor.IsEquivalence from inferInstance
instance : lightDiagramToLightProfinite.IsEquivalence :=
show LightProfinite.equivDiagram.inverse.IsEquivalence from inferInstance
noncomputable section EssentiallySmall
open LightDiagram
/--
| Mathlib/Topology/Category/LightProfinite/Basic.lean | 322 | 335 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Data.ENNReal.Action
import Mathlib.MeasureTheory.MeasurableSpace.Constructions
import Mathlib.MeasureTheory.OuterMeasure.Caratheodory
/-!
# Induced Outer Measure
We can extend a function defined on a subset of `Set α` to an outer measure.
The underlying function is called `extend`, and the measure it induces is called
`inducedOuterMeasure`.
Some lemmas below are proven twice, once in the general case, and one where the function `m`
is only defined on measurable sets (i.e. when `P = MeasurableSet`). In the latter cases, we can
remove some hypotheses in the statement. The general version has the same name, but with a prime
at the end.
## Tags
outer measure
-/
noncomputable section
open Set Function Filter
open scoped NNReal Topology ENNReal
namespace MeasureTheory
open OuterMeasure
section Extend
variable {α : Type*} {P : α → Prop}
variable (m : ∀ s : α, P s → ℝ≥0∞)
/-- We can trivially extend a function defined on a subclass of objects (with codomain `ℝ≥0∞`)
to all objects by defining it to be `∞` on the objects not in the class. -/
def extend (s : α) : ℝ≥0∞ :=
⨅ h : P s, m s h
theorem extend_eq {s : α} (h : P s) : extend m s = m s h := by simp [extend, h]
theorem extend_eq_top {s : α} (h : ¬P s) : extend m s = ∞ := by simp [extend, h]
theorem smul_extend {R} [Zero R] [SMulWithZero R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
[NoZeroSMulDivisors R ℝ≥0∞] {c : R} (hc : c ≠ 0) :
c • extend m = extend fun s h => c • m s h := by
classical
ext1 s
dsimp [extend]
by_cases h : P s
· simp [h]
· simp [h, ENNReal.smul_top, hc]
theorem le_extend {s : α} (h : P s) : m s h ≤ extend m s := by
simp only [extend, le_iInf_iff]
intro
rfl
-- TODO: why this is a bad `congr` lemma?
theorem extend_congr {β : Type*} {Pb : β → Prop} {mb : ∀ s : β, Pb s → ℝ≥0∞} {sa : α} {sb : β}
(hP : P sa ↔ Pb sb) (hm : ∀ (ha : P sa) (hb : Pb sb), m sa ha = mb sb hb) :
extend m sa = extend mb sb :=
iInf_congr_Prop hP fun _h => hm _ _
@[simp]
theorem extend_top {α : Type*} {P : α → Prop} : extend (fun _ _ => ∞ : ∀ s : α, P s → ℝ≥0∞) = ⊤ :=
funext fun _ => iInf_eq_top.mpr fun _ => rfl
end Extend
section ExtendSet
variable {α : Type*} {P : Set α → Prop}
variable {m : ∀ s : Set α, P s → ℝ≥0∞}
variable (P0 : P ∅) (m0 : m ∅ P0 = 0)
variable (PU : ∀ ⦃f : ℕ → Set α⦄ (_hm : ∀ i, P (f i)), P (⋃ i, f i))
variable
(mU :
∀ ⦃f : ℕ → Set α⦄ (hm : ∀ i, P (f i)),
Pairwise (Disjoint on f) → m (⋃ i, f i) (PU hm) = ∑' i, m (f i) (hm i))
variable (msU : ∀ ⦃f : ℕ → Set α⦄ (hm : ∀ i, P (f i)), m (⋃ i, f i) (PU hm) ≤ ∑' i, m (f i) (hm i))
variable (m_mono : ∀ ⦃s₁ s₂ : Set α⦄ (hs₁ : P s₁) (hs₂ : P s₂), s₁ ⊆ s₂ → m s₁ hs₁ ≤ m s₂ hs₂)
theorem extend_iUnion_nat {f : ℕ → Set α} (hm : ∀ i, P (f i))
(mU : m (⋃ i, f i) (PU hm) = ∑' i, m (f i) (hm i)) :
extend m (⋃ i, f i) = ∑' i, extend m (f i) :=
(extend_eq _ _).trans <|
mU.trans <| by
congr with i
rw [extend_eq]
include P0 m0 in
theorem extend_empty : extend m ∅ = 0 :=
(extend_eq _ P0).trans m0
section Subadditive
include PU msU in
theorem extend_iUnion_le_tsum_nat' (s : ℕ → Set α) :
extend m (⋃ i, s i) ≤ ∑' i, extend m (s i) := by
by_cases h : ∀ i, P (s i)
· rw [extend_eq _ (PU h), congr_arg tsum _]
· apply msU h
funext i
apply extend_eq _ (h i)
· obtain ⟨i, hi⟩ := not_forall.1 h
exact le_trans (le_iInf fun h => hi.elim h) (ENNReal.le_tsum i)
end Subadditive
section Mono
include m_mono in
theorem extend_mono' ⦃s₁ s₂ : Set α⦄ (h₁ : P s₁) (hs : s₁ ⊆ s₂) : extend m s₁ ≤ extend m s₂ := by
refine le_iInf ?_
intro h₂
rw [extend_eq m h₁]
exact m_mono h₁ h₂ hs
end Mono
section Unions
include P0 m0 PU mU in
theorem extend_iUnion {β} [Countable β] {f : β → Set α} (hd : Pairwise (Disjoint on f))
(hm : ∀ i, P (f i)) : extend m (⋃ i, f i) = ∑' i, extend m (f i) := by
cases nonempty_encodable β
rw [← Encodable.iUnion_decode₂, ← tsum_iUnion_decode₂]
· exact
extend_iUnion_nat PU (fun n => Encodable.iUnion_decode₂_cases P0 hm)
(mU _ (Encodable.iUnion_decode₂_disjoint_on hd))
· exact extend_empty P0 m0
include P0 m0 PU mU in
theorem extend_union {s₁ s₂ : Set α} (hd : Disjoint s₁ s₂) (h₁ : P s₁) (h₂ : P s₂) :
extend m (s₁ ∪ s₂) = extend m s₁ + extend m s₂ := by
rw [union_eq_iUnion,
extend_iUnion P0 m0 PU mU (pairwise_disjoint_on_bool.2 hd) (Bool.forall_bool.2 ⟨h₂, h₁⟩),
tsum_fintype]
simp
end Unions
variable (m)
/-- Given an arbitrary function on a subset of sets, we can define the outer measure corresponding
to it (this is the unique maximal outer measure that is at most `m` on the domain of `m`). -/
def inducedOuterMeasure : OuterMeasure α :=
OuterMeasure.ofFunction (extend m) (extend_empty P0 m0)
variable {m P0 m0}
theorem le_inducedOuterMeasure {μ : OuterMeasure α} :
μ ≤ inducedOuterMeasure m P0 m0 ↔ ∀ (s) (hs : P s), μ s ≤ m s hs :=
le_ofFunction.trans <| forall_congr' fun _s => le_iInf_iff
/-- If `P u` is `False` for any set `u` that has nonempty intersection both with `s` and `t`, then
`μ (s ∪ t) = μ s + μ t`, where `μ = inducedOuterMeasure m P0 m0`.
E.g., if `α` is an (e)metric space and `P u = diam u < r`, then this lemma implies that
`μ (s ∪ t) = μ s + μ t` on any two sets such that `r ≤ edist x y` for all `x ∈ s` and `y ∈ t`. -/
theorem inducedOuterMeasure_union_of_false_of_nonempty_inter {s t : Set α}
(h : ∀ u, (s ∩ u).Nonempty → (t ∩ u).Nonempty → ¬P u) :
inducedOuterMeasure m P0 m0 (s ∪ t) =
inducedOuterMeasure m P0 m0 s + inducedOuterMeasure m P0 m0 t :=
ofFunction_union_of_top_of_nonempty_inter fun u hsu htu => @iInf_of_empty _ _ _ ⟨h u hsu htu⟩ _
include PU msU m_mono
theorem inducedOuterMeasure_eq_extend' {s : Set α} (hs : P s) :
inducedOuterMeasure m P0 m0 s = extend m s :=
ofFunction_eq s (fun _t => extend_mono' m_mono hs) (extend_iUnion_le_tsum_nat' PU msU)
theorem inducedOuterMeasure_eq' {s : Set α} (hs : P s) : inducedOuterMeasure m P0 m0 s = m s hs :=
(inducedOuterMeasure_eq_extend' PU msU m_mono hs).trans <| extend_eq _ _
theorem inducedOuterMeasure_eq_iInf (s : Set α) :
inducedOuterMeasure m P0 m0 s = ⨅ (t : Set α) (ht : P t) (_ : s ⊆ t), m t ht := by
apply le_antisymm
· simp only [le_iInf_iff]
intro t ht hs
refine le_trans (measure_mono hs) ?_
exact le_of_eq (inducedOuterMeasure_eq' _ msU m_mono _)
· refine le_iInf ?_
intro f
refine le_iInf ?_
intro hf
refine le_trans ?_ (extend_iUnion_le_tsum_nat' _ msU _)
refine le_iInf ?_
intro h2f
exact iInf_le_of_le _ (iInf_le_of_le h2f <| iInf_le _ hf)
theorem inducedOuterMeasure_preimage (f : α ≃ α) (Pm : ∀ s : Set α, P (f ⁻¹' s) ↔ P s)
(mm : ∀ (s : Set α) (hs : P s), m (f ⁻¹' s) ((Pm _).mpr hs) = m s hs) {A : Set α} :
inducedOuterMeasure m P0 m0 (f ⁻¹' A) = inducedOuterMeasure m P0 m0 A := by
rw [inducedOuterMeasure_eq_iInf _ msU m_mono, inducedOuterMeasure_eq_iInf _ msU m_mono]; symm
refine f.injective.preimage_surjective.iInf_congr (preimage f) fun s => ?_
refine iInf_congr_Prop (Pm s) ?_; intro hs
refine iInf_congr_Prop f.surjective.preimage_subset_preimage_iff ?_
intro _; exact mm s hs
theorem inducedOuterMeasure_exists_set {s : Set α} (hs : inducedOuterMeasure m P0 m0 s ≠ ∞)
{ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ t : Set α,
P t ∧ s ⊆ t ∧ inducedOuterMeasure m P0 m0 t ≤ inducedOuterMeasure m P0 m0 s + ε := by
have h := ENNReal.lt_add_right hs hε
conv at h =>
lhs
rw [inducedOuterMeasure_eq_iInf _ msU m_mono]
simp only [iInf_lt_iff] at h
rcases h with ⟨t, h1t, h2t, h3t⟩
exact
⟨t, h1t, h2t, le_trans (le_of_eq <| inducedOuterMeasure_eq' _ msU m_mono h1t) (le_of_lt h3t)⟩
/-- To test whether `s` is Carathéodory-measurable we only need to check the sets `t` for which
`P t` holds. See `ofFunction_caratheodory` for another way to show the Carathéodory-measurability
of `s`.
-/
theorem inducedOuterMeasure_caratheodory (s : Set α) :
MeasurableSet[(inducedOuterMeasure m P0 m0).caratheodory] s ↔
∀ t : Set α,
P t →
inducedOuterMeasure m P0 m0 (t ∩ s) + inducedOuterMeasure m P0 m0 (t \ s) ≤
inducedOuterMeasure m P0 m0 t := by
rw [isCaratheodory_iff_le]
constructor
· intro h t _ht
exact h t
· intro h u
conv_rhs => rw [inducedOuterMeasure_eq_iInf _ msU m_mono]
refine le_iInf ?_
intro t
refine le_iInf ?_
intro ht
refine le_iInf ?_
intro h2t
refine le_trans ?_ ((h t ht).trans_eq <| inducedOuterMeasure_eq' _ msU m_mono ht)
gcongr
end ExtendSet
/-! If `P` is `MeasurableSet` for some measurable space, then we can remove some hypotheses of the
above lemmas. -/
section MeasurableSpace
variable {α : Type*} [MeasurableSpace α]
variable {m : ∀ s : Set α, MeasurableSet s → ℝ≥0∞}
variable (m0 : m ∅ MeasurableSet.empty = 0)
variable
(mU :
∀ ⦃f : ℕ → Set α⦄ (hm : ∀ i, MeasurableSet (f i)),
Pairwise (Disjoint on f) → m (⋃ i, f i) (MeasurableSet.iUnion hm) = ∑' i, m (f i) (hm i))
include m0 mU
theorem extend_mono {s₁ s₂ : Set α} (h₁ : MeasurableSet s₁) (hs : s₁ ⊆ s₂) :
extend m s₁ ≤ extend m s₂ := by
refine le_iInf ?_; intro h₂
have :=
extend_union MeasurableSet.empty m0 MeasurableSet.iUnion mU disjoint_sdiff_self_right h₁
(h₂.diff h₁)
rw [union_diff_cancel hs] at this
rw [← extend_eq m]
exact le_iff_exists_add.2 ⟨_, this⟩
theorem extend_iUnion_le_tsum_nat : ∀ s : ℕ → Set α,
extend m (⋃ i, s i) ≤ ∑' i, extend m (s i) := by
refine extend_iUnion_le_tsum_nat' MeasurableSet.iUnion ?_; intro f h
simp +singlePass only [iUnion_disjointed.symm]
rw [mU (MeasurableSet.disjointed h) (disjoint_disjointed _)]
refine ENNReal.tsum_le_tsum fun i => ?_
rw [← extend_eq m, ← extend_eq m]
exact extend_mono m0 mU (MeasurableSet.disjointed h _) (disjointed_le f _)
theorem inducedOuterMeasure_eq_extend {s : Set α} (hs : MeasurableSet s) :
inducedOuterMeasure m MeasurableSet.empty m0 s = extend m s :=
ofFunction_eq s (fun _t => extend_mono m0 mU hs) (extend_iUnion_le_tsum_nat m0 mU)
theorem inducedOuterMeasure_eq {s : Set α} (hs : MeasurableSet s) :
inducedOuterMeasure m MeasurableSet.empty m0 s = m s hs :=
(inducedOuterMeasure_eq_extend m0 mU hs).trans <| extend_eq _ _
end MeasurableSpace
namespace OuterMeasure
variable {α : Type*} [MeasurableSpace α] (m : OuterMeasure α)
/-- Given an outer measure `m` we can forget its value on non-measurable sets, and then consider
`m.trim`, the unique maximal outer measure less than that function. -/
def trim : OuterMeasure α :=
inducedOuterMeasure (P := MeasurableSet) (fun s _ => m s) .empty m.empty
theorem le_trim_iff {m₁ m₂ : OuterMeasure α} :
m₁ ≤ m₂.trim ↔ ∀ s, MeasurableSet s → m₁ s ≤ m₂ s :=
le_inducedOuterMeasure
theorem le_trim : m ≤ m.trim := le_trim_iff.2 fun _ _ ↦ le_rfl
lemma null_of_trim_null {s : Set α} (h : m.trim s = 0) : m s = 0 :=
nonpos_iff_eq_zero.1 <| (le_trim m s).trans_eq h
@[simp]
theorem trim_eq {s : Set α} (hs : MeasurableSet s) : m.trim s = m s :=
inducedOuterMeasure_eq' MeasurableSet.iUnion (fun f _hf => measure_iUnion_le f)
(fun _ _ _ _ h => measure_mono h) hs
theorem trim_congr {m₁ m₂ : OuterMeasure α} (H : ∀ {s : Set α}, MeasurableSet s → m₁ s = m₂ s) :
m₁.trim = m₂.trim := by
simp +contextual only [trim, H]
@[mono]
theorem trim_mono : Monotone (trim : OuterMeasure α → OuterMeasure α) := fun _m₁ _m₂ H _s =>
iInf₂_mono fun _f _hs => ENNReal.tsum_le_tsum fun _b => iInf_mono fun _hf => H _
/-- `OuterMeasure.trim` is antitone in the σ-algebra. -/
theorem trim_anti_measurableSpace {α} (m : OuterMeasure α) {m0 m1 : MeasurableSpace α}
(h : m0 ≤ m1) : @trim _ m1 m ≤ @trim _ m0 m := by
simp only [le_trim_iff]
intro s hs
rw [trim_eq _ (h s hs)]
theorem trim_le_trim_iff {m₁ m₂ : OuterMeasure α} :
m₁.trim ≤ m₂.trim ↔ ∀ s, MeasurableSet s → m₁ s ≤ m₂ s :=
le_trim_iff.trans <| forall₂_congr fun s hs => by rw [trim_eq _ hs]
theorem trim_eq_trim_iff {m₁ m₂ : OuterMeasure α} :
m₁.trim = m₂.trim ↔ ∀ s, MeasurableSet s → m₁ s = m₂ s := by
simp only [le_antisymm_iff, trim_le_trim_iff, forall_and]
theorem trim_eq_iInf (s : Set α) : m.trim s = ⨅ (t) (_ : s ⊆ t) (_ : MeasurableSet t), m t := by
simp +singlePass only [iInf_comm]
exact
inducedOuterMeasure_eq_iInf MeasurableSet.iUnion (fun f _ => measure_iUnion_le f)
(fun _ _ _ _ h => measure_mono h) s
theorem trim_eq_iInf' (s : Set α) : m.trim s = ⨅ t : { t // s ⊆ t ∧ MeasurableSet t }, m t := by
simp [iInf_subtype, iInf_and, trim_eq_iInf]
theorem trim_trim (m : OuterMeasure α) : m.trim.trim = m.trim :=
trim_eq_trim_iff.2 fun _s => m.trim_eq
@[simp]
theorem trim_top : (⊤ : OuterMeasure α).trim = ⊤ :=
top_unique <| le_trim _
@[simp]
theorem trim_zero : (0 : OuterMeasure α).trim = 0 :=
ext fun s =>
le_antisymm
((measure_mono (subset_univ s)).trans_eq <| trim_eq _ MeasurableSet.univ)
(zero_le _)
theorem trim_sum_ge {ι} (m : ι → OuterMeasure α) : (sum fun i => (m i).trim) ≤ (sum m).trim :=
fun s => by
simp only [sum_apply, trim_eq_iInf, le_iInf_iff]
exact fun t st ht =>
ENNReal.tsum_le_tsum fun i => iInf_le_of_le t <| iInf_le_of_le st <| iInf_le _ ht
theorem exists_measurable_superset_eq_trim (m : OuterMeasure α) (s : Set α) :
∃ t, s ⊆ t ∧ MeasurableSet t ∧ m t = m.trim s := by
simp only [trim_eq_iInf]; set ms := ⨅ (t : Set α) (_ : s ⊆ t) (_ : MeasurableSet t), m t
by_cases hs : ms = ∞
· simp only [hs]
simp only [iInf_eq_top, ms] at hs
exact ⟨univ, subset_univ s, MeasurableSet.univ, hs _ (subset_univ s) MeasurableSet.univ⟩
· have : ∀ r > ms, ∃ t, s ⊆ t ∧ MeasurableSet t ∧ m t < r := by
intro r hs
have : ∃t, MeasurableSet t ∧ s ⊆ t ∧ m t < r := by simpa [ms, iInf_lt_iff] using hs
rcases this with ⟨t, hmt, hin, hlt⟩
exists t
have : ∀ n : ℕ, ∃ t, s ⊆ t ∧ MeasurableSet t ∧ m t < ms + (n : ℝ≥0∞)⁻¹ := by
intro n
refine this _ (ENNReal.lt_add_right hs ?_)
simp
choose t hsub hm hm' using this
refine ⟨⋂ n, t n, subset_iInter hsub, MeasurableSet.iInter hm, ?_⟩
have : Tendsto (fun n : ℕ => ms + (n : ℝ≥0∞)⁻¹) atTop (𝓝 (ms + 0)) :=
tendsto_const_nhds.add ENNReal.tendsto_inv_nat_nhds_zero
rw [add_zero] at this
refine le_antisymm (ge_of_tendsto' this fun n => ?_) ?_
· exact le_trans (measure_mono <| iInter_subset t n) (hm' n).le
· refine iInf_le_of_le (⋂ n, t n) ?_
refine iInf_le_of_le (subset_iInter hsub) ?_
exact iInf_le _ (MeasurableSet.iInter hm)
theorem exists_measurable_superset_of_trim_eq_zero {m : OuterMeasure α} {s : Set α}
(h : m.trim s = 0) : ∃ t, s ⊆ t ∧ MeasurableSet t ∧ m t = 0 := by
rcases exists_measurable_superset_eq_trim m s with ⟨t, hst, ht, hm⟩
exact ⟨t, hst, ht, h ▸ hm⟩
/-- If `μ i` is a countable family of outer measures, then for every set `s` there exists
a measurable set `t ⊇ s` such that `μ i t = (μ i).trim s` for all `i`. -/
theorem exists_measurable_superset_forall_eq_trim {ι} [Countable ι] (μ : ι → OuterMeasure α)
(s : Set α) : ∃ t, s ⊆ t ∧ MeasurableSet t ∧ ∀ i, μ i t = (μ i).trim s := by
choose t hst ht hμt using fun i => (μ i).exists_measurable_superset_eq_trim s
replace hst := subset_iInter hst
replace ht := MeasurableSet.iInter ht
refine ⟨⋂ i, t i, hst, ht, fun i => le_antisymm ?_ ?_⟩
exacts [hμt i ▸ (μ i).mono (iInter_subset _ _), (measure_mono hst).trans_eq ((μ i).trim_eq ht)]
/-- If `m₁ s = op (m₂ s) (m₃ s)` for all `s`, then the same is true for `m₁.trim`, `m₂.trim`,
and `m₃ s`. -/
theorem trim_binop {m₁ m₂ m₃ : OuterMeasure α} {op : ℝ≥0∞ → ℝ≥0∞ → ℝ≥0∞}
(h : ∀ s, m₁ s = op (m₂ s) (m₃ s)) (s : Set α) : m₁.trim s = op (m₂.trim s) (m₃.trim s) := by
rcases exists_measurable_superset_forall_eq_trim ![m₁, m₂, m₃] s with ⟨t, _hst, _ht, htm⟩
simp only [Fin.forall_iff_succ, Matrix.cons_val_zero, Matrix.cons_val_succ] at htm
rw [← htm.1, ← htm.2.1, ← htm.2.2.1, h]
/-- If `m₁ s = op (m₂ s)` for all `s`, then the same is true for `m₁.trim` and `m₂.trim`. -/
theorem trim_op {m₁ m₂ : OuterMeasure α} {op : ℝ≥0∞ → ℝ≥0∞} (h : ∀ s, m₁ s = op (m₂ s))
(s : Set α) : m₁.trim s = op (m₂.trim s) :=
@trim_binop α _ m₁ m₂ 0 (fun a _b => op a) h s
/-- `trim` is additive. -/
theorem trim_add (m₁ m₂ : OuterMeasure α) : (m₁ + m₂).trim = m₁.trim + m₂.trim :=
ext <| trim_binop (add_apply m₁ m₂)
/-- `trim` respects scalar multiplication. -/
theorem trim_smul {R : Type*} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (c : R)
(m : OuterMeasure α) : (c • m).trim = c • m.trim :=
ext <| trim_op (smul_apply c m)
| /-- `trim` sends the supremum of two outer measures to the supremum of the trimmed measures. -/
theorem trim_sup (m₁ m₂ : OuterMeasure α) : (m₁ ⊔ m₂).trim = m₁.trim ⊔ m₂.trim :=
ext fun s => (trim_binop (sup_apply m₁ m₂) s).trans (sup_apply _ _ _).symm
/-- `trim` sends the supremum of a countable family of outer measures to the supremum
of the trimmed measures. -/
theorem trim_iSup {ι} [Countable ι] (μ : ι → OuterMeasure α) :
| Mathlib/MeasureTheory/OuterMeasure/Induced.lean | 434 | 440 |
/-
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 Batteries.Data.Rat.Lemmas
import Mathlib.Algebra.Group.Defs
import Mathlib.Data.Rat.Init
import Mathlib.Order.Basic
import Mathlib.Tactic.Common
import Mathlib.Data.Int.Init
import Mathlib.Data.Nat.Basic
/-!
# Basics for the Rational Numbers
## Summary
We define the integral domain structure on `ℚ` and prove basic lemmas about it.
The definition of the field structure on `ℚ` will be done in `Mathlib.Data.Rat.Basic` once the
`Field` class has been defined.
## Main Definitions
- `Rat.divInt n d` constructs a rational number `q = n / d` from `n d : ℤ`.
## Notations
- `/.` is infix notation for `Rat.divInt`.
-/
-- TODO: If `Inv` was defined earlier than `Algebra.Group.Defs`, we could have
-- assert_not_exists Monoid
assert_not_exists MonoidWithZero Lattice PNat Nat.gcd_greatest
open Function
namespace Rat
variable {q : ℚ}
theorem pos (a : ℚ) : 0 < a.den := Nat.pos_of_ne_zero a.den_nz
lemma mk'_num_den (q : ℚ) : mk' q.num q.den q.den_nz q.reduced = q := rfl
@[simp]
theorem ofInt_eq_cast (n : ℤ) : ofInt n = Int.cast n :=
rfl
-- TODO: Replace `Rat.ofNat_num`/`Rat.ofNat_den` in Batteries
@[simp] lemma num_ofNat (n : ℕ) : num ofNat(n) = ofNat(n) := rfl
@[simp] lemma den_ofNat (n : ℕ) : den ofNat(n) = 1 := rfl
@[simp, norm_cast] lemma num_natCast (n : ℕ) : num n = n := rfl
@[simp, norm_cast] lemma den_natCast (n : ℕ) : den n = 1 := rfl
-- TODO: Replace `intCast_num`/`intCast_den` the names in Batteries
@[simp, norm_cast] lemma num_intCast (n : ℤ) : (n : ℚ).num = n := rfl
@[simp, norm_cast] lemma den_intCast (n : ℤ) : (n : ℚ).den = 1 := rfl
lemma intCast_injective : Injective (Int.cast : ℤ → ℚ) := fun _ _ ↦ congr_arg num
lemma natCast_injective : Injective (Nat.cast : ℕ → ℚ) :=
intCast_injective.comp fun _ _ ↦ Int.natCast_inj.1
@[simp high, norm_cast] lemma natCast_inj {m n : ℕ} : (m : ℚ) = n ↔ m = n :=
natCast_injective.eq_iff
@[simp high, norm_cast] lemma intCast_eq_zero {n : ℤ} : (n : ℚ) = 0 ↔ n = 0 := intCast_inj
@[simp high, norm_cast] lemma natCast_eq_zero {n : ℕ} : (n : ℚ) = 0 ↔ n = 0 := natCast_inj
@[simp high, norm_cast] lemma intCast_eq_one {n : ℤ} : (n : ℚ) = 1 ↔ n = 1 := intCast_inj
@[simp high, norm_cast] lemma natCast_eq_one {n : ℕ} : (n : ℚ) = 1 ↔ n = 1 := natCast_inj
lemma mkRat_eq_divInt (n d) : mkRat n d = n /. d := rfl
@[simp] lemma mk'_zero (d) (h : d ≠ 0) (w) : mk' 0 d h w = 0 := by congr; simp_all
@[simp]
lemma num_eq_zero {q : ℚ} : q.num = 0 ↔ q = 0 := by
induction q
constructor
· rintro rfl
exact mk'_zero _ _ _
· exact congr_arg num
lemma num_ne_zero {q : ℚ} : q.num ≠ 0 ↔ q ≠ 0 := num_eq_zero.not
@[simp] lemma den_ne_zero (q : ℚ) : q.den ≠ 0 := q.den_pos.ne'
@[simp] lemma num_nonneg : 0 ≤ q.num ↔ 0 ≤ q := by
simp [Int.le_iff_lt_or_eq, instLE, Rat.blt, Int.not_lt]; tauto
@[simp]
theorem divInt_eq_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b = 0 ↔ a = 0 := by
rw [← zero_divInt b, divInt_eq_iff b0 b0, Int.zero_mul, Int.mul_eq_zero, or_iff_left b0]
theorem divInt_ne_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b ≠ 0 ↔ a ≠ 0 :=
(divInt_eq_zero b0).not
-- TODO: this can move to Batteries
theorem normalize_eq_mk' (n : Int) (d : Nat) (h : d ≠ 0) (c : Nat.gcd (Int.natAbs n) d = 1) :
normalize n d h = mk' n d h c := (mk_eq_normalize ..).symm
-- TODO: Rename `mkRat_num_den` in Batteries
@[simp] alias mkRat_num_den' := mkRat_self
-- TODO: Rename `Rat.divInt_self` to `Rat.num_divInt_den` in Batteries
lemma num_divInt_den (q : ℚ) : q.num /. q.den = q := divInt_self _
lemma mk'_eq_divInt {n d h c} : (⟨n, d, h, c⟩ : ℚ) = n /. d := (num_divInt_den _).symm
theorem intCast_eq_divInt (z : ℤ) : (z : ℚ) = z /. 1 := mk'_eq_divInt
-- TODO: Rename `divInt_self` in Batteries to `num_divInt_den`
@[simp] lemma divInt_self' {n : ℤ} (hn : n ≠ 0) : n /. n = 1 := by
simpa using divInt_mul_right (n := 1) (d := 1) hn
/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
numbers of the form `n /. d` with `0 < d` and coprime `n`, `d`. -/
@[elab_as_elim]
def numDenCasesOn.{u} {C : ℚ → Sort u} :
∀ (a : ℚ) (_ : ∀ n d, 0 < d → (Int.natAbs n).Coprime d → C (n /. d)), C a
| ⟨n, d, h, c⟩, H => by rw [mk'_eq_divInt]; exact H n d (Nat.pos_of_ne_zero h) c
/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
numbers of the form `n /. d` with `d ≠ 0`. -/
@[elab_as_elim]
def numDenCasesOn'.{u} {C : ℚ → Sort u} (a : ℚ) (H : ∀ (n : ℤ) (d : ℕ), d ≠ 0 → C (n /. d)) :
C a :=
numDenCasesOn a fun n d h _ => H n d h.ne'
/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
numbers of the form `mk' n d` with `d ≠ 0`. -/
@[elab_as_elim]
def numDenCasesOn''.{u} {C : ℚ → Sort u} (a : ℚ)
(H : ∀ (n : ℤ) (d : ℕ) (nz red), C (mk' n d nz red)) : C a :=
numDenCasesOn a fun n d h h' ↦ by rw [← mk_eq_divInt _ _ h.ne' h']; exact H n d h.ne' _
theorem lift_binop_eq (f : ℚ → ℚ → ℚ) (f₁ : ℤ → ℤ → ℤ → ℤ → ℤ) (f₂ : ℤ → ℤ → ℤ → ℤ → ℤ)
(fv :
∀ {n₁ d₁ h₁ c₁ n₂ d₂ h₂ c₂},
f ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ = f₁ n₁ d₁ n₂ d₂ /. f₂ n₁ d₁ n₂ d₂)
(f0 : ∀ {n₁ d₁ n₂ d₂}, d₁ ≠ 0 → d₂ ≠ 0 → f₂ n₁ d₁ n₂ d₂ ≠ 0) (a b c d : ℤ)
(b0 : b ≠ 0) (d0 : d ≠ 0)
(H :
∀ {n₁ d₁ n₂ d₂}, a * d₁ = n₁ * b → c * d₂ = n₂ * d →
f₁ n₁ d₁ n₂ d₂ * f₂ a b c d = f₁ a b c d * f₂ n₁ d₁ n₂ d₂) :
f (a /. b) (c /. d) = f₁ a b c d /. f₂ a b c d := by
generalize ha : a /. b = x; obtain ⟨n₁, d₁, h₁, c₁⟩ := x; rw [mk'_eq_divInt] at ha
generalize hc : c /. d = x; obtain ⟨n₂, d₂, h₂, c₂⟩ := x; rw [mk'_eq_divInt] at hc
rw [fv]
have d₁0 := Int.ofNat_ne_zero.2 h₁
have d₂0 := Int.ofNat_ne_zero.2 h₂
exact (divInt_eq_iff (f0 d₁0 d₂0) (f0 b0 d0)).2
(H ((divInt_eq_iff b0 d₁0).1 ha) ((divInt_eq_iff d0 d₂0).1 hc))
attribute [simp] divInt_add_divInt
attribute [simp] neg_divInt
lemma neg_def (q : ℚ) : -q = -q.num /. q.den := by rw [← neg_divInt, num_divInt_den]
@[simp] lemma divInt_neg (n d : ℤ) : n /. -d = -n /. d := divInt_neg' ..
attribute [simp] divInt_sub_divInt
@[simp]
lemma divInt_mul_divInt' (n₁ d₁ n₂ d₂ : ℤ) : (n₁ /. d₁) * (n₂ /. d₂) = (n₁ * n₂) /. (d₁ * d₂) := by
obtain rfl | h₁ := eq_or_ne d₁ 0
· simp
obtain rfl | h₂ := eq_or_ne d₂ 0
· simp
exact divInt_mul_divInt _ _ h₁ h₂
attribute [simp] mkRat_mul_mkRat
lemma mk'_mul_mk' (n₁ n₂ : ℤ) (d₁ d₂ : ℕ) (hd₁ hd₂ hnd₁ hnd₂) (h₁₂ : n₁.natAbs.Coprime d₂)
(h₂₁ : n₂.natAbs.Coprime d₁) :
mk' n₁ d₁ hd₁ hnd₁ * mk' n₂ d₂ hd₂ hnd₂ = mk' (n₁ * n₂) (d₁ * d₂) (Nat.mul_ne_zero hd₁ hd₂) (by
rw [Int.natAbs_mul]; exact (hnd₁.mul h₂₁).mul_right (h₁₂.mul hnd₂)) := by
rw [mul_def]; dsimp; simp [mk_eq_normalize]
lemma mul_eq_mkRat (q r : ℚ) : q * r = mkRat (q.num * r.num) (q.den * r.den) := by
rw [mul_def, normalize_eq_mkRat]
-- TODO: Rename `divInt_eq_iff` in Batteries to `divInt_eq_divInt`
alias divInt_eq_divInt := divInt_eq_iff
instance instPowNat : Pow ℚ ℕ where
pow q n := ⟨q.num ^ n, q.den ^ n, by simp [Nat.pow_eq_zero], by
rw [Int.natAbs_pow]; exact q.reduced.pow _ _⟩
lemma pow_def (q : ℚ) (n : ℕ) :
q ^ n = ⟨q.num ^ n, q.den ^ n,
by simp [Nat.pow_eq_zero],
by rw [Int.natAbs_pow]; exact q.reduced.pow _ _⟩ := rfl
lemma pow_eq_mkRat (q : ℚ) (n : ℕ) : q ^ n = mkRat (q.num ^ n) (q.den ^ n) := by
rw [pow_def, mk_eq_mkRat]
lemma pow_eq_divInt (q : ℚ) (n : ℕ) : q ^ n = q.num ^ n /. q.den ^ n := by
rw [pow_def, mk_eq_divInt, Int.natCast_pow]
@[simp] lemma num_pow (q : ℚ) (n : ℕ) : (q ^ n).num = q.num ^ n := rfl
@[simp] lemma den_pow (q : ℚ) (n : ℕ) : (q ^ n).den = q.den ^ n := rfl
@[simp] lemma mk'_pow (num : ℤ) (den : ℕ) (hd hdn) (n : ℕ) :
mk' num den hd hdn ^ n = mk' (num ^ n) (den ^ n)
(by simp [Nat.pow_eq_zero, hd]) (by rw [Int.natAbs_pow]; exact hdn.pow _ _) := rfl
instance : Inv ℚ :=
⟨Rat.inv⟩
@[simp] lemma inv_divInt' (a b : ℤ) : (a /. b)⁻¹ = b /. a := inv_divInt ..
@[simp] lemma inv_mkRat (a : ℤ) (b : ℕ) : (mkRat a b)⁻¹ = b /. a := by
rw [mkRat_eq_divInt, inv_divInt']
lemma inv_def' (q : ℚ) : q⁻¹ = q.den /. q.num := by rw [← inv_divInt', num_divInt_den]
@[simp] lemma divInt_div_divInt (n₁ d₁ n₂ d₂) :
(n₁ /. d₁) / (n₂ /. d₂) = (n₁ * d₂) /. (d₁ * n₂) := by
rw [div_def, inv_divInt, divInt_mul_divInt']
lemma div_def' (q r : ℚ) : q / r = (q.num * r.den) /. (q.den * r.num) := by
rw [← divInt_div_divInt, num_divInt_den, num_divInt_den]
variable (a b c : ℚ)
protected lemma add_zero : a + 0 = a := by simp [add_def, normalize_eq_mkRat]
protected lemma zero_add : 0 + a = a := by simp [add_def, normalize_eq_mkRat]
protected lemma add_comm : a + b = b + a := by
simp [add_def, Int.add_comm, Int.mul_comm, Nat.mul_comm]
protected theorem add_assoc : a + b + c = a + (b + c) :=
numDenCasesOn' a fun n₁ d₁ h₁ ↦ numDenCasesOn' b fun n₂ d₂ h₂ ↦ numDenCasesOn' c fun n₃ d₃ h₃ ↦ by
simp only [ne_eq, Int.natCast_eq_zero, h₁, not_false_eq_true, h₂, divInt_add_divInt,
Int.mul_eq_zero, or_self, h₃]
rw [Int.mul_assoc, Int.add_mul, Int.add_mul, Int.mul_assoc, Int.add_assoc]
congr 2
ac_rfl
protected lemma neg_add_cancel : -a + a = 0 := by
simp [add_def, normalize_eq_mkRat, Int.neg_mul, Int.add_comm, ← Int.sub_eq_add_neg]
@[simp] lemma divInt_one (n : ℤ) : n /. 1 = n := by simp [divInt, mkRat, normalize]
@[simp] lemma mkRat_one (n : ℤ) : mkRat n 1 = n := by simp [mkRat_eq_divInt]
lemma divInt_one_one : 1 /. 1 = 1 := by rw [divInt_one, intCast_one]
protected theorem mul_assoc : a * b * c = a * (b * c) :=
numDenCasesOn' a fun n₁ d₁ h₁ =>
numDenCasesOn' b fun n₂ d₂ h₂ =>
numDenCasesOn' c fun n₃ d₃ h₃ => by
simp [h₁, h₂, h₃, Int.mul_comm, Nat.mul_assoc, Int.mul_left_comm]
protected theorem add_mul : (a + b) * c = a * c + b * c :=
numDenCasesOn' a fun n₁ d₁ h₁ ↦ numDenCasesOn' b fun n₂ d₂ h₂ ↦ numDenCasesOn' c fun n₃ d₃ h₃ ↦ by
simp only [ne_eq, Int.natCast_eq_zero, h₁, not_false_eq_true, h₂, divInt_add_divInt,
Int.mul_eq_zero, or_self, h₃, divInt_mul_divInt]
rw [← divInt_mul_right (Int.natCast_ne_zero.2 h₃), Int.add_mul, Int.add_mul]
ac_rfl
protected theorem mul_add : a * (b + c) = a * b + a * c := by
rw [Rat.mul_comm, Rat.add_mul, Rat.mul_comm, Rat.mul_comm c a]
protected theorem zero_ne_one : 0 ≠ (1 : ℚ) := by
rw [ne_comm, ← divInt_one_one, divInt_ne_zero] <;> omega
attribute [simp] mkRat_eq_zero
protected theorem mul_inv_cancel : a ≠ 0 → a * a⁻¹ = 1 :=
numDenCasesOn' a fun n d hd hn ↦ by
simp only [divInt_ofNat, ne_eq, hd, not_false_eq_true, mkRat_eq_zero] at hn
simp [-divInt_ofNat, mkRat_eq_divInt, Int.mul_comm, Int.mul_ne_zero hn (Int.ofNat_ne_zero.2 hd)]
protected theorem inv_mul_cancel (h : a ≠ 0) : a⁻¹ * a = 1 :=
Eq.trans (Rat.mul_comm _ _) (Rat.mul_inv_cancel _ h)
-- Extra instances to short-circuit type class resolution
-- TODO(Mario): this instance slows down Mathlib.Data.Real.Basic
instance nontrivial : Nontrivial ℚ where exists_pair_ne := ⟨1, 0, by decide⟩
/-! ### The rational numbers are a group -/
instance addCommGroup : AddCommGroup ℚ where
zero := 0
add := (· + ·)
neg := Neg.neg
zero_add := Rat.zero_add
add_zero := Rat.add_zero
add_comm := Rat.add_comm
add_assoc := Rat.add_assoc
neg_add_cancel := Rat.neg_add_cancel
sub_eq_add_neg := Rat.sub_eq_add_neg
nsmul := nsmulRec
zsmul := zsmulRec
instance addGroup : AddGroup ℚ := by infer_instance
instance addCommMonoid : AddCommMonoid ℚ := by infer_instance
instance addMonoid : AddMonoid ℚ := by infer_instance
instance addLeftCancelSemigroup : AddLeftCancelSemigroup ℚ := by infer_instance
instance addRightCancelSemigroup : AddRightCancelSemigroup ℚ := by infer_instance
instance addCommSemigroup : AddCommSemigroup ℚ := by infer_instance
instance addSemigroup : AddSemigroup ℚ := by infer_instance
instance commMonoid : CommMonoid ℚ where
one := 1
mul := (· * ·)
mul_one := Rat.mul_one
one_mul := Rat.one_mul
mul_comm := Rat.mul_comm
mul_assoc := Rat.mul_assoc
npow n q := q ^ n
npow_zero := by intros; apply Rat.ext <;> simp [Int.pow_zero]
npow_succ n q := by
rw [← q.mk'_num_den, mk'_pow, mk'_mul_mk']
· congr
· rw [mk'_pow, Int.natAbs_pow]
exact q.reduced.pow_left _
· rw [mk'_pow]
exact q.reduced.pow_right _
instance monoid : Monoid ℚ := by infer_instance
instance commSemigroup : CommSemigroup ℚ := by infer_instance
instance semigroup : Semigroup ℚ := by infer_instance
theorem eq_iff_mul_eq_mul {p q : ℚ} : p = q ↔ p.num * q.den = q.num * p.den := by
conv =>
lhs
rw [← num_divInt_den p, ← num_divInt_den q]
apply Rat.divInt_eq_iff <;>
· rw [← Int.natCast_zero, Ne, Int.ofNat_inj]
apply den_nz
@[simp]
theorem den_neg_eq_den (q : ℚ) : (-q).den = q.den :=
rfl
@[simp]
theorem num_neg_eq_neg_num (q : ℚ) : (-q).num = -q.num :=
rfl
-- Not `@[simp]` as `num_ofNat` is stronger.
theorem num_zero : Rat.num 0 = 0 :=
rfl
-- Not `@[simp]` as `den_ofNat` is stronger.
theorem den_zero : Rat.den 0 = 1 :=
rfl
lemma zero_of_num_zero {q : ℚ} (hq : q.num = 0) : q = 0 := by simpa [hq] using q.num_divInt_den.symm
theorem zero_iff_num_zero {q : ℚ} : q = 0 ↔ q.num = 0 :=
⟨fun _ => by simp [*], zero_of_num_zero⟩
-- `Not `@[simp]` as `num_ofNat` is stronger.
theorem num_one : (1 : ℚ).num = 1 :=
rfl
@[simp]
theorem den_one : (1 : ℚ).den = 1 :=
| rfl
theorem mk_num_ne_zero_of_ne_zero {q : ℚ} {n d : ℤ} (hq : q ≠ 0) (hqnd : q = n /. d) : n ≠ 0 :=
fun this => hq <| by simpa [this] using hqnd
| Mathlib/Data/Rat/Defs.lean | 373 | 376 |
/-
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.Field.IsField
import Mathlib.Algebra.Polynomial.Inductions
import Mathlib.Algebra.Polynomial.Monic
import Mathlib.Algebra.Ring.Regular
import Mathlib.RingTheory.Multiplicity
import Mathlib.Data.Nat.Lattice
/-!
# Division of univariate polynomials
The main defs are `divByMonic` and `modByMonic`.
The compatibility between these is given by `modByMonic_add_div`.
We also define `rootMultiplicity`.
-/
noncomputable section
open Polynomial
open Finset
namespace Polynomial
universe u v w z
variable {R : Type u} {S : Type v} {T : Type w} {A : Type z} {a b : R} {n : ℕ}
section Semiring
variable [Semiring R]
theorem X_dvd_iff {f : R[X]} : X ∣ f ↔ f.coeff 0 = 0 :=
⟨fun ⟨g, hfg⟩ => by rw [hfg, coeff_X_mul_zero], fun hf =>
⟨f.divX, by rw [← add_zero (X * f.divX), ← C_0, ← hf, X_mul_divX_add]⟩⟩
theorem X_pow_dvd_iff {f : R[X]} {n : ℕ} : X ^ n ∣ f ↔ ∀ d < n, f.coeff d = 0 :=
⟨fun ⟨g, hgf⟩ d hd => by
simp only [hgf, coeff_X_pow_mul', ite_eq_right_iff, not_le_of_lt hd, IsEmpty.forall_iff],
fun hd => by
induction n with
| zero => simp [pow_zero, one_dvd]
| succ n hn =>
obtain ⟨g, hgf⟩ := hn fun d : ℕ => fun H : d < n => hd _ (Nat.lt_succ_of_lt H)
have := coeff_X_pow_mul g n 0
rw [zero_add, ← hgf, hd n (Nat.lt_succ_self n)] at this
obtain ⟨k, hgk⟩ := Polynomial.X_dvd_iff.mpr this.symm
use k
rwa [pow_succ, mul_assoc, ← hgk]⟩
variable {p q : R[X]}
theorem finiteMultiplicity_of_degree_pos_of_monic (hp : (0 : WithBot ℕ) < degree p) (hmp : Monic p)
(hq : q ≠ 0) : FiniteMultiplicity p q :=
have zn0 : (0 : R) ≠ 1 :=
haveI := Nontrivial.of_polynomial_ne hq
zero_ne_one
⟨natDegree q, fun ⟨r, hr⟩ => by
have hp0 : p ≠ 0 := fun hp0 => by simp [hp0] at hp
have hr0 : r ≠ 0 := fun hr0 => by subst hr0; simp [hq] at hr
have hpn1 : leadingCoeff p ^ (natDegree q + 1) = 1 := by simp [show _ = _ from hmp]
have hpn0' : leadingCoeff p ^ (natDegree q + 1) ≠ 0 := hpn1.symm ▸ zn0.symm
have hpnr0 : leadingCoeff (p ^ (natDegree q + 1)) * leadingCoeff r ≠ 0 := by
simp only [leadingCoeff_pow' hpn0', leadingCoeff_eq_zero, hpn1, one_pow, one_mul, Ne,
hr0, not_false_eq_true]
have hnp : 0 < natDegree p := Nat.cast_lt.1 <| by
rw [← degree_eq_natDegree hp0]; exact hp
have := congr_arg natDegree hr
rw [natDegree_mul' hpnr0, natDegree_pow' hpn0', add_mul, add_assoc] at this
exact
ne_of_lt
(lt_add_of_le_of_pos (le_mul_of_one_le_right (Nat.zero_le _) hnp)
(add_pos_of_pos_of_nonneg (by rwa [one_mul]) (Nat.zero_le _)))
this⟩
@[deprecated (since := "2024-11-30")]
alias multiplicity_finite_of_degree_pos_of_monic := finiteMultiplicity_of_degree_pos_of_monic
end Semiring
section Ring
variable [Ring R] {p q : R[X]}
theorem div_wf_lemma (h : degree q ≤ degree p ∧ p ≠ 0) (hq : Monic q) :
degree (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) < degree p :=
have hp : leadingCoeff p ≠ 0 := mt leadingCoeff_eq_zero.1 h.2
have hq0 : q ≠ 0 := hq.ne_zero_of_polynomial_ne h.2
have hlt : natDegree q ≤ natDegree p :=
(Nat.cast_le (α := WithBot ℕ)).1
(by rw [← degree_eq_natDegree h.2, ← degree_eq_natDegree hq0]; exact h.1)
degree_sub_lt
(by
rw [hq.degree_mul_comm, hq.degree_mul, degree_C_mul_X_pow _ hp, degree_eq_natDegree h.2,
degree_eq_natDegree hq0, ← Nat.cast_add, tsub_add_cancel_of_le hlt])
h.2 (by rw [leadingCoeff_monic_mul hq, leadingCoeff_mul_X_pow, leadingCoeff_C])
/-- See `divByMonic`. -/
noncomputable def divModByMonicAux : ∀ (_p : R[X]) {q : R[X]}, Monic q → R[X] × R[X]
| p, q, hq =>
letI := Classical.decEq R
if h : degree q ≤ degree p ∧ p ≠ 0 then
let z := C (leadingCoeff p) * X ^ (natDegree p - natDegree q)
have _wf := div_wf_lemma h hq
let dm := divModByMonicAux (p - q * z) hq
⟨z + dm.1, dm.2⟩
else ⟨0, p⟩
termination_by p => p
/-- `divByMonic`, denoted as `p /ₘ q`, gives the quotient of `p` by a monic polynomial `q`. -/
def divByMonic (p q : R[X]) : R[X] :=
letI := Classical.decEq R
if hq : Monic q then (divModByMonicAux p hq).1 else 0
/-- `modByMonic`, denoted as `p %ₘ q`, gives the remainder of `p` by a monic polynomial `q`. -/
def modByMonic (p q : R[X]) : R[X] :=
letI := Classical.decEq R
if hq : Monic q then (divModByMonicAux p hq).2 else p
@[inherit_doc]
infixl:70 " /ₘ " => divByMonic
@[inherit_doc]
infixl:70 " %ₘ " => modByMonic
theorem degree_modByMonic_lt [Nontrivial R] :
∀ (p : R[X]) {q : R[X]} (_hq : Monic q), degree (p %ₘ q) < degree q
| p, q, hq =>
letI := Classical.decEq R
if h : degree q ≤ degree p ∧ p ≠ 0 then by
have _wf := div_wf_lemma ⟨h.1, h.2⟩ hq
have :=
degree_modByMonic_lt (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq
unfold modByMonic at this ⊢
unfold divModByMonicAux
dsimp
rw [dif_pos hq] at this ⊢
rw [if_pos h]
exact this
else
Or.casesOn (not_and_or.1 h)
(by
unfold modByMonic divModByMonicAux
dsimp
rw [dif_pos hq, if_neg h]
exact lt_of_not_ge)
(by
intro hp
unfold modByMonic divModByMonicAux
dsimp
rw [dif_pos hq, if_neg h, Classical.not_not.1 hp]
exact lt_of_le_of_ne bot_le (Ne.symm (mt degree_eq_bot.1 hq.ne_zero)))
termination_by p => p
theorem natDegree_modByMonic_lt (p : R[X]) {q : R[X]} (hmq : Monic q) (hq : q ≠ 1) :
natDegree (p %ₘ q) < q.natDegree := by
by_cases hpq : p %ₘ q = 0
· rw [hpq, natDegree_zero, Nat.pos_iff_ne_zero]
contrapose! hq
exact eq_one_of_monic_natDegree_zero hmq hq
· haveI := Nontrivial.of_polynomial_ne hpq
exact natDegree_lt_natDegree hpq (degree_modByMonic_lt p hmq)
@[simp]
theorem zero_modByMonic (p : R[X]) : 0 %ₘ p = 0 := by
classical
unfold modByMonic divModByMonicAux
dsimp
by_cases hp : Monic p
· rw [dif_pos hp, if_neg (mt And.right (not_not_intro rfl)), Prod.snd_zero]
· rw [dif_neg hp]
@[simp]
theorem zero_divByMonic (p : R[X]) : 0 /ₘ p = 0 := by
classical
unfold divByMonic divModByMonicAux
dsimp
by_cases hp : Monic p
· rw [dif_pos hp, if_neg (mt And.right (not_not_intro rfl)), Prod.fst_zero]
· rw [dif_neg hp]
@[simp]
theorem modByMonic_zero (p : R[X]) : p %ₘ 0 = p :=
letI := Classical.decEq R
if h : Monic (0 : R[X]) then by
haveI := monic_zero_iff_subsingleton.mp h
simp [eq_iff_true_of_subsingleton]
else by unfold modByMonic divModByMonicAux; rw [dif_neg h]
@[simp]
theorem divByMonic_zero (p : R[X]) : p /ₘ 0 = 0 :=
letI := Classical.decEq R
if h : Monic (0 : R[X]) then by
haveI := monic_zero_iff_subsingleton.mp h
simp [eq_iff_true_of_subsingleton]
else by unfold divByMonic divModByMonicAux; rw [dif_neg h]
theorem divByMonic_eq_of_not_monic (p : R[X]) (hq : ¬Monic q) : p /ₘ q = 0 :=
dif_neg hq
theorem modByMonic_eq_of_not_monic (p : R[X]) (hq : ¬Monic q) : p %ₘ q = p :=
dif_neg hq
theorem modByMonic_eq_self_iff [Nontrivial R] (hq : Monic q) : p %ₘ q = p ↔ degree p < degree q :=
⟨fun h => h ▸ degree_modByMonic_lt _ hq, fun h => by
classical
have : ¬degree q ≤ degree p := not_le_of_gt h
unfold modByMonic divModByMonicAux; dsimp; rw [dif_pos hq, if_neg (mt And.left this)]⟩
theorem degree_modByMonic_le (p : R[X]) {q : R[X]} (hq : Monic q) : degree (p %ₘ q) ≤ degree q := by
nontriviality R
exact (degree_modByMonic_lt _ hq).le
theorem degree_modByMonic_le_left : degree (p %ₘ q) ≤ degree p := by
nontriviality R
by_cases hq : q.Monic
· cases lt_or_ge (degree p) (degree q)
· rw [(modByMonic_eq_self_iff hq).mpr ‹_›]
· exact (degree_modByMonic_le p hq).trans ‹_›
· rw [modByMonic_eq_of_not_monic p hq]
theorem natDegree_modByMonic_le (p : Polynomial R) {g : Polynomial R} (hg : g.Monic) :
natDegree (p %ₘ g) ≤ g.natDegree :=
natDegree_le_natDegree (degree_modByMonic_le p hg)
theorem natDegree_modByMonic_le_left : natDegree (p %ₘ q) ≤ natDegree p :=
natDegree_le_natDegree degree_modByMonic_le_left
theorem X_dvd_sub_C : X ∣ p - C (p.coeff 0) := by
simp [X_dvd_iff, coeff_C]
theorem modByMonic_eq_sub_mul_div :
| ∀ (p : R[X]) {q : R[X]} (_hq : Monic q), p %ₘ q = p - q * (p /ₘ q)
| p, q, hq =>
| Mathlib/Algebra/Polynomial/Div.lean | 237 | 238 |
/-
Copyright (c) 2022 Junyan Xu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Junyan Xu
-/
import Mathlib.Data.Sym.Sym2
import Mathlib.Logic.Relation
/-!
# Game addition relation
This file defines, given relations `rα : α → α → Prop` and `rβ : β → β → Prop`, a relation
`Prod.GameAdd` on pairs, such that `GameAdd rα rβ x y` iff `x` can be reached from `y` by
decreasing either entry (with respect to `rα` and `rβ`). It is so called since it models the
subsequency relation on the addition of combinatorial games.
We also define `Sym2.GameAdd`, which is the unordered pair analog of `Prod.GameAdd`.
## Main definitions and results
- `Prod.GameAdd`: the game addition relation on ordered pairs.
- `WellFounded.prod_gameAdd`: formalizes induction on ordered pairs, where exactly one entry
decreases at a time.
- `Sym2.GameAdd`: the game addition relation on unordered pairs.
- `WellFounded.sym2_gameAdd`: formalizes induction on unordered pairs, where exactly one entry
decreases at a time.
-/
variable {α β : Type*} {rα : α → α → Prop} {rβ : β → β → Prop} {a : α} {b : β}
/-! ### `Prod.GameAdd` -/
namespace Prod
variable (rα rβ)
/-- `Prod.GameAdd rα rβ x y` means that `x` can be reached from `y` by decreasing either entry with
respect to the relations `rα` and `rβ`.
It is so called, as it models game addition within combinatorial game theory. If `rα a₁ a₂` means
that `a₂ ⟶ a₁` is a valid move in game `α`, and `rβ b₁ b₂` means that `b₂ ⟶ b₁` is a valid move
in game `β`, then `GameAdd rα rβ` specifies the valid moves in the juxtaposition of `α` and `β`:
the player is free to choose one of the games and make a move in it, while leaving the other game
unchanged.
See `Sym2.GameAdd` for the unordered pair analog. -/
inductive GameAdd : α × β → α × β → Prop
| fst {a₁ a₂ b} : rα a₁ a₂ → GameAdd (a₁, b) (a₂, b)
| snd {a b₁ b₂} : rβ b₁ b₂ → GameAdd (a, b₁) (a, b₂)
theorem gameAdd_iff {rα rβ} {x y : α × β} :
GameAdd rα rβ x y ↔ rα x.1 y.1 ∧ x.2 = y.2 ∨ rβ x.2 y.2 ∧ x.1 = y.1 := by
constructor
· rintro (@⟨a₁, a₂, b, h⟩ | @⟨a, b₁, b₂, h⟩)
exacts [Or.inl ⟨h, rfl⟩, Or.inr ⟨h, rfl⟩]
· revert x y
rintro ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ (⟨h, rfl : b₁ = b₂⟩ | ⟨h, rfl : a₁ = a₂⟩)
exacts [GameAdd.fst h, GameAdd.snd h]
theorem gameAdd_mk_iff {rα rβ} {a₁ a₂ : α} {b₁ b₂ : β} :
GameAdd rα rβ (a₁, b₁) (a₂, b₂) ↔ rα a₁ a₂ ∧ b₁ = b₂ ∨ rβ b₁ b₂ ∧ a₁ = a₂ :=
gameAdd_iff
@[simp]
theorem gameAdd_swap_swap : ∀ a b : α × β, GameAdd rβ rα a.swap b.swap ↔ GameAdd rα rβ a b :=
fun ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ => by rw [Prod.swap, Prod.swap, gameAdd_mk_iff, gameAdd_mk_iff, or_comm]
theorem gameAdd_swap_swap_mk (a₁ a₂ : α) (b₁ b₂ : β) :
GameAdd rα rβ (a₁, b₁) (a₂, b₂) ↔ GameAdd rβ rα (b₁, a₁) (b₂, a₂) :=
gameAdd_swap_swap rβ rα (b₁, a₁) (b₂, a₂)
/-- `Prod.GameAdd` is a subrelation of `Prod.Lex`. -/
theorem gameAdd_le_lex : GameAdd rα rβ ≤ Prod.Lex rα rβ := fun _ _ h =>
h.rec (Prod.Lex.left _ _) (Prod.Lex.right _)
/-- `Prod.RProd` is a subrelation of the transitive closure of `Prod.GameAdd`. -/
theorem rprod_le_transGen_gameAdd : RProd rα rβ ≤ Relation.TransGen (GameAdd rα rβ)
| _, _, h => h.rec (by
intro _ _ _ _ hα hβ
exact Relation.TransGen.tail (Relation.TransGen.single <| GameAdd.fst hα) (GameAdd.snd hβ))
end Prod
/-- If `a` is accessible under `rα` and `b` is accessible under `rβ`, then `(a, b)` is
accessible under `Prod.GameAdd rα rβ`. Notice that `Prod.lexAccessible` requires the
stronger condition `∀ b, Acc rβ b`. -/
theorem Acc.prod_gameAdd (ha : Acc rα a) (hb : Acc rβ b) :
Acc (Prod.GameAdd rα rβ) (a, b) := by
induction' ha with a _ iha generalizing b
induction' hb with b hb ihb
refine Acc.intro _ fun h => ?_
rintro (⟨ra⟩ | ⟨rb⟩)
exacts [iha _ ra (Acc.intro b hb), ihb _ rb]
/-- The `Prod.GameAdd` relation on well-founded inputs is well-founded.
In particular, the sum of two well-founded games is well-founded. -/
theorem WellFounded.prod_gameAdd (hα : WellFounded rα) (hβ : WellFounded rβ) :
WellFounded (Prod.GameAdd rα rβ) :=
⟨fun ⟨a, b⟩ => (hα.apply a).prod_gameAdd (hβ.apply b)⟩
namespace Prod
/-- Recursion on the well-founded `Prod.GameAdd` relation.
Note that it's strictly more general to recurse on the lexicographic order instead. -/
def GameAdd.fix {C : α → β → Sort*} (hα : WellFounded rα) (hβ : WellFounded rβ)
(IH : ∀ a₁ b₁, (∀ a₂ b₂, GameAdd rα rβ (a₂, b₂) (a₁, b₁) → C a₂ b₂) → C a₁ b₁) (a : α) (b : β) :
C a b :=
@WellFounded.fix (α × β) (fun x => C x.1 x.2) _ (hα.prod_gameAdd hβ)
(fun ⟨x₁, x₂⟩ IH' => IH x₁ x₂ fun a' b' => IH' ⟨a', b'⟩) ⟨a, b⟩
theorem GameAdd.fix_eq {C : α → β → Sort*} (hα : WellFounded rα) (hβ : WellFounded rβ)
(IH : ∀ a₁ b₁, (∀ a₂ b₂, GameAdd rα rβ (a₂, b₂) (a₁, b₁) → C a₂ b₂) → C a₁ b₁) (a : α) (b : β) :
GameAdd.fix hα hβ IH a b = IH a b fun a' b' _ => GameAdd.fix hα hβ IH a' b' :=
WellFounded.fix_eq _ _ _
/-- Induction on the well-founded `Prod.GameAdd` relation.
Note that it's strictly more general to induct on the lexicographic order instead. -/
theorem GameAdd.induction {C : α → β → Prop} :
WellFounded rα →
WellFounded rβ →
(∀ a₁ b₁, (∀ a₂ b₂, GameAdd rα rβ (a₂, b₂) (a₁, b₁) → C a₂ b₂) → C a₁ b₁) → ∀ a b, C a b :=
GameAdd.fix
end Prod
/-! ### `Sym2.GameAdd` -/
namespace Sym2
/-- `Sym2.GameAdd rα x y` means that `x` can be reached from `y` by decreasing either entry with
respect to the relation `rα`.
See `Prod.GameAdd` for the ordered pair analog. -/
def GameAdd (rα : α → α → Prop) : Sym2 α → Sym2 α → Prop :=
Sym2.lift₂
⟨fun a₁ b₁ a₂ b₂ => Prod.GameAdd rα rα (a₁, b₁) (a₂, b₂) ∨ Prod.GameAdd rα rα (b₁, a₁) (a₂, b₂),
fun a₁ b₁ a₂ b₂ => by
dsimp
rw [Prod.gameAdd_swap_swap_mk _ _ b₁ b₂ a₁ a₂, Prod.gameAdd_swap_swap_mk _ _ a₁ b₂ b₁ a₂]
simp [or_comm]⟩
theorem gameAdd_iff : ∀ {x y : α × α},
GameAdd rα (Sym2.mk x) (Sym2.mk y) ↔ Prod.GameAdd rα rα x y ∨ Prod.GameAdd rα rα x.swap y := by
rintro ⟨_, _⟩ ⟨_, _⟩
rfl
theorem gameAdd_mk'_iff {a₁ a₂ b₁ b₂ : α} :
GameAdd rα s(a₁, b₁) s(a₂, b₂) ↔
Prod.GameAdd rα rα (a₁, b₁) (a₂, b₂) ∨ Prod.GameAdd rα rα (b₁, a₁) (a₂, b₂) :=
Iff.rfl
theorem _root_.Prod.GameAdd.to_sym2 {a₁ a₂ b₁ b₂ : α} (h : Prod.GameAdd rα rα (a₁, b₁) (a₂, b₂)) :
Sym2.GameAdd rα s(a₁, b₁) s(a₂, b₂) :=
gameAdd_mk'_iff.2 <| Or.inl <| h
theorem GameAdd.fst {a₁ a₂ b : α} (h : rα a₁ a₂) : GameAdd rα s(a₁, b) s(a₂, b) :=
| (Prod.GameAdd.fst h).to_sym2
theorem GameAdd.snd {a b₁ b₂ : α} (h : rα b₁ b₂) : GameAdd rα s(a, b₁) s(a, b₂) :=
(Prod.GameAdd.snd h).to_sym2
| Mathlib/Order/GameAdd.lean | 161 | 164 |
/-
Copyright (c) 2021 Devon Tuma. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Devon Tuma
-/
import Mathlib.Algebra.Polynomial.Eval.Defs
import Mathlib.Analysis.Asymptotics.Lemmas
/-!
# Super-Polynomial Function Decay
This file defines a predicate `Asymptotics.SuperpolynomialDecay f` for a function satisfying
one of following equivalent definitions (The definition is in terms of the first condition):
* `x ^ n * f` tends to `𝓝 0` for all (or sufficiently large) naturals `n`
* `|x ^ n * f|` tends to `𝓝 0` for all naturals `n` (`superpolynomialDecay_iff_abs_tendsto_zero`)
* `|x ^ n * f|` is bounded for all naturals `n` (`superpolynomialDecay_iff_abs_isBoundedUnder`)
* `f` is `o(x ^ c)` for all integers `c` (`superpolynomialDecay_iff_isLittleO`)
* `f` is `O(x ^ c)` for all integers `c` (`superpolynomialDecay_iff_isBigO`)
These conditions are all equivalent to conditions in terms of polynomials, replacing `x ^ c` with
`p(x)` or `p(x)⁻¹` as appropriate, since asymptotically `p(x)` behaves like `X ^ p.natDegree`.
These further equivalences are not proven in mathlib but would be good future projects.
The definition of superpolynomial decay for `f : α → β` is relative to a parameter `k : α → β`.
Super-polynomial decay then means `f x` decays faster than `(k x) ^ c` for all integers `c`.
Equivalently `f x` decays faster than `p.eval (k x)` for all polynomials `p : β[X]`.
The definition is also relative to a filter `l : Filter α` where the decay rate is compared.
When the map `k` is given by `n ↦ ↑n : ℕ → ℝ` this defines negligible functions:
https://en.wikipedia.org/wiki/Negligible_function
When the map `k` is given by `(r₁,...,rₙ) ↦ r₁*...*rₙ : ℝⁿ → ℝ` this is equivalent
to the definition of rapidly decreasing functions given here:
https://ncatlab.org/nlab/show/rapidly+decreasing+function
# Main Theorems
* `SuperpolynomialDecay.polynomial_mul` says that if `f(x)` is negligible,
then so is `p(x) * f(x)` for any polynomial `p`.
* `superpolynomialDecay_iff_zpow_tendsto_zero` gives an equivalence between definitions in terms
of decaying faster than `k(x) ^ n` for all naturals `n` or `k(x) ^ c` for all integer `c`.
-/
namespace Asymptotics
open Topology Polynomial
open Filter
/-- `f` has superpolynomial decay in parameter `k` along filter `l` if
`k ^ n * f` tends to zero at `l` for all naturals `n` -/
def SuperpolynomialDecay {α β : Type*} [TopologicalSpace β] [CommSemiring β] (l : Filter α)
(k : α → β) (f : α → β) :=
∀ n : ℕ, Tendsto (fun a : α => k a ^ n * f a) l (𝓝 0)
variable {α β : Type*} {l : Filter α} {k : α → β} {f g g' : α → β}
section CommSemiring
variable [TopologicalSpace β] [CommSemiring β]
theorem SuperpolynomialDecay.congr' (hf : SuperpolynomialDecay l k f) (hfg : f =ᶠ[l] g) :
SuperpolynomialDecay l k g := fun z =>
(hf z).congr' (EventuallyEq.mul (EventuallyEq.refl l _) hfg)
theorem SuperpolynomialDecay.congr (hf : SuperpolynomialDecay l k f) (hfg : ∀ x, f x = g x) :
SuperpolynomialDecay l k g := fun z =>
(hf z).congr fun x => (congr_arg fun a => k x ^ z * a) <| hfg x
@[simp]
theorem superpolynomialDecay_zero (l : Filter α) (k : α → β) : SuperpolynomialDecay l k 0 :=
fun z => by simpa only [Pi.zero_apply, mul_zero] using tendsto_const_nhds
theorem SuperpolynomialDecay.add [ContinuousAdd β] (hf : SuperpolynomialDecay l k f)
(hg : SuperpolynomialDecay l k g) : SuperpolynomialDecay l k (f + g) := fun z => by
simpa only [mul_add, add_zero, Pi.add_apply] using (hf z).add (hg z)
theorem SuperpolynomialDecay.mul [ContinuousMul β] (hf : SuperpolynomialDecay l k f)
(hg : SuperpolynomialDecay l k g) : SuperpolynomialDecay l k (f * g) := fun z => by
simpa only [mul_assoc, one_mul, mul_zero, pow_zero] using (hf z).mul (hg 0)
theorem SuperpolynomialDecay.mul_const [ContinuousMul β] (hf : SuperpolynomialDecay l k f) (c : β) :
SuperpolynomialDecay l k fun n => f n * c := fun z => by
simpa only [← mul_assoc, zero_mul] using Tendsto.mul_const c (hf z)
theorem SuperpolynomialDecay.const_mul [ContinuousMul β] (hf : SuperpolynomialDecay l k f) (c : β) :
SuperpolynomialDecay l k fun n => c * f n :=
(hf.mul_const c).congr fun _ => mul_comm _ _
theorem SuperpolynomialDecay.param_mul (hf : SuperpolynomialDecay l k f) :
SuperpolynomialDecay l k (k * f) := fun z =>
tendsto_nhds.2 fun s hs hs0 =>
l.sets_of_superset ((tendsto_nhds.1 (hf <| z + 1)) s hs hs0) fun x hx => by
simpa only [Set.mem_preimage, Pi.mul_apply, ← mul_assoc, ← pow_succ] using hx
theorem SuperpolynomialDecay.mul_param (hf : SuperpolynomialDecay l k f) :
SuperpolynomialDecay l k (f * k) :=
hf.param_mul.congr fun _ => mul_comm _ _
theorem SuperpolynomialDecay.param_pow_mul (hf : SuperpolynomialDecay l k f) (n : ℕ) :
SuperpolynomialDecay l k (k ^ n * f) := by
induction n with
| zero => simpa only [one_mul, pow_zero] using hf
| succ n hn => simpa only [pow_succ', mul_assoc] using hn.param_mul
theorem SuperpolynomialDecay.mul_param_pow (hf : SuperpolynomialDecay l k f) (n : ℕ) :
SuperpolynomialDecay l k (f * k ^ n) :=
(hf.param_pow_mul n).congr fun _ => mul_comm _ _
theorem SuperpolynomialDecay.polynomial_mul [ContinuousAdd β] [ContinuousMul β]
(hf : SuperpolynomialDecay l k f) (p : β[X]) :
SuperpolynomialDecay l k fun x => (p.eval <| k x) * f x :=
Polynomial.induction_on' p (fun p q hp hq => by simpa [add_mul] using hp.add hq) fun n c => by
simpa [mul_assoc] using (hf.param_pow_mul n).const_mul c
theorem SuperpolynomialDecay.mul_polynomial [ContinuousAdd β] [ContinuousMul β]
(hf : SuperpolynomialDecay l k f) (p : β[X]) :
SuperpolynomialDecay l k fun x => f x * (p.eval <| k x) :=
(hf.polynomial_mul p).congr fun _ => mul_comm _ _
end CommSemiring
section OrderedCommSemiring
variable [TopologicalSpace β] [CommSemiring β] [PartialOrder β] [IsOrderedRing β] [OrderTopology β]
theorem SuperpolynomialDecay.trans_eventuallyLE (hk : 0 ≤ᶠ[l] k) (hg : SuperpolynomialDecay l k g)
(hg' : SuperpolynomialDecay l k g') (hfg : g ≤ᶠ[l] f) (hfg' : f ≤ᶠ[l] g') :
SuperpolynomialDecay l k f := fun z =>
tendsto_of_tendsto_of_tendsto_of_le_of_le' (hg z) (hg' z)
(hfg.mp (hk.mono fun _ hx hx' => mul_le_mul_of_nonneg_left hx' (pow_nonneg hx z)))
(hfg'.mp (hk.mono fun _ hx hx' => mul_le_mul_of_nonneg_left hx' (pow_nonneg hx z)))
end OrderedCommSemiring
section LinearOrderedCommRing
variable [TopologicalSpace β] [CommRing β] [LinearOrder β] [IsStrictOrderedRing β] [OrderTopology β]
variable (l k f)
theorem superpolynomialDecay_iff_abs_tendsto_zero :
SuperpolynomialDecay l k f ↔ ∀ n : ℕ, Tendsto (fun a : α => |k a ^ n * f a|) l (𝓝 0) :=
⟨fun h z => (tendsto_zero_iff_abs_tendsto_zero _).1 (h z), fun h z =>
(tendsto_zero_iff_abs_tendsto_zero _).2 (h z)⟩
theorem superpolynomialDecay_iff_superpolynomialDecay_abs :
SuperpolynomialDecay l k f ↔ SuperpolynomialDecay l (fun a => |k a|) fun a => |f a| :=
(superpolynomialDecay_iff_abs_tendsto_zero l k f).trans
(by simp_rw [SuperpolynomialDecay, abs_mul, abs_pow])
variable {l k f}
theorem SuperpolynomialDecay.trans_eventually_abs_le (hf : SuperpolynomialDecay l k f)
(hfg : abs ∘ g ≤ᶠ[l] abs ∘ f) : SuperpolynomialDecay l k g := by
rw [superpolynomialDecay_iff_abs_tendsto_zero] at hf ⊢
refine fun z =>
tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds (hf z)
(Eventually.of_forall fun x => abs_nonneg _) (hfg.mono fun x hx => ?_)
calc
|k x ^ z * g x| = |k x ^ z| * |g x| := abs_mul (k x ^ z) (g x)
_ ≤ |k x ^ z| * |f x| := by gcongr _ * ?_; exact hx
_ = |k x ^ z * f x| := (abs_mul (k x ^ z) (f x)).symm
theorem SuperpolynomialDecay.trans_abs_le (hf : SuperpolynomialDecay l k f)
(hfg : ∀ x, |g x| ≤ |f x|) : SuperpolynomialDecay l k g :=
hf.trans_eventually_abs_le (Eventually.of_forall hfg)
end LinearOrderedCommRing
section Field
variable [TopologicalSpace β] [Field β] (l k f)
theorem superpolynomialDecay_mul_const_iff [ContinuousMul β] {c : β} (hc0 : c ≠ 0) :
(SuperpolynomialDecay l k fun n => f n * c) ↔ SuperpolynomialDecay l k f :=
⟨fun h => (h.mul_const c⁻¹).congr fun x => by simp [mul_assoc, mul_inv_cancel₀ hc0], fun h =>
h.mul_const c⟩
theorem superpolynomialDecay_const_mul_iff [ContinuousMul β] {c : β} (hc0 : c ≠ 0) :
(SuperpolynomialDecay l k fun n => c * f n) ↔ SuperpolynomialDecay l k f :=
⟨fun h => (h.const_mul c⁻¹).congr fun x => by simp [← mul_assoc, inv_mul_cancel₀ hc0], fun h =>
h.const_mul c⟩
variable {l k f}
end Field
section LinearOrderedField
variable [TopologicalSpace β] [Field β] [LinearOrder β] [IsStrictOrderedRing β] [OrderTopology β]
variable (f)
theorem superpolynomialDecay_iff_abs_isBoundedUnder (hk : Tendsto k l atTop) :
SuperpolynomialDecay l k f ↔
∀ z : ℕ, IsBoundedUnder (· ≤ ·) l fun a : α => |k a ^ z * f a| := by
refine
⟨fun h z => Tendsto.isBoundedUnder_le (Tendsto.abs (h z)), fun h =>
(superpolynomialDecay_iff_abs_tendsto_zero l k f).2 fun z => ?_⟩
obtain ⟨m, hm⟩ := h (z + 1)
have h1 : Tendsto (fun _ : α => (0 : β)) l (𝓝 0) := tendsto_const_nhds
have h2 : Tendsto (fun a : α => |(k a)⁻¹| * m) l (𝓝 0) :=
zero_mul m ▸
Tendsto.mul_const m ((tendsto_zero_iff_abs_tendsto_zero _).1 hk.inv_tendsto_atTop)
refine
tendsto_of_tendsto_of_tendsto_of_le_of_le' h1 h2 (Eventually.of_forall fun x => abs_nonneg _)
((eventually_map.1 hm).mp ?_)
refine (hk.eventually_ne_atTop 0).mono fun x hk0 hx => ?_
refine Eq.trans_le ?_ (mul_le_mul_of_nonneg_left hx <| abs_nonneg (k x)⁻¹)
rw [← abs_mul, ← mul_assoc, pow_succ', ← mul_assoc, inv_mul_cancel₀ hk0, one_mul]
theorem superpolynomialDecay_iff_zpow_tendsto_zero (hk : Tendsto k l atTop) :
SuperpolynomialDecay l k f ↔ ∀ z : ℤ, Tendsto (fun a : α => k a ^ z * f a) l (𝓝 0) := by
refine ⟨fun h z => ?_, fun h n => by simpa only [zpow_natCast] using h (n : ℤ)⟩
by_cases hz : 0 ≤ z
· unfold Tendsto
lift z to ℕ using hz
simpa using h z
· have : Tendsto (fun a => k a ^ z) l (𝓝 0) :=
Tendsto.comp (tendsto_zpow_atTop_zero (not_le.1 hz)) hk
have h : Tendsto f l (𝓝 0) := by simpa using h 0
exact zero_mul (0 : β) ▸ this.mul h
variable {f}
theorem SuperpolynomialDecay.param_zpow_mul (hk : Tendsto k l atTop)
(hf : SuperpolynomialDecay l k f) (z : ℤ) :
SuperpolynomialDecay l k fun a => k a ^ z * f a := by
rw [superpolynomialDecay_iff_zpow_tendsto_zero _ hk] at hf ⊢
refine fun z' => (hf <| z' + z).congr' ((hk.eventually_ne_atTop 0).mono fun x hx => ?_)
simp [zpow_add₀ hx, mul_assoc, Pi.mul_apply]
theorem SuperpolynomialDecay.mul_param_zpow (hk : Tendsto k l atTop)
(hf : SuperpolynomialDecay l k f) (z : ℤ) : SuperpolynomialDecay l k fun a => f a * k a ^ z :=
(hf.param_zpow_mul hk z).congr fun _ => mul_comm _ _
theorem SuperpolynomialDecay.inv_param_mul (hk : Tendsto k l atTop)
(hf : SuperpolynomialDecay l k f) : SuperpolynomialDecay l k (k⁻¹ * f) := by
simpa using hf.param_zpow_mul hk (-1)
theorem SuperpolynomialDecay.param_inv_mul (hk : Tendsto k l atTop)
(hf : SuperpolynomialDecay l k f) : SuperpolynomialDecay l k (f * k⁻¹) :=
(hf.inv_param_mul hk).congr fun _ => mul_comm _ _
variable (f)
theorem superpolynomialDecay_param_mul_iff (hk : Tendsto k l atTop) :
SuperpolynomialDecay l k (k * f) ↔ SuperpolynomialDecay l k f :=
⟨fun h =>
(h.inv_param_mul hk).congr'
((hk.eventually_ne_atTop 0).mono fun x hx => by simp [← mul_assoc, inv_mul_cancel₀ hx]),
fun h => h.param_mul⟩
theorem superpolynomialDecay_mul_param_iff (hk : Tendsto k l atTop) :
SuperpolynomialDecay l k (f * k) ↔ SuperpolynomialDecay l k f := by
simpa [mul_comm k] using superpolynomialDecay_param_mul_iff f hk
theorem superpolynomialDecay_param_pow_mul_iff (hk : Tendsto k l atTop) (n : ℕ) :
SuperpolynomialDecay l k (k ^ n * f) ↔ SuperpolynomialDecay l k f := by
induction n with
| zero => simp
| succ n hn =>
simpa [pow_succ, ← mul_comm k, mul_assoc,
superpolynomialDecay_param_mul_iff (k ^ n * f) hk] using hn
theorem superpolynomialDecay_mul_param_pow_iff (hk : Tendsto k l atTop) (n : ℕ) :
SuperpolynomialDecay l k (f * k ^ n) ↔ SuperpolynomialDecay l k f := by
simpa [mul_comm f] using superpolynomialDecay_param_pow_mul_iff f hk n
variable {f}
end LinearOrderedField
section NormedLinearOrderedField
variable [NormedField β]
variable (l k f)
theorem superpolynomialDecay_iff_norm_tendsto_zero :
SuperpolynomialDecay l k f ↔ ∀ n : ℕ, Tendsto (fun a : α => ‖k a ^ n * f a‖) l (𝓝 0) :=
⟨fun h z => tendsto_zero_iff_norm_tendsto_zero.1 (h z), fun h z =>
tendsto_zero_iff_norm_tendsto_zero.2 (h z)⟩
theorem superpolynomialDecay_iff_superpolynomialDecay_norm :
SuperpolynomialDecay l k f ↔ SuperpolynomialDecay l (fun a => ‖k a‖) fun a => ‖f a‖ :=
| (superpolynomialDecay_iff_norm_tendsto_zero l k f).trans (by simp [SuperpolynomialDecay])
variable {l k}
| Mathlib/Analysis/Asymptotics/SuperpolynomialDecay.lean | 287 | 289 |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Mario Carneiro, Yaël Dillies
-/
import Mathlib.Data.Nat.Basic
import Mathlib.Data.Int.Order.Basic
import Mathlib.Logic.Function.Iterate
import Mathlib.Order.Compare
import Mathlib.Order.Max
import Mathlib.Order.Monotone.Defs
import Mathlib.Order.RelClasses
import Mathlib.Tactic.Choose
/-!
# Monotonicity
This file defines (strictly) monotone/antitone functions. Contrary to standard mathematical usage,
"monotone"/"mono" here means "increasing", not "increasing or decreasing". We use "antitone"/"anti"
to mean "decreasing".
## Main theorems
* `monotone_nat_of_le_succ`, `monotone_int_of_le_succ`: If `f : ℕ → α` or `f : ℤ → α` and
`f n ≤ f (n + 1)` for all `n`, then `f` is monotone.
* `antitone_nat_of_succ_le`, `antitone_int_of_succ_le`: If `f : ℕ → α` or `f : ℤ → α` and
`f (n + 1) ≤ f n` for all `n`, then `f` is antitone.
* `strictMono_nat_of_lt_succ`, `strictMono_int_of_lt_succ`: If `f : ℕ → α` or `f : ℤ → α` and
`f n < f (n + 1)` for all `n`, then `f` is strictly monotone.
* `strictAnti_nat_of_succ_lt`, `strictAnti_int_of_succ_lt`: If `f : ℕ → α` or `f : ℤ → α` and
`f (n + 1) < f n` for all `n`, then `f` is strictly antitone.
## Implementation notes
Some of these definitions used to only require `LE α` or `LT α`. The advantage of this is
unclear and it led to slight elaboration issues. Now, everything requires `Preorder α` and seems to
work fine. Related Zulip discussion:
https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/Order.20diamond/near/254353352.
## TODO
The above theorems are also true in `ℕ+`, `Fin n`... To make that work, we need `SuccOrder α`
and `IsSuccArchimedean α`.
## Tags
monotone, strictly monotone, antitone, strictly antitone, increasing, strictly increasing,
decreasing, strictly decreasing
-/
open Function OrderDual
universe u v w
variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {π : ι → Type*}
section Decidable
variable [Preorder α] [Preorder β] {f : α → β} {s : Set α}
instance [i : Decidable (∀ a b, a ≤ b → f a ≤ f b)] : Decidable (Monotone f) := i
instance [i : Decidable (∀ a b, a ≤ b → f b ≤ f a)] : Decidable (Antitone f) := i
instance [i : Decidable (∀ a ∈ s, ∀ b ∈ s, a ≤ b → f a ≤ f b)] :
Decidable (MonotoneOn f s) := i
instance [i : Decidable (∀ a ∈ s, ∀ b ∈ s, a ≤ b → f b ≤ f a)] :
Decidable (AntitoneOn f s) := i
instance [i : Decidable (∀ a b, a < b → f a < f b)] : Decidable (StrictMono f) := i
instance [i : Decidable (∀ a b, a < b → f b < f a)] : Decidable (StrictAnti f) := i
instance [i : Decidable (∀ a ∈ s, ∀ b ∈ s, a < b → f a < f b)] :
Decidable (StrictMonoOn f s) := i
instance [i : Decidable (∀ a ∈ s, ∀ b ∈ s, a < b → f b < f a)] :
Decidable (StrictAntiOn f s) := i
end Decidable
/-! ### Monotonicity on the dual order
Strictly, many of the `*On.dual` lemmas in this section should use `ofDual ⁻¹' s` instead of `s`,
but right now this is not possible as `Set.preimage` is not defined yet, and importing it creates
an import cycle.
Often, you should not need the rewriting lemmas. Instead, you probably want to add `.dual`,
`.dual_left` or `.dual_right` to your `Monotone`/`Antitone` hypothesis.
-/
section OrderDual
variable [Preorder α] [Preorder β] {f : α → β} {s : Set α}
@[simp]
theorem monotone_comp_ofDual_iff : Monotone (f ∘ ofDual) ↔ Antitone f :=
forall_swap
@[simp]
theorem antitone_comp_ofDual_iff : Antitone (f ∘ ofDual) ↔ Monotone f :=
forall_swap
-- Porting note:
-- Here (and below) without the type ascription, Lean is seeing through the
-- defeq `βᵒᵈ = β` and picking up the wrong `Preorder` instance.
-- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/logic.2Eequiv.2Ebasic.20mathlib4.23631/near/311744939
@[simp]
theorem monotone_toDual_comp_iff : Monotone (toDual ∘ f : α → βᵒᵈ) ↔ Antitone f :=
Iff.rfl
@[simp]
theorem antitone_toDual_comp_iff : Antitone (toDual ∘ f : α → βᵒᵈ) ↔ Monotone f :=
Iff.rfl
@[simp]
theorem monotoneOn_comp_ofDual_iff : MonotoneOn (f ∘ ofDual) s ↔ AntitoneOn f s :=
forall₂_swap
@[simp]
theorem antitoneOn_comp_ofDual_iff : AntitoneOn (f ∘ ofDual) s ↔ MonotoneOn f s :=
forall₂_swap
@[simp]
theorem monotoneOn_toDual_comp_iff : MonotoneOn (toDual ∘ f : α → βᵒᵈ) s ↔ AntitoneOn f s :=
Iff.rfl
@[simp]
theorem antitoneOn_toDual_comp_iff : AntitoneOn (toDual ∘ f : α → βᵒᵈ) s ↔ MonotoneOn f s :=
Iff.rfl
@[simp]
theorem strictMono_comp_ofDual_iff : StrictMono (f ∘ ofDual) ↔ StrictAnti f :=
forall_swap
@[simp]
theorem strictAnti_comp_ofDual_iff : StrictAnti (f ∘ ofDual) ↔ StrictMono f :=
forall_swap
@[simp]
theorem strictMono_toDual_comp_iff : StrictMono (toDual ∘ f : α → βᵒᵈ) ↔ StrictAnti f :=
Iff.rfl
@[simp]
theorem strictAnti_toDual_comp_iff : StrictAnti (toDual ∘ f : α → βᵒᵈ) ↔ StrictMono f :=
Iff.rfl
@[simp]
theorem strictMonoOn_comp_ofDual_iff : StrictMonoOn (f ∘ ofDual) s ↔ StrictAntiOn f s :=
forall₂_swap
@[simp]
theorem strictAntiOn_comp_ofDual_iff : StrictAntiOn (f ∘ ofDual) s ↔ StrictMonoOn f s :=
forall₂_swap
@[simp]
theorem strictMonoOn_toDual_comp_iff : StrictMonoOn (toDual ∘ f : α → βᵒᵈ) s ↔ StrictAntiOn f s :=
Iff.rfl
@[simp]
theorem strictAntiOn_toDual_comp_iff : StrictAntiOn (toDual ∘ f : α → βᵒᵈ) s ↔ StrictMonoOn f s :=
Iff.rfl
theorem monotone_dual_iff : Monotone (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) ↔ Monotone f := by
rw [monotone_toDual_comp_iff, antitone_comp_ofDual_iff]
theorem antitone_dual_iff : Antitone (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) ↔ Antitone f := by
rw [antitone_toDual_comp_iff, monotone_comp_ofDual_iff]
theorem monotoneOn_dual_iff : MonotoneOn (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) s ↔ MonotoneOn f s := by
rw [monotoneOn_toDual_comp_iff, antitoneOn_comp_ofDual_iff]
theorem antitoneOn_dual_iff : AntitoneOn (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) s ↔ AntitoneOn f s := by
rw [antitoneOn_toDual_comp_iff, monotoneOn_comp_ofDual_iff]
theorem strictMono_dual_iff : StrictMono (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) ↔ StrictMono f := by
rw [strictMono_toDual_comp_iff, strictAnti_comp_ofDual_iff]
theorem strictAnti_dual_iff : StrictAnti (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) ↔ StrictAnti f := by
rw [strictAnti_toDual_comp_iff, strictMono_comp_ofDual_iff]
theorem strictMonoOn_dual_iff :
StrictMonoOn (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) s ↔ StrictMonoOn f s := by
rw [strictMonoOn_toDual_comp_iff, strictAntiOn_comp_ofDual_iff]
theorem strictAntiOn_dual_iff :
StrictAntiOn (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) s ↔ StrictAntiOn f s := by
rw [strictAntiOn_toDual_comp_iff, strictMonoOn_comp_ofDual_iff]
alias ⟨_, Monotone.dual_left⟩ := antitone_comp_ofDual_iff
alias ⟨_, Antitone.dual_left⟩ := monotone_comp_ofDual_iff
alias ⟨_, Monotone.dual_right⟩ := antitone_toDual_comp_iff
alias ⟨_, Antitone.dual_right⟩ := monotone_toDual_comp_iff
alias ⟨_, MonotoneOn.dual_left⟩ := antitoneOn_comp_ofDual_iff
alias ⟨_, AntitoneOn.dual_left⟩ := monotoneOn_comp_ofDual_iff
alias ⟨_, MonotoneOn.dual_right⟩ := antitoneOn_toDual_comp_iff
alias ⟨_, AntitoneOn.dual_right⟩ := monotoneOn_toDual_comp_iff
alias ⟨_, StrictMono.dual_left⟩ := strictAnti_comp_ofDual_iff
alias ⟨_, StrictAnti.dual_left⟩ := strictMono_comp_ofDual_iff
alias ⟨_, StrictMono.dual_right⟩ := strictAnti_toDual_comp_iff
alias ⟨_, StrictAnti.dual_right⟩ := strictMono_toDual_comp_iff
alias ⟨_, StrictMonoOn.dual_left⟩ := strictAntiOn_comp_ofDual_iff
alias ⟨_, StrictAntiOn.dual_left⟩ := strictMonoOn_comp_ofDual_iff
alias ⟨_, StrictMonoOn.dual_right⟩ := strictAntiOn_toDual_comp_iff
alias ⟨_, StrictAntiOn.dual_right⟩ := strictMonoOn_toDual_comp_iff
alias ⟨_, Monotone.dual⟩ := monotone_dual_iff
alias ⟨_, Antitone.dual⟩ := antitone_dual_iff
alias ⟨_, MonotoneOn.dual⟩ := monotoneOn_dual_iff
alias ⟨_, AntitoneOn.dual⟩ := antitoneOn_dual_iff
alias ⟨_, StrictMono.dual⟩ := strictMono_dual_iff
alias ⟨_, StrictAnti.dual⟩ := strictAnti_dual_iff
alias ⟨_, StrictMonoOn.dual⟩ := strictMonoOn_dual_iff
alias ⟨_, StrictAntiOn.dual⟩ := strictAntiOn_dual_iff
end OrderDual
section WellFounded
variable [Preorder α] [Preorder β] {f : α → β}
theorem StrictMono.wellFoundedLT [WellFoundedLT β] (hf : StrictMono f) : WellFoundedLT α :=
Subrelation.isWellFounded (InvImage (· < ·) f) @hf
theorem StrictAnti.wellFoundedLT [WellFoundedGT β] (hf : StrictAnti f) : WellFoundedLT α :=
StrictMono.wellFoundedLT (β := βᵒᵈ) hf
theorem StrictMono.wellFoundedGT [WellFoundedGT β] (hf : StrictMono f) : WellFoundedGT α :=
StrictMono.wellFoundedLT (α := αᵒᵈ) (β := βᵒᵈ) (fun _ _ h ↦ hf h)
theorem StrictAnti.wellFoundedGT [WellFoundedLT β] (hf : StrictAnti f) : WellFoundedGT α :=
StrictMono.wellFoundedLT (α := αᵒᵈ) (fun _ _ h ↦ hf h)
end WellFounded
/-! ### Miscellaneous monotonicity results -/
section Preorder
variable [Preorder α] [Preorder β] {f g : α → β} {a : α}
theorem StrictMono.isMax_of_apply (hf : StrictMono f) (ha : IsMax (f a)) : IsMax a :=
of_not_not fun h ↦
let ⟨_, hb⟩ := not_isMax_iff.1 h
(hf hb).not_isMax ha
theorem StrictMono.isMin_of_apply (hf : StrictMono f) (ha : IsMin (f a)) : IsMin a :=
of_not_not fun h ↦
let ⟨_, hb⟩ := not_isMin_iff.1 h
(hf hb).not_isMin ha
theorem StrictAnti.isMax_of_apply (hf : StrictAnti f) (ha : IsMin (f a)) : IsMax a :=
of_not_not fun h ↦
let ⟨_, hb⟩ := not_isMax_iff.1 h
(hf hb).not_isMin ha
theorem StrictAnti.isMin_of_apply (hf : StrictAnti f) (ha : IsMax (f a)) : IsMin a :=
of_not_not fun h ↦
let ⟨_, hb⟩ := not_isMin_iff.1 h
(hf hb).not_isMax ha
lemma StrictMono.add_le_nat {f : ℕ → ℕ} (hf : StrictMono f) (m n : ℕ) : m + f n ≤ f (m + n) := by
rw [Nat.add_comm m, Nat.add_comm m]
induction m with
| zero => rw [Nat.add_zero, Nat.add_zero]
| succ m ih =>
rw [← Nat.add_assoc, ← Nat.add_assoc, Nat.succ_le]
exact ih.trans_lt (hf (n + m).lt_succ_self)
protected theorem StrictMono.ite' (hf : StrictMono f) (hg : StrictMono g) {p : α → Prop}
[DecidablePred p]
(hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ ⦃x y⦄, p x → ¬p y → x < y → f x < g y) :
StrictMono fun x ↦ if p x then f x else g x := by
intro x y h
by_cases hy : p y
· have hx : p x := hp h hy
simpa [hx, hy] using hf h
by_cases hx : p x
· simpa [hx, hy] using hfg hx hy h
· simpa [hx, hy] using hg h
protected theorem StrictMono.ite (hf : StrictMono f) (hg : StrictMono g) {p : α → Prop}
[DecidablePred p] (hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ x, f x ≤ g x) :
StrictMono fun x ↦ if p x then f x else g x :=
(hf.ite' hg hp) fun _ y _ _ h ↦ (hf h).trans_le (hfg y)
protected theorem StrictAnti.ite' (hf : StrictAnti f) (hg : StrictAnti g) {p : α → Prop}
[DecidablePred p]
(hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ ⦃x y⦄, p x → ¬p y → x < y → g y < f x) :
StrictAnti fun x ↦ if p x then f x else g x :=
StrictMono.ite' hf.dual_right hg.dual_right hp hfg
protected theorem StrictAnti.ite (hf : StrictAnti f) (hg : StrictAnti g) {p : α → Prop}
[DecidablePred p] (hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ x, g x ≤ f x) :
StrictAnti fun x ↦ if p x then f x else g x :=
(hf.ite' hg hp) fun _ y _ _ h ↦ (hfg y).trans_lt (hf h)
end Preorder
namespace List
section Fold
theorem foldl_monotone [Preorder α] {f : α → β → α} (H : ∀ b, Monotone fun a ↦ f a b)
(l : List β) : Monotone fun a ↦ l.foldl f a :=
List.recOn l (fun _ _ ↦ id) fun _ _ hl _ _ h ↦ hl (H _ h)
theorem foldr_monotone [Preorder β] {f : α → β → β} (H : ∀ a, Monotone (f a)) (l : List α) :
Monotone fun b ↦ l.foldr f b := fun _ _ h ↦ List.recOn l h fun i _ hl ↦ H i hl
theorem foldl_strictMono [Preorder α] {f : α → β → α} (H : ∀ b, StrictMono fun a ↦ f a b)
(l : List β) : StrictMono fun a ↦ l.foldl f a :=
List.recOn l (fun _ _ ↦ id) fun _ _ hl _ _ h ↦ hl (H _ h)
theorem foldr_strictMono [Preorder β] {f : α → β → β} (H : ∀ a, StrictMono (f a)) (l : List α) :
StrictMono fun b ↦ l.foldr f b := fun _ _ h ↦ List.recOn l h fun i _ hl ↦ H i hl
end Fold
end List
/-! ### Monotonicity in linear orders -/
section LinearOrder
variable [LinearOrder α]
section Preorder
variable [Preorder β] {f : α → β} {s : Set α}
open Ordering
theorem StrictMonoOn.le_iff_le (hf : StrictMonoOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) :
f a ≤ f b ↔ a ≤ b :=
⟨fun h ↦ le_of_not_gt fun h' ↦ (hf hb ha h').not_le h, fun h ↦
h.lt_or_eq_dec.elim (fun h' ↦ (hf ha hb h').le) fun h' ↦ h' ▸ le_rfl⟩
theorem StrictAntiOn.le_iff_le (hf : StrictAntiOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) :
f a ≤ f b ↔ b ≤ a :=
hf.dual_right.le_iff_le hb ha
theorem StrictMonoOn.eq_iff_eq (hf : StrictMonoOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) :
f a = f b ↔ a = b :=
⟨fun h ↦ le_antisymm ((hf.le_iff_le ha hb).mp h.le) ((hf.le_iff_le hb ha).mp h.ge), by
rintro rfl
rfl⟩
theorem StrictAntiOn.eq_iff_eq (hf : StrictAntiOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) :
f a = f b ↔ b = a :=
(hf.dual_right.eq_iff_eq ha hb).trans eq_comm
theorem StrictMonoOn.lt_iff_lt (hf : StrictMonoOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) :
f a < f b ↔ a < b := by
rw [lt_iff_le_not_le, lt_iff_le_not_le, hf.le_iff_le ha hb, hf.le_iff_le hb ha]
theorem StrictAntiOn.lt_iff_lt (hf : StrictAntiOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) :
f a < f b ↔ b < a :=
hf.dual_right.lt_iff_lt hb ha
theorem StrictMono.le_iff_le (hf : StrictMono f) {a b : α} : f a ≤ f b ↔ a ≤ b :=
(hf.strictMonoOn Set.univ).le_iff_le trivial trivial
theorem StrictAnti.le_iff_le (hf : StrictAnti f) {a b : α} : f a ≤ f b ↔ b ≤ a :=
(hf.strictAntiOn Set.univ).le_iff_le trivial trivial
theorem StrictMono.lt_iff_lt (hf : StrictMono f) {a b : α} : f a < f b ↔ a < b :=
(hf.strictMonoOn Set.univ).lt_iff_lt trivial trivial
theorem StrictAnti.lt_iff_lt (hf : StrictAnti f) {a b : α} : f a < f b ↔ b < a :=
(hf.strictAntiOn Set.univ).lt_iff_lt trivial trivial
protected theorem StrictMonoOn.compares (hf : StrictMonoOn f s) {a b : α} (ha : a ∈ s)
(hb : b ∈ s) : ∀ {o : Ordering}, o.Compares (f a) (f b) ↔ o.Compares a b
| Ordering.lt => hf.lt_iff_lt ha hb
| Ordering.eq => ⟨fun h ↦ ((hf.le_iff_le ha hb).1 h.le).antisymm
((hf.le_iff_le hb ha).1 h.symm.le), congr_arg _⟩
| Ordering.gt => hf.lt_iff_lt hb ha
protected theorem StrictAntiOn.compares (hf : StrictAntiOn f s) {a b : α} (ha : a ∈ s)
(hb : b ∈ s) {o : Ordering} : o.Compares (f a) (f b) ↔ o.Compares b a :=
toDual_compares_toDual.trans <| hf.dual_right.compares hb ha
protected theorem StrictMono.compares (hf : StrictMono f) {a b : α} {o : Ordering} :
o.Compares (f a) (f b) ↔ o.Compares a b :=
(hf.strictMonoOn Set.univ).compares trivial trivial
protected theorem StrictAnti.compares (hf : StrictAnti f) {a b : α} {o : Ordering} :
o.Compares (f a) (f b) ↔ o.Compares b a :=
(hf.strictAntiOn Set.univ).compares trivial trivial
theorem StrictMono.injective (hf : StrictMono f) : Injective f :=
fun x y h ↦ show Compares eq x y from hf.compares.1 h
theorem StrictAnti.injective (hf : StrictAnti f) : Injective f :=
fun x y h ↦ show Compares eq x y from hf.compares.1 h.symm
theorem StrictMono.maximal_of_maximal_image (hf : StrictMono f) {a} (hmax : ∀ p, p ≤ f a) (x : α) :
x ≤ a :=
hf.le_iff_le.mp (hmax (f x))
theorem StrictMono.minimal_of_minimal_image (hf : StrictMono f) {a} (hmin : ∀ p, f a ≤ p) (x : α) :
a ≤ x :=
hf.le_iff_le.mp (hmin (f x))
theorem StrictAnti.minimal_of_maximal_image (hf : StrictAnti f) {a} (hmax : ∀ p, p ≤ f a) (x : α) :
a ≤ x :=
hf.le_iff_le.mp (hmax (f x))
theorem StrictAnti.maximal_of_minimal_image (hf : StrictAnti f) {a} (hmin : ∀ p, f a ≤ p) (x : α) :
x ≤ a :=
hf.le_iff_le.mp (hmin (f x))
end Preorder
section PartialOrder
variable [PartialOrder β] {f : α → β}
theorem Monotone.strictMono_iff_injective (hf : Monotone f) : StrictMono f ↔ Injective f :=
⟨fun h ↦ h.injective, hf.strictMono_of_injective⟩
theorem Antitone.strictAnti_iff_injective (hf : Antitone f) : StrictAnti f ↔ Injective f :=
⟨fun h ↦ h.injective, hf.strictAnti_of_injective⟩
/-- If a monotone function is equal at two points, it is equal between all of them -/
theorem Monotone.eq_of_le_of_le {a₁ a₂ : α} (h_mon : Monotone f) (h_fa : f a₁ = f a₂) {i : α}
(h₁ : a₁ ≤ i) (h₂ : i ≤ a₂) : f i = f a₁ := by
apply le_antisymm
· rw [h_fa]; exact h_mon h₂
· exact h_mon h₁
/-- If an antitone function is equal at two points, it is equal between all of them -/
theorem Antitone.eq_of_le_of_le {a₁ a₂ : α} (h_anti : Antitone f) (h_fa : f a₁ = f a₂) {i : α}
(h₁ : a₁ ≤ i) (h₂ : i ≤ a₂) : f i = f a₁ := by
apply le_antisymm
· exact h_anti h₁
· rw [h_fa]; exact h_anti h₂
end PartialOrder
variable [LinearOrder β] {f : α → β} {s : Set α} {x y : α}
/-- A function between linear orders which is neither monotone nor antitone makes a dent upright or
downright. -/
lemma not_monotone_not_antitone_iff_exists_le_le :
¬ Monotone f ∧ ¬ Antitone f ↔
∃ a b c, a ≤ b ∧ b ≤ c ∧ ((f a < f b ∧ f c < f b) ∨ (f b < f a ∧ f b < f c)) := by
simp_rw [Monotone, Antitone, not_forall, not_le]
refine Iff.symm ⟨?_, ?_⟩
· rintro ⟨a, b, c, hab, hbc, ⟨hfab, hfcb⟩ | ⟨hfba, hfbc⟩⟩
exacts [⟨⟨_, _, hbc, hfcb⟩, _, _, hab, hfab⟩, ⟨⟨_, _, hab, hfba⟩, _, _, hbc, hfbc⟩]
rintro ⟨⟨a, b, hab, hfba⟩, c, d, hcd, hfcd⟩
obtain hda | had := le_total d a
· obtain hfad | hfda := le_total (f a) (f d)
· exact ⟨c, d, b, hcd, hda.trans hab, Or.inl ⟨hfcd, hfba.trans_le hfad⟩⟩
· exact ⟨c, a, b, hcd.trans hda, hab, Or.inl ⟨hfcd.trans_le hfda, hfba⟩⟩
obtain hac | hca := le_total a c
· obtain hfdb | hfbd := le_or_lt (f d) (f b)
· exact ⟨a, c, d, hac, hcd, Or.inr ⟨hfcd.trans <| hfdb.trans_lt hfba, hfcd⟩⟩
obtain hfca | hfac := lt_or_le (f c) (f a)
· exact ⟨a, c, d, hac, hcd, Or.inr ⟨hfca, hfcd⟩⟩
obtain hbd | hdb := le_total b d
· exact ⟨a, b, d, hab, hbd, Or.inr ⟨hfba, hfbd⟩⟩
· exact ⟨a, d, b, had, hdb, Or.inl ⟨hfac.trans_lt hfcd, hfbd⟩⟩
· obtain hfdb | hfbd := le_or_lt (f d) (f b)
· exact ⟨c, a, b, hca, hab, Or.inl ⟨hfcd.trans <| hfdb.trans_lt hfba, hfba⟩⟩
obtain hfca | hfac := lt_or_le (f c) (f a)
· exact ⟨c, a, b, hca, hab, Or.inl ⟨hfca, hfba⟩⟩
obtain hbd | hdb := le_total b d
· exact ⟨a, b, d, hab, hbd, Or.inr ⟨hfba, hfbd⟩⟩
· exact ⟨a, d, b, had, hdb, Or.inl ⟨hfac.trans_lt hfcd, hfbd⟩⟩
/-- A function between linear orders which is neither monotone nor antitone makes a dent upright or
downright. -/
lemma not_monotone_not_antitone_iff_exists_lt_lt :
¬ Monotone f ∧ ¬ Antitone f ↔ ∃ a b c, a < b ∧ b < c ∧
(f a < f b ∧ f c < f b ∨ f b < f a ∧ f b < f c) := by
simp_rw [not_monotone_not_antitone_iff_exists_le_le, ← and_assoc]
refine exists₃_congr (fun a b c ↦ and_congr_left <|
fun h ↦ (Ne.le_iff_lt ?_).and <| Ne.le_iff_lt ?_) <;>
(rintro rfl; simp at h)
/-!
### Strictly monotone functions and `cmp`
-/
theorem StrictMonoOn.cmp_map_eq (hf : StrictMonoOn f s) (hx : x ∈ s) (hy : y ∈ s) :
cmp (f x) (f y) = cmp x y :=
((hf.compares hx hy).2 (cmp_compares x y)).cmp_eq
theorem StrictMono.cmp_map_eq (hf : StrictMono f) (x y : α) : cmp (f x) (f y) = cmp x y :=
(hf.strictMonoOn Set.univ).cmp_map_eq trivial trivial
theorem StrictAntiOn.cmp_map_eq (hf : StrictAntiOn f s) (hx : x ∈ s) (hy : y ∈ s) :
cmp (f x) (f y) = cmp y x :=
hf.dual_right.cmp_map_eq hy hx
theorem StrictAnti.cmp_map_eq (hf : StrictAnti f) (x y : α) : cmp (f x) (f y) = cmp y x :=
(hf.strictAntiOn Set.univ).cmp_map_eq trivial trivial
end LinearOrder
/-! ### Monotonicity in `ℕ` and `ℤ` -/
section Preorder
variable [Preorder α]
theorem Nat.rel_of_forall_rel_succ_of_le_of_lt (r : β → β → Prop) [IsTrans β r] {f : ℕ → β} {a : ℕ}
(h : ∀ n, a ≤ n → r (f n) (f (n + 1))) ⦃b c : ℕ⦄ (hab : a ≤ b) (hbc : b < c) :
r (f b) (f c) := by
induction hbc with
| refl => exact h _ hab
| step b_lt_k r_b_k => exact _root_.trans r_b_k (h _ (hab.trans_lt b_lt_k).le)
theorem Nat.rel_of_forall_rel_succ_of_le_of_le (r : β → β → Prop) [IsRefl β r] [IsTrans β r]
{f : ℕ → β} {a : ℕ} (h : ∀ n, a ≤ n → r (f n) (f (n + 1)))
⦃b c : ℕ⦄ (hab : a ≤ b) (hbc : b ≤ c) : r (f b) (f c) :=
hbc.eq_or_lt.elim (fun h ↦ h ▸ refl _) (Nat.rel_of_forall_rel_succ_of_le_of_lt r h hab)
theorem Nat.rel_of_forall_rel_succ_of_lt (r : β → β → Prop) [IsTrans β r] {f : ℕ → β}
(h : ∀ n, r (f n) (f (n + 1))) ⦃a b : ℕ⦄ (hab : a < b) : r (f a) (f b) :=
Nat.rel_of_forall_rel_succ_of_le_of_lt r (fun n _ ↦ h n) le_rfl hab
theorem Nat.rel_of_forall_rel_succ_of_le (r : β → β → Prop) [IsRefl β r] [IsTrans β r] {f : ℕ → β}
(h : ∀ n, r (f n) (f (n + 1))) ⦃a b : ℕ⦄ (hab : a ≤ b) : r (f a) (f b) :=
Nat.rel_of_forall_rel_succ_of_le_of_le r (fun n _ ↦ h n) le_rfl hab
theorem monotone_nat_of_le_succ {f : ℕ → α} (hf : ∀ n, f n ≤ f (n + 1)) : Monotone f :=
Nat.rel_of_forall_rel_succ_of_le (· ≤ ·) hf
theorem antitone_nat_of_succ_le {f : ℕ → α} (hf : ∀ n, f (n + 1) ≤ f n) : Antitone f :=
@monotone_nat_of_le_succ αᵒᵈ _ _ hf
theorem strictMono_nat_of_lt_succ {f : ℕ → α} (hf : ∀ n, f n < f (n + 1)) : StrictMono f :=
Nat.rel_of_forall_rel_succ_of_lt (· < ·) hf
theorem strictAnti_nat_of_succ_lt {f : ℕ → α} (hf : ∀ n, f (n + 1) < f n) : StrictAnti f :=
@strictMono_nat_of_lt_succ αᵒᵈ _ f hf
namespace Nat
/-- If `α` is a preorder with no maximal elements, then there exists a strictly monotone function
`ℕ → α` with any prescribed value of `f 0`. -/
theorem exists_strictMono' [NoMaxOrder α] (a : α) : ∃ f : ℕ → α, StrictMono f ∧ f 0 = a := by
choose g hg using fun x : α ↦ exists_gt x
exact ⟨fun n ↦ Nat.recOn n a fun _ ↦ g, strictMono_nat_of_lt_succ fun n ↦ hg _, rfl⟩
/-- If `α` is a preorder with no maximal elements, then there exists a strictly antitone function
`ℕ → α` with any prescribed value of `f 0`. -/
theorem exists_strictAnti' [NoMinOrder α] (a : α) : ∃ f : ℕ → α, StrictAnti f ∧ f 0 = a :=
exists_strictMono' (OrderDual.toDual a)
theorem exists_strictMono_subsequence {P : ℕ → Prop} (h : ∀ N, ∃ n > N, P n) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P (φ n) := by
have : NoMaxOrder {n // P n} :=
⟨fun n ↦ Exists.intro ⟨(h n.1).choose, (h n.1).choose_spec.2⟩ (h n.1).choose_spec.1⟩
obtain ⟨f, hf, _⟩ := Nat.exists_strictMono' (⟨(h 0).choose, (h 0).choose_spec.2⟩ : {n // P n})
exact Exists.intro (fun n ↦ (f n).1) ⟨hf, fun n ↦ (f n).2⟩
variable (α)
/-- If `α` is a nonempty preorder with no maximal elements, then there exists a strictly monotone
function `ℕ → α`. -/
theorem exists_strictMono [Nonempty α] [NoMaxOrder α] : ∃ f : ℕ → α, StrictMono f :=
let ⟨a⟩ := ‹Nonempty α›
let ⟨f, hf, _⟩ := exists_strictMono' a
⟨f, hf⟩
/-- If `α` is a nonempty preorder with no minimal elements, then there exists a strictly antitone
function `ℕ → α`. -/
theorem exists_strictAnti [Nonempty α] [NoMinOrder α] : ∃ f : ℕ → α, StrictAnti f :=
exists_strictMono αᵒᵈ
lemma pow_self_mono : Monotone fun n : ℕ ↦ n ^ n := by
refine monotone_nat_of_le_succ fun n ↦ ?_
rw [Nat.pow_succ]
exact (Nat.pow_le_pow_left n.le_succ _).trans (Nat.le_mul_of_pos_right _ n.succ_pos)
lemma pow_monotoneOn : MonotoneOn (fun p : ℕ × ℕ ↦ p.1 ^ p.2) {p | p.1 ≠ 0} := fun _p _ _q hq hpq ↦
(Nat.pow_le_pow_left hpq.1 _).trans (Nat.pow_le_pow_right (Nat.pos_iff_ne_zero.2 hq) hpq.2)
lemma pow_self_strictMonoOn : StrictMonoOn (fun n : ℕ ↦ n ^ n) {n : ℕ | n ≠ 0} :=
fun _m hm _n hn hmn ↦
(Nat.pow_lt_pow_left hmn hm).trans_le (Nat.pow_le_pow_right (Nat.pos_iff_ne_zero.2 hn) hmn.le)
end Nat
theorem Int.rel_of_forall_rel_succ_of_lt (r : β → β → Prop) [IsTrans β r] {f : ℤ → β}
(h : ∀ n, r (f n) (f (n + 1))) ⦃a b : ℤ⦄ (hab : a < b) : r (f a) (f b) := by
rcases lt.dest hab with ⟨n, rfl⟩
clear hab
induction n with
| zero => rw [Int.ofNat_one]; apply h
| succ n ihn => rw [Int.natCast_succ, ← Int.add_assoc]; exact _root_.trans ihn (h _)
theorem Int.rel_of_forall_rel_succ_of_le (r : β → β → Prop) [IsRefl β r] [IsTrans β r] {f : ℤ → β}
(h : ∀ n, r (f n) (f (n + 1))) ⦃a b : ℤ⦄ (hab : a ≤ b) : r (f a) (f b) :=
hab.eq_or_lt.elim (fun h ↦ h ▸ refl _) fun h' ↦ Int.rel_of_forall_rel_succ_of_lt r h h'
theorem monotone_int_of_le_succ {f : ℤ → α} (hf : ∀ n, f n ≤ f (n + 1)) : Monotone f :=
Int.rel_of_forall_rel_succ_of_le (· ≤ ·) hf
theorem antitone_int_of_succ_le {f : ℤ → α} (hf : ∀ n, f (n + 1) ≤ f n) : Antitone f :=
Int.rel_of_forall_rel_succ_of_le (· ≥ ·) hf
theorem strictMono_int_of_lt_succ {f : ℤ → α} (hf : ∀ n, f n < f (n + 1)) : StrictMono f :=
Int.rel_of_forall_rel_succ_of_lt (· < ·) hf
theorem strictAnti_int_of_succ_lt {f : ℤ → α} (hf : ∀ n, f (n + 1) < f n) : StrictAnti f :=
Int.rel_of_forall_rel_succ_of_lt (· > ·) hf
namespace Int
variable (α)
variable [Nonempty α] [NoMinOrder α] [NoMaxOrder α]
/-- If `α` is a nonempty preorder with no minimal or maximal elements, then there exists a strictly
monotone function `f : ℤ → α`. -/
theorem exists_strictMono : ∃ f : ℤ → α, StrictMono f := by
inhabit α
rcases Nat.exists_strictMono' (default : α) with ⟨f, hf, hf₀⟩
rcases Nat.exists_strictAnti' (default : α) with ⟨g, hg, hg₀⟩
refine ⟨fun n ↦ Int.casesOn n f fun n ↦ g (n + 1), strictMono_int_of_lt_succ ?_⟩
rintro (n | _ | n)
· exact hf n.lt_succ_self
· show g 1 < f 0
rw [hf₀, ← hg₀]
exact hg Nat.zero_lt_one
· exact hg (Nat.lt_succ_self _)
/-- If `α` is a nonempty preorder with no minimal or maximal elements, then there exists a strictly
antitone function `f : ℤ → α`. -/
theorem exists_strictAnti : ∃ f : ℤ → α, StrictAnti f :=
exists_strictMono αᵒᵈ
end Int
-- TODO@Yael: Generalize the following four to succ orders
/-- If `f` is a monotone function from `ℕ` to a preorder such that `x` lies between `f n` and
`f (n + 1)`, then `x` doesn't lie in the range of `f`. -/
theorem Monotone.ne_of_lt_of_lt_nat {f : ℕ → α} (hf : Monotone f) (n : ℕ) {x : α} (h1 : f n < x)
(h2 : x < f (n + 1)) (a : ℕ) : f a ≠ x := by
rintro rfl
exact (hf.reflect_lt h1).not_le (Nat.le_of_lt_succ <| hf.reflect_lt h2)
/-- If `f` is an antitone function from `ℕ` to a preorder such that `x` lies between `f (n + 1)` and
`f n`, then `x` doesn't lie in the range of `f`. -/
theorem Antitone.ne_of_lt_of_lt_nat {f : ℕ → α} (hf : Antitone f) (n : ℕ) {x : α}
(h1 : f (n + 1) < x) (h2 : x < f n) (a : ℕ) : f a ≠ x := by
rintro rfl
exact (hf.reflect_lt h2).not_le (Nat.le_of_lt_succ <| hf.reflect_lt h1)
/-- If `f` is a monotone function from `ℤ` to a preorder and `x` lies between `f n` and
`f (n + 1)`, then `x` doesn't lie in the range of `f`. -/
theorem Monotone.ne_of_lt_of_lt_int {f : ℤ → α} (hf : Monotone f) (n : ℤ) {x : α} (h1 : f n < x)
(h2 : x < f (n + 1)) (a : ℤ) : f a ≠ x := by
rintro rfl
exact (hf.reflect_lt h1).not_le (Int.le_of_lt_add_one <| hf.reflect_lt h2)
/-- If `f` is an antitone function from `ℤ` to a preorder and `x` lies between `f (n + 1)` and
`f n`, then `x` doesn't lie in the range of `f`. -/
theorem Antitone.ne_of_lt_of_lt_int {f : ℤ → α} (hf : Antitone f) (n : ℤ) {x : α}
(h1 : f (n + 1) < x) (h2 : x < f n) (a : ℤ) : f a ≠ x := by
rintro rfl
exact (hf.reflect_lt h2).not_le (Int.le_of_lt_add_one <| hf.reflect_lt h1)
end Preorder
/-- A monotone function `f : ℕ → ℕ` bounded by `b`, which is constant after stabilising for the
first time, stabilises in at most `b` steps. -/
lemma Nat.stabilises_of_monotone {f : ℕ → ℕ} {b n : ℕ} (hfmono : Monotone f) (hfb : ∀ m, f m ≤ b)
(hfstab : ∀ m, f m = f (m + 1) → f (m + 1) = f (m + 2)) (hbn : b ≤ n) : f n = f b := by
obtain ⟨m, hmb, hm⟩ : ∃ m ≤ b, f m = f (m + 1) := by
contrapose! hfb
let rec strictMono : ∀ m ≤ b + 1, m ≤ f m
| 0, _ => Nat.zero_le _
| m + 1, hmb => (strictMono _ <| m.le_succ.trans hmb).trans_lt <| (hfmono m.le_succ).lt_of_ne <|
hfb _ <| Nat.le_of_succ_le_succ hmb
exact ⟨b + 1, strictMono _ le_rfl⟩
replace key : ∀ k : ℕ, f (m + k) = f (m + k + 1) ∧ f (m + k) = f m := fun k =>
Nat.rec ⟨hm, rfl⟩ (fun k ih => ⟨hfstab _ ih.1, ih.1.symm.trans ih.2⟩) k
replace key : ∀ k ≥ m, f k = f m := fun k hk =>
(congr_arg f (Nat.add_sub_of_le hk)).symm.trans (key (k - m)).2
exact (key n (hmb.trans hbn)).trans (key b hmb).symm
/-- A bounded monotone function `ℕ → ℕ` converges. -/
lemma converges_of_monotone_of_bounded {f : ℕ → ℕ} (mono_f : Monotone f)
{c : ℕ} (hc : ∀ n, f n ≤ c) : ∃ b N, ∀ n ≥ N, f n = b := by
induction c with
| zero => use 0, 0, fun n _ ↦ Nat.eq_zero_of_le_zero (hc n)
| succ c ih =>
by_cases h : ∀ n, f n ≤ c
· exact ih h
· push_neg at h; obtain ⟨N, hN⟩ := h
replace hN : f N = c + 1 := by specialize hc N; omega
use c + 1, N; intro n hn
specialize mono_f hn; specialize hc n; omega
@[deprecated (since := "2024-11-27")]
alias Group.card_pow_eq_card_pow_card_univ_aux := Nat.stabilises_of_monotone
@[deprecated (since := "2024-11-27")]
alias Group.card_nsmul_eq_card_nsmulpow_card_univ_aux := Nat.stabilises_of_monotone
| Mathlib/Order/Monotone/Basic.lean | 1,175 | 1,178 | |
/-
Copyright (c) 2023 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.MeasureTheory.Measure.Decomposition.RadonNikodym
/-!
# Exponentially tilted measures
The exponential tilting of a measure `μ` on `α` by a function `f : α → ℝ` is the measure with
density `x ↦ exp (f x) / ∫ y, exp (f y) ∂μ` with respect to `μ`. This is sometimes also called
the Esscher transform.
The definition is mostly used for `f` linear, in which case the exponentially tilted measure belongs
to the natural exponential family of the base measure. Exponentially tilted measures for general `f`
can be used for example to establish variational expressions for the Kullback-Leibler divergence.
## Main definitions
* `Measure.tilted μ f`: exponential tilting of `μ` by `f`, equal to
`μ.withDensity (fun x ↦ ENNReal.ofReal (exp (f x) / ∫ x, exp (f x) ∂μ))`.
-/
open Real
open scoped ENNReal NNReal
namespace MeasureTheory
variable {α : Type*} {mα : MeasurableSpace α} {μ : Measure α} {f : α → ℝ}
/-- Exponentially tilted measure. When `x ↦ exp (f x)` is integrable, `μ.tilted f` is the
probability measure with density with respect to `μ` proportional to `exp (f x)`. Otherwise it is 0.
-/
noncomputable
def Measure.tilted (μ : Measure α) (f : α → ℝ) : Measure α :=
μ.withDensity (fun x ↦ ENNReal.ofReal (exp (f x) / ∫ x, exp (f x) ∂μ))
@[simp]
lemma tilted_of_not_integrable (hf : ¬ Integrable (fun x ↦ exp (f x)) μ) : μ.tilted f = 0 := by
rw [Measure.tilted, integral_undef hf]
simp
@[simp]
lemma tilted_of_not_aemeasurable (hf : ¬ AEMeasurable f μ) : μ.tilted f = 0 := by
refine tilted_of_not_integrable ?_
suffices ¬ AEMeasurable (fun x ↦ exp (f x)) μ by exact fun h ↦ this h.1.aemeasurable
exact fun h ↦ hf (aemeasurable_of_aemeasurable_exp h)
@[simp]
lemma tilted_zero_measure (f : α → ℝ) : (0 : Measure α).tilted f = 0 := by simp [Measure.tilted]
@[simp]
lemma tilted_const' (μ : Measure α) (c : ℝ) :
μ.tilted (fun _ ↦ c) = (μ Set.univ)⁻¹ • μ := by
cases eq_zero_or_neZero μ with
| inl h => rw [h]; simp
| inr h0 =>
simp only [Measure.tilted, withDensity_const, integral_const, smul_eq_mul]
by_cases h_univ : μ Set.univ = ∞
· simp only [measureReal_def, h_univ, ENNReal.toReal_top, zero_mul, div_zero,
ENNReal.ofReal_zero, zero_smul, ENNReal.inv_top]
congr
rw [div_eq_mul_inv, mul_inv, mul_comm, mul_assoc, inv_mul_cancel₀ (exp_pos _).ne', mul_one,
measureReal_def, ← ENNReal.toReal_inv, ENNReal.ofReal_toReal]
simp [h0.out]
lemma tilted_const (μ : Measure α) [IsProbabilityMeasure μ] (c : ℝ) :
μ.tilted (fun _ ↦ c) = μ := by simp
@[simp]
lemma tilted_zero' (μ : Measure α) : μ.tilted 0 = (μ Set.univ)⁻¹ • μ := by
change μ.tilted (fun _ ↦ 0) = (μ Set.univ)⁻¹ • μ
simp
lemma tilted_zero (μ : Measure α) [IsProbabilityMeasure μ] : μ.tilted 0 = μ := by simp
lemma tilted_congr {g : α → ℝ} (hfg : f =ᵐ[μ] g) :
μ.tilted f = μ.tilted g := by
have h_int_eq : ∫ x, exp (f x) ∂μ = ∫ x, exp (g x) ∂μ := by
refine integral_congr_ae ?_
filter_upwards [hfg] with x hx
rw [hx]
refine withDensity_congr_ae ?_
filter_upwards [hfg] with x hx
rw [h_int_eq, hx]
| lemma tilted_eq_withDensity_nnreal (μ : Measure α) (f : α → ℝ) :
μ.tilted f = μ.withDensity (fun x ↦ ((↑) : ℝ≥0 → ℝ≥0∞)
(⟨exp (f x) / ∫ x, exp (f x) ∂μ, by positivity⟩ : ℝ≥0)) := by
rw [Measure.tilted]
congr with x
rw [ENNReal.ofReal_eq_coe_nnreal]
| Mathlib/MeasureTheory/Measure/Tilted.lean | 90 | 95 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Data.Finite.Sum
import Mathlib.GroupTheory.OrderOfElement
import Mathlib.GroupTheory.Perm.Support
import Mathlib.Logic.Equiv.Fintype
/-!
# Permutations on `Fintype`s
This file contains miscellaneous lemmas about `Equiv.Perm` and `Equiv.swap`, building on top
of those in `Mathlib/Logic/Equiv/Basic.lean` and other files in `Mathlib/GroupTheory/Perm/*`.
-/
universe u v
open Equiv Function Fintype Finset
variable {α : Type u} {β : Type v}
-- An example on how to determine the order of an element of a finite group.
-- import Mathlib.Data.Int.Order.Units
-- example : orderOf (-1 : ℤˣ) = 2 :=
-- orderOf_eq_prime (Int.units_sq _) (by decide)
namespace Equiv.Perm
section Conjugation
variable [DecidableEq α] [Fintype α] {σ τ : Perm α}
theorem isConj_of_support_equiv
(f : { x // x ∈ (σ.support : Set α) } ≃ { x // x ∈ (τ.support : Set α) })
(hf : ∀ (x : α) (hx : x ∈ (σ.support : Set α)),
(f ⟨σ x, apply_mem_support.2 hx⟩ : α) = τ ↑(f ⟨x, hx⟩)) :
IsConj σ τ := by
refine isConj_iff.2 ⟨Equiv.extendSubtype f, ?_⟩
rw [mul_inv_eq_iff_eq_mul]
ext x
simp only [Perm.mul_apply]
by_cases hx : x ∈ σ.support
· rw [Equiv.extendSubtype_apply_of_mem, Equiv.extendSubtype_apply_of_mem]
· exact hf x (Finset.mem_coe.2 hx)
· rwa [Classical.not_not.1 ((not_congr mem_support).1 (Equiv.extendSubtype_not_mem f _ _)),
Classical.not_not.1 ((not_congr mem_support).mp hx)]
end Conjugation
theorem perm_inv_on_of_perm_on_finset {s : Finset α} {f : Perm α} (h : ∀ x ∈ s, f x ∈ s) {y : α}
(hy : y ∈ s) : f⁻¹ y ∈ s := by
have h0 : ∀ y ∈ s, ∃ (x : _) (hx : x ∈ s), y = (fun i (_ : i ∈ s) => f i) x hx :=
Finset.surj_on_of_inj_on_of_card_le (fun x hx => (fun i _ => f i) x hx) (fun a ha => h a ha)
(fun a₁ a₂ ha₁ ha₂ heq => (Equiv.apply_eq_iff_eq f).mp heq) rfl.ge
obtain ⟨y2, hy2, heq⟩ := h0 y hy
convert hy2
rw [heq]
simp only [inv_apply_self]
theorem perm_inv_mapsTo_of_mapsTo (f : Perm α) {s : Set α} [Finite s] (h : Set.MapsTo f s s) :
Set.MapsTo (f⁻¹ :) s s := by
cases nonempty_fintype s
exact fun x hx =>
Set.mem_toFinset.mp <|
perm_inv_on_of_perm_on_finset
(fun a ha => Set.mem_toFinset.mpr (h (Set.mem_toFinset.mp ha)))
(Set.mem_toFinset.mpr hx)
@[simp]
theorem perm_inv_mapsTo_iff_mapsTo {f : Perm α} {s : Set α} [Finite s] :
Set.MapsTo (f⁻¹ :) s s ↔ Set.MapsTo f s s :=
⟨perm_inv_mapsTo_of_mapsTo f⁻¹, perm_inv_mapsTo_of_mapsTo f⟩
theorem perm_inv_on_of_perm_on_finite {f : Perm α} {p : α → Prop} [Finite { x // p x }]
(h : ∀ x, p x → p (f x)) {x : α} (hx : p x) : p (f⁻¹ x) := by
have : Finite { x | p x } := by simpa
simpa using perm_inv_mapsTo_of_mapsTo (s := {x | p x}) f h hx
/-- If the permutation `f` maps `{x // p x}` into itself, then this returns the permutation
on `{x // p x}` induced by `f`. Note that the `h` hypothesis is weaker than for
`Equiv.Perm.subtypePerm`. -/
abbrev subtypePermOfFintype (f : Perm α) {p : α → Prop} [Finite { x // p x }]
(h : ∀ x, p x → p (f x)) : Perm { x // p x } :=
f.subtypePerm fun x => ⟨h x, fun h₂ => f.inv_apply_self x ▸ perm_inv_on_of_perm_on_finite h h₂⟩
@[simp]
theorem subtypePermOfFintype_apply (f : Perm α) {p : α → Prop} [Finite { x // p x }]
(h : ∀ x, p x → p (f x)) (x : { x // p x }) : subtypePermOfFintype f h x = ⟨f x, h x x.2⟩ :=
rfl
theorem subtypePermOfFintype_one (p : α → Prop) [Finite { x // p x }]
(h : ∀ x, p x → p ((1 : Perm α) x)) : @subtypePermOfFintype α 1 p _ h = 1 :=
rfl
theorem perm_mapsTo_inl_iff_mapsTo_inr {m n : Type*} [Finite m] [Finite n] (σ : Perm (m ⊕ n)) :
Set.MapsTo σ (Set.range Sum.inl) (Set.range Sum.inl) ↔
Set.MapsTo σ (Set.range Sum.inr) (Set.range Sum.inr) := by
constructor <;>
( intro h
classical
rw [← perm_inv_mapsTo_iff_mapsTo] at h
intro x
rcases hx : σ x with l | r)
· rintro ⟨a, rfl⟩
obtain ⟨y, hy⟩ := h ⟨l, rfl⟩
rw [← hx, σ.inv_apply_self] at hy
exact absurd hy Sum.inl_ne_inr
· rintro _; exact ⟨r, rfl⟩
· rintro _; exact ⟨l, rfl⟩
· rintro ⟨a, rfl⟩
obtain ⟨y, hy⟩ := h ⟨r, rfl⟩
rw [← hx, σ.inv_apply_self] at hy
exact absurd hy Sum.inr_ne_inl
theorem mem_sumCongrHom_range_of_perm_mapsTo_inl {m n : Type*} [Finite m] [Finite n]
{σ : Perm (m ⊕ n)} (h : Set.MapsTo σ (Set.range Sum.inl) (Set.range Sum.inl)) :
σ ∈ (sumCongrHom m n).range := by
classical
have h1 : ∀ x : m ⊕ n, (∃ a : m, Sum.inl a = x) → ∃ a : m, Sum.inl a = σ x := by
rintro x ⟨a, ha⟩
apply h
rw [← ha]
exact ⟨a, rfl⟩
have h3 : ∀ x : m ⊕ n, (∃ b : n, Sum.inr b = x) → ∃ b : n, Sum.inr b = σ x := by
rintro x ⟨b, hb⟩
apply (perm_mapsTo_inl_iff_mapsTo_inr σ).mp h
rw [← hb]
exact ⟨b, rfl⟩
let σ₁' := subtypePermOfFintype σ h1
let σ₂' := subtypePermOfFintype σ h3
let σ₁ := permCongr (Equiv.ofInjective _ Sum.inl_injective).symm σ₁'
let σ₂ := permCongr (Equiv.ofInjective _ Sum.inr_injective).symm σ₂'
rw [MonoidHom.mem_range, Prod.exists]
use σ₁, σ₂
rw [Perm.sumCongrHom_apply]
ext x
rcases x with a | b
· rw [Equiv.sumCongr_apply, Sum.map_inl, permCongr_apply, Equiv.symm_symm,
apply_ofInjective_symm Sum.inl_injective]
rw [ofInjective_apply, Subtype.coe_mk, Subtype.coe_mk]
dsimp [Set.range]
rw [subtypePerm_apply]
· rw [Equiv.sumCongr_apply, Sum.map_inr, permCongr_apply, Equiv.symm_symm,
apply_ofInjective_symm Sum.inr_injective, ofInjective_apply]
dsimp [Set.range]
rw [subtypePerm_apply]
nonrec theorem Disjoint.orderOf {σ τ : Perm α} (hστ : Disjoint σ τ) :
orderOf (σ * τ) = Nat.lcm (orderOf σ) (orderOf τ) :=
haveI h : ∀ n : ℕ, (σ * τ) ^ n = 1 ↔ σ ^ n = 1 ∧ τ ^ n = 1 := fun n => by
rw [hστ.commute.mul_pow, Disjoint.mul_eq_one_iff (hστ.pow_disjoint_pow n n)]
Nat.dvd_antisymm hστ.commute.orderOf_mul_dvd_lcm
(Nat.lcm_dvd
(orderOf_dvd_of_pow_eq_one ((h (orderOf (σ * τ))).mp (pow_orderOf_eq_one (σ * τ))).1)
(orderOf_dvd_of_pow_eq_one ((h (orderOf (σ * τ))).mp (pow_orderOf_eq_one (σ * τ))).2))
theorem Disjoint.extendDomain {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p)
{σ τ : Perm α} (h : Disjoint σ τ) : Disjoint (σ.extendDomain f) (τ.extendDomain f) := by
intro b
by_cases pb : p b
· refine (h (f.symm ⟨b, pb⟩)).imp ?_ ?_ <;>
· intro h
rw [extendDomain_apply_subtype _ _ pb, h, apply_symm_apply, Subtype.coe_mk]
· left
rw [extendDomain_apply_not_subtype _ _ pb]
theorem Disjoint.isConj_mul [Finite α] {σ τ π ρ : Perm α} (hc1 : IsConj σ π)
(hc2 : IsConj τ ρ) (hd1 : Disjoint σ τ) (hd2 : Disjoint π ρ) : IsConj (σ * τ) (π * ρ) := by
classical
cases nonempty_fintype α
obtain ⟨f, rfl⟩ := isConj_iff.1 hc1
obtain ⟨g, rfl⟩ := isConj_iff.1 hc2
have hd1' := coe_inj.2 hd1.support_mul
have hd2' := coe_inj.2 hd2.support_mul
rw [coe_union] at *
have hd1'' := disjoint_coe.2 (disjoint_iff_disjoint_support.1 hd1)
have hd2'' := disjoint_coe.2 (disjoint_iff_disjoint_support.1 hd2)
refine isConj_of_support_equiv ?_ ?_
· refine
((Equiv.setCongr hd1').trans (Equiv.Set.union hd1'')).trans
((Equiv.sumCongr (subtypeEquiv f fun a => ?_) (subtypeEquiv g fun a => ?_)).trans
((Equiv.setCongr hd2').trans (Equiv.Set.union hd2'')).symm) <;>
| · simp only [Set.mem_image, toEmbedding_apply, exists_eq_right, support_conj, coe_map,
apply_eq_iff_eq]
· intro x hx
simp only [trans_apply, symm_trans_apply, Equiv.setCongr_apply, Equiv.setCongr_symm_apply,
Equiv.sumCongr_apply]
rw [hd1', Set.mem_union] at hx
rcases hx with hxσ | hxτ
· rw [mem_coe, mem_support] at hxσ
rw [Set.union_apply_left, Set.union_apply_left]
· simp only [subtypeEquiv_apply, Perm.coe_mul, Sum.map_inl, comp_apply,
Set.union_symm_apply_left, Subtype.coe_mk, apply_eq_iff_eq]
have h := (hd2 (f x)).resolve_left ?_
· rw [mul_apply, mul_apply] at h
rw [h, inv_apply_self, (hd1 x).resolve_left hxσ]
· rwa [mul_apply, mul_apply, inv_apply_self, apply_eq_iff_eq]
· rwa [Subtype.coe_mk, mem_coe, mem_support]
· rwa [Subtype.coe_mk, Perm.mul_apply, (hd1 x).resolve_left hxσ, mem_coe,
apply_mem_support, mem_support]
· rw [mem_coe, ← apply_mem_support, mem_support] at hxτ
rw [Set.union_apply_right, Set.union_apply_right]
· simp only [subtypeEquiv_apply, Perm.coe_mul, Sum.map_inr, comp_apply,
Set.union_symm_apply_right, Subtype.coe_mk, apply_eq_iff_eq]
have h := (hd2 (g (τ x))).resolve_right ?_
· rw [mul_apply, mul_apply] at h
rw [inv_apply_self, h, (hd1 (τ x)).resolve_right hxτ]
· rwa [mul_apply, mul_apply, inv_apply_self, apply_eq_iff_eq]
· rwa [Subtype.coe_mk, mem_coe, ← apply_mem_support, mem_support]
· rwa [Subtype.coe_mk, Perm.mul_apply, (hd1 (τ x)).resolve_right hxτ,
mem_coe, mem_support]
theorem mem_fixedPoints_iff_apply_mem_of_mem_centralizer {g p : Perm α}
(hp : p ∈ Subgroup.centralizer {g}) {x : α} :
x ∈ Function.fixedPoints g ↔ p x ∈ Function.fixedPoints g := by
simp only [Subgroup.mem_centralizer_singleton_iff] at hp
simp only [Function.mem_fixedPoints_iff]
rw [← mul_apply, ← hp, mul_apply, EmbeddingLike.apply_eq_iff_eq]
variable [DecidableEq α]
lemma disjoint_ofSubtype_of_memFixedPoints_self {g : Perm α}
(u : Perm (Function.fixedPoints g)) :
Disjoint (ofSubtype u) g := by
rw [disjoint_iff_eq_or_eq]
| Mathlib/GroupTheory/Perm/Finite.lean | 187 | 231 |
/-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.Analysis.InnerProductSpace.LinearMap
import Mathlib.MeasureTheory.Function.LpSpace.ContinuousFunctions
import Mathlib.MeasureTheory.Function.StronglyMeasurable.Inner
import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap
/-! # `L^2` space
If `E` is an inner product space over `𝕜` (`ℝ` or `ℂ`), then `Lp E 2 μ`
(defined in `Mathlib.MeasureTheory.Function.LpSpace`)
is also an inner product space, with inner product defined as `inner f g = ∫ a, ⟪f a, g a⟫ ∂μ`.
### Main results
* `mem_L1_inner` : for `f` and `g` in `Lp E 2 μ`, the pointwise inner product `fun x ↦ ⟪f x, g x⟫`
belongs to `Lp 𝕜 1 μ`.
* `integrable_inner` : for `f` and `g` in `Lp E 2 μ`, the pointwise inner product
`fun x ↦ ⟪f x, g x⟫` is integrable.
* `L2.innerProductSpace` : `Lp E 2 μ` is an inner product space.
-/
noncomputable section
open TopologicalSpace MeasureTheory MeasureTheory.Lp Filter
open scoped NNReal ENNReal MeasureTheory
namespace MeasureTheory
section
variable {α F : Type*} {m : MeasurableSpace α} {μ : Measure α} [NormedAddCommGroup F]
theorem MemLp.integrable_sq {f : α → ℝ} (h : MemLp f 2 μ) : Integrable (fun x => f x ^ 2) μ := by
simpa [← memLp_one_iff_integrable] using h.norm_rpow two_ne_zero ENNReal.ofNat_ne_top
@[deprecated (since := "2025-02-21")]
alias Memℒp.integrable_sq := MemLp.integrable_sq
theorem memLp_two_iff_integrable_sq_norm {f : α → F} (hf : AEStronglyMeasurable f μ) :
MemLp f 2 μ ↔ Integrable (fun x => ‖f x‖ ^ 2) μ := by
rw [← memLp_one_iff_integrable]
convert (memLp_norm_rpow_iff hf two_ne_zero ENNReal.ofNat_ne_top).symm
· simp
· rw [div_eq_mul_inv, ENNReal.mul_inv_cancel two_ne_zero ENNReal.ofNat_ne_top]
@[deprecated (since := "2025-02-21")]
alias memℒp_two_iff_integrable_sq_norm := memLp_two_iff_integrable_sq_norm
theorem memLp_two_iff_integrable_sq {f : α → ℝ} (hf : AEStronglyMeasurable f μ) :
MemLp f 2 μ ↔ Integrable (fun x => f x ^ 2) μ := by
convert memLp_two_iff_integrable_sq_norm hf using 3
simp
@[deprecated (since := "2025-02-21")]
alias memℒp_two_iff_integrable_sq := memLp_two_iff_integrable_sq
end
section InnerProductSpace
variable {α : Type*} {m : MeasurableSpace α} {p : ℝ≥0∞} {μ : Measure α}
variable {E 𝕜 : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 E _ x y
theorem MemLp.const_inner (c : E) {f : α → E} (hf : MemLp f p μ) : MemLp (fun a => ⟪c, f a⟫) p μ :=
hf.of_le_mul (AEStronglyMeasurable.inner aestronglyMeasurable_const hf.1)
(Eventually.of_forall fun _ => norm_inner_le_norm _ _)
@[deprecated (since := "2025-02-21")]
alias Memℒp.const_inner := MemLp.const_inner
theorem MemLp.inner_const {f : α → E} (hf : MemLp f p μ) (c : E) : MemLp (fun a => ⟪f a, c⟫) p μ :=
hf.of_le_mul (c := ‖c‖) (AEStronglyMeasurable.inner hf.1 aestronglyMeasurable_const)
(Eventually.of_forall fun x => by rw [mul_comm]; exact norm_inner_le_norm _ _)
@[deprecated (since := "2025-02-21")]
alias Memℒp.inner_const := MemLp.inner_const
variable {f : α → E}
@[fun_prop]
theorem Integrable.const_inner (c : E) (hf : Integrable f μ) :
Integrable (fun x => ⟪c, f x⟫) μ := by
rw [← memLp_one_iff_integrable] at hf ⊢; exact hf.const_inner c
@[fun_prop]
theorem Integrable.inner_const (hf : Integrable f μ) (c : E) :
Integrable (fun x => ⟪f x, c⟫) μ := by
rw [← memLp_one_iff_integrable] at hf ⊢; exact hf.inner_const c
variable [CompleteSpace E] [NormedSpace ℝ E]
theorem _root_.integral_inner {f : α → E} (hf : Integrable f μ) (c : E) :
∫ x, ⟪c, f x⟫ ∂μ = ⟪c, ∫ x, f x ∂μ⟫ :=
((innerSL 𝕜 c).restrictScalars ℝ).integral_comp_comm hf
variable (𝕜)
theorem _root_.integral_eq_zero_of_forall_integral_inner_eq_zero (f : α → E) (hf : Integrable f μ)
(hf_int : ∀ c : E, ∫ x, ⟪c, f x⟫ ∂μ = 0) : ∫ x, f x ∂μ = 0 := by
specialize hf_int (∫ x, f x ∂μ); rwa [integral_inner hf, inner_self_eq_zero] at hf_int
end InnerProductSpace
namespace L2
variable {α E F 𝕜 : Type*} [RCLike 𝕜] [MeasurableSpace α] {μ : Measure α} [NormedAddCommGroup E]
[InnerProductSpace 𝕜 E] [NormedAddCommGroup F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
| theorem eLpNorm_rpow_two_norm_lt_top (f : Lp F 2 μ) :
eLpNorm (fun x => ‖f x‖ ^ (2 : ℝ)) 1 μ < ∞ := by
have h_two : ENNReal.ofReal (2 : ℝ) = 2 := by simp [zero_le_one]
rw [eLpNorm_norm_rpow f zero_lt_two, one_mul, h_two]
| Mathlib/MeasureTheory/Function/L2Space.lean | 118 | 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.Algebra.Group.Basic
import Mathlib.Data.Set.Function
import Mathlib.Order.Interval.Set.Basic
import Mathlib.Algebra.Order.Monoid.Defs
import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE
/-!
# Images of intervals under `(+ d)`
The lemmas in this file state that addition maps intervals bijectively. The typeclass
`ExistsAddOfLE` is defined specifically to make them work when combined with
`OrderedCancelAddCommMonoid`; the lemmas below therefore apply to all
`OrderedAddCommGroup`, but also to `ℕ` and `ℝ≥0`, which are not groups.
-/
namespace Set
variable {M : Type*} [AddCommMonoid M] [PartialOrder M] [IsOrderedCancelAddMonoid M]
[ExistsAddOfLE M] (a b c d : M)
theorem Ici_add_bij : BijOn (· + d) (Ici a) (Ici (a + d)) := by
refine
⟨fun x h => add_le_add_right (mem_Ici.mp h) _, (add_left_injective d).injOn, fun _ h => ?_⟩
obtain ⟨c, rfl⟩ := exists_add_of_le (mem_Ici.mp h)
rw [mem_Ici, add_right_comm, add_le_add_iff_right] at h
exact ⟨a + c, h, by rw [add_right_comm]⟩
theorem Ioi_add_bij : BijOn (· + d) (Ioi a) (Ioi (a + d)) := by
refine
⟨fun x h => add_lt_add_right (mem_Ioi.mp h) _, fun _ _ _ _ h => add_right_cancel h, fun _ h =>
?_⟩
obtain ⟨c, rfl⟩ := exists_add_of_le (mem_Ioi.mp h).le
rw [mem_Ioi, add_right_comm, add_lt_add_iff_right] at h
exact ⟨a + c, h, by rw [add_right_comm]⟩
theorem Icc_add_bij : BijOn (· + d) (Icc a b) (Icc (a + d) (b + d)) := by
rw [← Ici_inter_Iic, ← Ici_inter_Iic]
exact
(Ici_add_bij a d).inter_mapsTo (fun x hx => add_le_add_right hx _) fun x hx =>
le_of_add_le_add_right hx.2
theorem Ioo_add_bij : BijOn (· + d) (Ioo a b) (Ioo (a + d) (b + d)) := by
rw [← Ioi_inter_Iio, ← Ioi_inter_Iio]
exact
(Ioi_add_bij a d).inter_mapsTo (fun x hx => add_lt_add_right hx _) fun x hx =>
lt_of_add_lt_add_right hx.2
theorem Ioc_add_bij : BijOn (· + d) (Ioc a b) (Ioc (a + d) (b + d)) := by
rw [← Ioi_inter_Iic, ← Ioi_inter_Iic]
exact
(Ioi_add_bij a d).inter_mapsTo (fun x hx => add_le_add_right hx _) fun x hx =>
le_of_add_le_add_right hx.2
theorem Ico_add_bij : BijOn (· + d) (Ico a b) (Ico (a + d) (b + d)) := by
rw [← Ici_inter_Iio, ← Ici_inter_Iio]
exact
(Ici_add_bij a d).inter_mapsTo (fun x hx => add_lt_add_right hx _) fun x hx =>
lt_of_add_lt_add_right hx.2
/-!
### Images under `x ↦ x + a`
-/
@[simp]
theorem image_add_const_Ici : (fun x => x + a) '' Ici b = Ici (b + a) :=
(Ici_add_bij _ _).image_eq
@[simp]
theorem image_add_const_Ioi : (fun x => x + a) '' Ioi b = Ioi (b + a) :=
(Ioi_add_bij _ _).image_eq
@[simp]
theorem image_add_const_Icc : (fun x => x + a) '' Icc b c = Icc (b + a) (c + a) :=
(Icc_add_bij _ _ _).image_eq
@[simp]
theorem image_add_const_Ico : (fun x => x + a) '' Ico b c = Ico (b + a) (c + a) :=
(Ico_add_bij _ _ _).image_eq
@[simp]
theorem image_add_const_Ioc : (fun x => x + a) '' Ioc b c = Ioc (b + a) (c + a) :=
(Ioc_add_bij _ _ _).image_eq
@[simp]
theorem image_add_const_Ioo : (fun x => x + a) '' Ioo b c = Ioo (b + a) (c + a) :=
(Ioo_add_bij _ _ _).image_eq
/-!
### Images under `x ↦ a + x`
-/
@[simp]
theorem image_const_add_Ici : (fun x => a + x) '' Ici b = Ici (a + b) := by
simp only [add_comm a, image_add_const_Ici]
@[simp]
theorem image_const_add_Ioi : (fun x => a + x) '' Ioi b = Ioi (a + b) := by
simp only [add_comm a, image_add_const_Ioi]
@[simp]
theorem image_const_add_Icc : (fun x => a + x) '' Icc b c = Icc (a + b) (a + c) := by
simp only [add_comm a, image_add_const_Icc]
@[simp]
theorem image_const_add_Ico : (fun x => a + x) '' Ico b c = Ico (a + b) (a + c) := by
simp only [add_comm a, image_add_const_Ico]
@[simp]
theorem image_const_add_Ioc : (fun x => a + x) '' Ioc b c = Ioc (a + b) (a + c) := by
simp only [add_comm a, image_add_const_Ioc]
@[simp]
theorem image_const_add_Ioo : (fun x => a + x) '' Ioo b c = Ioo (a + b) (a + c) := by
simp only [add_comm a, image_add_const_Ioo]
end Set
| Mathlib/Algebra/Order/Interval/Set/Monoid.lean | 133 | 134 | |
/-
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.Functor.Category
import Mathlib.CategoryTheory.CommSq
/-!
# HomLift
Given a functor `p : 𝒳 ⥤ 𝒮`, this file provides API for expressing the fact that `p(φ) = f`
for given morphisms `φ` and `f`. The reason this API is needed is because, in general, `p.map φ = f`
does not make sense when the domain and/or codomain of `φ` and `f` are not definitionally equal.
## Main definition
Given morphism `φ : a ⟶ b` in `𝒳` and `f : R ⟶ S` in `𝒮`, `p.IsHomLift f φ` is a class, defined
using the auxiliary inductive type `IsHomLiftAux` which expresses the fact that `f = p(φ)`.
We also define a macro `subst_hom_lift p f φ` which can be used to substitute `f` with `p(φ)` in a
goal, this tactic is just short for `obtain ⟨⟩ := Functor.IsHomLift.cond (p:=p) (f:=f) (φ:=φ)`, and
it is used to make the code more readable.
-/
universe u₁ v₁ u₂ v₂
open CategoryTheory Category
variable {𝒮 : Type u₁} {𝒳 : Type u₂} [Category.{v₁} 𝒳] [Category.{v₂} 𝒮] (p : 𝒳 ⥤ 𝒮)
namespace CategoryTheory
/-- Helper-type for defining `IsHomLift`. -/
inductive IsHomLiftAux : ∀ {R S : 𝒮} {a b : 𝒳} (_ : R ⟶ S) (_ : a ⟶ b), Prop
| map {a b : 𝒳} (φ : a ⟶ b) : IsHomLiftAux (p.map φ) φ
/-- Given a functor `p : 𝒳 ⥤ 𝒮`, an arrow `φ : a ⟶ b` in `𝒳` and an arrow `f : R ⟶ S` in `𝒮`,
`p.IsHomLift f φ` expresses the fact that `φ` lifts `f` through `p`.
This is often drawn as:
```
a --φ--> b
- -
| |
v v
R --f--> S
``` -/
class Functor.IsHomLift {R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) : Prop where
cond : IsHomLiftAux p f φ
/-- `subst_hom_lift p f φ` tries to substitute `f` with `p(φ)` by using `p.IsHomLift f φ` -/
macro "subst_hom_lift" p:term:max f:term:max φ:term:max : tactic =>
`(tactic| obtain ⟨⟩ := Functor.IsHomLift.cond (p := $p) (f := $f) (φ := $φ))
/-- For any arrow `φ : a ⟶ b` in `𝒳`, `φ` lifts the arrow `p.map φ` in the base `𝒮`. -/
@[simp]
instance {a b : 𝒳} (φ : a ⟶ b) : p.IsHomLift (p.map φ) φ where
cond := by constructor
@[simp]
instance (a : 𝒳) : p.IsHomLift (𝟙 (p.obj a)) (𝟙 a) := by
rw [← p.map_id]; infer_instance
namespace IsHomLift
protected lemma id {p : 𝒳 ⥤ 𝒮} {R : 𝒮} {a : 𝒳} (ha : p.obj a = R) : p.IsHomLift (𝟙 R) (𝟙 a) := by
cases ha; infer_instance
section
variable {R S : 𝒮} {a b : 𝒳}
| lemma domain_eq (f : R ⟶ S) (φ : a ⟶ b) [p.IsHomLift f φ] : p.obj a = R := by
subst_hom_lift p f φ; rfl
| Mathlib/CategoryTheory/FiberedCategory/HomLift.lean | 76 | 77 |
/-
Copyright (c) 2021 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.Sets.OpenCover
/-!
# Sober spaces
A quasi-sober space is a topological space where every irreducible closed subset has a generic
point.
A sober space is a quasi-sober space where every irreducible closed subset
has a *unique* generic point. This is if and only if the space is T0, and thus sober spaces can be
stated via `[QuasiSober α] [T0Space α]`.
## Main definition
* `IsGenericPoint` : `x` is the generic point of `S` if `S` is the closure of `x`.
* `QuasiSober` : A space is quasi-sober if every irreducible closed subset has a generic point.
* `genericPoints` : The set of generic points of irreducible components.
-/
open Set
variable {α β : Type*} [TopologicalSpace α] [TopologicalSpace β]
section genericPoint
/-- `x` is a generic point of `S` if `S` is the closure of `x`. -/
def IsGenericPoint (x : α) (S : Set α) : Prop :=
closure ({x} : Set α) = S
theorem isGenericPoint_def {x : α} {S : Set α} : IsGenericPoint x S ↔ closure ({x} : Set α) = S :=
Iff.rfl
theorem IsGenericPoint.def {x : α} {S : Set α} (h : IsGenericPoint x S) :
closure ({x} : Set α) = S :=
h
theorem isGenericPoint_closure {x : α} : IsGenericPoint x (closure ({x} : Set α)) :=
refl _
variable {x y : α} {S U Z : Set α}
theorem isGenericPoint_iff_specializes : IsGenericPoint x S ↔ ∀ y, x ⤳ y ↔ y ∈ S := by
simp only [specializes_iff_mem_closure, IsGenericPoint, Set.ext_iff]
namespace IsGenericPoint
theorem specializes_iff_mem (h : IsGenericPoint x S) : x ⤳ y ↔ y ∈ S :=
isGenericPoint_iff_specializes.1 h y
protected theorem specializes (h : IsGenericPoint x S) (h' : y ∈ S) : x ⤳ y :=
h.specializes_iff_mem.2 h'
protected theorem mem (h : IsGenericPoint x S) : x ∈ S :=
h.specializes_iff_mem.1 specializes_rfl
protected theorem isClosed (h : IsGenericPoint x S) : IsClosed S :=
h.def ▸ isClosed_closure
protected theorem isIrreducible (h : IsGenericPoint x S) : IsIrreducible S :=
h.def ▸ isIrreducible_singleton.closure
protected theorem inseparable (h : IsGenericPoint x S) (h' : IsGenericPoint y S) :
Inseparable x y :=
(h.specializes h'.mem).antisymm (h'.specializes h.mem)
/-- In a T₀ space, each set has at most one generic point. -/
protected theorem eq [T0Space α] (h : IsGenericPoint x S) (h' : IsGenericPoint y S) : x = y :=
(h.inseparable h').eq
theorem mem_open_set_iff (h : IsGenericPoint x S) (hU : IsOpen U) : x ∈ U ↔ (S ∩ U).Nonempty :=
⟨fun h' => ⟨x, h.mem, h'⟩, fun ⟨_y, hyS, hyU⟩ => (h.specializes hyS).mem_open hU hyU⟩
theorem disjoint_iff (h : IsGenericPoint x S) (hU : IsOpen U) : Disjoint S U ↔ x ∉ U := by
rw [h.mem_open_set_iff hU, ← not_disjoint_iff_nonempty_inter, Classical.not_not]
theorem mem_closed_set_iff (h : IsGenericPoint x S) (hZ : IsClosed Z) : x ∈ Z ↔ S ⊆ Z := by
rw [← h.def, hZ.closure_subset_iff, singleton_subset_iff]
protected theorem image (h : IsGenericPoint x S) {f : α → β} (hf : Continuous f) :
IsGenericPoint (f x) (closure (f '' S)) := by
rw [isGenericPoint_def, ← h.def, ← image_singleton, closure_image_closure hf]
end IsGenericPoint
theorem isGenericPoint_iff_forall_closed (hS : IsClosed S) (hxS : x ∈ S) :
IsGenericPoint x S ↔ ∀ Z : Set α, IsClosed Z → x ∈ Z → S ⊆ Z := by
have : closure {x} ⊆ S := closure_minimal (singleton_subset_iff.2 hxS) hS
simp_rw [IsGenericPoint, subset_antisymm_iff, this, true_and, closure, subset_sInter_iff,
mem_setOf_eq, and_imp, singleton_subset_iff]
end genericPoint
section Sober
/-- A space is sober if every irreducible closed subset has a generic point. -/
@[mk_iff]
class QuasiSober (α : Type*) [TopologicalSpace α] : Prop where
sober : ∀ {S : Set α}, IsIrreducible S → IsClosed S → ∃ x, IsGenericPoint x S
| /-- A generic point of the closure of an irreducible space. -/
noncomputable def IsIrreducible.genericPoint [QuasiSober α] {S : Set α} (hS : IsIrreducible S) :
α :=
(QuasiSober.sober hS.closure isClosed_closure).choose
| Mathlib/Topology/Sober.lean | 107 | 111 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Finite.Defs
import Mathlib.Data.Finset.BooleanAlgebra
import Mathlib.Data.Finset.Image
import Mathlib.Data.Fintype.Defs
import Mathlib.Data.Fintype.OfMap
import Mathlib.Data.Fintype.Sets
import Mathlib.Data.List.FinRange
/-!
# Instances for finite types
This file is a collection of basic `Fintype` instances for types such as `Fin`, `Prod` and pi types.
-/
assert_not_exists Monoid
open Function
open Nat
universe u v
variable {α β γ : Type*}
open Finset
instance Fin.fintype (n : ℕ) : Fintype (Fin n) :=
⟨⟨List.finRange n, List.nodup_finRange n⟩, List.mem_finRange⟩
theorem Fin.univ_def (n : ℕ) : (univ : Finset (Fin n)) = ⟨List.finRange n, List.nodup_finRange n⟩ :=
rfl
theorem Finset.val_univ_fin (n : ℕ) : (Finset.univ : Finset (Fin n)).val = List.finRange n := rfl
/-- See also `nonempty_encodable`, `nonempty_denumerable`. -/
theorem nonempty_fintype (α : Type*) [Finite α] : Nonempty (Fintype α) := by
rcases Finite.exists_equiv_fin α with ⟨n, ⟨e⟩⟩
exact ⟨.ofEquiv _ e.symm⟩
@[simp] theorem List.toFinset_finRange (n : ℕ) : (List.finRange n).toFinset = Finset.univ := by
ext; simp
@[simp] theorem Fin.univ_val_map {n : ℕ} (f : Fin n → α) :
Finset.univ.val.map f = List.ofFn f := by
simp [List.ofFn_eq_map, univ_def]
theorem Fin.univ_image_def {n : ℕ} [DecidableEq α] (f : Fin n → α) :
Finset.univ.image f = (List.ofFn f).toFinset := by
simp [Finset.image]
theorem Fin.univ_map_def {n : ℕ} (f : Fin n ↪ α) :
Finset.univ.map f = ⟨List.ofFn f, List.nodup_ofFn.mpr f.injective⟩ := by
simp [Finset.map]
@[simp]
theorem Fin.image_succAbove_univ {n : ℕ} (i : Fin (n + 1)) : univ.image i.succAbove = {i}ᶜ := by
ext m
simp
@[simp]
theorem Fin.image_succ_univ (n : ℕ) : (univ : Finset (Fin n)).image Fin.succ = {0}ᶜ := by
rw [← Fin.succAbove_zero, Fin.image_succAbove_univ]
@[simp]
theorem Fin.image_castSucc (n : ℕ) :
(univ : Finset (Fin n)).image Fin.castSucc = {Fin.last n}ᶜ := by
rw [← Fin.succAbove_last, Fin.image_succAbove_univ]
/- The following three lemmas use `Finset.cons` instead of `insert` and `Finset.map` instead of
`Finset.image` to reduce proof obligations downstream. -/
/-- Embed `Fin n` into `Fin (n + 1)` by prepending zero to the `univ` -/
theorem Fin.univ_succ (n : ℕ) :
(univ : Finset (Fin (n + 1))) =
Finset.cons 0 (univ.map ⟨Fin.succ, Fin.succ_injective _⟩) (by simp [map_eq_image]) := by
simp [map_eq_image]
/-- Embed `Fin n` into `Fin (n + 1)` by appending a new `Fin.last n` to the `univ` -/
theorem Fin.univ_castSuccEmb (n : ℕ) :
(univ : Finset (Fin (n + 1))) =
Finset.cons (Fin.last n) (univ.map Fin.castSuccEmb) (by simp [map_eq_image]) := by
simp [map_eq_image]
/-- Embed `Fin n` into `Fin (n + 1)` by inserting
around a specified pivot `p : Fin (n + 1)` into the `univ` -/
theorem Fin.univ_succAbove (n : ℕ) (p : Fin (n + 1)) :
(univ : Finset (Fin (n + 1))) = Finset.cons p (univ.map <| Fin.succAboveEmb p) (by simp) := by
simp [map_eq_image]
@[simp] theorem Fin.univ_image_get [DecidableEq α] (l : List α) :
Finset.univ.image l.get = l.toFinset := by
simp [univ_image_def]
@[simp] theorem Fin.univ_image_getElem' [DecidableEq β] (l : List α) (f : α → β) :
Finset.univ.image (fun i : Fin l.length => f <| l[(i : Nat)]) = (l.map f).toFinset := by
simp only [univ_image_def, List.ofFn_getElem_eq_map]
theorem Fin.univ_image_get' [DecidableEq β] (l : List α) (f : α → β) :
Finset.univ.image (f <| l.get ·) = (l.map f).toFinset := by
simp
@[instance]
def Unique.fintype {α : Type*} [Unique α] : Fintype α :=
Fintype.ofSubsingleton default
/-- Short-circuit instance to decrease search for `Unique.fintype`,
since that relies on a subsingleton elimination for `Unique`. -/
instance Fintype.subtypeEq (y : α) : Fintype { x // x = y } :=
Fintype.subtype {y} (by simp)
/-- Short-circuit instance to decrease search for `Unique.fintype`,
since that relies on a subsingleton elimination for `Unique`. -/
instance Fintype.subtypeEq' (y : α) : Fintype { x // y = x } :=
Fintype.subtype {y} (by simp [eq_comm])
theorem Fintype.univ_empty : @univ Empty _ = ∅ :=
rfl
theorem Fintype.univ_pempty : @univ PEmpty _ = ∅ :=
rfl
instance Unit.fintype : Fintype Unit :=
Fintype.ofSubsingleton ()
theorem Fintype.univ_unit : @univ Unit _ = {()} :=
rfl
instance PUnit.fintype : Fintype PUnit :=
Fintype.ofSubsingleton PUnit.unit
theorem Fintype.univ_punit : @univ PUnit _ = {PUnit.unit} :=
rfl
@[simp]
theorem Fintype.univ_bool : @univ Bool _ = {true, false} :=
rfl
/-- Given that `α × β` is a fintype, `α` is also a fintype. -/
def Fintype.prodLeft {α β} [DecidableEq α] [Fintype (α × β)] [Nonempty β] : Fintype α :=
⟨(@univ (α × β) _).image Prod.fst, fun a => by simp⟩
/-- Given that `α × β` is a fintype, `β` is also a fintype. -/
def Fintype.prodRight {α β} [DecidableEq β] [Fintype (α × β)] [Nonempty α] : Fintype β :=
⟨(@univ (α × β) _).image Prod.snd, fun b => by simp⟩
instance ULift.fintype (α : Type*) [Fintype α] : Fintype (ULift α) :=
Fintype.ofEquiv _ Equiv.ulift.symm
instance PLift.fintype (α : Type*) [Fintype α] : Fintype (PLift α) :=
Fintype.ofEquiv _ Equiv.plift.symm
instance PLift.fintypeProp (p : Prop) [Decidable p] : Fintype (PLift p) :=
⟨if h : p then {⟨h⟩} else ∅, fun ⟨h⟩ => by simp [h]⟩
instance Quotient.fintype [Fintype α] (s : Setoid α) [DecidableRel ((· ≈ ·) : α → α → Prop)] :
Fintype (Quotient s) :=
Fintype.ofSurjective Quotient.mk'' Quotient.mk''_surjective
instance PSigma.fintypePropLeft {α : Prop} {β : α → Type*} [Decidable α] [∀ a, Fintype (β a)] :
Fintype (Σ'a, β a) :=
if h : α then Fintype.ofEquiv (β h) ⟨fun x => ⟨h, x⟩, PSigma.snd, fun _ => rfl, fun ⟨_, _⟩ => rfl⟩
else ⟨∅, fun x => (h x.1).elim⟩
instance PSigma.fintypePropRight {α : Type*} {β : α → Prop} [∀ a, Decidable (β a)] [Fintype α] :
Fintype (Σ'a, β a) :=
Fintype.ofEquiv { a // β a }
⟨fun ⟨x, y⟩ => ⟨x, y⟩, fun ⟨x, y⟩ => ⟨x, y⟩, fun ⟨_, _⟩ => rfl, fun ⟨_, _⟩ => rfl⟩
instance PSigma.fintypePropProp {α : Prop} {β : α → Prop} [Decidable α] [∀ a, Decidable (β a)] :
Fintype (Σ'a, β a) :=
if h : ∃ a, β a then ⟨{⟨h.fst, h.snd⟩}, fun ⟨_, _⟩ => by simp⟩ else ⟨∅, fun ⟨x, y⟩ =>
(h ⟨x, y⟩).elim⟩
instance pfunFintype (p : Prop) [Decidable p] (α : p → Type*) [∀ hp, Fintype (α hp)] :
Fintype (∀ hp : p, α hp) :=
if hp : p then Fintype.ofEquiv (α hp) ⟨fun a _ => a, fun f => f hp, fun _ => rfl, fun _ => rfl⟩
else ⟨singleton fun h => (hp h).elim, fun h => mem_singleton.2
(funext fun x => by contradiction)⟩
section Trunc
/-- For `s : Multiset α`, we can lift the existential statement that `∃ x, x ∈ s` to a `Trunc α`.
-/
def truncOfMultisetExistsMem {α} (s : Multiset α) : (∃ x, x ∈ s) → Trunc α :=
Quotient.recOnSubsingleton s fun l h =>
match l, h with
| [], _ => False.elim (by tauto)
| a :: _, _ => Trunc.mk a
/-- A `Nonempty` `Fintype` constructively contains an element.
-/
def truncOfNonemptyFintype (α) [Nonempty α] [Fintype α] : Trunc α :=
truncOfMultisetExistsMem Finset.univ.val (by simp)
/-- By iterating over the elements of a fintype, we can lift an existential statement `∃ a, P a`
to `Trunc (Σ' a, P a)`, containing data.
-/
def truncSigmaOfExists {α} [Fintype α] {P : α → Prop} [DecidablePred P] (h : ∃ a, P a) :
Trunc (Σ'a, P a) :=
@truncOfNonemptyFintype (Σ'a, P a) ((Exists.elim h) fun a ha => ⟨⟨a, ha⟩⟩) _
end Trunc
namespace Multiset
variable [Fintype α] [Fintype β]
@[simp]
theorem count_univ [DecidableEq α] (a : α) : count a Finset.univ.val = 1 :=
count_eq_one_of_mem Finset.univ.nodup (Finset.mem_univ _)
@[simp]
theorem map_univ_val_equiv (e : α ≃ β) :
map e univ.val = univ.val := by
rw [← congr_arg Finset.val (Finset.map_univ_equiv e), Finset.map_val, Equiv.coe_toEmbedding]
/-- For functions on finite sets, they are bijections iff they map universes into universes. -/
@[simp]
theorem bijective_iff_map_univ_eq_univ (f : α → β) :
f.Bijective ↔ map f (Finset.univ : Finset α).val = univ.val :=
⟨fun bij ↦ congr_arg (·.val) (map_univ_equiv <| Equiv.ofBijective f bij),
fun eq ↦ ⟨
fun a₁ a₂ ↦ inj_on_of_nodup_map (eq.symm ▸ univ.nodup) _ (mem_univ a₁) _ (mem_univ a₂),
fun b ↦ have ⟨a, _, h⟩ := mem_map.mp (eq.symm ▸ mem_univ_val b); ⟨a, h⟩⟩⟩
end Multiset
/-- Auxiliary definition to show `exists_seq_of_forall_finset_exists`. -/
noncomputable def seqOfForallFinsetExistsAux {α : Type*} [DecidableEq α] (P : α → Prop)
(r : α → α → Prop) (h : ∀ s : Finset α, ∃ y, (∀ x ∈ s, P x) → P y ∧ ∀ x ∈ s, r x y) : ℕ → α
| n =>
Classical.choose
(h
(Finset.image (fun i : Fin n => seqOfForallFinsetExistsAux P r h i)
(Finset.univ : Finset (Fin n))))
/-- Induction principle to build a sequence, by adding one point at a time satisfying a given
relation with respect to all the previously chosen points.
More precisely, Assume that, for any finite set `s`, one can find another point satisfying
some relation `r` with respect to all the points in `s`. Then one may construct a
function `f : ℕ → α` such that `r (f m) (f n)` holds whenever `m < n`.
We also ensure that all constructed points satisfy a given predicate `P`. -/
theorem exists_seq_of_forall_finset_exists {α : Type*} (P : α → Prop) (r : α → α → Prop)
(h : ∀ s : Finset α, (∀ x ∈ s, P x) → ∃ y, P y ∧ ∀ x ∈ s, r x y) :
∃ f : ℕ → α, (∀ n, P (f n)) ∧ ∀ m n, m < n → r (f m) (f n) := by
classical
have : Nonempty α := by
rcases h ∅ (by simp) with ⟨y, _⟩
exact ⟨y⟩
choose! F hF using h
have h' : ∀ s : Finset α, ∃ y, (∀ x ∈ s, P x) → P y ∧ ∀ x ∈ s, r x y := fun s => ⟨F s, hF s⟩
set f := seqOfForallFinsetExistsAux P r h' with hf
have A : ∀ n : ℕ, P (f n) := by
intro n
induction' n using Nat.strong_induction_on with n IH
have IH' : ∀ x : Fin n, P (f x) := fun n => IH n.1 n.2
rw [hf, seqOfForallFinsetExistsAux]
exact
(Classical.choose_spec
(h' (Finset.image (fun i : Fin n => f i) (Finset.univ : Finset (Fin n))))
(by simp [IH'])).1
refine ⟨f, A, fun m n hmn => ?_⟩
conv_rhs => rw [hf]
rw [seqOfForallFinsetExistsAux]
apply
(Classical.choose_spec
(h' (Finset.image (fun i : Fin n => f i) (Finset.univ : Finset (Fin n)))) (by simp [A])).2
exact Finset.mem_image.2 ⟨⟨m, hmn⟩, Finset.mem_univ _, rfl⟩
/-- Induction principle to build a sequence, by adding one point at a time satisfying a given
symmetric relation with respect to all the previously chosen points.
More precisely, Assume that, for any finite set `s`, one can find another point satisfying
some relation `r` with respect to all the points in `s`. Then one may construct a
function `f : ℕ → α` such that `r (f m) (f n)` holds whenever `m ≠ n`.
We also ensure that all constructed points satisfy a given predicate `P`. -/
theorem exists_seq_of_forall_finset_exists' {α : Type*} (P : α → Prop) (r : α → α → Prop)
[IsSymm α r] (h : ∀ s : Finset α, (∀ x ∈ s, P x) → ∃ y, P y ∧ ∀ x ∈ s, r x y) :
∃ f : ℕ → α, (∀ n, P (f n)) ∧ Pairwise (r on f) := by
rcases exists_seq_of_forall_finset_exists P r h with ⟨f, hf, hf'⟩
refine ⟨f, hf, fun m n hmn => ?_⟩
rcases lt_trichotomy m n with (h | rfl | h)
· exact hf' m n h
· exact (hmn rfl).elim
· unfold Function.onFun
apply symm
exact hf' n m h
| Mathlib/Data/Fintype/Basic.lean | 871 | 873 | |
/-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.FDeriv.Linear
import Mathlib.Analysis.Calculus.FDeriv.Comp
/-!
# Additive operations on derivatives
For detailed documentation of the Fréchet derivative,
see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`.
This file contains the usual formulas (and existence assertions) for the derivative of
* sum of finitely many functions
* multiplication of a function by a scalar constant
* negative of a function
* subtraction of two functions
-/
open Filter Asymptotics ContinuousLinearMap
noncomputable section
section
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
variable {f g : E → F}
variable {f' g' : E →L[𝕜] F}
variable {x : E}
variable {s : Set E}
variable {L : Filter E}
section ConstSMul
variable {R : Type*} [Semiring R] [Module R F] [SMulCommClass 𝕜 R F] [ContinuousConstSMul R F]
/-! ### Derivative of a function multiplied by a constant -/
@[fun_prop]
theorem HasStrictFDerivAt.const_smul (h : HasStrictFDerivAt f f' x) (c : R) :
HasStrictFDerivAt (fun x => c • f x) (c • f') x :=
(c • (1 : F →L[𝕜] F)).hasStrictFDerivAt.comp x h
theorem HasFDerivAtFilter.const_smul (h : HasFDerivAtFilter f f' x L) (c : R) :
HasFDerivAtFilter (fun x => c • f x) (c • f') x L :=
(c • (1 : F →L[𝕜] F)).hasFDerivAtFilter.comp x h tendsto_map
@[fun_prop]
nonrec theorem HasFDerivWithinAt.const_smul (h : HasFDerivWithinAt f f' s x) (c : R) :
HasFDerivWithinAt (fun x => c • f x) (c • f') s x :=
h.const_smul c
@[fun_prop]
nonrec theorem HasFDerivAt.const_smul (h : HasFDerivAt f f' x) (c : R) :
HasFDerivAt (fun x => c • f x) (c • f') x :=
h.const_smul c
@[fun_prop]
theorem DifferentiableWithinAt.const_smul (h : DifferentiableWithinAt 𝕜 f s x) (c : R) :
DifferentiableWithinAt 𝕜 (fun y => c • f y) s x :=
(h.hasFDerivWithinAt.const_smul c).differentiableWithinAt
@[fun_prop]
theorem DifferentiableAt.const_smul (h : DifferentiableAt 𝕜 f x) (c : R) :
DifferentiableAt 𝕜 (fun y => c • f y) x :=
(h.hasFDerivAt.const_smul c).differentiableAt
@[fun_prop]
theorem DifferentiableOn.const_smul (h : DifferentiableOn 𝕜 f s) (c : R) :
DifferentiableOn 𝕜 (fun y => c • f y) s := fun x hx => (h x hx).const_smul c
@[fun_prop]
theorem Differentiable.const_smul (h : Differentiable 𝕜 f) (c : R) :
Differentiable 𝕜 fun y => c • f y := fun x => (h x).const_smul c
theorem fderivWithin_const_smul (hxs : UniqueDiffWithinAt 𝕜 s x)
(h : DifferentiableWithinAt 𝕜 f s x) (c : R) :
fderivWithin 𝕜 (fun y => c • f y) s x = c • fderivWithin 𝕜 f s x :=
(h.hasFDerivWithinAt.const_smul c).fderivWithin hxs
/-- Version of `fderivWithin_const_smul` written with `c • f` instead of `fun y ↦ c • f y`. -/
theorem fderivWithin_const_smul' (hxs : UniqueDiffWithinAt 𝕜 s x)
(h : DifferentiableWithinAt 𝕜 f s x) (c : R) :
fderivWithin 𝕜 (c • f) s x = c • fderivWithin 𝕜 f s x :=
fderivWithin_const_smul hxs h c
theorem fderiv_const_smul (h : DifferentiableAt 𝕜 f x) (c : R) :
fderiv 𝕜 (fun y => c • f y) x = c • fderiv 𝕜 f x :=
(h.hasFDerivAt.const_smul c).fderiv
/-- Version of `fderiv_const_smul` written with `c • f` instead of `fun y ↦ c • f y`. -/
theorem fderiv_const_smul' (h : DifferentiableAt 𝕜 f x) (c : R) :
fderiv 𝕜 (c • f) x = c • fderiv 𝕜 f x :=
(h.hasFDerivAt.const_smul c).fderiv
end ConstSMul
section Add
/-! ### Derivative of the sum of two functions -/
@[fun_prop]
nonrec theorem HasStrictFDerivAt.add (hf : HasStrictFDerivAt f f' x)
(hg : HasStrictFDerivAt g g' x) : HasStrictFDerivAt (fun y => f y + g y) (f' + g') x :=
.of_isLittleO <| (hf.isLittleO.add hg.isLittleO).congr_left fun y => by
simp only [LinearMap.sub_apply, LinearMap.add_apply, map_sub, map_add, add_apply]
abel
theorem HasFDerivAtFilter.add (hf : HasFDerivAtFilter f f' x L)
(hg : HasFDerivAtFilter g g' x L) : HasFDerivAtFilter (fun y => f y + g y) (f' + g') x L :=
.of_isLittleO <| (hf.isLittleO.add hg.isLittleO).congr_left fun _ => by
simp only [LinearMap.sub_apply, LinearMap.add_apply, map_sub, map_add, add_apply]
abel
@[fun_prop]
nonrec theorem HasFDerivWithinAt.add (hf : HasFDerivWithinAt f f' s x)
(hg : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt (fun y => f y + g y) (f' + g') s x :=
hf.add hg
@[fun_prop]
nonrec theorem HasFDerivAt.add (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) :
HasFDerivAt (fun x => f x + g x) (f' + g') x :=
hf.add hg
@[fun_prop]
theorem DifferentiableWithinAt.add (hf : DifferentiableWithinAt 𝕜 f s x)
(hg : DifferentiableWithinAt 𝕜 g s x) : DifferentiableWithinAt 𝕜 (fun y => f y + g y) s x :=
(hf.hasFDerivWithinAt.add hg.hasFDerivWithinAt).differentiableWithinAt
@[simp, fun_prop]
theorem DifferentiableAt.add (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) :
DifferentiableAt 𝕜 (fun y => f y + g y) x :=
(hf.hasFDerivAt.add hg.hasFDerivAt).differentiableAt
@[fun_prop]
theorem DifferentiableOn.add (hf : DifferentiableOn 𝕜 f s) (hg : DifferentiableOn 𝕜 g s) :
DifferentiableOn 𝕜 (fun y => f y + g y) s := fun x hx => (hf x hx).add (hg x hx)
@[simp, fun_prop]
theorem Differentiable.add (hf : Differentiable 𝕜 f) (hg : Differentiable 𝕜 g) :
Differentiable 𝕜 fun y => f y + g y := fun x => (hf x).add (hg x)
theorem fderivWithin_add (hxs : UniqueDiffWithinAt 𝕜 s x) (hf : DifferentiableWithinAt 𝕜 f s x)
(hg : DifferentiableWithinAt 𝕜 g s x) :
fderivWithin 𝕜 (fun y => f y + g y) s x = fderivWithin 𝕜 f s x + fderivWithin 𝕜 g s x :=
(hf.hasFDerivWithinAt.add hg.hasFDerivWithinAt).fderivWithin hxs
/-- Version of `fderivWithin_add` where the function is written as `f + g` instead
of `fun y ↦ f y + g y`. -/
theorem fderivWithin_add' (hxs : UniqueDiffWithinAt 𝕜 s x) (hf : DifferentiableWithinAt 𝕜 f s x)
(hg : DifferentiableWithinAt 𝕜 g s x) :
fderivWithin 𝕜 (f + g) s x = fderivWithin 𝕜 f s x + fderivWithin 𝕜 g s x :=
fderivWithin_add hxs hf hg
theorem fderiv_add (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) :
fderiv 𝕜 (fun y => f y + g y) x = fderiv 𝕜 f x + fderiv 𝕜 g x :=
(hf.hasFDerivAt.add hg.hasFDerivAt).fderiv
/-- Version of `fderiv_add` where the function is written as `f + g` instead
of `fun y ↦ f y + g y`. -/
theorem fderiv_add' (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) :
fderiv 𝕜 (f + g) x = fderiv 𝕜 f x + fderiv 𝕜 g x :=
fderiv_add hf hg
@[simp]
theorem hasFDerivAtFilter_add_const_iff (c : F) :
HasFDerivAtFilter (f · + c) f' x L ↔ HasFDerivAtFilter f f' x L := by
simp [hasFDerivAtFilter_iff_isLittleOTVS]
alias ⟨_, HasFDerivAtFilter.add_const⟩ := hasFDerivAtFilter_add_const_iff
@[simp]
theorem hasStrictFDerivAt_add_const_iff (c : F) :
HasStrictFDerivAt (f · + c) f' x ↔ HasStrictFDerivAt f f' x := by
simp [hasStrictFDerivAt_iff_isLittleO]
@[fun_prop]
alias ⟨_, HasStrictFDerivAt.add_const⟩ := hasStrictFDerivAt_add_const_iff
@[simp]
theorem hasFDerivWithinAt_add_const_iff (c : F) :
HasFDerivWithinAt (f · + c) f' s x ↔ HasFDerivWithinAt f f' s x :=
hasFDerivAtFilter_add_const_iff c
@[fun_prop]
alias ⟨_, HasFDerivWithinAt.add_const⟩ := hasFDerivWithinAt_add_const_iff
@[simp]
theorem hasFDerivAt_add_const_iff (c : F) : HasFDerivAt (f · + c) f' x ↔ HasFDerivAt f f' x :=
hasFDerivAtFilter_add_const_iff c
@[fun_prop]
alias ⟨_, HasFDerivAt.add_const⟩ := hasFDerivAt_add_const_iff
@[simp]
theorem differentiableWithinAt_add_const_iff (c : F) :
DifferentiableWithinAt 𝕜 (fun y => f y + c) s x ↔ DifferentiableWithinAt 𝕜 f s x :=
exists_congr fun _ ↦ hasFDerivWithinAt_add_const_iff c
@[fun_prop]
alias ⟨_, DifferentiableWithinAt.add_const⟩ := differentiableWithinAt_add_const_iff
@[simp]
theorem differentiableAt_add_const_iff (c : F) :
DifferentiableAt 𝕜 (fun y => f y + c) x ↔ DifferentiableAt 𝕜 f x :=
exists_congr fun _ ↦ hasFDerivAt_add_const_iff c
@[fun_prop]
alias ⟨_, DifferentiableAt.add_const⟩ := differentiableAt_add_const_iff
@[simp]
theorem differentiableOn_add_const_iff (c : F) :
DifferentiableOn 𝕜 (fun y => f y + c) s ↔ DifferentiableOn 𝕜 f s :=
forall₂_congr fun _ _ ↦ differentiableWithinAt_add_const_iff c
@[fun_prop]
alias ⟨_, DifferentiableOn.add_const⟩ := differentiableOn_add_const_iff
@[simp]
theorem differentiable_add_const_iff (c : F) :
(Differentiable 𝕜 fun y => f y + c) ↔ Differentiable 𝕜 f :=
forall_congr' fun _ ↦ differentiableAt_add_const_iff c
@[fun_prop]
alias ⟨_, Differentiable.add_const⟩ := differentiable_add_const_iff
@[simp]
theorem fderivWithin_add_const (c : F) :
fderivWithin 𝕜 (fun y => f y + c) s x = fderivWithin 𝕜 f s x := by
classical simp [fderivWithin]
@[simp]
theorem fderiv_add_const (c : F) : fderiv 𝕜 (fun y => f y + c) x = fderiv 𝕜 f x := by
simp only [← fderivWithin_univ, fderivWithin_add_const]
@[simp]
theorem hasFDerivAtFilter_const_add_iff (c : F) :
HasFDerivAtFilter (c + f ·) f' x L ↔ HasFDerivAtFilter f f' x L := by
simpa only [add_comm] using hasFDerivAtFilter_add_const_iff c
alias ⟨_, HasFDerivAtFilter.const_add⟩ := hasFDerivAtFilter_const_add_iff
@[simp]
theorem hasStrictFDerivAt_const_add_iff (c : F) :
HasStrictFDerivAt (c + f ·) f' x ↔ HasStrictFDerivAt f f' x := by
simpa only [add_comm] using hasStrictFDerivAt_add_const_iff c
@[fun_prop]
alias ⟨_, HasStrictFDerivAt.const_add⟩ := hasStrictFDerivAt_const_add_iff
@[simp]
theorem hasFDerivWithinAt_const_add_iff (c : F) :
HasFDerivWithinAt (c + f ·) f' s x ↔ HasFDerivWithinAt f f' s x :=
hasFDerivAtFilter_const_add_iff c
@[fun_prop]
alias ⟨_, HasFDerivWithinAt.const_add⟩ := hasFDerivWithinAt_const_add_iff
@[simp]
theorem hasFDerivAt_const_add_iff (c : F) : HasFDerivAt (c + f ·) f' x ↔ HasFDerivAt f f' x :=
hasFDerivAtFilter_const_add_iff c
@[fun_prop]
alias ⟨_, HasFDerivAt.const_add⟩ := hasFDerivAt_const_add_iff
@[simp]
theorem differentiableWithinAt_const_add_iff (c : F) :
DifferentiableWithinAt 𝕜 (fun y => c + f y) s x ↔ DifferentiableWithinAt 𝕜 f s x :=
exists_congr fun _ ↦ hasFDerivWithinAt_const_add_iff c
@[fun_prop]
alias ⟨_, DifferentiableWithinAt.const_add⟩ := differentiableWithinAt_const_add_iff
@[simp]
theorem differentiableAt_const_add_iff (c : F) :
DifferentiableAt 𝕜 (fun y => c + f y) x ↔ DifferentiableAt 𝕜 f x :=
exists_congr fun _ ↦ hasFDerivAt_const_add_iff c
@[fun_prop]
alias ⟨_, DifferentiableAt.const_add⟩ := differentiableAt_const_add_iff
@[simp]
theorem differentiableOn_const_add_iff (c : F) :
DifferentiableOn 𝕜 (fun y => c + f y) s ↔ DifferentiableOn 𝕜 f s :=
forall₂_congr fun _ _ ↦ differentiableWithinAt_const_add_iff c
@[fun_prop]
alias ⟨_, DifferentiableOn.const_add⟩ := differentiableOn_const_add_iff
@[simp]
theorem differentiable_const_add_iff (c : F) :
(Differentiable 𝕜 fun y => c + f y) ↔ Differentiable 𝕜 f :=
forall_congr' fun _ ↦ differentiableAt_const_add_iff c
@[fun_prop]
alias ⟨_, Differentiable.const_add⟩ := differentiable_const_add_iff
@[simp]
theorem fderivWithin_const_add (c : F) :
fderivWithin 𝕜 (fun y => c + f y) s x = fderivWithin 𝕜 f s x := by
simpa only [add_comm] using fderivWithin_add_const c
@[simp]
theorem fderiv_const_add (c : F) : fderiv 𝕜 (fun y => c + f y) x = fderiv 𝕜 f x := by
simp only [add_comm c, fderiv_add_const]
end Add
section Sum
/-! ### Derivative of a finite sum of functions -/
variable {ι : Type*} {u : Finset ι} {A : ι → E → F} {A' : ι → E →L[𝕜] F}
@[fun_prop]
theorem HasStrictFDerivAt.sum (h : ∀ i ∈ u, HasStrictFDerivAt (A i) (A' i) x) :
HasStrictFDerivAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x := by
simp only [hasStrictFDerivAt_iff_isLittleO] at *
convert IsLittleO.sum h
simp [Finset.sum_sub_distrib, ContinuousLinearMap.sum_apply]
theorem HasFDerivAtFilter.sum (h : ∀ i ∈ u, HasFDerivAtFilter (A i) (A' i) x L) :
HasFDerivAtFilter (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x L := by
simp only [hasFDerivAtFilter_iff_isLittleO] at *
convert IsLittleO.sum h
simp [ContinuousLinearMap.sum_apply]
@[fun_prop]
theorem HasFDerivWithinAt.sum (h : ∀ i ∈ u, HasFDerivWithinAt (A i) (A' i) s x) :
HasFDerivWithinAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) s x :=
HasFDerivAtFilter.sum h
@[fun_prop]
theorem HasFDerivAt.sum (h : ∀ i ∈ u, HasFDerivAt (A i) (A' i) x) :
HasFDerivAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x :=
HasFDerivAtFilter.sum h
@[fun_prop]
theorem DifferentiableWithinAt.sum (h : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (A i) s x) :
DifferentiableWithinAt 𝕜 (fun y => ∑ i ∈ u, A i y) s x :=
HasFDerivWithinAt.differentiableWithinAt <|
HasFDerivWithinAt.sum fun i hi => (h i hi).hasFDerivWithinAt
@[simp, fun_prop]
theorem DifferentiableAt.sum (h : ∀ i ∈ u, DifferentiableAt 𝕜 (A i) x) :
DifferentiableAt 𝕜 (fun y => ∑ i ∈ u, A i y) x :=
HasFDerivAt.differentiableAt <| HasFDerivAt.sum fun i hi => (h i hi).hasFDerivAt
@[fun_prop]
theorem DifferentiableOn.sum (h : ∀ i ∈ u, DifferentiableOn 𝕜 (A i) s) :
DifferentiableOn 𝕜 (fun y => ∑ i ∈ u, A i y) s := fun x hx =>
DifferentiableWithinAt.sum fun i hi => h i hi x hx
@[simp, fun_prop]
theorem Differentiable.sum (h : ∀ i ∈ u, Differentiable 𝕜 (A i)) :
Differentiable 𝕜 fun y => ∑ i ∈ u, A i y := fun x => DifferentiableAt.sum fun i hi => h i hi x
theorem fderivWithin_sum (hxs : UniqueDiffWithinAt 𝕜 s x)
(h : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (A i) s x) :
fderivWithin 𝕜 (fun y => ∑ i ∈ u, A i y) s x = ∑ i ∈ u, fderivWithin 𝕜 (A i) s x :=
(HasFDerivWithinAt.sum fun i hi => (h i hi).hasFDerivWithinAt).fderivWithin hxs
theorem fderiv_sum (h : ∀ i ∈ u, DifferentiableAt 𝕜 (A i) x) :
fderiv 𝕜 (fun y => ∑ i ∈ u, A i y) x = ∑ i ∈ u, fderiv 𝕜 (A i) x :=
(HasFDerivAt.sum fun i hi => (h i hi).hasFDerivAt).fderiv
end Sum
section Neg
/-! ### Derivative of the negative of a function -/
@[fun_prop]
theorem HasStrictFDerivAt.neg (h : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (fun x => -f x) (-f') x :=
(-1 : F →L[𝕜] F).hasStrictFDerivAt.comp x h
theorem HasFDerivAtFilter.neg (h : HasFDerivAtFilter f f' x L) :
HasFDerivAtFilter (fun x => -f x) (-f') x L :=
(-1 : F →L[𝕜] F).hasFDerivAtFilter.comp x h tendsto_map
@[fun_prop]
nonrec theorem HasFDerivWithinAt.neg (h : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (fun x => -f x) (-f') s x :=
h.neg
@[fun_prop]
nonrec theorem HasFDerivAt.neg (h : HasFDerivAt f f' x) : HasFDerivAt (fun x => -f x) (-f') x :=
h.neg
@[fun_prop]
theorem DifferentiableWithinAt.neg (h : DifferentiableWithinAt 𝕜 f s x) :
DifferentiableWithinAt 𝕜 (fun y => -f y) s x :=
h.hasFDerivWithinAt.neg.differentiableWithinAt
@[simp]
theorem differentiableWithinAt_neg_iff :
DifferentiableWithinAt 𝕜 (fun y => -f y) s x ↔ DifferentiableWithinAt 𝕜 f s x :=
⟨fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩
@[fun_prop]
theorem DifferentiableAt.neg (h : DifferentiableAt 𝕜 f x) : DifferentiableAt 𝕜 (fun y => -f y) x :=
h.hasFDerivAt.neg.differentiableAt
@[simp]
theorem differentiableAt_neg_iff : DifferentiableAt 𝕜 (fun y => -f y) x ↔ DifferentiableAt 𝕜 f x :=
⟨fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩
@[fun_prop]
theorem DifferentiableOn.neg (h : DifferentiableOn 𝕜 f s) : DifferentiableOn 𝕜 (fun y => -f y) s :=
fun x hx => (h x hx).neg
@[simp]
theorem differentiableOn_neg_iff : DifferentiableOn 𝕜 (fun y => -f y) s ↔ DifferentiableOn 𝕜 f s :=
⟨fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩
@[fun_prop]
theorem Differentiable.neg (h : Differentiable 𝕜 f) : Differentiable 𝕜 fun y => -f y := fun x =>
(h x).neg
@[simp]
theorem differentiable_neg_iff : (Differentiable 𝕜 fun y => -f y) ↔ Differentiable 𝕜 f :=
⟨fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩
theorem fderivWithin_neg (hxs : UniqueDiffWithinAt 𝕜 s x) :
fderivWithin 𝕜 (fun y => -f y) s x = -fderivWithin 𝕜 f s x := by
classical
by_cases h : DifferentiableWithinAt 𝕜 f s x
· exact h.hasFDerivWithinAt.neg.fderivWithin hxs
· rw [fderivWithin_zero_of_not_differentiableWithinAt h,
fderivWithin_zero_of_not_differentiableWithinAt, neg_zero]
simpa
/-- Version of `fderivWithin_neg` where the function is written `-f` instead of `fun y ↦ - f y`. -/
theorem fderivWithin_neg' (hxs : UniqueDiffWithinAt 𝕜 s x) :
fderivWithin 𝕜 (-f) s x = -fderivWithin 𝕜 f s x :=
fderivWithin_neg hxs
@[simp]
theorem fderiv_neg : fderiv 𝕜 (fun y => -f y) x = -fderiv 𝕜 f x := by
simp only [← fderivWithin_univ, fderivWithin_neg uniqueDiffWithinAt_univ]
/-- Version of `fderiv_neg` where the function is written `-f` instead of `fun y ↦ - f y`. -/
theorem fderiv_neg' : fderiv 𝕜 (-f) x = -fderiv 𝕜 f x :=
| fderiv_neg
| Mathlib/Analysis/Calculus/FDeriv/Add.lean | 454 | 455 |
/-
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 <;>
try simp only [show zero = 0 from rfl, show ((0 : Num) : ℕ) = 0 from rfl]
· rw [f00, Nat.bitwise_zero]; rfl
· rw [f0n, Nat.bitwise_zero_left]
cases g false true <;> rfl
· rw [fn0, Nat.bitwise_zero_right]
cases g true false <;> rfl
· rw [fnn]
have this b (n : PosNum) : (cond b (↑n) 0 : ℕ) = ↑(cond b (pos n) 0 : Num) := by
cases b <;> rfl
have this' b (n : PosNum) : ↑ (pos (PosNum.bit b n)) = Nat.bit b ↑n := by
cases b <;> simp
induction' m with m IH m IH generalizing n <;> obtain - | n | n := n
any_goals simp only [show one = 1 from rfl, show pos 1 = 1 from rfl,
show PosNum.bit0 = PosNum.bit false from rfl, show PosNum.bit1 = PosNum.bit true from rfl,
show ((1 : Num) : ℕ) = Nat.bit true 0 from rfl]
all_goals
repeat rw [this']
rw [Nat.bitwise_bit gff]
any_goals rw [Nat.bitwise_zero, p11]; cases g true true <;> rfl
any_goals rw [Nat.bitwise_zero_left, ← Bool.cond_eq_ite, this, ← bit_to_nat, p1b]
any_goals rw [Nat.bitwise_zero_right, ← Bool.cond_eq_ite, this, ← bit_to_nat, pb1]
all_goals
rw [← show ∀ n : PosNum, ↑(p m n) = Nat.bitwise g ↑m ↑n from IH]
rw [← bit_to_nat, pbb]
@[simp, norm_cast]
theorem castNum_or : ∀ m n : Num, ↑(m ||| n) = (↑m ||| ↑n : ℕ) := by
apply castNum_eq_bitwise fun x y => pos (PosNum.lor x y) <;>
(try rintro (_ | _)) <;> (try rintro (_ | _)) <;> intros <;> rfl
@[simp, norm_cast]
theorem castNum_and : ∀ m n : Num, ↑(m &&& n) = (↑m &&& ↑n : ℕ) := by
apply castNum_eq_bitwise PosNum.land <;> intros <;> (try cases_type* Bool) <;> rfl
@[simp, norm_cast]
theorem castNum_ldiff : ∀ m n : Num, (ldiff m n : ℕ) = Nat.ldiff m n := by
apply castNum_eq_bitwise PosNum.ldiff <;> intros <;> (try cases_type* Bool) <;> rfl
@[simp, norm_cast]
theorem castNum_xor : ∀ m n : Num, ↑(m ^^^ n) = (↑m ^^^ ↑n : ℕ) := by
apply castNum_eq_bitwise PosNum.lxor <;> intros <;> (try cases_type* Bool) <;> rfl
@[simp, norm_cast]
theorem castNum_shiftLeft (m : Num) (n : Nat) : ↑(m <<< n) = (m : ℕ) <<< (n : ℕ) := by
cases m <;> dsimp only [← shiftl_eq_shiftLeft, shiftl]
· symm
apply Nat.zero_shiftLeft
simp only [cast_pos]
induction' n with n IH
· rfl
simp [PosNum.shiftl_succ_eq_bit0_shiftl, Nat.shiftLeft_succ, IH, pow_succ, ← mul_assoc, mul_comm,
-shiftl_eq_shiftLeft, -PosNum.shiftl_eq_shiftLeft, shiftl, mul_two]
@[simp, norm_cast]
theorem castNum_shiftRight (m : Num) (n : Nat) : ↑(m >>> n) = (m : ℕ) >>> (n : ℕ) := by
obtain - | m := m <;> dsimp only [← shiftr_eq_shiftRight, shiftr]
· symm
apply Nat.zero_shiftRight
induction' n with n IH generalizing m
· cases m <;> rfl
have hdiv2 : ∀ m, Nat.div2 (m + m) = m := by intro; rw [Nat.div2_val]; omega
obtain - | m | m := m <;> dsimp only [PosNum.shiftr, ← PosNum.shiftr_eq_shiftRight]
· rw [Nat.shiftRight_eq_div_pow]
symm
apply Nat.div_eq_of_lt
simp
· trans
· apply IH
change Nat.shiftRight m n = Nat.shiftRight (m + m + 1) (n + 1)
rw [add_comm n 1, @Nat.shiftRight_eq _ (1 + n), Nat.shiftRight_add]
apply congr_arg fun x => Nat.shiftRight x n
simp [-add_assoc, Nat.shiftRight_succ, Nat.shiftRight_zero, ← Nat.div2_val, hdiv2]
· trans
· apply IH
change Nat.shiftRight m n = Nat.shiftRight (m + m) (n + 1)
rw [add_comm n 1, @Nat.shiftRight_eq _ (1 + n), Nat.shiftRight_add]
apply congr_arg fun x => Nat.shiftRight x n
simp [-add_assoc, Nat.shiftRight_succ, Nat.shiftRight_zero, ← Nat.div2_val, hdiv2]
@[simp]
theorem castNum_testBit (m n) : testBit m n = Nat.testBit m n := by
cases m with dsimp only [testBit]
| zero =>
rw [show (Num.zero : Nat) = 0 from rfl, Nat.zero_testBit]
| pos m =>
rw [cast_pos]
induction' n with n IH generalizing m <;> obtain - | m | m := m
<;> simp only [PosNum.testBit]
· rfl
· rw [PosNum.cast_bit1, ← two_mul, ← congr_fun Nat.bit_true, Nat.testBit_bit_zero]
· rw [PosNum.cast_bit0, ← two_mul, ← congr_fun Nat.bit_false, Nat.testBit_bit_zero]
· simp [Nat.testBit_add_one]
· rw [PosNum.cast_bit1, ← two_mul, ← congr_fun Nat.bit_true, Nat.testBit_bit_succ, IH]
· rw [PosNum.cast_bit0, ← two_mul, ← congr_fun Nat.bit_false, Nat.testBit_bit_succ, IH]
end Num
namespace Int
/-- Cast a `SNum` to the corresponding integer. -/
def ofSnum : SNum → ℤ :=
SNum.rec' (fun a => cond a (-1) 0) fun a _p IH => cond a (2 * IH + 1) (2 * IH)
instance snumCoe : Coe SNum ℤ :=
⟨ofSnum⟩
end Int
instance SNum.lt : LT SNum :=
⟨fun a b => (a : ℤ) < b⟩
instance SNum.le : LE SNum :=
⟨fun a b => (a : ℤ) ≤ b⟩
| Mathlib/Data/Num/Lemmas.lean | 1,384 | 1,385 | |
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Lie.Abelian
import Mathlib.Algebra.Lie.Solvable
import Mathlib.LinearAlgebra.Dual.Defs
/-!
# Characters of Lie algebras
A character of a Lie algebra `L` over a commutative ring `R` is a morphism of Lie algebras `L → R`,
where `R` is regarded as a Lie algebra over itself via the ring commutator. For an Abelian Lie
algebra (e.g., a Cartan subalgebra of a semisimple Lie algebra) a character is just a linear form.
## Main definitions
* `LieAlgebra.LieCharacter`
* `LieAlgebra.lieCharacterEquivLinearDual`
## Tags
lie algebra, lie character
-/
universe u v w w₁
namespace LieAlgebra
variable (R : Type u) (L : Type v) [CommRing R] [LieRing L] [LieAlgebra R L]
/-- A character of a Lie algebra is a morphism to the scalars. -/
abbrev LieCharacter :=
L →ₗ⁅R⁆ R
variable {R L}
theorem lieCharacter_apply_lie (χ : LieCharacter R L) (x y : L) : χ ⁅x, y⁆ = 0 := by
rw [LieHom.map_lie, LieRing.of_associative_ring_bracket, mul_comm, sub_self]
@[simp]
| theorem lieCharacter_apply_lie' (χ : LieCharacter R L) (x y : L) : ⁅χ x, χ y⁆ = 0 := by
rw [LieRing.of_associative_ring_bracket, mul_comm, sub_self]
| Mathlib/Algebra/Lie/Character.lean | 44 | 45 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes Hölzl, Patrick Massot
-/
import Mathlib.Data.Set.Image
import Mathlib.Data.SProd
/-!
# Sets in product and pi types
This file proves basic properties of product of sets in `α × β` and in `Π i, α i`, and of the
diagonal of a type.
## Main declarations
This file contains basic results on the following notions, which are defined in `Set.Operations`.
* `Set.prod`: Binary product of sets. For `s : Set α`, `t : Set β`, we have
`s.prod t : Set (α × β)`. Denoted by `s ×ˢ t`.
* `Set.diagonal`: Diagonal of a type. `Set.diagonal α = {(x, x) | x : α}`.
* `Set.offDiag`: Off-diagonal. `s ×ˢ s` without the diagonal.
* `Set.pi`: Arbitrary product of sets.
-/
open Function
namespace Set
/-! ### Cartesian binary product of sets -/
section Prod
variable {α β γ δ : Type*} {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {a : α} {b : β}
theorem Subsingleton.prod (hs : s.Subsingleton) (ht : t.Subsingleton) :
(s ×ˢ t).Subsingleton := fun _x hx _y hy ↦
Prod.ext (hs hx.1 hy.1) (ht hx.2 hy.2)
noncomputable instance decidableMemProd [DecidablePred (· ∈ s)] [DecidablePred (· ∈ t)] :
DecidablePred (· ∈ s ×ˢ t) := fun x => inferInstanceAs (Decidable (x.1 ∈ s ∧ x.2 ∈ t))
@[gcongr]
theorem prod_mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : s₁ ×ˢ t₁ ⊆ s₂ ×ˢ t₂ :=
fun _ ⟨h₁, h₂⟩ => ⟨hs h₁, ht h₂⟩
@[gcongr]
theorem prod_mono_left (hs : s₁ ⊆ s₂) : s₁ ×ˢ t ⊆ s₂ ×ˢ t :=
prod_mono hs Subset.rfl
@[gcongr]
theorem prod_mono_right (ht : t₁ ⊆ t₂) : s ×ˢ t₁ ⊆ s ×ˢ t₂ :=
prod_mono Subset.rfl ht
@[simp]
theorem prod_self_subset_prod_self : s₁ ×ˢ s₁ ⊆ s₂ ×ˢ s₂ ↔ s₁ ⊆ s₂ :=
⟨fun h _ hx => (h (mk_mem_prod hx hx)).1, fun h _ hx => ⟨h hx.1, h hx.2⟩⟩
@[simp]
theorem prod_self_ssubset_prod_self : s₁ ×ˢ s₁ ⊂ s₂ ×ˢ s₂ ↔ s₁ ⊂ s₂ :=
and_congr prod_self_subset_prod_self <| not_congr prod_self_subset_prod_self
theorem prod_subset_iff {P : Set (α × β)} : s ×ˢ t ⊆ P ↔ ∀ x ∈ s, ∀ y ∈ t, (x, y) ∈ P :=
⟨fun h _ hx _ hy => h (mk_mem_prod hx hy), fun h ⟨_, _⟩ hp => h _ hp.1 _ hp.2⟩
theorem forall_prod_set {p : α × β → Prop} : (∀ x ∈ s ×ˢ t, p x) ↔ ∀ x ∈ s, ∀ y ∈ t, p (x, y) :=
prod_subset_iff
theorem exists_prod_set {p : α × β → Prop} : (∃ x ∈ s ×ˢ t, p x) ↔ ∃ x ∈ s, ∃ y ∈ t, p (x, y) := by
simp [and_assoc]
@[simp]
theorem prod_empty : s ×ˢ (∅ : Set β) = ∅ := by
ext
exact iff_of_eq (and_false _)
@[simp]
theorem empty_prod : (∅ : Set α) ×ˢ t = ∅ := by
ext
exact iff_of_eq (false_and _)
@[simp, mfld_simps]
theorem univ_prod_univ : @univ α ×ˢ @univ β = univ := by
ext
exact iff_of_eq (true_and _)
theorem univ_prod {t : Set β} : (univ : Set α) ×ˢ t = Prod.snd ⁻¹' t := by simp [prod_eq]
theorem prod_univ {s : Set α} : s ×ˢ (univ : Set β) = Prod.fst ⁻¹' s := by simp [prod_eq]
@[simp] lemma prod_eq_univ [Nonempty α] [Nonempty β] : s ×ˢ t = univ ↔ s = univ ∧ t = univ := by
simp [eq_univ_iff_forall, forall_and]
theorem singleton_prod : ({a} : Set α) ×ˢ t = Prod.mk a '' t := by
ext ⟨x, y⟩
simp [and_left_comm, eq_comm]
theorem prod_singleton : s ×ˢ ({b} : Set β) = (fun a => (a, b)) '' s := by
ext ⟨x, y⟩
simp [and_left_comm, eq_comm]
@[simp]
theorem singleton_prod_singleton : ({a} : Set α) ×ˢ ({b} : Set β) = {(a, b)} := by ext ⟨c, d⟩; simp
@[simp]
theorem union_prod : (s₁ ∪ s₂) ×ˢ t = s₁ ×ˢ t ∪ s₂ ×ˢ t := by
ext ⟨x, y⟩
simp [or_and_right]
@[simp]
theorem prod_union : s ×ˢ (t₁ ∪ t₂) = s ×ˢ t₁ ∪ s ×ˢ t₂ := by
ext ⟨x, y⟩
simp [and_or_left]
theorem inter_prod : (s₁ ∩ s₂) ×ˢ t = s₁ ×ˢ t ∩ s₂ ×ˢ t := by
ext ⟨x, y⟩
simp only [← and_and_right, mem_inter_iff, mem_prod]
theorem prod_inter : s ×ˢ (t₁ ∩ t₂) = s ×ˢ t₁ ∩ s ×ˢ t₂ := by
ext ⟨x, y⟩
simp only [← and_and_left, mem_inter_iff, mem_prod]
@[mfld_simps]
theorem prod_inter_prod : s₁ ×ˢ t₁ ∩ s₂ ×ˢ t₂ = (s₁ ∩ s₂) ×ˢ (t₁ ∩ t₂) := by
ext ⟨x, y⟩
simp [and_assoc, and_left_comm]
lemma compl_prod_eq_union {α β : Type*} (s : Set α) (t : Set β) :
(s ×ˢ t)ᶜ = (sᶜ ×ˢ univ) ∪ (univ ×ˢ tᶜ) := by
ext p
simp only [mem_compl_iff, mem_prod, not_and, mem_union, mem_univ, and_true, true_and]
constructor <;> intro h
· by_cases fst_in_s : p.fst ∈ s
· exact Or.inr (h fst_in_s)
· exact Or.inl fst_in_s
· intro fst_in_s
simpa only [fst_in_s, not_true, false_or] using h
@[simp]
theorem disjoint_prod : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) ↔ Disjoint s₁ s₂ ∨ Disjoint t₁ t₂ := by
simp_rw [disjoint_left, mem_prod, not_and_or, Prod.forall, and_imp, ← @forall_or_right α, ←
@forall_or_left β, ← @forall_or_right (_ ∈ s₁), ← @forall_or_left (_ ∈ t₁)]
theorem Disjoint.set_prod_left (hs : Disjoint s₁ s₂) (t₁ t₂ : Set β) :
Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) :=
disjoint_left.2 fun ⟨_a, _b⟩ ⟨ha₁, _⟩ ⟨ha₂, _⟩ => disjoint_left.1 hs ha₁ ha₂
theorem Disjoint.set_prod_right (ht : Disjoint t₁ t₂) (s₁ s₂ : Set α) :
Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) :=
disjoint_left.2 fun ⟨_a, _b⟩ ⟨_, hb₁⟩ ⟨_, hb₂⟩ => disjoint_left.1 ht hb₁ hb₂
theorem prodMap_image_prod (f : α → β) (g : γ → δ) (s : Set α) (t : Set γ) :
(Prod.map f g) '' (s ×ˢ t) = (f '' s) ×ˢ (g '' t) := by
ext
aesop
theorem insert_prod : insert a s ×ˢ t = Prod.mk a '' t ∪ s ×ˢ t := by
simp only [insert_eq, union_prod, singleton_prod]
theorem prod_insert : s ×ˢ insert b t = (fun a => (a, b)) '' s ∪ s ×ˢ t := by
simp only [insert_eq, prod_union, prod_singleton]
theorem prod_preimage_eq {f : γ → α} {g : δ → β} :
(f ⁻¹' s) ×ˢ (g ⁻¹' t) = (fun p : γ × δ => (f p.1, g p.2)) ⁻¹' s ×ˢ t :=
rfl
theorem prod_preimage_left {f : γ → α} :
(f ⁻¹' s) ×ˢ t = (fun p : γ × β => (f p.1, p.2)) ⁻¹' s ×ˢ t :=
rfl
theorem prod_preimage_right {g : δ → β} :
s ×ˢ (g ⁻¹' t) = (fun p : α × δ => (p.1, g p.2)) ⁻¹' s ×ˢ t :=
rfl
theorem preimage_prod_map_prod (f : α → β) (g : γ → δ) (s : Set β) (t : Set δ) :
Prod.map f g ⁻¹' s ×ˢ t = (f ⁻¹' s) ×ˢ (g ⁻¹' t) :=
rfl
theorem mk_preimage_prod (f : γ → α) (g : γ → β) :
(fun x => (f x, g x)) ⁻¹' s ×ˢ t = f ⁻¹' s ∩ g ⁻¹' t :=
rfl
@[simp]
theorem mk_preimage_prod_left (hb : b ∈ t) : (fun a => (a, b)) ⁻¹' s ×ˢ t = s := by
ext a
simp [hb]
@[simp]
theorem mk_preimage_prod_right (ha : a ∈ s) : Prod.mk a ⁻¹' s ×ˢ t = t := by
ext b
simp [ha]
@[simp]
theorem mk_preimage_prod_left_eq_empty (hb : b ∉ t) : (fun a => (a, b)) ⁻¹' s ×ˢ t = ∅ := by
ext a
simp [hb]
@[simp]
theorem mk_preimage_prod_right_eq_empty (ha : a ∉ s) : Prod.mk a ⁻¹' s ×ˢ t = ∅ := by
ext b
simp [ha]
theorem mk_preimage_prod_left_eq_if [DecidablePred (· ∈ t)] :
(fun a => (a, b)) ⁻¹' s ×ˢ t = if b ∈ t then s else ∅ := by split_ifs with h <;> simp [h]
theorem mk_preimage_prod_right_eq_if [DecidablePred (· ∈ s)] :
Prod.mk a ⁻¹' s ×ˢ t = if a ∈ s then t else ∅ := by split_ifs with h <;> simp [h]
theorem mk_preimage_prod_left_fn_eq_if [DecidablePred (· ∈ t)] (f : γ → α) :
(fun a => (f a, b)) ⁻¹' s ×ˢ t = if b ∈ t then f ⁻¹' s else ∅ := by
rw [← mk_preimage_prod_left_eq_if, prod_preimage_left, preimage_preimage]
theorem mk_preimage_prod_right_fn_eq_if [DecidablePred (· ∈ s)] (g : δ → β) :
(fun b => (a, g b)) ⁻¹' s ×ˢ t = if a ∈ s then g ⁻¹' t else ∅ := by
rw [← mk_preimage_prod_right_eq_if, prod_preimage_right, preimage_preimage]
@[simp]
theorem preimage_swap_prod (s : Set α) (t : Set β) : Prod.swap ⁻¹' s ×ˢ t = t ×ˢ s := by
ext ⟨x, y⟩
simp [and_comm]
@[simp]
theorem image_swap_prod (s : Set α) (t : Set β) : Prod.swap '' s ×ˢ t = t ×ˢ s := by
rw [image_swap_eq_preimage_swap, preimage_swap_prod]
theorem mapsTo_swap_prod (s : Set α) (t : Set β) : MapsTo Prod.swap (s ×ˢ t) (t ×ˢ s) :=
fun _ ⟨hx, hy⟩ ↦ ⟨hy, hx⟩
theorem prod_image_image_eq {m₁ : α → γ} {m₂ : β → δ} :
(m₁ '' s) ×ˢ (m₂ '' t) = (fun p : α × β => (m₁ p.1, m₂ p.2)) '' s ×ˢ t :=
ext <| by
simp [-exists_and_right, exists_and_right.symm, and_left_comm, and_assoc, and_comm]
theorem prod_range_range_eq {m₁ : α → γ} {m₂ : β → δ} :
range m₁ ×ˢ range m₂ = range fun p : α × β => (m₁ p.1, m₂ p.2) :=
ext <| by simp [range]
@[simp, mfld_simps]
theorem range_prodMap {m₁ : α → γ} {m₂ : β → δ} : range (Prod.map m₁ m₂) = range m₁ ×ˢ range m₂ :=
prod_range_range_eq.symm
@[deprecated (since := "2025-04-10")] alias range_prod_map := range_prodMap
theorem prod_range_univ_eq {m₁ : α → γ} :
range m₁ ×ˢ (univ : Set β) = range fun p : α × β => (m₁ p.1, p.2) :=
ext <| by simp [range]
theorem prod_univ_range_eq {m₂ : β → δ} :
(univ : Set α) ×ˢ range m₂ = range fun p : α × β => (p.1, m₂ p.2) :=
ext <| by simp [range]
theorem range_pair_subset (f : α → β) (g : α → γ) :
(range fun x => (f x, g x)) ⊆ range f ×ˢ range g := by
have : (fun x => (f x, g x)) = Prod.map f g ∘ fun x => (x, x) := funext fun x => rfl
rw [this, ← range_prodMap]
apply range_comp_subset_range
theorem Nonempty.prod : s.Nonempty → t.Nonempty → (s ×ˢ t).Nonempty := fun ⟨x, hx⟩ ⟨y, hy⟩ =>
⟨(x, y), ⟨hx, hy⟩⟩
theorem Nonempty.fst : (s ×ˢ t).Nonempty → s.Nonempty := fun ⟨x, hx⟩ => ⟨x.1, hx.1⟩
theorem Nonempty.snd : (s ×ˢ t).Nonempty → t.Nonempty := fun ⟨x, hx⟩ => ⟨x.2, hx.2⟩
@[simp]
theorem prod_nonempty_iff : (s ×ˢ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty :=
⟨fun h => ⟨h.fst, h.snd⟩, fun h => h.1.prod h.2⟩
@[simp]
theorem prod_eq_empty_iff : s ×ˢ t = ∅ ↔ s = ∅ ∨ t = ∅ := by
simp only [not_nonempty_iff_eq_empty.symm, prod_nonempty_iff, not_and_or]
theorem prod_sub_preimage_iff {W : Set γ} {f : α × β → γ} :
s ×ˢ t ⊆ f ⁻¹' W ↔ ∀ a b, a ∈ s → b ∈ t → f (a, b) ∈ W := by simp [subset_def]
theorem image_prodMk_subset_prod {f : α → β} {g : α → γ} {s : Set α} :
(fun x => (f x, g x)) '' s ⊆ (f '' s) ×ˢ (g '' s) := by
rintro _ ⟨x, hx, rfl⟩
exact mk_mem_prod (mem_image_of_mem f hx) (mem_image_of_mem g hx)
@[deprecated (since := "2025-02-22")]
alias image_prod_mk_subset_prod := image_prodMk_subset_prod
theorem image_prodMk_subset_prod_left (hb : b ∈ t) : (fun a => (a, b)) '' s ⊆ s ×ˢ t := by
rintro _ ⟨a, ha, rfl⟩
exact ⟨ha, hb⟩
@[deprecated (since := "2025-02-22")]
alias image_prod_mk_subset_prod_left := image_prodMk_subset_prod_left
theorem image_prodMk_subset_prod_right (ha : a ∈ s) : Prod.mk a '' t ⊆ s ×ˢ t := by
rintro _ ⟨b, hb, rfl⟩
exact ⟨ha, hb⟩
@[deprecated (since := "2025-02-22")]
alias image_prod_mk_subset_prod_right := image_prodMk_subset_prod_right
theorem prod_subset_preimage_fst (s : Set α) (t : Set β) : s ×ˢ t ⊆ Prod.fst ⁻¹' s :=
inter_subset_left
theorem fst_image_prod_subset (s : Set α) (t : Set β) : Prod.fst '' s ×ˢ t ⊆ s :=
image_subset_iff.2 <| prod_subset_preimage_fst s t
theorem fst_image_prod (s : Set β) {t : Set α} (ht : t.Nonempty) : Prod.fst '' s ×ˢ t = s :=
(fst_image_prod_subset _ _).antisymm fun y hy =>
let ⟨x, hx⟩ := ht
⟨(y, x), ⟨hy, hx⟩, rfl⟩
lemma mapsTo_fst_prod {s : Set α} {t : Set β} : MapsTo Prod.fst (s ×ˢ t) s :=
fun _ hx ↦ (mem_prod.1 hx).1
theorem prod_subset_preimage_snd (s : Set α) (t : Set β) : s ×ˢ t ⊆ Prod.snd ⁻¹' t :=
inter_subset_right
theorem snd_image_prod_subset (s : Set α) (t : Set β) : Prod.snd '' s ×ˢ t ⊆ t :=
image_subset_iff.2 <| prod_subset_preimage_snd s t
theorem snd_image_prod {s : Set α} (hs : s.Nonempty) (t : Set β) : Prod.snd '' s ×ˢ t = t :=
(snd_image_prod_subset _ _).antisymm fun y y_in =>
let ⟨x, x_in⟩ := hs
⟨(x, y), ⟨x_in, y_in⟩, rfl⟩
lemma mapsTo_snd_prod {s : Set α} {t : Set β} : MapsTo Prod.snd (s ×ˢ t) t :=
fun _ hx ↦ (mem_prod.1 hx).2
theorem prod_diff_prod : s ×ˢ t \ s₁ ×ˢ t₁ = s ×ˢ (t \ t₁) ∪ (s \ s₁) ×ˢ t := by
ext x
by_cases h₁ : x.1 ∈ s₁ <;> by_cases h₂ : x.2 ∈ t₁ <;> simp [*]
/-- A product set is included in a product set if and only factors are included, or a factor of the
first set is empty. -/
theorem prod_subset_prod_iff : s ×ˢ t ⊆ s₁ ×ˢ t₁ ↔ s ⊆ s₁ ∧ t ⊆ t₁ ∨ s = ∅ ∨ t = ∅ := by
rcases (s ×ˢ t).eq_empty_or_nonempty with h | h
· simp [h, prod_eq_empty_iff.1 h]
have st : s.Nonempty ∧ t.Nonempty := by rwa [prod_nonempty_iff] at h
refine ⟨fun H => Or.inl ⟨?_, ?_⟩, ?_⟩
· have := image_subset (Prod.fst : α × β → α) H
rwa [fst_image_prod _ st.2, fst_image_prod _ (h.mono H).snd] at this
· have := image_subset (Prod.snd : α × β → β) H
rwa [snd_image_prod st.1, snd_image_prod (h.mono H).fst] at this
· intro H
simp only [st.1.ne_empty, st.2.ne_empty, or_false] at H
exact prod_mono H.1 H.2
theorem prod_eq_prod_iff_of_nonempty (h : (s ×ˢ t).Nonempty) :
s ×ˢ t = s₁ ×ˢ t₁ ↔ s = s₁ ∧ t = t₁ := by
constructor
· intro heq
have h₁ : (s₁ ×ˢ t₁ : Set _).Nonempty := by rwa [← heq]
rw [prod_nonempty_iff] at h h₁
rw [← fst_image_prod s h.2, ← fst_image_prod s₁ h₁.2, heq, eq_self_iff_true, true_and, ←
snd_image_prod h.1 t, ← snd_image_prod h₁.1 t₁, heq]
· rintro ⟨rfl, rfl⟩
rfl
theorem prod_eq_prod_iff :
s ×ˢ t = s₁ ×ˢ t₁ ↔ s = s₁ ∧ t = t₁ ∨ (s = ∅ ∨ t = ∅) ∧ (s₁ = ∅ ∨ t₁ = ∅) := by
symm
rcases eq_empty_or_nonempty (s ×ˢ t) with h | h
· simp_rw [h, @eq_comm _ ∅, prod_eq_empty_iff, prod_eq_empty_iff.mp h, true_and,
or_iff_right_iff_imp]
rintro ⟨rfl, rfl⟩
exact prod_eq_empty_iff.mp h
rw [prod_eq_prod_iff_of_nonempty h]
rw [nonempty_iff_ne_empty, Ne, prod_eq_empty_iff] at h
simp_rw [h, false_and, or_false]
@[simp]
theorem prod_eq_iff_eq (ht : t.Nonempty) : s ×ˢ t = s₁ ×ˢ t ↔ s = s₁ := by
simp_rw [prod_eq_prod_iff, ht.ne_empty, and_true, or_iff_left_iff_imp, or_false]
rintro ⟨rfl, rfl⟩
rfl
theorem subset_prod {s : Set (α × β)} : s ⊆ (Prod.fst '' s) ×ˢ (Prod.snd '' s) :=
fun _ hp ↦ mem_prod.2 ⟨mem_image_of_mem _ hp, mem_image_of_mem _ hp⟩
section Mono
variable [Preorder α] {f : α → Set β} {g : α → Set γ}
theorem _root_.Monotone.set_prod (hf : Monotone f) (hg : Monotone g) :
Monotone fun x => f x ×ˢ g x :=
fun _ _ h => prod_mono (hf h) (hg h)
theorem _root_.Antitone.set_prod (hf : Antitone f) (hg : Antitone g) :
Antitone fun x => f x ×ˢ g x :=
fun _ _ h => prod_mono (hf h) (hg h)
theorem _root_.MonotoneOn.set_prod (hf : MonotoneOn f s) (hg : MonotoneOn g s) :
MonotoneOn (fun x => f x ×ˢ g x) s := fun _ ha _ hb h => prod_mono (hf ha hb h) (hg ha hb h)
theorem _root_.AntitoneOn.set_prod (hf : AntitoneOn f s) (hg : AntitoneOn g s) :
AntitoneOn (fun x => f x ×ˢ g x) s := fun _ ha _ hb h => prod_mono (hf ha hb h) (hg ha hb h)
end Mono
end Prod
/-! ### Diagonal
In this section we prove some lemmas about the diagonal set `{p | p.1 = p.2}` and the diagonal map
`fun x ↦ (x, x)`.
-/
section Diagonal
variable {α : Type*} {s t : Set α}
lemma diagonal_nonempty [Nonempty α] : (diagonal α).Nonempty :=
Nonempty.elim ‹_› fun x => ⟨_, mem_diagonal x⟩
instance decidableMemDiagonal [h : DecidableEq α] (x : α × α) : Decidable (x ∈ diagonal α) :=
h x.1 x.2
theorem preimage_coe_coe_diagonal (s : Set α) :
Prod.map (fun x : s => (x : α)) (fun x : s => (x : α)) ⁻¹' diagonal α = diagonal s := by
ext ⟨⟨x, hx⟩, ⟨y, hy⟩⟩
simp [Set.diagonal]
@[simp]
theorem range_diag : (range fun x => (x, x)) = diagonal α := by
ext ⟨x, y⟩
simp [diagonal, eq_comm]
theorem diagonal_subset_iff {s} : diagonal α ⊆ s ↔ ∀ x, (x, x) ∈ s := by
rw [← range_diag, range_subset_iff]
@[simp]
theorem prod_subset_compl_diagonal_iff_disjoint : s ×ˢ t ⊆ (diagonal α)ᶜ ↔ Disjoint s t :=
prod_subset_iff.trans disjoint_iff_forall_ne.symm
@[simp]
theorem diag_preimage_prod (s t : Set α) : (fun x => (x, x)) ⁻¹' s ×ˢ t = s ∩ t :=
rfl
theorem diag_preimage_prod_self (s : Set α) : (fun x => (x, x)) ⁻¹' s ×ˢ s = s :=
inter_self s
theorem diag_image (s : Set α) : (fun x => (x, x)) '' s = diagonal α ∩ s ×ˢ s := by
rw [← range_diag, ← image_preimage_eq_range_inter, diag_preimage_prod_self]
theorem diagonal_eq_univ_iff : diagonal α = univ ↔ Subsingleton α := by
simp only [subsingleton_iff, eq_univ_iff_forall, Prod.forall, mem_diagonal_iff]
theorem diagonal_eq_univ [Subsingleton α] : diagonal α = univ := diagonal_eq_univ_iff.2 ‹_›
end Diagonal
/-- A function is `Function.const α a` for some `a` if and only if `∀ x y, f x = f y`. -/
theorem range_const_eq_diagonal {α β : Type*} [hβ : Nonempty β] :
range (const α) = {f : α → β | ∀ x y, f x = f y} := by
refine (range_eq_iff _ _).mpr ⟨fun _ _ _ ↦ rfl, fun f hf ↦ ?_⟩
rcases isEmpty_or_nonempty α with h|⟨⟨a⟩⟩
· exact hβ.elim fun b ↦ ⟨b, Subsingleton.elim _ _⟩
· exact ⟨f a, funext fun x ↦ hf _ _⟩
end Set
section Pullback
open Set
variable {X Y Z}
/-- The fiber product $X \times_Y Z$. -/
abbrev Function.Pullback (f : X → Y) (g : Z → Y) := {p : X × Z // f p.1 = g p.2}
/-- The fiber product $X \times_Y X$. -/
abbrev Function.PullbackSelf (f : X → Y) := f.Pullback f
/-- The projection from the fiber product to the first factor. -/
def Function.Pullback.fst {f : X → Y} {g : Z → Y} (p : f.Pullback g) : X := p.val.1
/-- The projection from the fiber product to the second factor. -/
def Function.Pullback.snd {f : X → Y} {g : Z → Y} (p : f.Pullback g) : Z := p.val.2
open Function.Pullback in
lemma Function.pullback_comm_sq (f : X → Y) (g : Z → Y) :
f ∘ @fst X Y Z f g = g ∘ @snd X Y Z f g := funext fun p ↦ p.2
/-- The diagonal map $\Delta: X \to X \times_Y X$. -/
@[simps]
def toPullbackDiag (f : X → Y) (x : X) : f.Pullback f := ⟨(x, x), rfl⟩
/-- The diagonal $\Delta(X) \subseteq X \times_Y X$. -/
def Function.pullbackDiagonal (f : X → Y) : Set (f.Pullback f) := {p | p.fst = p.snd}
/-- Three functions between the three pairs of spaces $X_i, Y_i, Z_i$ that are compatible
induce a function $X_1 \times_{Y_1} Z_1 \to X_2 \times_{Y_2} Z_2$. -/
def Function.mapPullback {X₁ X₂ Y₁ Y₂ Z₁ Z₂}
{f₁ : X₁ → Y₁} {g₁ : Z₁ → Y₁} {f₂ : X₂ → Y₂} {g₂ : Z₂ → Y₂}
(mapX : X₁ → X₂) (mapY : Y₁ → Y₂) (mapZ : Z₁ → Z₂)
(commX : f₂ ∘ mapX = mapY ∘ f₁) (commZ : g₂ ∘ mapZ = mapY ∘ g₁)
(p : f₁.Pullback g₁) : f₂.Pullback g₂ :=
⟨(mapX p.fst, mapZ p.snd),
(congr_fun commX _).trans <| (congr_arg mapY p.2).trans <| congr_fun commZ.symm _⟩
open Function.Pullback in
/-- The projection $(X \times_Y Z) \times_Z (X \times_Y Z) \to X \times_Y X$. -/
def Function.PullbackSelf.map_fst {f : X → Y} {g : Z → Y} :
(@snd X Y Z f g).PullbackSelf → f.PullbackSelf :=
mapPullback fst g fst (pullback_comm_sq f g) (pullback_comm_sq f g)
open Function.Pullback in
/-- The projection $(X \times_Y Z) \times_X (X \times_Y Z) \to Z \times_Y Z$. -/
def Function.PullbackSelf.map_snd {f : X → Y} {g : Z → Y} :
(@fst X Y Z f g).PullbackSelf → g.PullbackSelf :=
mapPullback snd f snd (pullback_comm_sq f g).symm (pullback_comm_sq f g).symm
open Function.PullbackSelf Function.Pullback
theorem preimage_map_fst_pullbackDiagonal {f : X → Y} {g : Z → Y} :
@map_fst X Y Z f g ⁻¹' pullbackDiagonal f = pullbackDiagonal (@snd X Y Z f g) := by
ext ⟨⟨p₁, p₂⟩, he⟩
simp_rw [pullbackDiagonal, mem_setOf, Subtype.ext_iff, Prod.ext_iff]
exact (and_iff_left he).symm
theorem Function.Injective.preimage_pullbackDiagonal {f : X → Y} {g : Z → X} (inj : g.Injective) :
mapPullback g id g (by rfl) (by rfl) ⁻¹' pullbackDiagonal f = pullbackDiagonal (f ∘ g) :=
ext fun _ ↦ inj.eq_iff
theorem image_toPullbackDiag (f : X → Y) (s : Set X) :
toPullbackDiag f '' s = pullbackDiagonal f ∩ Subtype.val ⁻¹' s ×ˢ s := by
ext x
constructor
· rintro ⟨x, hx, rfl⟩
exact ⟨rfl, hx, hx⟩
· obtain ⟨⟨x, y⟩, h⟩ := x
rintro ⟨rfl : x = y, h2x⟩
exact mem_image_of_mem _ h2x.1
theorem range_toPullbackDiag (f : X → Y) : range (toPullbackDiag f) = pullbackDiagonal f := by
rw [← image_univ, image_toPullbackDiag, univ_prod_univ, preimage_univ, inter_univ]
theorem injective_toPullbackDiag (f : X → Y) : (toPullbackDiag f).Injective :=
fun _ _ h ↦ congr_arg Prod.fst (congr_arg Subtype.val h)
end Pullback
namespace Set
section OffDiag
variable {α : Type*} {s t : Set α} {a : α}
theorem offDiag_mono : Monotone (offDiag : Set α → Set (α × α)) := fun _ _ h _ =>
And.imp (@h _) <| And.imp_left <| @h _
@[simp]
theorem offDiag_nonempty : s.offDiag.Nonempty ↔ s.Nontrivial := by
simp [offDiag, Set.Nonempty, Set.Nontrivial]
@[simp]
theorem offDiag_eq_empty : s.offDiag = ∅ ↔ s.Subsingleton := by
rw [← not_nonempty_iff_eq_empty, ← not_nontrivial_iff, offDiag_nonempty.not]
alias ⟨_, Nontrivial.offDiag_nonempty⟩ := offDiag_nonempty
alias ⟨_, Subsingleton.offDiag_eq_empty⟩ := offDiag_nonempty
variable (s t)
theorem offDiag_subset_prod : s.offDiag ⊆ s ×ˢ s := fun _ hx => ⟨hx.1, hx.2.1⟩
theorem offDiag_eq_sep_prod : s.offDiag = { x ∈ s ×ˢ s | x.1 ≠ x.2 } :=
ext fun _ => and_assoc.symm
@[simp]
theorem offDiag_empty : (∅ : Set α).offDiag = ∅ := by simp
@[simp]
theorem offDiag_singleton (a : α) : ({a} : Set α).offDiag = ∅ := by simp
@[simp]
theorem offDiag_univ : (univ : Set α).offDiag = (diagonal α)ᶜ :=
ext <| by simp
@[simp]
theorem prod_sdiff_diagonal : s ×ˢ s \ diagonal α = s.offDiag :=
ext fun _ => and_assoc
@[simp]
theorem disjoint_diagonal_offDiag : Disjoint (diagonal α) s.offDiag :=
disjoint_left.mpr fun _ hd ho => ho.2.2 hd
theorem offDiag_inter : (s ∩ t).offDiag = s.offDiag ∩ t.offDiag :=
ext fun x => by
simp only [mem_offDiag, mem_inter_iff]
tauto
variable {s t}
theorem offDiag_union (h : Disjoint s t) :
(s ∪ t).offDiag = s.offDiag ∪ t.offDiag ∪ s ×ˢ t ∪ t ×ˢ s := by
ext x
simp only [mem_offDiag, mem_union, ne_eq, mem_prod]
constructor
· rintro ⟨h0|h0, h1|h1, h2⟩ <;> simp [h0, h1, h2]
· rintro (((⟨h0, h1, h2⟩|⟨h0, h1, h2⟩)|⟨h0, h1⟩)|⟨h0, h1⟩) <;> simp [*]
· rintro h3
rw [h3] at h0
exact Set.disjoint_left.mp h h0 h1
· rintro h3
rw [h3] at h0
exact (Set.disjoint_right.mp h h0 h1).elim
theorem offDiag_insert (ha : a ∉ s) : (insert a s).offDiag = s.offDiag ∪ {a} ×ˢ s ∪ s ×ˢ {a} := by
rw [insert_eq, union_comm, offDiag_union, offDiag_singleton, union_empty, union_right_comm]
rw [disjoint_left]
rintro b hb (rfl : b = a)
exact ha hb
end OffDiag
/-! ### Cartesian set-indexed product of sets -/
section Pi
variable {ι : Type*} {α β : ι → Type*} {s s₁ s₂ : Set ι} {t t₁ t₂ : ∀ i, Set (α i)} {i : ι}
@[simp]
theorem empty_pi (s : ∀ i, Set (α i)) : pi ∅ s = univ := by
ext
simp [pi]
theorem subsingleton_univ_pi (ht : ∀ i, (t i).Subsingleton) :
(univ.pi t).Subsingleton := fun _f hf _g hg ↦ funext fun i ↦
(ht i) (hf _ <| mem_univ _) (hg _ <| mem_univ _)
@[simp]
theorem pi_univ (s : Set ι) : (pi s fun i => (univ : Set (α i))) = univ :=
eq_univ_of_forall fun _ _ _ => mem_univ _
@[simp]
theorem pi_univ_ite (s : Set ι) [DecidablePred (· ∈ s)] (t : ∀ i, Set (α i)) :
(pi univ fun i => if i ∈ s then t i else univ) = s.pi t := by
ext; simp_rw [Set.mem_pi]; apply forall_congr'; intro i; split_ifs with h <;> simp [h]
theorem pi_mono (h : ∀ i ∈ s, t₁ i ⊆ t₂ i) : pi s t₁ ⊆ pi s t₂ := fun _ hx i hi => h i hi <| hx i hi
theorem pi_inter_distrib : (s.pi fun i => t i ∩ t₁ i) = s.pi t ∩ s.pi t₁ :=
ext fun x => by simp only [forall_and, mem_pi, mem_inter_iff]
theorem pi_congr (h : s₁ = s₂) (h' : ∀ i ∈ s₁, t₁ i = t₂ i) : s₁.pi t₁ = s₂.pi t₂ :=
h ▸ ext fun _ => forall₂_congr fun i hi => h' i hi ▸ Iff.rfl
theorem pi_eq_empty (hs : i ∈ s) (ht : t i = ∅) : s.pi t = ∅ := by
ext f
simp only [mem_empty_iff_false, not_forall, iff_false, mem_pi, Classical.not_imp]
exact ⟨i, hs, by simp [ht]⟩
theorem univ_pi_eq_empty (ht : t i = ∅) : pi univ t = ∅ :=
pi_eq_empty (mem_univ i) ht
theorem pi_nonempty_iff : (s.pi t).Nonempty ↔ ∀ i, ∃ x, i ∈ s → x ∈ t i := by
simp [Classical.skolem, Set.Nonempty]
theorem univ_pi_nonempty_iff : (pi univ t).Nonempty ↔ ∀ i, (t i).Nonempty := by
simp [Classical.skolem, Set.Nonempty]
theorem pi_eq_empty_iff : s.pi t = ∅ ↔ ∃ i, IsEmpty (α i) ∨ i ∈ s ∧ t i = ∅ := by
rw [← not_nonempty_iff_eq_empty, pi_nonempty_iff]
push_neg
refine exists_congr fun i => ?_
cases isEmpty_or_nonempty (α i) <;> simp [*, forall_and, eq_empty_iff_forall_not_mem]
@[simp]
theorem univ_pi_eq_empty_iff : pi univ t = ∅ ↔ ∃ i, t i = ∅ := by
simp [← not_nonempty_iff_eq_empty, univ_pi_nonempty_iff]
@[simp]
theorem univ_pi_empty [h : Nonempty ι] : pi univ (fun _ => ∅ : ∀ i, Set (α i)) = ∅ :=
univ_pi_eq_empty_iff.2 <| h.elim fun x => ⟨x, rfl⟩
@[simp]
theorem disjoint_univ_pi : Disjoint (pi univ t₁) (pi univ t₂) ↔ ∃ i, Disjoint (t₁ i) (t₂ i) := by
simp only [disjoint_iff_inter_eq_empty, ← pi_inter_distrib, univ_pi_eq_empty_iff]
theorem Disjoint.set_pi (hi : i ∈ s) (ht : Disjoint (t₁ i) (t₂ i)) : Disjoint (s.pi t₁) (s.pi t₂) :=
disjoint_left.2 fun _ h₁ h₂ => disjoint_left.1 ht (h₁ _ hi) (h₂ _ hi)
theorem uniqueElim_preimage [Unique ι] (t : ∀ i, Set (α i)) :
uniqueElim ⁻¹' pi univ t = t (default : ι) := by ext; simp [Unique.forall_iff]
section Nonempty
variable [∀ i, Nonempty (α i)]
theorem pi_eq_empty_iff' : s.pi t = ∅ ↔ ∃ i ∈ s, t i = ∅ := by simp [pi_eq_empty_iff]
@[simp]
theorem disjoint_pi : Disjoint (s.pi t₁) (s.pi t₂) ↔ ∃ i ∈ s, Disjoint (t₁ i) (t₂ i) := by
simp only [disjoint_iff_inter_eq_empty, ← pi_inter_distrib, pi_eq_empty_iff']
end Nonempty
@[simp]
theorem insert_pi (i : ι) (s : Set ι) (t : ∀ i, Set (α i)) :
pi (insert i s) t = eval i ⁻¹' t i ∩ pi s t := by
ext
simp [pi, or_imp, forall_and]
@[simp]
theorem singleton_pi (i : ι) (t : ∀ i, Set (α i)) : pi {i} t = eval i ⁻¹' t i := by
ext
simp [pi]
theorem singleton_pi' (i : ι) (t : ∀ i, Set (α i)) : pi {i} t = { x | x i ∈ t i } :=
singleton_pi i t
theorem univ_pi_singleton (f : ∀ i, α i) : (pi univ fun i => {f i}) = ({f} : Set (∀ i, α i)) :=
ext fun g => by simp [funext_iff]
theorem preimage_pi (s : Set ι) (t : ∀ i, Set (β i)) (f : ∀ i, α i → β i) :
(fun (g : ∀ i, α i) i => f _ (g i)) ⁻¹' s.pi t = s.pi fun i => f i ⁻¹' t i :=
rfl
theorem pi_if {p : ι → Prop} [h : DecidablePred p] (s : Set ι) (t₁ t₂ : ∀ i, Set (α i)) :
(pi s fun i => if p i then t₁ i else t₂ i) =
pi ({ i ∈ s | p i }) t₁ ∩ pi ({ i ∈ s | ¬p i }) t₂ := by
ext f
refine ⟨fun h => ?_, ?_⟩
· constructor <;>
· rintro i ⟨his, hpi⟩
simpa [*] using h i
· rintro ⟨ht₁, ht₂⟩ i his
by_cases p i <;> simp_all
theorem union_pi : (s₁ ∪ s₂).pi t = s₁.pi t ∩ s₂.pi t := by
simp [pi, or_imp, forall_and, setOf_and]
theorem union_pi_inter
(ht₁ : ∀ i ∉ s₁, t₁ i = univ) (ht₂ : ∀ i ∉ s₂, t₂ i = univ) :
(s₁ ∪ s₂).pi (fun i ↦ t₁ i ∩ t₂ i) = s₁.pi t₁ ∩ s₂.pi t₂ := by
ext x
simp only [mem_pi, mem_union, mem_inter_iff]
refine ⟨fun h ↦ ⟨fun i his₁ ↦ (h i (Or.inl his₁)).1, fun i his₂ ↦ (h i (Or.inr his₂)).2⟩,
fun h i hi ↦ ?_⟩
rcases hi with hi | hi
· by_cases hi2 : i ∈ s₂
· exact ⟨h.1 i hi, h.2 i hi2⟩
· refine ⟨h.1 i hi, ?_⟩
rw [ht₂ i hi2]
exact mem_univ _
· by_cases hi1 : i ∈ s₁
· exact ⟨h.1 i hi1, h.2 i hi⟩
· refine ⟨?_, h.2 i hi⟩
rw [ht₁ i hi1]
exact mem_univ _
@[simp]
theorem pi_inter_compl (s : Set ι) : pi s t ∩ pi sᶜ t = pi univ t := by
rw [← union_pi, union_compl_self]
theorem pi_update_of_not_mem [DecidableEq ι] (hi : i ∉ s) (f : ∀ j, α j) (a : α i)
(t : ∀ j, α j → Set (β j)) : (s.pi fun j => t j (update f i a j)) = s.pi fun j => t j (f j) :=
(pi_congr rfl) fun j hj => by
rw [update_of_ne]
exact fun h => hi (h ▸ hj)
theorem pi_update_of_mem [DecidableEq ι] (hi : i ∈ s) (f : ∀ j, α j) (a : α i)
(t : ∀ j, α j → Set (β j)) :
(s.pi fun j => t j (update f i a j)) = { x | x i ∈ t i a } ∩ (s \ {i}).pi fun j => t j (f j) :=
calc
(s.pi fun j => t j (update f i a j)) = ({i} ∪ s \ {i}).pi fun j => t j (update f i a j) := by
rw [union_diff_self, union_eq_self_of_subset_left (singleton_subset_iff.2 hi)]
_ = { x | x i ∈ t i a } ∩ (s \ {i}).pi fun j => t j (f j) := by
rw [union_pi, singleton_pi', update_self, pi_update_of_not_mem]; simp
theorem univ_pi_update [DecidableEq ι] {β : ι → Type*} (i : ι) (f : ∀ j, α j) (a : α i)
(t : ∀ j, α j → Set (β j)) :
(pi univ fun j => t j (update f i a j)) = { x | x i ∈ t i a } ∩ pi {i}ᶜ fun j => t j (f j) := by
rw [compl_eq_univ_diff, ← pi_update_of_mem (mem_univ _)]
theorem univ_pi_update_univ [DecidableEq ι] (i : ι) (s : Set (α i)) :
pi univ (update (fun j : ι => (univ : Set (α j))) i s) = eval i ⁻¹' s := by
rw [univ_pi_update i (fun j => (univ : Set (α j))) s fun j t => t, pi_univ, inter_univ, preimage]
theorem eval_image_pi_subset (hs : i ∈ s) : eval i '' s.pi t ⊆ t i :=
image_subset_iff.2 fun _ hf => hf i hs
theorem eval_image_univ_pi_subset : eval i '' pi univ t ⊆ t i :=
eval_image_pi_subset (mem_univ i)
theorem subset_eval_image_pi (ht : (s.pi t).Nonempty) (i : ι) : t i ⊆ eval i '' s.pi t := by
classical
obtain ⟨f, hf⟩ := ht
refine fun y hy => ⟨update f i y, fun j hj => ?_, update_self ..⟩
obtain rfl | hji := eq_or_ne j i <;> simp [*, hf _ hj]
theorem eval_image_pi (hs : i ∈ s) (ht : (s.pi t).Nonempty) : eval i '' s.pi t = t i :=
(eval_image_pi_subset hs).antisymm (subset_eval_image_pi ht i)
lemma eval_image_pi_of_not_mem [Decidable (s.pi t).Nonempty] (hi : i ∉ s) :
eval i '' s.pi t = if (s.pi t).Nonempty then univ else ∅ := by
classical
ext xᵢ
simp only [eval, mem_image, mem_pi, Set.Nonempty, mem_ite_empty_right, mem_univ, and_true]
constructor
· rintro ⟨x, hx, rfl⟩
exact ⟨x, hx⟩
· rintro ⟨x, hx⟩
refine ⟨Function.update x i xᵢ, ?_⟩
simpa (config := { contextual := true }) [(ne_of_mem_of_not_mem · hi)]
@[simp]
theorem eval_image_univ_pi (ht : (pi univ t).Nonempty) :
(fun f : ∀ i, α i => f i) '' pi univ t = t i :=
eval_image_pi (mem_univ i) ht
theorem piMap_mapsTo_pi {I : Set ι} {f : ∀ i, α i → β i} {s : ∀ i, Set (α i)} {t : ∀ i, Set (β i)}
(h : ∀ i ∈ I, MapsTo (f i) (s i) (t i)) :
MapsTo (Pi.map f) (I.pi s) (I.pi t) :=
fun _x hx i hi => h i hi (hx i hi)
theorem piMap_image_pi_subset {f : ∀ i, α i → β i} (t : ∀ i, Set (α i)) :
Pi.map f '' s.pi t ⊆ s.pi fun i ↦ f i '' t i :=
image_subset_iff.2 <| piMap_mapsTo_pi fun _ _ => mapsTo_image _ _
theorem piMap_image_pi {f : ∀ i, α i → β i} (hf : ∀ i ∉ s, Surjective (f i)) (t : ∀ i, Set (α i)) :
Pi.map f '' s.pi t = s.pi fun i ↦ f i '' t i := by
refine Subset.antisymm (piMap_image_pi_subset _) fun b hb => ?_
have (i : ι) : ∃ a, f i a = b i ∧ (i ∈ s → a ∈ t i) := by
if hi : i ∈ s then
exact (hb i hi).imp fun a ⟨hat, hab⟩ ↦ ⟨hab, fun _ ↦ hat⟩
else
exact (hf i hi (b i)).imp fun a ha ↦ ⟨ha, (absurd · hi)⟩
choose a hab hat using this
exact ⟨a, hat, funext hab⟩
theorem piMap_image_univ_pi (f : ∀ i, α i → β i) (t : ∀ i, Set (α i)) :
Pi.map f '' univ.pi t = univ.pi fun i ↦ f i '' t i :=
piMap_image_pi (by simp) t
@[simp]
theorem range_piMap (f : ∀ i, α i → β i) : range (Pi.map f) = pi univ fun i ↦ range (f i) := by
simp only [← image_univ, ← piMap_image_univ_pi, pi_univ]
theorem pi_subset_pi_iff : pi s t₁ ⊆ pi s t₂ ↔ (∀ i ∈ s, t₁ i ⊆ t₂ i) ∨ pi s t₁ = ∅ := by
refine
⟨fun h => or_iff_not_imp_right.2 ?_, fun h => h.elim pi_mono fun h' => h'.symm ▸ empty_subset _⟩
rw [← Ne, ← nonempty_iff_ne_empty]
intro hne i hi
simpa only [eval_image_pi hi hne, eval_image_pi hi (hne.mono h)] using
image_subset (fun f : ∀ i, α i => f i) h
theorem univ_pi_subset_univ_pi_iff :
pi univ t₁ ⊆ pi univ t₂ ↔ (∀ i, t₁ i ⊆ t₂ i) ∨ ∃ i, t₁ i = ∅ := by simp [pi_subset_pi_iff]
theorem eval_preimage [DecidableEq ι] {s : Set (α i)} :
eval i ⁻¹' s = pi univ (update (fun _ => univ) i s) := by
ext x
simp [@forall_update_iff _ (fun i => Set (α i)) _ _ _ _ fun i' y => x i' ∈ y]
theorem eval_preimage' [DecidableEq ι] {s : Set (α i)} :
eval i ⁻¹' s = pi {i} (update (fun _ => univ) i s) := by
ext
simp
theorem update_preimage_pi [DecidableEq ι] {f : ∀ i, α i} (hi : i ∈ s)
(hf : ∀ j ∈ s, j ≠ i → f j ∈ t j) : update f i ⁻¹' s.pi t = t i := by
ext x
refine ⟨fun h => ?_, fun hx j hj => ?_⟩
· convert h i hi
simp
· obtain rfl | h := eq_or_ne j i
· simpa
· rw [update_of_ne h]
exact hf j hj h
theorem update_image [DecidableEq ι] (x : (i : ι) → β i) (i : ι) (s : Set (β i)) :
update x i '' s = Set.univ.pi (update (fun j ↦ {x j}) i s) := by
ext y
simp only [mem_image, update_eq_iff, ne_eq, and_left_comm (a := _ ∈ s), exists_eq_left, mem_pi,
mem_univ, true_implies]
| rw [forall_update_iff (p := fun x s => y x ∈ s)]
simp [eq_comm]
theorem update_preimage_univ_pi [DecidableEq ι] {f : ∀ i, α i} (hf : ∀ j ≠ i, f j ∈ t j) :
update f i ⁻¹' pi univ t = t i :=
update_preimage_pi (mem_univ i) fun j _ => hf j
theorem subset_pi_eval_image (s : Set ι) (u : Set (∀ i, α i)) : u ⊆ pi s fun i => eval i '' u :=
| Mathlib/Data/Set/Prod.lean | 879 | 886 |
/-
Copyright (c) 2019 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston, Jireh Loreaux
-/
import Mathlib.Algebra.GroupWithZero.Hom
import Mathlib.Algebra.Ring.Defs
import Mathlib.Algebra.Ring.Basic
/-!
# Homomorphisms of semirings and rings
This file defines bundled homomorphisms of (non-unital) semirings and rings. As with monoid and
groups, we use the same structure `RingHom a β`, a.k.a. `α →+* β`, for both types of homomorphisms.
## Main definitions
* `NonUnitalRingHom`: Non-unital (semi)ring homomorphisms. Additive monoid homomorphism which
preserve multiplication.
* `RingHom`: (Semi)ring homomorphisms. Monoid homomorphisms which are also additive monoid
homomorphism.
## Notations
* `→ₙ+*`: Non-unital (semi)ring homs
* `→+*`: (Semi)ring homs
## Implementation notes
* There's a coercion from bundled homs to fun, and the canonical notation is to
use the bundled hom as a function via this coercion.
* There is no `SemiringHom` -- the idea is that `RingHom` is used.
The constructor for a `RingHom` between semirings needs a proof of `map_zero`,
`map_one` and `map_add` as well as `map_mul`; a separate constructor
`RingHom.mk'` will construct ring homs between rings from monoid homs given
only a proof that addition is preserved.
## Tags
`RingHom`, `SemiringHom`
-/
assert_not_exists Function.Injective.mulZeroClass semigroupDvd Units.map Set.range
open Function
variable {F α β γ : Type*}
/-- Bundled non-unital semiring homomorphisms `α →ₙ+* β`; use this for bundled non-unital ring
homomorphisms too.
When possible, instead of parametrizing results over `(f : α →ₙ+* β)`,
you should parametrize over `(F : Type*) [NonUnitalRingHomClass F α β] (f : F)`.
When you extend this structure, make sure to extend `NonUnitalRingHomClass`. -/
structure NonUnitalRingHom (α β : Type*) [NonUnitalNonAssocSemiring α]
[NonUnitalNonAssocSemiring β] extends α →ₙ* β, α →+ β
/-- `α →ₙ+* β` denotes the type of non-unital ring homomorphisms from `α` to `β`. -/
infixr:25 " →ₙ+* " => NonUnitalRingHom
/-- Reinterpret a non-unital ring homomorphism `f : α →ₙ+* β` as a semigroup
homomorphism `α →ₙ* β`. The `simp`-normal form is `(f : α →ₙ* β)`. -/
add_decl_doc NonUnitalRingHom.toMulHom
/-- Reinterpret a non-unital ring homomorphism `f : α →ₙ+* β` as an additive
monoid homomorphism `α →+ β`. The `simp`-normal form is `(f : α →+ β)`. -/
add_decl_doc NonUnitalRingHom.toAddMonoidHom
section NonUnitalRingHomClass
/-- `NonUnitalRingHomClass F α β` states that `F` is a type of non-unital (semi)ring
homomorphisms. You should extend this class when you extend `NonUnitalRingHom`. -/
class NonUnitalRingHomClass (F : Type*) (α β : outParam Type*) [NonUnitalNonAssocSemiring α]
[NonUnitalNonAssocSemiring β] [FunLike F α β] : Prop
extends MulHomClass F α β, AddMonoidHomClass F α β
variable [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β] [FunLike F α β]
variable [NonUnitalRingHomClass F α β]
/-- Turn an element of a type `F` satisfying `NonUnitalRingHomClass F α β` into an actual
`NonUnitalRingHom`. This is declared as the default coercion from `F` to `α →ₙ+* β`. -/
@[coe]
def NonUnitalRingHomClass.toNonUnitalRingHom (f : F) : α →ₙ+* β :=
{ (f : α →ₙ* β), (f : α →+ β) with }
/-- Any type satisfying `NonUnitalRingHomClass` can be cast into `NonUnitalRingHom` via
`NonUnitalRingHomClass.toNonUnitalRingHom`. -/
instance : CoeTC F (α →ₙ+* β) :=
⟨NonUnitalRingHomClass.toNonUnitalRingHom⟩
end NonUnitalRingHomClass
namespace NonUnitalRingHom
section coe
variable [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β]
instance : FunLike (α →ₙ+* β) α β where
coe f := f.toFun
coe_injective' f g h := by
cases f
cases g
congr
apply DFunLike.coe_injective'
exact h
instance : NonUnitalRingHomClass (α →ₙ+* β) α β where
map_add := NonUnitalRingHom.map_add'
map_zero := NonUnitalRingHom.map_zero'
map_mul f := f.map_mul'
initialize_simps_projections NonUnitalRingHom (toFun → apply)
@[simp]
theorem coe_toMulHom (f : α →ₙ+* β) : ⇑f.toMulHom = f :=
rfl
@[simp]
theorem coe_mulHom_mk (f : α → β) (h₁ h₂ h₃) :
((⟨⟨f, h₁⟩, h₂, h₃⟩ : α →ₙ+* β) : α →ₙ* β) = ⟨f, h₁⟩ :=
rfl
theorem coe_toAddMonoidHom (f : α →ₙ+* β) : ⇑f.toAddMonoidHom = f := rfl
@[simp]
theorem coe_addMonoidHom_mk (f : α → β) (h₁ h₂ h₃) :
((⟨⟨f, h₁⟩, h₂, h₃⟩ : α →ₙ+* β) : α →+ β) = ⟨⟨f, h₂⟩, h₃⟩ :=
rfl
/-- Copy of a `RingHom` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (f : α →ₙ+* β) (f' : α → β) (h : f' = f) : α →ₙ+* β :=
{ f.toMulHom.copy f' h, f.toAddMonoidHom.copy f' h with }
@[simp]
theorem coe_copy (f : α →ₙ+* β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
theorem copy_eq (f : α →ₙ+* β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
end coe
section
variable [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β]
@[ext]
theorem ext ⦃f g : α →ₙ+* β⦄ : (∀ x, f x = g x) → f = g :=
DFunLike.ext _ _
@[simp]
theorem mk_coe (f : α →ₙ+* β) (h₁ h₂ h₃) : NonUnitalRingHom.mk (MulHom.mk f h₁) h₂ h₃ = f :=
ext fun _ => rfl
theorem coe_addMonoidHom_injective : Injective fun f : α →ₙ+* β => (f : α →+ β) :=
Injective.of_comp (f := DFunLike.coe) DFunLike.coe_injective
theorem coe_mulHom_injective : Injective fun f : α →ₙ+* β => (f : α →ₙ* β) :=
Injective.of_comp (f := DFunLike.coe) DFunLike.coe_injective
end
variable [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β]
/-- The identity non-unital ring homomorphism from a non-unital semiring to itself. -/
protected def id (α : Type*) [NonUnitalNonAssocSemiring α] : α →ₙ+* α where
toFun := id
map_mul' _ _ := rfl
map_zero' := rfl
map_add' _ _ := rfl
instance : Zero (α →ₙ+* β) :=
⟨{ toFun := 0, map_mul' := fun _ _ => (mul_zero (0 : β)).symm, map_zero' := rfl,
map_add' := fun _ _ => (add_zero (0 : β)).symm }⟩
instance : Inhabited (α →ₙ+* β) :=
⟨0⟩
@[simp]
theorem coe_zero : ⇑(0 : α →ₙ+* β) = 0 :=
rfl
@[simp]
theorem zero_apply (x : α) : (0 : α →ₙ+* β) x = 0 :=
rfl
@[simp]
theorem id_apply (x : α) : NonUnitalRingHom.id α x = x :=
rfl
@[simp]
theorem coe_addMonoidHom_id : (NonUnitalRingHom.id α : α →+ α) = AddMonoidHom.id α :=
rfl
@[simp]
theorem coe_mulHom_id : (NonUnitalRingHom.id α : α →ₙ* α) = MulHom.id α :=
rfl
variable [NonUnitalNonAssocSemiring γ]
/-- Composition of non-unital ring homomorphisms is a non-unital ring homomorphism. -/
def comp (g : β →ₙ+* γ) (f : α →ₙ+* β) : α →ₙ+* γ :=
{ g.toMulHom.comp f.toMulHom, g.toAddMonoidHom.comp f.toAddMonoidHom with }
/-- Composition of non-unital ring homomorphisms is associative. -/
theorem comp_assoc {δ} {_ : NonUnitalNonAssocSemiring δ} (f : α →ₙ+* β) (g : β →ₙ+* γ)
(h : γ →ₙ+* δ) : (h.comp g).comp f = h.comp (g.comp f) :=
rfl
@[simp]
theorem coe_comp (g : β →ₙ+* γ) (f : α →ₙ+* β) : ⇑(g.comp f) = g ∘ f :=
rfl
@[simp]
theorem comp_apply (g : β →ₙ+* γ) (f : α →ₙ+* β) (x : α) : g.comp f x = g (f x) :=
rfl
@[simp]
theorem coe_comp_addMonoidHom (g : β →ₙ+* γ) (f : α →ₙ+* β) :
AddMonoidHom.mk ⟨g ∘ f, (g.comp f).map_zero'⟩ (g.comp f).map_add' = (g : β →+ γ).comp f :=
rfl
@[simp]
theorem coe_comp_mulHom (g : β →ₙ+* γ) (f : α →ₙ+* β) :
MulHom.mk (g ∘ f) (g.comp f).map_mul' = (g : β →ₙ* γ).comp f :=
rfl
@[simp]
theorem comp_zero (g : β →ₙ+* γ) : g.comp (0 : α →ₙ+* β) = 0 := by
ext
simp
@[simp]
theorem zero_comp (f : α →ₙ+* β) : (0 : β →ₙ+* γ).comp f = 0 := by
ext
rfl
@[simp]
theorem comp_id (f : α →ₙ+* β) : f.comp (NonUnitalRingHom.id α) = f :=
ext fun _ => rfl
@[simp]
theorem id_comp (f : α →ₙ+* β) : (NonUnitalRingHom.id β).comp f = f :=
ext fun _ => rfl
instance : MonoidWithZero (α →ₙ+* α) where
one := NonUnitalRingHom.id α
mul := comp
mul_one := comp_id
one_mul := id_comp
mul_assoc _ _ _ := comp_assoc _ _ _
zero := 0
mul_zero := comp_zero
zero_mul := zero_comp
theorem one_def : (1 : α →ₙ+* α) = NonUnitalRingHom.id α :=
rfl
@[simp]
theorem coe_one : ⇑(1 : α →ₙ+* α) = id :=
rfl
theorem mul_def (f g : α →ₙ+* α) : f * g = f.comp g :=
rfl
@[simp]
theorem coe_mul (f g : α →ₙ+* α) : ⇑(f * g) = f ∘ g :=
rfl
@[simp]
theorem cancel_right {g₁ g₂ : β →ₙ+* γ} {f : α →ₙ+* β} (hf : Surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => ext <| hf.forall.2 (NonUnitalRingHom.ext_iff.1 h), fun h => h ▸ rfl⟩
@[simp]
theorem cancel_left {g : β →ₙ+* γ} {f₁ f₂ : α →ₙ+* β} (hg : Injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => ext fun x => hg <| by rw [← comp_apply, h, comp_apply], fun h => h ▸ rfl⟩
end NonUnitalRingHom
/-- Bundled semiring homomorphisms; use this for bundled ring homomorphisms too.
This extends from both `MonoidHom` and `MonoidWithZeroHom` in order to put the fields in a
sensible order, even though `MonoidWithZeroHom` already extends `MonoidHom`. -/
structure RingHom (α : Type*) (β : Type*) [NonAssocSemiring α] [NonAssocSemiring β] extends
α →* β, α →+ β, α →ₙ+* β, α →*₀ β
/-- `α →+* β` denotes the type of ring homomorphisms from `α` to `β`. -/
infixr:25 " →+* " => RingHom
/-- Reinterpret a ring homomorphism `f : α →+* β` as a monoid with zero homomorphism `α →*₀ β`.
The `simp`-normal form is `(f : α →*₀ β)`. -/
add_decl_doc RingHom.toMonoidWithZeroHom
/-- Reinterpret a ring homomorphism `f : α →+* β` as a monoid homomorphism `α →* β`.
The `simp`-normal form is `(f : α →* β)`. -/
add_decl_doc RingHom.toMonoidHom
/-- Reinterpret a ring homomorphism `f : α →+* β` as an additive monoid homomorphism `α →+ β`.
The `simp`-normal form is `(f : α →+ β)`. -/
add_decl_doc RingHom.toAddMonoidHom
/-- Reinterpret a ring homomorphism `f : α →+* β` as a non-unital ring homomorphism `α →ₙ+* β`. The
`simp`-normal form is `(f : α →ₙ+* β)`. -/
add_decl_doc RingHom.toNonUnitalRingHom
section RingHomClass
/-- `RingHomClass F α β` states that `F` is a type of (semi)ring homomorphisms.
You should extend this class when you extend `RingHom`.
This extends from both `MonoidHomClass` and `MonoidWithZeroHomClass` in
order to put the fields in a sensible order, even though
`MonoidWithZeroHomClass` already extends `MonoidHomClass`. -/
class RingHomClass (F : Type*) (α β : outParam Type*)
[NonAssocSemiring α] [NonAssocSemiring β] [FunLike F α β] : Prop
extends MonoidHomClass F α β, AddMonoidHomClass F α β, MonoidWithZeroHomClass F α β
variable [FunLike F α β]
-- See note [implicit instance arguments].
variable {_ : NonAssocSemiring α} {_ : NonAssocSemiring β} [RingHomClass F α β]
/-- Turn an element of a type `F` satisfying `RingHomClass F α β` into an actual
`RingHom`. This is declared as the default coercion from `F` to `α →+* β`. -/
@[coe]
def RingHomClass.toRingHom (f : F) : α →+* β :=
{ (f : α →* β), (f : α →+ β) with }
/-- Any type satisfying `RingHomClass` can be cast into `RingHom` via `RingHomClass.toRingHom`. -/
instance : CoeTC F (α →+* β) :=
⟨RingHomClass.toRingHom⟩
instance (priority := 100) RingHomClass.toNonUnitalRingHomClass : NonUnitalRingHomClass F α β :=
{ ‹RingHomClass F α β› with }
end RingHomClass
namespace RingHom
section coe
/-!
Throughout this section, some `Semiring` arguments are specified with `{}` instead of `[]`.
See note [implicit instance arguments].
-/
variable {_ : NonAssocSemiring α} {_ : NonAssocSemiring β}
instance instFunLike : FunLike (α →+* β) α β where
coe f := f.toFun
coe_injective' f g h := by
cases f
cases g
congr
apply DFunLike.coe_injective'
exact h
instance instRingHomClass : RingHomClass (α →+* β) α β where
map_add := RingHom.map_add'
map_zero := RingHom.map_zero'
map_mul f := f.map_mul'
map_one f := f.map_one'
initialize_simps_projections RingHom (toFun → apply)
theorem toFun_eq_coe (f : α →+* β) : f.toFun = f :=
rfl
@[simp]
theorem coe_mk (f : α →* β) (h₁ h₂) : ((⟨f, h₁, h₂⟩ : α →+* β) : α → β) = f :=
rfl
@[simp]
theorem coe_coe {F : Type*} [FunLike F α β] [RingHomClass F α β] (f : F) :
((f : α →+* β) : α → β) = f :=
rfl
attribute [coe] RingHom.toMonoidHom
instance coeToMonoidHom : Coe (α →+* β) (α →* β) :=
⟨RingHom.toMonoidHom⟩
@[simp]
theorem toMonoidHom_eq_coe (f : α →+* β) : f.toMonoidHom = f :=
rfl
theorem toMonoidWithZeroHom_eq_coe (f : α →+* β) : (f.toMonoidWithZeroHom : α → β) = f := by
rfl
@[simp]
theorem coe_monoidHom_mk (f : α →* β) (h₁ h₂) : ((⟨f, h₁, h₂⟩ : α →+* β) : α →* β) = f :=
rfl
@[simp]
theorem toAddMonoidHom_eq_coe (f : α →+* β) : f.toAddMonoidHom = f :=
rfl
@[simp]
theorem coe_addMonoidHom_mk (f : α → β) (h₁ h₂ h₃ h₄) :
((⟨⟨⟨f, h₁⟩, h₂⟩, h₃, h₄⟩ : α →+* β) : α →+ β) = ⟨⟨f, h₃⟩, h₄⟩ :=
rfl
/-- Copy of a `RingHom` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
def copy (f : α →+* β) (f' : α → β) (h : f' = f) : α →+* β :=
{ f.toMonoidWithZeroHom.copy f' h, f.toAddMonoidHom.copy f' h with }
@[simp]
theorem coe_copy (f : α →+* β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
theorem copy_eq (f : α →+* β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
end coe
section
variable {_ : NonAssocSemiring α} {_ : NonAssocSemiring β} (f : α →+* β)
protected theorem congr_fun {f g : α →+* β} (h : f = g) (x : α) : f x = g x :=
DFunLike.congr_fun h x
protected theorem congr_arg (f : α →+* β) {x y : α} (h : x = y) : f x = f y :=
DFunLike.congr_arg f h
theorem coe_inj ⦃f g : α →+* β⦄ (h : (f : α → β) = g) : f = g :=
DFunLike.coe_injective h
@[ext]
theorem ext ⦃f g : α →+* β⦄ : (∀ x, f x = g x) → f = g :=
DFunLike.ext _ _
@[simp]
theorem mk_coe (f : α →+* β) (h₁ h₂ h₃ h₄) : RingHom.mk ⟨⟨f, h₁⟩, h₂⟩ h₃ h₄ = f :=
ext fun _ => rfl
theorem coe_addMonoidHom_injective : Injective (fun f : α →+* β => (f : α →+ β)) := fun _ _ h =>
ext <| DFunLike.congr_fun (F := α →+ β) h
theorem coe_monoidHom_injective : Injective (fun f : α →+* β => (f : α →* β)) :=
Injective.of_comp (f := DFunLike.coe) DFunLike.coe_injective
/-- Ring homomorphisms map zero to zero. -/
protected theorem map_zero (f : α →+* β) : f 0 = 0 :=
map_zero f
/-- Ring homomorphisms map one to one. -/
protected theorem map_one (f : α →+* β) : f 1 = 1 :=
map_one f
/-- Ring homomorphisms preserve addition. -/
protected theorem map_add (f : α →+* β) : ∀ a b, f (a + b) = f a + f b :=
map_add f
/-- Ring homomorphisms preserve multiplication. -/
protected theorem map_mul (f : α →+* β) : ∀ a b, f (a * b) = f a * f b :=
map_mul f
/-- `f : α →+* β` has a trivial codomain iff `f 1 = 0`. -/
| theorem codomain_trivial_iff_map_one_eq_zero : (0 : β) = 1 ↔ f 1 = 0 := by rw [map_one, eq_comm]
| Mathlib/Algebra/Ring/Hom/Defs.lean | 467 | 468 |
/-
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, Sébastien Gouëzel
-/
import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic
import Mathlib.MeasureTheory.Integral.IntervalIntegral.FundThmCalculus
import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts
deprecated_module (since := "2025-04-13")
| Mathlib/MeasureTheory/Integral/IntervalIntegral.lean | 537 | 540 | |
/-
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.Algebra.Polynomial.Bivariate
import Mathlib.AlgebraicGeometry.EllipticCurve.Weierstrass
import Mathlib.AlgebraicGeometry.EllipticCurve.VariableChange
/-!
# Affine coordinates for Weierstrass curves
This file defines the type of points on a Weierstrass curve as an inductive, consisting of the point
at infinity and affine points satisfying a Weierstrass equation with a nonsingular condition. This
file also defines the negation and addition operations of the group law for this type, and proves
that they respect the Weierstrass equation and the nonsingular condition. The fact that they form an
abelian group is proven in `Mathlib/AlgebraicGeometry/EllipticCurve/Group.lean`.
## Mathematical background
Let `W` be a Weierstrass curve over a field `F` with coefficients `aᵢ`. An *affine point*
on `W` is a tuple `(x, y)` of elements in `R` satisfying the *Weierstrass equation* `W(X, Y) = 0` in
*affine coordinates*, where `W(X, Y) := Y² + a₁XY + a₃Y - (X³ + a₂X² + a₄X + a₆)`. It is
*nonsingular* if its partial derivatives `W_X(x, y)` and `W_Y(x, y)` do not vanish simultaneously.
The nonsingular affine points on `W` can be given negation and addition operations defined by a
secant-and-tangent process.
* Given a nonsingular affine point `P`, its *negation* `-P` is defined to be the unique third
nonsingular point of intersection between `W` and the vertical line through `P`.
Explicitly, if `P` is `(x, y)`, then `-P` is `(x, -y - a₁x - a₃)`.
* Given two nonsingular affine points `P` and `Q`, their *addition* `P + Q` is defined to be the
negation of the unique third nonsingular point of intersection between `W` and the line `L`
through `P` and `Q`. Explicitly, let `P` be `(x₁, y₁)` and let `Q` be `(x₂, y₂)`.
* If `x₁ = x₂` and `y₁ = -y₂ - a₁x₂ - a₃`, then `L` is vertical.
* If `x₁ = x₂` and `y₁ ≠ -y₂ - a₁x₂ - a₃`, then `L` is the tangent of `W` at `P = Q`, and has
slope `ℓ := (3x₁² + 2a₂x₁ + a₄ - a₁y₁) / (2y₁ + a₁x₁ + a₃)`.
* Otherwise `x₁ ≠ x₂`, then `L` is the secant of `W` through `P` and `Q`, and has slope
`ℓ := (y₁ - y₂) / (x₁ - x₂)`.
In the last two cases, the `X`-coordinate of `P + Q` is then the unique third solution of the
equation obtained by substituting the line `Y = ℓ(X - x₁) + y₁` into the Weierstrass equation,
and can be written down explicitly as `x := ℓ² + a₁ℓ - a₂ - x₁ - x₂` by inspecting the
coefficients of `X²`. The `Y`-coordinate of `P + Q`, after applying the final negation that maps
`Y` to `-Y - a₁X - a₃`, is precisely `y := -(ℓ(x - x₁) + y₁) - a₁x - a₃`.
The type of nonsingular points `W⟮F⟯` in affine coordinates is an inductive, consisting of the
unique point at infinity `𝓞` and nonsingular affine points `(x, y)`. Then `W⟮F⟯` can be endowed with
a group law, with `𝓞` as the identity nonsingular point, which is uniquely determined by these
formulae.
## Main definitions
* `WeierstrassCurve.Affine.Equation`: the Weierstrass equation of an affine Weierstrass curve.
* `WeierstrassCurve.Affine.Nonsingular`: the nonsingular condition on an affine Weierstrass curve.
* `WeierstrassCurve.Affine.Point`: a nonsingular rational point on an affine Weierstrass curve.
* `WeierstrassCurve.Affine.Point.neg`: the negation operation on an affine Weierstrass curve.
* `WeierstrassCurve.Affine.Point.add`: the addition operation on an affine Weierstrass curve.
## Main statements
* `WeierstrassCurve.Affine.equation_neg`: negation preserves the Weierstrass equation.
* `WeierstrassCurve.Affine.equation_add`: addition preserves the Weierstrass equation.
* `WeierstrassCurve.Affine.nonsingular_neg`: negation preserves the nonsingular condition.
* `WeierstrassCurve.Affine.nonsingular_add`: addition preserves the nonsingular condition.
* `WeierstrassCurve.Affine.nonsingular_of_Δ_ne_zero`: an affine Weierstrass curve is nonsingular at
every point if its discriminant is non-zero.
* `WeierstrassCurve.Affine.nonsingular`: an affine elliptic curve is nonsingular at every point.
## Notations
* `W⟮K⟯`: the group of nonsingular rational points on `W` base changed to `K`.
## References
[J Silverman, *The Arithmetic of Elliptic Curves*][silverman2009]
## Tags
elliptic curve, rational point, affine coordinates
-/
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 "derivative_simp" : tactic =>
`(tactic| simp only [derivative_C, derivative_X, derivative_X_pow, derivative_neg, derivative_add,
derivative_sub, derivative_mul, derivative_sq])
local macro "eval_simp" : tactic =>
`(tactic| simp only [eval_C, eval_X, eval_neg, eval_add, eval_sub, eval_mul, eval_pow, evalEval])
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, map_C, map_X, Polynomial.map_neg, Polynomial.map_add, Polynomial.map_sub,
Polynomial.map_mul, Polynomial.map_pow, Polynomial.map_div, coe_mapRingHom,
WeierstrassCurve.map])
universe r s u v w
/-! ## Weierstrass curves -/
namespace WeierstrassCurve
variable {R : Type r} {S : Type s} {A F : Type u} {B K : Type v} {L : Type w}
variable (R) in
/-- An abbreviation for a Weierstrass curve in affine coordinates. -/
abbrev Affine : Type r :=
WeierstrassCurve R
/-- The conversion from a Weierstrass curve to affine coordinates. -/
abbrev toAffine (W : WeierstrassCurve R) : Affine R :=
W
namespace Affine
variable [CommRing R] [CommRing S] [CommRing A] [CommRing B] [Field F] [Field K] [Field L]
{W' : Affine R} {W : Affine F}
section Equation
/-! ### Weierstrass equations -/
variable (W') in
/-- The polynomial `W(X, Y) := Y² + a₁XY + a₃Y - (X³ + a₂X² + a₄X + a₆)` associated to a Weierstrass
curve `W` over a ring `R` in affine coordinates.
For ease of polynomial manipulation, this is represented as a term of type `R[X][X]`, where the
inner variable represents `X` and the outer variable represents `Y`. For clarity, the alternative
notations `Y` and `R[X][Y]` are provided in the `Polynomial.Bivariate` scope to represent the outer
variable and the bivariate polynomial ring `R[X][X]` respectively. -/
noncomputable def polynomial : R[X][Y] :=
Y ^ 2 + C (C W'.a₁ * X + C W'.a₃) * Y - C (X ^ 3 + C W'.a₂ * X ^ 2 + C W'.a₄ * X + C W'.a₆)
lemma polynomial_eq : W'.polynomial = Cubic.toPoly
⟨0, 1, Cubic.toPoly ⟨0, 0, W'.a₁, W'.a₃⟩, Cubic.toPoly ⟨-1, -W'.a₂, -W'.a₄, -W'.a₆⟩⟩ := by
simp only [polynomial, Cubic.toPoly]
C_simp
ring1
lemma polynomial_ne_zero [Nontrivial R] : W'.polynomial ≠ 0 := by
rw [polynomial_eq]
exact Cubic.ne_zero_of_b_ne_zero one_ne_zero
@[simp]
lemma degree_polynomial [Nontrivial R] : W'.polynomial.degree = 2 := by
rw [polynomial_eq]
exact Cubic.degree_of_b_ne_zero' one_ne_zero
@[simp]
lemma natDegree_polynomial [Nontrivial R] : W'.polynomial.natDegree = 2 := by
rw [polynomial_eq]
exact Cubic.natDegree_of_b_ne_zero' one_ne_zero
lemma monic_polynomial : W'.polynomial.Monic := by
nontriviality R
simpa only [polynomial_eq] using Cubic.monic_of_b_eq_one'
lemma irreducible_polynomial [IsDomain R] : Irreducible W'.polynomial := by
by_contra h
rcases (monic_polynomial.not_irreducible_iff_exists_add_mul_eq_coeff natDegree_polynomial).mp h
with ⟨f, g, h0, h1⟩
simp only [polynomial_eq, Cubic.coeff_eq_c, Cubic.coeff_eq_d] at h0 h1
apply_fun degree at h0 h1
rw [Cubic.degree_of_a_ne_zero' <| neg_ne_zero.mpr <| one_ne_zero' R, degree_mul] at h0
apply (h1.symm.le.trans Cubic.degree_of_b_eq_zero').not_lt
rcases Nat.WithBot.add_eq_three_iff.mp h0.symm with h | h | h | h
iterate 2 rw [degree_add_eq_right_of_degree_lt] <;> simp only [h] <;> decide
iterate 2 rw [degree_add_eq_left_of_degree_lt] <;> simp only [h] <;> decide
lemma evalEval_polynomial (x y : R) : W'.polynomial.evalEval x y =
y ^ 2 + W'.a₁ * x * y + W'.a₃ * y - (x ^ 3 + W'.a₂ * x ^ 2 + W'.a₄ * x + W'.a₆) := by
simp only [polynomial]
eval_simp
rw [add_mul, ← add_assoc]
@[simp]
lemma evalEval_polynomial_zero : W'.polynomial.evalEval 0 0 = -W'.a₆ := by
simp only [evalEval_polynomial, zero_add, zero_sub, mul_zero, zero_pow <| Nat.succ_ne_zero _]
variable (W') in
/-- The proposition that an affine point `(x, y)` lies in a Weierstrass curve `W`.
In other words, it satisfies the Weierstrass equation `W(X, Y) = 0`. -/
def Equation (x y : R) : Prop :=
W'.polynomial.evalEval x y = 0
lemma equation_iff' (x y : R) : W'.Equation x y ↔
y ^ 2 + W'.a₁ * x * y + W'.a₃ * y - (x ^ 3 + W'.a₂ * x ^ 2 + W'.a₄ * x + W'.a₆) = 0 := by
rw [Equation, evalEval_polynomial]
lemma equation_iff (x y : R) : W'.Equation x y ↔
y ^ 2 + W'.a₁ * x * y + W'.a₃ * y = x ^ 3 + W'.a₂ * x ^ 2 + W'.a₄ * x + W'.a₆ := by
rw [equation_iff', sub_eq_zero]
@[simp]
lemma equation_zero : W'.Equation 0 0 ↔ W'.a₆ = 0 := by
rw [Equation, evalEval_polynomial_zero, neg_eq_zero]
lemma equation_iff_variableChange (x y : R) :
W'.Equation x y ↔ (VariableChange.mk 1 x 0 y • W').toAffine.Equation 0 0 := by
rw [equation_iff', ← neg_eq_zero, equation_zero, variableChange_a₆, inv_one, Units.val_one]
congr! 1
ring1
end Equation
section Nonsingular
/-! ### Nonsingular Weierstrass equations -/
variable (W') in
/-- The partial derivative `W_X(X, Y)` with respect to `X` of the polynomial `W(X, Y)` associated to
a Weierstrass curve `W` in affine coordinates. -/
-- TODO: define this in terms of `Polynomial.derivative`.
noncomputable def polynomialX : R[X][Y] :=
C (C W'.a₁) * Y - C (C 3 * X ^ 2 + C (2 * W'.a₂) * X + C W'.a₄)
lemma evalEval_polynomialX (x y : R) :
W'.polynomialX.evalEval x y = W'.a₁ * y - (3 * x ^ 2 + 2 * W'.a₂ * x + W'.a₄) := by
simp only [polynomialX]
eval_simp
@[simp]
lemma evalEval_polynomialX_zero : W'.polynomialX.evalEval 0 0 = -W'.a₄ := by
simp only [evalEval_polynomialX, zero_add, zero_sub, mul_zero, zero_pow <| Nat.succ_ne_zero _]
variable (W') in
/-- The partial derivative `W_Y(X, Y)` with respect to `Y` of the polynomial `W(X, Y)` associated to
a Weierstrass curve `W` in affine coordinates. -/
-- TODO: define this in terms of `Polynomial.derivative`.
noncomputable def polynomialY : R[X][Y] :=
C (C 2) * Y + C (C W'.a₁ * X + C W'.a₃)
lemma evalEval_polynomialY (x y : R) : W'.polynomialY.evalEval x y = 2 * y + W'.a₁ * x + W'.a₃ := by
simp only [polynomialY]
eval_simp
rw [← add_assoc]
@[simp]
lemma evalEval_polynomialY_zero : W'.polynomialY.evalEval 0 0 = W'.a₃ := by
simp only [evalEval_polynomialY, zero_add, mul_zero]
variable (W') in
/-- The proposition that an affine point `(x, y)` on a Weierstrass curve `W` is nonsingular.
In other words, either `W_X(x, y) ≠ 0` or `W_Y(x, y) ≠ 0`.
Note that this definition is only mathematically accurate for fields. -/
-- TODO: generalise this definition to be mathematically accurate for a larger class of rings.
def Nonsingular (x y : R) : Prop :=
W'.Equation x y ∧ (W'.polynomialX.evalEval x y ≠ 0 ∨ W'.polynomialY.evalEval x y ≠ 0)
lemma nonsingular_iff' (x y : R) : W'.Nonsingular x y ↔ W'.Equation x y ∧
(W'.a₁ * y - (3 * x ^ 2 + 2 * W'.a₂ * x + W'.a₄) ≠ 0 ∨ 2 * y + W'.a₁ * x + W'.a₃ ≠ 0) := by
rw [Nonsingular, equation_iff', evalEval_polynomialX, evalEval_polynomialY]
lemma nonsingular_iff (x y : R) : W'.Nonsingular x y ↔ W'.Equation x y ∧
(W'.a₁ * y ≠ 3 * x ^ 2 + 2 * W'.a₂ * x + W'.a₄ ∨ y ≠ -y - W'.a₁ * x - W'.a₃) := by
rw [nonsingular_iff', sub_ne_zero, ← sub_ne_zero (a := y)]
congr! 3
ring1
@[simp]
lemma nonsingular_zero : W'.Nonsingular 0 0 ↔ W'.a₆ = 0 ∧ (W'.a₃ ≠ 0 ∨ W'.a₄ ≠ 0) := by
rw [Nonsingular, equation_zero, evalEval_polynomialX_zero, neg_ne_zero, evalEval_polynomialY_zero,
or_comm]
lemma nonsingular_iff_variableChange (x y : R) :
W'.Nonsingular x y ↔ (VariableChange.mk 1 x 0 y • W').toAffine.Nonsingular 0 0 := by
rw [nonsingular_iff', equation_iff_variableChange, equation_zero, ← neg_ne_zero, or_comm,
nonsingular_zero, variableChange_a₃, variableChange_a₄, inv_one, Units.val_one]
simp only [variableChange_def]
congr! 3 <;> ring1
private lemma equation_zero_iff_nonsingular_zero_of_Δ_ne_zero (hΔ : W'.Δ ≠ 0) :
W'.Equation 0 0 ↔ W'.Nonsingular 0 0 := by
simp only [equation_zero, nonsingular_zero, iff_self_and]
contrapose! hΔ
simp only [b₂, b₄, b₆, b₈, Δ, hΔ]
ring1
/-- A Weierstrass curve is nonsingular at every point if its discriminant is non-zero. -/
lemma equation_iff_nonsingular_of_Δ_ne_zero {x y : R} (hΔ : W'.Δ ≠ 0) :
W'.Equation x y ↔ W'.Nonsingular x y := by
rw [equation_iff_variableChange, nonsingular_iff_variableChange,
equation_zero_iff_nonsingular_zero_of_Δ_ne_zero <| by
rwa [variableChange_Δ, inv_one, Units.val_one, one_pow, one_mul]]
/-- An elliptic curve is nonsingular at every point. -/
lemma equation_iff_nonsingular [Nontrivial R] [W'.IsElliptic] {x y : R} :
W'.toAffine.Equation x y ↔ W'.toAffine.Nonsingular x y :=
W'.toAffine.equation_iff_nonsingular_of_Δ_ne_zero <| W'.coe_Δ' ▸ W'.Δ'.ne_zero
@[deprecated (since := "2025-03-01")] alias nonsingular_zero_of_Δ_ne_zero :=
equation_iff_nonsingular_of_Δ_ne_zero
@[deprecated (since := "2025-03-01")] alias nonsingular_of_Δ_ne_zero :=
equation_iff_nonsingular_of_Δ_ne_zero
@[deprecated (since := "2025-03-01")] alias nonsingular := equation_iff_nonsingular
end Nonsingular
section Ring
/-! ### Group operation polynomials over a ring -/
variable (W') in
/-- The negation polynomial `-Y - a₁X - a₃` associated to the negation of a nonsingular affine point
on a Weierstrass curve. -/
noncomputable def negPolynomial : R[X][Y] :=
-(Y : R[X][Y]) - C (C W'.a₁ * X + C W'.a₃)
lemma Y_sub_polynomialY : Y - W'.polynomialY = W'.negPolynomial := by
rw [polynomialY, negPolynomial]
C_simp
ring1
lemma Y_sub_negPolynomial : Y - W'.negPolynomial = W'.polynomialY := by
rw [← Y_sub_polynomialY, sub_sub_cancel]
variable (W') in
/-- The `Y`-coordinate of `-(x, y)` for a nonsingular affine point `(x, y)` on a Weierstrass curve
`W`.
This depends on `W`, and has argument order: `x`, `y`. -/
@[simp]
def negY (x y : R) : R :=
-y - W'.a₁ * x - W'.a₃
lemma negY_negY (x y : R) : W'.negY x (W'.negY x y) = y := by
simp only [negY]
ring1
lemma evalEval_negPolynomial (x y : R) : W'.negPolynomial.evalEval x y = W'.negY x y := by
rw [negY, sub_sub, negPolynomial]
eval_simp
@[deprecated (since := "2025-03-05")] alias eval_negPolynomial := evalEval_negPolynomial
/-- The line polynomial `ℓ(X - x) + y` associated to the line `Y = ℓ(X - x) + y` that passes through
a nonsingular affine point `(x, y)` on a Weierstrass curve `W` with a slope of `ℓ`.
This does not depend on `W`, and has argument order: `x`, `y`, `ℓ`. -/
noncomputable def linePolynomial (x y ℓ : R) : R[X] :=
C ℓ * (X - C x) + C y
variable (W') in
/-- The addition polynomial obtained by substituting the line `Y = ℓ(X - x) + y` into the polynomial
`W(X, Y)` associated to a Weierstrass curve `W`. If such a line intersects `W` at another
nonsingular affine point `(x', y')` on `W`, then the roots of this polynomial are precisely `x`,
`x'`, and the `X`-coordinate of the addition of `(x, y)` and `(x', y')`.
This depends on `W`, and has argument order: `x`, `y`, `ℓ`. -/
noncomputable def addPolynomial (x y ℓ : R) : R[X] :=
W'.polynomial.eval <| linePolynomial x y ℓ
lemma C_addPolynomial (x y ℓ : R) : C (W'.addPolynomial x y ℓ) =
(Y - C (linePolynomial x y ℓ)) * (W'.negPolynomial - C (linePolynomial x y ℓ)) +
W'.polynomial := by
rw [addPolynomial, linePolynomial, polynomial, negPolynomial]
eval_simp
C_simp
ring1
lemma addPolynomial_eq (x y ℓ : R) : W'.addPolynomial x y ℓ = -Cubic.toPoly
⟨1, -ℓ ^ 2 - W'.a₁ * ℓ + W'.a₂,
2 * x * ℓ ^ 2 + (W'.a₁ * x - 2 * y - W'.a₃) * ℓ + (-W'.a₁ * y + W'.a₄),
-x ^ 2 * ℓ ^ 2 + (2 * x * y + W'.a₃ * x) * ℓ - (y ^ 2 + W'.a₃ * y - W'.a₆)⟩ := by
rw [addPolynomial, linePolynomial, polynomial, Cubic.toPoly]
eval_simp
C_simp
ring1
variable (W') in
/-- The `X`-coordinate of `(x₁, y₁) + (x₂, y₂)` for two nonsingular affine points `(x₁, y₁)` and
`(x₂, y₂)` on a Weierstrass curve `W`, where the line through them has a slope of `ℓ`.
This depends on `W`, and has argument order: `x₁`, `x₂`, `ℓ`. -/
@[simp]
def addX (x₁ x₂ ℓ : R) : R :=
ℓ ^ 2 + W'.a₁ * ℓ - W'.a₂ - x₁ - x₂
variable (W') in
/-- The `Y`-coordinate of `-((x₁, y₁) + (x₂, y₂))` for two nonsingular affine points `(x₁, y₁)` and
`(x₂, y₂)` on a Weierstrass curve `W`, where the line through them has a slope of `ℓ`.
This depends on `W`, and has argument order: `x₁`, `x₂`, `y₁`, `ℓ`. -/
@[simp]
def negAddY (x₁ x₂ y₁ ℓ : R) : R :=
ℓ * (W'.addX x₁ x₂ ℓ - x₁) + y₁
variable (W') in
/-- The `Y`-coordinate of `(x₁, y₁) + (x₂, y₂)` for two nonsingular affine points `(x₁, y₁)` and
`(x₂, y₂)` on a Weierstrass curve `W`, where the line through them has a slope of `ℓ`.
This depends on `W`, and has argument order: `x₁`, `x₂`, `y₁`, `ℓ`. -/
@[simp]
def addY (x₁ x₂ y₁ ℓ : R) : R :=
W'.negY (W'.addX x₁ x₂ ℓ) (W'.negAddY x₁ x₂ y₁ ℓ)
lemma equation_neg (x y : R) : W'.Equation x (W'.negY x y) ↔ W'.Equation x y := by
rw [equation_iff, equation_iff, negY]
congr! 1
ring1
@[deprecated (since := "2025-02-01")] alias equation_neg_of := equation_neg
@[deprecated (since := "2025-02-01")] alias equation_neg_iff := equation_neg
lemma nonsingular_neg (x y : R) : W'.Nonsingular x (W'.negY x y) ↔ W'.Nonsingular x y := by
rw [nonsingular_iff, equation_neg, ← negY, negY_negY, ← @ne_comm _ y, nonsingular_iff]
exact and_congr_right' <| (iff_congr not_and_or.symm not_and_or.symm).mpr <|
not_congr <| and_congr_left fun h => by rw [← h]
@[deprecated (since := "2025-02-01")] alias nonsingular_neg_of := nonsingular_neg
@[deprecated (since := "2025-02-01")] alias nonsingular_neg_iff := nonsingular_neg
lemma equation_add_iff (x₁ x₂ y₁ ℓ : R) : W'.Equation (W'.addX x₁ x₂ ℓ) (W'.negAddY x₁ x₂ y₁ ℓ) ↔
(W'.addPolynomial x₁ y₁ ℓ).eval (W'.addX x₁ x₂ ℓ) = 0 := by
rw [Equation, negAddY, addPolynomial, linePolynomial, polynomial]
eval_simp
lemma nonsingular_negAdd_of_eval_derivative_ne_zero {x₁ x₂ y₁ ℓ : R}
(hx' : W'.Equation (W'.addX x₁ x₂ ℓ) (W'.negAddY x₁ x₂ y₁ ℓ))
(hx : (W'.addPolynomial x₁ y₁ ℓ).derivative.eval (W'.addX x₁ x₂ ℓ) ≠ 0) :
W'.Nonsingular (W'.addX x₁ x₂ ℓ) (W'.negAddY x₁ x₂ y₁ ℓ) := by
rw [Nonsingular, and_iff_right hx', negAddY, polynomialX, polynomialY]
eval_simp
contrapose! hx
rw [addPolynomial, linePolynomial, polynomial]
eval_simp
derivative_simp
simp only [zero_add, add_zero, sub_zero, zero_mul, mul_one]
eval_simp
linear_combination (norm := (norm_num1; ring1)) hx.left + ℓ * hx.right
end Ring
section Field
/-! ### Group operation polynomials over a field -/
open Classical in
variable (W) in
/-- The slope of the line through two nonsingular affine points `(x₁, y₁)` and `(x₂, y₂)` on a
Weierstrass curve `W`.
If `x₁ ≠ x₂`, then this line is the secant of `W` through `(x₁, y₁)` and `(x₂, y₂)`, and has slope
`(y₁ - y₂) / (x₁ - x₂)`. Otherwise, if `y₁ ≠ -y₁ - a₁x₁ - a₃`, then this line is the tangent of `W`
at `(x₁, y₁) = (x₂, y₂)`, and has slope `(3x₁² + 2a₂x₁ + a₄ - a₁y₁) / (2y₁ + a₁x₁ + a₃)`. Otherwise,
this line is vertical, in which case this returns the value `0`.
This depends on `W`, and has argument order: `x₁`, `x₂`, `y₁`, `y₂`. -/
noncomputable def slope (x₁ x₂ y₁ y₂ : F) : F :=
if x₁ = x₂ then if y₁ = W.negY x₂ y₂ then 0
else (3 * x₁ ^ 2 + 2 * W.a₂ * x₁ + W.a₄ - W.a₁ * y₁) / (y₁ - W.negY x₁ y₁)
else (y₁ - y₂) / (x₁ - x₂)
@[simp]
lemma slope_of_Y_eq {x₁ x₂ y₁ y₂ : F} (hx : x₁ = x₂) (hy : y₁ = W.negY x₂ y₂) :
W.slope x₁ x₂ y₁ y₂ = 0 := by
rw [slope, if_pos hx, if_pos hy]
@[simp]
lemma slope_of_Y_ne {x₁ x₂ y₁ y₂ : F} (hx : x₁ = x₂) (hy : y₁ ≠ W.negY x₂ y₂) :
W.slope x₁ x₂ y₁ y₂ =
(3 * x₁ ^ 2 + 2 * W.a₂ * x₁ + W.a₄ - W.a₁ * y₁) / (y₁ - W.negY x₁ y₁) := by
rw [slope, if_pos hx, if_neg hy]
@[simp]
lemma slope_of_X_ne {x₁ x₂ y₁ y₂ : F} (hx : x₁ ≠ x₂) :
W.slope x₁ x₂ y₁ y₂ = (y₁ - y₂) / (x₁ - x₂) := by
rw [slope, if_neg hx]
lemma slope_of_Y_ne_eq_evalEval {x₁ x₂ y₁ y₂ : F} (hx : x₁ = x₂) (hy : y₁ ≠ W.negY x₂ y₂) :
W.slope x₁ x₂ y₁ y₂ = -W.polynomialX.evalEval x₁ y₁ / W.polynomialY.evalEval x₁ y₁ := by
rw [slope_of_Y_ne hx hy, evalEval_polynomialX, neg_sub]
congr 1
rw [negY, evalEval_polynomialY]
ring1
@[deprecated (since := "2025-03-05")] alias slope_of_Y_ne_eq_eval := slope_of_Y_ne_eq_evalEval
lemma Y_eq_of_X_eq {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂)
(hx : x₁ = x₂) : y₁ = y₂ ∨ y₁ = W.negY x₂ y₂ := by
rw [equation_iff] at h₁ h₂
rw [← sub_eq_zero, ← sub_eq_zero (a := y₁), ← mul_eq_zero, negY]
linear_combination (norm := (rw [hx]; ring1)) h₁ - h₂
lemma Y_eq_of_Y_ne {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂) (hx : x₁ = x₂)
(hy : y₁ ≠ W.negY x₂ y₂) : y₁ = y₂ :=
(Y_eq_of_X_eq h₁ h₂ hx).resolve_right hy
lemma 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₂)) : W.addPolynomial x₁ y₁ (W.slope x₁ x₂ y₁ y₂) =
-((X - C x₁) * (X - C x₂) * (X - C (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂))) := by
rw [addPolynomial_eq, neg_inj, Cubic.prod_X_sub_C_eq, Cubic.toPoly_injective]
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⟩
rw [equation_iff] at h₁ h₂
rw [slope_of_Y_ne rfl hy]
rw [negY, ← sub_ne_zero] at hy
ext
· rfl
· simp only [addX]
ring1
· field_simp [hy]
ring1
· linear_combination (norm := (field_simp [hy]; ring1)) -h₁
· rw [equation_iff] at h₁ h₂
rw [slope_of_X_ne hx]
rw [← sub_eq_zero] at hx
ext
· rfl
· simp only [addX]
ring1
· apply mul_right_injective₀ hx
linear_combination (norm := (field_simp [hx]; ring1)) h₂ - h₁
· apply mul_right_injective₀ hx
linear_combination (norm := (field_simp [hx]; ring1)) x₂ * h₁ - x₁ * h₂
/-- The negated addition of two affine points in `W` on a sloped line lies in `W`. -/
lemma equation_negAdd {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂)
(hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : W.Equation
(W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.negAddY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) := by
rw [equation_add_iff, addPolynomial_slope h₁ h₂ hxy]
eval_simp
rw [neg_eq_zero, sub_self, mul_zero]
/-- The addition of two affine points in `W` on a sloped line lies in `W`. -/
lemma equation_add {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂)
(hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) :
W.Equation (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.addY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) :=
(equation_neg ..).mpr <| equation_negAdd h₁ h₂ hxy
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₂)) : C (W.addPolynomial x₁ y₁ <| W.slope x₁ x₂ y₁ y₂) =
-(C (X - C x₁) * C (X - C x₂) * C (X - C (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂))) := by
rw [addPolynomial_slope h₁ h₂ hxy]
map_simp
lemma derivative_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₂)) :
derivative (W.addPolynomial x₁ y₁ <| W.slope x₁ x₂ y₁ y₂) =
-((X - C x₁) * (X - C x₂) + (X - C x₁) * (X - C (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂)) +
(X - C x₂) * (X - C (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂))) := by
rw [addPolynomial_slope h₁ h₂ hxy]
derivative_simp
ring1
/-- The negated addition of two nonsingular affine points in `W` on a sloped line is nonsingular. -/
lemma nonsingular_negAdd {x₁ x₂ y₁ y₂ : F} (h₁ : W.Nonsingular x₁ y₁) (h₂ : W.Nonsingular x₂ y₂)
(hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : W.Nonsingular
(W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.negAddY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) := by
by_cases hx₁ : W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂) = x₁
· rwa [negAddY, hx₁, sub_self, mul_zero, zero_add]
· by_cases hx₂ : W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂) = x₂
· by_cases hx : x₁ = x₂
· subst hx
contradiction
· rwa [negAddY, ← neg_sub, mul_neg, hx₂, slope_of_X_ne hx,
div_mul_cancel₀ _ <| sub_ne_zero_of_ne hx, neg_sub, sub_add_cancel]
· apply nonsingular_negAdd_of_eval_derivative_ne_zero <| equation_negAdd h₁.left h₂.left hxy
rw [derivative_addPolynomial_slope h₁.left h₂.left hxy]
eval_simp
simp only [neg_ne_zero, sub_self, mul_zero, add_zero]
exact mul_ne_zero (sub_ne_zero_of_ne hx₁) (sub_ne_zero_of_ne hx₂)
/-- The addition of two nonsingular affine points in `W` on a sloped line is nonsingular. -/
lemma nonsingular_add {x₁ x₂ y₁ y₂ : F} (h₁ : W.Nonsingular x₁ y₁) (h₂ : W.Nonsingular x₂ y₂)
(hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) :
W.Nonsingular (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.addY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) :=
(nonsingular_neg ..).mpr <| nonsingular_negAdd h₁ h₂ hxy
/-- The formula `x(P₁ + P₂) = x(P₁ - P₂) - ψ(P₁)ψ(P₂) / (x(P₂) - x(P₁))²`,
where `ψ(x,y) = 2y + a₁x + a₃`. -/
lemma addX_eq_addX_negY_sub {x₁ x₂ : F} (y₁ y₂ : F) (hx : x₁ ≠ x₂) :
W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂) = W.addX x₁ x₂ (W.slope x₁ x₂ y₁ <| W.negY x₂ y₂) -
(y₁ - W.negY x₁ y₁) * (y₂ - W.negY x₂ y₂) / (x₂ - x₁) ^ 2 := by
simp_rw [slope_of_X_ne hx, addX, negY, ← neg_sub x₁, neg_sq]
field_simp [sub_ne_zero.mpr hx]
ring1
/-- The formula `y(P₁)(x(P₂) - x(P₃)) + y(P₂)(x(P₃) - x(P₁)) + y(P₃)(x(P₁) - x(P₂)) = 0`,
assuming that `P₁ + P₂ + P₃ = O`. -/
lemma cyclic_sum_Y_mul_X_sub_X {x₁ x₂ : F} (y₁ y₂ : F) (hx : x₁ ≠ x₂) :
let x₃ := W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂)
y₁ * (x₂ - x₃) + y₂ * (x₃ - x₁) + W.negAddY x₁ x₂ y₁ (W.slope x₁ x₂ y₁ y₂) * (x₁ - x₂) = 0 := by
simp_rw [slope_of_X_ne hx, negAddY, addX]
field_simp [sub_ne_zero.mpr hx]
ring1
/-- The formula `ψ(P₁ + P₂) = (ψ(P₂)(x(P₁) - x(P₃)) - ψ(P₁)(x(P₂) - x(P₃))) / (x(P₂) - x(P₁))`,
where `ψ(x,y) = 2y + a₁x + a₃`. -/
lemma addY_sub_negY_addY {x₁ x₂ : F} (y₁ y₂ : F) (hx : x₁ ≠ x₂) :
let x₃ := W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂)
let y₃ := W.addY x₁ x₂ y₁ (W.slope x₁ x₂ y₁ y₂)
y₃ - W.negY x₃ y₃ =
((y₂ - W.negY x₂ y₂) * (x₁ - x₃) - (y₁ - W.negY x₁ y₁) * (x₂ - x₃)) / (x₂ - x₁) := by
simp_rw [addY, negY, eq_div_iff (sub_ne_zero.mpr hx.symm)]
linear_combination (norm := ring1) 2 * cyclic_sum_Y_mul_X_sub_X y₁ y₂ hx
end Field
section Group
/-! ### Nonsingular points -/
variable (W') in
/-- A nonsingular point on a Weierstrass curve `W` in affine coordinates. This is either the unique
point at infinity `WeierstrassCurve.Affine.Point.zero` or a nonsingular affine point
`WeierstrassCurve.Affine.Point.some (x, y)` satisfying the Weierstrass equation of `W`. -/
inductive Point
| zero
| some {x y : R} (h : W'.Nonsingular x y)
/-- For an algebraic extension `S` of a ring `R`, the type of nonsingular `S`-points on a
Weierstrass curve `W` over `R` in affine coordinates. -/
scoped notation3:max W' "⟮" S "⟯" => Affine.Point <| baseChange W' S
namespace Point
/-! ### Group operations -/
instance : Inhabited W'.Point :=
⟨.zero⟩
instance : Zero W'.Point :=
⟨.zero⟩
lemma zero_def : 0 = (.zero : W'.Point) :=
rfl
lemma some_ne_zero {x y : R} (h : W'.Nonsingular x y) : Point.some h ≠ 0 := by
rintro (_ | _)
/-- The negation of a nonsingular point on a Weierstrass curve in affine coordinates.
Given a nonsingular point `P` in affine coordinates, use `-P` instead of `neg P`. -/
def neg : W'.Point → W'.Point
| 0 => 0
| some h => some <| (nonsingular_neg ..).mpr h
instance : Neg W'.Point :=
⟨neg⟩
lemma neg_def (P : W'.Point) : -P = P.neg :=
rfl
@[simp]
lemma neg_zero : (-0 : W'.Point) = 0 :=
rfl
@[simp]
lemma neg_some {x y : R} (h : W'.Nonsingular x y) : -some h = some ((nonsingular_neg ..).mpr h) :=
rfl
instance : InvolutiveNeg W'.Point where
neg_neg := by
rintro (_ | _)
· rfl
· simp only [neg_some, negY_negY]
open Classical in
/-- The addition of two nonsingular points on a Weierstrass curve in affine coordinates.
Given two nonsingular points `P` and `Q` in affine coordinates, use `P + Q` instead of `add P Q`. -/
noncomputable def add : W.Point → W.Point → W.Point
| 0, P => P
| P, 0 => P
| @some _ _ _ x₁ y₁ h₁, @some _ _ _ x₂ y₂ h₂ =>
if hxy : x₁ = x₂ ∧ y₁ = W.negY x₂ y₂ then 0 else some <| nonsingular_add h₁ h₂ hxy
noncomputable instance : Add W.Point :=
⟨add⟩
noncomputable instance : AddZeroClass W.Point :=
⟨by rintro (_ | _) <;> rfl, by rintro (_ | _) <;> rfl⟩
lemma add_def (P Q : W.Point) : P + Q = P.add Q :=
rfl
lemma add_some {x₁ x₂ y₁ y₂ : F} (hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) {h₁ : W.Nonsingular x₁ y₁}
{h₂ : W.Nonsingular x₂ y₂} : some h₁ + some h₂ = some (nonsingular_add h₁ h₂ hxy) := by
simp only [add_def, add, dif_neg hxy]
@[deprecated (since := "2025-02-28")] alias add_of_imp := add_some
@[simp]
lemma add_of_Y_eq {x₁ x₂ y₁ y₂ : F} {h₁ : W.Nonsingular x₁ y₁} {h₂ : W.Nonsingular x₂ y₂}
(hx : x₁ = x₂) (hy : y₁ = W.negY x₂ y₂) : some h₁ + some h₂ = 0 := by
simpa only [add_def, add] using dif_pos ⟨hx, hy⟩
@[simp]
lemma add_self_of_Y_eq {x₁ y₁ : F} {h₁ : W.Nonsingular x₁ y₁} (hy : y₁ = W.negY x₁ y₁) :
some h₁ + some h₁ = 0 :=
add_of_Y_eq rfl hy
@[simp]
lemma add_of_Y_ne {x₁ x₂ y₁ y₂ : F} {h₁ : W.Nonsingular x₁ y₁} {h₂ : W.Nonsingular x₂ y₂}
(hy : y₁ ≠ W.negY x₂ y₂) :
some h₁ + some h₂ = some (nonsingular_add h₁ h₂ fun hxy => hy hxy.right) :=
add_some fun hxy => hy hxy.right
lemma add_of_Y_ne' {x₁ x₂ y₁ y₂ : F} {h₁ : W.Nonsingular x₁ y₁} {h₂ : W.Nonsingular x₂ y₂}
(hy : y₁ ≠ W.negY x₂ y₂) :
some h₁ + some h₂ = -some (nonsingular_negAdd h₁ h₂ fun hxy => hy hxy.right) :=
add_of_Y_ne hy
@[simp]
lemma add_self_of_Y_ne {x₁ y₁ : F} {h₁ : W.Nonsingular x₁ y₁} (hy : y₁ ≠ W.negY x₁ y₁) :
some h₁ + some h₁ = some (nonsingular_add h₁ h₁ fun hxy => hy hxy.right) :=
add_of_Y_ne hy
lemma add_self_of_Y_ne' {x₁ y₁ : F} {h₁ : W.Nonsingular x₁ y₁} (hy : y₁ ≠ W.negY x₁ y₁) :
some h₁ + some h₁ = -some (nonsingular_negAdd h₁ h₁ fun hxy => hy hxy.right) :=
add_of_Y_ne hy
@[simp]
lemma add_of_X_ne {x₁ x₂ y₁ y₂ : F} {h₁ : W.Nonsingular x₁ y₁} {h₂ : W.Nonsingular x₂ y₂}
(hx : x₁ ≠ x₂) : some h₁ + some h₂ = some (nonsingular_add h₁ h₂ fun hxy => hx hxy.left) :=
add_some fun hxy => hx hxy.left
lemma add_of_X_ne' {x₁ x₂ y₁ y₂ : F} {h₁ : W.Nonsingular x₁ y₁} {h₂ : W.Nonsingular x₂ y₂}
(hx : x₁ ≠ x₂) : some h₁ + some h₂ = -some (nonsingular_negAdd h₁ h₂ fun hxy => hx hxy.left) :=
add_of_X_ne hx
end Point
end Group
section Map
/-! ### Maps across ring homomorphisms -/
variable (f : R →+* S) (x y x₁ y₁ x₂ y₂ ℓ : R)
lemma map_polynomial : (W'.map f).toAffine.polynomial = W'.polynomial.map (mapRingHom f) := by
simp only [polynomial]
map_simp
lemma evalEval_baseChange_polynomial :
(W'.baseChange R[X][Y]).toAffine.polynomial.evalEval (C X) Y = W'.polynomial := by
rw [map_polynomial, evalEval, eval_map, eval_C_X_eval₂_map_C_X]
@[deprecated (since := "2025-03-05")] alias evalEval_baseChange_polynomial_X_Y :=
evalEval_baseChange_polynomial
variable {x y} in
lemma Equation.map {x y : R} (h : W'.Equation x y) : (W'.map f).toAffine.Equation (f x) (f y) := by
rw [Equation, map_polynomial, map_mapRingHom_evalEval, h, map_zero]
variable {f} in
lemma map_equation (hf : Function.Injective f) :
(W'.map f).toAffine.Equation (f x) (f y) ↔ W'.Equation x y := by
simp only [Equation, map_polynomial, map_mapRingHom_evalEval, map_eq_zero_iff f hf]
lemma map_polynomialX : (W'.map f).toAffine.polynomialX = W'.polynomialX.map (mapRingHom f) := by
simp only [polynomialX]
map_simp
lemma map_polynomialY : (W'.map f).toAffine.polynomialY = W'.polynomialY.map (mapRingHom f) := by
simp only [polynomialY]
map_simp
variable {f} in
lemma map_nonsingular (hf : Function.Injective f) :
(W'.map f).toAffine.Nonsingular (f x) (f y) ↔ W'.Nonsingular x y := by
simp only [Nonsingular, evalEval, map_equation _ _ hf, map_polynomialX, map_polynomialY,
map_mapRingHom_evalEval, map_ne_zero_iff f hf]
lemma map_negPolynomial :
(W'.map f).toAffine.negPolynomial = W'.negPolynomial.map (mapRingHom f) := by
simp only [negPolynomial]
map_simp
lemma map_negY : (W'.map f).toAffine.negY (f x) (f y) = f (W'.negY x y) := by
simp only [negY]
map_simp
lemma map_linePolynomial : linePolynomial (f x) (f y) (f ℓ) = (linePolynomial x y ℓ).map f := by
simp only [linePolynomial]
map_simp
lemma map_addPolynomial :
(W'.map f).toAffine.addPolynomial (f x) (f y) (f ℓ) = (W'.addPolynomial x y ℓ).map f := by
rw [addPolynomial, map_polynomial, eval_map, linePolynomial, addPolynomial, ← coe_mapRingHom,
← eval₂_hom, linePolynomial]
map_simp
lemma map_addX : (W'.map f).toAffine.addX (f x₁) (f x₂) (f ℓ) = f (W'.addX x₁ x₂ ℓ) := by
simp only [addX]
map_simp
lemma map_negAddY :
(W'.map f).toAffine.negAddY (f x₁) (f x₂) (f y₁) (f ℓ) = f (W'.negAddY x₁ x₂ y₁ ℓ) := by
simp only [negAddY, map_addX]
map_simp
lemma map_addY :
(W'.map f).toAffine.addY (f x₁) (f x₂) (f y₁) (f ℓ) = f (W'.toAffine.addY x₁ x₂ y₁ ℓ) := by
simp only [addY, map_negAddY, map_addX, map_negY]
lemma map_slope (f : F →+* K) (x₁ x₂ y₁ y₂ : F) :
(W.map f).toAffine.slope (f x₁) (f x₂) (f y₁) (f y₂) = f (W.slope x₁ x₂ y₁ y₂) := by
by_cases hx : x₁ = x₂
· by_cases hy : y₁ = W.negY x₂ y₂
· rw [slope_of_Y_eq (congr_arg f hx) <| by rw [hy, map_negY], slope_of_Y_eq hx hy, map_zero]
· rw [slope_of_Y_ne (congr_arg f hx) <| map_negY f x₂ y₂ ▸ fun h => hy <| f.injective h,
map_negY, slope_of_Y_ne hx hy]
map_simp
· rw [slope_of_X_ne fun h => hx <| f.injective h, slope_of_X_ne hx]
map_simp
end Map
section BaseChange
/-! ### Base changes across algebra homomorphisms -/
variable [Algebra R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] [Algebra R B] [Algebra S B]
[IsScalarTower R S B] (f : A →ₐ[S] B) (x y x₁ y₁ x₂ y₂ ℓ : A)
lemma baseChange_polynomial : (W'.baseChange B).toAffine.polynomial =
(W'.baseChange A).toAffine.polynomial.map (mapRingHom f) := by
rw [← map_polynomial, map_baseChange]
variable {x y} in
lemma Equation.baseChange (h : (W'.baseChange A).toAffine.Equation x y) :
(W'.baseChange B).toAffine.Equation (f x) (f y) := by
convert Equation.map f.toRingHom h using 1
rw [AlgHom.toRingHom_eq_coe, map_baseChange]
variable {f} in
lemma baseChange_equation (hf : Function.Injective f) :
(W'.baseChange B).toAffine.Equation (f x) (f y) ↔ (W'.baseChange A).toAffine.Equation x y := by
rw [← map_equation _ _ hf, AlgHom.toRingHom_eq_coe, map_baseChange, RingHom.coe_coe]
lemma baseChange_polynomialX : (W'.baseChange B).toAffine.polynomialX =
(W'.baseChange A).toAffine.polynomialX.map (mapRingHom f) := by
rw [← map_polynomialX, map_baseChange]
lemma baseChange_polynomialY : (W'.baseChange B).toAffine.polynomialY =
(W'.baseChange A).toAffine.polynomialY.map (mapRingHom f) := by
rw [← map_polynomialY, map_baseChange]
variable {f} in
lemma baseChange_nonsingular (hf : Function.Injective f) :
(W'.baseChange B).toAffine.Nonsingular (f x) (f y) ↔
(W'.baseChange A).toAffine.Nonsingular x y := by
rw [← map_nonsingular _ _ hf, AlgHom.toRingHom_eq_coe, map_baseChange, RingHom.coe_coe]
lemma baseChange_negPolynomial : (W'.baseChange B).toAffine.negPolynomial =
(W'.baseChange A).toAffine.negPolynomial.map (mapRingHom f) := by
rw [← map_negPolynomial, map_baseChange]
lemma baseChange_negY :
(W'.baseChange B).toAffine.negY (f x) (f y) = f ((W'.baseChange A).toAffine.negY x y) := by
rw [← RingHom.coe_coe, ← map_negY, map_baseChange]
lemma baseChange_addPolynomial : (W'.baseChange B).toAffine.addPolynomial (f x) (f y) (f ℓ) =
((W'.baseChange A).toAffine.addPolynomial x y ℓ).map f := by
rw [← RingHom.coe_coe, ← map_addPolynomial, map_baseChange]
lemma baseChange_addX : (W'.baseChange B).toAffine.addX (f x₁) (f x₂) (f ℓ) =
f ((W'.baseChange A).toAffine.addX x₁ x₂ ℓ) := by
rw [← RingHom.coe_coe, ← map_addX, map_baseChange]
lemma baseChange_negAddY : (W'.baseChange B).toAffine.negAddY (f x₁) (f x₂) (f y₁) (f ℓ) =
f ((W'.baseChange A).toAffine.negAddY x₁ x₂ y₁ ℓ) := by
rw [← RingHom.coe_coe, ← map_negAddY, map_baseChange]
lemma baseChange_addY : (W'.baseChange B).toAffine.addY (f x₁) (f x₂) (f y₁) (f ℓ) =
f ((W'.baseChange A).toAffine.addY x₁ x₂ y₁ ℓ) := by
rw [← RingHom.coe_coe, ← map_addY, map_baseChange]
lemma baseChange_slope [Algebra R F] [Algebra S F] [IsScalarTower R S F] [Algebra R K] [Algebra S K]
[IsScalarTower R S K] (f : F →ₐ[S] K) (x₁ x₂ y₁ y₂ : F) :
(W'.baseChange K).toAffine.slope (f x₁) (f x₂) (f y₁) (f y₂) =
f ((W'.baseChange F).toAffine.slope x₁ x₂ y₁ y₂) := by
rw [← RingHom.coe_coe, ← map_slope, map_baseChange]
end BaseChange
namespace Point
variable [Algebra R S] [Algebra R F] [Algebra S F] [IsScalarTower R S F] [Algebra R K] [Algebra S K]
[IsScalarTower R S K] [Algebra R L] [Algebra S L] [IsScalarTower R S L] (f : F →ₐ[S] K)
(g : K →ₐ[S] L)
/-- The group homomorphism from `W⟮F⟯` to `W⟮K⟯` induced by an algebra homomorphism `f : F →ₐ[S] K`,
where `W` is defined over a subring of a ring `S`, and `F` and `K` are field extensions of `S`. -/
def map : W'⟮F⟯ →+ W'⟮K⟯ where
toFun P := match P with
| 0 => 0
| some h => some <| (baseChange_nonsingular _ _ f.injective).mpr h
map_zero' := rfl
map_add' := by
rintro (_ | @⟨x₁, y₁, _⟩) (_ | @⟨x₂, y₂, _⟩)
any_goals rfl
by_cases hxy : x₁ = x₂ ∧ y₁ = (W'.baseChange F).toAffine.negY x₂ y₂
· simp only [add_of_Y_eq hxy.left hxy.right]
rw [add_of_Y_eq (congr_arg _ hxy.left) <| by rw [hxy.right, baseChange_negY]]
· simp only [add_some hxy, ← baseChange_addX, ← baseChange_addY, ← baseChange_slope]
rw [add_some fun h => hxy ⟨f.injective h.1, f.injective (W'.baseChange_negY f .. ▸ h).2⟩]
@[deprecated (since := "2025-03-01")] alias mapFun := map
lemma map_zero : map f (0 : W'⟮F⟯) = 0 :=
rfl
lemma map_some {x y : F} (h : (W'.baseChange F).toAffine.Nonsingular x y) :
map f (some h) = some ((W'.baseChange_nonsingular _ _ f.injective).mpr h) :=
rfl
lemma map_id (P : W'⟮F⟯) : map (Algebra.ofId F F) P = P := by
cases P <;> rfl
lemma map_map (P : W'⟮F⟯) : map g (map f P) = map (g.comp f) P := by
cases P <;> rfl
lemma map_injective : Function.Injective <| map (W' := W') f := by
rintro (_ | _) (_ | _) h
any_goals contradiction
· rfl
· simpa only [some.injEq] using ⟨f.injective (some.inj h).left, f.injective (some.inj h).right⟩
variable (F K) in
/-- The group homomorphism from `W⟮F⟯` to `W⟮K⟯` induced by the base change from `F` to `K`, where
`W` is defined over a subring of a ring `S`, and `F` and `K` are field extensions of `S`. -/
abbrev baseChange [Algebra F K] [IsScalarTower R F K] : W'⟮F⟯ →+ W'⟮K⟯ :=
map <| Algebra.ofId F K
lemma map_baseChange [Algebra F K] [IsScalarTower R F K] [Algebra F L] [IsScalarTower R F L]
(f : K →ₐ[F] L) (P : W'⟮F⟯) : map f (baseChange F K P) = baseChange F L P := by
have : Subsingleton (F →ₐ[F] L) := inferInstance
convert map_map (Algebra.ofId F K) f P
|
end Point
| Mathlib/AlgebraicGeometry/EllipticCurve/Affine.lean | 942 | 944 |
/-
Copyright (c) 2022 Floris van Doorn, Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Heather Macbeth
-/
import Mathlib.Geometry.Manifold.ContMDiff.Atlas
import Mathlib.Geometry.Manifold.VectorBundle.FiberwiseLinear
import Mathlib.Topology.VectorBundle.Constructions
/-! # `C^n` vector bundles
This file defines `C^n` vector bundles over a manifold.
Let `E` be a topological vector bundle, with model fiber `F` and base space `B`. We consider `E` as
carrying a charted space structure given by its trivializations -- these are charts to `B × F`.
Then, by "composition", if `B` is itself a charted space over `H` (e.g. a smooth manifold), then `E`
is also a charted space over `H × F`.
Now, we define `ContMDiffVectorBundle` as the `Prop` of having `C^n` transition functions.
Recall the structure groupoid `contMDiffFiberwiseLinear` on `B × F` consisting of `C^n`, fiberwise
linear partial homeomorphisms. We show that our definition of "`C^n` vector bundle" implies
`HasGroupoid` for this groupoid, and show (by a "composition" of `HasGroupoid` instances) that
this means that a `C^n` vector bundle is a `C^n` manifold.
Since `ContMDiffVectorBundle` is a mixin, it should be easy to make variants and for many such
variants to coexist -- vector bundles can be `C^n` vector bundles over several different base
fields, etc.
## Main definitions and constructions
* `FiberBundle.chartedSpace`: A fiber bundle `E` over a base `B` with model fiber `F` is naturally
a charted space modelled on `B × F`.
* `FiberBundle.chartedSpace'`: Let `B` be a charted space modelled on `HB`. Then a fiber bundle
`E` over a base `B` with model fiber `F` is naturally a charted space modelled on `HB.prod F`.
* `ContMDiffVectorBundle`: Mixin class stating that a (topological) `VectorBundle` is `C^n`, in the
sense of having `C^n` transition functions, where the smoothness index `n`
belongs to `WithTop ℕ∞`.
* `ContMDiffFiberwiseLinear.hasGroupoid`: For a `C^n` vector bundle `E` over `B` with fiber
modelled on `F`, the change-of-co-ordinates between two trivializations `e`, `e'` for `E`,
considered as charts to `B × F`, is `C^n` and fiberwise linear, in the sense of belonging to the
structure groupoid `contMDiffFiberwiseLinear`.
* `Bundle.TotalSpace.isManifold`: A `C^n` vector bundle is naturally a `C^n` manifold.
* `VectorBundleCore.instContMDiffVectorBundle`: If a (topological) `VectorBundleCore` is `C^n`,
in the sense of having `C^n` transition functions (cf. `VectorBundleCore.IsContMDiff`),
then the vector bundle constructed from it is a `C^n` vector bundle.
* `VectorPrebundle.contMDiffVectorBundle`: If a `VectorPrebundle` is `C^n`,
in the sense of having `C^n` transition functions (cf. `VectorPrebundle.IsContMDiff`),
then the vector bundle constructed from it is a `C^n` vector bundle.
* `Bundle.Prod.contMDiffVectorBundle`: The direct sum of two `C^n` vector bundles is a `C^n`
vector bundle.
-/
assert_not_exists mfderiv
open Bundle Set PartialHomeomorph
open Function (id_def)
open Filter
open scoped Manifold Bundle Topology ContDiff
variable {n : WithTop ℕ∞} {𝕜 B B' F M : Type*} {E : B → Type*}
/-! ### Charted space structure on a fiber bundle -/
section
variable [TopologicalSpace F] [TopologicalSpace (TotalSpace F E)] [∀ x, TopologicalSpace (E x)]
{HB : Type*} [TopologicalSpace HB] [TopologicalSpace B] [ChartedSpace HB B] [FiberBundle F E]
/-- A fiber bundle `E` over a base `B` with model fiber `F` is naturally a charted space modelled on
`B × F`. -/
instance FiberBundle.chartedSpace' : ChartedSpace (B × F) (TotalSpace F E) where
atlas := (fun e : Trivialization F (π F E) => e.toPartialHomeomorph) '' trivializationAtlas F E
chartAt x := (trivializationAt F E x.proj).toPartialHomeomorph
mem_chart_source x :=
(trivializationAt F E x.proj).mem_source.mpr (mem_baseSet_trivializationAt F E x.proj)
chart_mem_atlas _ := mem_image_of_mem _ (trivialization_mem_atlas F E _)
theorem FiberBundle.chartedSpace'_chartAt (x : TotalSpace F E) :
chartAt (B × F) x = (trivializationAt F E x.proj).toPartialHomeomorph :=
rfl
/- Porting note: In Lean 3, the next instance was inside a section with locally reducible
`ModelProd` and it used `ModelProd B F` as the intermediate space. Using `B × F` in the middle
gives the same instance.
-/
--attribute [local reducible] ModelProd
/-- Let `B` be a charted space modelled on `HB`. Then a fiber bundle `E` over a base `B` with model
fiber `F` is naturally a charted space modelled on `HB.prod F`. -/
instance FiberBundle.chartedSpace : ChartedSpace (ModelProd HB F) (TotalSpace F E) :=
ChartedSpace.comp _ (B × F) _
theorem FiberBundle.chartedSpace_chartAt (x : TotalSpace F E) :
chartAt (ModelProd HB F) x =
(trivializationAt F E x.proj).toPartialHomeomorph ≫ₕ
(chartAt HB x.proj).prod (PartialHomeomorph.refl F) := by
dsimp only [chartAt_comp, prodChartedSpace_chartAt, FiberBundle.chartedSpace'_chartAt,
chartAt_self_eq]
rw [Trivialization.coe_coe, Trivialization.coe_fst' _ (mem_baseSet_trivializationAt F E x.proj)]
theorem FiberBundle.chartedSpace_chartAt_symm_fst (x : TotalSpace F E) (y : ModelProd HB F)
(hy : y ∈ (chartAt (ModelProd HB F) x).target) :
((chartAt (ModelProd HB F) x).symm y).proj = (chartAt HB x.proj).symm y.1 := by
simp only [FiberBundle.chartedSpace_chartAt, mfld_simps] at hy ⊢
exact (trivializationAt F E x.proj).proj_symm_apply hy.2
end
section
variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup F] [NormedSpace 𝕜 F]
[TopologicalSpace (TotalSpace F E)] [∀ x, TopologicalSpace (E x)] {EB : Type*}
[NormedAddCommGroup EB] [NormedSpace 𝕜 EB] {HB : Type*} [TopologicalSpace HB]
{IB : ModelWithCorners 𝕜 EB HB} (E' : B → Type*) [∀ x, Zero (E' x)] {EM : Type*}
[NormedAddCommGroup EM] [NormedSpace 𝕜 EM] {HM : Type*} [TopologicalSpace HM]
{IM : ModelWithCorners 𝕜 EM HM} [TopologicalSpace M] [ChartedSpace HM M]
variable [TopologicalSpace B] [ChartedSpace HB B] [FiberBundle F E]
protected theorem FiberBundle.extChartAt (x : TotalSpace F E) :
extChartAt (IB.prod 𝓘(𝕜, F)) x =
(trivializationAt F E x.proj).toPartialEquiv ≫
(extChartAt IB x.proj).prod (PartialEquiv.refl F) := by
simp_rw [extChartAt, FiberBundle.chartedSpace_chartAt, extend]
simp only [PartialEquiv.trans_assoc, mfld_simps]
-- Porting note: should not be needed
rw [PartialEquiv.prod_trans, PartialEquiv.refl_trans]
protected theorem FiberBundle.extChartAt_target (x : TotalSpace F E) :
(extChartAt (IB.prod 𝓘(𝕜, F)) x).target =
((extChartAt IB x.proj).target ∩
(extChartAt IB x.proj).symm ⁻¹' (trivializationAt F E x.proj).baseSet) ×ˢ univ := by
rw [FiberBundle.extChartAt, PartialEquiv.trans_target, Trivialization.target_eq, inter_prod]
rfl
theorem FiberBundle.writtenInExtChartAt_trivializationAt {x : TotalSpace F E} {y}
(hy : y ∈ (extChartAt (IB.prod 𝓘(𝕜, F)) x).target) :
writtenInExtChartAt (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) x
(trivializationAt F E x.proj) y = y :=
writtenInExtChartAt_chartAt_comp _ hy
theorem FiberBundle.writtenInExtChartAt_trivializationAt_symm {x : TotalSpace F E} {y}
(hy : y ∈ (extChartAt (IB.prod 𝓘(𝕜, F)) x).target) :
writtenInExtChartAt (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) (trivializationAt F E x.proj x)
(trivializationAt F E x.proj).toPartialHomeomorph.symm y = y :=
writtenInExtChartAt_chartAt_symm_comp _ hy
/-! ### Regularity of maps in/out fiber bundles
Note: For these results we don't need that the bundle is a `C^n` vector bundle, or even a vector
bundle at all, just that it is a fiber bundle over a charted base space.
-/
namespace Bundle
/-- Characterization of `C^n` functions into a vector bundle. -/
theorem contMDiffWithinAt_totalSpace (f : M → TotalSpace F E) {s : Set M} {x₀ : M} :
ContMDiffWithinAt IM (IB.prod 𝓘(𝕜, F)) n f s x₀ ↔
ContMDiffWithinAt IM IB n (fun x => (f x).proj) s x₀ ∧
ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun x ↦ (trivializationAt F E (f x₀).proj (f x)).2) s x₀ := by
simp +singlePass only [contMDiffWithinAt_iff_target]
rw [and_and_and_comm, ← FiberBundle.continuousWithinAt_totalSpace, and_congr_right_iff]
intro hf
simp_rw [modelWithCornersSelf_prod, FiberBundle.extChartAt, Function.comp_def,
PartialEquiv.trans_apply, PartialEquiv.prod_coe, PartialEquiv.refl_coe,
extChartAt_self_apply, modelWithCornersSelf_coe, Function.id_def, ← chartedSpaceSelf_prod]
refine (contMDiffWithinAt_prod_iff _).trans (and_congr ?_ Iff.rfl)
have h1 : (fun x => (f x).proj) ⁻¹' (trivializationAt F E (f x₀).proj).baseSet ∈ 𝓝[s] x₀ :=
((FiberBundle.continuous_proj F E).continuousWithinAt.comp hf (mapsTo_image f s))
((Trivialization.open_baseSet _).mem_nhds (mem_baseSet_trivializationAt F E _))
refine EventuallyEq.contMDiffWithinAt_iff (eventually_of_mem h1 fun x hx => ?_) ?_
· simp_rw [Function.comp, PartialHomeomorph.coe_coe, Trivialization.coe_coe]
rw [Trivialization.coe_fst']
exact hx
· simp only [mfld_simps]
/-- Characterization of `C^n` functions into a vector bundle. -/
theorem contMDiffAt_totalSpace (f : M → TotalSpace F E) (x₀ : M) :
ContMDiffAt IM (IB.prod 𝓘(𝕜, F)) n f x₀ ↔
ContMDiffAt IM IB n (fun x => (f x).proj) x₀ ∧
ContMDiffAt IM 𝓘(𝕜, F) n (fun x => (trivializationAt F E (f x₀).proj (f x)).2) x₀ := by
simp_rw [← contMDiffWithinAt_univ]; exact contMDiffWithinAt_totalSpace f
/-- Characterization of `C^n` sections within a set at a point of a vector bundle. -/
theorem contMDiffWithinAt_section (s : ∀ x, E x) (a : Set B) (x₀ : B) :
ContMDiffWithinAt IB (IB.prod 𝓘(𝕜, F)) n (fun x => TotalSpace.mk' F x (s x)) a x₀ ↔
ContMDiffWithinAt IB 𝓘(𝕜, F) n (fun x ↦ (trivializationAt F E x₀ ⟨x, s x⟩).2) a x₀ := by
simp_rw [contMDiffWithinAt_totalSpace, and_iff_right_iff_imp]; intro; exact contMDiffWithinAt_id
/-- Characterization of `C^n` sections of a vector bundle. -/
theorem contMDiffAt_section (s : ∀ x, E x) (x₀ : B) :
ContMDiffAt IB (IB.prod 𝓘(𝕜, F)) n (fun x => TotalSpace.mk' F x (s x)) x₀ ↔
ContMDiffAt IB 𝓘(𝕜, F) n (fun x ↦ (trivializationAt F E x₀ ⟨x, s x⟩).2) x₀ := by
simp_rw [contMDiffAt_totalSpace, and_iff_right_iff_imp]; intro; exact contMDiffAt_id
variable (E)
theorem contMDiff_proj : ContMDiff (IB.prod 𝓘(𝕜, F)) IB n (π F E) := fun x ↦ by
have : ContMDiffAt (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) n id x := contMDiffAt_id
rw [contMDiffAt_totalSpace] at this
exact this.1
@[deprecated (since := "2024-11-21")] alias smooth_proj := contMDiff_proj
theorem contMDiffOn_proj {s : Set (TotalSpace F E)} :
ContMDiffOn (IB.prod 𝓘(𝕜, F)) IB n (π F E) s :=
(Bundle.contMDiff_proj E).contMDiffOn
@[deprecated (since := "2024-11-21")] alias smoothOn_proj := contMDiffOn_proj
theorem contMDiffAt_proj {p : TotalSpace F E} : ContMDiffAt (IB.prod 𝓘(𝕜, F)) IB n (π F E) p :=
(Bundle.contMDiff_proj E).contMDiffAt
@[deprecated (since := "2024-11-21")] alias smoothAt_proj := contMDiffAt_proj
theorem contMDiffWithinAt_proj {s : Set (TotalSpace F E)} {p : TotalSpace F E} :
ContMDiffWithinAt (IB.prod 𝓘(𝕜, F)) IB n (π F E) s p :=
(Bundle.contMDiffAt_proj E).contMDiffWithinAt
@[deprecated (since := "2024-11-21")] alias smoothWithinAt_proj := contMDiffWithinAt_proj
variable (𝕜) [∀ x, AddCommMonoid (E x)]
variable [∀ x, Module 𝕜 (E x)] [VectorBundle 𝕜 F E]
theorem contMDiff_zeroSection : ContMDiff IB (IB.prod 𝓘(𝕜, F)) n (zeroSection F E) := fun x ↦ by
unfold zeroSection
rw [Bundle.contMDiffAt_section]
apply (contMDiffAt_const (c := 0)).congr_of_eventuallyEq
filter_upwards [(trivializationAt F E x).open_baseSet.mem_nhds
(mem_baseSet_trivializationAt F E x)] with y hy
using congr_arg Prod.snd <| (trivializationAt F E x).zeroSection 𝕜 hy
@[deprecated (since := "2024-11-21")] alias smooth_zeroSection := contMDiff_zeroSection
end Bundle
end
/-! ### `C^n` vector bundles -/
variable [NontriviallyNormedField 𝕜] {EB : Type*} [NormedAddCommGroup EB] [NormedSpace 𝕜 EB]
{HB : Type*} [TopologicalSpace HB] {IB : ModelWithCorners 𝕜 EB HB} [TopologicalSpace B]
[ChartedSpace HB B] {EM : Type*} [NormedAddCommGroup EM]
[NormedSpace 𝕜 EM] {HM : Type*} [TopologicalSpace HM] {IM : ModelWithCorners 𝕜 EM HM}
[TopologicalSpace M] [ChartedSpace HM M]
[∀ x, AddCommMonoid (E x)] [∀ x, Module 𝕜 (E x)] [NormedAddCommGroup F] [NormedSpace 𝕜 F]
section WithTopology
variable [TopologicalSpace (TotalSpace F E)] [∀ x, TopologicalSpace (E x)] (F E)
variable [FiberBundle F E] [VectorBundle 𝕜 F E]
variable (n IB) in
/-- When `B` is a manifold with respect to a model `IB` and `E` is a
topological vector bundle over `B` with fibers isomorphic to `F`,
then `ContMDiffVectorBundle n F E IB` registers that the bundle is `C^n`, in the sense of having
`C^n` transition functions. This is a mixin, not carrying any new data. -/
class ContMDiffVectorBundle : Prop where
protected contMDiffOn_coordChangeL :
∀ (e e' : Trivialization F (π F E)) [MemTrivializationAtlas e] [MemTrivializationAtlas e'],
ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun b : B => (e.coordChangeL 𝕜 e' b : F →L[𝕜] F))
(e.baseSet ∩ e'.baseSet)
@[deprecated (since := "2025-01-09")] alias SmoothVectorBundle := ContMDiffVectorBundle
variable {F E} in
protected theorem ContMDiffVectorBundle.of_le {m n : WithTop ℕ∞} (hmn : m ≤ n)
[h : ContMDiffVectorBundle n F E IB] : ContMDiffVectorBundle m F E IB :=
⟨fun e e' _ _ ↦ (h.contMDiffOn_coordChangeL e e').of_le hmn⟩
instance {a : WithTop ℕ∞} [ContMDiffVectorBundle ∞ F E IB] [h : ENat.LEInfty a] :
ContMDiffVectorBundle a F E IB :=
ContMDiffVectorBundle.of_le h.out
instance {a : WithTop ℕ∞} [ContMDiffVectorBundle ω F E IB] : ContMDiffVectorBundle a F E IB :=
ContMDiffVectorBundle.of_le le_top
instance [ContMDiffVectorBundle 2 F E IB] : ContMDiffVectorBundle 1 F E IB :=
ContMDiffVectorBundle.of_le one_le_two
instance : ContMDiffVectorBundle 0 F E IB := by
constructor
intro e e' he he'
rw [contMDiffOn_zero_iff]
exact VectorBundle.continuousOn_coordChange' e e'
variable [ContMDiffVectorBundle n F E IB]
section ContMDiffCoordChange
variable {F E}
variable (e e' : Trivialization F (π F E)) [MemTrivializationAtlas e] [MemTrivializationAtlas e']
theorem contMDiffOn_coordChangeL :
ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun b : B => (e.coordChangeL 𝕜 e' b : F →L[𝕜] F))
(e.baseSet ∩ e'.baseSet) :=
ContMDiffVectorBundle.contMDiffOn_coordChangeL e e'
theorem contMDiffOn_symm_coordChangeL :
ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun b : B => ((e.coordChangeL 𝕜 e' b).symm : F →L[𝕜] F))
(e.baseSet ∩ e'.baseSet) := by
rw [inter_comm]
refine (ContMDiffVectorBundle.contMDiffOn_coordChangeL e' e).congr fun b hb ↦ ?_
rw [e.symm_coordChangeL e' hb]
@[deprecated (since := "2024-11-21")] alias smoothOn_coordChangeL := contMDiffOn_coordChangeL
@[deprecated (since := "2024-11-21")]
alias smoothOn_symm_coordChangeL := contMDiffOn_symm_coordChangeL
variable {e e'}
theorem contMDiffAt_coordChangeL {x : B} (h : x ∈ e.baseSet) (h' : x ∈ e'.baseSet) :
ContMDiffAt IB 𝓘(𝕜, F →L[𝕜] F) n (fun b : B => (e.coordChangeL 𝕜 e' b : F →L[𝕜] F)) x :=
(contMDiffOn_coordChangeL e e').contMDiffAt <|
(e.open_baseSet.inter e'.open_baseSet).mem_nhds ⟨h, h'⟩
@[deprecated (since := "2024-11-21")] alias smoothAt_coordChangeL := contMDiffAt_coordChangeL
variable {s : Set M} {f : M → B} {g : M → F} {x : M}
protected theorem ContMDiffWithinAt.coordChangeL
(hf : ContMDiffWithinAt IM IB n f s x) (he : f x ∈ e.baseSet) (he' : f x ∈ e'.baseSet) :
ContMDiffWithinAt IM 𝓘(𝕜, F →L[𝕜] F) n (fun y ↦ (e.coordChangeL 𝕜 e' (f y) : F →L[𝕜] F)) s x :=
(contMDiffAt_coordChangeL he he').comp_contMDiffWithinAt _ hf
protected nonrec theorem ContMDiffAt.coordChangeL
(hf : ContMDiffAt IM IB n f x) (he : f x ∈ e.baseSet) (he' : f x ∈ e'.baseSet) :
ContMDiffAt IM 𝓘(𝕜, F →L[𝕜] F) n (fun y ↦ (e.coordChangeL 𝕜 e' (f y) : F →L[𝕜] F)) x :=
hf.coordChangeL he he'
protected theorem ContMDiffOn.coordChangeL
(hf : ContMDiffOn IM IB n f s) (he : MapsTo f s e.baseSet) (he' : MapsTo f s e'.baseSet) :
ContMDiffOn IM 𝓘(𝕜, F →L[𝕜] F) n (fun y ↦ (e.coordChangeL 𝕜 e' (f y) : F →L[𝕜] F)) s :=
fun x hx ↦ (hf x hx).coordChangeL (he hx) (he' hx)
protected theorem ContMDiff.coordChangeL
(hf : ContMDiff IM IB n f) (he : ∀ x, f x ∈ e.baseSet) (he' : ∀ x, f x ∈ e'.baseSet) :
ContMDiff IM 𝓘(𝕜, F →L[𝕜] F) n (fun y ↦ (e.coordChangeL 𝕜 e' (f y) : F →L[𝕜] F)) := fun x ↦
(hf x).coordChangeL (he x) (he' x)
@[deprecated (since := "2024-11-21")]
alias SmoothWithinAt.coordChangeL := ContMDiffWithinAt.coordChangeL
@[deprecated (since := "2024-11-21")]
alias SmoothAt.coordChangeL := ContMDiffAt.coordChangeL
@[deprecated (since := "2024-11-21")]
alias SmoothOn.coordChangeL := ContMDiffOn.coordChangeL
@[deprecated (since := "2024-11-21")]
alias Smooth.coordChangeL := ContMDiff.coordChangeL
protected theorem ContMDiffWithinAt.coordChange
(hf : ContMDiffWithinAt IM IB n f s x) (hg : ContMDiffWithinAt IM 𝓘(𝕜, F) n g s x)
(he : f x ∈ e.baseSet) (he' : f x ∈ e'.baseSet) :
ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun y ↦ e.coordChange e' (f y) (g y)) s x := by
refine ((hf.coordChangeL he he').clm_apply hg).congr_of_eventuallyEq ?_ ?_
· have : e.baseSet ∩ e'.baseSet ∈ 𝓝 (f x) :=
(e.open_baseSet.inter e'.open_baseSet).mem_nhds ⟨he, he'⟩
filter_upwards [hf.continuousWithinAt this] with y hy
exact (Trivialization.coordChangeL_apply' e e' hy (g y)).symm
· exact (Trivialization.coordChangeL_apply' e e' ⟨he, he'⟩ (g x)).symm
protected nonrec theorem ContMDiffAt.coordChange
(hf : ContMDiffAt IM IB n f x) (hg : ContMDiffAt IM 𝓘(𝕜, F) n g x) (he : f x ∈ e.baseSet)
(he' : f x ∈ e'.baseSet) :
ContMDiffAt IM 𝓘(𝕜, F) n (fun y ↦ e.coordChange e' (f y) (g y)) x :=
hf.coordChange hg he he'
protected theorem ContMDiffOn.coordChange (hf : ContMDiffOn IM IB n f s)
(hg : ContMDiffOn IM 𝓘(𝕜, F) n g s) (he : MapsTo f s e.baseSet) (he' : MapsTo f s e'.baseSet) :
ContMDiffOn IM 𝓘(𝕜, F) n (fun y ↦ e.coordChange e' (f y) (g y)) s := fun x hx ↦
(hf x hx).coordChange (hg x hx) (he hx) (he' hx)
protected theorem ContMDiff.coordChange (hf : ContMDiff IM IB n f)
(hg : ContMDiff IM 𝓘(𝕜, F) n g) (he : ∀ x, f x ∈ e.baseSet) (he' : ∀ x, f x ∈ e'.baseSet) :
ContMDiff IM 𝓘(𝕜, F) n (fun y ↦ e.coordChange e' (f y) (g y)) := fun x ↦
(hf x).coordChange (hg x) (he x) (he' x)
@[deprecated (since := "2024-11-21")]
alias SmoothWithinAt.coordChange := ContMDiffWithinAt.coordChange
@[deprecated (since := "2024-11-21")]
alias SmoothAt.coordChange := ContMDiffAt.coordChange
@[deprecated (since := "2024-11-21")]
alias SmoothOn.coordChange := ContMDiffOn.coordChange
@[deprecated (since := "2024-11-21")]
alias Smooth.coordChange := ContMDiff.coordChange
variable (e e')
variable (IB) in
theorem Trivialization.contMDiffOn_symm_trans :
ContMDiffOn (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) n
(e.toPartialHomeomorph.symm ≫ₕ e'.toPartialHomeomorph) (e.target ∩ e'.target) := by
have Hmaps : MapsTo Prod.fst (e.target ∩ e'.target) (e.baseSet ∩ e'.baseSet) := fun x hx ↦
⟨e.mem_target.1 hx.1, e'.mem_target.1 hx.2⟩
rw [mapsTo_inter] at Hmaps
-- TODO: drop `congr` https://github.com/leanprover-community/mathlib4/issues/5473
refine (contMDiffOn_fst.prodMk
(contMDiffOn_fst.coordChange contMDiffOn_snd Hmaps.1 Hmaps.2)).congr ?_
rintro ⟨b, x⟩ hb
refine Prod.ext ?_ rfl
have : (e.toPartialHomeomorph.symm (b, x)).1 ∈ e'.baseSet := by
simp_all only [Trivialization.mem_target, mfld_simps]
exact (e'.coe_fst' this).trans (e.proj_symm_apply hb.1)
variable {e e'}
theorem ContMDiffWithinAt.change_section_trivialization {f : M → TotalSpace F E}
(hp : ContMDiffWithinAt IM IB n (π F E ∘ f) s x)
(hf : ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun y ↦ (e (f y)).2) s x)
(he : f x ∈ e.source) (he' : f x ∈ e'.source) :
| ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun y ↦ (e' (f y)).2) s x := by
rw [Trivialization.mem_source] at he he'
refine (hp.coordChange hf he he').congr_of_eventuallyEq ?_ ?_
· filter_upwards [hp.continuousWithinAt (e.open_baseSet.mem_nhds he)] with y hy
rw [Function.comp_apply, e.coordChange_apply_snd _ hy]
· rw [Function.comp_apply, e.coordChange_apply_snd _ he]
theorem Trivialization.contMDiffWithinAt_snd_comp_iff₂ {f : M → TotalSpace F E}
(hp : ContMDiffWithinAt IM IB n (π F E ∘ f) s x)
(he : f x ∈ e.source) (he' : f x ∈ e'.source) :
ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun y ↦ (e (f y)).2) s x ↔
ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun y ↦ (e' (f y)).2) s x :=
⟨(hp.change_section_trivialization · he he'), (hp.change_section_trivialization · he' he)⟩
| Mathlib/Geometry/Manifold/VectorBundle/Basic.lean | 429 | 442 |
/-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation
/-!
# Recursive computation rules for the Clifford algebra
This file provides API for a special case `CliffordAlgebra.foldr` of the universal property
`CliffordAlgebra.lift` with `A = Module.End R N` for some arbitrary module `N`. This specialization
resembles the `list.foldr` operation, allowing a bilinear map to be "folded" along the generators.
For convenience, this file also provides `CliffordAlgebra.foldl`, implemented via
`CliffordAlgebra.reverse`
## Main definitions
* `CliffordAlgebra.foldr`: a computation rule for building linear maps out of the clifford
algebra starting on the right, analogous to using `list.foldr` on the generators.
* `CliffordAlgebra.foldl`: a computation rule for building linear maps out of the clifford
algebra starting on the left, analogous to using `list.foldl` on the generators.
## Main statements
* `CliffordAlgebra.right_induction`: an induction rule that adds generators from the right.
* `CliffordAlgebra.left_induction`: an induction rule that adds generators from the left.
-/
universe u1 u2 u3
variable {R M N : Type*}
variable [CommRing R] [AddCommGroup M] [AddCommGroup N]
variable [Module R M] [Module R N]
variable (Q : QuadraticForm R M)
namespace CliffordAlgebra
section Foldr
/-- Fold a bilinear map along the generators of a term of the clifford algebra, with the rule
given by `foldr Q f hf n (ι Q m * x) = f m (foldr Q f hf n x)`.
For example, `foldr f hf n (r • ι R u + ι R v * ι R w) = r • f u n + f v (f w n)`. -/
def foldr (f : M →ₗ[R] N →ₗ[R] N) (hf : ∀ m x, f m (f m x) = Q m • x) :
N →ₗ[R] CliffordAlgebra Q →ₗ[R] N :=
(CliffordAlgebra.lift Q ⟨f, fun v => LinearMap.ext <| hf v⟩).toLinearMap.flip
@[simp]
theorem foldr_ι (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (m : M) : foldr Q f hf n (ι Q m) = f m n :=
LinearMap.congr_fun (lift_ι_apply _ _ _) n
@[simp]
theorem foldr_algebraMap (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (r : R) :
foldr Q f hf n (algebraMap R _ r) = r • n :=
LinearMap.congr_fun (AlgHom.commutes _ r) n
@[simp]
theorem foldr_one (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) : foldr Q f hf n 1 = n :=
LinearMap.congr_fun (map_one (lift Q _)) n
@[simp]
theorem foldr_mul (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (a b : CliffordAlgebra Q) :
foldr Q f hf n (a * b) = foldr Q f hf (foldr Q f hf n b) a :=
LinearMap.congr_fun (map_mul (lift Q _) _ _) n
/-- This lemma demonstrates the origin of the `foldr` name. -/
theorem foldr_prod_map_ι (l : List M) (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) :
foldr Q f hf n (l.map <| ι Q).prod = List.foldr (fun m n => f m n) n l := by
induction l with
| nil => rw [List.map_nil, List.prod_nil, List.foldr_nil, foldr_one]
| cons hd tl ih => rw [List.map_cons, List.prod_cons, List.foldr_cons, foldr_mul, foldr_ι, ih]
end Foldr
section Foldl
/-- Fold a bilinear map along the generators of a term of the clifford algebra, with the rule
given by `foldl Q f hf n (ι Q m * x) = f m (foldl Q f hf n x)`.
For example, `foldl f hf n (r • ι R u + ι R v * ι R w) = r • f u n + f v (f w n)`. -/
def foldl (f : M →ₗ[R] N →ₗ[R] N) (hf : ∀ m x, f m (f m x) = Q m • x) :
N →ₗ[R] CliffordAlgebra Q →ₗ[R] N :=
LinearMap.compl₂ (foldr Q f hf) reverse
@[simp]
theorem foldl_reverse (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (x : CliffordAlgebra Q) :
foldl Q f hf n (reverse x) = foldr Q f hf n x :=
DFunLike.congr_arg (foldr Q f hf n) <| reverse_reverse _
@[simp]
theorem foldr_reverse (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (x : CliffordAlgebra Q) :
foldr Q f hf n (reverse x) = foldl Q f hf n x :=
rfl
@[simp]
theorem foldl_ι (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (m : M) : foldl Q f hf n (ι Q m) = f m n := by
rw [← foldr_reverse, reverse_ι, foldr_ι]
@[simp]
theorem foldl_algebraMap (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (r : R) :
foldl Q f hf n (algebraMap R _ r) = r • n := by
rw [← foldr_reverse, reverse.commutes, foldr_algebraMap]
@[simp]
theorem foldl_one (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) : foldl Q f hf n 1 = n := by
rw [← foldr_reverse, reverse.map_one, foldr_one]
@[simp]
theorem foldl_mul (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (a b : CliffordAlgebra Q) :
foldl Q f hf n (a * b) = foldl Q f hf (foldl Q f hf n a) b := by
rw [← foldr_reverse, ← foldr_reverse, ← foldr_reverse, reverse.map_mul, foldr_mul]
/-- This lemma demonstrates the origin of the `foldl` name. -/
theorem foldl_prod_map_ι (l : List M) (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) :
foldl Q f hf n (l.map <| ι Q).prod = List.foldl (fun m n => f n m) n l := by
rw [← foldr_reverse, reverse_prod_map_ι, ← List.map_reverse, foldr_prod_map_ι, List.foldr_reverse]
end Foldl
@[elab_as_elim]
theorem right_induction {P : CliffordAlgebra Q → Prop} (algebraMap : ∀ r : R, P (algebraMap _ _ r))
(add : ∀ x y, P x → P y → P (x + y)) (mul_ι : ∀ m x, P x → P (x * ι Q m)) : ∀ x, P x := by
/- It would be neat if we could prove this via `foldr` like how we prove
`CliffordAlgebra.induction`, but going via the grading seems easier. -/
intro x
have : x ∈ ⊤ := Submodule.mem_top (R := R)
rw [← iSup_ι_range_eq_top] at this
induction this using Submodule.iSup_induction' with
| mem i x hx =>
induction hx using Submodule.pow_induction_on_right' with
| algebraMap r => exact algebraMap r
| add _x _y _i _ _ ihx ihy => exact add _ _ ihx ihy
| mul_mem _i x _hx px m hm =>
obtain ⟨m, rfl⟩ := hm
exact mul_ι _ _ px
| zero => simpa only [map_zero] using algebraMap 0
| add _x _y _ _ ihx ihy =>
exact add _ _ ihx ihy
@[elab_as_elim]
theorem left_induction {P : CliffordAlgebra Q → Prop} (algebraMap : ∀ r : R, P (algebraMap _ _ r))
(add : ∀ x y, P x → P y → P (x + y)) (ι_mul : ∀ x m, P x → P (ι Q m * x)) : ∀ x, P x := by
refine reverse_involutive.surjective.forall.2 ?_
intro x
induction x using CliffordAlgebra.right_induction with
| algebraMap r => simpa only [reverse.commutes] using algebraMap r
| add _ _ hx hy => simpa only [map_add] using add _ _ hx hy
| mul_ι _ _ hx => simpa only [reverse.map_mul, reverse_ι] using ι_mul _ _ hx
/-! ### Versions with extra state -/
/-- Auxiliary definition for `CliffordAlgebra.foldr'` -/
def foldr'Aux (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N) :
M →ₗ[R] Module.End R (CliffordAlgebra Q × N) := by
have v_mul := (Algebra.lmul R (CliffordAlgebra Q)).toLinearMap ∘ₗ ι Q
have l := v_mul.compl₂ (LinearMap.fst _ _ N)
exact
{ toFun := fun m => (l m).prod (f m)
map_add' := fun v₂ v₂ =>
LinearMap.ext fun x =>
Prod.ext (LinearMap.congr_fun (l.map_add _ _) x) (LinearMap.congr_fun (f.map_add _ _) x)
map_smul' := fun c v =>
LinearMap.ext fun x =>
Prod.ext (LinearMap.congr_fun (l.map_smul _ _) x)
(LinearMap.congr_fun (f.map_smul _ _) x) }
theorem foldr'Aux_apply_apply (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N) (m : M) (x_fx) :
foldr'Aux Q f m x_fx = (ι Q m * x_fx.1, f m x_fx) :=
rfl
theorem foldr'Aux_foldr'Aux (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N)
(hf : ∀ m x fx, f m (ι Q m * x, f m (x, fx)) = Q m • fx) (v : M) (x_fx) :
foldr'Aux Q f v (foldr'Aux Q f v x_fx) = Q v • x_fx := by
obtain ⟨x, fx⟩ := x_fx
simp only [foldr'Aux_apply_apply]
rw [← mul_assoc, ι_sq_scalar, ← Algebra.smul_def, hf, Prod.smul_mk]
/-- Fold a bilinear map along the generators of a term of the clifford algebra, with the rule
given by `foldr' Q f hf n (ι Q m * x) = f m (x, foldr' Q f hf n x)`.
Note this is like `CliffordAlgebra.foldr`, but with an extra `x` argument.
Implement the recursion scheme `F[n0](m * x) = f(m, (x, F[n0](x)))`. -/
def foldr' (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N)
(hf : ∀ m x fx, f m (ι Q m * x, f m (x, fx)) = Q m • fx) (n : N) : CliffordAlgebra Q →ₗ[R] N :=
LinearMap.snd _ _ _ ∘ₗ foldr Q (foldr'Aux Q f) (foldr'Aux_foldr'Aux Q _ hf) (1, n)
theorem foldr'_algebraMap (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N)
(hf : ∀ m x fx, f m (ι Q m * x, f m (x, fx)) = Q m • fx) (n r) :
foldr' Q f hf n (algebraMap R _ r) = r • n :=
congr_arg Prod.snd (foldr_algebraMap _ _ _ _ _)
| theorem foldr'_ι (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N)
(hf : ∀ m x fx, f m (ι Q m * x, f m (x, fx)) = Q m • fx) (n m) :
foldr' Q f hf n (ι Q m) = f m (1, n) :=
congr_arg Prod.snd (foldr_ι _ _ _ _ _)
theorem foldr'_ι_mul (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N)
| Mathlib/LinearAlgebra/CliffordAlgebra/Fold.lean | 195 | 200 |
/-
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
theorem rpow_lt_one_of_one_lt_of_neg {x : ℝ≥0} {z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 :=
Real.rpow_lt_one_of_one_lt_of_neg hx hz
theorem rpow_le_one_of_one_le_of_nonpos {x : ℝ≥0} {z : ℝ} (hx : 1 ≤ x) (hz : z ≤ 0) : x ^ z ≤ 1 :=
Real.rpow_le_one_of_one_le_of_nonpos hx hz
theorem one_lt_rpow {x : ℝ≥0} {z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x ^ z :=
Real.one_lt_rpow hx hz
theorem one_le_rpow {x : ℝ≥0} {z : ℝ} (h : 1 ≤ x) (h₁ : 0 ≤ z) : 1 ≤ x ^ z :=
Real.one_le_rpow h h₁
theorem one_lt_rpow_of_pos_of_lt_one_of_neg {x : ℝ≥0} {z : ℝ} (hx1 : 0 < x) (hx2 : x < 1)
(hz : z < 0) : 1 < x ^ z :=
Real.one_lt_rpow_of_pos_of_lt_one_of_neg hx1 hx2 hz
theorem one_le_rpow_of_pos_of_le_one_of_nonpos {x : ℝ≥0} {z : ℝ} (hx1 : 0 < x) (hx2 : x ≤ 1)
(hz : z ≤ 0) : 1 ≤ x ^ z :=
Real.one_le_rpow_of_pos_of_le_one_of_nonpos hx1 hx2 hz
|
theorem rpow_le_self_of_le_one {x : ℝ≥0} {z : ℝ} (hx : x ≤ 1) (h_one_le : 1 ≤ z) : x ^ z ≤ x := by
rcases eq_bot_or_bot_lt x with (rfl | (h : 0 < x))
| Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean | 362 | 364 |
/-
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
| Mathlib/Order/Filter/Basic.lean | 348 | 348 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.