source stringlengths 17 118 | lean4 stringlengths 0 335k |
|---|---|
.lake/packages/mathlib/Mathlib/Algebra/Order/Floor/Semifield.lean | import Mathlib.Algebra.Order.Field.Basic
import Mathlib.Algebra.Order.Floor.Semiring
import Mathlib.Tactic.Linarith
/-!
# Lemmas on `Nat.floor` and `Nat.ceil` for semifields
This file contains basic results on the natural-valued floor and ceiling functions.
## Tags
rounding, floor, ceil
-/
assert_not_exists Finset
open Set
variable {R K : Type*}
namespace Nat
section LinearOrderedSemifield
variable [Semifield K] [LinearOrder K] [IsStrictOrderedRing K] [FloorSemiring K]
-- TODO: should these lemmas be `simp`? `norm_cast`?
theorem floor_div_natCast (a : K) (n : ℕ) : ⌊a / n⌋₊ = ⌊a⌋₊ / n := by
rcases le_total a 0 with ha | ha
· rw [floor_of_nonpos, floor_of_nonpos ha]
· simp
apply div_nonpos_of_nonpos_of_nonneg ha n.cast_nonneg
obtain rfl | hn := n.eq_zero_or_pos
· simp
refine eq_of_forall_le_iff fun m ↦ ?_
rw [Nat.le_div_iff_mul_le hn, le_floor_iff (by positivity), le_floor_iff ha,
le_div_iff₀ (by positivity), cast_mul]
theorem cast_mul_floor_div_cancel {n : ℕ} (hn : n ≠ 0) (a : K) : ⌊n * a⌋₊ / n = ⌊a⌋₊ := by
simpa [hn] using (floor_div_natCast (n * a) n).symm
theorem mul_cast_floor_div_cancel {n : ℕ} (hn : n ≠ 0) (a : K) : ⌊a * n⌋₊ / n = ⌊a⌋₊ := by
rw [mul_comm, cast_mul_floor_div_cancel hn]
theorem floor_div_ofNat (a : K) (n : ℕ) [n.AtLeastTwo] :
⌊a / ofNat(n)⌋₊ = ⌊a⌋₊ / ofNat(n) :=
floor_div_natCast a n
/-- Natural division is the floor of field division. -/
theorem floor_div_eq_div (m n : ℕ) : ⌊(m : K) / n⌋₊ = m / n := by
convert floor_div_natCast (m : K) n
rw [m.floor_natCast]
end LinearOrderedSemifield
section LinearOrderedField
variable [Field K] [LinearOrder K] [IsStrictOrderedRing K] [FloorSemiring K] {a b : K}
lemma mul_lt_floor (hb₀ : 0 < b) (hb : b < 1) (hba : ⌈b / (1 - b)⌉₊ ≤ a) : b * a < ⌊a⌋₊ := by
calc
b * a < b * (⌊a⌋₊ + 1) := by gcongr; apply lt_floor_add_one
_ ≤ ⌊a⌋₊ := by
rw [_root_.mul_add_one, ← le_sub_iff_add_le', ← one_sub_mul, ← div_le_iff₀' (by linarith),
← ceil_le]
exact le_floor hba
lemma ceil_lt_mul (hb : 1 < b) (hba : ⌈(b - 1)⁻¹⌉₊ / b < a) : ⌈a⌉₊ < b * a := by
obtain hab | hba := le_total a (b - 1)⁻¹
· calc
⌈a⌉₊ ≤ (⌈(b - 1)⁻¹⌉₊ : K) := by gcongr
_ < b * a := by rwa [← div_lt_iff₀']; positivity
· rw [← sub_pos] at hb
calc
⌈a⌉₊ < a + 1 := ceil_lt_add_one <| hba.trans' <| by positivity
_ = a + (b - 1) * (b - 1)⁻¹ := by rw [mul_inv_cancel₀]; positivity
_ ≤ a + (b - 1) * a := by gcongr
_ = b * a := by rw [sub_one_mul, add_sub_cancel]
lemma ceil_le_mul (hb : 1 < b) (hba : ⌈(b - 1)⁻¹⌉₊ / b ≤ a) : ⌈a⌉₊ ≤ b * a := by
obtain rfl | hba := hba.eq_or_lt
· rw [mul_div_cancel₀, cast_le, ceil_le]
· exact _root_.div_le_self (by positivity) hb.le
· positivity
· exact (ceil_lt_mul hb hba).le
lemma div_two_lt_floor (ha : 1 ≤ a) : a / 2 < ⌊a⌋₊ := by
rw [div_eq_inv_mul]; refine mul_lt_floor ?_ ?_ ?_ <;> norm_num; assumption
lemma ceil_lt_two_mul (ha : 2⁻¹ < a) : ⌈a⌉₊ < 2 * a :=
ceil_lt_mul one_lt_two (by norm_num at ha ⊢; exact ha)
lemma ceil_le_two_mul (ha : 2⁻¹ ≤ a) : ⌈a⌉₊ ≤ 2 * a :=
ceil_le_mul one_lt_two (by norm_num at ha ⊢; exact ha)
end LinearOrderedField
end Nat
namespace Mathlib.Meta.NormNum
open Qq
/-!
### `norm_num` extension for `Nat.floor`
-/
theorem IsNat.natFloor {R : Type*} [Semiring R] [LinearOrder R] [IsStrictOrderedRing R]
[FloorSemiring R] (r : R) (m : ℕ) : IsNat r m → IsNat (⌊r⌋₊) m := by
rintro ⟨⟨⟩⟩
exact ⟨by simp⟩
theorem IsInt.natFloor {R : Type*} [Ring R] [LinearOrder R] [IsStrictOrderedRing R]
[FloorSemiring R] (r : R) (m : ℕ) : IsInt r (.negOfNat m) → IsNat (⌊r⌋₊) 0 := by
rintro ⟨⟨⟩⟩
exact ⟨Nat.floor_of_nonpos <| by simp⟩
theorem IsNNRat.natFloor {R : Type*} [Semifield R] [LinearOrder R] [IsStrictOrderedRing R]
[FloorSemiring R] (r : R) (n d : ℕ) (h : IsNNRat r n d) (res : ℕ) (hres : n / d = res) :
IsNat ⌊r⌋₊ res := by
constructor
rw [← hres, h.to_eq rfl rfl, Nat.floor_div_eq_div, Nat.cast_id]
theorem IsRat.natFloor {R : Type*} [Field R] [LinearOrder R] [IsStrictOrderedRing R]
[FloorSemiring R] (r : R) (n d : ℕ) (h : IsRat r (Int.negOfNat n) d) : IsNat ⌊r⌋₊ 0 := by
rcases h with ⟨hd, rfl⟩
constructor
rw [Nat.cast_zero, Nat.floor_eq_zero]
exact lt_of_le_of_lt (by simp [mul_nonneg]) one_pos
open Lean in
/-- `norm_num` extension for `Nat.floor` -/
@[norm_num ⌊_⌋₊]
def evalNatFloor : NormNumExt where eval {u αZ} e := do
match u, αZ, e with
| 0, ~q(ℕ), ~q(@Nat.floor $α $instSemiring $instPartialOrder $instFloorSemiring $x) =>
match ← derive x with
| .isBool .. => failure
| .isNat sα nb pb => do
let instLinearOrder ← synthInstanceQ q(LinearOrder $α)
let instIsStrictOrderedRing ← synthInstanceQ q(IsStrictOrderedRing $α)
assertInstancesCommute
return .isNat q(inferInstance) nb q(IsNat.natFloor $x _ $pb)
| .isNegNat sα nb pb => do
let instLinearOrder ← synthInstanceQ q(LinearOrder $α)
let instIsStrictOrderedRing ← synthInstanceQ q(IsStrictOrderedRing $α)
assertInstancesCommute
return .isNat q(inferInstance) (mkRawNatLit 0) q(IsInt.natFloor _ _ $pb)
| .isNNRat dα q n d h => do
let instSemifield ← synthInstanceQ q(Semifield $α)
let instLinearOrder ← synthInstanceQ q(LinearOrder $α)
let instIsStrictOrderedRing ← synthInstanceQ q(IsStrictOrderedRing $α)
assertInstancesCommute
have z : Q(ℕ) := mkRawNatLit (q.num.toNat / q.den)
haveI : $z =Q $n / $d := ⟨⟩
return .isNat q(inferInstance) z q(IsNNRat.natFloor _ $n $d $h $z rfl)
| .isNegNNRat _ q n d h => do
let instField ← synthInstanceQ q(Field $α)
let instLinearOrder ← synthInstanceQ q(LinearOrder $α)
let instIsStrictOrderedRing ← synthInstanceQ q(IsStrictOrderedRing $α)
assertInstancesCommute
return .isNat q(inferInstance) (mkRawNatLit 0) q(IsRat.natFloor $x $n $d $h)
| _, _, _ => failure
end Mathlib.Meta.NormNum |
.lake/packages/mathlib/Mathlib/Algebra/Order/Floor/Defs.lean | import Mathlib.Algebra.Order.Ring.Cast
import Mathlib.Data.Nat.Cast.Basic
import Mathlib.Tactic.HaveI
/-!
# Floor and ceil
We define the natural- and integer-valued floor and ceil functions on linearly ordered rings.
We also provide `positivity` extensions to handle floor and ceil.
## Main definitions
* `FloorSemiring`: An ordered semiring with natural-valued floor and ceil.
* `Nat.floor a`: Greatest natural `n` such that `n ≤ a`. Equal to `0` if `a < 0`.
* `Nat.ceil a`: Least natural `n` such that `a ≤ n`.
* `FloorRing`: A linearly ordered ring with integer-valued floor and ceil.
* `Int.floor a`: Greatest integer `z` such that `z ≤ a`.
* `Int.ceil a`: Least integer `z` such that `a ≤ z`.
* `Int.fract a`: Fractional part of `a`, defined as `a - floor a`.
## Notation
* `⌊a⌋₊` is `Nat.floor a`.
* `⌈a⌉₊` is `Nat.ceil a`.
* `⌊a⌋` is `Int.floor a`.
* `⌈a⌉` is `Int.ceil a`.
The index `₊` in the notations for `Nat.floor` and `Nat.ceil` is used in analogy to the notation
for `nnnorm`.
## TODO
`LinearOrderedRing`/`LinearOrderedSemiring` can be relaxed to `OrderedRing`/`OrderedSemiring` in
many lemmas.
## Tags
rounding, floor, ceil
-/
assert_not_exists Finset
open Set
variable {F α β : Type*}
/-! ### Floor semiring -/
/-- A `FloorSemiring` is an ordered semiring over `α` with a function
`floor : α → ℕ` satisfying `∀ (n : ℕ) (x : α), n ≤ ⌊x⌋ ↔ (n : α) ≤ x)`.
Note that many lemmas require a `LinearOrder`. Please see the above `TODO`. -/
class FloorSemiring (α) [Semiring α] [PartialOrder α] where
/-- `FloorSemiring.floor a` computes the greatest natural `n` such that `(n : α) ≤ a`. -/
floor : α → ℕ
/-- `FloorSemiring.ceil a` computes the least natural `n` such that `a ≤ (n : α)`. -/
ceil : α → ℕ
/-- `FloorSemiring.floor` of a negative element is zero. -/
floor_of_neg {a : α} (ha : a < 0) : floor a = 0
/-- A natural number `n` is smaller than `FloorSemiring.floor a` iff its coercion to `α` is
smaller than `a`. -/
gc_floor {a : α} {n : ℕ} (ha : 0 ≤ a) : n ≤ floor a ↔ (n : α) ≤ a
/-- `FloorSemiring.ceil` is the lower adjoint of the coercion `↑ : ℕ → α`. -/
gc_ceil : GaloisConnection ceil (↑)
instance : FloorSemiring ℕ where
floor := id
ceil := id
floor_of_neg ha := (Nat.not_lt_zero _ ha).elim
gc_floor _ := by
rw [Nat.cast_id, id_def]
gc_ceil n a := by
rw [Nat.cast_id, id_def]
namespace Nat
section OrderedSemiring
variable [Semiring α] [PartialOrder α] [FloorSemiring α] {a : α} {n : ℕ}
/-- `⌊a⌋₊` is the greatest natural `n` such that `n ≤ a`. If `a` is negative, then `⌊a⌋₊ = 0`. -/
def floor : α → ℕ :=
FloorSemiring.floor
/-- `⌈a⌉₊` is the least natural `n` such that `a ≤ n` -/
def ceil : α → ℕ :=
FloorSemiring.ceil
@[simp]
theorem floor_nat : (Nat.floor : ℕ → ℕ) = id :=
rfl
@[simp]
theorem ceil_nat : (Nat.ceil : ℕ → ℕ) = id :=
rfl
@[inherit_doc]
notation "⌊" a "⌋₊" => Nat.floor a
@[inherit_doc]
notation "⌈" a "⌉₊" => Nat.ceil a
theorem le_floor_iff (ha : 0 ≤ a) : n ≤ ⌊a⌋₊ ↔ (n : α) ≤ a :=
FloorSemiring.gc_floor ha
theorem le_floor [IsOrderedRing α] (h : (n : α) ≤ a) : n ≤ ⌊a⌋₊ :=
(le_floor_iff <| n.cast_nonneg.trans h).2 h
theorem gc_ceil_coe : GaloisConnection (ceil : α → ℕ) (↑) :=
FloorSemiring.gc_ceil
@[simp]
theorem ceil_le : ⌈a⌉₊ ≤ n ↔ a ≤ n :=
gc_ceil_coe _ _
end OrderedSemiring
section LinearOrderedSemiring
variable [Semiring α] [LinearOrder α] [FloorSemiring α] {a b : α} {n : ℕ}
theorem lt_ceil : n < ⌈a⌉₊ ↔ (n : α) < a :=
lt_iff_lt_of_le_iff_le ceil_le
@[simp]
theorem ceil_pos : 0 < ⌈a⌉₊ ↔ 0 < a := by rw [lt_ceil, cast_zero]
end LinearOrderedSemiring
end Nat
/-! ### Floor rings -/
/-- A `FloorRing` is a linear ordered ring over `α` with a function
`floor : α → ℤ` satisfying `∀ (z : ℤ) (a : α), z ≤ floor a ↔ (z : α) ≤ a)`.
-/
class FloorRing (α) [Ring α] [LinearOrder α] where
/-- `FloorRing.floor a` computes the greatest integer `z` such that `(z : α) ≤ a`. -/
floor : α → ℤ
/-- `FloorRing.ceil a` computes the least integer `z` such that `a ≤ (z : α)`. -/
ceil : α → ℤ
/-- `FloorRing.ceil` is the upper adjoint of the coercion `↑ : ℤ → α`. -/
gc_coe_floor : GaloisConnection (↑) floor
/-- `FloorRing.ceil` is the lower adjoint of the coercion `↑ : ℤ → α`. -/
gc_ceil_coe : GaloisConnection ceil (↑)
instance : FloorRing ℤ where
floor := id
ceil := id
gc_coe_floor a b := by
rw [Int.cast_id, id_def]
gc_ceil_coe a b := by
rw [Int.cast_id, id_def]
/-- A `FloorRing` constructor from the `floor` function alone. -/
def FloorRing.ofFloor (α) [Ring α] [LinearOrder α] [IsStrictOrderedRing α] (floor : α → ℤ)
(gc_coe_floor : GaloisConnection (↑) floor) : FloorRing α :=
{ floor
ceil := fun a => -floor (-a)
gc_coe_floor
gc_ceil_coe := fun a z => by rw [neg_le, ← gc_coe_floor, Int.cast_neg, neg_le_neg_iff] }
/-- A `FloorRing` constructor from the `ceil` function alone. -/
def FloorRing.ofCeil (α) [Ring α] [LinearOrder α] [IsStrictOrderedRing α] (ceil : α → ℤ)
(gc_ceil_coe : GaloisConnection ceil (↑)) : FloorRing α :=
{ floor := fun a => -ceil (-a)
ceil
gc_coe_floor := fun a z => by rw [le_neg, gc_ceil_coe, Int.cast_neg, neg_le_neg_iff]
gc_ceil_coe }
namespace Int
variable [Ring α] [LinearOrder α] [FloorRing α] {z : ℤ} {a b : α}
/-- `Int.floor a` is the greatest integer `z` such that `z ≤ a`. It is denoted with `⌊a⌋`. -/
def floor : α → ℤ :=
FloorRing.floor
/-- `Int.ceil a` is the smallest integer `z` such that `a ≤ z`. It is denoted with `⌈a⌉`. -/
def ceil : α → ℤ :=
FloorRing.ceil
/-- `Int.fract a` the fractional part of `a`, is `a` minus its floor. -/
def fract (a : α) : α :=
a - floor a
@[simp]
theorem floor_int : (Int.floor : ℤ → ℤ) = id :=
rfl
@[simp]
theorem ceil_int : (Int.ceil : ℤ → ℤ) = id :=
rfl
@[simp]
theorem fract_int : (Int.fract : ℤ → ℤ) = 0 :=
funext fun x => by simp [fract]
@[inherit_doc]
notation "⌊" a "⌋" => Int.floor a
@[inherit_doc]
notation "⌈" a "⌉" => Int.ceil a
-- Mathematical notation for `fract a` is usually `{a}`. Let's not even go there.
@[simp]
theorem floorRing_floor_eq : @FloorRing.floor = @Int.floor :=
rfl
@[simp]
theorem floorRing_ceil_eq : @FloorRing.ceil = @Int.ceil :=
rfl
/-! #### Floor -/
theorem gc_coe_floor : GaloisConnection ((↑) : ℤ → α) floor :=
FloorRing.gc_coe_floor
theorem le_floor : z ≤ ⌊a⌋ ↔ (z : α) ≤ a :=
(gc_coe_floor z a).symm
theorem floor_lt : ⌊a⌋ < z ↔ a < z :=
lt_iff_lt_of_le_iff_le le_floor
@[bound]
theorem floor_le (a : α) : (⌊a⌋ : α) ≤ a :=
gc_coe_floor.l_u_le a
theorem floor_nonneg : 0 ≤ ⌊a⌋ ↔ 0 ≤ a := by rw [le_floor, Int.cast_zero]
@[bound]
theorem floor_nonpos [IsStrictOrderedRing α] (ha : a ≤ 0) : ⌊a⌋ ≤ 0 := by
rw [← @cast_le α, Int.cast_zero]
exact (floor_le a).trans ha
/-! #### Ceil -/
theorem gc_ceil_coe : GaloisConnection ceil ((↑) : ℤ → α) :=
FloorRing.gc_ceil_coe
theorem ceil_le : ⌈a⌉ ≤ z ↔ a ≤ z :=
gc_ceil_coe a z
theorem lt_ceil : z < ⌈a⌉ ↔ (z : α) < a :=
lt_iff_lt_of_le_iff_le ceil_le
@[bound]
theorem le_ceil (a : α) : a ≤ ⌈a⌉ :=
gc_ceil_coe.le_u_l a
@[bound]
theorem ceil_nonneg [IsStrictOrderedRing α] (ha : 0 ≤ a) : 0 ≤ ⌈a⌉ := mod_cast ha.trans (le_ceil a)
@[simp]
theorem ceil_pos : 0 < ⌈a⌉ ↔ 0 < a := by rw [lt_ceil, cast_zero]
end Int
section FloorRingToSemiring
variable [Ring α] [LinearOrder α] [IsStrictOrderedRing α] [FloorRing α]
/-! #### A floor ring as a floor semiring -/
-- see Note [lower instance priority]
instance (priority := 100) FloorRing.toFloorSemiring : FloorSemiring α where
floor a := ⌊a⌋.toNat
ceil a := ⌈a⌉.toNat
floor_of_neg {_} ha := Int.toNat_of_nonpos (Int.floor_nonpos ha.le)
gc_floor {a n} ha := by rw [Int.le_toNat (Int.floor_nonneg.2 ha), Int.le_floor, Int.cast_natCast]
gc_ceil a n := by rw [Int.toNat_le, Int.ceil_le, Int.cast_natCast]
theorem Int.floor_toNat (a : α) : ⌊a⌋.toNat = ⌊a⌋₊ :=
rfl
theorem Int.ceil_toNat (a : α) : ⌈a⌉.toNat = ⌈a⌉₊ :=
rfl
@[simp]
theorem Nat.floor_int : (Nat.floor : ℤ → ℕ) = Int.toNat :=
rfl
@[simp]
theorem Nat.ceil_int : (Nat.ceil : ℤ → ℕ) = Int.toNat :=
rfl
end FloorRingToSemiring |
.lake/packages/mathlib/Mathlib/Algebra/Order/Floor/Semiring.lean | import Mathlib.Algebra.Order.Floor.Defs
import Mathlib.Order.Interval.Set.Defs
/-!
# Lemmas on `Nat.floor` and `Nat.ceil` for semirings
This file contains basic results on the natural-valued floor and ceiling functions.
## TODO
`LinearOrderedSemiring` can be relaxed to `OrderedSemiring` in many lemmas.
## Tags
rounding, floor, ceil
-/
assert_not_exists Finset
open Set
variable {R K : Type*}
namespace Nat
section LinearOrderedSemiring
variable [Semiring R] [LinearOrder R] [FloorSemiring R] {a b : R} {n : ℕ}
section floor
theorem floor_lt (ha : 0 ≤ a) : ⌊a⌋₊ < n ↔ a < n :=
lt_iff_lt_of_le_iff_le <| le_floor_iff ha
theorem floor_lt_one (ha : 0 ≤ a) : ⌊a⌋₊ < 1 ↔ a < 1 :=
(floor_lt ha).trans <| by rw [Nat.cast_one]
theorem floor_le (ha : 0 ≤ a) : (⌊a⌋₊ : R) ≤ a :=
(le_floor_iff ha).1 le_rfl
theorem floor_eq_iff (ha : 0 ≤ a) : ⌊a⌋₊ = n ↔ ↑n ≤ a ∧ a < ↑n + 1 := by
rw [← le_floor_iff ha, ← Nat.cast_one, ← Nat.cast_add, ← floor_lt ha, Nat.lt_add_one_iff,
le_antisymm_iff, and_comm]
variable [IsStrictOrderedRing R]
theorem lt_of_floor_lt (h : ⌊a⌋₊ < n) : a < n :=
lt_of_not_ge fun h' => (le_floor h').not_gt h
theorem lt_one_of_floor_lt_one (h : ⌊a⌋₊ < 1) : a < 1 := mod_cast lt_of_floor_lt h
theorem lt_succ_floor (a : R) : a < ⌊a⌋₊.succ :=
lt_of_floor_lt <| Nat.lt_succ_self _
@[bound]
theorem lt_floor_add_one (a : R) : a < ⌊a⌋₊ + 1 := by simpa using lt_succ_floor a
@[simp]
theorem floor_natCast (n : ℕ) : ⌊(n : R)⌋₊ = n :=
eq_of_forall_le_iff fun a => by
rw [le_floor_iff, Nat.cast_le]
exact n.cast_nonneg
@[simp]
theorem floor_zero : ⌊(0 : R)⌋₊ = 0 := by rw [← Nat.cast_zero, floor_natCast]
@[simp]
theorem floor_one : ⌊(1 : R)⌋₊ = 1 := by rw [← Nat.cast_one, floor_natCast]
@[simp]
theorem floor_ofNat (n : ℕ) [n.AtLeastTwo] : ⌊(ofNat(n) : R)⌋₊ = ofNat(n) :=
Nat.floor_natCast _
theorem floor_of_nonpos (ha : a ≤ 0) : ⌊a⌋₊ = 0 :=
ha.lt_or_eq.elim FloorSemiring.floor_of_neg <| by
rintro rfl
exact floor_zero
@[gcongr]
theorem floor_mono : Monotone (floor : R → ℕ) := fun a b h => by
obtain ha | ha := le_total a 0
· rw [floor_of_nonpos ha]
exact Nat.zero_le _
· exact le_floor ((floor_le ha).trans h)
@[bound] lemma floor_le_floor (hab : a ≤ b) : ⌊a⌋₊ ≤ ⌊b⌋₊ := floor_mono hab
theorem le_floor_iff' (hn : n ≠ 0) : n ≤ ⌊a⌋₊ ↔ (n : R) ≤ a := by
obtain ha | ha := le_total a 0
· rw [floor_of_nonpos ha]
exact
iff_of_false (Nat.pos_of_ne_zero hn).not_ge
(not_le_of_gt <| ha.trans_lt <| cast_pos.2 <| Nat.pos_of_ne_zero hn)
· exact le_floor_iff ha
@[simp]
theorem one_le_floor_iff (x : R) : 1 ≤ ⌊x⌋₊ ↔ 1 ≤ x :=
mod_cast le_floor_iff' one_ne_zero
theorem floor_lt' (hn : n ≠ 0) : ⌊a⌋₊ < n ↔ a < n :=
lt_iff_lt_of_le_iff_le <| le_floor_iff' hn
theorem floor_pos : 0 < ⌊a⌋₊ ↔ 1 ≤ a := by
rw [Nat.lt_iff_add_one_le, zero_add, le_floor_iff' Nat.one_ne_zero, cast_one]
theorem pos_of_floor_pos (h : 0 < ⌊a⌋₊) : 0 < a :=
(le_or_gt a 0).resolve_left fun ha => lt_irrefl 0 <| by rwa [floor_of_nonpos ha] at h
theorem lt_of_lt_floor (h : n < ⌊a⌋₊) : ↑n < a :=
(Nat.cast_lt.2 h).trans_le <| floor_le (pos_of_floor_pos <| (Nat.zero_le n).trans_lt h).le
theorem floor_le_of_le (h : a ≤ n) : ⌊a⌋₊ ≤ n :=
le_imp_le_iff_lt_imp_lt.2 lt_of_lt_floor h
theorem floor_le_one_of_le_one (h : a ≤ 1) : ⌊a⌋₊ ≤ 1 :=
floor_le_of_le <| h.trans_eq <| Nat.cast_one.symm
@[simp]
theorem floor_eq_zero : ⌊a⌋₊ = 0 ↔ a < 1 := by
rw [← lt_one_iff, ← @cast_one R]
exact floor_lt' Nat.one_ne_zero
theorem floor_eq_iff' (hn : n ≠ 0) : ⌊a⌋₊ = n ↔ ↑n ≤ a ∧ a < ↑n + 1 := by
rw [← le_floor_iff' hn, ← Nat.cast_one, ← Nat.cast_add, ← floor_lt' (Nat.add_one_ne_zero n),
Nat.lt_add_one_iff, le_antisymm_iff, and_comm]
theorem floor_eq_on_Ico (n : ℕ) : ∀ a ∈ (Set.Ico n (n + 1) : Set R), ⌊a⌋₊ = n := fun _ ⟨h₀, h₁⟩ =>
(floor_eq_iff <| n.cast_nonneg.trans h₀).mpr ⟨h₀, h₁⟩
theorem floor_eq_on_Ico' (n : ℕ) :
∀ a ∈ (Set.Ico n (n + 1) : Set R), (⌊a⌋₊ : R) = n :=
fun x hx => mod_cast floor_eq_on_Ico n x hx
@[simp]
theorem preimage_floor_zero : (floor : R → ℕ) ⁻¹' {0} = Iio 1 :=
ext fun _ => floor_eq_zero
theorem preimage_floor_of_ne_zero {n : ℕ} (hn : n ≠ 0) :
(floor : R → ℕ) ⁻¹' {n} = Ico (n : R) (n + 1) :=
ext fun _ => floor_eq_iff' hn
end floor
/-! #### Ceil -/
section ceil
theorem add_one_le_ceil_iff : n + 1 ≤ ⌈a⌉₊ ↔ (n : R) < a := by
rw [← Nat.lt_ceil, Nat.add_one_le_iff]
@[simp]
theorem one_le_ceil_iff : 1 ≤ ⌈a⌉₊ ↔ 0 < a := by
rw [← zero_add 1, Nat.add_one_le_ceil_iff, Nat.cast_zero]
@[bound]
theorem le_ceil (a : R) : a ≤ ⌈a⌉₊ :=
ceil_le.1 le_rfl
theorem ceil_mono : Monotone (ceil : R → ℕ) :=
gc_ceil_coe.monotone_l
@[gcongr, bound] lemma ceil_le_ceil (hab : a ≤ b) : ⌈a⌉₊ ≤ ⌈b⌉₊ := ceil_mono hab
@[simp]
theorem ceil_eq_zero : ⌈a⌉₊ = 0 ↔ a ≤ 0 := by rw [← Nat.le_zero, ceil_le, Nat.cast_zero]
theorem ceil_eq_iff (hn : n ≠ 0) : ⌈a⌉₊ = n ↔ ↑(n - 1) < a ∧ a ≤ n := by
rw [← ceil_le, ← not_le, ← ceil_le, not_le,
tsub_lt_iff_right (Nat.add_one_le_iff.2 (pos_iff_ne_zero.2 hn)), Nat.lt_add_one_iff,
le_antisymm_iff, and_comm]
@[simp]
theorem preimage_ceil_zero : (Nat.ceil : R → ℕ) ⁻¹' {0} = Iic 0 :=
ext fun _ => ceil_eq_zero
theorem preimage_ceil_of_ne_zero (hn : n ≠ 0) : (Nat.ceil : R → ℕ) ⁻¹' {n} = Ioc (↑(n - 1) : R) n :=
ext fun _ => ceil_eq_iff hn
variable [IsStrictOrderedRing R]
@[bound]
theorem ceil_le_floor_add_one (a : R) : ⌈a⌉₊ ≤ ⌊a⌋₊ + 1 := by
rw [ceil_le, Nat.cast_add, Nat.cast_one]
exact (lt_floor_add_one a).le
@[simp]
theorem ceil_intCast {R : Type*} [Ring R] [LinearOrder R] [IsStrictOrderedRing R]
[FloorSemiring R] (z : ℤ) :
⌈(z : R)⌉₊ = z.toNat :=
eq_of_forall_ge_iff fun a => by
simp only [ceil_le, Int.toNat_le]
norm_cast
@[simp]
theorem ceil_natCast (n : ℕ) : ⌈(n : R)⌉₊ = n :=
eq_of_forall_ge_iff fun a => by rw [ceil_le, cast_le]
@[simp]
theorem ceil_zero : ⌈(0 : R)⌉₊ = 0 := by rw [← Nat.cast_zero, ceil_natCast]
@[simp]
theorem ceil_one : ⌈(1 : R)⌉₊ = 1 := by rw [← Nat.cast_one, ceil_natCast]
@[simp]
theorem ceil_ofNat (n : ℕ) [n.AtLeastTwo] : ⌈(ofNat(n) : R)⌉₊ = ofNat(n) := ceil_natCast n
theorem lt_of_ceil_lt (h : ⌈a⌉₊ < n) : a < n :=
(le_ceil a).trans_lt (Nat.cast_lt.2 h)
theorem le_of_ceil_le (h : ⌈a⌉₊ ≤ n) : a ≤ n :=
(le_ceil a).trans (Nat.cast_le.2 h)
@[bound]
theorem floor_le_ceil (a : R) : ⌊a⌋₊ ≤ ⌈a⌉₊ := by
obtain ha | ha := le_total a 0
· rw [floor_of_nonpos ha]
exact Nat.zero_le _
· exact cast_le.1 ((floor_le ha).trans <| le_ceil _)
theorem floor_lt_ceil_of_lt_of_pos {a b : R} (h : a < b) (h' : 0 < b) : ⌊a⌋₊ < ⌈b⌉₊ := by
rcases le_or_gt 0 a with (ha | ha)
· rw [floor_lt ha]
exact h.trans_le (le_ceil _)
· rwa [floor_of_nonpos ha.le, lt_ceil, Nat.cast_zero]
end ceil
/-! #### Intervals -/
@[simp]
theorem preimage_Ioo {a b : R} (ha : 0 ≤ a) :
(Nat.cast : ℕ → R) ⁻¹' Set.Ioo a b = Set.Ioo ⌊a⌋₊ ⌈b⌉₊ := by
ext
simp [floor_lt, lt_ceil, ha]
@[simp]
theorem preimage_Ico {a b : R} : (Nat.cast : ℕ → R) ⁻¹' Set.Ico a b = Set.Ico ⌈a⌉₊ ⌈b⌉₊ := by
ext
simp [ceil_le, lt_ceil]
@[simp]
theorem preimage_Ioc {a b : R} (ha : 0 ≤ a) (hb : 0 ≤ b) :
(Nat.cast : ℕ → R) ⁻¹' Set.Ioc a b = Set.Ioc ⌊a⌋₊ ⌊b⌋₊ := by
ext
simp [floor_lt, le_floor_iff, hb, ha]
@[simp]
theorem preimage_Icc {a b : R} (hb : 0 ≤ b) :
(Nat.cast : ℕ → R) ⁻¹' Set.Icc a b = Set.Icc ⌈a⌉₊ ⌊b⌋₊ := by
ext
simp [ceil_le, hb, le_floor_iff]
@[simp]
theorem preimage_Ioi {a : R} (ha : 0 ≤ a) : (Nat.cast : ℕ → R) ⁻¹' Set.Ioi a = Set.Ioi ⌊a⌋₊ := by
ext
simp [floor_lt, ha]
@[simp]
theorem preimage_Ici {a : R} : (Nat.cast : ℕ → R) ⁻¹' Set.Ici a = Set.Ici ⌈a⌉₊ := by
ext
simp [ceil_le]
@[simp]
theorem preimage_Iio {a : R} : (Nat.cast : ℕ → R) ⁻¹' Set.Iio a = Set.Iio ⌈a⌉₊ := by
ext
simp [lt_ceil]
@[simp]
theorem preimage_Iic {a : R} (ha : 0 ≤ a) : (Nat.cast : ℕ → R) ⁻¹' Set.Iic a = Set.Iic ⌊a⌋₊ := by
ext
simp [le_floor_iff, ha]
theorem floor_add_natCast [IsStrictOrderedRing R] (ha : 0 ≤ a) (n : ℕ) : ⌊a + n⌋₊ = ⌊a⌋₊ + n :=
eq_of_forall_le_iff fun b => by
rw [le_floor_iff (add_nonneg ha n.cast_nonneg)]
obtain hb | hb := le_total n b
· obtain ⟨d, rfl⟩ := exists_add_of_le hb
rw [Nat.cast_add, add_comm n, add_comm (n : R), add_le_add_iff_right, add_le_add_iff_right,
le_floor_iff ha]
· obtain ⟨d, rfl⟩ := exists_add_of_le hb
rw [Nat.cast_add, add_left_comm _ b, add_left_comm _ (b : R)]
refine iff_of_true ?_ le_self_add
exact le_add_of_nonneg_right <| ha.trans <| le_add_of_nonneg_right d.cast_nonneg
variable [IsStrictOrderedRing R]
theorem floor_add_one (ha : 0 ≤ a) : ⌊a + 1⌋₊ = ⌊a⌋₊ + 1 := by
rw [← cast_one, floor_add_natCast ha 1]
theorem floor_add_ofNat (ha : 0 ≤ a) (n : ℕ) [n.AtLeastTwo] :
⌊a + ofNat(n)⌋₊ = ⌊a⌋₊ + ofNat(n) :=
floor_add_natCast ha n
@[simp]
theorem floor_sub_natCast [Sub R] [OrderedSub R] [ExistsAddOfLE R] (a : R) (n : ℕ) :
⌊a - n⌋₊ = ⌊a⌋₊ - n := by
obtain ha | ha := le_total a 0
· rw [floor_of_nonpos ha, floor_of_nonpos (tsub_nonpos_of_le (ha.trans n.cast_nonneg)), zero_tsub]
rcases le_total a n with h | h
· rw [floor_of_nonpos (tsub_nonpos_of_le h), eq_comm, tsub_eq_zero_iff_le]
exact Nat.cast_le.1 ((Nat.floor_le ha).trans h)
· rw [eq_tsub_iff_add_eq_of_le (le_floor h), ← floor_add_natCast _, tsub_add_cancel_of_le h]
exact le_tsub_of_add_le_left ((add_zero _).trans_le h)
@[simp]
theorem floor_sub_one [Sub R] [OrderedSub R] [ExistsAddOfLE R] (a : R) : ⌊a - 1⌋₊ = ⌊a⌋₊ - 1 :=
mod_cast floor_sub_natCast a 1
@[simp]
theorem floor_sub_ofNat [Sub R] [OrderedSub R] [ExistsAddOfLE R] (a : R) (n : ℕ) [n.AtLeastTwo] :
⌊a - ofNat(n)⌋₊ = ⌊a⌋₊ - ofNat(n) :=
floor_sub_natCast a n
theorem ceil_add_natCast (ha : 0 ≤ a) (n : ℕ) : ⌈a + n⌉₊ = ⌈a⌉₊ + n :=
eq_of_forall_ge_iff fun b => by
rw [← not_lt, ← not_lt, not_iff_not, lt_ceil]
obtain hb | hb := le_or_gt n b
· obtain ⟨d, rfl⟩ := exists_add_of_le hb
rw [Nat.cast_add, add_comm n, add_comm (n : R), add_lt_add_iff_right, add_lt_add_iff_right,
lt_ceil]
· exact iff_of_true (lt_add_of_nonneg_of_lt ha <| cast_lt.2 hb) (Nat.lt_add_left _ hb)
theorem ceil_add_one (ha : 0 ≤ a) : ⌈a + 1⌉₊ = ⌈a⌉₊ + 1 := by
rw [cast_one.symm, ceil_add_natCast ha 1]
theorem ceil_add_ofNat (ha : 0 ≤ a) (n : ℕ) [n.AtLeastTwo] :
⌈a + ofNat(n)⌉₊ = ⌈a⌉₊ + ofNat(n) :=
ceil_add_natCast ha n
@[bound]
theorem ceil_lt_add_one (ha : 0 ≤ a) : (⌈a⌉₊ : R) < a + 1 :=
lt_ceil.1 <| (Nat.lt_succ_self _).trans_le (ceil_add_one ha).ge
@[bound]
theorem ceil_add_le (a b : R) : ⌈a + b⌉₊ ≤ ⌈a⌉₊ + ⌈b⌉₊ := by
rw [ceil_le, Nat.cast_add]
gcongr <;> apply le_ceil
variable [Sub R] [OrderedSub R] [ExistsAddOfLE R]
@[simp] lemma ceil_sub_natCast (a : R) (n : ℕ) : ⌈a - n⌉₊ = ⌈a⌉₊ - n := by
obtain han | hna := le_total a n
· rwa [ceil_eq_zero.2 (tsub_nonpos_of_le han), eq_comm, tsub_eq_zero_iff_le, Nat.ceil_le]
· refine eq_tsub_of_add_eq ?_
rw [← ceil_add_natCast, tsub_add_cancel_of_le hna]
exact le_tsub_of_add_le_left ((add_zero _).trans_le hna)
@[simp] lemma ceil_sub_one (a : R) : ⌈a - 1⌉₊ = ⌈a⌉₊ - 1 := by simpa using ceil_sub_natCast a 1
@[simp] lemma ceil_sub_ofNat (a : R) (n : ℕ) [n.AtLeastTwo] : ⌈a - ofNat(n)⌉₊ = ⌈a⌉₊ - ofNat(n) :=
ceil_sub_natCast a n
end LinearOrderedSemiring
section LinearOrderedRing
variable [Ring R] [LinearOrder R] [IsStrictOrderedRing R] [FloorSemiring R]
@[bound]
theorem sub_one_lt_floor (a : R) : a - 1 < ⌊a⌋₊ :=
sub_lt_iff_lt_add.2 <| lt_floor_add_one a
lemma abs_sub_floor_le {a : R} (ha : 0 ≤ a) : |a - ⌊a⌋₊| ≤ 1 := by
refine abs_le.mpr ⟨?_, ?_⟩
· simpa using (floor_le ha).trans (le_add_of_nonneg_right zero_le_one)
· simpa [add_comm] using (lt_floor_add_one a).le
lemma abs_floor_sub_le {a : R} (ha : 0 ≤ a) : |⌊a⌋₊ - a| ≤ 1 :=
abs_sub_comm a ⌊a⌋₊ ▸ abs_sub_floor_le ha
lemma abs_sub_ceil_le {a : R} (ha : 0 ≤ a) : |a - ⌈a⌉₊| ≤ 1 := by
refine abs_le.mpr ⟨?_, ?_⟩
· simpa using (ceil_lt_add_one ha).le
· simpa using (le_ceil a).trans (le_add_of_nonneg_left zero_le_one)
lemma abs_ceil_sub_le {a : R} (ha : 0 ≤ a) : |⌈a⌉₊ - a| ≤ 1 :=
abs_sub_comm a ⌈a⌉₊ ▸ abs_sub_ceil_le ha
end LinearOrderedRing
variable [Semiring R] [LinearOrder R] [FloorSemiring R] {a : R}
variable {S : Type*} [Semiring S] [LinearOrder S] [FloorSemiring S] {b : S}
theorem floor_congr [IsStrictOrderedRing R] [IsStrictOrderedRing S]
(h : ∀ n : ℕ, (n : R) ≤ a ↔ (n : S) ≤ b) : ⌊a⌋₊ = ⌊b⌋₊ := by
have h₀ : 0 ≤ a ↔ 0 ≤ b := by simpa only [cast_zero] using h 0
obtain ha | ha := lt_or_ge a 0
· rw [floor_of_nonpos ha.le, floor_of_nonpos (le_of_not_ge <| h₀.not.mp ha.not_ge)]
exact (le_floor <| (h _).1 <| floor_le ha).antisymm (le_floor <| (h _).2 <| floor_le <| h₀.1 ha)
theorem ceil_congr (h : ∀ n : ℕ, a ≤ n ↔ b ≤ n) : ⌈a⌉₊ = ⌈b⌉₊ :=
(ceil_le.2 <| (h _).2 <| le_ceil _).antisymm <| ceil_le.2 <| (h _).1 <| le_ceil _
variable {F : Type*} [FunLike F R S] [RingHomClass F R S]
theorem map_floor [IsStrictOrderedRing R] [IsStrictOrderedRing S]
(f : F) (hf : StrictMono f) (a : R) : ⌊f a⌋₊ = ⌊a⌋₊ :=
floor_congr fun n => by rw [← map_natCast f, hf.le_iff_le]
theorem map_ceil (f : F) (hf : StrictMono f) (a : R) : ⌈f a⌉₊ = ⌈a⌉₊ :=
ceil_congr fun n => by rw [← map_natCast f, hf.le_iff_le]
end Nat
/-- There exists at most one `FloorSemiring` structure on a linear ordered semiring. -/
theorem subsingleton_floorSemiring {R} [Semiring R] [LinearOrder R] :
Subsingleton (FloorSemiring R) := by
refine ⟨fun H₁ H₂ => ?_⟩
have : H₁.ceil = H₂.ceil := funext fun a => (H₁.gc_ceil.l_unique H₂.gc_ceil) fun n => rfl
have : H₁.floor = H₂.floor := by
ext a
rcases lt_or_ge a 0 with h | h
· rw [H₁.floor_of_neg, H₂.floor_of_neg] <;> exact h
· refine eq_of_forall_le_iff fun n => ?_
rw [H₁.gc_floor, H₂.gc_floor] <;> exact h
cases H₁
cases H₂
congr |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/WithTop.lean | import Mathlib.Algebra.Order.GroupWithZero.Synonym
import Mathlib.Algebra.Order.Ring.Canonical
import Mathlib.Algebra.Ring.Hom.Defs
import Mathlib.Algebra.Order.Monoid.WithTop
/-! # Structures involving `*` and `0` on `WithTop` and `WithBot`
The main results of this section are `WithTop.instOrderedCommSemiring` and
`WithBot.instOrderedCommSemiring`.
-/
variable {α : Type*}
namespace WithTop
variable [DecidableEq α]
section MulZeroClass
variable [MulZeroClass α] {a b : WithTop α}
instance instMulZeroClass : MulZeroClass (WithTop α) where
mul
| (a : α), (b : α) => ↑(a * b)
| (a : α), ⊤ => if a = 0 then 0 else ⊤
| ⊤, (b : α) => if b = 0 then 0 else ⊤
| ⊤, ⊤ => ⊤
mul_zero
| (a : α) => congr_arg some <| mul_zero _
| ⊤ => if_pos rfl
zero_mul
| (b : α) => congr_arg some <| zero_mul _
| ⊤ => if_pos rfl
@[simp, norm_cast] lemma coe_mul (a b : α) : (↑(a * b) : WithTop α) = a * b := rfl
lemma mul_top' : ∀ (a : WithTop α), a * ⊤ = if a = 0 then 0 else ⊤
| (a : α) => if_congr coe_eq_zero.symm rfl rfl
| ⊤ => (if_neg top_ne_zero).symm
@[simp] lemma mul_top (h : a ≠ 0) : a * ⊤ = ⊤ := by rw [mul_top', if_neg h]
lemma top_mul' : ∀ (b : WithTop α), ⊤ * b = if b = 0 then 0 else ⊤
| (b : α) => if_congr coe_eq_zero.symm rfl rfl
| ⊤ => (if_neg top_ne_zero).symm
@[simp] lemma top_mul (hb : b ≠ 0) : ⊤ * b = ⊤ := by rw [top_mul', if_neg hb]
@[simp] lemma top_mul_top : (⊤ * ⊤ : WithTop α) = ⊤ := rfl
lemma mul_def (a b : WithTop α) :
a * b = if a = 0 ∨ b = 0 then 0 else WithTop.map₂ (· * ·) a b := by
cases a <;> cases b <;> aesop
lemma mul_eq_top_iff : a * b = ⊤ ↔ a ≠ 0 ∧ b = ⊤ ∨ a = ⊤ ∧ b ≠ 0 := by rw [mul_def]; aesop
lemma mul_coe_eq_bind {b : α} (hb : b ≠ 0) : ∀ a, (a * b : WithTop α) = a.bind fun a ↦ ↑(a * b)
| ⊤ => by simp [top_mul, hb]; rfl
| (a : α) => rfl
lemma coe_mul_eq_bind {a : α} (ha : a ≠ 0) : ∀ b, (a * b : WithTop α) = b.bind fun b ↦ ↑(a * b)
| ⊤ => by simp [ha]; rfl
| (b : α) => rfl
@[simp]
lemma untopD_zero_mul (a b : WithTop α) : (a * b).untopD 0 = a.untopD 0 * b.untopD 0 := by
by_cases ha : a = 0; · rw [ha, zero_mul, ← coe_zero, untopD_coe, zero_mul]
by_cases hb : b = 0; · rw [hb, mul_zero, ← coe_zero, untopD_coe, mul_zero]
cases a; · rw [top_mul hb, untopD_top, zero_mul]
cases b; · rw [mul_top ha, untopD_top, mul_zero]
rw [← coe_mul, untopD_coe, untopD_coe, untopD_coe]
theorem mul_ne_top {a b : WithTop α} (ha : a ≠ ⊤) (hb : b ≠ ⊤) : a * b ≠ ⊤ := by
simp [mul_eq_top_iff, *]
theorem mul_lt_top [LT α] {a b : WithTop α} (ha : a < ⊤) (hb : b < ⊤) : a * b < ⊤ := by
rw [WithTop.lt_top_iff_ne_top] at *
exact mul_ne_top ha hb
instance instNoZeroDivisors [NoZeroDivisors α] : NoZeroDivisors (WithTop α) := by
refine ⟨fun h₁ => Decidable.byContradiction fun h₂ => ?_⟩
rw [mul_def, if_neg h₂] at h₁
rcases Option.mem_map₂_iff.1 h₁ with ⟨a, b, (rfl : _ = _), (rfl : _ = _), hab⟩
exact h₂ ((eq_zero_or_eq_zero_of_mul_eq_zero hab).imp (congr_arg some) (congr_arg some))
variable [Preorder α]
protected lemma mul_right_strictMono [PosMulStrictMono α] (h₀ : 0 < a) (hinf : a ≠ ⊤) :
StrictMono (a * ·) := by
lift a to α using hinf
rintro b c hbc
lift b to α using hbc.ne_top
match c with
| ⊤ => simp [← coe_mul, mul_top h₀.ne']
| (c : α) =>
simp only [coe_pos, coe_lt_coe, ← coe_mul, gt_iff_lt] at *
exact mul_lt_mul_of_pos_left hbc h₀
protected lemma mul_left_strictMono [MulPosStrictMono α] (h₀ : 0 < a) (hinf : a ≠ ⊤) :
StrictMono (· * a) := by
lift a to α using hinf
rintro b c hbc
lift b to α using hbc.ne_top
match c with
| ⊤ => simp [← coe_mul, top_mul h₀.ne']
| (c : α) =>
simp only [coe_pos, coe_lt_coe, ← coe_mul, gt_iff_lt] at *
exact mul_lt_mul_of_pos_right hbc h₀
end MulZeroClass
/-- `Nontrivial α` is needed here as otherwise we have `1 * ⊤ = ⊤` but also `0 * ⊤ = 0`. -/
instance instMulZeroOneClass [MulZeroOneClass α] [Nontrivial α] : MulZeroOneClass (WithTop α) where
__ := instMulZeroClass
one_mul
| ⊤ => mul_top (mt coe_eq_coe.1 one_ne_zero)
| (a : α) => by rw [← coe_one, ← coe_mul, one_mul]
mul_one
| ⊤ => top_mul (mt coe_eq_coe.1 one_ne_zero)
| (a : α) => by rw [← coe_one, ← coe_mul, mul_one]
/-- A version of `WithTop.map` for `MonoidWithZeroHom`s. -/
@[simps -fullyApplied]
protected def _root_.MonoidWithZeroHom.withTopMap {R S : Type*} [MulZeroOneClass R] [DecidableEq R]
[Nontrivial R] [MulZeroOneClass S] [DecidableEq S] [Nontrivial S] (f : R →*₀ S)
(hf : Function.Injective f) : WithTop R →*₀ WithTop S :=
{ f.toZeroHom.withTopMap, f.toMonoidHom.toOneHom.withTopMap with
toFun := WithTop.map f
map_mul' := fun x y => by
have : ∀ z, map f z = 0 ↔ z = 0 := fun z =>
(Option.map_injective hf).eq_iff' f.toZeroHom.withTopMap.map_zero
rcases Decidable.eq_or_ne x 0 with (rfl | hx)
· simp
rcases Decidable.eq_or_ne y 0 with (rfl | hy)
· simp
cases x with | top => simp [hy, this] | coe x => ?_
cases y with
| top =>
have : (f x : WithTop S) ≠ 0 := by simpa [hf.eq_iff' (map_zero f)] using hx
simp [mul_top hx, mul_top this]
| coe y => simp [← coe_mul] }
instance instSemigroupWithZero [SemigroupWithZero α] [NoZeroDivisors α] :
SemigroupWithZero (WithTop α) where
__ := instMulZeroClass
mul_assoc a b c := by
rcases eq_or_ne a 0 with (rfl | ha); · simp only [zero_mul]
rcases eq_or_ne b 0 with (rfl | hb); · simp only [zero_mul, mul_zero]
rcases eq_or_ne c 0 with (rfl | hc); · simp only [mul_zero]
cases a with | top => simp [hb, hc] | coe a => ?_
cases b with | top => simp [mul_top ha, top_mul hc] | coe b => ?_
cases c with
| top =>
rw [mul_top hb, mul_top ha]
rw [← coe_zero, ne_eq, coe_eq_coe] at ha hb
simp [ha, hb]
| coe c => simp only [← coe_mul, mul_assoc]
section MonoidWithZero
variable [MonoidWithZero α] [NoZeroDivisors α] [Nontrivial α] {x : WithTop α} {n : ℕ}
instance instMonoidWithZero : MonoidWithZero (WithTop α) where
__ := instMulZeroOneClass
__ := instSemigroupWithZero
npow n a := match a, n with
| (a : α), n => ↑(a ^ n)
| ⊤, 0 => 1
| ⊤, _n + 1 => ⊤
npow_zero a := by cases a <;> simp
npow_succ n a := by cases n <;> cases a <;> simp [pow_succ]
@[simp, norm_cast] lemma coe_pow (a : α) (n : ℕ) : (↑(a ^ n) : WithTop α) = a ^ n := rfl
@[simp] lemma top_pow : ∀ {n : ℕ}, n ≠ 0 → (⊤ : WithTop α) ^ n = ⊤ | _ + 1, _ => rfl
@[simp] lemma pow_eq_top_iff : x ^ n = ⊤ ↔ x = ⊤ ∧ n ≠ 0 := by
cases x <;> cases n <;> simp [← coe_pow]
lemma pow_ne_top_iff : x ^ n ≠ ⊤ ↔ x ≠ ⊤ ∨ n = 0 := by simp [pow_eq_top_iff, or_iff_not_imp_left]
@[simp] lemma pow_lt_top_iff [Preorder α] : x ^ n < ⊤ ↔ x < ⊤ ∨ n = 0 := by
simp_rw [WithTop.lt_top_iff_ne_top, pow_ne_top_iff]
lemma eq_top_of_pow (n : ℕ) (hx : x ^ n = ⊤) : x = ⊤ := (pow_eq_top_iff.1 hx).1
lemma pow_ne_top (hx : x ≠ ⊤) : x ^ n ≠ ⊤ := pow_ne_top_iff.2 <| .inl hx
lemma pow_lt_top [Preorder α] (hx : x < ⊤) : x ^ n < ⊤ := pow_lt_top_iff.2 <| .inl hx
end MonoidWithZero
instance instCommMonoidWithZero [CommMonoidWithZero α] [NoZeroDivisors α] [Nontrivial α] :
CommMonoidWithZero (WithTop α) where
__ := instMonoidWithZero
mul_comm a b := by simp_rw [mul_def]; exact if_congr or_comm rfl (Option.map₂_comm mul_comm)
instance instNonUnitalNonAssocSemiring [NonUnitalNonAssocSemiring α] [PartialOrder α]
[CanonicallyOrderedAdd α] : NonUnitalNonAssocSemiring (WithTop α) where
toAddCommMonoid := WithTop.addCommMonoid
__ := WithTop.instMulZeroClass
right_distrib a b c := by
cases c with
| top => by_cases ha : a = 0 <;> simp [ha]
| coe c =>
by_cases hc : c = 0; · simp [hc]
simp only [mul_coe_eq_bind hc]
cases a <;> cases b <;> try rfl
exact congr_arg some (add_mul _ _ _)
left_distrib c a b := by
cases c with
| top => by_cases ha : a = 0 <;> simp [ha]
| coe c =>
by_cases hc : c = 0; · simp [hc]
simp only [coe_mul_eq_bind hc]
cases a <;> cases b <;> try rfl
exact congr_arg some (mul_add _ _ _)
instance instNonAssocSemiring [NonAssocSemiring α] [PartialOrder α] [CanonicallyOrderedAdd α]
[Nontrivial α] : NonAssocSemiring (WithTop α) where
toNonUnitalNonAssocSemiring := instNonUnitalNonAssocSemiring
__ := WithTop.instMulZeroOneClass
__ := WithTop.addCommMonoidWithOne
instance instNonUnitalSemiring [NonUnitalSemiring α] [PartialOrder α] [CanonicallyOrderedAdd α]
[NoZeroDivisors α] : NonUnitalSemiring (WithTop α) where
toNonUnitalNonAssocSemiring := WithTop.instNonUnitalNonAssocSemiring
__ := WithTop.instSemigroupWithZero
instance instSemiring [Semiring α] [PartialOrder α] [CanonicallyOrderedAdd α]
[NoZeroDivisors α] [Nontrivial α] : Semiring (WithTop α) where
toNonUnitalSemiring := WithTop.instNonUnitalSemiring
__ := WithTop.instMonoidWithZero
__ := WithTop.addCommMonoidWithOne
instance instCommSemiring [CommSemiring α] [PartialOrder α] [CanonicallyOrderedAdd α]
[NoZeroDivisors α] [Nontrivial α] : CommSemiring (WithTop α) where
toSemiring := WithTop.instSemiring
__ := WithTop.instCommMonoidWithZero
instance instIsOrderedRing [CommSemiring α] [PartialOrder α] [CanonicallyOrderedAdd α]
[NoZeroDivisors α] [Nontrivial α] : IsOrderedRing (WithTop α) :=
CanonicallyOrderedAdd.toIsOrderedRing
/-- A version of `WithTop.map` for `RingHom`s. -/
@[simps -fullyApplied]
protected def _root_.RingHom.withTopMap {R S : Type*}
[NonAssocSemiring R] [PartialOrder R] [CanonicallyOrderedAdd R]
[DecidableEq R] [Nontrivial R]
[NonAssocSemiring S] [PartialOrder S] [CanonicallyOrderedAdd S]
[DecidableEq S] [Nontrivial S]
(f : R →+* S) (hf : Function.Injective f) : WithTop R →+* WithTop S :=
{MonoidWithZeroHom.withTopMap f.toMonoidWithZeroHom hf, f.toAddMonoidHom.withTopMap with}
variable [CommSemiring α] [PartialOrder α] [OrderBot α]
[CanonicallyOrderedAdd α] [PosMulStrictMono α]
{a a₁ a₂ b₁ b₂ : WithTop α}
@[gcongr]
protected lemma mul_lt_mul (ha : a₁ < a₂) (hb : b₁ < b₂) : a₁ * b₁ < a₂ * b₂ := by
have := posMulStrictMono_iff_mulPosStrictMono.1 ‹_›
lift a₁ to α using ha.lt_top.ne
lift b₁ to α using hb.lt_top.ne
obtain rfl | ha₂ := eq_or_ne a₂ ⊤
· rw [top_mul (by simpa [bot_eq_zero] using hb.bot_lt.ne')]
exact coe_lt_top _
obtain rfl | hb₂ := eq_or_ne b₂ ⊤
· rw [mul_top (by simpa [bot_eq_zero] using ha.bot_lt.ne')]
exact coe_lt_top _
lift a₂ to α using ha₂
lift b₂ to α using hb₂
norm_cast at *
obtain rfl | hb₁ := eq_zero_or_pos b₁
· rw [mul_zero]
exact mul_pos (by simpa [bot_eq_zero] using ha.bot_lt) hb
· exact mul_lt_mul ha hb.le hb₁ (zero_le _)
variable [NoZeroDivisors α] [Nontrivial α] {a b : WithTop α}
protected lemma pow_right_strictMono : ∀ {n : ℕ}, n ≠ 0 → StrictMono fun a : WithTop α ↦ a ^ n
| 0, h => absurd rfl h
| 1, _ => by simpa only [pow_one] using strictMono_id
| n + 2, _ => fun x y h ↦ by
simp_rw [pow_succ _ (n + 1)]
exact WithTop.mul_lt_mul (WithTop.pow_right_strictMono n.succ_ne_zero h) h
@[gcongr] protected lemma pow_lt_pow_left (hab : a < b) {n : ℕ} (hn : n ≠ 0) : a ^ n < b ^ n :=
WithTop.pow_right_strictMono hn hab
end WithTop
namespace WithBot
variable [DecidableEq α]
section MulZeroClass
variable [MulZeroClass α] {a b : WithBot α}
instance : MulZeroClass (WithBot α) := WithTop.instMulZeroClass
@[simp, norm_cast] lemma coe_mul (a b : α) : (↑(a * b) : WithBot α) = a * b := rfl
lemma mul_bot' : ∀ (a : WithBot α), a * ⊥ = if a = 0 then 0 else ⊥
| (a : α) => if_congr coe_eq_zero.symm rfl rfl
| ⊥ => (if_neg bot_ne_zero).symm
@[simp] lemma mul_bot (h : a ≠ 0) : a * ⊥ = ⊥ := by rw [mul_bot', if_neg h]
lemma bot_mul' : ∀ (b : WithBot α), ⊥ * b = if b = 0 then 0 else ⊥
| (b : α) => if_congr coe_eq_zero.symm rfl rfl
| ⊥ => (if_neg bot_ne_zero).symm
@[simp] lemma bot_mul (hb : b ≠ 0) : ⊥ * b = ⊥ := by rw [bot_mul', if_neg hb]
@[simp] lemma bot_mul_bot : (⊥ * ⊥ : WithBot α) = ⊥ := rfl
lemma mul_def (a b : WithBot α) :
a * b = if a = 0 ∨ b = 0 then 0 else WithBot.map₂ (· * ·) a b := by
cases a <;> cases b <;> aesop
lemma mul_eq_bot_iff : a * b = ⊥ ↔ a ≠ 0 ∧ b = ⊥ ∨ a = ⊥ ∧ b ≠ 0 := by rw [mul_def]; aesop
lemma mul_coe_eq_bind {b : α} (hb : b ≠ 0) : ∀ a, (a * b : WithBot α) = a.bind fun a ↦ ↑(a * b)
| ⊥ => by simp only [ne_eq, coe_eq_zero, hb, not_false_eq_true, bot_mul]; rfl
| (a : α) => rfl
lemma coe_mul_eq_bind {a : α} (ha : a ≠ 0) : ∀ b, (a * b : WithBot α) = b.bind fun b ↦ ↑(a * b)
| ⊥ => by simp only [ne_eq, coe_eq_zero, ha, not_false_eq_true, mul_bot]; rfl
| (b : α) => rfl
@[simp]
lemma unbotD_zero_mul (a b : WithBot α) : (a * b).unbotD 0 = a.unbotD 0 * b.unbotD 0 := by
by_cases ha : a = 0; · rw [ha, zero_mul, ← coe_zero, unbotD_coe, zero_mul]
by_cases hb : b = 0; · rw [hb, mul_zero, ← coe_zero, unbotD_coe, mul_zero]
cases a; · rw [bot_mul hb, unbotD_bot, zero_mul]
cases b; · rw [mul_bot ha, unbotD_bot, mul_zero]
rw [← coe_mul, unbotD_coe, unbotD_coe, unbotD_coe]
theorem mul_ne_bot {a b : WithBot α} (ha : a ≠ ⊥) (hb : b ≠ ⊥) : a * b ≠ ⊥ :=
WithTop.mul_ne_top (α := αᵒᵈ) ha hb
theorem bot_lt_mul [LT α] {a b : WithBot α} (ha : ⊥ < a) (hb : ⊥ < b) : ⊥ < a * b :=
WithTop.mul_lt_top (α := αᵒᵈ) ha hb
instance instNoZeroDivisors [NoZeroDivisors α] : NoZeroDivisors (WithBot α) :=
WithTop.instNoZeroDivisors
end MulZeroClass
/-- `Nontrivial α` is needed here as otherwise we have `1 * ⊥ = ⊥` but also `= 0 * ⊥ = 0`. -/
instance instMulZeroOneClass [MulZeroOneClass α] [Nontrivial α] : MulZeroOneClass (WithBot α) :=
WithTop.instMulZeroOneClass
instance instSemigroupWithZero [SemigroupWithZero α] [NoZeroDivisors α] :
SemigroupWithZero (WithBot α) := WithTop.instSemigroupWithZero
section MonoidWithZero
variable [MonoidWithZero α] [NoZeroDivisors α] [Nontrivial α]
instance instMonoidWithZero : MonoidWithZero (WithBot α) := WithTop.instMonoidWithZero
@[simp, norm_cast] lemma coe_pow (a : α) (n : ℕ) : (↑(a ^ n) : WithBot α) = a ^ n := rfl
end MonoidWithZero
instance instCommMonoidWithZero [CommMonoidWithZero α] [NoZeroDivisors α] [Nontrivial α] :
CommMonoidWithZero (WithBot α) :=
WithTop.instCommMonoidWithZero
instance instCommSemiring [CommSemiring α] [PartialOrder α] [CanonicallyOrderedAdd α]
[NoZeroDivisors α] [Nontrivial α] :
CommSemiring (WithBot α) :=
WithTop.instCommSemiring
instance [MulZeroClass α] [Preorder α] [PosMulMono α] : PosMulMono (WithBot α) where
mul_le_mul_of_nonneg_left x x0 a b h := by
rcases eq_or_ne x 0 with rfl | x0'
· simp
lift x to α
· rintro rfl
exact (WithBot.bot_lt_coe (0 : α)).not_ge x0
cases a
· simp_rw [mul_bot x0', bot_le]
cases b
· exact absurd h (bot_lt_coe _).not_ge
simp only [← coe_mul, coe_le_coe] at *
norm_cast at x0
exact mul_le_mul_of_nonneg_left h x0
instance [MulZeroClass α] [Preorder α] [MulPosMono α] : MulPosMono (WithBot α) where
mul_le_mul_of_nonneg_right x x0 a b h := by
rcases eq_or_ne x 0 with rfl | x0'
· simp
lift x to α
· rintro rfl
exact (WithBot.bot_lt_coe (0 : α)).not_ge x0
cases a
· simp_rw [bot_mul x0', bot_le]
cases b
· exact absurd h (bot_lt_coe _).not_ge
simp only [← coe_mul, coe_le_coe] at *
norm_cast at x0
exact mul_le_mul_of_nonneg_right h x0
instance [MulZeroClass α] [Preorder α] [PosMulStrictMono α] : PosMulStrictMono (WithBot α) where
mul_lt_mul_of_pos_left x x0 a b h := by
lift x to α using x0.ne_bot
cases b
· exact absurd h not_lt_bot
cases a
· simp_rw [mul_bot x0.ne.symm, ← coe_mul, bot_lt_coe]
simp only [← coe_mul, coe_lt_coe] at *
norm_cast at x0
exact mul_lt_mul_of_pos_left h x0
instance [MulZeroClass α] [Preorder α] [MulPosStrictMono α] : MulPosStrictMono (WithBot α) where
mul_lt_mul_of_pos_right x x0 a b h := by
lift x to α using x0.ne_bot
cases b
· exact absurd h not_lt_bot
cases a
· simp_rw [bot_mul x0.ne.symm, ← coe_mul, bot_lt_coe]
simp only [← coe_mul, coe_lt_coe] at *
norm_cast at x0
exact mul_lt_mul_of_pos_right h x0
instance [MulZeroClass α] [Preorder α] [PosMulReflectLT α] : PosMulReflectLT (WithBot α) where
elim := by
intro ⟨x, x0⟩ a b h
simp only at h
rcases eq_or_ne x 0 with rfl | x0'
· simp at h
lift x to α
· rintro rfl
exact (WithBot.bot_lt_coe (0 : α)).not_ge x0
cases b
· rw [mul_bot x0'] at h
exact absurd h bot_le.not_gt
cases a
· exact WithBot.bot_lt_coe _
simp only [← coe_mul, coe_lt_coe] at *
norm_cast at x0
exact lt_of_mul_lt_mul_left h x0
instance [MulZeroClass α] [Preorder α] [MulPosReflectLT α] : MulPosReflectLT (WithBot α) where
elim := by
intro ⟨x, x0⟩ a b h
simp only at h
rcases eq_or_ne x 0 with rfl | x0'
· simp at h
lift x to α
· rintro rfl
exact (WithBot.bot_lt_coe (0 : α)).not_ge x0
cases b
· rw [bot_mul x0'] at h
exact absurd h bot_le.not_gt
cases a
· exact WithBot.bot_lt_coe _
simp only [← coe_mul, coe_lt_coe] at *
norm_cast at x0
exact lt_of_mul_lt_mul_right h x0
instance [MulZeroClass α] [Preorder α] [PosMulReflectLE α] : PosMulReflectLE (WithBot α) where
elim := by
intro ⟨x, x0⟩ a b h
simp only at h
lift x to α using x0.ne_bot
cases a
· exact bot_le
cases b
· rw [mul_bot x0.ne.symm, ← coe_mul] at h
exact absurd h (bot_lt_coe _).not_ge
simp only [← coe_mul, coe_le_coe] at *
norm_cast at x0
exact le_of_mul_le_mul_left h x0
instance [MulZeroClass α] [Preorder α] [MulPosReflectLE α] : MulPosReflectLE (WithBot α) where
elim := by
intro ⟨x, x0⟩ a b h
simp only at h
lift x to α using x0.ne_bot
cases a
· exact bot_le
cases b
· rw [bot_mul x0.ne.symm, ← coe_mul] at h
exact absurd h (bot_lt_coe _).not_ge
simp only [← coe_mul, coe_le_coe] at *
norm_cast at x0
exact le_of_mul_le_mul_right h x0
instance instIsOrderedRing [CommSemiring α] [PartialOrder α] [IsOrderedRing α]
[CanonicallyOrderedAdd α] [NoZeroDivisors α] [Nontrivial α] :
IsOrderedRing (WithBot α) where
end WithBot |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Synonym.lean | import Mathlib.Algebra.Order.Group.Synonym
import Mathlib.Algebra.Ring.Defs
/-!
# Ring structure on the order type synonyms
Transfer algebraic instances from `R` to `Rᵒᵈ` and `Lex R`.
-/
variable {R : Type*}
/-! ### Order dual -/
instance [h : Distrib R] : Distrib Rᵒᵈ := h
instance [Mul R] [Add R] [h : LeftDistribClass R] : LeftDistribClass Rᵒᵈ := h
instance [Mul R] [Add R] [h : RightDistribClass R] : RightDistribClass Rᵒᵈ := h
instance [h : NonUnitalNonAssocSemiring R] : NonUnitalNonAssocSemiring Rᵒᵈ := h
instance [h : NonUnitalSemiring R] : NonUnitalSemiring Rᵒᵈ := h
instance [h : NonAssocSemiring R] : NonAssocSemiring Rᵒᵈ := h
instance [h : Semiring R] : Semiring Rᵒᵈ := h
instance [h : NonUnitalCommSemiring R] : NonUnitalCommSemiring Rᵒᵈ := h
instance [h : CommSemiring R] : CommSemiring Rᵒᵈ := h
instance [Mul R] [h : HasDistribNeg R] : HasDistribNeg Rᵒᵈ := h
instance [h : NonUnitalNonAssocRing R] : NonUnitalNonAssocRing Rᵒᵈ := h
instance [h : NonUnitalRing R] : NonUnitalRing Rᵒᵈ := h
instance [h : NonAssocRing R] : NonAssocRing Rᵒᵈ := h
instance [h : Ring R] : Ring Rᵒᵈ := h
instance [h : NonUnitalCommRing R] : NonUnitalCommRing Rᵒᵈ := h
instance [h : CommRing R] : CommRing Rᵒᵈ := h
instance [Ring R] [h : IsDomain R] : IsDomain Rᵒᵈ := h
/-! ### Lexicographical order -/
instance [h : Distrib R] : Distrib (Lex R) := h
instance [Mul R] [Add R] [h : LeftDistribClass R] : LeftDistribClass (Lex R) := h
instance [Mul R] [Add R] [h : RightDistribClass R] : RightDistribClass (Lex R) := h
instance [h : NonUnitalNonAssocSemiring R] : NonUnitalNonAssocSemiring (Lex R) := h
instance [h : NonUnitalSemiring R] : NonUnitalSemiring (Lex R) := h
instance [h : NonAssocSemiring R] : NonAssocSemiring (Lex R) := h
instance [h : Semiring R] : Semiring (Lex R) := h
instance [h : NonUnitalCommSemiring R] : NonUnitalCommSemiring (Lex R) := h
instance [h : CommSemiring R] : CommSemiring (Lex R) := h
instance [Mul R] [h : HasDistribNeg R] : HasDistribNeg (Lex R) := h
instance [h : NonUnitalNonAssocRing R] : NonUnitalNonAssocRing (Lex R) := h
instance [h : NonUnitalRing R] : NonUnitalRing (Lex R) := h
instance [h : NonAssocRing R] : NonAssocRing (Lex R) := h
instance [h : Ring R] : Ring (Lex R) := h
instance [h : NonUnitalCommRing R] : NonUnitalCommRing (Lex R) := h
instance [h : CommRing R] : CommRing (Lex R) := h
instance [Ring R] [h : IsDomain R] : IsDomain (Lex R) := h |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Idempotent.lean | import Mathlib.Algebra.Ring.Idempotent
import Mathlib.Order.BooleanAlgebra.Defs
import Mathlib.Order.Hom.Basic
/-!
# Boolean algebra structure on idempotents in a commutative (semi)ring
We show that the idempotent in a commutative ring form a Boolean algebra, with complement given
by `a ↦ 1 - a` and infimum given by multiplication. In a commutative semiring where subtraction
is not available, it is still true that pairs of elements `(a, b)` satisfying `a * b = 0` and
`a + b = 1` form a Boolean algebra (such elements are automatically idempotents, and such a pair
is uniquely determined by either `a` or `b`).
-/
variable {R : Type*}
instance [CommMonoid R] [AddCommMonoid R] :
HasCompl {a : R × R // a.1 * a.2 = 0 ∧ a.1 + a.2 = 1} where
compl a := ⟨(a.1.2, a.1.1), (mul_comm ..).trans a.2.1, (add_comm ..).trans a.2.2⟩
lemma eq_of_mul_eq_add_eq_one [NonAssocSemiring R] (a : R) {b c : R}
(mul : a * b = c * a) (add_ab : a + b = 1) (add_ac : a + c = 1) :
b = c :=
calc b = (a + c) * b := by rw [add_ac, one_mul]
_ = c * (a + b) := by rw [add_mul, mul, mul_add]
_ = c := by rw [add_ab, mul_one]
section CommSemiring
variable [CommSemiring R] {a b : {a : R × R // a.1 * a.2 = 0 ∧ a.1 + a.2 = 1}}
lemma mul_eq_zero_add_eq_one_ext_left (eq : a.1.1 = b.1.1) : a = b := by
refine Subtype.ext <| Prod.ext_iff.mpr ⟨eq, eq_of_mul_eq_add_eq_one a.1.1 ?_ a.2.2 ?_⟩
· rw [a.2.1, mul_comm, eq, b.2.1]
· rw [eq, b.2.2]
lemma mul_eq_zero_add_eq_one_ext_right (eq : a.1.2 = b.1.2) : a = b := by
refine Subtype.ext <| Prod.ext_iff.mpr ⟨eq_of_mul_eq_add_eq_one a.1.2 ?_ ?_ ?_, eq⟩
· rw [mul_comm, a.2.1, eq, b.2.1]
· rw [add_comm, a.2.2]
· rw [add_comm, eq, b.2.2]
instance : PartialOrder {a : R × R // a.1 * a.2 = 0 ∧ a.1 + a.2 = 1} where
le a b := a.1.1 * b.1.1 = a.1.1
le_refl a := (IsIdempotentElem.of_mul_add a.2.1 a.2.2).1
le_trans a b c hab hbc := show _ = _ by rw [← hab, mul_assoc, hbc]
le_antisymm a b hab hba := mul_eq_zero_add_eq_one_ext_left <| by rw [← hab, mul_comm, hba]
instance : SemilatticeSup {a : R × R // a.1 * a.2 = 0 ∧ a.1 + a.2 = 1} where
sup a b := ⟨(a.1.1 + a.1.2 * b.1.1, a.1.2 * b.1.2), by simp_rw [add_mul,
mul_mul_mul_comm _ b.1.1, b.2.1, mul_zero, ← mul_assoc, a.2.1, zero_mul, add_zero], by
simp_rw [add_assoc, ← mul_add, b.2.2, mul_one, a.2.2]⟩
le_sup_left a b := by
simp_rw [(· ≤ ·), mul_add, ← mul_assoc, a.2.1, zero_mul, add_zero,
(IsIdempotentElem.of_mul_add a.2.1 a.2.2).1.eq]
le_sup_right a b := by
simp_rw [(· ≤ ·), mul_add, mul_comm a.1.2, ← mul_assoc,
(IsIdempotentElem.of_mul_add b.2.1 b.2.2).1.eq, ← mul_add, a.2.2, mul_one]
sup_le a b c hac hbc := by simp_rw [(· ≤ ·), add_mul, mul_assoc]; rw [hac, hbc]
instance : BooleanAlgebra {a : R × R // a.1 * a.2 = 0 ∧ a.1 + a.2 = 1} where
inf a b := (aᶜ ⊔ bᶜ)ᶜ
inf_le_left a b := by simp_rw [(· ≤ ·), (· ⊔ ·), (·ᶜ), SemilatticeSup.sup,
mul_right_comm, (IsIdempotentElem.of_mul_add a.2.1 a.2.2).1.eq]
inf_le_right a b := by simp_rw [(· ≤ ·), (· ⊔ ·), (·ᶜ), SemilatticeSup.sup,
mul_assoc, (IsIdempotentElem.of_mul_add b.2.1 b.2.2).1.eq]
le_inf a b c hab hac := by
simp_rw [(· ≤ ·), (· ⊔ ·), (·ᶜ), SemilatticeSup.sup, ← mul_assoc]; rw [hab, hac]
le_sup_inf a b c := Eq.le <| mul_eq_zero_add_eq_one_ext_right <| by simp_rw [(· ⊔ ·), (· ⊓ ·),
(·ᶜ), SemilatticeSup.sup, add_mul, mul_add, mul_mul_mul_comm _ b.1.1,
(IsIdempotentElem.of_mul_add a.2.1 a.2.2).2.eq, ← mul_assoc, a.2.1, zero_mul, zero_add]
top := ⟨(1, 0), mul_zero _, add_zero _⟩
bot := ⟨(0, 1), zero_mul _, zero_add _⟩
inf_compl_le_bot a := Eq.le <| mul_eq_zero_add_eq_one_ext_right <| by
simp_rw [(· ⊔ ·), (· ⊓ ·), (·ᶜ), SemilatticeSup.sup,
(IsIdempotentElem.of_mul_add a.2.1 a.2.2).1.eq, add_comm, a.2.2]
top_le_sup_compl a := Eq.le <| mul_eq_zero_add_eq_one_ext_left <| by simp_rw [(· ⊔ ·), (·ᶜ),
SemilatticeSup.sup, (IsIdempotentElem.of_mul_add a.2.1 a.2.2).2.eq, a.2.2]
le_top _ := mul_one _
bot_le _ := zero_mul _
sdiff_eq _ _ := rfl
himp_eq _ _ := rfl
end CommSemiring
instance {S : Type*} [CommSemigroup S] : SemilatticeInf {a : S // IsIdempotentElem a} where
le a b := a.1 * b = a
le_refl a := a.2
le_trans a b c hab hbc := show _ = _ by rw [← hab, mul_assoc, hbc]
le_antisymm a b hab hba := Subtype.ext <| by rw [← hab, mul_comm, hba]
inf a b := ⟨_, a.2.mul b.2⟩
inf_le_left a b := show _ = _ by simp_rw [mul_right_comm]; rw [a.2]
inf_le_right a b := show _ = _ by simp_rw [mul_assoc]; rw [b.2]
le_inf a b c hab hac := by simp_rw [← mul_assoc]; rw [hab, hac]
instance {M : Type*} [CommMonoid M] : OrderTop {a : M // IsIdempotentElem a} where
top := ⟨1, .one⟩
le_top _ := mul_one _
instance {M₀ : Type*} [CommMonoidWithZero M₀] : OrderBot {a : M₀ // IsIdempotentElem a} where
bot := ⟨0, .zero⟩
bot_le _ := zero_mul _
section CommRing
variable [CommRing R]
instance : Lattice {a : R // IsIdempotentElem a} where
__ : SemilatticeInf _ := inferInstance
sup a b := ⟨_, a.2.add_sub_mul b.2⟩
le_sup_left a b := show _ = _ by
simp_rw [mul_sub, mul_add]; rw [← mul_assoc, a.2, add_sub_cancel_right]
le_sup_right a b := show _ = _ by
simp_rw [mul_sub, mul_add]; rw [← mul_assoc, mul_right_comm, b.2, add_sub_cancel_left]
sup_le a b c hac hbc := show _ = _ by simp_rw [sub_mul, add_mul, mul_assoc]; rw [hbc, hac]
instance : BooleanAlgebra {a : R // IsIdempotentElem a} where
__ : DistribLattice _ := .ofInfSupLe fun a b c ↦ Eq.le <| Subtype.ext <| by
simp_rw [(· ⊔ ·), (· ⊓ ·), SemilatticeSup.sup, SemilatticeInf.inf, Lattice.inf,
SemilatticeInf.inf, mul_sub, mul_add, mul_mul_mul_comm]
rw [a.2]
__ : OrderTop _ := inferInstance
__ : OrderBot _ := inferInstance
compl a := ⟨_, a.2.one_sub⟩
inf_compl_le_bot a := (mul_zero _).trans ((mul_one_sub ..).trans <| by rw [a.2, sub_self]).symm
top_le_sup_compl a := (one_mul _).trans <| by
simp_rw [(· ⊔ ·), SemilatticeSup.sup, add_sub_cancel, mul_sub, mul_one]
rw [a.2, sub_self, sub_zero]; rfl
sdiff_eq _ _ := rfl
himp a b := ⟨_, (a.2.mul b.2.one_sub).one_sub⟩
himp_eq a b := Subtype.ext <| by simp_rw [(· ⊔ ·), SemilatticeSup.sup,
add_comm b.1, add_sub_assoc, mul_sub, mul_one, sub_sub_cancel, sub_add, mul_comm]
/-- In a commutative ring, the idempotents are in 1-1 correspondence with pairs of elements
whose product is 0 and whose sum is 1. The correspondence is given by `a ↔ (a, 1 - a)`. -/
def OrderIso.isIdempotentElemMulZeroAddOne :
{a : R // IsIdempotentElem a} ≃o {a : R × R // a.1 * a.2 = 0 ∧ a.1 + a.2 = 1} where
toFun a := ⟨(a, 1 - a), by simp_rw [mul_sub, mul_one, a.2.eq, sub_self], by rw [add_sub_cancel]⟩
invFun a := ⟨a.1.1, (IsIdempotentElem.of_mul_add a.2.1 a.2.2).1⟩
right_inv a := Subtype.ext <| Prod.ext rfl <| sub_eq_of_eq_add <| a.2.2.symm.trans (add_comm ..)
map_rel_iff' := Iff.rfl
end CommRing |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Pow.lean | import Mathlib.Data.Nat.Cast.Commute
import Mathlib.Data.Nat.Cast.Order.Ring
/-! # Bernoulli's inequality -/
variable {R : Type*}
section OrderedSemiring
variable [Semiring R] [PartialOrder R] [IsOrderedRing R] {a : R}
/-- **Bernoulli's inequality**. This version works for semirings but requires
additional hypotheses `0 ≤ a * a` and `0 ≤ (1 + a) * (1 + a)`. -/
lemma one_add_mul_le_pow' (Hsq : 0 ≤ a * a) (Hsq' : 0 ≤ (1 + a) * (1 + a)) (H : 0 ≤ 2 + a) :
∀ n : ℕ, 1 + n * a ≤ (1 + a) ^ n
| 0 => by simp
| 1 => by simp
| n + 2 =>
have : 0 ≤ n * (a * a * (2 + a)) + a * a :=
add_nonneg (mul_nonneg n.cast_nonneg (mul_nonneg Hsq H)) Hsq
calc
_ ≤ 1 + ↑(n + 2) * a + (n * (a * a * (2 + a)) + a * a) := le_add_of_nonneg_right this
_ = (1 + a) * (1 + a) * (1 + n * a) := by
simp only [Nat.cast_add, add_mul, mul_add, one_mul, mul_one, ← one_add_one_eq_two,
Nat.cast_one, add_assoc]
simp only [← add_assoc, add_comm _ (↑n * a)]
simp only [add_assoc, (n.cast_commute (_ : R)).left_comm]
simp only [add_comm, add_left_comm]
_ ≤ (1 + a) * (1 + a) * (1 + a) ^ n :=
mul_le_mul_of_nonneg_left (one_add_mul_le_pow' Hsq Hsq' H _) Hsq'
_ = (1 + a) ^ (n + 2) := by simp only [pow_succ', mul_assoc]
end OrderedSemiring
section LinearOrderedRing
variable [Ring R] [LinearOrder R] [IsStrictOrderedRing R] {a : R} {n : ℕ}
/-- **Bernoulli's inequality** for `n : ℕ`, `-2 ≤ a`. -/
lemma one_add_mul_le_pow (H : -2 ≤ a) (n : ℕ) : 1 + n * a ≤ (1 + a) ^ n :=
one_add_mul_le_pow' (mul_self_nonneg _) (mul_self_nonneg _) (neg_le_iff_add_nonneg'.1 H) _
/-- **Bernoulli's inequality** reformulated to estimate `a^n`. -/
lemma one_add_mul_sub_le_pow (H : -1 ≤ a) (n : ℕ) : 1 + n * (a - 1) ≤ a ^ n := by
have : -2 ≤ a - 1 := by
rwa [← one_add_one_eq_two, neg_add, ← sub_eq_add_neg, sub_le_sub_iff_right]
simpa only [add_sub_cancel] using one_add_mul_le_pow this n
end LinearOrderedRing |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Opposite.lean | import Mathlib.Algebra.Order.Group.Opposite
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Ring.Opposite
/-!
# Ordered ring instances for `MulOpposite`/`AddOpposite`
This file transfers ordered (semi)ring instances from `R` to `Rᵐᵒᵖ` and `Rᵃᵒᵖ`.
-/
variable {R : Type*}
namespace MulOpposite
instance [Semiring R] [PartialOrder R] [IsOrderedRing R] : IsOrderedRing Rᵐᵒᵖ where
zero_le_one := zero_le_one (α := R)
mul_le_mul_of_nonneg_left _a ha _b _c hbc := mul_le_mul_of_nonneg_right (α := R) hbc ha
mul_le_mul_of_nonneg_right _a ha _b _c hbc := mul_le_mul_of_nonneg_left (α := R) hbc ha
end MulOpposite
namespace AddOpposite
instance [Semiring R] [PartialOrder R] [IsOrderedRing R] : IsOrderedRing Rᵃᵒᵖ where
zero_le_one := zero_le_one (α := R)
mul_le_mul_of_nonneg_left _a ha _b _c hbc := mul_le_mul_of_nonneg_left (α := R) hbc ha
mul_le_mul_of_nonneg_right _a ha _b _c hbc := mul_le_mul_of_nonneg_right (α := R) hbc ha
end AddOpposite |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Int.lean | import Mathlib.Algebra.Order.Group.Int
import Mathlib.Algebra.Order.Group.Unbundled.Int
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Ring.Int.Parity
import Mathlib.Data.Int.GCD
import Mathlib.Data.Nat.Cast.Order.Basic
import Mathlib.Order.BooleanAlgebra.Set
/-!
# The integers form a linear ordered ring
This file contains:
* instances on `ℤ`. The stronger one is `Int.instLinearOrderedCommRing`.
* basic lemmas about integers that involve order properties.
## Recursors
* `Int.rec`: Sign disjunction. Something is true/defined on `ℤ` if it's true/defined for nonnegative
and for negative values. (Defined in core Lean 3)
* `Int.inductionOn`: Simple growing induction on positive numbers, plus simple decreasing induction
on negative numbers. Note that this recursor is currently only `Prop`-valued.
* `Int.inductionOn'`: Simple growing induction for numbers greater than `b`, plus simple decreasing
induction on numbers less than `b`.
-/
-- We should need only a minimal development of sets in order to get here.
assert_not_exists Set.Subsingleton
open Function Nat
namespace Int
instance instIsStrictOrderedRing : IsStrictOrderedRing ℤ := .of_mul_pos @Int.mul_pos
/-! ### Miscellaneous lemmas -/
lemma isCompl_even_odd : IsCompl { n : ℤ | Even n } { n | Odd n } := by
simp [← not_even_iff_odd, ← Set.compl_setOf, isCompl_compl]
@[simp]
lemma _root_.Nat.cast_natAbs {α : Type*} [AddGroupWithOne α] (n : ℤ) : (n.natAbs : α) = |n| := by
rw [← natCast_natAbs, Int.cast_natCast]
lemma two_le_iff_pos_of_even {m : ℤ} (even : Even m) : 2 ≤ m ↔ 0 < m :=
le_iff_pos_of_dvd (by decide) even.two_dvd
lemma add_two_le_iff_lt_of_even_sub {m n : ℤ} (even : Even (n - m)) : m + 2 ≤ n ↔ m < n := by
grind
end Int
/-- If the gcd of two natural numbers `p` and `q` divides a third natural number `n`,
and if `n` is at least `(p - 1) * (q - 1)`, then `n` can be represented as an `ℕ`-linear
combination of `p` and `q`.
TODO: show that if `p.gcd q = 1` and `0 ≤ n ≤ (p - 1) * (q - 1) - 1 = N`, then `n` is
representable iff `N - n` is not. In particular `N` is not representable, solving the
coin problem for two coins: https://en.wikipedia.org/wiki/Coin_problem#n_=_2. -/
theorem Nat.exists_add_mul_eq_of_gcd_dvd_of_mul_pred_le (p q n : ℕ) (dvd : p.gcd q ∣ n)
(le : p.pred * q.pred ≤ n) : ∃ a b : ℕ, a * p + b * q = n := by
obtain _ | p := p
· have ⟨b, eq⟩ := q.gcd_zero_left ▸ dvd
exact ⟨0, b, by simpa [mul_comm, eq_comm] using eq⟩
obtain _ | q := q
· have ⟨a, eq⟩ := p.gcd_zero_right ▸ dvd
exact ⟨a, 0, by simpa [mul_comm, eq_comm] using eq⟩
rw [← Int.gcd_natCast_natCast, Int.gcd_dvd_iff] at dvd
have ⟨a_n, b_n, eq⟩ := dvd
let a := a_n % q.succ
let b := b_n + a_n / q.succ * p.succ
refine ⟨a.toNat, b.toNat, Nat.cast_injective (R := ℤ) ?_⟩
have : a * p.succ + b * q.succ = n := by rw [add_mul, ← add_assoc,
add_right_comm, mul_right_comm, ← add_mul, Int.emod_add_ediv_mul, eq, mul_comm, mul_comm b_n]
rw [Nat.cast_add, Nat.cast_mul, Nat.cast_mul, Int.natCast_toNat_eq_self.mpr
(Int.emod_nonneg _ <| by cutsat), Int.natCast_toNat_eq_self.mpr, this]
-- show b ≥ 0 by contradiction
by_contra hb
replace hb : b ≤ -1 := by omega
apply lt_irrefl (n : ℤ)
have ha := Int.emod_lt a_n (by cutsat : (q.succ : ℤ) ≠ 0)
rw [p.pred_succ, q.pred_succ] at le
calc n = a * p.succ + b * q.succ := this.symm
_ ≤ q * p.succ + -1 * q.succ := by gcongr <;> omega
_ = p * q - 1 := by simp_rw [Nat.cast_succ, mul_add, mul_comm]; cutsat
_ ≤ n - 1 := by rwa [sub_le_sub_iff_right, ← Nat.cast_mul, Nat.cast_le]
_ < n := by cutsat |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Canonical.lean | import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Order.Sub.Basic
import Mathlib.Algebra.Ring.Parity
/-!
# Canonically ordered rings and semirings.
-/
open Function
universe u
variable {R : Type u}
-- see Note [lower instance priority]
instance (priority := 10) CanonicallyOrderedAdd.toZeroLEOneClass
[AddZeroClass R] [One R] [LE R] [CanonicallyOrderedAdd R] : ZeroLEOneClass R where
zero_le_one := zero_le _
-- this holds more generally if we refactor `Odd` to use
-- either `2 • t` or `t + t` instead of `2 * t`.
lemma Odd.pos [Semiring R] [PartialOrder R] [CanonicallyOrderedAdd R] [Nontrivial R] {a : R} :
Odd a → 0 < a := by
rintro ⟨k, rfl⟩; simp
namespace CanonicallyOrderedAdd
-- see Note [lower instance priority]
instance (priority := 100) toMulLeftMono [NonUnitalNonAssocSemiring R]
[LE R] [CanonicallyOrderedAdd R] : MulLeftMono R := by
refine ⟨fun a b c h => ?_⟩
dsimp
rcases exists_add_of_le h with ⟨c, rfl⟩
rw [mul_add]
apply self_le_add_right
-- see Note [lower instance priority]
instance (priority := 100) toMulRightMono [NonUnitalNonAssocSemiring R]
[LE R] [CanonicallyOrderedAdd R] : MulRightMono R := by
refine ⟨fun a b c h => ?_⟩
dsimp [swap]
rcases exists_add_of_le h with ⟨c, rfl⟩
rw [add_mul]
apply self_le_add_right
variable [CommSemiring R] [PartialOrder R] [CanonicallyOrderedAdd R]
-- TODO: make it an instance
lemma toIsOrderedMonoid : IsOrderedMonoid R where
mul_le_mul_left _ _ := mul_le_mul_left'
-- TODO: make it an instance
lemma toIsOrderedRing : IsOrderedRing R where
add_le_add_left _ _ := add_le_add_left
@[simp]
protected theorem mul_pos [NoZeroDivisors R] {a b : R} :
0 < a * b ↔ 0 < a ∧ 0 < b := by
simp only [pos_iff_ne_zero, ne_eq, mul_eq_zero, not_or]
lemma pow_pos [NoZeroDivisors R] {a : R} (ha : 0 < a) (n : ℕ) : 0 < a ^ n :=
pos_iff_ne_zero.2 <| pow_ne_zero _ ha.ne'
protected lemma mul_lt_mul_of_lt_of_lt
[PosMulStrictMono R] {a b c d : R} (hab : a < b) (hcd : c < d) :
a * c < b * d := by
-- TODO: This should be an instance but it currently times out
have := posMulStrictMono_iff_mulPosStrictMono.1 ‹_›
obtain rfl | hc := eq_zero_or_pos c
· rw [mul_zero]
exact mul_pos ((zero_le _).trans_lt hab) hcd
· exact mul_lt_mul_of_pos' hab hcd hc ((zero_le _).trans_lt hab)
end CanonicallyOrderedAdd
section Sub
section NonUnitalNonAssocSemiring
variable [NonUnitalNonAssocSemiring R] [PartialOrder R] [CanonicallyOrderedAdd R]
[Sub R] [OrderedSub R] [IsTotal R (· ≤ ·)]
namespace AddLECancellable
protected theorem mul_tsub {a b c : R}
(h : AddLECancellable (a * c)) : a * (b - c) = a * b - a * c := by
obtain (hbc | hcb) := total_of (· ≤ ·) b c
· rw [tsub_eq_zero_iff_le.2 hbc, mul_zero, tsub_eq_zero_iff_le.2 (mul_le_mul_left' hbc a)]
· apply h.eq_tsub_of_add_eq
rw [← mul_add, tsub_add_cancel_of_le hcb]
protected theorem tsub_mul [MulRightMono R] {a b c : R}
(h : AddLECancellable (b * c)) : (a - b) * c = a * c - b * c := by
obtain (hab | hba) := total_of (· ≤ ·) a b
· rw [tsub_eq_zero_iff_le.2 hab, zero_mul, tsub_eq_zero_iff_le.2 (mul_le_mul_right' hab c)]
· apply h.eq_tsub_of_add_eq
rw [← add_mul, tsub_add_cancel_of_le hba]
end AddLECancellable
variable [AddLeftReflectLE R]
theorem mul_tsub (a b c : R) : a * (b - c) = a * b - a * c :=
Contravariant.AddLECancellable.mul_tsub
theorem tsub_mul [MulRightMono R] (a b c : R) :
(a - b) * c = a * c - b * c :=
Contravariant.AddLECancellable.tsub_mul
end NonUnitalNonAssocSemiring
section NonAssocSemiring
variable [NonAssocSemiring R] [PartialOrder R] [CanonicallyOrderedAdd R]
[Sub R] [OrderedSub R] [IsTotal R (· ≤ ·)]
lemma mul_tsub_one [AddLeftReflectLE R] (a b : R) :
a * (b - 1) = a * b - a := by rw [mul_tsub, mul_one]
lemma tsub_one_mul [MulRightMono R] [AddLeftReflectLE R] (a b : R) :
(a - 1) * b = a * b - b := by rw [tsub_mul, one_mul]
end NonAssocSemiring
section CommSemiring
variable [CommSemiring R] [PartialOrder R] [CanonicallyOrderedAdd R]
[Sub R] [OrderedSub R] [IsTotal R (· ≤ ·)] [AddLeftReflectLE R]
/-- The `tsub` version of `mul_self_sub_mul_self`. Notably, this holds for `Nat` and `NNReal`. -/
theorem mul_self_tsub_mul_self (a b : R) :
a * a - b * b = (a + b) * (a - b) := by
rw [mul_tsub, add_mul, add_mul, tsub_add_eq_tsub_tsub, mul_comm b a, add_tsub_cancel_right]
/-- The `tsub` version of `sq_sub_sq`. Notably, this holds for `Nat` and `NNReal`. -/
theorem sq_tsub_sq (a b : R) : a ^ 2 - b ^ 2 = (a + b) * (a - b) := by
rw [sq, sq, mul_self_tsub_mul_self]
theorem mul_self_tsub_one (a : R) : a * a - 1 = (a + 1) * (a - 1) := by
rw [← mul_self_tsub_mul_self, mul_one]
end CommSemiring
end Sub |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Rat.lean | import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Order.Ring.Unbundled.Rat
import Mathlib.Algebra.Ring.Rat
/-!
# The rational numbers form a linear ordered field
This file constructs the order on `ℚ` and proves that `ℚ` is a discrete, linearly ordered
commutative ring.
`ℚ` is in fact a linearly ordered field, but this fact is located in `Data.Rat.Field` instead of
here because we need the order on `ℚ` to define `ℚ≥0`, which we itself need to define `Field`.
## Tags
rat, rationals, field, ℚ, numerator, denominator, num, denom, order, ordering
-/
assert_not_exists Field Finset Set.Icc GaloisConnection
namespace Rat
instance instIsOrderedAddMonoid : IsOrderedAddMonoid ℚ where
add_le_add_left := fun _ _ ab _ => Rat.add_le_add_left.2 ab
instance instIsStrictOrderedRing : IsStrictOrderedRing ℚ := .of_mul_pos fun _ _ ha hb ↦
(Rat.mul_nonneg ha.le hb.le).lt_of_ne' (mul_ne_zero ha.ne' hb.ne')
end Rat |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Star.lean | import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Order.Star.Basic
/-!
# Commutative star-ordered rings are ordered rings
A noncommutative star-ordered ring is generally not an ordered ring. Indeed, in a star-ordered
ring, nonnegative elements are self-adjoint, but the product of self-adjoint elements is
self-adjoint if and only if they commute. Therefore, a necessary condition for a star-ordered ring
to be an ordered ring is that all nonnegative elements commute. Consequently, if a star-ordered
ring is spanned by it nonnegative elements (as is the case for C⋆-algebras) and it is also an
ordered ring, then it is commutative.
In this file we prove the converse: a *commutative* star-ordered ring is an ordered ring.
-/
namespace StarOrderedRing
/- This example shows that nonnegative elements in a ordered semiring which is also star-ordered
must commute. We provide this only as an example as opposed to a lemma because we never expect the
type class assumptions to be satisfied without a `CommSemiring` instance already in scope; not that
it is impossible, only that it shouldn't occur in practice. -/
example {R : Type*} [Semiring R] [PartialOrder R] [IsOrderedRing R]
[StarRing R] [StarOrderedRing R] {x y : R} (hx : 0 ≤ x)
(hy : 0 ≤ y) : x * y = y * x := by
rw [← IsSelfAdjoint.of_nonneg (mul_nonneg hy hx), star_mul, IsSelfAdjoint.of_nonneg hx,
IsSelfAdjoint.of_nonneg hy]
/-- A commutative star-ordered semiring is an ordered semiring. -/
instance toIsOrderedRing (R : Type*) [CommSemiring R] [PartialOrder R]
[StarRing R] [StarOrderedRing R] : IsOrderedRing R where
mul_le_mul_of_nonneg_left _a ha _b _c hbc := smul_le_smul_of_nonneg_left hbc ha
mul_le_mul_of_nonneg_right _a ha _b _c hbc := smul_le_smul_of_nonneg_right hbc ha
end StarOrderedRing |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Prod.lean | import Mathlib.Algebra.Order.Monoid.Prod
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Ring.Prod
/-!
# Products of ordered rings
-/
variable {α β : Type*}
instance [Semiring α] [PartialOrder α] [IsOrderedRing α]
[Semiring β] [PartialOrder β] [IsOrderedRing β] : IsOrderedRing (α × β) where
zero_le_one := ⟨zero_le_one, zero_le_one⟩
mul_le_mul_of_nonneg_left _a ha _b _c hbc :=
⟨mul_le_mul_of_nonneg_left hbc.1 ha.1, mul_le_mul_of_nonneg_left hbc.2 ha.2⟩
mul_le_mul_of_nonneg_right _a ha _b _c hbc :=
⟨mul_le_mul_of_nonneg_right hbc.1 ha.1, mul_le_mul_of_nonneg_right hbc.2 ha.2⟩ |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Nat.lean | import Mathlib.Algebra.Order.Group.Nat
import Mathlib.Algebra.Order.GroupWithZero.Canonical
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Ring.Parity
import Mathlib.Order.BooleanAlgebra.Set
/-!
# The natural numbers form an ordered semiring
This file contains the commutative linear orderded semiring instance on the natural numbers.
See note [foundational algebra order theory].
-/
namespace Nat
/-! ### Instances -/
instance instIsStrictOrderedRing : IsStrictOrderedRing ℕ where
add_le_add_left := @Nat.add_le_add_left
le_of_add_le_add_left := @Nat.le_of_add_le_add_left
zero_le_one := Nat.le_of_lt (Nat.zero_lt_succ 0)
mul_lt_mul_of_pos_left _a ha _b _c hbc := Nat.mul_lt_mul_of_pos_left hbc ha
mul_lt_mul_of_pos_right _a ha _b _c hbc := Nat.mul_lt_mul_of_pos_right hbc ha
exists_pair_ne := ⟨0, 1, ne_of_lt Nat.zero_lt_one⟩
instance instLinearOrderedCommMonoidWithZero : LinearOrderedCommMonoidWithZero ℕ where
bot := 0
bot_le := zero_le
zero_le_one := zero_le_one
mul_le_mul_left _ _ h c := Nat.mul_le_mul_left c h
/-! ### Miscellaneous lemmas -/
lemma isCompl_even_odd : IsCompl { n : ℕ | Even n } { n | Odd n } := by
simp only [← Set.compl_setOf, isCompl_compl, ← not_even_iff_odd]
end Nat |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Archimedean.lean | import Mathlib.Algebra.Order.Archimedean.Class
import Mathlib.Algebra.Order.Group.DenselyOrdered
import Mathlib.Algebra.Order.Ring.Basic
import Mathlib.Algebra.Order.Hom.Ring
import Mathlib.RingTheory.Valuation.Basic
/-!
# Archimedean classes of a linearly ordered ring
The archimedean classes of a linearly ordered ring can be given the structure of an `AddCommMonoid`,
by defining
* `0 = mk 1`
* `mk x + mk y = mk (x * y)`
For a linearly ordered field, we can define a negative as
* `-mk x = mk x⁻¹`
which turns them into a `LinearOrderedAddCommGroupWithTop`.
## Implementation notes
We give Archimedean class an additive structure, rather than a multiplicative one, for the following
reasons:
* In the ring version of Hahn embedding theorem, the subtype `FiniteArchimedeanClass R` of non-top
elements in `ArchimedeanClass R` naturally becomes the additive abelian group for the ring
`HahnSeries (FiniteArchimedeanClass R) ℝ`.
* The order we defined on `ArchimedeanClass R` matches the order on `AddValuation`, rather than the
one on `Valuation`.
-/
variable {R S : Type*} [LinearOrder R] [LinearOrder S]
namespace ArchimedeanClass
section Ring
variable [CommRing R]
section IsOrderedRing
variable [IsOrderedRing R]
instance : Zero (ArchimedeanClass R) where
zero := mk 1
@[simp] theorem mk_one : mk (1 : R) = 0 := rfl
private theorem mk_mul_le_of_le {x₁ y₁ x₂ y₂ : R} (hx : mk x₁ ≤ mk x₂) (hy : mk y₁ ≤ mk y₂) :
mk (x₁ * y₁) ≤ mk (x₂ * y₂) := by
obtain ⟨m, hm⟩ := hx
obtain ⟨n, hn⟩ := hy
use m * n
convert mul_le_mul hm hn (abs_nonneg _) (nsmul_nonneg (abs_nonneg _) _) using 1 <;>
simp_rw [ArchimedeanOrder.val_of, abs_mul]
ring
/-- Multipilication in `R` transfers to Addition in `ArchimedeanClass R`. -/
instance : Add (ArchimedeanClass R) where
add := lift₂ (fun x y ↦ .mk <| x * y) fun _ _ _ _ hx hy ↦
(mk_mul_le_of_le hx.le hy.le).antisymm (mk_mul_le_of_le hx.ge hy.ge)
@[simp] theorem mk_mul (x y : R) : mk (x * y) = mk x + mk y := rfl
instance : SMul ℕ (ArchimedeanClass R) where
smul n := lift (fun x ↦ mk (x ^ n)) fun x y h ↦ by
induction n with
| zero => simp
| succ n IH => simp_rw [pow_succ, mk_mul, IH, h]
@[simp] theorem mk_pow (n : ℕ) (x : R) : mk (x ^ n) = n • mk x := rfl
instance : AddCommMagma (ArchimedeanClass R) where
add_comm x y := by
induction x with | mk x
induction y with | mk y
rw [← mk_mul, mul_comm, mk_mul]
private theorem zero_add' (x : ArchimedeanClass R) : 0 + x = x := by
induction x with | mk x
rw [← mk_one, ← mk_mul, one_mul]
private theorem add_assoc' (x y z : ArchimedeanClass R) : x + y + z = x + (y + z) := by
induction x with | mk x
induction y with | mk y
induction z with | mk z
simp_rw [← mk_mul, mul_assoc]
instance : AddCommMonoid (ArchimedeanClass R) where
add_assoc := add_assoc'
zero_add := zero_add'
add_zero x := add_comm x _ ▸ zero_add' x
nsmul n x := n • x
nsmul_zero x := by induction x with | mk x => rw [← mk_pow, pow_zero, mk_one]
nsmul_succ n x := by induction x with | mk x => rw [← mk_pow, pow_succ, mk_mul, mk_pow]
instance : IsOrderedAddMonoid (ArchimedeanClass R) where
add_le_add_left x y h z := by
induction x with | mk x
induction y with | mk y
induction z with | mk z
rw [← mk_mul, ← mk_mul]
exact mk_mul_le_of_le le_rfl h
noncomputable instance : LinearOrderedAddCommMonoidWithTop (ArchimedeanClass R) where
top_add' x := by induction x with | mk x => rw [← mk_zero, ← mk_mul, zero_mul]
variable (R) in
/-- `ArchimedeanClass.mk` defines an `AddValuation` on the ring `R`. -/
noncomputable def addValuation : AddValuation R (ArchimedeanClass R) := AddValuation.of mk
rfl rfl min_le_mk_add mk_mul
@[simp] theorem addValuation_apply (a : R) : addValuation R a = mk a := rfl
variable {S : Type*} [LinearOrder S] [CommRing S] [IsOrderedRing S]
@[simp]
theorem orderHom_zero (f : S →+o R) : orderHom f 0 = mk (f 1) := by
rw [← mk_one, orderHom_mk]
@[simp]
theorem mk_eq_zero_of_archimedean [Archimedean S] {x : S} (h : x ≠ 0) : mk x = 0 := by
have : Nontrivial S := ⟨_, _, h⟩
exact mk_eq_mk_of_archimedean h one_ne_zero
theorem eq_zero_or_top_of_archimedean [Archimedean S] (x : ArchimedeanClass S) : x = 0 ∨ x = ⊤ := by
induction x with | mk x
obtain rfl | h := eq_or_ne x 0 <;> simp_all
/-- See `mk_map_of_archimedean'` for a version taking `M →+*o R`. -/
theorem mk_map_of_archimedean [Archimedean S] (f : S →+o R) {x : S} (h : x ≠ 0) :
mk (f x) = mk (f 1) := by
rw [← orderHom_mk, mk_eq_zero_of_archimedean h, orderHom_zero]
/-- See `mk_map_of_archimedean` for a version taking `M →+o R`. -/
theorem mk_map_of_archimedean' [Archimedean S] (f : S →+*o R) {x : S} (h : x ≠ 0) :
mk (f x) = 0 := by
simpa using mk_map_of_archimedean f.toOrderAddMonoidHom h
@[simp]
theorem mk_intCast {n : ℤ} (h : n ≠ 0) : mk (n : S) = 0 := by
obtain _ | _ := subsingleton_or_nontrivial S
· exact Subsingleton.allEq ..
· exact mk_map_of_archimedean' ⟨Int.castRingHom S, fun _ ↦ by simp⟩ h
@[simp]
theorem mk_natCast {n : ℕ} (h : n ≠ 0) : mk (n : S) = 0 := by
rw [← Int.cast_natCast]
exact mk_intCast (mod_cast h)
end IsOrderedRing
section IsStrictOrderedRing
variable [IsStrictOrderedRing R]
theorem add_left_cancel_of_ne_top {x y z : ArchimedeanClass R} (hx : x ≠ ⊤) (h : x + y = x + z) :
y = z := by
induction x with | mk x
induction y with | mk y
induction z with | mk z
simp_rw [← mk_mul, mk_eq_mk] at h
obtain ⟨⟨m, hm⟩, ⟨n, hn⟩⟩ := h
simp_rw [abs_mul, mul_comm |x|, nsmul_eq_mul, ← mul_assoc, ← nsmul_eq_mul] at hm hn
refine mk_eq_mk.2 ⟨⟨m, ?_⟩, ⟨n, ?_⟩⟩ <;> exact le_of_mul_le_mul_right ‹_› (by simpa using hx)
theorem add_right_cancel_of_ne_top {x y z : ArchimedeanClass R} (hx : x ≠ ⊤) (h : y + x = z + x) :
y = z := by
simp_rw [← add_comm x] at h
exact add_left_cancel_of_ne_top hx h
theorem mk_le_mk_iff_denselyOrdered [Ring S] [IsStrictOrderedRing S]
[DenselyOrdered R] [Archimedean R] {x y : S} (f : R →+* S) (hf : StrictMono f) :
mk x ≤ mk y ↔ ∃ q : R, 0 < f q ∧ f q * |y| ≤ |x| := by
have H {q} : 0 < f q ↔ 0 < q := by simpa using hf.lt_iff_lt (a := 0)
constructor
· rintro ⟨(_ | n), hn⟩
· simp_all [exists_zero_lt]
· obtain ⟨q, hq₀, hq⟩ := exists_nsmul_lt_of_pos (one_pos (α := R)) (n + 1)
refine ⟨q, H.2 hq₀, le_of_mul_le_mul_left ?_ n.cast_add_one_pos⟩
simpa [← mul_assoc] using mul_le_mul (hf hq).le hn (abs_nonneg y) (by simp)
· rintro ⟨q, hq₀, hq⟩
have hq₀' := H.1 hq₀
obtain ⟨n, hn⟩ := exists_lt_nsmul hq₀' 1
refine ⟨n, le_of_mul_le_mul_left ?_ hq₀⟩
have h : 0 ≤ f (n • q) := by
rw [← f.map_zero]
exact hf.monotone (nsmul_nonneg hq₀'.le n)
simpa [mul_comm, mul_assoc] using mul_le_mul (hf hn).le hq (mul_nonneg hq₀.le (abs_nonneg y)) h
end IsStrictOrderedRing
end Ring
section Field
variable [Field R] [IsOrderedRing R]
instance : Neg (ArchimedeanClass R) where
neg := lift (fun x ↦ mk x⁻¹) fun x y h ↦ by
have := IsOrderedRing.toIsStrictOrderedRing R
obtain rfl | hx := eq_or_ne x 0
· simp_all
obtain rfl | hy := eq_or_ne y 0
· simp_all
have hx' : mk x ≠ ⊤ := by simpa using hx
apply add_left_cancel_of_ne_top hx'
nth_rw 2 [h]
simp [← mk_mul, hx, hy]
@[simp] theorem mk_inv (x : R) : mk x⁻¹ = -mk x := rfl
instance : SMul ℤ (ArchimedeanClass R) where
smul n := lift (fun x ↦ mk (x ^ n)) fun x y h ↦ by
obtain ⟨n, rfl | rfl⟩ := n.eq_nat_or_neg <;> simp [h]
@[simp] theorem mk_zpow (n : ℤ) (x : R) : mk (x ^ n) = n • mk x := rfl
private theorem zsmul_succ' (n : ℕ) (x : ArchimedeanClass R) :
(n.succ : ℤ) • x = (n : ℤ) • x + x := by
induction x with | mk x
rw [← mk_zpow, Nat.cast_succ]
obtain rfl | hx := eq_or_ne x 0
· simp [zero_zpow _ n.cast_add_one_ne_zero]
· rw [zpow_add_one₀ hx, mk_mul, mk_zpow]
noncomputable instance : LinearOrderedAddCommGroupWithTop (ArchimedeanClass R) where
neg_top := by simp [← mk_zero, ← mk_inv]
add_neg_cancel x h := by
induction x with | mk x
simp [← mk_inv, ← mk_mul, mul_inv_cancel₀ (mk_eq_top_iff.not.1 h)]
zsmul n x := n • x
zsmul_zero' x := by induction x with | mk x => rw [← mk_zpow, zpow_zero, mk_one]
zsmul_succ' := zsmul_succ'
zsmul_neg' n x := by
induction x with | mk x
rw [← mk_zpow, zpow_negSucc, pow_succ, zsmul_succ', mk_inv, mk_mul, ← zpow_natCast, mk_zpow]
@[simp]
theorem mk_ratCast {q : ℚ} (h : q ≠ 0) : mk (q : R) = 0 := by
have := IsOrderedRing.toIsStrictOrderedRing R
simpa using mk_map_of_archimedean ⟨(Rat.castHom R).toAddMonoidHom, fun _ ↦ by simp⟩ h
theorem mk_le_mk_iff_ratCast {x y : R} : mk x ≤ mk y ↔ ∃ q : ℚ, 0 < q ∧ q * |y| ≤ |x| := by
have := IsOrderedRing.toIsStrictOrderedRing R
simpa using mk_le_mk_iff_denselyOrdered (Rat.castHom _) Rat.cast_strictMono (x := x)
end Field
end ArchimedeanClass |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/IsNonarchimedean.lean | import Mathlib.Algebra.Order.Hom.Basic
import Mathlib.Data.Nat.Choose.Sum
/-!
# Nonarchimedean functions
A function `f : α → R` is nonarchimedean if it satisfies the strong triangle inequality
`f (a + b) ≤ max (f a) (f b)` for all `a b : α`. This file proves basic properties of
nonarchimedean functions.
-/
namespace IsNonarchimedean
variable {R : Type*} [Semiring R] [LinearOrder R] {a b : R} {m n : ℕ}
/-- A nonnegative nonarchimedean function satisfies the triangle inequality. -/
theorem add_le [IsStrictOrderedRing R] {α : Type*} [Add α] {f : α → R} (hf : ∀ x : α, 0 ≤ f x)
(hna : IsNonarchimedean f) {a b : α} : f (a + b) ≤ f a + f b := by
apply le_trans (hna _ _)
rw [max_le_iff, le_add_iff_nonneg_right, le_add_iff_nonneg_left]
exact ⟨hf _, hf _⟩
/-- If `f` is a nonnegative nonarchimedean function `α → R` such that `f 0 = 0`, then for every
`n : ℕ` and `a : α`, we have `f (n • a) ≤ (f a)`. -/
theorem nsmul_le {F α : Type*} [AddMonoid α] [FunLike F α R] [ZeroHomClass F α R]
[NonnegHomClass F α R] {f : F} (hna : IsNonarchimedean f) {n : ℕ} {a : α} :
f (n • a) ≤ f a := by
induction n with
| zero => simp
| succ n _ =>
rw [add_nsmul]
apply le_trans <| hna (n • a) (1 • a)
simpa
/-- If `f` is a nonnegative nonarchimedean function `α → R` such that `f 0 = 0`, then for every
`n : ℕ` and `a : α`, we have `f (n * a) ≤ (f a)`. -/
theorem nmul_le {F α : Type*} [NonAssocSemiring α] [FunLike F α R] [ZeroHomClass F α R]
[NonnegHomClass F α R] {f : F} (hna : IsNonarchimedean f) {n : ℕ} {a : α} :
f (n * a) ≤ f a := by
rw [← nsmul_eq_mul]
exact nsmul_le hna
lemma apply_natCast_le_one_of_isNonarchimedean {F α : Type*} [AddMonoidWithOne α] [FunLike F α R]
[ZeroHomClass F α R] [NonnegHomClass F α R] [OneHomClass F α R] {f : F}
(hna : IsNonarchimedean f) {n : ℕ} : f n ≤ 1 := by
rw [← nsmul_one n, ← map_one f]
exact nsmul_le hna
/-- If `f` is a nonarchimedean additive group seminorm on `α` with `f 1 = 1`, then for every `n : ℤ`
we have `f n ≤ 1`. -/
theorem apply_intCast_le_one_of_isNonarchimedean [IsStrictOrderedRing R]
{F α : Type*} [AddGroupWithOne α] [FunLike F α R]
[AddGroupSeminormClass F α R] [OneHomClass F α R] {f : F}
(hna : IsNonarchimedean f) {n : ℤ} : f n ≤ 1 := by
obtain ⟨a, rfl | rfl⟩ := Int.eq_nat_or_neg n <;>
simp [apply_natCast_le_one_of_isNonarchimedean hna]
lemma add_eq_right_of_lt {F α : Type*} [AddGroup α] [FunLike F α R]
[AddGroupSeminormClass F α R] {f : F} (hna : IsNonarchimedean f) {x y : α}
(h_lt : f x < f y) : f (x + y) = f y := by
by_contra! h
have h1 : f (x + y) ≤ f y := (hna x y).trans_eq (max_eq_right_of_lt h_lt)
apply lt_irrefl (f y)
calc
f y = f (-x + (x + y)) := by simp
_ ≤ max (f (-x)) (f (x + y)) := hna (-x) (x + y)
_ < max (f y) (f y) := by
rw [max_self, map_neg_eq_map]
exact max_lt h_lt <| lt_of_le_of_ne h1 h
_ = f y := max_self (f y)
lemma add_eq_left_of_lt {F α : Type*} [AddGroup α] [FunLike F α R]
[AddGroupSeminormClass F α R] {f : F} (hna : IsNonarchimedean f) {x y : α}
(h_lt : f y < f x) : f (x + y) = f x := by
by_contra! h
have h1 : f (x + y) ≤ f x := (hna x y).trans_eq (max_eq_left_of_lt h_lt)
apply lt_irrefl (f x)
calc
f x = f (x + y + -y) := by simp
_ ≤ max (f (x + y)) (f (-y)) := hna (x + y) (-y)
_ < max (f x) (f x) := by
rw [max_self, map_neg_eq_map]
apply max_lt (lt_of_le_of_ne h1 h) h_lt
_ = f x := max_self (f x)
/-- If `f` is a nonarchimedean additive group seminorm on `α` and `x y : α` are such that
`f x ≠ f y`, then `f (x + y) = max (f x) (f y)`. -/
theorem add_eq_max_of_ne {F α : Type*} [AddGroup α] [FunLike F α R]
[AddGroupSeminormClass F α R] {f : F} (hna : IsNonarchimedean f) {x y : α} (hne : f x ≠ f y) :
f (x + y) = max (f x) (f y) := by
rcases hne.lt_or_gt with h_lt | h_lt
· rw [add_eq_right_of_lt hna h_lt]
exact (max_eq_right_of_lt h_lt).symm
· rw [add_eq_left_of_lt hna h_lt]
exact (max_eq_left_of_lt h_lt).symm
omit [Semiring R] in
/-- Given a nonarchimedean function `α → R`, a function `g : β → α` and a nonempty multiset
`s : Multiset β`, we can always find `b : β` belonging to `s` such that
`f (t.sum g) ≤ f (g b)` . -/
theorem multiset_image_add_of_nonempty {α β : Type*} [AddCommMonoid α] [Nonempty β] {f : α → R}
(hna : IsNonarchimedean f) (g : β → α) {s : Multiset β} (hs : s ≠ 0) :
∃ b : β, (b ∈ s) ∧ f (Multiset.map g s).sum ≤ f (g b) := by
induction s using Multiset.induction_on with
| empty => contradiction
| cons a s h =>
simp only [Multiset.mem_cons, Multiset.map_cons, Multiset.sum_cons, exists_eq_or_imp]
by_cases h1 : s = 0
· simp [h1]
· obtain ⟨w, h2, h3⟩ := h h1
rcases le_max_iff.mp <| hna (g a) (Multiset.map g s).sum with h4 | h4
· exact .inl h4
· exact .inr ⟨w, h2, le_trans h4 h3⟩
omit [Semiring R] in
/-- Given a nonarchimedean function `α → R`, a function `g : β → α` and a nonempty finset
`t : Finset β`, we can always find `b : β` belonging to `t` such that `f (t.sum g) ≤ f (g b)` . -/
theorem finset_image_add_of_nonempty {α β : Type*} [AddCommMonoid α] [Nonempty β] {f : α → R}
(hna : IsNonarchimedean f) (g : β → α) {t : Finset β} (ht : t.Nonempty) :
∃ b ∈ t, f (t.sum g) ≤ f (g b) := by
apply multiset_image_add_of_nonempty hna
simp_all [Finset.nonempty_iff_ne_empty]
/-- Given a nonnegative nonarchimedean function `α → R` such that `f 0 = 0`, a function `g : β → α`
and a multiset `s : Multiset β`, we can always find `b : β`, belonging to `s` if `s` is nonempty,
such that `f (s.sum g) ≤ f (g b)` . -/
theorem multiset_image_add {F α β : Type*} [AddCommMonoid α] [FunLike F α R] [ZeroHomClass F α R]
[NonnegHomClass F α R] [Nonempty β] {f : F} (hna : IsNonarchimedean f) (g : β → α)
(s : Multiset β) : ∃ b : β, (s ≠ 0 → b ∈ s) ∧ f (Multiset.map g s).sum ≤ f (g b) := by
induction s using Multiset.induction_on with
| empty => simp
| cons a s h =>
obtain ⟨b, hb1, hb2⟩ := multiset_image_add_of_nonempty (s := a ::ₘ s)
hna g Multiset.cons_ne_zero
exact ⟨b, fun _ ↦ hb1, hb2⟩
/-- Given a nonnegative nonarchimedean function `α → R` such that `f 0 = 0`, a function `g : β → α`
and a finset `t : Finset β`, we can always find `b : β`, belonging to `t` if `t` is nonempty,
such that `f (t.sum g) ≤ f (g b)` . -/
theorem finset_image_add {F α β : Type*} [AddCommMonoid α] [FunLike F α R]
[ZeroHomClass F α R] [NonnegHomClass F α R] [Nonempty β] {f : F} (hna : IsNonarchimedean f)
(g : β → α) (t : Finset β) :
∃ b : β, (t.Nonempty → b ∈ t) ∧ f (t.sum g) ≤ f (g b) := by
have h1 : t.Nonempty ↔ t.val ≠ 0 := by simp [Finset.nonempty_iff_ne_empty]
rw [h1]
exact multiset_image_add hna g t.val
open Multiset in
theorem multiset_powerset_image_add [IsStrictOrderedRing R]
{F α : Type*} [CommRing α] [FunLike F α R]
[AddGroupSeminormClass F α R] {f : F} (hf_na : IsNonarchimedean f) (s : Multiset α) (m : ℕ) :
∃ t : Multiset α, card t = card s - m ∧ (∀ x : α, x ∈ t → x ∈ s) ∧
f (map prod (powersetCard (card s - m) s)).sum ≤ f t.prod := by
set g := fun t : Multiset α ↦ t.prod
obtain ⟨b, hb_in, hb_le⟩ := hf_na.multiset_image_add g (powersetCard (card s - m) s)
have hb : b ≤ s ∧ card b = card s - m := by
rw [← mem_powersetCard]
exact hb_in (card_pos.mp
(card_powersetCard (s.card - m) s ▸ Nat.choose_pos ((card s).sub_le m)))
exact ⟨b, hb.2, fun x hx ↦ mem_of_le hb.left hx, hb_le⟩
open Finset in
theorem finset_powerset_image_add [IsStrictOrderedRing R]
{F α β : Type*} [CommRing α] [FunLike F α R]
[AddGroupSeminormClass F α R] {f : F} (hf_na : IsNonarchimedean f) (s : Finset β)
(b : β → α) (m : ℕ) :
∃ u : powersetCard (s.card - m) s,
f ((powersetCard (s.card - m) s).sum fun t : Finset β ↦
t.prod fun i : β ↦ -b i) ≤ f (u.val.prod fun i : β ↦ -b i) := by
set g := fun t : Finset β ↦ t.prod fun i : β ↦ - b i
obtain ⟨b, hb_in, hb⟩ := hf_na.finset_image_add g (powersetCard (s.card - m) s)
exact ⟨⟨b, hb_in (powersetCard_nonempty.mpr (Nat.sub_le s.card m))⟩, hb⟩
omit [Semiring R] in
open Finset in
/-- Ultrametric inequality with `Finset.sum`. -/
lemma apply_sum_le_sup_of_isNonarchimedean {α β : Type*} [AddCommMonoid α] {f : α → R}
(nonarch : IsNonarchimedean f) {s : Finset β} (hnonempty : s.Nonempty) {l : β → α} :
f (∑ i ∈ s, l i) ≤ s.sup' hnonempty fun i => f (l i) := by
induction hnonempty using Nonempty.cons_induction with
| singleton i => simp
| cons i s _ hs hind =>
simp only [sum_cons, le_sup'_iff, mem_cons, exists_eq_or_imp]
rw [← le_sup'_iff hs]
rcases le_max_iff.mp <| nonarch (l i) (∑ i ∈ s, l i) with h₁ | h₂
· exact .inl h₁
· exact .inr <| le_trans h₂ hind
/-- If `f` is a nonarchimedean additive group seminorm on a commutative ring `α`, `n : ℕ`, and
`a b : α`, then we can find `m : ℕ` such that `m ≤ n` and
`f ((a + b) ^ n) ≤ (f (a ^ m)) * (f (b ^ (n - m)))`. -/
theorem add_pow_le {F α : Type*} [CommRing α] [FunLike F α R] [ZeroHomClass F α R]
[NonnegHomClass F α R] [SubmultiplicativeHomClass F α R] {f : F} (hna : IsNonarchimedean f)
(n : ℕ) (a b : α) : ∃ m < n + 1, f ((a + b) ^ n) ≤ f (a ^ m) * f (b ^ (n - m)) := by
obtain ⟨m, hm_lt, hM⟩ := finset_image_add hna
(fun m => a ^ m * b ^ (n - m) * ↑(n.choose m)) (Finset.range (n + 1))
simp only [Finset.nonempty_range_iff, ne_eq, Nat.succ_ne_zero, not_false_iff, Finset.mem_range,
forall_true_left] at hm_lt
refine ⟨m, hm_lt, ?_⟩
simp only [← add_pow] at hM
rw [mul_comm] at hM
exact le_trans hM (le_trans (nmul_le hna) (map_mul_le_mul _ _ _))
end IsNonarchimedean |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Cone.lean | import Mathlib.Algebra.Order.Group.Cone
import Mathlib.Algebra.Ring.Subsemiring.Order
/-!
# Construct ordered rings from rings with a specified positive cone.
In this file we provide the structure `RingCone`
that encodes axioms of `OrderedRing` and `LinearOrderedRing`
in terms of the subset of non-negative elements.
We also provide constructors that convert between
cones in rings and the corresponding ordered rings.
-/
/-- `RingConeClass S R` says that `S` is a type of cones in `R`. -/
class RingConeClass (S : Type*) (R : outParam Type*) [Ring R] [SetLike S R] : Prop
extends AddGroupConeClass S R, SubsemiringClass S R
/-- A (positive) cone in a ring is a subsemiring that
does not contain both `a` and `-a` for any nonzero `a`.
This is equivalent to being the set of non-negative elements of
some order making the ring into a partially ordered ring. -/
structure RingCone (R : Type*) [Ring R] extends Subsemiring R, AddGroupCone R
/-- Interpret a cone in a ring as a cone in the underlying additive group. -/
add_decl_doc RingCone.toAddGroupCone
instance RingCone.instSetLike (R : Type*) [Ring R] : SetLike (RingCone R) R where
coe C := C.carrier
coe_injective' p q h := by cases p; cases q; congr; exact SetLike.ext' h
instance RingCone.instRingConeClass (R : Type*) [Ring R] :
RingConeClass (RingCone R) R where
add_mem {C} := C.add_mem'
zero_mem {C} := C.zero_mem'
mul_mem {C} := C.mul_mem'
one_mem {C} := C.one_mem'
eq_zero_of_mem_of_neg_mem {C} := C.eq_zero_of_mem_of_neg_mem'
@[simp]
theorem RingCone.mem_mk {R : Type*} [Ring R] {toSubsemiring : Subsemiring R}
(eq_zero_of_mem_of_neg_mem) {x : R} :
x ∈ mk toSubsemiring eq_zero_of_mem_of_neg_mem ↔ x ∈ toSubsemiring := .rfl
@[simp]
theorem RingCone.coe_set_mk {R : Type*} [Ring R] {toSubsemiring : Subsemiring R}
(eq_zero_of_mem_of_neg_mem) :
(mk toSubsemiring eq_zero_of_mem_of_neg_mem : Set R) = toSubsemiring := rfl
namespace RingCone
variable {T : Type*} [Ring T] [PartialOrder T] [IsOrderedRing T] {a : T}
variable (T) in
/-- Construct a cone from the set of non-negative elements of a partially ordered ring. -/
def nonneg : RingCone T where
__ := Subsemiring.nonneg T
eq_zero_of_mem_of_neg_mem' {a} := by simpa using ge_antisymm
@[simp] lemma nonneg_toSubsemiring : (nonneg T).toSubsemiring = .nonneg T := rfl
@[simp] lemma nonneg_toAddGroupCone : (nonneg T).toAddGroupCone = .nonneg T := rfl
@[simp] lemma mem_nonneg : a ∈ nonneg T ↔ 0 ≤ a := Iff.rfl
@[simp, norm_cast] lemma coe_nonneg : nonneg T = {x : T | 0 ≤ x} := rfl
instance nonneg.hasMemOrNegMem {T : Type*} [Ring T] [LinearOrder T] [IsOrderedRing T] :
HasMemOrNegMem (nonneg T) where
mem_or_neg_mem := mem_or_neg_mem (AddGroupCone.nonneg T)
@[deprecated (since := "2025-08-21")] alias nonneg.isMaxCone := nonneg.hasMemOrNegMem
end RingCone
variable {S R : Type*} [Ring R] [SetLike S R] (C : S)
/-- Construct a partially ordered ring by designating a cone in a ring. -/
lemma IsOrderedRing.mkOfCone [RingConeClass S R] :
letI _ : PartialOrder R := .mkOfAddGroupCone C
IsOrderedRing R :=
letI _ : PartialOrder R := .mkOfAddGroupCone C
haveI : IsOrderedAddMonoid R := .mkOfCone C
haveI : ZeroLEOneClass R := ⟨show _ ∈ C by simp⟩
.of_mul_nonneg fun x y xnn ynn ↦ show _ ∈ C by simpa using mul_mem xnn ynn |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Finset.lean | import Mathlib.Algebra.Order.Ring.Canonical
import Mathlib.Data.Finset.Lattice.Fold
import Mathlib.Data.Nat.Cast.Order.Ring
/-!
# `Finset.sup` and ring operations
-/
open Finset
namespace Nat
variable {ι R : Type*}
section LinearOrderedSemiring
variable [Semiring R] [LinearOrder R] [IsStrictOrderedRing R] {s : Finset ι}
set_option linter.docPrime false in
@[simp, norm_cast]
lemma cast_finsetSup' (f : ι → ℕ) (hs) : ((s.sup' hs f : ℕ) : R) = s.sup' hs fun i ↦ (f i : R) :=
comp_sup'_eq_sup'_comp _ _ cast_max
set_option linter.docPrime false in
@[simp, norm_cast]
lemma cast_finsetInf' (f : ι → ℕ) (hs) : (↑(s.inf' hs f) : R) = s.inf' hs fun i ↦ (f i : R) :=
comp_inf'_eq_inf'_comp _ _ cast_min
@[simp, norm_cast]
lemma cast_finsetSup [OrderBot R] [CanonicallyOrderedAdd R] (s : Finset ι) (f : ι → ℕ) :
(↑(s.sup f) : R) = s.sup fun i ↦ (f i : R) :=
comp_sup_eq_sup_comp _ cast_max (by simp)
end LinearOrderedSemiring
end Nat
section
variable {R ι : Type*} [LinearOrder R] [NonUnitalNonAssocSemiring R]
[CanonicallyOrderedAdd R] [OrderBot R]
lemma Finset.mul_sup₀ (s : Finset ι) (f : ι → R) (a : R) :
a * s.sup f = s.sup (a * f ·) := by
classical
induction s using Finset.induction with
| empty => simp
| insert _ _ _ IH => simp only [sup_insert, mul_max, ← IH]
/-- Also see `Finset.sup'_mul₀` for a version for `GroupWithZero`s. -/
lemma Finset.sup_mul₀ (s : Finset ι) (f : ι → R) (a : R) :
s.sup f * a = s.sup (f · * a) := by
classical
induction s using Finset.induction with
| empty => simp
| insert _ _ _ IH => simp only [sup_insert, max_mul, ← IH]
end |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Basic.lean | import Mathlib.Algebra.Order.Monoid.Unbundled.Pow
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Ring.Parity
import Mathlib.Tactic.Bound.Attribute
/-!
# Basic lemmas about ordered rings
-/
-- We should need only a minimal development of sets in order to get here.
assert_not_exists Set.Subsingleton
open Function Int
variable {α M R : Type*}
theorem IsSquare.nonneg [Semiring R] [LinearOrder R]
[ExistsAddOfLE R] [PosMulMono R] [AddLeftMono R]
{x : R} (h : IsSquare x) : 0 ≤ x := by
rcases h with ⟨y, rfl⟩
exact mul_self_nonneg y
@[simp]
lemma not_isSquare_of_neg [Semiring R] [LinearOrder R]
[ExistsAddOfLE R] [PosMulMono R] [AddLeftMono R]
{x : R} (h : x < 0) : ¬ IsSquare x :=
(h.not_ge ·.nonneg)
namespace MonoidHom
variable [Ring R] [Monoid M] [LinearOrder M] [MulLeftMono M] (f : R →* M)
theorem map_neg_one : f (-1) = 1 :=
(pow_eq_one_iff (Nat.succ_ne_zero 1)).1 <| by rw [← map_pow, neg_one_sq, map_one]
@[simp]
theorem map_neg (x : R) : f (-x) = f x := by rw [← neg_one_mul, map_mul, map_neg_one, one_mul]
theorem map_sub_swap (x y : R) : f (x - y) = f (y - x) := by rw [← map_neg, neg_sub]
end MonoidHom
section OrderedSemiring
variable [Semiring R] [PartialOrder R] [IsOrderedRing R] {a b x y : R} {n : ℕ}
theorem pow_add_pow_le (hx : 0 ≤ x) (hy : 0 ≤ y) (hn : n ≠ 0) : x ^ n + y ^ n ≤ (x + y) ^ n := by
rcases Nat.exists_eq_add_one_of_ne_zero hn with ⟨k, rfl⟩
induction k with
| zero => simp only [zero_add, pow_one, le_refl]
| succ k ih =>
let n := k.succ
have h1 := add_nonneg (mul_nonneg hx (pow_nonneg hy n)) (mul_nonneg hy (pow_nonneg hx n))
have h2 := add_nonneg hx hy
calc
x ^ (n + 1) + y ^ (n + 1) ≤ x * x ^ n + y * y ^ n + (x * y ^ n + y * x ^ n) := by
rw [pow_succ' _ n, pow_succ' _ n]
exact le_add_of_nonneg_right h1
_ = (x + y) * (x ^ n + y ^ n) := by
rw [add_mul, mul_add, mul_add, add_comm (y * x ^ n), ← add_assoc, ← add_assoc,
add_assoc (x * x ^ n) (x * y ^ n), add_comm (x * y ^ n) (y * y ^ n), ← add_assoc]
_ ≤ (x + y) ^ (n + 1) := by
rw [pow_succ' _ n]
exact mul_le_mul_of_nonneg_left (ih (Nat.succ_ne_zero k)) h2
attribute [bound] pow_le_one₀ one_le_pow₀
lemma pow_add_pow_le' (ha : 0 ≤ a) (hb : 0 ≤ b) : a ^ n + b ^ n ≤ 2 * (a + b) ^ n := by
rw [two_mul]
gcongr <;> try assumption
exacts [le_add_of_nonneg_right hb, le_add_of_nonneg_left ha]
end OrderedSemiring
section StrictOrderedRing
variable [Ring R] [PartialOrder R] [IsStrictOrderedRing R] {a : R}
lemma sq_pos_of_neg (ha : a < 0) : 0 < a ^ 2 := by rw [sq]; exact mul_pos_of_neg_of_neg ha ha
end StrictOrderedRing
section LinearOrderedSemiring
section IsOrderedRing
variable [Semiring R] [LinearOrder R] [IsOrderedRing R] [ExistsAddOfLE R] {m n : ℕ}
protected lemma Even.pow_nonneg (hn : Even n) (a : R) : 0 ≤ a ^ n := by
obtain ⟨k, rfl⟩ := hn; rw [pow_add]; exact mul_self_nonneg _
lemma pow_four_le_pow_two_of_pow_two_le {a b : R} (h : a ^ 2 ≤ b) : a ^ 4 ≤ b ^ 2 :=
(pow_mul a 2 2).symm ▸ pow_le_pow_left₀ (sq_nonneg a) h 2
end IsOrderedRing
variable [Semiring R] [LinearOrder R] [IsStrictOrderedRing R] {a b : R} {m n : ℕ}
/-- A function `f : α → R` is nonarchimedean if it satisfies the ultrametric inequality
`f (a + b) ≤ max (f a) (f b)` for all `a b : α`. -/
def IsNonarchimedean {α : Type*} [Add α] (f : α → R) : Prop := ∀ a b : α, f (a + b) ≤ f a ⊔ f b
/-!
### Lemmas for canonically linear ordered semirings or linear ordered rings
The slightly unusual typeclass assumptions `[LinearOrderedSemiring R] [ExistsAddOfLE R]` cover two
more familiar settings:
* `[LinearOrderedRing R]`, e.g. `ℤ`, `ℚ` or `ℝ`
* `[CanonicallyLinearOrderedSemiring R]` (although we don't actually have this typeclass), e.g. `ℕ`,
`ℚ≥0` or `ℝ≥0`
-/
variable [ExistsAddOfLE R]
lemma add_sq_le : (a + b) ^ 2 ≤ 2 * (a ^ 2 + b ^ 2) := by
calc
(a + b) ^ 2 = a ^ 2 + b ^ 2 + (a * b + b * a) := by
simp_rw [pow_succ', pow_zero, mul_one, add_mul, mul_add, add_comm (b * a), add_add_add_comm]
_ ≤ a ^ 2 + b ^ 2 + (a * a + b * b) := add_le_add_left ?_ _
_ = _ := by simp_rw [pow_succ', pow_zero, mul_one, two_mul]
cases le_total a b
· exact mul_add_mul_le_mul_add_mul ‹_› ‹_›
· exact mul_add_mul_le_mul_add_mul' ‹_› ‹_›
-- TODO: Use `gcongr`, `positivity`, `ring` once those tactics are made available here
lemma add_pow_le (ha : 0 ≤ a) (hb : 0 ≤ b) : ∀ n, (a + b) ^ n ≤ 2 ^ (n - 1) * (a ^ n + b ^ n)
| 0 => by simp
| 1 => by simp
| n + 2 => by
rw [pow_succ]
calc
_ ≤ 2 ^ n * (a ^ (n + 1) + b ^ (n + 1)) * (a + b) :=
mul_le_mul_of_nonneg_right (add_pow_le ha hb (n + 1)) <| add_nonneg ha hb
_ = 2 ^ n * (a ^ (n + 2) + b ^ (n + 2) + (a ^ (n + 1) * b + b ^ (n + 1) * a)) := by
rw [mul_assoc, mul_add, add_mul, add_mul, ← pow_succ, ← pow_succ, add_comm _ (b ^ _),
add_add_add_comm, add_comm (_ * a)]
_ ≤ 2 ^ n * (a ^ (n + 2) + b ^ (n + 2) + (a ^ (n + 1) * a + b ^ (n + 1) * b)) := by
gcongr _ * (_ + _ + ?_)
· exact pow_nonneg zero_le_two _
obtain hab | hba := le_total a b
· exact mul_add_mul_le_mul_add_mul (by gcongr; exact ha) hab
· exact mul_add_mul_le_mul_add_mul' (by gcongr; exact hb) hba
_ = _ := by simp only [← pow_succ, ← two_mul, ← mul_assoc]; rfl
protected lemma Even.add_pow_le (hn : Even n) :
(a + b) ^ n ≤ 2 ^ (n - 1) * (a ^ n + b ^ n) := by
obtain ⟨n, rfl⟩ := hn
rw [← two_mul, pow_mul]
calc
_ ≤ (2 * (a ^ 2 + b ^ 2)) ^ n := pow_le_pow_left₀ (sq_nonneg _) add_sq_le _
_ = 2 ^ n * (a ^ 2 + b ^ 2) ^ n := by -- TODO: Should be `Nat.cast_commute`
rw [Commute.mul_pow]; simp [Commute, SemiconjBy, two_mul, mul_two]
_ ≤ 2 ^ n * (2 ^ (n - 1) * ((a ^ 2) ^ n + (b ^ 2) ^ n)) := mul_le_mul_of_nonneg_left
(add_pow_le (sq_nonneg _) (sq_nonneg _) _) <| pow_nonneg (zero_le_two (α := R)) _
_ = _ := by
simp only [← mul_assoc, ← pow_add, ← pow_mul]
cases n
· rfl
· simp [Nat.two_mul]
lemma Even.pow_pos (hn : Even n) (ha : a ≠ 0) : 0 < a ^ n :=
(hn.pow_nonneg _).lt_of_ne' (pow_ne_zero _ ha)
lemma Even.pow_pos_iff (hn : Even n) (h₀ : n ≠ 0) : 0 < a ^ n ↔ a ≠ 0 := by
obtain ⟨k, rfl⟩ := hn; rw [pow_add, mul_self_pos, pow_ne_zero_iff (by simpa using h₀)]
lemma Odd.pow_neg_iff (hn : Odd n) : a ^ n < 0 ↔ a < 0 := by
refine ⟨lt_imp_lt_of_le_imp_le (pow_nonneg · _), fun ha ↦ ?_⟩
obtain ⟨k, rfl⟩ := hn
rw [pow_succ]
exact mul_neg_of_pos_of_neg ((even_two_mul _).pow_pos ha.ne) ha
lemma Odd.pow_nonneg_iff (hn : Odd n) : 0 ≤ a ^ n ↔ 0 ≤ a :=
le_iff_le_iff_lt_iff_lt.2 hn.pow_neg_iff
lemma Odd.pow_nonpos_iff (hn : Odd n) : a ^ n ≤ 0 ↔ a ≤ 0 := by
rw [le_iff_lt_or_eq, le_iff_lt_or_eq, hn.pow_neg_iff, pow_eq_zero_iff]
rintro rfl; simp [Odd, eq_comm (a := 0)] at hn
lemma Odd.pow_pos_iff (hn : Odd n) : 0 < a ^ n ↔ 0 < a := lt_iff_lt_of_le_iff_le hn.pow_nonpos_iff
alias ⟨_, Odd.pow_nonpos⟩ := Odd.pow_nonpos_iff
alias ⟨_, Odd.pow_neg⟩ := Odd.pow_neg_iff
lemma Odd.strictMono_pow (hn : Odd n) : StrictMono fun a : R => a ^ n := by
have hn₀ : n ≠ 0 := by rintro rfl; simp [Odd, eq_comm (a := 0)] at hn
intro a b hab
obtain ha | ha := le_total 0 a
· exact pow_lt_pow_left₀ hab ha hn₀
obtain hb | hb := lt_or_ge 0 b
· exact (hn.pow_nonpos ha).trans_lt (pow_pos hb _)
obtain ⟨c, hac⟩ := exists_add_of_le ha
obtain ⟨d, hbd⟩ := exists_add_of_le hb
have hd := nonneg_of_le_add_right (hb.trans_eq hbd)
refine lt_of_add_lt_add_right (a := c ^ n + d ^ n) ?_
dsimp
calc
a ^ n + (c ^ n + d ^ n) = d ^ n := by
rw [← add_assoc, hn.pow_add_pow_eq_zero hac.symm, zero_add]
_ < c ^ n := pow_lt_pow_left₀ ?_ hd hn₀
_ = b ^ n + (c ^ n + d ^ n) := by rw [add_left_comm, hn.pow_add_pow_eq_zero hbd.symm, add_zero]
refine lt_of_add_lt_add_right (a := a + b) ?_
rwa [add_rotate', ← hbd, add_zero, add_left_comm, ← add_assoc, ← hac, zero_add]
lemma Odd.pow_injective {n : ℕ} (hn : Odd n) : Injective (· ^ n : R → R) :=
hn.strictMono_pow.injective
lemma Odd.pow_lt_pow {n : ℕ} (hn : Odd n) {a b : R} : a ^ n < b ^ n ↔ a < b :=
hn.strictMono_pow.lt_iff_lt
lemma Odd.pow_le_pow {n : ℕ} (hn : Odd n) {a b : R} : a ^ n ≤ b ^ n ↔ a ≤ b :=
hn.strictMono_pow.le_iff_le
lemma Odd.pow_inj {n : ℕ} (hn : Odd n) {a b : R} : a ^ n = b ^ n ↔ a = b :=
hn.pow_injective.eq_iff
lemma sq_pos_iff {a : R} : 0 < a ^ 2 ↔ a ≠ 0 := even_two.pow_pos_iff two_ne_zero
alias ⟨_, sq_pos_of_ne_zero⟩ := sq_pos_iff
alias pow_two_pos_of_ne_zero := sq_pos_of_ne_zero
end LinearOrderedSemiring |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/InjSurj.lean | import Mathlib.Algebra.Order.Monoid.Basic
import Mathlib.Algebra.Order.Ring.Defs
/-!
# Pulling back ordered rings along injective maps
-/
variable {R S : Type*}
namespace Function.Injective
variable [Semiring R] [PartialOrder R]
/-- Pullback an `IsOrderedRing` under an injective map. -/
protected lemma isOrderedRing [IsOrderedRing R] [Semiring S] [PartialOrder S]
(f : S → R) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(le : ∀ {x y}, f x ≤ f y ↔ x ≤ y) :
IsOrderedRing S where
__ := Function.Injective.isOrderedAddMonoid f add le
zero_le_one := by simp only [← le, zero, one, zero_le_one]
mul_le_mul_of_nonneg_left a ha b c hbc := by
rw [← le, mul, mul]; refine mul_le_mul_of_nonneg_left (le.2 hbc) ?_; rwa [← zero, le]
mul_le_mul_of_nonneg_right a ha b c hbc := by
rw [← le, mul, mul]; refine mul_le_mul_of_nonneg_right (le.2 hbc) ?_; rwa [← zero, le]
/-- Pullback a `IsStrictOrderedRing` under an injective map. -/
protected lemma isStrictOrderedRing [IsStrictOrderedRing R] [Semiring S] [PartialOrder S]
(f : S → R) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(le : ∀ {x y}, f x ≤ f y ↔ x ≤ y) (lt : ∀ {x y}, f x < f y ↔ x < y) :
IsStrictOrderedRing S where
__ := Function.Injective.isOrderedCancelAddMonoid f add le
__ := domain_nontrivial f zero one
__ := Function.Injective.isOrderedRing f zero one add mul le
mul_lt_mul_of_pos_left a ha b c hbc := by
rw [← lt, mul, mul]; refine mul_lt_mul_of_pos_left (lt.2 hbc) ?_; rwa [← zero, lt]
mul_lt_mul_of_pos_right a ha b c hbc := by
rw [← lt, mul, mul]; refine mul_lt_mul_of_pos_right (lt.2 hbc) ?_; rwa [← zero, lt]
end Function.Injective |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Defs.lean | import Mathlib.Algebra.Order.Ring.Unbundled.Basic
import Mathlib.Algebra.CharZero.Defs
import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic
import Mathlib.Algebra.Order.Monoid.NatCast
import Mathlib.Algebra.Order.Monoid.Unbundled.MinMax
import Mathlib.Algebra.Ring.Defs
import Mathlib.Algebra.Ring.GrindInstances
import Mathlib.Tactic.Tauto
import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE
/-!
# Ordered rings and semirings
This file develops the basics of ordered (semi)rings.
Each typeclass here comprises
* an algebraic class (`Semiring`, `CommSemiring`, `Ring`, `CommRing`)
* an order class (`PartialOrder`, `LinearOrder`)
* assumptions on how both interact ((strict) monotonicity, canonicity)
For short,
* "`+` respects `≤`" means "monotonicity of addition"
* "`+` respects `<`" means "strict monotonicity of addition"
* "`*` respects `≤`" means "monotonicity of multiplication by a nonnegative number".
* "`*` respects `<`" means "strict monotonicity of multiplication by a positive number".
## Typeclasses
* `OrderedSemiring`: Semiring with a partial order such that `+` and `*` respect `≤`.
* `StrictOrderedSemiring`: Nontrivial semiring with a partial order such that `+` and `*` respects
`<`.
* `OrderedCommSemiring`: Commutative semiring with a partial order such that `+` and `*` respect
`≤`.
* `StrictOrderedCommSemiring`: Nontrivial commutative semiring with a partial order such that `+`
and `*` respect `<`.
* `OrderedRing`: Ring with a partial order such that `+` respects `≤` and `*` respects `<`.
* `OrderedCommRing`: Commutative ring with a partial order such that `+` respects `≤` and
`*` respects `<`.
* `LinearOrderedSemiring`: Nontrivial semiring with a linear order such that `+` respects `≤` and
`*` respects `<`.
* `LinearOrderedCommSemiring`: Nontrivial commutative semiring with a linear order such that `+`
respects `≤` and `*` respects `<`.
* `LinearOrderedRing`: Nontrivial ring with a linear order such that `+` respects `≤` and `*`
respects `<`.
* `LinearOrderedCommRing`: Nontrivial commutative ring with a linear order such that `+` respects
`≤` and `*` respects `<`.
## Hierarchy
The hardest part of proving order lemmas might be to figure out the correct generality and its
corresponding typeclass. Here's an attempt at demystifying it. For each typeclass, we list its
immediate predecessors and what conditions are added to each of them.
* `OrderedSemiring`
- `OrderedAddCommMonoid` & multiplication & `*` respects `≤`
- `Semiring` & partial order structure & `+` respects `≤` & `*` respects `≤`
* `StrictOrderedSemiring`
- `OrderedCancelAddCommMonoid` & multiplication & `*` respects `<` & nontriviality
- `OrderedSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedCommSemiring`
- `OrderedSemiring` & commutativity of multiplication
- `CommSemiring` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedCommSemiring`
- `StrictOrderedSemiring` & commutativity of multiplication
- `OrderedCommSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedRing`
- `OrderedSemiring` & additive inverses
- `OrderedAddCommGroup` & multiplication & `*` respects `<`
- `Ring` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedRing`
- `StrictOrderedSemiring` & additive inverses
- `OrderedSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedCommRing`
- `OrderedRing` & commutativity of multiplication
- `OrderedCommSemiring` & additive inverses
- `CommRing` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedCommRing`
- `StrictOrderedCommSemiring` & additive inverses
- `StrictOrderedRing` & commutativity of multiplication
- `OrderedCommRing` & `+` respects `<` & `*` respects `<` & nontriviality
* `LinearOrderedSemiring`
- `StrictOrderedSemiring` & totality of the order
- `LinearOrderedAddCommMonoid` & multiplication & nontriviality & `*` respects `<`
* `LinearOrderedCommSemiring`
- `StrictOrderedCommSemiring` & totality of the order
- `LinearOrderedSemiring` & commutativity of multiplication
* `LinearOrderedRing`
- `StrictOrderedRing` & totality of the order
- `LinearOrderedSemiring` & additive inverses
- `LinearOrderedAddCommGroup` & multiplication & `*` respects `<`
- `Ring` & `IsDomain` & linear order structure
* `LinearOrderedCommRing`
- `StrictOrderedCommRing` & totality of the order
- `LinearOrderedRing` & commutativity of multiplication
- `LinearOrderedCommSemiring` & additive inverses
- `CommRing` & `IsDomain` & linear order structure
-/
assert_not_exists MonoidHom
open Function
universe u
variable {R : Type u}
-- TODO: assume weaker typeclasses
/-- An ordered semiring is a semiring with a partial order such that addition is monotone and
multiplication by a nonnegative number is monotone. -/
class IsOrderedRing (R : Type*) [Semiring R] [PartialOrder R] extends
IsOrderedAddMonoid R, ZeroLEOneClass R, PosMulMono R, MulPosMono R where
-- See note [lower instance priority]
attribute [instance 100] IsOrderedRing.toZeroLEOneClass
attribute [instance 200] IsOrderedRing.toPosMulMono
attribute [instance 200] IsOrderedRing.toMulPosMono
/-- A strict ordered semiring is a nontrivial semiring with a partial order such that addition is
strictly monotone and multiplication by a positive number is strictly monotone. -/
class IsStrictOrderedRing (R : Type*) [Semiring R] [PartialOrder R] extends
IsOrderedCancelAddMonoid R, ZeroLEOneClass R, Nontrivial R, PosMulStrictMono R,
MulPosStrictMono R where
-- See note [lower instance priority]
attribute [instance 100] IsStrictOrderedRing.toZeroLEOneClass
attribute [instance 100] IsStrictOrderedRing.toNontrivial
attribute [instance 200] IsStrictOrderedRing.toPosMulStrictMono
attribute [instance 200] IsStrictOrderedRing.toMulPosStrictMono
instance [Semiring R] [PartialOrder R] [IsStrictOrderedRing R] : Lean.Grind.OrderedRing R where
zero_lt_one := zero_lt_one
mul_lt_mul_of_pos_left := mul_lt_mul_of_pos_left
mul_lt_mul_of_pos_right := mul_lt_mul_of_pos_right
lemma IsOrderedRing.of_mul_nonneg [Ring R] [PartialOrder R] [IsOrderedAddMonoid R]
[ZeroLEOneClass R] (mul_nonneg : ∀ a b : R, 0 ≤ a → 0 ≤ b → 0 ≤ a * b) :
IsOrderedRing R where
mul_le_mul_of_nonneg_left a ha b c hbc := by
simpa only [mul_sub, sub_nonneg] using mul_nonneg _ _ ha (sub_nonneg.2 hbc)
mul_le_mul_of_nonneg_right a ha b c hbc := by
simpa only [sub_mul, sub_nonneg] using mul_nonneg _ _ (sub_nonneg.2 hbc) ha
lemma IsStrictOrderedRing.of_mul_pos [Ring R] [PartialOrder R] [IsOrderedAddMonoid R]
[ZeroLEOneClass R] [Nontrivial R] (mul_pos : ∀ a b : R, 0 < a → 0 < b → 0 < a * b) :
IsStrictOrderedRing R where
mul_lt_mul_of_pos_left a ha b c hbc := by
simpa only [mul_sub, sub_pos] using mul_pos _ _ ha (sub_pos.2 hbc)
mul_lt_mul_of_pos_right a ha b c hbc := by
simpa only [sub_mul, sub_pos] using mul_pos _ _ (sub_pos.2 hbc) ha
-- see Note [lower instance priority]
/-- Turn an ordered domain into a strict ordered ring. -/
instance (priority := 50) IsOrderedRing.toIsStrictOrderedRing (R : Type*)
[Ring R] [PartialOrder R] [IsOrderedRing R] [NoZeroDivisors R] [Nontrivial R] :
IsStrictOrderedRing R :=
.of_mul_pos fun _ _ ap bp ↦ (mul_nonneg ap.le bp.le).lt_of_ne' (mul_ne_zero ap.ne' bp.ne')
section IsStrictOrderedRing
variable [Semiring R] [PartialOrder R] [IsStrictOrderedRing R]
-- see Note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.toIsOrderedRing : IsOrderedRing R where
__ := ‹IsStrictOrderedRing R›
/-- This is not an instance, as it would loop with `NeZero.charZero_one`. -/
theorem AddMonoidWithOne.toCharZero {R}
[AddMonoidWithOne R] [PartialOrder R] [ZeroLEOneClass R]
[NeZero (1 : R)] [AddLeftStrictMono R] : CharZero R where
cast_injective :=
(strictMono_nat_of_lt_succ fun n ↦ by rw [Nat.cast_succ]; apply lt_add_one).injective
-- see Note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.toCharZero :
CharZero R := AddMonoidWithOne.toCharZero
-- see Note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.toNoMaxOrder : NoMaxOrder R :=
⟨fun a => ⟨a + 1, lt_add_of_pos_right _ one_pos⟩⟩
end IsStrictOrderedRing
section LinearOrder
variable [Semiring R] [LinearOrder R] [IsStrictOrderedRing R] [ExistsAddOfLE R]
-- See note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.noZeroDivisors : NoZeroDivisors R where
eq_zero_or_eq_zero_of_mul_eq_zero {a b} hab := by
contrapose! hab
obtain ha | ha := hab.1.lt_or_gt <;> obtain hb | hb := hab.2.lt_or_gt
exacts [(mul_pos_of_neg_of_neg ha hb).ne', (mul_neg_of_neg_of_pos ha hb).ne,
(mul_neg_of_pos_of_neg ha hb).ne, (mul_pos ha hb).ne']
-- Note that we can't use `NoZeroDivisors.to_isDomain` since we are merely in a semiring.
-- See note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.isDomain : IsDomain R where
mul_left_cancel_of_ne_zero {a} ha _ _ h := by
obtain ha | ha := ha.lt_or_gt
exacts [(strictAnti_mul_left ha).injective h, (strictMono_mul_left_of_pos ha).injective h]
mul_right_cancel_of_ne_zero {a} ha _ _ h := by
obtain ha | ha := ha.lt_or_gt
exacts [(strictAnti_mul_right ha).injective h, (strictMono_mul_right_of_pos ha).injective h]
end LinearOrder
/-! Note that `OrderDual` does not satisfy any of the ordered ring typeclasses due to the
`zero_le_one` field. -/
section OrderedRing
variable [Ring R] [PartialOrder R] [IsOrderedRing R] {a b c : R}
lemma one_add_le_one_sub_mul_one_add (h : a + b + b * c ≤ c) : 1 + a ≤ (1 - b) * (1 + c) := by
rw [one_sub_mul, mul_one_add, le_sub_iff_add_le, add_assoc, ← add_assoc a]
gcongr
lemma one_add_le_one_add_mul_one_sub (h : a + c + b * c ≤ b) : 1 + a ≤ (1 + b) * (1 - c) := by
rw [mul_one_sub, one_add_mul, le_sub_iff_add_le, add_assoc, ← add_assoc a]
gcongr
lemma one_sub_le_one_sub_mul_one_add (h : b + b * c ≤ a + c) : 1 - a ≤ (1 - b) * (1 + c) := by
rw [one_sub_mul, mul_one_add, sub_le_sub_iff, add_assoc, add_comm c]
gcongr
lemma one_sub_le_one_add_mul_one_sub (h : c + b * c ≤ a + b) : 1 - a ≤ (1 + b) * (1 - c) := by
rw [mul_one_sub, one_add_mul, sub_le_sub_iff, add_assoc, add_comm b]
gcongr
instance [Nontrivial R] : NoMaxOrder R := ⟨fun a ↦ ⟨a + 1, by simp⟩⟩
instance [Nontrivial R] : NoMinOrder R := ⟨fun a ↦ ⟨a - 1, by simp⟩⟩
end OrderedRing |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/GeomSum.lean | import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Ring.GeomSum
/-!
# Partial sums of geometric series in an ordered ring
This file upper- and lower-bounds the values of the geometric series $\sum_{i=0}^{n-1} x^i$ and
$\sum_{i=0}^{n-1} x^i y^{n-1-i}$ and variants thereof. We also provide some bounds on the
"geometric" sum of `a/b^i` where `a b : ℕ`.
-/
assert_not_exists Field
open Finset MulOpposite
variable {R : Type*}
section Semiring
variable [Semiring R] [PartialOrder R] [IsStrictOrderedRing R] {n : ℕ} {x : R}
lemma geom_sum_pos (hx : 0 ≤ x) (hn : n ≠ 0) : 0 < ∑ i ∈ range n, x ^ i :=
sum_pos' (fun _ _ => pow_nonneg hx _) ⟨0, mem_range.2 hn.bot_lt, by simp⟩
end Semiring
section Ring
variable [Ring R]
section PartialOrder
variable [PartialOrder R]
section IsOrderedRing
variable [IsOrderedRing R] {x : R}
lemma geom_sum_alternating_of_le_neg_one (hx : x + 1 ≤ 0) (n : ℕ) :
if Even n then (∑ i ∈ range n, x ^ i) ≤ 0 else 1 ≤ ∑ i ∈ range n, x ^ i := by
have hx0 : x ≤ 0 := (le_add_of_nonneg_right zero_le_one).trans hx
induction n with
| zero => simp only [range_zero, sum_empty, le_refl, ite_true, Even.zero]
| succ n ih =>
simp only [Nat.even_add_one, geom_sum_succ]
split_ifs at ih ⊢ with h
· rw [le_add_iff_nonneg_left]
exact mul_nonneg_of_nonpos_of_nonpos hx0 ih
· grw [← hx]
gcongr
simpa only [mul_one] using mul_le_mul_of_nonpos_left ih hx0
end IsOrderedRing
section IsStrictOrderedRing
variable [IsStrictOrderedRing R] {n : ℕ} {x : R}
lemma geom_sum_pos_and_lt_one (hx : x < 0) (hx' : 0 < x + 1) (hn : 1 < n) :
0 < ∑ i ∈ range n, x ^ i ∧ ∑ i ∈ range n, x ^ i < 1 := by
refine Nat.le_induction ?_ ?_ n (show 2 ≤ n from hn)
· rw [geom_sum_two]
exact ⟨hx', (add_lt_iff_neg_right _).2 hx⟩
clear hn
intro n _ ihn
rw [geom_sum_succ, add_lt_iff_neg_right, ← neg_lt_iff_pos_add', neg_mul_eq_neg_mul]
exact
⟨mul_lt_one_of_nonneg_of_lt_one_left (neg_nonneg.2 hx.le) (neg_lt_iff_pos_add'.2 hx') ihn.2.le,
mul_neg_of_neg_of_pos hx ihn.1⟩
lemma geom_sum_alternating_of_lt_neg_one (hx : x + 1 < 0) (hn : 1 < n) :
if Even n then ∑ i ∈ range n, x ^ i < 0 else 1 < ∑ i ∈ range n, x ^ i := by
have hx0 : x < 0 := (le_add_of_nonneg_right zero_le_one).trans_lt hx
refine Nat.le_induction ?_ ?_ n (show 2 ≤ n from hn)
· simp only [geom_sum_two, lt_add_iff_pos_left, ite_true, hx, even_two]
clear hn
intro n _ ihn
simp only [Nat.even_add_one, geom_sum_succ]
split_ifs at ihn ⊢ with hn'
· rw [lt_add_iff_pos_left]
exact mul_pos_of_neg_of_neg hx0 ihn
· grw [← hx]
gcongr
simpa only [mul_one] using mul_lt_mul_of_neg_left ihn hx0
end IsStrictOrderedRing
end PartialOrder
section LinearOrder
variable [LinearOrder R] [IsStrictOrderedRing R] {n : ℕ} {x : R}
lemma geom_sum_pos' (hx : 0 < x + 1) (hn : n ≠ 0) : 0 < ∑ i ∈ range n, x ^ i := by
obtain _ | _ | n := n
· cases hn rfl
· simp only [zero_add, range_one, sum_singleton, pow_zero, zero_lt_one]
obtain hx' | hx' := lt_or_ge x 0
· exact (geom_sum_pos_and_lt_one hx' hx n.one_lt_succ_succ).1
· exact geom_sum_pos hx' (by simp only [Nat.succ_ne_zero, Ne, not_false_iff])
lemma Odd.geom_sum_pos (h : Odd n) : 0 < ∑ i ∈ range n, x ^ i := by
rcases n with (_ | _ | k)
· exact (Nat.not_odd_zero h).elim
· simp only [zero_add, range_one, sum_singleton, pow_zero, zero_lt_one]
rw [← Nat.not_even_iff_odd] at h
rcases lt_trichotomy (x + 1) 0 with (hx | hx | hx)
· have := geom_sum_alternating_of_lt_neg_one hx k.one_lt_succ_succ
simp only [h, if_false] at this
exact zero_lt_one.trans this
· simp only [eq_neg_of_add_eq_zero_left hx, h, neg_one_geom_sum, if_false, zero_lt_one]
· exact geom_sum_pos' hx k.succ.succ_ne_zero
lemma geom_sum_pos_iff (hn : n ≠ 0) : 0 < ∑ i ∈ range n, x ^ i ↔ Odd n ∨ 0 < x + 1 := by
refine ⟨fun h => ?_, ?_⟩
· rw [or_iff_not_imp_left, ← not_le, Nat.not_odd_iff_even]
refine fun hn hx => h.not_ge ?_
simpa [if_pos hn] using geom_sum_alternating_of_le_neg_one hx n
· rintro (hn | hx')
· exact hn.geom_sum_pos
· exact geom_sum_pos' hx' hn
lemma geom_sum_ne_zero (hx : x ≠ -1) (hn : n ≠ 0) : ∑ i ∈ range n, x ^ i ≠ 0 := by
obtain _ | _ | n := n
· cases hn rfl
· simp only [zero_add, range_one, sum_singleton, pow_zero, ne_eq, one_ne_zero, not_false_eq_true]
rw [Ne, eq_neg_iff_add_eq_zero, ← Ne] at hx
obtain h | h := hx.lt_or_gt
· have := geom_sum_alternating_of_lt_neg_one h n.one_lt_succ_succ
split_ifs at this
· exact this.ne
· exact (zero_lt_one.trans this).ne'
· exact (geom_sum_pos' h n.succ.succ_ne_zero).ne'
lemma geom_sum_eq_zero_iff_neg_one (hn : n ≠ 0) : ∑ i ∈ range n, x ^ i = 0 ↔ x = -1 ∧ Even n := by
refine ⟨fun h => ?_, @fun ⟨h, hn⟩ => by simp only [h, hn, neg_one_geom_sum, if_true]⟩
contrapose! h
have hx := eq_or_ne x (-1)
rcases hx with hx | hx
· rw [hx, neg_one_geom_sum]
simp only [h hx, ite_false, ne_eq, one_ne_zero, not_false_eq_true]
· exact geom_sum_ne_zero hx hn
lemma geom_sum_neg_iff (hn : n ≠ 0) : ∑ i ∈ range n, x ^ i < 0 ↔ Even n ∧ x + 1 < 0 := by
rw [← not_iff_not, not_lt, le_iff_lt_or_eq, eq_comm,
or_congr (geom_sum_pos_iff hn) (geom_sum_eq_zero_iff_neg_one hn), ← Nat.not_even_iff_odd, ←
add_eq_zero_iff_eq_neg, not_and, not_lt, le_iff_lt_or_eq, eq_comm, ← imp_iff_not_or, or_comm,
and_comm, Decidable.and_or_imp, or_comm]
end LinearOrder
end Ring
/-! ### Geometric sum with `ℕ`-division -/
lemma Nat.pred_mul_geom_sum_le (a b n : ℕ) :
((b - 1) * ∑ i ∈ range n.succ, a / b ^ i) ≤ a * b - a / b ^ n :=
calc
((b - 1) * ∑ i ∈ range n.succ, a / b ^ i) =
(∑ i ∈ range n, a / b ^ (i + 1) * b) + a * b - ((∑ i ∈ range n, a / b ^ i) + a / b ^ n) := by
rw [Nat.sub_mul, mul_comm, sum_mul, one_mul, sum_range_succ', sum_range_succ, pow_zero,
Nat.div_one]
_ ≤ (∑ i ∈ range n, a / b ^ i) + a * b - ((∑ i ∈ range n, a / b ^ i) + a / b ^ n) := by
gcongr with i hi
rw [pow_succ, ← Nat.div_div_eq_div_mul]
exact Nat.div_mul_le_self _ _
_ = a * b - a / b ^ n := add_tsub_add_eq_tsub_left _ _ _
lemma Nat.geom_sum_le {b : ℕ} (hb : 2 ≤ b) (a n : ℕ) :
∑ i ∈ range n, a / b ^ i ≤ a * b / (b - 1) := by
refine (Nat.le_div_iff_mul_le <| tsub_pos_of_lt hb).2 ?_
rcases n with - | n
· rw [sum_range_zero, zero_mul]
exact Nat.zero_le _
rw [mul_comm]
exact (Nat.pred_mul_geom_sum_le a b n).trans tsub_le_self
lemma Nat.geom_sum_Ico_le {b : ℕ} (hb : 2 ≤ b) (a n : ℕ) :
∑ i ∈ Ico 1 n, a / b ^ i ≤ a / (b - 1) := by
rcases n with - | n
· rw [Ico_eq_empty_of_le (by cutsat), sum_empty]
exact Nat.zero_le _
rw [← add_le_add_iff_left a]
calc
(a + ∑ i ∈ Ico 1 n.succ, a / b ^ i) = a / b ^ 0 + ∑ i ∈ Ico 1 n.succ, a / b ^ i := by
rw [pow_zero, Nat.div_one]
_ = ∑ i ∈ range n.succ, a / b ^ i := by
rw [range_eq_Ico, ← Finset.insert_Ico_add_one_left_eq_Ico (Nat.succ_pos _), sum_insert] <;>
simp
_ ≤ a * b / (b - 1) := Nat.geom_sum_le hb a _
_ = (a * 1 + a * (b - 1)) / (b - 1) := by rw [← mul_add, add_tsub_cancel_of_le (by cutsat)]
_ = a + a / (b - 1) := by rw [mul_one, Nat.add_mul_div_right _ _ (tsub_pos_of_lt hb), add_comm]
variable {m n : ℕ} {s : Finset ℕ}
/-- If all the elements of a finset of naturals are less than `n`, then the sum of their powers of
`m ≥ 2` is less than `m ^ n`. -/
lemma Nat.geomSum_lt (hm : 2 ≤ m) (hs : ∀ k ∈ s, k < n) : ∑ k ∈ s, m ^ k < m ^ n :=
calc
∑ k ∈ s, m ^ k ≤ ∑ k ∈ range n, m ^ k := sum_le_sum_of_subset fun _ hk ↦
mem_range.2 <| hs _ hk
_ = (m ^ n - 1) / (m - 1) := Nat.geomSum_eq hm _
_ ≤ m ^ n - 1 := Nat.div_le_self _ _
_ < m ^ n := tsub_lt_self (Nat.pow_pos <| by cutsat) (by cutsat) |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Abs.lean | import Mathlib.Algebra.Order.Group.Abs
import Mathlib.Algebra.Order.Ring.Basic
import Mathlib.Algebra.Order.Ring.Int
import Mathlib.Algebra.Ring.Divisibility.Basic
import Mathlib.Algebra.Ring.Int.Units
import Mathlib.Data.Nat.Cast.Order.Ring
/-!
# Absolute values in linear ordered rings.
-/
variable {α : Type*}
section LinearOrderedAddCommGroup
variable [CommGroup α] [LinearOrder α] [IsOrderedMonoid α]
@[to_additive] lemma mabs_zpow (n : ℤ) (a : α) : |a ^ n|ₘ = |a|ₘ ^ |n| := by
obtain n0 | n0 := le_total 0 n
· obtain ⟨n, rfl⟩ := Int.eq_ofNat_of_zero_le n0
simp only [mabs_pow, zpow_natCast, Nat.abs_cast]
· obtain ⟨m, h⟩ := Int.eq_ofNat_of_zero_le (neg_nonneg.2 n0)
rw [← mabs_inv, ← zpow_neg, ← abs_neg, h, zpow_natCast, Nat.abs_cast, zpow_natCast]
exact mabs_pow m _
end LinearOrderedAddCommGroup
lemma odd_abs [LinearOrder α] [Ring α] {a : α} : Odd (abs a) ↔ Odd a := by
rcases abs_choice a with h | h <;> simp only [h, odd_neg]
section LinearOrderedRing
variable [Ring α] [LinearOrder α] [IsOrderedRing α] {n : ℕ} {a b : α}
@[simp] lemma abs_one : |(1 : α)| = 1 := abs_of_nonneg zero_le_one
lemma abs_two : |(2 : α)| = 2 := abs_of_nonneg zero_le_two
@[simp]
lemma abs_mul (a b : α) : |a * b| = |a| * |b| := by
rw [abs_eq (mul_nonneg (abs_nonneg a) (abs_nonneg b))]
rcases le_total a 0 with ha | ha <;> rcases le_total b 0 with hb | hb <;>
simp only [abs_of_nonpos, abs_of_nonneg, true_or, or_true, neg_mul, mul_neg, neg_neg, *]
/-- `abs` as a `MonoidWithZeroHom`. -/
def absHom : α →*₀ α where
toFun := abs
map_zero' := abs_zero
map_one' := abs_one
map_mul' := abs_mul
@[simp]
lemma abs_pow (a : α) (n : ℕ) : |a ^ n| = |a| ^ n := (absHom.toMonoidHom : α →* α).map_pow _ _
lemma pow_abs (a : α) (n : ℕ) : |a| ^ n = |a ^ n| := (abs_pow a n).symm
lemma Even.pow_abs (hn : Even n) (a : α) : |a| ^ n = a ^ n := by
rw [← abs_pow, abs_eq_self]; exact hn.pow_nonneg _
lemma abs_neg_one_pow (n : ℕ) : |(-1 : α) ^ n| = 1 := by rw [← pow_abs, abs_neg, abs_one, one_pow]
omit [IsOrderedRing α] in
@[simp] lemma abs_mul_abs_self (a : α) : |a| * |a| = a * a :=
abs_by_cases (fun x => x * x = a * a) rfl (neg_mul_neg a a)
lemma abs_mul_self (a : α) : |a * a| = a * a := by simp
omit [IsOrderedRing α] in
@[simp] lemma sq_abs (a : α) : |a| ^ 2 = a ^ 2 := by simpa only [sq] using abs_mul_abs_self a
lemma abs_sq (x : α) : |x ^ 2| = x ^ 2 := by simpa only [sq] using abs_mul_self x
lemma exists_abs_lt [Nontrivial α] (a : α) : ∃ b > 0, |a| < b :=
⟨|a| + 1, lt_of_lt_of_le zero_lt_one <| by simp, lt_add_one |a|⟩
end LinearOrderedRing
section LinearStrictOrderedRing
variable [Ring α] [LinearOrder α] [IsStrictOrderedRing α] {n : ℕ} {a b : α}
lemma abs_pow_eq_one (a : α) (h : n ≠ 0) : |a ^ n| = 1 ↔ |a| = 1 := by
convert pow_left_inj₀ (abs_nonneg a) zero_le_one h
exacts [(pow_abs _ _).symm, (one_pow _).symm]
lemma abs_eq_iff_mul_self_eq : |a| = |b| ↔ a * a = b * b := by
rw [← abs_mul_abs_self, ← abs_mul_abs_self b]
exact (mul_self_inj (abs_nonneg a) (abs_nonneg b)).symm
lemma abs_lt_iff_mul_self_lt : |a| < |b| ↔ a * a < b * b := by
rw [← abs_mul_abs_self, ← abs_mul_abs_self b]
exact mul_self_lt_mul_self_iff (abs_nonneg a) (abs_nonneg b)
lemma abs_le_iff_mul_self_le : |a| ≤ |b| ↔ a * a ≤ b * b := by
rw [← abs_mul_abs_self, ← abs_mul_abs_self b]
exact mul_self_le_mul_self_iff (abs_nonneg a) (abs_nonneg b)
lemma abs_le_one_iff_mul_self_le_one : |a| ≤ 1 ↔ a * a ≤ 1 := by
simpa only [abs_one, one_mul] using abs_le_iff_mul_self_le (a := a) (b := 1)
lemma sq_lt_sq : a ^ 2 < b ^ 2 ↔ |a| < |b| := by
simpa only [sq_abs] using sq_lt_sq₀ (abs_nonneg a) (abs_nonneg b)
lemma sq_lt_sq' (h1 : -b < a) (h2 : a < b) : a ^ 2 < b ^ 2 :=
sq_lt_sq.2 (lt_of_lt_of_le (abs_lt.2 ⟨h1, h2⟩) (le_abs_self _))
lemma sq_le_sq : a ^ 2 ≤ b ^ 2 ↔ |a| ≤ |b| := by
simpa only [sq_abs] using sq_le_sq₀ (abs_nonneg a) (abs_nonneg b)
lemma sq_le_sq' (h1 : -b ≤ a) (h2 : a ≤ b) : a ^ 2 ≤ b ^ 2 :=
sq_le_sq.2 (le_trans (abs_le.mpr ⟨h1, h2⟩) (le_abs_self _))
lemma abs_lt_of_sq_lt_sq (h : a ^ 2 < b ^ 2) (hb : 0 ≤ b) : |a| < b := by
rwa [← abs_of_nonneg hb, ← sq_lt_sq]
lemma abs_lt_of_sq_lt_sq' (h : a ^ 2 < b ^ 2) (hb : 0 ≤ b) : -b < a ∧ a < b :=
abs_lt.1 <| abs_lt_of_sq_lt_sq h hb
lemma abs_le_of_sq_le_sq (h : a ^ 2 ≤ b ^ 2) (hb : 0 ≤ b) : |a| ≤ b := by
rwa [← abs_of_nonneg hb, ← sq_le_sq]
theorem le_of_sq_le_sq (h : a ^ 2 ≤ b ^ 2) (hb : 0 ≤ b) : a ≤ b :=
le_abs_self a |>.trans <| abs_le_of_sq_le_sq h hb
lemma abs_le_of_sq_le_sq' (h : a ^ 2 ≤ b ^ 2) (hb : 0 ≤ b) : -b ≤ a ∧ a ≤ b :=
abs_le.1 <| abs_le_of_sq_le_sq h hb
lemma sq_eq_sq_iff_abs_eq_abs (a b : α) : a ^ 2 = b ^ 2 ↔ |a| = |b| := by
simp only [le_antisymm_iff, sq_le_sq]
@[simp] lemma sq_le_one_iff_abs_le_one (a : α) : a ^ 2 ≤ 1 ↔ |a| ≤ 1 := by
simpa only [one_pow, abs_one] using sq_le_sq (a := a) (b := 1)
@[simp] lemma sq_lt_one_iff_abs_lt_one (a : α) : a ^ 2 < 1 ↔ |a| < 1 := by
simpa only [one_pow, abs_one] using sq_lt_sq (a := a) (b := 1)
@[simp] lemma one_le_sq_iff_one_le_abs (a : α) : 1 ≤ a ^ 2 ↔ 1 ≤ |a| := by
simpa only [one_pow, abs_one] using sq_le_sq (a := 1) (b := a)
@[simp] lemma one_lt_sq_iff_one_lt_abs (a : α) : 1 < a ^ 2 ↔ 1 < |a| := by
simpa only [one_pow, abs_one] using sq_lt_sq (a := 1) (b := a)
end LinearStrictOrderedRing
section LinearOrderedCommRing
variable [CommRing α] [LinearOrder α] (a b : α) (n : ℕ)
theorem abs_sub_sq (a b : α) : |a - b| * |a - b| = a * a + b * b - (1 + 1) * a * b := by
rw [abs_mul_abs_self]
simp only [mul_add, add_comm, add_left_comm, mul_comm, sub_eq_add_neg, mul_one, mul_neg,
neg_add_rev, neg_neg, add_assoc]
lemma abs_unit_intCast [IsOrderedRing α] (a : ℤˣ) : |((a : ℤ) : α)| = 1 := by
cases Int.units_eq_one_or a <;> simp_all
private def geomSum : ℕ → α
| 0 => 1
| n + 1 => a * geomSum n + b ^ (n + 1)
private theorem abs_geomSum_le [IsOrderedRing α] : |geomSum a b n| ≤ (n + 1) * max |a| |b| ^ n := by
induction n with | zero => simp [geomSum] | succ n ih => ?_
refine (abs_add_le ..).trans ?_
rw [abs_mul, abs_pow, Nat.cast_succ, add_one_mul]
refine add_le_add ?_ (pow_le_pow_left₀ (abs_nonneg _) le_sup_right _)
rw [pow_succ, ← mul_assoc, mul_comm |a|]
exact mul_le_mul ih le_sup_left (abs_nonneg _) (mul_nonneg
(@Nat.cast_succ α .. ▸ Nat.cast_nonneg _) <| pow_nonneg ((abs_nonneg _).trans le_sup_left) _)
omit [LinearOrder α] in
private theorem pow_sub_pow_eq_sub_mul_geomSum :
a ^ (n + 1) - b ^ (n + 1) = (a - b) * geomSum a b n := by
induction n with | zero => simp [geomSum] | succ n ih => ?_
rw [geomSum, mul_add, mul_comm a, ← mul_assoc, ← ih,
sub_mul, sub_mul, ← pow_succ, ← pow_succ', mul_comm, sub_add_sub_cancel]
theorem abs_pow_sub_pow_le [IsOrderedRing α] :
|a ^ n - b ^ n| ≤ |a - b| * n * max |a| |b| ^ (n - 1) := by
obtain _ | n := n; · simp
rw [Nat.add_sub_cancel, pow_sub_pow_eq_sub_mul_geomSum, abs_mul, mul_assoc, Nat.cast_succ]
gcongr
· exact abs_nonneg _
· exact abs_geomSum_le ..
end LinearOrderedCommRing
section
variable [Ring α] [LinearOrder α]
@[simp]
theorem abs_dvd (a b : α) : |a| ∣ b ↔ a ∣ b := by
rcases abs_choice a with h | h <;> simp only [h, neg_dvd]
theorem abs_dvd_self (a : α) : |a| ∣ a :=
(abs_dvd a a).mpr (dvd_refl a)
@[simp]
theorem dvd_abs (a b : α) : a ∣ |b| ↔ a ∣ b := by
rcases abs_choice b with h | h <;> simp only [h, dvd_neg]
theorem self_dvd_abs (a : α) : a ∣ |a| :=
(dvd_abs a a).mpr (dvd_refl a)
theorem abs_dvd_abs (a b : α) : |a| ∣ |b| ↔ a ∣ b :=
(abs_dvd _ _).trans (dvd_abs _ _)
end
open Nat
section LinearOrderedRing
variable {R : Type*} [Ring R] [LinearOrder R] [IsStrictOrderedRing R] {a b : R} {n : ℕ}
lemma pow_eq_pow_iff_of_ne_zero (hn : n ≠ 0) : a ^ n = b ^ n ↔ a = b ∨ a = -b ∧ Even n :=
match n.even_xor_odd with
| .inl hne => by simp only [*, and_true, ← abs_eq_abs,
← pow_left_inj₀ (abs_nonneg a) (abs_nonneg b) hn, hne.1.pow_abs]
| .inr hn => by simp [hn, (hn.1.strictMono_pow (R := R)).injective.eq_iff]
lemma pow_eq_pow_iff_cases : a ^ n = b ^ n ↔ n = 0 ∨ a = b ∨ a = -b ∧ Even n := by
rcases eq_or_ne n 0 with rfl | hn <;> simp [pow_eq_pow_iff_of_ne_zero, *]
lemma pow_eq_one_iff_of_ne_zero (hn : n ≠ 0) : a ^ n = 1 ↔ a = 1 ∨ a = -1 ∧ Even n := by
simp [← pow_eq_pow_iff_of_ne_zero hn]
lemma pow_eq_one_iff_cases : a ^ n = 1 ↔ n = 0 ∨ a = 1 ∨ a = -1 ∧ Even n := by
simp [← pow_eq_pow_iff_cases]
lemma pow_eq_neg_pow_iff (hb : b ≠ 0) : a ^ n = -b ^ n ↔ a = -b ∧ Odd n :=
match n.even_or_odd with
| .inl he =>
suffices a ^ n > -b ^ n by simpa [he, not_odd_iff_even.2 he] using this.ne'
lt_of_lt_of_le (by simp [he.pow_pos hb]) (he.pow_nonneg _)
| .inr ho => by
simp only [ho, and_true, ← ho.neg_pow, (ho.strictMono_pow (R := R)).injective.eq_iff]
lemma pow_eq_neg_one_iff : a ^ n = -1 ↔ a = -1 ∧ Odd n := by
simpa using pow_eq_neg_pow_iff (R := R) one_ne_zero
end LinearOrderedRing
variable {m n a : ℕ}
/-- If `a` is even, then `n` is odd iff `n % a` is odd. -/
lemma Odd.mod_even_iff (ha : Even a) : Odd (n % a) ↔ Odd n :=
((even_sub' <| mod_le n a).mp <|
even_iff_two_dvd.mpr <| (even_iff_two_dvd.mp ha).trans <| dvd_sub_mod n).symm
/-- If `a` is even, then `n` is even iff `n % a` is even. -/
lemma Even.mod_even_iff (ha : Even a) : Even (n % a) ↔ Even n :=
((even_sub <| mod_le n a).mp <|
even_iff_two_dvd.mpr <| (even_iff_two_dvd.mp ha).trans <| dvd_sub_mod n).symm
/-- If `n` is odd and `a` is even, then `n % a` is odd. -/
lemma Odd.mod_even (hn : Odd n) (ha : Even a) : Odd (n % a) := (Odd.mod_even_iff ha).mpr hn
/-- If `n` is even and `a` is even, then `n % a` is even. -/
lemma Even.mod_even (hn : Even n) (ha : Even a) : Even (n % a) :=
(Even.mod_even_iff ha).mpr hn
lemma Odd.of_dvd_nat (hn : Odd n) (hm : m ∣ n) : Odd m :=
not_even_iff_odd.1 <| mt hm.even (not_even_iff_odd.2 hn)
/-- `2` is not a factor of an odd natural number. -/
lemma Odd.ne_two_of_dvd_nat {m n : ℕ} (hn : Odd n) (hm : m ∣ n) : m ≠ 2 := by
rintro rfl
exact absurd (hn.of_dvd_nat hm) (by decide) |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Units.lean | import Mathlib.Algebra.Ring.Subring.Units
import Mathlib.GroupTheory.Index
/-! # Lemmas about units of ordered rings -/
lemma Units.index_posSubgroup (R : Type*) [Ring R] [LinearOrder R] [IsStrictOrderedRing R] :
(posSubgroup R).index = 2 := by
rw [Subgroup.index_eq_two_iff]
refine ⟨-1, fun a ↦ ?_⟩
obtain h | h := lt_or_gt_of_ne a.ne_zero
· simp [h, h.le]
· simp [h, xor_comm, h.le] |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Cast.lean | import Mathlib.Algebra.Order.Group.Abs
import Mathlib.Algebra.Order.Ring.Int
import Mathlib.Data.Nat.Cast.Order.Ring
/-!
# Order properties of cast of integers
This file proves additional properties about the *canonical* homomorphism from
the integers into an additive group with a one (`Int.cast`),
particularly results involving algebraic homomorphisms or the order structure on `ℤ`
which were not available in the import dependencies of `Mathlib/Data/Int/Cast/Basic.lean`.
## TODO
Move order lemmas about `Nat.cast`, `Rat.cast`, `NNRat.cast` here.
-/
open Function Nat
variable {R : Type*}
namespace Int
section OrderedAddCommGroupWithOne
variable [AddCommGroupWithOne R] [PartialOrder R] [AddLeftMono R]
variable [ZeroLEOneClass R]
@[gcongr]
lemma cast_mono : Monotone (Int.cast : ℤ → R) := by
intro m n h
rw [← sub_nonneg] at h
lift n - m to ℕ using h with k hk
rw [← sub_nonneg, ← cast_sub, ← hk, cast_natCast]
exact k.cast_nonneg'
@[simp] lemma cast_nonneg : ∀ {n : ℤ}, 0 ≤ n → (0 : R) ≤ n | (n : ℕ), _ => by simp
variable [NeZero (1 : R)] {m n : ℤ}
@[simp] lemma cast_nonneg_iff : ∀ {n : ℤ}, (0 : R) ≤ n ↔ 0 ≤ n
| (n : ℕ) => by simp
| -[n+1] => by
have : -(n : R) < 1 := lt_of_le_of_lt (by simp) zero_lt_one
simpa [(negSucc_lt_zero n).not_ge, ← sub_eq_add_neg, le_neg] using this.not_ge
@[simp, norm_cast] lemma cast_le : (m : R) ≤ n ↔ m ≤ n := by
rw [← sub_nonneg, ← cast_sub, cast_nonneg_iff, sub_nonneg]
lemma cast_strictMono : StrictMono (fun x : ℤ => (x : R)) :=
strictMono_of_le_iff_le fun _ _ => cast_le.symm
@[simp, norm_cast] lemma cast_lt : (m : R) < n ↔ m < n := cast_strictMono.lt_iff_lt
@[gcongr] protected alias ⟨_, GCongr.intCast_strictMono⟩ := Int.cast_lt
@[simp] lemma cast_nonpos : (n : R) ≤ 0 ↔ n ≤ 0 := by rw [← cast_zero, cast_le]
@[simp] lemma cast_pos : (0 : R) < n ↔ 0 < n := by rw [← cast_zero, cast_lt]
@[simp] lemma cast_lt_zero : (n : R) < 0 ↔ n < 0 := by rw [← cast_zero, cast_lt]
end OrderedAddCommGroupWithOne
section LinearOrderedRing
variable [Ring R] [LinearOrder R] [IsStrictOrderedRing R] {a b n : ℤ} {x : R}
@[simp, norm_cast]
lemma cast_min : ↑(min a b) = (min a b : R) := Monotone.map_min cast_mono
@[simp, norm_cast]
lemma cast_max : (↑(max a b) : R) = max (a : R) (b : R) := Monotone.map_max cast_mono
@[simp, norm_cast]
lemma cast_abs : (↑|a| : R) = |(a : R)| := by simp [abs_eq_max_neg]
lemma cast_one_le_of_pos (h : 0 < a) : (1 : R) ≤ a := mod_cast Int.add_one_le_of_lt h
lemma cast_le_neg_one_of_neg (h : a < 0) : (a : R) ≤ -1 := by
rw [← Int.cast_one, ← Int.cast_neg, cast_le]
exact Int.le_sub_one_of_lt h
variable (R) in
lemma cast_le_neg_one_or_one_le_cast_of_ne_zero (hn : n ≠ 0) : (n : R) ≤ -1 ∨ 1 ≤ (n : R) :=
hn.lt_or_gt.imp cast_le_neg_one_of_neg cast_one_le_of_pos
lemma nneg_mul_add_sq_of_abs_le_one (n : ℤ) (hx : |x| ≤ 1) : (0 : R) ≤ n * x + n * n := by
have hnx : 0 < n → 0 ≤ x + n := fun hn => by
have := _root_.add_le_add (neg_le_of_abs_le hx) (cast_one_le_of_pos hn)
rwa [neg_add_cancel] at this
have hnx' : n < 0 → x + n ≤ 0 := fun hn => by
have := _root_.add_le_add (le_of_abs_le hx) (cast_le_neg_one_of_neg hn)
rwa [add_neg_cancel] at this
rw [← mul_add, mul_nonneg_iff]
rcases lt_trichotomy n 0 with (h | rfl | h)
· exact Or.inr ⟨mod_cast h.le, hnx' h⟩
· simp [le_total 0 x]
· exact Or.inl ⟨mod_cast h.le, hnx h⟩
@[deprecated (since := "2025-11-07")] alias cast_natAbs := Nat.cast_natAbs
end LinearOrderedRing
end Int
/-! ### Order dual -/
open OrderDual
namespace OrderDual
instance instIntCast [IntCast R] : IntCast Rᵒᵈ := ‹_›
instance instAddGroupWithOne [AddGroupWithOne R] : AddGroupWithOne Rᵒᵈ := ‹_›
instance instAddCommGroupWithOne [AddCommGroupWithOne R] : AddCommGroupWithOne Rᵒᵈ := ‹_›
end OrderDual
@[simp] lemma toDual_intCast [IntCast R] (n : ℤ) : toDual (n : R) = n := rfl
@[simp] lemma ofDual_intCast [IntCast R] (n : ℤ) : (ofDual n : R) = n := rfl
/-! ### Lexicographic order -/
namespace Lex
instance instIntCast [IntCast R] : IntCast (Lex R) := ‹_›
instance instAddGroupWithOne [AddGroupWithOne R] : AddGroupWithOne (Lex R) := ‹_›
instance instAddCommGroupWithOne [AddCommGroupWithOne R] : AddCommGroupWithOne (Lex R) := ‹_›
end Lex
@[simp] lemma toLex_intCast [IntCast R] (n : ℤ) : toLex (n : R) = n := rfl
@[simp] lemma ofLex_intCast [IntCast R] (n : ℤ) : (ofLex n : R) = n := rfl |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Ordering/Basic.lean | import Mathlib.Algebra.Field.IsField
import Mathlib.Algebra.Order.Ring.Ordering.Defs
import Mathlib.Algebra.Ring.SumsOfSquares
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.LinearCombination
/-!
# Ring orderings
We prove basic properties of (pre)orderings on rings and their supports.
## References
- [*An introduction to real algebra*, T.Y. Lam][lam_1984]
-/
variable {R : Type*} [CommRing R] {P : RingPreordering R}
/-!
### Preorderings
-/
namespace RingPreordering
theorem toSubsemiring_le_toSubsemiring {P₁ P₂ : RingPreordering R} :
P₁.toSubsemiring ≤ P₂.toSubsemiring ↔ P₁ ≤ P₂ := .rfl
theorem toSubsemiring_lt_toSubsemiring {P₁ P₂ : RingPreordering R} :
P₁.toSubsemiring < P₂.toSubsemiring ↔ P₁ < P₂ := .rfl
@[gcongr] alias ⟨_, GCongr.toSubsemiring_le_toSubsemiring⟩ := toSubsemiring_le_toSubsemiring
@[gcongr] alias ⟨_, GCongr.toSubsemiring_lt_toSubsemiring⟩ := toSubsemiring_lt_toSubsemiring
@[mono]
theorem toSubsemiring_mono : Monotone (toSubsemiring : RingPreordering R → _) :=
fun _ _ => id
@[mono]
theorem toSubsemiring_strictMono : StrictMono (toSubsemiring : RingPreordering R → _) :=
fun _ _ => id
@[aesop unsafe 90% apply (rule_sets := [SetLike])]
theorem unitsInv_mem {a : Rˣ} (ha : ↑a ∈ P) : ↑a⁻¹ ∈ P := by
have : (a * (a⁻¹ * a⁻¹) : R) ∈ P := by aesop (config := { enableSimp := false })
simp_all
@[aesop unsafe 90% apply (rule_sets := [SetLike])]
theorem inv_mem {F : Type*} [Field F] {P : RingPreordering F} {a : F} (ha : a ∈ P) :
a⁻¹ ∈ P := by
have mem : a * (a⁻¹ * a⁻¹) ∈ P := by aesop
field_simp at mem
simp_all
@[aesop unsafe 80% apply (rule_sets := [SetLike])]
theorem mem_of_isSumSq {x : R} (hx : IsSumSq x) : x ∈ P := by
induction hx using IsSumSq.rec' <;> aesop
section mk'
variable {R : Type*} [CommRing R] {P : Set R} {add} {mul} {sq} {neg_one}
/-- Construct a preordering from a minimal set of axioms. -/
def mk' {R : Type*} [CommRing R] (P : Set R)
(add : ∀ {x y : R}, x ∈ P → y ∈ P → x + y ∈ P)
(mul : ∀ {x y : R}, x ∈ P → y ∈ P → x * y ∈ P)
(sq : ∀ x : R, x * x ∈ P)
(neg_one : -1 ∉ P) :
RingPreordering R where
carrier := P
add_mem' {x y} := by simpa using add
mul_mem' {x y} := by simpa using mul
zero_mem' := by simpa using sq 0
one_mem' := by simpa using sq 1
@[simp] theorem mem_mk' {x : R} : x ∈ mk' P add mul sq neg_one ↔ x ∈ P := .rfl
@[simp, norm_cast] theorem coe_mk' : mk' P add mul sq neg_one = P := rfl
end mk'
/-!
### Supports
-/
section ne_top
variable (P)
theorem one_notMem_supportAddSubgroup : 1 ∉ P.supportAddSubgroup :=
fun h => RingPreordering.neg_one_notMem P h.2
theorem one_notMem_support [P.HasIdealSupport] : 1 ∉ P.support := by
simpa using one_notMem_supportAddSubgroup P
theorem supportAddSubgroup_ne_top : P.supportAddSubgroup ≠ ⊤ :=
fun h => RingPreordering.neg_one_notMem P (by simp [h] : 1 ∈ P.supportAddSubgroup).2
theorem support_ne_top [P.HasIdealSupport] : P.support ≠ ⊤ := by
apply_fun Submodule.toAddSubgroup
simpa using supportAddSubgroup_ne_top P
/-- Constructor for IsOrdering that doesn't require `ne_top'`. -/
theorem IsOrdering.mk' [HasMemOrNegMem P]
(h : ∀ {x y}, x * y ∈ P.support → x ∈ P.support ∨ y ∈ P.support) : P.IsOrdering where
ne_top' := support_ne_top P
mem_or_mem' := h
end ne_top
namespace HasIdealSupport
theorem smul_mem [P.HasIdealSupport]
(x : R) {a : R} (h₁a : a ∈ P) (h₂a : -a ∈ P) : x * a ∈ P := by
rw [hasIdealSupport_iff] at ‹P.HasIdealSupport›
simp [*]
theorem neg_smul_mem [P.HasIdealSupport]
(x : R) {a : R} (h₁a : a ∈ P) (h₂a : -a ∈ P) : -(x * a) ∈ P := by
rw [hasIdealSupport_iff] at ‹P.HasIdealSupport›
simp [*]
end HasIdealSupport
theorem hasIdealSupport_of_isUnit_two (h : IsUnit (2 : R)) : P.HasIdealSupport := by
rw [hasIdealSupport_iff]
intro x a _ _
rcases h.exists_right_inv with ⟨half, h2⟩
set y := (1 + x) * half
set z := (1 - x) * half
rw [show x = y ^ 2 - z ^ 2 by
linear_combination (- x - x * half * 2) * h2]
ring_nf
aesop (add simp sub_eq_add_neg)
instance [h : Fact (IsUnit (2 : R))] : P.HasIdealSupport := hasIdealSupport_of_isUnit_two h.out
section Field
variable {F : Type*} [Field F] (P : RingPreordering F)
variable {P} in
@[aesop unsafe 70% apply]
protected theorem eq_zero_of_mem_of_neg_mem {x} (h : x ∈ P) (h2 : -x ∈ P) : x = 0 := by
by_contra
have mem : -x * x⁻¹ ∈ P := by aesop (erase simp neg_mul)
field_simp at mem
exact RingPreordering.neg_one_notMem P mem
theorem supportAddSubgroup_eq_bot : P.supportAddSubgroup = ⊥ := by
ext; aesop (add simp mem_supportAddSubgroup)
instance : P.HasIdealSupport where
smul_mem_support := by simp [supportAddSubgroup_eq_bot]
@[simp] theorem support_eq_bot : P.support = ⊥ := by
simpa [← Submodule.toAddSubgroup_inj] using supportAddSubgroup_eq_bot P
instance : P.support.IsPrime := by simpa using Ideal.bot_prime
end Field
theorem isOrdering_iff :
P.IsOrdering ↔ ∀ a b : R, -(a * b) ∈ P → a ∈ P ∨ b ∈ P := by
refine ⟨fun _ a b _ => ?_, fun h => ?_⟩
· by_contra
have : a * b ∈ P := by simpa using mul_mem (by aesop : -a ∈ P) (by aesop : -b ∈ P)
have : a ∈ P.support ∨ b ∈ P.support :=
Ideal.IsPrime.mem_or_mem inferInstance (by simp_all [mem_support])
simp_all [mem_support]
· have : HasMemOrNegMem P := ⟨by simp [h]⟩
refine IsOrdering.mk' P (fun {x y} _ => ?_)
by_contra
have := h (-x) y
have := h (-x) (-y)
have := h x y
have := h x (-y)
cases (by aesop : x ∈ P ∨ -x ∈ P) <;> simp_all [mem_support]
end RingPreordering |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Ordering/Defs.lean | import Mathlib.Algebra.Ring.Subsemiring.Defs
import Mathlib.RingTheory.Ideal.Prime
import Mathlib.Algebra.Group.Pointwise.Set.Basic
/-!
# Ring orderings
Let `R` be a commutative ring. A preordering on `R` is a subset closed under
addition and multiplication that contains all squares, but not `-1`.
The support of a preordering `P` is the set of elements `x` such that both `x` and `-x` lie in `P`.
An ordering `O` on `R` is a preordering such that
1. `O` contains either `x` or `-x` for each `x` in `R` and
2. the support of `O` is a prime ideal.
We define preorderings, supports and orderings.
A ring preordering can intuitively be viewed as a set of "non-negative" ring elements.
Indeed, an ordering `O` with support `p` induces a linear order on `R⧸p` making it
into an ordered ring, and vice versa.
## References
- [*An introduction to real algebra*, T.Y. Lam][lam_1984]
-/
/-!
#### Preorderings
-/
variable (R : Type*) [CommRing R]
/-- A preordering on a ring `R` is a subsemiring of `R` containing all squares,
but not containing `-1`. -/
@[ext]
structure RingPreordering extends Subsemiring R where
mem_of_isSquare' {x : R} (hx : IsSquare x) : x ∈ carrier := by aesop
neg_one_notMem' : -1 ∉ carrier := by aesop
namespace RingPreordering
attribute [coe] toSubsemiring
instance : SetLike (RingPreordering R) R where
coe P := P.carrier
coe_injective' p q h := by cases p; cases q; congr; exact SetLike.ext' h
initialize_simps_projections RingPreordering (carrier → coe, as_prefix coe)
instance : SubsemiringClass (RingPreordering R) R where
zero_mem _ := Subsemiring.zero_mem _
one_mem _ := Subsemiring.one_mem _
add_mem := Subsemiring.add_mem _
mul_mem := Subsemiring.mul_mem _
variable {R}
@[aesop unsafe 80% (rule_sets := [SetLike])]
protected theorem mem_of_isSquare (P : RingPreordering R) {x : R} (hx : IsSquare x) : x ∈ P :=
RingPreordering.mem_of_isSquare' _ hx
@[simp]
protected theorem mul_self_mem (P : RingPreordering R) (x : R) : x * x ∈ P := by aesop
@[simp]
protected theorem pow_two_mem (P : RingPreordering R) (x : R) : x ^ 2 ∈ P := by aesop
@[aesop unsafe 20% forward (rule_sets := [SetLike])]
protected theorem neg_one_notMem (P : RingPreordering R) : -1 ∉ P :=
RingPreordering.neg_one_notMem' _
theorem toSubsemiring_injective :
Function.Injective (toSubsemiring : RingPreordering R → _) := fun A B h => by ext; rw [h]
@[simp]
theorem toSubsemiring_inj {P₁ P₂ : RingPreordering R} :
P₁.toSubsemiring = P₂.toSubsemiring ↔ P₁ = P₂ := toSubsemiring_injective.eq_iff
@[simp]
theorem mem_toSubsemiring {P : RingPreordering R} {x : R} : x ∈ P.toSubsemiring ↔ x ∈ P := .rfl
@[simp, norm_cast]
theorem coe_toSubsemiring (P : RingPreordering R) : (P.toSubsemiring : Set R) = P := rfl
@[simp]
theorem mem_mk {toSubsemiring : Subsemiring R} (mem_of_isSquare neg_one_notMem) {x : R} :
x ∈ mk toSubsemiring mem_of_isSquare neg_one_notMem ↔ x ∈ toSubsemiring := .rfl
@[simp]
theorem coe_set_mk (toSubsemiring : Subsemiring R) (mem_of_isSquare neg_one_notMem) :
(mk toSubsemiring mem_of_isSquare neg_one_notMem : Set R) = toSubsemiring := rfl
section copy
variable (P : RingPreordering R) (S : Set R) (hS : S = P)
/-- Copy of a preordering with a new `carrier` equal to the old one. Useful to fix definitional
equalities. -/
@[simps]
protected def copy : RingPreordering R where
carrier := S
zero_mem' := by aesop
add_mem' ha hb := by aesop
one_mem' := by aesop
mul_mem' ha hb := by aesop
attribute [norm_cast] coe_copy
@[simp] theorem mem_copy {x} : x ∈ P.copy S hS ↔ x ∈ S := .rfl
theorem copy_eq : P.copy S hS = S := rfl
end copy
variable {P : RingPreordering R}
/-!
#### Support
-/
section supportAddSubgroup
variable (P) in
/--
The support of a ring preordering `P` in a commutative ring `R` is
the set of elements `x` in `R` such that both `x` and `-x` lie in `P`.
-/
def supportAddSubgroup : AddSubgroup R where
carrier := P ∩ -P
zero_mem' := by aesop
add_mem' := by aesop
neg_mem' := by aesop
theorem mem_supportAddSubgroup {x} : x ∈ P.supportAddSubgroup ↔ x ∈ P ∧ -x ∈ P := .rfl
theorem coe_supportAddSubgroup : P.supportAddSubgroup = (P ∩ -P : Set R) := rfl
end supportAddSubgroup
/-- Typeclass to track whether the support of a preordering forms an ideal. -/
class HasIdealSupport (P : RingPreordering R) : Prop where
smul_mem_support (P) (x : R) {a : R} (ha : a ∈ P.supportAddSubgroup) :
x * a ∈ P.supportAddSubgroup
export HasIdealSupport (smul_mem_support)
theorem hasIdealSupport_iff :
P.HasIdealSupport ↔ ∀ x a : R, a ∈ P → -a ∈ P → x * a ∈ P ∧ -(x * a) ∈ P where
mp _ := by simpa [mem_supportAddSubgroup] using P.smul_mem_support
mpr _ := ⟨by simpa [mem_supportAddSubgroup]⟩
instance [HasMemOrNegMem P] : P.HasIdealSupport where
smul_mem_support x a ha :=
match mem_or_neg_mem P x with
| .inl hx => ⟨by simpa using mul_mem hx ha.1, by simpa using mul_mem hx ha.2⟩
| .inr hx => ⟨by simpa using mul_mem hx ha.2, by simpa using mul_mem hx ha.1⟩
section support
variable [P.HasIdealSupport]
variable (P) in
/--
The support of a ring preordering `P` in a commutative ring `R` is
the set of elements `x` in `R` such that both `x` and `-x` lie in `P`.
-/
def support : Ideal R where
__ := P.supportAddSubgroup
smul_mem' := by simpa using smul_mem_support P
theorem mem_support {x} : x ∈ P.support ↔ x ∈ P ∧ -x ∈ P := .rfl
theorem coe_support : P.support = (P : Set R) ∩ -(P : Set R) := rfl
@[simp] theorem supportAddSubgroup_eq : P.supportAddSubgroup = P.support.toAddSubgroup := rfl
end support
/--
An ordering `O` on a ring `R` is a preordering such that
1. `O` contains either `x` or `-x` for each `x` in `R` and
2. the support of `O` is a prime ideal.
-/
class IsOrdering (P : RingPreordering R) extends HasMemOrNegMem P, P.support.IsPrime
end RingPreordering |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Unbundled/Rat.lean | import Mathlib.Algebra.Order.Group.Unbundled.Abs
import Mathlib.Algebra.Order.Group.Unbundled.Basic
import Mathlib.Algebra.Order.Group.Unbundled.Int
import Mathlib.Data.Rat.Defs
import Mathlib.Algebra.Ring.Int.Defs
/-!
# The rational numbers possess a linear order
This file constructs the order on `ℚ` and proves various facts relating the order to
ring structure on `ℚ`. This only uses unbundled type classes, e.g. `CovariantClass`,
relating the order structure and algebra structure on `ℚ`.
For the bundled `LinearOrderedCommRing` instance on `ℚ`, see `Algebra.Order.Ring.Rat`.
## Tags
rat, rationals, field, ℚ, numerator, denominator, num, denom, order, ordering
-/
assert_not_exists IsOrderedMonoid Field Finset Set.Icc GaloisConnection
namespace Rat
variable {a b c p q : ℚ}
@[simp] lemma mkRat_nonneg {a : ℤ} (ha : 0 ≤ a) (b : ℕ) : 0 ≤ mkRat a b := by
simpa using divInt_nonneg ha (Int.natCast_nonneg _)
theorem ofScientific_nonneg (m : ℕ) (s : Bool) (e : ℕ) : 0 ≤ Rat.ofScientific m s e := by
rw [Rat.ofScientific]
cases s
· rw [if_neg (by decide)]
exact num_nonneg.mp <| Int.natCast_nonneg _
· grind [normalize_eq_mkRat, Rat.mkRat_nonneg]
instance _root_.NNRatCast.toOfScientific {K} [NNRatCast K] : OfScientific K where
ofScientific (m : ℕ) (b : Bool) (d : ℕ) :=
NNRat.cast ⟨Rat.ofScientific m b d, ofScientific_nonneg m b d⟩
theorem _root_.NNRatCast.toOfScientific_def {K} [NNRatCast K] (m : ℕ) (b : Bool) (d : ℕ) :
(OfScientific.ofScientific m b d : K) =
NNRat.cast ⟨(OfScientific.ofScientific m b d : ℚ), ofScientific_nonneg m b d⟩ :=
rfl
/-- Casting a scientific literal via `ℚ≥0` is the same as casting directly. -/
@[simp, norm_cast]
theorem _root_.NNRat.cast_ofScientific {K} [NNRatCast K] (m : ℕ) (s : Bool) (e : ℕ) :
(OfScientific.ofScientific m s e : ℚ≥0) = (OfScientific.ofScientific m s e : K) :=
rfl
protected lemma divInt_le_divInt {a b c d : ℤ} (b0 : 0 < b) (d0 : 0 < d) :
a /. b ≤ c /. d ↔ a * d ≤ c * b := by
rw [Rat.le_iff_sub_nonneg, ← Int.sub_nonneg]
simp [sub_eq_add_neg, ne_of_gt b0, ne_of_gt d0, Int.mul_pos d0 b0]
protected lemma lt_iff_le_not_ge (a b : ℚ) : a < b ↔ a ≤ b ∧ ¬b ≤ a :=
Std.LawfulOrderLT.lt_iff a b
instance linearOrder : LinearOrder ℚ where
le_refl _ := Rat.le_refl
le_trans _ _ _ := Rat.le_trans
le_antisymm _ _ := Rat.le_antisymm
le_total _ _ := Rat.le_total
toDecidableEq := inferInstance
toDecidableLE := inferInstance
toDecidableLT := inferInstance
lt_iff_le_not_ge := Rat.lt_iff_le_not_ge
theorem mkRat_nonneg_iff (a : ℤ) {b : ℕ} (hb : b ≠ 0) : 0 ≤ mkRat a b ↔ 0 ≤ a :=
divInt_nonneg_iff_of_pos_right (show 0 < (b : ℤ) by simpa using Nat.pos_of_ne_zero hb)
theorem mkRat_pos_iff (a : ℤ) {b : ℕ} (hb : b ≠ 0) : 0 < mkRat a b ↔ 0 < a := by
grind [mkRat_nonneg_iff, Rat.mkRat_eq_zero]
theorem mkRat_pos {a : ℤ} (ha : 0 < a) {b : ℕ} (hb : b ≠ 0) : 0 < mkRat a b :=
(mkRat_pos_iff a hb).mpr ha
theorem mkRat_nonpos_iff (a : ℤ) {b : ℕ} (hb : b ≠ 0) : mkRat a b ≤ 0 ↔ a ≤ 0 := by
grind [mkRat_pos_iff]
theorem mkRat_nonpos {a : ℤ} (ha : a ≤ 0) (b : ℕ) : mkRat a b ≤ 0 := by
obtain rfl | hb := eq_or_ne b 0
· simp
· exact (mkRat_nonpos_iff a hb).mpr ha
theorem mkRat_neg_iff (a : ℤ) {b : ℕ} (hb : b ≠ 0) : mkRat a b < 0 ↔ a < 0 := by
grind [mkRat_nonneg_iff]
theorem mkRat_neg {a : ℤ} (ha : a < 0) {b : ℕ} (hb : b ≠ 0) : mkRat a b < 0 :=
(mkRat_neg_iff a hb).mpr ha
/-!
### Extra instances to short-circuit type class resolution
These also prevent non-computable instances being used to construct these instances non-computably.
-/
instance instDistribLattice : DistribLattice ℚ := inferInstance
instance instLattice : Lattice ℚ := inferInstance
instance instSemilatticeInf : SemilatticeInf ℚ := inferInstance
instance instSemilatticeSup : SemilatticeSup ℚ := inferInstance
instance instInf : Min ℚ := inferInstance
instance instSup : Max ℚ := inferInstance
instance instPartialOrder : PartialOrder ℚ := inferInstance
instance instPreorder : Preorder ℚ := inferInstance
/-! ### Miscellaneous lemmas -/
@[deprecated (since := "2025-08-14")] alias le_def := Rat.le_iff
@[deprecated (since := "2025-08-14")] alias lt_def := Rat.lt_iff
instance : AddLeftMono ℚ where
elim := fun _ _ _ h => Rat.add_le_add_left.2 h
@[simp] lemma num_nonpos {a : ℚ} : a.num ≤ 0 ↔ a ≤ 0 := by
simp [Int.le_iff_lt_or_eq, instLE, Rat.blt]
@[simp] lemma num_pos {a : ℚ} : 0 < a.num ↔ 0 < a := lt_iff_lt_of_le_iff_le num_nonpos
@[simp] lemma num_neg {a : ℚ} : a.num < 0 ↔ a < 0 := lt_iff_lt_of_le_iff_le num_nonneg
theorem div_lt_div_iff_mul_lt_mul {a b c d : ℤ} (b_pos : 0 < b) (d_pos : 0 < d) :
(a : ℚ) / b < c / d ↔ a * d < c * b := by
simp only [lt_iff_le_not_ge]
apply and_congr
· simp [div_def', Rat.divInt_le_divInt b_pos d_pos]
· simp [div_def', Rat.divInt_le_divInt d_pos b_pos]
theorem lt_one_iff_num_lt_denom {q : ℚ} : q < 1 ↔ q.num < q.den := by simp [Rat.lt_iff]
theorem abs_def (q : ℚ) : |q| = q.num.natAbs /. q.den := by
grind [abs_of_nonpos, neg_def, Rat.num_nonneg, abs_of_nonneg, num_divInt_den]
theorem abs_def' (q : ℚ) :
|q| = ⟨|q.num|, q.den, q.den_ne_zero, q.num.abs_eq_natAbs ▸ q.reduced⟩ := by
refine ext ?_ ?_ <;>
simp [Int.abs_eq_natAbs, abs_def, ← Rat.mk_eq_divInt q.num.natAbs _ q.den_ne_zero q.reduced]
@[simp]
theorem num_abs_eq_abs_num (q : ℚ) : |q|.num = |q.num| := by
rw [abs_def']
@[simp]
theorem den_abs_eq_den (q : ℚ) : |q|.den = q.den := by
rw [abs_def']
end Rat |
.lake/packages/mathlib/Mathlib/Algebra/Order/Ring/Unbundled/Basic.lean | import Mathlib.Algebra.Group.Units.Basic
import Mathlib.Algebra.GroupWithZero.NeZero
import Mathlib.Algebra.Order.Group.Unbundled.Basic
import Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic
import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE
import Mathlib.Algebra.Order.Monoid.NatCast
import Mathlib.Algebra.Order.Monoid.Unbundled.MinMax
import Mathlib.Algebra.Ring.Defs
import Mathlib.Tactic.Tauto
/-!
# Basic facts for ordered rings and semirings
This file develops the basics of ordered (semi)rings in an unbundled fashion for later use with
the bundled classes from `Mathlib/Algebra/Order/Ring/Defs.lean`.
The set of typeclass variables here comprises
* an algebraic class (`Semiring`, `CommSemiring`, `Ring`, `CommRing`)
* an order class (`PartialOrder`, `LinearOrder`)
* assumptions on how both interact ((strict) monotonicity, canonicity)
For short,
* "`+` respects `≤`" means "monotonicity of addition"
* "`+` respects `<`" means "strict monotonicity of addition"
* "`*` respects `≤`" means "monotonicity of multiplication by a nonnegative number".
* "`*` respects `<`" means "strict monotonicity of multiplication by a positive number".
## Typeclasses found in `Algebra.Order.Ring.Defs`
* `OrderedSemiring`: Semiring with a partial order such that `+` and `*` respect `≤`.
* `StrictOrderedSemiring`: Nontrivial semiring with a partial order such that `+` and `*` respects
`<`.
* `OrderedCommSemiring`: Commutative semiring with a partial order such that `+` and `*` respect
`≤`.
* `StrictOrderedCommSemiring`: Nontrivial commutative semiring with a partial order such that `+`
and `*` respect `<`.
* `OrderedRing`: Ring with a partial order such that `+` respects `≤` and `*` respects `<`.
* `OrderedCommRing`: Commutative ring with a partial order such that `+` respects `≤` and
`*` respects `<`.
* `LinearOrderedSemiring`: Nontrivial semiring with a linear order such that `+` respects `≤` and
`*` respects `<`.
* `LinearOrderedCommSemiring`: Nontrivial commutative semiring with a linear order such that `+`
respects `≤` and `*` respects `<`.
* `LinearOrderedRing`: Nontrivial ring with a linear order such that `+` respects `≤` and `*`
respects `<`.
* `LinearOrderedCommRing`: Nontrivial commutative ring with a linear order such that `+` respects
`≤` and `*` respects `<`.
* `CanonicallyOrderedCommSemiring`: Commutative semiring with a partial order such that `+`
respects `≤`, `*` respects `<`, and `a ≤ b ↔ ∃ c, b = a + c`.
## Hierarchy
The hardest part of proving order lemmas might be to figure out the correct generality and its
corresponding typeclass. Here's an attempt at demystifying it. For each typeclass, we list its
immediate predecessors and what conditions are added to each of them.
* `OrderedSemiring`
- `OrderedAddCommMonoid` & multiplication & `*` respects `≤`
- `Semiring` & partial order structure & `+` respects `≤` & `*` respects `≤`
* `StrictOrderedSemiring`
- `OrderedCancelAddCommMonoid` & multiplication & `*` respects `<` & nontriviality
- `OrderedSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedCommSemiring`
- `OrderedSemiring` & commutativity of multiplication
- `CommSemiring` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedCommSemiring`
- `StrictOrderedSemiring` & commutativity of multiplication
- `OrderedCommSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedRing`
- `OrderedSemiring` & additive inverses
- `OrderedAddCommGroup` & multiplication & `*` respects `<`
- `Ring` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedRing`
- `StrictOrderedSemiring` & additive inverses
- `OrderedSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedCommRing`
- `OrderedRing` & commutativity of multiplication
- `OrderedCommSemiring` & additive inverses
- `CommRing` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedCommRing`
- `StrictOrderedCommSemiring` & additive inverses
- `StrictOrderedRing` & commutativity of multiplication
- `OrderedCommRing` & `+` respects `<` & `*` respects `<` & nontriviality
* `LinearOrderedSemiring`
- `StrictOrderedSemiring` & totality of the order
- `LinearOrderedAddCommMonoid` & multiplication & nontriviality & `*` respects `<`
* `LinearOrderedCommSemiring`
- `StrictOrderedCommSemiring` & totality of the order
- `LinearOrderedSemiring` & commutativity of multiplication
* `LinearOrderedRing`
- `StrictOrderedRing` & totality of the order
- `LinearOrderedSemiring` & additive inverses
- `LinearOrderedAddCommGroup` & multiplication & `*` respects `<`
- `Ring` & `IsDomain` & linear order structure
* `LinearOrderedCommRing`
- `StrictOrderedCommRing` & totality of the order
- `LinearOrderedRing` & commutativity of multiplication
- `LinearOrderedCommSemiring` & additive inverses
- `CommRing` & `IsDomain` & linear order structure
## Generality
Each section is labelled with a corresponding bundled ordered ring typeclass in mind. Mixins for
relating the order structures and ring structures are added as needed.
TODO: the mixin assumptions can be relaxed in most cases
-/
assert_not_exists IsOrderedMonoid MonoidHom
open Function
universe u
variable {R : Type u} {α : Type*}
/-! Note that `OrderDual` does not satisfy any of the ordered ring typeclasses due to the
`zero_le_one` field. -/
theorem add_one_le_two_mul [LE R] [NonAssocSemiring R] [AddLeftMono R] {a : R}
(a1 : 1 ≤ a) : a + 1 ≤ 2 * a :=
calc
a + 1 ≤ a + a := by gcongr
_ = 2 * a := (two_mul _).symm
section OrderedSemiring
variable [Semiring R] [Preorder R] {a b c d : R}
theorem add_le_mul_two_add [ZeroLEOneClass R] [MulPosMono R] [AddLeftMono R]
(a2 : 2 ≤ a) (b0 : 0 ≤ b) : a + (2 + b) ≤ a * (2 + b) :=
calc
a + (2 + b) ≤ a + (a + a * b) := by
gcongr; exact le_mul_of_one_le_left b0 <| one_le_two.trans a2
_ ≤ a * (2 + b) := by rw [mul_add, mul_two, add_assoc]
theorem mul_le_mul_of_nonpos_left [ExistsAddOfLE R] [PosMulMono R]
[AddRightMono R] [AddRightReflectLE R]
(h : b ≤ a) (hc : c ≤ 0) : c * a ≤ c * b := by
obtain ⟨d, hcd⟩ := exists_add_of_le hc
refine le_of_add_le_add_right (a := d * b + d * a) ?_
calc
_ = d * b := by rw [add_left_comm, ← add_mul, ← hcd, zero_mul, add_zero]
_ ≤ d * a := by gcongr; exact hcd.trans_le <| add_le_of_nonpos_left hc
_ = _ := by rw [← add_assoc, ← add_mul, ← hcd, zero_mul, zero_add]
theorem mul_le_mul_of_nonpos_right [ExistsAddOfLE R] [MulPosMono R]
[AddRightMono R] [AddRightReflectLE R]
(h : b ≤ a) (hc : c ≤ 0) : a * c ≤ b * c := by
obtain ⟨d, hcd⟩ := exists_add_of_le hc
refine le_of_add_le_add_right (a := b * d + a * d) ?_
calc
_ = b * d := by rw [add_left_comm, ← mul_add, ← hcd, mul_zero, add_zero]
_ ≤ a * d := by gcongr; exact hcd.trans_le <| add_le_of_nonpos_left hc
_ = _ := by rw [← add_assoc, ← mul_add, ← hcd, mul_zero, zero_add]
theorem mul_nonneg_of_nonpos_of_nonpos [ExistsAddOfLE R] [MulPosMono R]
[AddRightMono R] [AddRightReflectLE R]
(ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a * b := by
simpa only [zero_mul] using mul_le_mul_of_nonpos_right ha hb
theorem mul_le_mul_of_nonneg_of_nonpos [ExistsAddOfLE R] [MulPosMono R] [PosMulMono R]
[AddRightMono R] [AddRightReflectLE R]
(hca : c ≤ a) (hbd : b ≤ d) (hc : 0 ≤ c) (hb : b ≤ 0) : a * b ≤ c * d :=
(mul_le_mul_of_nonpos_right hca hb).trans <| by gcongr; assumption
theorem mul_le_mul_of_nonneg_of_nonpos' [ExistsAddOfLE R] [PosMulMono R] [MulPosMono R]
[AddRightMono R] [AddRightReflectLE R]
(hca : c ≤ a) (hbd : b ≤ d) (ha : 0 ≤ a) (hd : d ≤ 0) : a * b ≤ c * d :=
(mul_le_mul_of_nonneg_left hbd ha).trans <| mul_le_mul_of_nonpos_right hca hd
theorem mul_le_mul_of_nonpos_of_nonneg [ExistsAddOfLE R] [MulPosMono R] [PosMulMono R]
[AddRightMono R] [AddRightReflectLE R]
(hac : a ≤ c) (hdb : d ≤ b) (hc : c ≤ 0) (hb : 0 ≤ b) : a * b ≤ c * d :=
(mul_le_mul_of_nonneg_right hac hb).trans <| mul_le_mul_of_nonpos_left hdb hc
theorem mul_le_mul_of_nonpos_of_nonneg' [ExistsAddOfLE R] [PosMulMono R] [MulPosMono R]
[AddRightMono R] [AddRightReflectLE R]
(hca : c ≤ a) (hbd : b ≤ d) (ha : 0 ≤ a) (hd : d ≤ 0) : a * b ≤ c * d :=
(mul_le_mul_of_nonneg_left hbd ha).trans <| mul_le_mul_of_nonpos_right hca hd
theorem mul_le_mul_of_nonpos_of_nonpos [ExistsAddOfLE R] [MulPosMono R] [PosMulMono R]
[AddRightMono R] [AddRightReflectLE R]
(hca : c ≤ a) (hdb : d ≤ b) (hc : c ≤ 0) (hb : b ≤ 0) : a * b ≤ c * d :=
(mul_le_mul_of_nonpos_right hca hb).trans <| mul_le_mul_of_nonpos_left hdb hc
theorem mul_le_mul_of_nonpos_of_nonpos' [ExistsAddOfLE R] [PosMulMono R] [MulPosMono R]
[AddRightMono R] [AddRightReflectLE R]
(hca : c ≤ a) (hdb : d ≤ b) (ha : a ≤ 0) (hd : d ≤ 0) : a * b ≤ c * d :=
(mul_le_mul_of_nonpos_left hdb ha).trans <| mul_le_mul_of_nonpos_right hca hd
/-- Variant of `mul_le_of_le_one_left` for `b` non-positive instead of non-negative. -/
theorem le_mul_of_le_one_left [ExistsAddOfLE R] [MulPosMono R]
[AddRightMono R] [AddRightReflectLE R]
(hb : b ≤ 0) (h : a ≤ 1) : b ≤ a * b := by
simpa only [one_mul] using mul_le_mul_of_nonpos_right h hb
/-- Variant of `le_mul_of_one_le_left` for `b` non-positive instead of non-negative. -/
theorem mul_le_of_one_le_left [ExistsAddOfLE R] [MulPosMono R]
[AddRightMono R] [AddRightReflectLE R]
(hb : b ≤ 0) (h : 1 ≤ a) : a * b ≤ b := by
simpa only [one_mul] using mul_le_mul_of_nonpos_right h hb
/-- Variant of `mul_le_of_le_one_right` for `a` non-positive instead of non-negative. -/
theorem le_mul_of_le_one_right [ExistsAddOfLE R] [PosMulMono R]
[AddRightMono R] [AddRightReflectLE R]
(ha : a ≤ 0) (h : b ≤ 1) : a ≤ a * b := by
simpa only [mul_one] using mul_le_mul_of_nonpos_left h ha
/-- Variant of `le_mul_of_one_le_right` for `a` non-positive instead of non-negative. -/
theorem mul_le_of_one_le_right [ExistsAddOfLE R] [PosMulMono R]
[AddRightMono R] [AddRightReflectLE R]
(ha : a ≤ 0) (h : 1 ≤ b) : a * b ≤ a := by
simpa only [mul_one] using mul_le_mul_of_nonpos_left h ha
section Monotone
variable [Preorder α] {f g : α → R}
theorem antitone_mul_left [ExistsAddOfLE R] [PosMulMono R]
[AddRightMono R] [AddRightReflectLE R]
{a : R} (ha : a ≤ 0) : Antitone (a * ·) := fun _ _ b_le_c =>
mul_le_mul_of_nonpos_left b_le_c ha
theorem antitone_mul_right [ExistsAddOfLE R] [MulPosMono R]
[AddRightMono R] [AddRightReflectLE R]
{a : R} (ha : a ≤ 0) : Antitone fun x => x * a := fun _ _ b_le_c =>
mul_le_mul_of_nonpos_right b_le_c ha
theorem Monotone.const_mul_of_nonpos [ExistsAddOfLE R] [PosMulMono R]
[AddRightMono R] [AddRightReflectLE R]
(hf : Monotone f) (ha : a ≤ 0) : Antitone fun x => a * f x :=
(antitone_mul_left ha).comp_monotone hf
theorem Monotone.mul_const_of_nonpos [ExistsAddOfLE R] [MulPosMono R]
[AddRightMono R] [AddRightReflectLE R]
(hf : Monotone f) (ha : a ≤ 0) : Antitone fun x => f x * a :=
(antitone_mul_right ha).comp_monotone hf
theorem Antitone.const_mul_of_nonpos [ExistsAddOfLE R] [PosMulMono R]
[AddRightMono R] [AddRightReflectLE R]
(hf : Antitone f) (ha : a ≤ 0) : Monotone fun x => a * f x :=
(antitone_mul_left ha).comp hf
theorem Antitone.mul_const_of_nonpos [ExistsAddOfLE R] [MulPosMono R]
[AddRightMono R] [AddRightReflectLE R]
(hf : Antitone f) (ha : a ≤ 0) : Monotone fun x => f x * a :=
(antitone_mul_right ha).comp hf
theorem Antitone.mul_monotone [ExistsAddOfLE R] [PosMulMono R] [MulPosMono R]
[AddRightMono R] [AddRightReflectLE R]
(hf : Antitone f) (hg : Monotone g) (hf₀ : ∀ x, f x ≤ 0)
(hg₀ : ∀ x, 0 ≤ g x) : Antitone (f * g) := fun _ _ h =>
mul_le_mul_of_nonpos_of_nonneg (hf h) (hg h) (hf₀ _) (hg₀ _)
theorem Monotone.mul_antitone [ExistsAddOfLE R] [PosMulMono R] [MulPosMono R]
[AddRightMono R] [AddRightReflectLE R]
(hf : Monotone f) (hg : Antitone g) (hf₀ : ∀ x, 0 ≤ f x)
(hg₀ : ∀ x, g x ≤ 0) : Antitone (f * g) := fun _ _ h =>
mul_le_mul_of_nonneg_of_nonpos (hf h) (hg h) (hf₀ _) (hg₀ _)
theorem Antitone.mul [ExistsAddOfLE R] [PosMulMono R] [MulPosMono R]
[AddRightMono R] [AddRightReflectLE R]
(hf : Antitone f) (hg : Antitone g) (hf₀ : ∀ x, f x ≤ 0) (hg₀ : ∀ x, g x ≤ 0) :
Monotone (f * g) := fun _ _ h => mul_le_mul_of_nonpos_of_nonpos (hf h) (hg h) (hf₀ _) (hg₀ _)
end Monotone
end OrderedSemiring
section OrderedCommRing
section StrictOrderedSemiring
variable [Semiring R] [PartialOrder R] {a b c d : R}
theorem lt_two_mul_self [ZeroLEOneClass R] [MulPosStrictMono R] [NeZero (1 : R)]
[AddLeftStrictMono R] (ha : 0 < a) : a < 2 * a :=
lt_mul_of_one_lt_left ha one_lt_two
theorem mul_lt_mul_of_neg_left [ExistsAddOfLE R] [PosMulStrictMono R]
[AddRightStrictMono R] [AddRightReflectLT R]
(h : b < a) (hc : c < 0) : c * a < c * b := by
obtain ⟨d, hcd⟩ := exists_add_of_le hc.le
refine (add_lt_add_iff_right (d * b + d * a)).1 ?_
calc
_ = d * b := by rw [add_left_comm, ← add_mul, ← hcd, zero_mul, add_zero]
_ < d * a := mul_lt_mul_of_pos_left h <| hcd.trans_lt <| add_lt_of_neg_left _ hc
_ = _ := by rw [← add_assoc, ← add_mul, ← hcd, zero_mul, zero_add]
theorem mul_lt_mul_of_neg_right [ExistsAddOfLE R] [MulPosStrictMono R]
[AddRightStrictMono R] [AddRightReflectLT R]
(h : b < a) (hc : c < 0) : a * c < b * c := by
obtain ⟨d, hcd⟩ := exists_add_of_le hc.le
refine (add_lt_add_iff_right (b * d + a * d)).1 ?_
calc
_ = b * d := by rw [add_left_comm, ← mul_add, ← hcd, mul_zero, add_zero]
_ < a * d := mul_lt_mul_of_pos_right h <| hcd.trans_lt <| add_lt_of_neg_left _ hc
_ = _ := by rw [← add_assoc, ← mul_add, ← hcd, mul_zero, zero_add]
theorem mul_pos_of_neg_of_neg [ExistsAddOfLE R] [MulPosStrictMono R]
[AddRightStrictMono R] [AddRightReflectLT R]
{a b : R} (ha : a < 0) (hb : b < 0) : 0 < a * b := by
simpa only [zero_mul] using mul_lt_mul_of_neg_right ha hb
/-- Variant of `mul_lt_of_lt_one_left` for `b` negative instead of positive. -/
theorem lt_mul_of_lt_one_left [ExistsAddOfLE R] [MulPosStrictMono R]
[AddRightStrictMono R] [AddRightReflectLT R]
(hb : b < 0) (h : a < 1) : b < a * b := by
simpa only [one_mul] using mul_lt_mul_of_neg_right h hb
/-- Variant of `lt_mul_of_one_lt_left` for `b` negative instead of positive. -/
theorem mul_lt_of_one_lt_left [ExistsAddOfLE R] [MulPosStrictMono R]
[AddRightStrictMono R] [AddRightReflectLT R]
(hb : b < 0) (h : 1 < a) : a * b < b := by
simpa only [one_mul] using mul_lt_mul_of_neg_right h hb
/-- Variant of `mul_lt_of_lt_one_right` for `a` negative instead of positive. -/
theorem lt_mul_of_lt_one_right [ExistsAddOfLE R] [PosMulStrictMono R]
[AddRightStrictMono R] [AddRightReflectLT R]
(ha : a < 0) (h : b < 1) : a < a * b := by
simpa only [mul_one] using mul_lt_mul_of_neg_left h ha
/-- Variant of `lt_mul_of_lt_one_right` for `a` negative instead of positive. -/
theorem mul_lt_of_one_lt_right [ExistsAddOfLE R] [PosMulStrictMono R]
[AddRightStrictMono R] [AddRightReflectLT R]
(ha : a < 0) (h : 1 < b) : a * b < a := by
simpa only [mul_one] using mul_lt_mul_of_neg_left h ha
section Monotone
variable [Preorder α] {f : α → R}
theorem strictAnti_mul_left [ExistsAddOfLE R] [PosMulStrictMono R]
[AddRightStrictMono R] [AddRightReflectLT R]
{a : R} (ha : a < 0) : StrictAnti (a * ·) := fun _ _ b_lt_c =>
mul_lt_mul_of_neg_left b_lt_c ha
theorem strictAnti_mul_right [ExistsAddOfLE R] [MulPosStrictMono R]
[AddRightStrictMono R] [AddRightReflectLT R]
{a : R} (ha : a < 0) : StrictAnti fun x => x * a := fun _ _ b_lt_c =>
mul_lt_mul_of_neg_right b_lt_c ha
theorem StrictMono.const_mul_of_neg [ExistsAddOfLE R] [PosMulStrictMono R]
[AddRightStrictMono R] [AddRightReflectLT R]
(hf : StrictMono f) (ha : a < 0) : StrictAnti fun x => a * f x :=
(strictAnti_mul_left ha).comp_strictMono hf
theorem StrictMono.mul_const_of_neg [ExistsAddOfLE R] [MulPosStrictMono R]
[AddRightStrictMono R] [AddRightReflectLT R]
(hf : StrictMono f) (ha : a < 0) : StrictAnti fun x => f x * a :=
(strictAnti_mul_right ha).comp_strictMono hf
theorem StrictAnti.const_mul_of_neg [ExistsAddOfLE R] [PosMulStrictMono R]
[AddRightStrictMono R] [AddRightReflectLT R]
(hf : StrictAnti f) (ha : a < 0) : StrictMono fun x => a * f x :=
(strictAnti_mul_left ha).comp hf
theorem StrictAnti.mul_const_of_neg [ExistsAddOfLE R] [MulPosStrictMono R]
[AddRightStrictMono R] [AddRightReflectLT R]
(hf : StrictAnti f) (ha : a < 0) : StrictMono fun x => f x * a :=
(strictAnti_mul_right ha).comp hf
end Monotone
/-- Binary **rearrangement inequality**. -/
lemma mul_add_mul_le_mul_add_mul [ExistsAddOfLE R] [MulPosMono R]
[AddLeftMono R] [AddLeftReflectLE R]
(hab : a ≤ b) (hcd : c ≤ d) : a * d + b * c ≤ a * c + b * d := by
obtain ⟨d, hd, rfl⟩ := exists_nonneg_add_of_le hcd
rw [mul_add, add_right_comm, mul_add, ← add_assoc]
gcongr
assumption
/-- Binary **rearrangement inequality**. -/
lemma mul_add_mul_le_mul_add_mul' [ExistsAddOfLE R] [MulPosMono R]
[AddLeftMono R] [AddLeftReflectLE R]
(hba : b ≤ a) (hdc : d ≤ c) : a * d + b * c ≤ a * c + b * d := by
rw [add_comm (a * d), add_comm (a * c)]; exact mul_add_mul_le_mul_add_mul hba hdc
variable [AddLeftReflectLT R]
/-- Binary strict **rearrangement inequality**. -/
lemma mul_add_mul_lt_mul_add_mul [ExistsAddOfLE R] [MulPosStrictMono R]
[AddLeftStrictMono R]
(hab : a < b) (hcd : c < d) : a * d + b * c < a * c + b * d := by
obtain ⟨d, hd, rfl⟩ := exists_pos_add_of_lt' hcd
rw [mul_add, add_right_comm, mul_add, ← add_assoc]
gcongr
exact hd
/-- Binary **rearrangement inequality**. -/
lemma mul_add_mul_lt_mul_add_mul' [ExistsAddOfLE R] [MulPosStrictMono R]
[AddLeftStrictMono R]
(hba : b < a) (hdc : d < c) : a * d + b * c < a * c + b * d := by
rw [add_comm (a * d), add_comm (a * c)]
exact mul_add_mul_lt_mul_add_mul hba hdc
end StrictOrderedSemiring
section LinearOrderedSemiring
variable [Semiring R] [LinearOrder R] {a b c : R}
theorem nonneg_and_nonneg_or_nonpos_and_nonpos_of_mul_nonneg
[MulPosStrictMono R] [PosMulStrictMono R]
(hab : 0 ≤ a * b) : 0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0 := by
refine Decidable.or_iff_not_not_and_not.2 ?_
simp only [not_and, not_le]; intro ab nab; apply not_lt_of_ge hab _
rcases lt_trichotomy 0 a with (ha | rfl | ha)
· exact mul_neg_of_pos_of_neg ha (ab ha.le)
· exact ((ab le_rfl).asymm (nab le_rfl)).elim
· exact mul_neg_of_neg_of_pos ha (nab ha.le)
theorem nonneg_of_mul_nonneg_left [MulPosStrictMono R]
(h : 0 ≤ a * b) (hb : 0 < b) : 0 ≤ a :=
le_of_not_gt fun ha => (mul_neg_of_neg_of_pos ha hb).not_ge h
theorem nonneg_of_mul_nonneg_right [PosMulStrictMono R]
(h : 0 ≤ a * b) (ha : 0 < a) : 0 ≤ b :=
le_of_not_gt fun hb => (mul_neg_of_pos_of_neg ha hb).not_ge h
theorem nonpos_of_mul_nonpos_left [PosMulStrictMono R]
(h : a * b ≤ 0) (hb : 0 < b) : a ≤ 0 :=
le_of_not_gt fun ha : a > 0 => (mul_pos ha hb).not_ge h
theorem nonpos_of_mul_nonpos_right [PosMulStrictMono R]
(h : a * b ≤ 0) (ha : 0 < a) : b ≤ 0 :=
le_of_not_gt fun hb : b > 0 => (mul_pos ha hb).not_ge h
@[simp]
theorem mul_nonneg_iff_of_pos_left [PosMulStrictMono R]
(h : 0 < c) : 0 ≤ c * b ↔ 0 ≤ b := by
convert mul_le_mul_iff_right₀ h
simp
@[simp]
theorem mul_nonneg_iff_of_pos_right [MulPosStrictMono R]
(h : 0 < c) : 0 ≤ b * c ↔ 0 ≤ b := by
simpa using (mul_le_mul_iff_left₀ h : 0 * c ≤ b * c ↔ 0 ≤ b)
theorem add_le_mul_of_left_le_right [ZeroLEOneClass R] [NeZero (1 : R)]
[MulPosStrictMono R] [AddLeftMono R]
(a2 : 2 ≤ a) (ab : a ≤ b) : a + b ≤ a * b :=
have : 0 < b :=
calc
0 < 2 := zero_lt_two
_ ≤ a := a2
_ ≤ b := ab
calc
a + b ≤ b + b := by gcongr
_ = 2 * b := (two_mul b).symm
_ ≤ a * b := (mul_le_mul_iff_left₀ this).mpr a2
theorem add_le_mul_of_right_le_left [ZeroLEOneClass R] [NeZero (1 : R)]
[AddLeftMono R] [PosMulStrictMono R]
(b2 : 2 ≤ b) (ba : b ≤ a) : a + b ≤ a * b :=
have : 0 < a :=
calc 0
_ < 2 := zero_lt_two
_ ≤ b := b2
_ ≤ a := ba
calc
a + b ≤ a + a := by gcongr
_ = a * 2 := (mul_two a).symm
_ ≤ a * b := (mul_le_mul_iff_right₀ this).mpr b2
theorem add_le_mul [ZeroLEOneClass R] [NeZero (1 : R)]
[MulPosStrictMono R] [PosMulStrictMono R] [AddLeftMono R]
(a2 : 2 ≤ a) (b2 : 2 ≤ b) : a + b ≤ a * b :=
if hab : a ≤ b then add_le_mul_of_left_le_right a2 hab
else add_le_mul_of_right_le_left b2 (le_of_not_ge hab)
theorem add_le_mul' [ZeroLEOneClass R] [NeZero (1 : R)]
[MulPosStrictMono R] [PosMulStrictMono R] [AddLeftMono R]
(a2 : 2 ≤ a) (b2 : 2 ≤ b) : a + b ≤ b * a :=
(le_of_eq (add_comm _ _)).trans (add_le_mul b2 a2)
theorem mul_nonneg_iff_right_nonneg_of_pos [PosMulStrictMono R]
(ha : 0 < a) : 0 ≤ a * b ↔ 0 ≤ b :=
⟨fun h => nonneg_of_mul_nonneg_right h ha, mul_nonneg ha.le⟩
theorem mul_nonneg_iff_left_nonneg_of_pos [PosMulStrictMono R] [MulPosStrictMono R]
(hb : 0 < b) : 0 ≤ a * b ↔ 0 ≤ a :=
⟨fun h => nonneg_of_mul_nonneg_left h hb, fun h => mul_nonneg h hb.le⟩
theorem nonpos_of_mul_nonneg_left [PosMulStrictMono R]
(h : 0 ≤ a * b) (hb : b < 0) : a ≤ 0 :=
le_of_not_gt fun ha => absurd h (mul_neg_of_pos_of_neg ha hb).not_ge
theorem nonpos_of_mul_nonneg_right [MulPosStrictMono R]
(h : 0 ≤ a * b) (ha : a < 0) : b ≤ 0 :=
le_of_not_gt fun hb => absurd h (mul_neg_of_neg_of_pos ha hb).not_ge
@[simp]
theorem Units.inv_pos
[ZeroLEOneClass R] [NeZero (1 : R)] [PosMulStrictMono R]
{u : Rˣ} : (0 : R) < ↑u⁻¹ ↔ (0 : R) < u :=
have : ∀ {u : Rˣ}, (0 : R) < u → (0 : R) < ↑u⁻¹ := @fun u h =>
(mul_pos_iff_of_pos_left h).mp <| u.mul_inv.symm ▸ zero_lt_one
⟨this, this⟩
@[simp]
theorem Units.inv_neg
[ZeroLEOneClass R] [NeZero (1 : R)] [MulPosMono R] [PosMulMono R]
{u : Rˣ} : ↑u⁻¹ < (0 : R) ↔ ↑u < (0 : R) :=
have : ∀ {u : Rˣ}, ↑u < (0 : R) → ↑u⁻¹ < (0 : R) := @fun u h =>
neg_of_mul_pos_right (u.mul_inv.symm ▸ zero_lt_one) h.le
⟨this, this⟩
theorem cmp_mul_pos_left [PosMulStrictMono R]
(ha : 0 < a) (b c : R) : cmp (a * b) (a * c) = cmp b c :=
(strictMono_mul_left_of_pos ha).cmp_map_eq b c
theorem cmp_mul_pos_right [MulPosStrictMono R]
(ha : 0 < a) (b c : R) : cmp (b * a) (c * a) = cmp b c :=
(strictMono_mul_right_of_pos ha).cmp_map_eq b c
theorem mul_max_of_nonneg [PosMulMono R]
(b c : R) (ha : 0 ≤ a) : a * max b c = max (a * b) (a * c) :=
(monotone_mul_left_of_nonneg ha).map_max
theorem mul_min_of_nonneg [PosMulMono R]
(b c : R) (ha : 0 ≤ a) : a * min b c = min (a * b) (a * c) :=
(monotone_mul_left_of_nonneg ha).map_min
theorem max_mul_of_nonneg [MulPosMono R]
(a b : R) (hc : 0 ≤ c) : max a b * c = max (a * c) (b * c) :=
(monotone_mul_right_of_nonneg hc).map_max
theorem min_mul_of_nonneg [MulPosMono R]
(a b : R) (hc : 0 ≤ c) : min a b * c = min (a * c) (b * c) :=
(monotone_mul_right_of_nonneg hc).map_min
theorem le_of_mul_le_of_one_le
[ZeroLEOneClass R] [NeZero (1 : R)] [MulPosStrictMono R] [PosMulMono R]
{a b c : R} (h : a * c ≤ b) (hb : 0 ≤ b) (hc : 1 ≤ c) : a ≤ b :=
le_of_mul_le_mul_right (h.trans <| le_mul_of_one_le_right hb hc) <| zero_lt_one.trans_le hc
theorem nonneg_le_nonneg_of_sq_le_sq [PosMulStrictMono R] [MulPosMono R]
{a b : R} (hb : 0 ≤ b) (h : a * a ≤ b * b) : a ≤ b :=
le_of_not_gt fun hab => (mul_self_lt_mul_self hb hab).not_ge h
theorem mul_self_le_mul_self_iff [PosMulStrictMono R] [MulPosMono R]
{a b : R} (h1 : 0 ≤ a) (h2 : 0 ≤ b) : a ≤ b ↔ a * a ≤ b * b :=
⟨mul_self_le_mul_self h1, nonneg_le_nonneg_of_sq_le_sq h2⟩
theorem mul_self_lt_mul_self_iff [PosMulStrictMono R] [MulPosMono R]
{a b : R} (h1 : 0 ≤ a) (h2 : 0 ≤ b) : a < b ↔ a * a < b * b :=
((@strictMonoOn_mul_self R _).lt_iff_lt h1 h2).symm
theorem mul_self_inj [PosMulStrictMono R] [MulPosMono R]
{a b : R} (h1 : 0 ≤ a) (h2 : 0 ≤ b) : a * a = b * b ↔ a = b :=
(@strictMonoOn_mul_self R _).eq_iff_eq h1 h2
lemma sign_cases_of_C_mul_pow_nonneg [PosMulStrictMono R]
(h : ∀ n, 0 ≤ a * b ^ n) : a = 0 ∨ 0 < a ∧ 0 ≤ b := by
have : 0 ≤ a := by simpa only [pow_zero, mul_one] using h 0
refine this.eq_or_lt'.imp_right fun ha ↦ ⟨ha, nonneg_of_mul_nonneg_right ?_ ha⟩
simpa only [pow_one] using h 1
theorem mul_pos_iff [ExistsAddOfLE R] [PosMulStrictMono R] [MulPosStrictMono R]
[AddLeftStrictMono R] [AddLeftReflectLT R] :
0 < a * b ↔ 0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 :=
⟨pos_and_pos_or_neg_and_neg_of_mul_pos, fun h =>
h.elim (and_imp.2 mul_pos) (and_imp.2 mul_pos_of_neg_of_neg)⟩
theorem mul_nonneg_iff [ExistsAddOfLE R] [MulPosStrictMono R] [PosMulStrictMono R]
[AddLeftReflectLE R] [AddLeftMono R] :
0 ≤ a * b ↔ 0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0 :=
⟨nonneg_and_nonneg_or_nonpos_and_nonpos_of_mul_nonneg, fun h =>
h.elim (and_imp.2 mul_nonneg) (and_imp.2 mul_nonneg_of_nonpos_of_nonpos)⟩
/-- Out of three elements of a `LinearOrderedRing`, two must have the same sign. -/
theorem mul_nonneg_of_three [ExistsAddOfLE R] [MulPosStrictMono R] [PosMulStrictMono R]
[AddLeftMono R] [AddLeftReflectLE R]
(a b c : R) : 0 ≤ a * b ∨ 0 ≤ b * c ∨ 0 ≤ c * a := by
iterate 3 rw [mul_nonneg_iff]
have or_a := le_total 0 a
have or_b := le_total 0 b
have or_c := le_total 0 c
aesop
lemma mul_nonneg_iff_pos_imp_nonneg [ExistsAddOfLE R] [PosMulStrictMono R] [MulPosStrictMono R]
[AddLeftMono R] [AddLeftReflectLE R] :
0 ≤ a * b ↔ (0 < a → 0 ≤ b) ∧ (0 < b → 0 ≤ a) := by
refine mul_nonneg_iff.trans ?_
simp_rw [← not_le, ← or_iff_not_imp_left]
have := le_total a 0
have := le_total b 0
tauto
@[simp]
theorem mul_le_mul_left_of_neg [ExistsAddOfLE R] [PosMulStrictMono R]
[AddRightMono R] [AddRightReflectLE R]
{a b c : R} (h : c < 0) : c * a ≤ c * b ↔ b ≤ a :=
(strictAnti_mul_left h).le_iff_ge
@[simp]
theorem mul_le_mul_right_of_neg [ExistsAddOfLE R] [MulPosStrictMono R]
[AddRightMono R] [AddRightReflectLE R]
{a b c : R} (h : c < 0) : a * c ≤ b * c ↔ b ≤ a :=
(strictAnti_mul_right h).le_iff_ge
@[simp]
theorem mul_lt_mul_left_of_neg [ExistsAddOfLE R] [PosMulStrictMono R]
[AddRightStrictMono R] [AddRightReflectLT R]
{a b c : R} (h : c < 0) : c * a < c * b ↔ b < a :=
(strictAnti_mul_left h).lt_iff_gt
@[simp]
theorem mul_lt_mul_right_of_neg [ExistsAddOfLE R] [MulPosStrictMono R]
[AddRightStrictMono R] [AddRightReflectLT R]
{a b c : R} (h : c < 0) : a * c < b * c ↔ b < a :=
(strictAnti_mul_right h).lt_iff_gt
theorem lt_of_mul_lt_mul_of_nonpos_left [ExistsAddOfLE R] [PosMulMono R]
[AddRightMono R] [AddRightReflectLE R]
(h : c * a < c * b) (hc : c ≤ 0) : b < a :=
(antitone_mul_left hc).reflect_lt h
theorem lt_of_mul_lt_mul_of_nonpos_right [ExistsAddOfLE R] [MulPosMono R]
[AddRightMono R] [AddRightReflectLE R]
(h : a * c < b * c) (hc : c ≤ 0) : b < a :=
(antitone_mul_right hc).reflect_lt h
theorem cmp_mul_neg_left [ExistsAddOfLE R] [PosMulStrictMono R]
[AddRightReflectLT R] [AddRightStrictMono R]
{a : R} (ha : a < 0) (b c : R) : cmp (a * b) (a * c) = cmp c b :=
(strictAnti_mul_left ha).cmp_map_eq b c
theorem cmp_mul_neg_right [ExistsAddOfLE R] [MulPosStrictMono R]
[AddRightReflectLT R] [AddRightStrictMono R]
{a : R} (ha : a < 0) (b c : R) : cmp (b * a) (c * a) = cmp c b :=
(strictAnti_mul_right ha).cmp_map_eq b c
@[simp]
theorem mul_self_pos [ExistsAddOfLE R] [PosMulStrictMono R] [MulPosStrictMono R]
[AddLeftStrictMono R] [AddLeftReflectLT R]
{a : R} : 0 < a * a ↔ a ≠ 0 := by
constructor
· rintro h rfl
rw [mul_zero] at h
exact h.false
· intro h
rcases h.lt_or_gt with h | h
exacts [mul_pos_of_neg_of_neg h h, mul_pos h h]
theorem nonneg_of_mul_nonpos_left [ExistsAddOfLE R] [MulPosStrictMono R]
[AddRightMono R] [AddRightReflectLE R]
{a b : R} (h : a * b ≤ 0) (hb : b < 0) : 0 ≤ a :=
le_of_not_gt fun ha => absurd h (mul_pos_of_neg_of_neg ha hb).not_ge
theorem nonneg_of_mul_nonpos_right [ExistsAddOfLE R] [MulPosStrictMono R]
[AddRightMono R] [AddRightReflectLE R]
{a b : R} (h : a * b ≤ 0) (ha : a < 0) : 0 ≤ b :=
le_of_not_gt fun hb => absurd h (mul_pos_of_neg_of_neg ha hb).not_ge
theorem pos_of_mul_neg_left [ExistsAddOfLE R] [MulPosMono R]
[AddRightMono R] [AddRightReflectLE R]
{a b : R} (h : a * b < 0) (hb : b ≤ 0) : 0 < a :=
lt_of_not_ge fun ha => absurd h (mul_nonneg_of_nonpos_of_nonpos ha hb).not_gt
theorem pos_of_mul_neg_right [ExistsAddOfLE R] [MulPosMono R]
[AddRightMono R] [AddRightReflectLE R]
{a b : R} (h : a * b < 0) (ha : a ≤ 0) : 0 < b :=
lt_of_not_ge fun hb => absurd h (mul_nonneg_of_nonpos_of_nonpos ha hb).not_gt
theorem neg_iff_pos_of_mul_neg [ExistsAddOfLE R] [PosMulMono R] [MulPosMono R]
[AddRightMono R] [AddRightReflectLE R]
(hab : a * b < 0) : a < 0 ↔ 0 < b :=
⟨pos_of_mul_neg_right hab ∘ le_of_lt, neg_of_mul_neg_left hab ∘ le_of_lt⟩
theorem pos_iff_neg_of_mul_neg [ExistsAddOfLE R] [PosMulMono R] [MulPosMono R]
[AddRightMono R] [AddRightReflectLE R]
(hab : a * b < 0) : 0 < a ↔ b < 0 :=
⟨neg_of_mul_neg_right hab ∘ le_of_lt, pos_of_mul_neg_left hab ∘ le_of_lt⟩
lemma sq_nonneg [ExistsAddOfLE R] [PosMulMono R] [AddLeftMono R]
(a : R) : 0 ≤ a ^ 2 := by
obtain ha | ha := le_or_gt 0 a
· exact pow_succ_nonneg ha _
obtain ⟨b, hab⟩ := exists_add_of_le ha.le
have hb : 0 < b := not_le.1 fun hb ↦ (add_neg_of_neg_of_nonpos ha hb).ne' hab
calc
0 ≤ b ^ 2 := pow_succ_nonneg hb.le _
_ = b ^ 2 + a * (a + b) := by rw [← hab, mul_zero, add_zero]
_ = a ^ 2 + (a + b) * b := by rw [add_mul, mul_add, sq, sq, add_comm, add_assoc]
_ = a ^ 2 := by rw [← hab, zero_mul, add_zero]
@[simp]
lemma sq_nonpos_iff [ExistsAddOfLE R]
[PosMulMono R] [AddLeftMono R] [NoZeroDivisors R] (r : R) :
r ^ 2 ≤ 0 ↔ r = 0 := by
trans r ^ 2 = 0
· rw [le_antisymm_iff, and_iff_left (sq_nonneg r)]
· exact sq_eq_zero_iff
alias pow_two_nonneg := sq_nonneg
lemma mul_self_nonneg [ExistsAddOfLE R] [PosMulMono R] [AddLeftMono R]
(a : R) : 0 ≤ a * a := by simpa only [sq] using sq_nonneg a
/-- The sum of two squares is zero iff both elements are zero. -/
lemma mul_self_add_mul_self_eq_zero [NoZeroDivisors R]
[ExistsAddOfLE R] [PosMulMono R] [AddLeftMono R] :
a * a + b * b = 0 ↔ a = 0 ∧ b = 0 := by
rw [add_eq_zero_iff_of_nonneg, mul_self_eq_zero (M₀ := R), mul_self_eq_zero (M₀ := R)] <;>
apply mul_self_nonneg
lemma eq_zero_of_mul_self_add_mul_self_eq_zero [NoZeroDivisors R]
[ExistsAddOfLE R] [PosMulMono R] [AddLeftMono R]
(h : a * a + b * b = 0) : a = 0 :=
(mul_self_add_mul_self_eq_zero.mp h).left
end LinearOrderedSemiring
section LinearOrderedCommSemiring
variable [CommSemiring R] [LinearOrder R] {a d : R}
lemma max_mul_mul_le_max_mul_max [PosMulMono R] [MulPosMono R] (b c : R) (ha : 0 ≤ a) (hd : 0 ≤ d) :
max (a * b) (d * c) ≤ max a c * max d b :=
have ba : b * a ≤ max d b * max c a := by
gcongr
exacts [ha, hd.trans <| le_max_left d b, le_max_right d b, le_max_right c a]
have cd : c * d ≤ max a c * max b d :=
mul_le_mul (le_max_right a c) (le_max_right b d) hd (le_trans ha (le_max_left a c))
max_le (by simpa [mul_comm, max_comm] using ba) (by simpa [mul_comm, max_comm] using cd)
/-- Binary, squared, and division-free **arithmetic mean-geometric mean inequality**
(aka AM-GM inequality) for linearly ordered commutative semirings. -/
lemma two_mul_le_add_sq [ExistsAddOfLE R] [MulPosStrictMono R]
[AddLeftReflectLE R] [AddLeftMono R]
(a b : R) : 2 * a * b ≤ a ^ 2 + b ^ 2 := by
simpa [fn_min_add_fn_max (fun x ↦ x * x), sq, two_mul, add_mul]
using mul_add_mul_le_mul_add_mul (@min_le_max _ _ a b) (@min_le_max _ _ a b)
alias two_mul_le_add_pow_two := two_mul_le_add_sq
/-- Binary, squared, and division-free **arithmetic mean-geometric mean inequality**
(aka AM-GM inequality) for linearly ordered commutative semirings. -/
lemma four_mul_le_sq_add [ExistsAddOfLE R] [MulPosStrictMono R]
[AddLeftReflectLE R] [AddLeftMono R]
(a b : R) : 4 * a * b ≤ (a + b) ^ 2 := by
calc 4 * a * b
_ = 2 * a * b + 2 * a * b := by rw [mul_assoc, two_add_two_eq_four.symm, add_mul, mul_assoc]
_ ≤ a ^ 2 + b ^ 2 + 2 * a * b := by gcongr; exact two_mul_le_add_sq _ _
_ = a ^ 2 + 2 * a * b + b ^ 2 := by rw [add_right_comm]
_ = (a + b) ^ 2 := (add_sq a b).symm
alias four_mul_le_pow_two_add := four_mul_le_sq_add
/-- Binary and division-free **arithmetic mean-geometric mean inequality**
(aka AM-GM inequality) for linearly ordered commutative semirings. -/
lemma two_mul_le_add_of_sq_eq_mul [ExistsAddOfLE R] [MulPosStrictMono R] [PosMulStrictMono R]
[AddLeftReflectLE R] [AddLeftMono R] {a b r : R}
(ha : 0 ≤ a) (hb : 0 ≤ b) (ht : r ^ 2 = a * b) : 2 * r ≤ a + b := by
apply nonneg_le_nonneg_of_sq_le_sq (Left.add_nonneg ha hb)
conv_rhs => rw [← pow_two]
convert four_mul_le_sq_add a b using 1
rw [mul_mul_mul_comm, two_mul, two_add_two_eq_four, ← pow_two, ht, mul_assoc]
end LinearOrderedCommSemiring
section LinearOrderedRing
variable [Ring R] [LinearOrder R] {a b : R}
-- TODO: Can the following five lemmas be generalised to
-- `[Semiring R] [LinearOrder R] [ExistsAddOfLE R] ..`?
lemma mul_neg_iff [PosMulStrictMono R] [MulPosStrictMono R]
[AddLeftReflectLT R] [AddLeftStrictMono R] :
a * b < 0 ↔ 0 < a ∧ b < 0 ∨ a < 0 ∧ 0 < b := by
rw [← neg_pos, neg_mul_eq_mul_neg, mul_pos_iff (R := R), neg_pos, neg_lt_zero]
lemma mul_nonpos_iff [MulPosStrictMono R] [PosMulStrictMono R]
[AddLeftReflectLE R] [AddLeftMono R] :
a * b ≤ 0 ↔ 0 ≤ a ∧ b ≤ 0 ∨ a ≤ 0 ∧ 0 ≤ b := by
rw [← neg_nonneg, neg_mul_eq_mul_neg, mul_nonneg_iff (R := R), neg_nonneg, neg_nonpos]
lemma mul_nonneg_iff_neg_imp_nonpos [PosMulStrictMono R] [MulPosStrictMono R]
[AddLeftMono R] [AddLeftReflectLE R] :
0 ≤ a * b ↔ (a < 0 → b ≤ 0) ∧ (b < 0 → a ≤ 0) := by
rw [← neg_mul_neg, mul_nonneg_iff_pos_imp_nonneg (R := R)]; simp only [neg_pos, neg_nonneg]
lemma mul_nonpos_iff_pos_imp_nonpos [PosMulStrictMono R] [MulPosStrictMono R]
[AddLeftMono R] [AddLeftReflectLE R] :
a * b ≤ 0 ↔ (0 < a → b ≤ 0) ∧ (b < 0 → 0 ≤ a) := by
rw [← neg_nonneg, ← mul_neg, mul_nonneg_iff_pos_imp_nonneg (R := R)]
simp only [neg_pos, neg_nonneg]
lemma mul_nonpos_iff_neg_imp_nonneg [PosMulStrictMono R] [MulPosStrictMono R]
[AddLeftMono R] [AddLeftReflectLE R] :
a * b ≤ 0 ↔ (a < 0 → 0 ≤ b) ∧ (0 < b → a ≤ 0) := by
rw [← neg_nonneg, ← neg_mul, mul_nonneg_iff_pos_imp_nonneg (R := R)]
simp only [neg_pos, neg_nonneg]
lemma neg_one_lt_zero
[ZeroLEOneClass R] [NeZero (1 : R)] [AddLeftStrictMono R] :
-1 < (0 : R) := neg_lt_zero.2 zero_lt_one
lemma sub_one_lt [ZeroLEOneClass R] [NeZero (1 : R)]
[AddLeftStrictMono R]
(a : R) : a - 1 < a := sub_lt_iff_lt_add.2 <| lt_add_one a
lemma mul_self_le_mul_self_of_le_of_neg_le
[MulPosMono R] [PosMulMono R] [AddLeftMono R]
(h₁ : a ≤ b) (h₂ : -a ≤ b) : a * a ≤ b * b :=
(le_total 0 a).elim (mul_self_le_mul_self · h₁) fun h ↦
(neg_mul_neg a a).symm.trans_le <|
mul_le_mul h₂ h₂ (neg_nonneg.2 h) <| (neg_nonneg.2 h).trans h₂
lemma sub_mul_sub_nonneg_iff [MulPosStrictMono R] [PosMulStrictMono R] [AddLeftMono R]
(x : R) (h : a ≤ b) : 0 ≤ (x - a) * (x - b) ↔ x ≤ a ∨ b ≤ x := by
rw [mul_nonneg_iff, sub_nonneg, sub_nonneg, sub_nonpos, sub_nonpos,
and_iff_right_of_imp h.trans, and_iff_left_of_imp h.trans', or_comm]
lemma sub_mul_sub_nonpos_iff [MulPosStrictMono R] [PosMulStrictMono R] [AddLeftMono R]
(x : R) (h : a ≤ b) : (x - a) * (x - b) ≤ 0 ↔ a ≤ x ∧ x ≤ b := by
rw [mul_nonpos_iff, sub_nonneg, sub_nonneg, sub_nonpos, sub_nonpos, or_iff_left_iff_imp, and_comm]
exact And.imp h.trans h.trans'
lemma sub_mul_sub_pos_iff [MulPosStrictMono R] [PosMulStrictMono R] [AddLeftMono R]
(x : R) (h : a ≤ b) : 0 < (x - a) * (x - b) ↔ x < a ∨ b < x := by
rw [mul_pos_iff, sub_pos, sub_pos, sub_neg, sub_neg, and_iff_right_of_imp h.trans_lt,
and_iff_left_of_imp h.trans_lt', or_comm]
lemma sub_mul_sub_neg_iff [MulPosStrictMono R] [PosMulStrictMono R] [AddLeftMono R]
(x : R) (h : a ≤ b) : (x - a) * (x - b) < 0 ↔ a < x ∧ x < b := by
rw [mul_neg_iff, sub_pos, sub_pos, sub_neg, sub_neg, or_iff_left_iff_imp, and_comm]
exact And.imp h.trans_lt h.trans_lt'
end LinearOrderedRing
end OrderedCommRing |
.lake/packages/mathlib/Mathlib/Algebra/Azumaya/Matrix.lean | import Mathlib.Algebra.Azumaya.Defs
import Mathlib.LinearAlgebra.FreeModule.Finite.Basic
/-!
# Matrix algebra is an Azumaya algebra over R
In this file we prove that finite-dimensional matrix algebra `Matrix n n R` over `R`
is an Azumaya algebra where `R` is a commutative ring.
## Main Results
- `IsAzumaya.Matrix`: Finite-dimensional matrix algebra over `R` is Azumaya.
-/
open scoped TensorProduct
variable (R n : Type*) [CommSemiring R] [Fintype n] [DecidableEq n]
noncomputable section
open Matrix MulOpposite
/-- `AlgHom.mulLeftRight` for matrix algebra sends basis Eᵢⱼ⊗Eₖₗ to
the map `f : Eₛₜ ↦ Eᵢⱼ * Eₛₜ * Eₖₗ = δⱼₛδₜₖEᵢₗ`, therefore we construct the inverse
by sending `f` to `∑ᵢₗₛₜ f(Eₛₜ)ᵢₗ • Eᵢₛ⊗Eₜₗ`. -/
abbrev AlgHom.mulLeftRightMatrix_inv :
Module.End R (Matrix n n R) →ₗ[R] Matrix n n R ⊗[R] (Matrix n n R)ᵐᵒᵖ where
toFun f := ∑ ⟨⟨i, j⟩, k, l⟩ : (n × n) × n × n,
f (single j k 1) i l • (single i j 1) ⊗ₜ[R] op (single k l 1)
map_add' f1 f2 := by simp [add_smul, Finset.sum_add_distrib]
map_smul' r f := by simp [MulAction.mul_smul, Finset.smul_sum]
lemma AlgHom.mulLeftRightMatrix.inv_comp :
(AlgHom.mulLeftRightMatrix_inv R n).comp
(AlgHom.mulLeftRight R (Matrix n n R)).toLinearMap = .id :=
((Matrix.stdBasis _ _ _).tensorProduct ((Matrix.stdBasis _ _ _).map (opLinearEquiv ..))).ext
fun ⟨⟨i0, j0⟩, k0, l0⟩ ↦ by
simp [stdBasis_eq_single, ite_and, Fintype.sum_prod_type,
mulLeftRight_apply, single, Matrix.mul_apply]
lemma AlgHom.mulLeftRightMatrix.comp_inv :
(AlgHom.mulLeftRight R (Matrix n n R)).toLinearMap.comp
(AlgHom.mulLeftRightMatrix_inv R n) = .id := by
ext f : 1
apply (Matrix.stdBasis _ _ _).ext
intro ⟨i, j⟩
simp only [LinearMap.coe_comp, LinearMap.coe_mk, AddHom.coe_mk, Function.comp_apply, map_sum,
map_smul, stdBasis_eq_single, LinearMap.coeFn_sum, Finset.sum_apply,
LinearMap.smul_apply, LinearMap.id_coe, id_eq]
ext k l
simp [sum_apply, Matrix.mul_apply, single, Fintype.sum_prod_type, ite_and]
namespace IsAzumaya
/-- A nontrivial matrix ring over `R` is an Azumaya algebra over `R`. -/
theorem matrix [Nonempty n] : IsAzumaya R (Matrix n n R) where
eq_of_smul_eq_smul := by nontriviality R; exact eq_of_smul_eq_smul
bij := Function.bijective_iff_has_inverse.mpr
⟨AlgHom.mulLeftRightMatrix_inv R n,
DFunLike.congr_fun (AlgHom.mulLeftRightMatrix.inv_comp R n),
DFunLike.congr_fun (AlgHom.mulLeftRightMatrix.comp_inv R n)⟩
end IsAzumaya
end |
.lake/packages/mathlib/Mathlib/Algebra/Azumaya/Basic.lean | import Mathlib.Algebra.Azumaya.Defs
import Mathlib.LinearAlgebra.Matrix.ToLin
import Mathlib.RingTheory.Finiteness.Basic
import Mathlib.GroupTheory.GroupAction.Hom
import Mathlib.RingTheory.TensorProduct.Maps
/-!
# Basic properties of Azumaya algebras
In this file we prove basic facts about Azumaya algebras such as `R` is an Azumaya algebra
over itself where `R` is a commutative ring.
## Main Results
- `IsAzumaya.id`: `R` is an Azumaya algebra over itself.
- `IsAzumaya.ofAlgEquiv`: If `A` is an Azumaya algebra over `R` and `A` is isomorphic to `B`
as an `R`-algebra, then `B` is an Azumaya algebra over `R`.
## Tags
Noncommutative algebra, Azumaya algebra, Brauer Group
-/
open scoped TensorProduct
open MulOpposite
namespace IsAzumaya
variable (R A B : Type*) [CommSemiring R] [Ring A] [Ring B] [Algebra R A] [Algebra R B]
lemma AlgHom.mulLeftRight_bij [h : IsAzumaya R A] :
Function.Bijective (AlgHom.mulLeftRight R A) := h.bij
/-- The "canonical" isomorphism between `R ⊗ Rᵒᵖ` and `End R R` which is equal
to `AlgHom.mulLeftRight R R`. -/
abbrev tensorEquivEnd : R ⊗[R] Rᵐᵒᵖ ≃ₐ[R] Module.End R R :=
Algebra.TensorProduct.lid R Rᵐᵒᵖ |>.trans <| .moduleEndSelf R
lemma coe_tensorEquivEnd : tensorEquivEnd R = AlgHom.mulLeftRight R R := by
ext; simp
instance id : IsAzumaya R R where
bij := by rw [← coe_tensorEquivEnd]; exact tensorEquivEnd R |>.bijective
/--
The following diagram commutes:
```
e ⊗ eᵒᵖ
A ⊗ Aᵐᵒᵖ ------------> B ⊗ Bᵐᵒᵖ
| |
| |
| mulLeftRight R A | mulLeftRight R B
| |
V V
End R A ------------> End R B
e.conj
```
-/
lemma mulLeftRight_comp_congr (e : A ≃ₐ[R] B) :
(AlgHom.mulLeftRight R B).comp (Algebra.TensorProduct.congr e e.op).toAlgHom =
(e.toLinearEquiv.algConj R).toAlgHom.comp (AlgHom.mulLeftRight R A) := by
ext <;> simp
theorem of_AlgEquiv (e : A ≃ₐ[R] B) [IsAzumaya R A] : IsAzumaya R B :=
let _ : Module.Projective R B := .of_equiv e.toLinearEquiv
let _ : FaithfulSMul R B := .of_injective e e.injective
let _ : Module.Finite R B := .equiv e.toLinearEquiv
⟨Function.Bijective.of_comp_iff (AlgHom.mulLeftRight R B)
(Algebra.TensorProduct.congr e e.op).bijective |>.1 <| by
rw [← AlgEquiv.coe_algHom, ← AlgHom.coe_comp, mulLeftRight_comp_congr]
simp [AlgHom.mulLeftRight_bij]⟩
end IsAzumaya |
.lake/packages/mathlib/Mathlib/Algebra/Azumaya/Defs.lean | import Mathlib.Algebra.Module.Projective
import Mathlib.RingTheory.Finiteness.Defs
import Mathlib.RingTheory.TensorProduct.Basic
/-!
# Azumaya Algebras
An Azumaya algebra over a commutative ring `R` is a finitely generated, projective
and faithful R-algebra where the tensor product `A ⊗[R] Aᵐᵒᵖ` is isomorphic to the
`R`-endomorphisms of A via the map `f : a ⊗ b ↦ (x ↦ a * x * b.unop)`.
TODO : Add the three more definitions and prove they are equivalent:
· There exists an `R`-algebra `B` such that `B ⊗[R] A` is Morita equivalent to `R`;
· `Aᵐᵒᵖ ⊗[R] A` is Morita equivalent to `R`;
· The center of `A` is `R` and `A` is a separable algebra.
## Reference
* [Benson Farb, R. Keith Dennis, *Noncommutative Algebra*][bensonfarb1993]
## Tags
Azumaya algebra, central simple algebra, noncommutative algebra
-/
variable (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A]
open TensorProduct MulOpposite
/-- `A` as a `A ⊗[R] Aᵐᵒᵖ`-module (or equivalently, an `A`-`A` bimodule). -/
abbrev instModuleTensorProductMop : Module (A ⊗[R] Aᵐᵒᵖ) A := TensorProduct.Algebra.module
/-- The canonical map from `A ⊗[R] Aᵐᵒᵖ` to `Module.End R A` where
`a ⊗ b` maps to `f : x ↦ a * x * b`. -/
def AlgHom.mulLeftRight : (A ⊗[R] Aᵐᵒᵖ) →ₐ[R] Module.End R A :=
letI : Module (A ⊗[R] Aᵐᵒᵖ) A := TensorProduct.Algebra.module
letI : IsScalarTower R (A ⊗[R] Aᵐᵒᵖ) A := {
smul_assoc := fun r ab a ↦ by
change TensorProduct.Algebra.moduleAux _ _ = _ • TensorProduct.Algebra.moduleAux _ _
simp }
Algebra.lsmul R (A := A ⊗[R] Aᵐᵒᵖ) R A
@[simp]
lemma AlgHom.mulLeftRight_apply (a : A) (b : Aᵐᵒᵖ) (x : A) :
AlgHom.mulLeftRight R A (a ⊗ₜ b) x = a * x * b.unop := by
simp only [AlgHom.mulLeftRight, Algebra.lsmul_coe]
change TensorProduct.Algebra.moduleAux _ _ = _
simp [TensorProduct.Algebra.moduleAux, ← mul_assoc]
/-- An Azumaya algebra is a finitely generated, projective and faithful R-algebra where
`AlgHom.mulLeftRight R A : (A ⊗[R] Aᵐᵒᵖ) →ₐ[R] Module.End R A` is an isomorphism. -/
class IsAzumaya : Prop extends Module.Projective R A, FaithfulSMul R A, Module.Finite R A where
bij : Function.Bijective <| AlgHom.mulLeftRight R A |
.lake/packages/mathlib/Mathlib/Algebra/FreeAlgebra/Cardinality.lean | import Mathlib.Algebra.FreeAlgebra
import Mathlib.SetTheory.Cardinal.Free
/-!
# Cardinality of free algebras
This file contains some results about the cardinality of `FreeAlgebra`,
parallel to that of `MvPolynomial`.
-/
universe u v
variable (R : Type u) [CommSemiring R]
open Cardinal
namespace FreeAlgebra
variable (X : Type v)
@[simp]
theorem cardinalMk_eq_max_lift [Nonempty X] [Nontrivial R] :
#(FreeAlgebra R X) = Cardinal.lift.{v} #R ⊔ Cardinal.lift.{u} #X ⊔ ℵ₀ := by
have hX := mk_freeMonoid X
rw [equivMonoidAlgebraFreeMonoid.toEquiv.cardinal_eq, MonoidAlgebra,
mk_finsupp_lift_of_infinite, hX, lift_max, lift_aleph0, sup_comm, ← sup_assoc]
@[simp]
theorem cardinalMk_eq_lift [IsEmpty X] : #(FreeAlgebra R X) = Cardinal.lift.{v} #R := by
have := lift_mk_eq'.2 ⟨show (FreeMonoid X →₀ R) ≃ R from Equiv.finsuppUnique⟩
rw [lift_id'.{u, v}, lift_umax] at this
rwa [equivMonoidAlgebraFreeMonoid.toEquiv.cardinal_eq, MonoidAlgebra]
@[nontriviality]
theorem cardinalMk_eq_one [Subsingleton R] : #(FreeAlgebra R X) = 1 := by
rw [equivMonoidAlgebraFreeMonoid.toEquiv.cardinal_eq, MonoidAlgebra, mk_eq_one]
theorem cardinalMk_le_max_lift :
#(FreeAlgebra R X) ≤ Cardinal.lift.{v} #R ⊔ Cardinal.lift.{u} #X ⊔ ℵ₀ := by
cases subsingleton_or_nontrivial R
· exact (cardinalMk_eq_one R X).trans_le (le_max_of_le_right one_le_aleph0)
cases isEmpty_or_nonempty X
· exact (cardinalMk_eq_lift R X).trans_le (le_max_of_le_left <| le_max_left _ _)
· exact (cardinalMk_eq_max_lift R X).le
variable (X : Type u)
theorem cardinalMk_eq_max [Nonempty X] [Nontrivial R] : #(FreeAlgebra R X) = #R ⊔ #X ⊔ ℵ₀ := by
simp
theorem cardinalMk_eq [IsEmpty X] : #(FreeAlgebra R X) = #R := by
simp
theorem cardinalMk_le_max : #(FreeAlgebra R X) ≤ #R ⊔ #X ⊔ ℵ₀ := by
simpa using cardinalMk_le_max_lift R X
end FreeAlgebra
namespace Algebra
theorem lift_cardinalMk_adjoin_le {A : Type v} [Semiring A] [Algebra R A] (s : Set A) :
lift.{u} #(adjoin R s) ≤ lift.{v} #R ⊔ lift.{u} #s ⊔ ℵ₀ := by
have H := mk_range_le_lift (f := FreeAlgebra.lift R ((↑) : s → A))
rw [lift_umax, lift_id'.{v, u}] at H
rw [Algebra.adjoin_eq_range_freeAlgebra_lift]
exact H.trans (FreeAlgebra.cardinalMk_le_max_lift R s)
theorem cardinalMk_adjoin_le {A : Type u} [Semiring A] [Algebra R A] (s : Set A) :
#(adjoin R s) ≤ #R ⊔ #s ⊔ ℵ₀ := by
simpa using lift_cardinalMk_adjoin_le R s
end Algebra |
.lake/packages/mathlib/Mathlib/Algebra/DirectSum/Decomposition.lean | import Mathlib.Algebra.DirectSum.Module
import Mathlib.Algebra.Module.Submodule.Basic
/-!
# Decompositions of additive monoids, groups, and modules into direct sums
## Main definitions
* `DirectSum.Decomposition ℳ`: A typeclass to provide a constructive decomposition from
an additive monoid `M` into a family of additive submonoids `ℳ`
* `DirectSum.decompose ℳ`: The canonical equivalence provided by the above typeclass
## Main statements
* `DirectSum.Decomposition.isInternal`: The link to `DirectSum.IsInternal`.
## Implementation details
As we want to talk about different types of decomposition (additive monoids, modules, rings, ...),
we choose to avoid heavily bundling `DirectSum.decompose`, instead making copies for the
`AddEquiv`, `LinearEquiv`, etc. This means we have to repeat statements that follow from these
bundled homs, but means we don't have to repeat statements for different types of decomposition.
-/
variable {ι R M σ : Type*}
open DirectSum
namespace DirectSum
section AddCommMonoid
variable [DecidableEq ι] [AddCommMonoid M]
variable [SetLike σ M] [AddSubmonoidClass σ M] (ℳ : ι → σ)
/-- A decomposition is an equivalence between an additive monoid `M` and a direct sum of additive
submonoids `ℳ i` of that `M`, such that the "recomposition" is canonical. This definition also
works for additive groups and modules.
This is a version of `DirectSum.IsInternal` which comes with a constructive inverse to the
canonical "recomposition" rather than just a proof that the "recomposition" is bijective.
Often it is easier to construct a term of this type via `Decomposition.ofAddHom` or
`Decomposition.ofLinearMap`. -/
class Decomposition where
decompose' : M → ⨁ i, ℳ i
left_inv : Function.LeftInverse (DirectSum.coeAddMonoidHom ℳ) decompose'
right_inv : Function.RightInverse (DirectSum.coeAddMonoidHom ℳ) decompose'
/-- `DirectSum.Decomposition` instances, while carrying data, are always equal. -/
instance : Subsingleton (Decomposition ℳ) :=
⟨fun x y ↦ by
obtain ⟨_, _, xr⟩ := x
obtain ⟨_, yl, _⟩ := y
congr
exact Function.LeftInverse.eq_rightInverse xr yl⟩
/-- A convenience method to construct a decomposition from an `AddMonoidHom`, such that the proofs
of left and right inverse can be constructed via `ext`. -/
abbrev Decomposition.ofAddHom (decompose : M →+ ⨁ i, ℳ i)
(h_left_inv : (DirectSum.coeAddMonoidHom ℳ).comp decompose = .id _)
(h_right_inv : decompose.comp (DirectSum.coeAddMonoidHom ℳ) = .id _) : Decomposition ℳ where
decompose' := decompose
left_inv := DFunLike.congr_fun h_left_inv
right_inv := DFunLike.congr_fun h_right_inv
/-- Noncomputably conjure a decomposition instance from a `DirectSum.IsInternal` proof. -/
noncomputable def IsInternal.chooseDecomposition (h : IsInternal ℳ) :
DirectSum.Decomposition ℳ where
decompose' := (Equiv.ofBijective _ h).symm
left_inv := (Equiv.ofBijective _ h).right_inv
right_inv := (Equiv.ofBijective _ h).left_inv
variable [Decomposition ℳ]
protected theorem Decomposition.isInternal : DirectSum.IsInternal ℳ :=
⟨Decomposition.right_inv.injective, Decomposition.left_inv.surjective⟩
/-- If `M` is graded by `ι` with degree `i` component `ℳ i`, then it is isomorphic as
to a direct sum of components. This is the canonical spelling of the `decompose'` field. -/
def decompose : M ≃ ⨁ i, ℳ i where
toFun := Decomposition.decompose'
invFun := DirectSum.coeAddMonoidHom ℳ
left_inv := Decomposition.left_inv
right_inv := Decomposition.right_inv
omit [AddSubmonoidClass σ M] in
/-- A substructure `p ⊆ M` is homogeneous if for every `m ∈ p`, all homogeneous components
of `m` are in `p`. -/
def SetLike.IsHomogeneous {P : Type*} [SetLike P M] (p : P) : Prop :=
∀ (i : ι) ⦃m : M⦄, m ∈ p → (DirectSum.decompose ℳ m i : M) ∈ p
@[elab_as_elim]
protected theorem Decomposition.inductionOn {motive : M → Prop} (zero : motive 0)
(homogeneous : ∀ {i} (m : ℳ i), motive (m : M))
(add : ∀ m m' : M, motive m → motive m' → motive (m + m')) : ∀ m, motive m := by
let ℳ' : ι → AddSubmonoid M := fun i ↦
(⟨⟨ℳ i, fun x y ↦ AddMemClass.add_mem x y⟩, (ZeroMemClass.zero_mem _)⟩ : AddSubmonoid M)
haveI t : DirectSum.Decomposition ℳ' :=
{ decompose' := DirectSum.decompose ℳ
left_inv := fun _ ↦ (decompose ℳ).left_inv _
right_inv := fun _ ↦ (decompose ℳ).right_inv _ }
have mem : ∀ m, m ∈ iSup ℳ' := fun _m ↦
(DirectSum.IsInternal.addSubmonoid_iSup_eq_top ℳ' (Decomposition.isInternal ℳ')).symm ▸ trivial
-- Porting note: needs to use @ even though no implicit argument is provided
exact fun m ↦ @AddSubmonoid.iSup_induction _ _ _ ℳ' _ _ (mem m)
(fun i m h ↦ homogeneous ⟨m, h⟩) zero add
-- exact fun m ↦
-- AddSubmonoid.iSup_induction ℳ' (mem m) (fun i m h ↦ h_homogeneous ⟨m, h⟩) h_zero h_add
@[simp]
theorem Decomposition.decompose'_eq : Decomposition.decompose' = decompose ℳ := rfl
@[simp]
theorem decompose_symm_of {i : ι} (x : ℳ i) : (decompose ℳ).symm (DirectSum.of _ i x) = x :=
DirectSum.coeAddMonoidHom_of ℳ _ _
@[simp]
theorem decompose_coe {i : ι} (x : ℳ i) : decompose ℳ (x : M) = DirectSum.of _ i x := by
rw [← decompose_symm_of _, Equiv.apply_symm_apply]
theorem decompose_of_mem {x : M} {i : ι} (hx : x ∈ ℳ i) :
decompose ℳ x = DirectSum.of (fun i ↦ ℳ i) i ⟨x, hx⟩ :=
decompose_coe _ ⟨x, hx⟩
theorem decompose_of_mem_same {x : M} {i : ι} (hx : x ∈ ℳ i) : (decompose ℳ x i : M) = x := by
rw [decompose_of_mem _ hx, DirectSum.of_eq_same, Subtype.coe_mk]
theorem decompose_of_mem_ne {x : M} {i j : ι} (hx : x ∈ ℳ i) (hij : i ≠ j) :
(decompose ℳ x j : M) = 0 := by
rw [decompose_of_mem _ hx, DirectSum.of_eq_of_ne _ _ _ hij.symm, ZeroMemClass.coe_zero]
theorem degree_eq_of_mem_mem {x : M} {i j : ι} (hxi : x ∈ ℳ i) (hxj : x ∈ ℳ j) (hx : x ≠ 0) :
i = j := by
contrapose! hx; rw [← decompose_of_mem_same ℳ hxj, decompose_of_mem_ne ℳ hxi hx]
/-- If `M` is graded by `ι` with degree `i` component `ℳ i`, then it is isomorphic as
an additive monoid to a direct sum of components. -/
@[simps!]
def decomposeAddEquiv : M ≃+ ⨁ i, ℳ i :=
AddEquiv.symm { (decompose ℳ).symm with map_add' := map_add (DirectSum.coeAddMonoidHom ℳ) }
@[simp]
theorem decompose_zero : decompose ℳ (0 : M) = 0 :=
map_zero (decomposeAddEquiv ℳ)
@[simp]
theorem decompose_symm_zero : (decompose ℳ).symm 0 = (0 : M) :=
map_zero (decomposeAddEquiv ℳ).symm
@[simp]
theorem decompose_add (x y : M) : decompose ℳ (x + y) = decompose ℳ x + decompose ℳ y :=
map_add (decomposeAddEquiv ℳ) x y
@[simp]
theorem decompose_symm_add (x y : ⨁ i, ℳ i) :
(decompose ℳ).symm (x + y) = (decompose ℳ).symm x + (decompose ℳ).symm y :=
map_add (decomposeAddEquiv ℳ).symm x y
@[simp]
theorem decompose_sum {ι'} (s : Finset ι') (f : ι' → M) :
decompose ℳ (∑ i ∈ s, f i) = ∑ i ∈ s, decompose ℳ (f i) :=
map_sum (decomposeAddEquiv ℳ) f s
@[simp]
theorem decompose_symm_sum {ι'} (s : Finset ι') (f : ι' → ⨁ i, ℳ i) :
(decompose ℳ).symm (∑ i ∈ s, f i) = ∑ i ∈ s, (decompose ℳ).symm (f i) :=
map_sum (decomposeAddEquiv ℳ).symm f s
theorem sum_support_decompose [∀ (i) (x : ℳ i), Decidable (x ≠ 0)] (r : M) :
(∑ i ∈ (decompose ℳ r).support, (decompose ℳ r i : M)) = r := by
conv_rhs =>
rw [← (decompose ℳ).symm_apply_apply r, ← sum_support_of (decompose ℳ r)]
rw [decompose_symm_sum]
simp_rw [decompose_symm_of]
theorem AddSubmonoidClass.IsHomogeneous.mem_iff
{P : Type*} [SetLike P M] [AddSubmonoidClass P M] (p : P)
(hp : SetLike.IsHomogeneous ℳ p) {x} :
x ∈ p ↔ ∀ i, (decompose ℳ x i : M) ∈ p := by
classical
refine ⟨fun hx i ↦ hp i hx, fun hx ↦ ?_⟩
rw [← DirectSum.sum_support_decompose ℳ x]
exact sum_mem (fun i _ ↦ hx i)
theorem AddSubmonoidClass.IsHomogeneous.ext
{ℳ : ι → σ} [Decomposition ℳ] {P : Type*} [SetLike P M] [AddSubmonoidClass P M]
{p q : P} (hp : SetLike.IsHomogeneous ℳ p) (hq : SetLike.IsHomogeneous ℳ q)
(hpq : ∀ i, ∀ m ∈ ℳ i, m ∈ p ↔ m ∈ q) :
p = q := by
refine SetLike.ext fun m ↦ ?_
rw [AddSubmonoidClass.IsHomogeneous.mem_iff ℳ p hp,
AddSubmonoidClass.IsHomogeneous.mem_iff ℳ q hq]
exact forall_congr' fun i ↦ hpq i _ (decompose ℳ _ i).2
end AddCommMonoid
/-- The `-` in the statements below doesn't resolve without this line.
This seems to be a problem of synthesized vs inferred typeclasses disagreeing. If we replace
the statement of `decompose_neg` with `@Eq (⨁ i, ℳ i) (decompose ℳ (-x)) (-decompose ℳ x)`
instead of `decompose ℳ (-x) = -decompose ℳ x`, which forces the typeclasses needed by `⨁ i, ℳ i`
to be found by unification rather than synthesis, then everything works fine without this
instance. -/
instance addCommGroupSetLike [AddCommGroup M] [SetLike σ M] [AddSubgroupClass σ M] (ℳ : ι → σ) :
AddCommGroup (⨁ i, ℳ i) := by infer_instance
section AddCommGroup
variable [DecidableEq ι] [AddCommGroup M]
variable [SetLike σ M] [AddSubgroupClass σ M] (ℳ : ι → σ)
variable [Decomposition ℳ]
@[simp]
theorem decompose_neg (x : M) : decompose ℳ (-x) = -decompose ℳ x :=
map_neg (decomposeAddEquiv ℳ) x
@[simp]
theorem decompose_symm_neg (x : ⨁ i, ℳ i) : (decompose ℳ).symm (-x) = -(decompose ℳ).symm x :=
map_neg (decomposeAddEquiv ℳ).symm x
@[simp]
theorem decompose_sub (x y : M) : decompose ℳ (x - y) = decompose ℳ x - decompose ℳ y :=
map_sub (decomposeAddEquiv ℳ) x y
@[simp]
theorem decompose_symm_sub (x y : ⨁ i, ℳ i) :
(decompose ℳ).symm (x - y) = (decompose ℳ).symm x - (decompose ℳ).symm y :=
map_sub (decomposeAddEquiv ℳ).symm x y
end AddCommGroup
section Module
variable [DecidableEq ι] [Semiring R] [AddCommMonoid M] [Module R M]
variable (ℳ : ι → Submodule R M)
/-- A convenience method to construct a decomposition from an `LinearMap`, such that the proofs
of left and right inverse can be constructed via `ext`. -/
abbrev Decomposition.ofLinearMap (decompose : M →ₗ[R] ⨁ i, ℳ i)
(h_left_inv : DirectSum.coeLinearMap ℳ ∘ₗ decompose = .id)
(h_right_inv : decompose ∘ₗ DirectSum.coeLinearMap ℳ = .id) : Decomposition ℳ where
decompose' := decompose
left_inv := DFunLike.congr_fun h_left_inv
right_inv := DFunLike.congr_fun h_right_inv
variable [Decomposition ℳ]
/-- If `M` is graded by `ι` with degree `i` component `ℳ i`, then it is isomorphic as
a module to a direct sum of components. -/
def decomposeLinearEquiv : M ≃ₗ[R] ⨁ i, ℳ i :=
LinearEquiv.symm
{ (decomposeAddEquiv ℳ).symm with map_smul' := map_smul (DirectSum.coeLinearMap ℳ) }
@[simp] theorem decomposeLinearEquiv_apply (m : M) :
decomposeLinearEquiv ℳ m = decompose ℳ m := rfl
@[simp] theorem decomposeLinearEquiv_symm_apply (m : ⨁ i, ℳ i) :
(decomposeLinearEquiv ℳ).symm m = (decompose ℳ).symm m := rfl
@[simp]
theorem decompose_smul (r : R) (x : M) : decompose ℳ (r • x) = r • decompose ℳ x :=
map_smul (decomposeLinearEquiv ℳ) r x
@[simp] theorem decomposeLinearEquiv_symm_comp_lof (i : ι) :
(decomposeLinearEquiv ℳ).symm ∘ₗ lof R ι (ℳ ·) i = (ℳ i).subtype :=
LinearMap.ext <| decompose_symm_of _
/-- Two linear maps from a module with a decomposition agree if they agree on every piece.
Note this cannot be `@[ext]` as `ℳ` cannot be inferred. -/
theorem decompose_lhom_ext {N} [AddCommMonoid N] [Module R N] ⦃f g : M →ₗ[R] N⦄
(h : ∀ i, f ∘ₗ (ℳ i).subtype = g ∘ₗ (ℳ i).subtype) : f = g :=
LinearMap.ext <| (decomposeLinearEquiv ℳ).symm.surjective.forall.mpr <|
suffices f ∘ₗ (decomposeLinearEquiv ℳ).symm
= (g ∘ₗ (decomposeLinearEquiv ℳ).symm : (⨁ i, ℳ i) →ₗ[R] N) from
DFunLike.congr_fun this
linearMap_ext _ fun i => by
simp_rw [LinearMap.comp_assoc, decomposeLinearEquiv_symm_comp_lof ℳ i, h]
end Module
end DirectSum |
.lake/packages/mathlib/Mathlib/Algebra/DirectSum/Module.lean | import Mathlib.Algebra.DirectSum.Basic
import Mathlib.LinearAlgebra.DFinsupp
import Mathlib.LinearAlgebra.Basis.Defs
/-!
# Direct sum of modules
The first part of the file provides constructors for direct sums of modules. It provides a
construction of the direct sum using the universal property and proves its uniqueness
(`DirectSum.toModule.unique`).
The second part of the file covers the special case of direct sums of submodules of a fixed module
`M`. There is a canonical linear map from this direct sum to `M` (`DirectSum.coeLinearMap`), and
the construction is of particular importance when this linear map is an equivalence; that is, when
the submodules provide an internal decomposition of `M`. The property is defined more generally
elsewhere as `DirectSum.IsInternal`, but its basic consequences on `Submodule`s are established
in this file.
-/
universe u v w u₁
namespace DirectSum
open DirectSum Finsupp Module
section General
variable {R : Type u} [Semiring R]
variable {ι : Type v}
variable {M : ι → Type w} [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)]
instance : Module R (⨁ i, M i) :=
DFinsupp.module
instance {S : Type*} [Semiring S] [∀ i, Module S (M i)] [∀ i, SMulCommClass R S (M i)] :
SMulCommClass R S (⨁ i, M i) :=
DFinsupp.smulCommClass
instance {S : Type*} [Semiring S] [SMul R S] [∀ i, Module S (M i)] [∀ i, IsScalarTower R S (M i)] :
IsScalarTower R S (⨁ i, M i) :=
DFinsupp.isScalarTower
instance [∀ i, Module Rᵐᵒᵖ (M i)] [∀ i, IsCentralScalar R (M i)] : IsCentralScalar R (⨁ i, M i) :=
DFinsupp.isCentralScalar
theorem smul_apply (b : R) (v : ⨁ i, M i) (i : ι) : (b • v) i = b • v i :=
DFinsupp.smul_apply _ _ _
variable (R) in
/-- Coercion from a `DirectSum` to a pi type is a `LinearMap`. -/
def coeFnLinearMap : (⨁ i, M i) →ₗ[R] ∀ i, M i :=
DFinsupp.coeFnLinearMap R
@[simp]
lemma coeFnLinearMap_apply (v : ⨁ i, M i) : coeFnLinearMap R v = v :=
rfl
variable (R ι M)
section DecidableEq
variable [DecidableEq ι]
/-- Create the direct sum given a family `M` of `R` modules indexed over `ι`. -/
def lmk : ∀ s : Finset ι, (∀ i : (↑s : Set ι), M i.val) →ₗ[R] ⨁ i, M i :=
DFinsupp.lmk
/-- Inclusion of each component into the direct sum. -/
def lof : ∀ i : ι, M i →ₗ[R] ⨁ i, M i :=
DFinsupp.lsingle
theorem lof_eq_of (i : ι) (b : M i) : lof R ι M i b = of M i b := rfl
variable {ι M}
theorem single_eq_lof (i : ι) (b : M i) : DFinsupp.single i b = lof R ι M i b := rfl
/-- Scalar multiplication commutes with direct sums. -/
theorem mk_smul (s : Finset ι) (c : R) (x) : mk M s (c • x) = c • mk M s x :=
(lmk R ι M s).map_smul c x
/-- Scalar multiplication commutes with the inclusion of each component into the direct sum. -/
theorem of_smul (i : ι) (c : R) (x) : of M i (c • x) = c • of M i x :=
(lof R ι M i).map_smul c x
variable {R}
theorem support_smul [∀ (i : ι) (x : M i), Decidable (x ≠ 0)] (c : R) (v : ⨁ i, M i) :
(c • v).support ⊆ v.support :=
DFinsupp.support_smul _ _
variable {N : Type u₁} [AddCommMonoid N] [Module R N]
variable (φ : ∀ i, M i →ₗ[R] N)
variable (R ι N)
/-- The linear map constructed using the universal property of the coproduct. -/
def toModule : (⨁ i, M i) →ₗ[R] N :=
DFunLike.coe (DFinsupp.lsum ℕ) φ
/-- Coproducts in the categories of modules and additive monoids commute with the forgetful functor
from modules to additive monoids. -/
theorem coe_toModule_eq_coe_toAddMonoid :
(toModule R ι N φ : (⨁ i, M i) → N) = toAddMonoid fun i ↦ (φ i).toAddMonoidHom := rfl
variable {ι N φ}
/-- The map constructed using the universal property gives back the original maps when
restricted to each component. -/
@[simp]
theorem toModule_lof (i) (x : M i) : toModule R ι N φ (lof R ι M i x) = φ i x :=
toAddMonoid_of (fun i ↦ (φ i).toAddMonoidHom) i x
variable (ψ : (⨁ i, M i) →ₗ[R] N)
/-- Every linear map from a direct sum agrees with the one obtained by applying
the universal property to each of its components. -/
theorem toModule.unique (f : ⨁ i, M i) : ψ f = toModule R ι N (fun i ↦ ψ.comp <| lof R ι M i) f :=
toAddMonoid.unique ψ.toAddMonoidHom f
variable {ψ} {ψ' : (⨁ i, M i) →ₗ[R] N}
/-- Two `LinearMap`s out of a direct sum are equal if they agree on the generators.
See note [partially-applied ext lemmas]. -/
@[ext]
theorem linearMap_ext ⦃ψ ψ' : (⨁ i, M i) →ₗ[R] N⦄
(H : ∀ i, ψ.comp (lof R ι M i) = ψ'.comp (lof R ι M i)) : ψ = ψ' :=
DFinsupp.lhom_ext' H
/-- The inclusion of a subset of the direct summands
into a larger subset of the direct summands, as a linear map. -/
def lsetToSet (S T : Set ι) (H : S ⊆ T) : (⨁ i : S, M i) →ₗ[R] ⨁ i : T, M i :=
toModule R _ _ fun i ↦ lof R T (fun i : Subtype T ↦ M i) ⟨i, H i.prop⟩
variable (ι M)
/-- Given `Fintype α`, `linearEquivFunOnFintype R` is the natural `R`-linear equivalence
between `⨁ i, M i` and `∀ i, M i`. -/
@[simps! apply]
def linearEquivFunOnFintype [Fintype ι] : (⨁ i, M i) ≃ₗ[R] ∀ i, M i :=
DFinsupp.linearEquivFunOnFintype
variable {ι M}
@[simp]
theorem linearEquivFunOnFintype_lof [Fintype ι] (i : ι) (m : M i) :
(linearEquivFunOnFintype R ι M) (lof R ι M i m) = Pi.single i m := by
rfl
@[simp]
theorem linearEquivFunOnFintype_symm_single [Fintype ι] (i : ι) (m : M i) :
(linearEquivFunOnFintype R ι M).symm (Pi.single i m) = lof R ι M i m :=
DFinsupp.equivFunOnFintype_symm_single i m
end DecidableEq
@[simp]
theorem linearEquivFunOnFintype_symm_coe [Fintype ι] (f : ⨁ i, M i) :
(linearEquivFunOnFintype R ι M).symm f = f :=
(linearEquivFunOnFintype R ι M).symm_apply_apply _
/-- The natural linear equivalence between `⨁ _ : ι, M` and `M` when `Unique ι`. -/
protected def lid (M : Type v) (ι : Type* := PUnit) [AddCommMonoid M] [Module R M] [Unique ι] :
(⨁ _ : ι, M) ≃ₗ[R] M :=
{ DirectSum.id M ι, toModule R ι M fun _ ↦ LinearMap.id with }
/-- The projection map onto one component, as a linear map. -/
def component (i : ι) : (⨁ i, M i) →ₗ[R] M i :=
DFinsupp.lapply i
variable {ι M}
theorem apply_eq_component (f : ⨁ i, M i) (i : ι) : f i = component R ι M i f := rfl
-- Note(kmill): `@[ext]` cannot prove `ext_iff` because `R` is not determined by `f` or `g`.
-- This is not useful as an `@[ext]` lemma as the `ext` tactic cannot infer `R`.
theorem ext_component {f g : ⨁ i, M i} (h : ∀ i, component R ι M i f = component R ι M i g) :
f = g :=
DFinsupp.ext h
theorem ext_component_iff {f g : ⨁ i, M i} :
f = g ↔ ∀ i, component R ι M i f = component R ι M i g :=
⟨fun h _ ↦ by rw [h], ext_component R⟩
@[simp]
theorem lof_apply [DecidableEq ι] (i : ι) (b : M i) : ((lof R ι M i) b) i = b :=
DFinsupp.single_eq_same
@[simp]
theorem component.lof_self [DecidableEq ι] (i : ι) (b : M i) :
component R ι M i ((lof R ι M i) b) = b :=
lof_apply R i b
theorem component.of [DecidableEq ι] (i j : ι) (b : M j) :
component R ι M i ((lof R ι M j) b) = if h : j = i then Eq.recOn h b else 0 :=
DFinsupp.single_apply
section map
variable {R} {N : ι → Type*}
section AddCommMonoid
variable [∀ i, AddCommMonoid (N i)] [∀ i, Module R (N i)]
section
variable (f : ∀ i, M i →+ N i)
lemma mker_map :
AddMonoidHom.mker (map f) =
(AddSubmonoid.pi Set.univ (fun i ↦ AddMonoidHom.mker (f i))).comap (coeFnAddMonoidHom M) :=
DFinsupp.mker_mapRangeAddMonoidHom f
lemma mrange_map :
AddMonoidHom.mrange (map f) =
(AddSubmonoid.pi Set.univ (fun i ↦ AddMonoidHom.mrange (f i))).comap (coeFnAddMonoidHom N) :=
DFinsupp.mrange_mapRangeAddMonoidHom f
end
variable (f : Π i, M i →ₗ[R] N i)
/-- The linear map between direct sums induced by a family of linear maps. -/
def lmap : (⨁ i, M i) →ₗ[R] ⨁ i, N i := DFinsupp.mapRange.linearMap f
@[simp] theorem lmap_apply (x i) : lmap f x i = f i (x i) := rfl
@[simp] lemma lmap_of [DecidableEq ι] (i : ι) (x : M i) :
lmap f (of M i x) = of N i (f i x) :=
DFinsupp.mapRange_single (hf := fun _ => map_zero _)
@[simp] theorem lmap_lof [DecidableEq ι] (i) (x : M i) :
lmap f (lof R _ _ _ x) = lof R _ _ _ (f i x) :=
DFinsupp.mapRange_single (hf := fun _ ↦ map_zero _)
@[simp] lemma lmap_id :
(lmap (fun i ↦ LinearMap.id (R := R) (M := M i))) = LinearMap.id :=
DFinsupp.mapRange.linearMap_id
@[simp] lemma lmap_comp {K : ι → Type*} [∀ i, AddCommMonoid (K i)] [∀ i, Module R (K i)]
(g : ∀ (i : ι), N i →ₗ[R] K i) :
(lmap (fun i ↦ (g i) ∘ₗ (f i))) = (lmap g) ∘ₗ (lmap f) :=
DFinsupp.mapRange.linearMap_comp _ _
theorem lmap_injective : Function.Injective (lmap f) ↔ ∀ i, Function.Injective (f i) := by
classical exact DFinsupp.mapRange_injective (hf := fun _ ↦ map_zero _)
theorem lmap_surjective : Function.Surjective (lmap f) ↔ (∀ i, Function.Surjective (f i)) := by
classical exact DFinsupp.mapRange_surjective (hf := fun _ ↦ map_zero _)
lemma lmap_eq_iff (x y : ⨁ i, M i) :
lmap f x = lmap f y ↔ ∀ i, f i (x i) = f i (y i) :=
map_eq_iff (fun i => (f i).toAddMonoidHom) _ _
lemma toAddMonoidHom_lmap :
(lmap f).toAddMonoidHom = map (fun i => (f i).toAddMonoidHom) :=
rfl
lemma lmap_eq_map (x : ⨁ i, M i) : lmap f x = map (fun i => (f i).toAddMonoidHom) x :=
rfl
lemma ker_lmap :
LinearMap.ker (lmap f) =
(Submodule.pi Set.univ (fun i ↦ LinearMap.ker (f i))).comap (DirectSum.coeFnLinearMap R) :=
DFinsupp.ker_mapRangeLinearMap f
lemma range_lmap :
LinearMap.range (lmap f) =
(Submodule.pi Set.univ (fun i ↦ LinearMap.range (f i))).comap (DirectSum.coeFnLinearMap R) :=
DFinsupp.range_mapRangeLinearMap f
end AddCommMonoid
section AddCommGroup
variable {R : Type u} {ι : Type v} {M : ι → Type w} {N : ι → Type*}
lemma ker_map [∀ i, AddCommGroup (M i)] [∀ i, AddCommMonoid (N i)] (f : ∀ i, M i →+ N i) :
(map f).ker =
(AddSubgroup.pi Set.univ (f · |>.ker)).comap (DirectSum.coeFnAddMonoidHom M) :=
DFinsupp.ker_mapRangeAddMonoidHom f
lemma range_map [∀ i, AddCommGroup (M i)] [∀ i, AddCommGroup (N i)] (f : ∀ i, M i →+ N i) :
(map f).range =
(AddSubgroup.pi Set.univ (f · |>.range)).comap (DirectSum.coeFnAddMonoidHom N) :=
DFinsupp.range_mapRangeAddMonoidHom f
end AddCommGroup
end map
section CongrLeft
variable {κ : Type*}
/-- Reindexing terms of a direct sum is linear. -/
def lequivCongrLeft (h : ι ≃ κ) : (⨁ i, M i) ≃ₗ[R] ⨁ k, M (h.symm k) :=
DFinsupp.domLCongr h
@[simp]
theorem lequivCongrLeft_apply (h : ι ≃ κ) (f : ⨁ i, M i) (k : κ) :
lequivCongrLeft R h f k = f (h.symm k) :=
equivCongrLeft_apply _ _ _
end CongrLeft
section Sigma
variable {α : ι → Type*} {δ : ∀ i, α i → Type w}
variable [DecidableEq ι] [∀ i j, AddCommMonoid (δ i j)] [∀ i j, Module R (δ i j)]
/-- `curry` as a linear map. -/
def sigmaLcurry : (⨁ i : Σ _, _, δ i.1 i.2) →ₗ[R] ⨁ (i) (j), δ i j :=
{ sigmaCurry with map_smul' := fun r ↦ by convert DFinsupp.sigmaCurry_smul (δ := δ) r }
@[simp]
theorem sigmaLcurry_apply (f : ⨁ i : Σ _, _, δ i.1 i.2) (i : ι) (j : α i) :
sigmaLcurry R f i j = f ⟨i, j⟩ :=
sigmaCurry_apply f i j
/-- `uncurry` as a linear map. -/
def sigmaLuncurry : (⨁ (i) (j), δ i j) →ₗ[R] ⨁ i : Σ _, _, δ i.1 i.2 :=
{ sigmaUncurry with map_smul' := DFinsupp.sigmaUncurry_smul }
@[simp]
theorem sigmaLuncurry_apply (f : ⨁ (i) (j), δ i j) (i : ι) (j : α i) :
sigmaLuncurry R f ⟨i, j⟩ = f i j :=
sigmaUncurry_apply f i j
/-- `curryEquiv` as a linear equiv. -/
def sigmaLcurryEquiv : (⨁ i : Σ _, _, δ i.1 i.2) ≃ₗ[R] ⨁ (i) (j), δ i j :=
DFinsupp.sigmaCurryLEquiv
end Sigma
section Option
variable {α : Option ι → Type w} [∀ i, AddCommMonoid (α i)] [∀ i, Module R (α i)]
/-- Linear isomorphism obtained by separating the term of index `none` of a direct sum over
`Option ι`. -/
@[simps]
noncomputable def lequivProdDirectSum : (⨁ i, α i) ≃ₗ[R] α none × ⨁ i, α (some i) :=
{ addEquivProdDirectSum with map_smul' := DFinsupp.equivProdDFinsupp_smul }
end Option
end General
section Submodule
section Semiring
variable {R : Type u} [Semiring R]
variable {ι : Type v} [dec_ι : DecidableEq ι]
variable {M : Type*} [AddCommMonoid M] [Module R M]
variable (A : ι → Submodule R M)
/-- The canonical linear map from `⨁ i, A i` to `M` where `A` is a collection of `Submodule R M`
indexed by `ι`. This is `DirectSum.coeAddMonoidHom` as a `LinearMap`. -/
def coeLinearMap : (⨁ i, A i) →ₗ[R] M :=
toModule R ι M fun i ↦ (A i).subtype
theorem coeLinearMap_eq_dfinsuppSum [DecidableEq M] (x : DirectSum ι fun i => A i) :
coeLinearMap A x = DFinsupp.sum x fun i => (fun x : A i => ↑x) := by
simp only [coeLinearMap, toModule, DFinsupp.lsum, LinearEquiv.coe_mk, LinearMap.coe_mk,
AddHom.coe_mk]
rw [DFinsupp.sumAddHom_apply]
simp only [LinearMap.toAddMonoidHom_coe, Submodule.coe_subtype]
@[simp]
theorem coeLinearMap_of (i : ι) (x : A i) : DirectSum.coeLinearMap A (of (fun i ↦ A i) i x) = x :=
-- Porting note: spelled out arguments. (I don't know how this works.)
toAddMonoid_of (β := fun i => A i) (fun i ↦ ((A i).subtype : A i →+ M)) i x
variable {A}
theorem range_coeLinearMap : LinearMap.range (coeLinearMap A) = ⨆ i, A i :=
(Submodule.iSup_eq_range_dfinsupp_lsum _).symm
@[simp]
theorem IsInternal.ofBijective_coeLinearMap_same (h : IsInternal A)
{i : ι} (x : A i) :
(LinearEquiv.ofBijective (coeLinearMap A) h).symm x i = x := by
rw [← coeLinearMap_of, LinearEquiv.ofBijective_symm_apply_apply, of_eq_same]
@[simp]
theorem IsInternal.ofBijective_coeLinearMap_of_ne (h : IsInternal A)
{i j : ι} (hij : i ≠ j) (x : A i) :
(LinearEquiv.ofBijective (coeLinearMap A) h).symm x j = 0 := by
rw [← coeLinearMap_of, LinearEquiv.ofBijective_symm_apply_apply, of_eq_of_ne i j _ hij.symm]
theorem IsInternal.ofBijective_coeLinearMap_of_mem (h : IsInternal A)
{i : ι} {x : M} (hx : x ∈ A i) :
(LinearEquiv.ofBijective (coeLinearMap A) h).symm x i = ⟨x, hx⟩ :=
h.ofBijective_coeLinearMap_same ⟨x, hx⟩
theorem IsInternal.ofBijective_coeLinearMap_of_mem_ne (h : IsInternal A)
{i j : ι} (hij : i ≠ j) {x : M} (hx : x ∈ A i) :
(LinearEquiv.ofBijective (coeLinearMap A) h).symm x j = 0 :=
h.ofBijective_coeLinearMap_of_ne hij ⟨x, hx⟩
/-- If a direct sum of submodules is internal then the submodules span the module. -/
theorem IsInternal.submodule_iSup_eq_top (h : IsInternal A) : iSup A = ⊤ := by
rw [Submodule.iSup_eq_range_dfinsupp_lsum, LinearMap.range_eq_top]
exact Function.Bijective.surjective h
/-- If a direct sum of submodules is internal then the submodules are independent. -/
theorem IsInternal.submodule_iSupIndep (h : IsInternal A) : iSupIndep A :=
iSupIndep_of_dfinsupp_lsum_injective _ h.injective
/-- Given an internal direct sum decomposition of a module `M`, and a basis for each of the
components of the direct sum, the disjoint union of these bases is a basis for `M`. -/
noncomputable def IsInternal.collectedBasis (h : IsInternal A) {α : ι → Type*}
(v : ∀ i, Basis (α i) R (A i)) : Basis (Σ i, α i) R M where
repr :=
((LinearEquiv.ofBijective (DirectSum.coeLinearMap A) h).symm ≪≫ₗ
DFinsupp.mapRange.linearEquiv fun i ↦ (v i).repr) ≪≫ₗ
(sigmaFinsuppLequivDFinsupp R).symm
@[simp]
theorem IsInternal.collectedBasis_coe (h : IsInternal A) {α : ι → Type*}
(v : ∀ i, Basis (α i) R (A i)) : ⇑(h.collectedBasis v) = fun a : Σ i, α i ↦ ↑(v a.1 a.2) := by
funext a
-- Porting note: was
-- simp only [IsInternal.collectedBasis, toModule, coeLinearMap, Basis.coe_ofRepr,
-- Basis.repr_symm_apply, DFinsupp.lsum_apply_apply, DFinsupp.mapRange.linearEquiv_apply,
-- DFinsupp.mapRange.linearEquiv_symm, DFinsupp.mapRange_single, linearCombination_single,
-- LinearEquiv.ofBijective_apply, LinearEquiv.symm_symm, LinearEquiv.symm_trans_apply, one_smul,
-- sigmaFinsuppAddEquivDFinsupp_apply, sigmaFinsuppEquivDFinsupp_single,
-- sigmaFinsuppLequivDFinsupp_apply]
-- convert DFinsupp.sumAddHom_single (fun i ↦ (A i).subtype.toAddMonoidHom) a.1 (v a.1 a.2)
simp only [IsInternal.collectedBasis, coeLinearMap, Basis.coe_ofRepr, LinearEquiv.trans_symm,
LinearEquiv.symm_symm, LinearEquiv.trans_apply, sigmaFinsuppLequivDFinsupp_apply,
AddEquiv.toEquiv_eq_coe, Equiv.toFun_as_coe, EquivLike.coe_coe,
sigmaFinsuppAddEquivDFinsupp_apply, sigmaFinsuppEquivDFinsupp_single,
LinearEquiv.ofBijective_apply]
rw [DFinsupp.mapRange.linearEquiv_symm]
-- `DFunLike.coe (β := fun x ↦ ⨁ (i : ι), ↥(A i))`
-- appears in the goal, but the lemma is expecting
-- `DFunLike.coe (β := fun x ↦ Π₀ (i : ι), ↥(A i))`
erw [DFinsupp.mapRange.linearEquiv_apply]
simp only [DFinsupp.mapRange_single, Basis.repr_symm_apply, linearCombination_single, one_smul,
toModule]
-- Similarly here.
erw [DFinsupp.lsum_single]
simp only [Submodule.coe_subtype]
theorem IsInternal.collectedBasis_mem (h : IsInternal A) {α : ι → Type*}
(v : ∀ i, Basis (α i) R (A i)) (a : Σ i, α i) : h.collectedBasis v a ∈ A a.1 := by simp
theorem IsInternal.collectedBasis_repr_of_mem (h : IsInternal A) {α : ι → Type*}
(v : ∀ i, Basis (α i) R (A i)) {x : M} {i : ι} {a : α i} (hx : x ∈ A i) :
(h.collectedBasis v).repr x ⟨i, a⟩ = (v i).repr ⟨x, hx⟩ a := by
change (sigmaFinsuppLequivDFinsupp R).symm (DFinsupp.mapRange _ (fun i ↦ map_zero _) _) _ = _
simp [h.ofBijective_coeLinearMap_of_mem hx]
theorem IsInternal.collectedBasis_repr_of_mem_ne (h : IsInternal A) {α : ι → Type*}
(v : ∀ i, Basis (α i) R (A i)) {x : M} {i j : ι} (hij : i ≠ j) {a : α j} (hx : x ∈ A i) :
(h.collectedBasis v).repr x ⟨j, a⟩ = 0 := by
change (sigmaFinsuppLequivDFinsupp R).symm (DFinsupp.mapRange _ (fun i ↦ map_zero _) _) _ = _
simp [h.ofBijective_coeLinearMap_of_mem_ne hij hx]
/-- When indexed by only two distinct elements, `DirectSum.IsInternal` implies
the two submodules are complementary. Over a `Ring R`, this is true as an iff, as
`DirectSum.isInternal_submodule_iff_isCompl`. -/
theorem IsInternal.isCompl {A : ι → Submodule R M} {i j : ι} (hij : i ≠ j)
(h : (Set.univ : Set ι) = {i, j}) (hi : IsInternal A) : IsCompl (A i) (A j) :=
⟨hi.submodule_iSupIndep.pairwiseDisjoint hij,
codisjoint_iff.mpr <| Eq.symm <| hi.submodule_iSup_eq_top.symm.trans <| by
rw [← sSup_pair, iSup, ← Set.image_univ, h, Set.image_insert_eq, Set.image_singleton]⟩
end Semiring
section Ring
variable {R : Type u} [Ring R]
variable {ι : Type v} [dec_ι : DecidableEq ι]
variable {M : Type*} [AddCommGroup M] [Module R M]
/-- Note that this is not generally true for `[Semiring R]`; see
`iSupIndep.dfinsupp_lsum_injective` for details. -/
theorem isInternal_submodule_of_iSupIndep_of_iSup_eq_top {A : ι → Submodule R M}
(hi : iSupIndep A) (hs : iSup A = ⊤) : IsInternal A :=
⟨hi.dfinsupp_lsum_injective,
-- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specify value of `f`
(LinearMap.range_eq_top (f := DFinsupp.lsum _ _)).1 <|
(Submodule.iSup_eq_range_dfinsupp_lsum _).symm.trans hs⟩
/-- `iff` version of `DirectSum.isInternal_submodule_of_iSupIndep_of_iSup_eq_top`,
`DirectSum.IsInternal.iSupIndep`, and `DirectSum.IsInternal.submodule_iSup_eq_top`. -/
theorem isInternal_submodule_iff_iSupIndep_and_iSup_eq_top (A : ι → Submodule R M) :
IsInternal A ↔ iSupIndep A ∧ iSup A = ⊤ :=
⟨fun i ↦ ⟨i.submodule_iSupIndep, i.submodule_iSup_eq_top⟩,
And.rec isInternal_submodule_of_iSupIndep_of_iSup_eq_top⟩
/-- If a collection of submodules has just two indices, `i` and `j`, then
`DirectSum.IsInternal` is equivalent to `isCompl`. -/
theorem isInternal_submodule_iff_isCompl (A : ι → Submodule R M) {i j : ι} (hij : i ≠ j)
(h : (Set.univ : Set ι) = {i, j}) : IsInternal A ↔ IsCompl (A i) (A j) := by
have : ∀ k, k = i ∨ k = j := fun k ↦ by simpa using Set.ext_iff.mp h k
rw [isInternal_submodule_iff_iSupIndep_and_iSup_eq_top, iSup, ← Set.image_univ, h,
Set.image_insert_eq, Set.image_singleton, sSup_pair, iSupIndep_pair hij this]
exact ⟨fun ⟨hd, ht⟩ ↦ ⟨hd, codisjoint_iff.mpr ht⟩, fun ⟨hd, ht⟩ ↦ ⟨hd, ht.eq_top⟩⟩
@[simp]
theorem isInternal_ne_bot_iff {A : ι → Submodule R M} :
IsInternal (fun i : {i // A i ≠ ⊥} ↦ A i) ↔ IsInternal A := by
simp [isInternal_submodule_iff_iSupIndep_and_iSup_eq_top]
lemma isInternal_biSup_submodule_of_iSupIndep {A : ι → Submodule R M} (s : Set ι)
(h : iSupIndep <| fun i : s ↦ A i) :
IsInternal <| fun (i : s) ↦ (A i).comap (⨆ i ∈ s, A i).subtype := by
refine (isInternal_submodule_iff_iSupIndep_and_iSup_eq_top _).mpr ⟨?_, by simp [iSup_subtype]⟩
let p := ⨆ i ∈ s, A i
have hp : ∀ i ∈ s, A i ≤ p := fun i hi ↦ le_biSup A hi
let e : Submodule R p ≃o Set.Iic p := p.mapIic
suffices (e ∘ fun i : s ↦ (A i).comap p.subtype) = fun i ↦ ⟨A i, hp i i.property⟩ by
rw [← iSupIndep_map_orderIso_iff e, this]
exact .of_coe_Iic_comp h
ext i m
change m ∈ ((A i).comap p.subtype).map p.subtype ↔ _
rw [Submodule.map_comap_subtype, inf_of_le_right (hp i i.property)]
/-! Now copy the lemmas for subgroup and submonoids. -/
theorem IsInternal.addSubmonoid_iSupIndep {M : Type*} [AddCommMonoid M] {A : ι → AddSubmonoid M}
(h : IsInternal A) : iSupIndep A :=
iSupIndep_of_dfinsuppSumAddHom_injective _ h.injective
theorem IsInternal.addSubgroup_iSupIndep {G : Type*} [AddCommGroup G] {A : ι → AddSubgroup G}
(h : IsInternal A) : iSupIndep A :=
iSupIndep_of_dfinsuppSumAddHom_injective' _ h.injective
end Ring
end Submodule
end DirectSum |
.lake/packages/mathlib/Mathlib/Algebra/DirectSum/Ring.lean | import Mathlib.Algebra.GradedMonoid
import Mathlib.Algebra.DirectSum.Basic
import Mathlib.Algebra.Ring.Associator
/-!
# Additively-graded multiplicative structures on `⨁ i, A i`
This module provides a set of heterogeneous typeclasses for defining a multiplicative structure
over `⨁ i, A i` such that `(*) : A i → A j → A (i + j)`; that is to say, `A` forms an
additively-graded ring. The typeclasses are:
* `DirectSum.GNonUnitalNonAssocSemiring A`
* `DirectSum.GSemiring A`
* `DirectSum.GRing A`
* `DirectSum.GCommSemiring A`
* `DirectSum.GCommRing A`
Respectively, these imbue the external direct sum `⨁ i, A i` with:
* `DirectSum.nonUnitalNonAssocSemiring`, `DirectSum.nonUnitalNonAssocRing`
* `DirectSum.semiring`
* `DirectSum.ring`
* `DirectSum.commSemiring`
* `DirectSum.commRing`
the base ring `A 0` with:
* `DirectSum.GradeZero.nonUnitalNonAssocSemiring`,
`DirectSum.GradeZero.nonUnitalNonAssocRing`
* `DirectSum.GradeZero.semiring`
* `DirectSum.GradeZero.ring`
* `DirectSum.GradeZero.commSemiring`
* `DirectSum.GradeZero.commRing`
and the `i`th grade `A i` with `A 0`-actions (`•`) defined as left-multiplication:
* `DirectSum.GradeZero.smul (A 0)`, `DirectSum.GradeZero.smulWithZero (A 0)`
* `DirectSum.GradeZero.module (A 0)`
* (nothing)
* (nothing)
* (nothing)
Note that in the presence of these instances, `⨁ i, A i` itself inherits an `A 0`-action.
`DirectSum.ofZeroRingHom : A 0 →+* ⨁ i, A i` provides `DirectSum.of A 0` as a ring
homomorphism.
`DirectSum.toSemiring` extends `DirectSum.toAddMonoid` to produce a `RingHom`.
## Direct sums of subobjects
Additionally, this module provides helper functions to construct `GSemiring` and `GCommSemiring`
instances for:
* `A : ι → Submonoid S`:
`DirectSum.GSemiring.ofAddSubmonoids`, `DirectSum.GCommSemiring.ofAddSubmonoids`.
* `A : ι → Subgroup S`:
`DirectSum.GSemiring.ofAddSubgroups`, `DirectSum.GCommSemiring.ofAddSubgroups`.
* `A : ι → Submodule S`:
`DirectSum.GSemiring.ofSubmodules`, `DirectSum.GCommSemiring.ofSubmodules`.
If `sSupIndep A`, these provide a gradation of `⨆ i, A i`, and the mapping `⨁ i, A i →+ ⨆ i, A i`
can be obtained as `DirectSum.toMonoid (fun i ↦ AddSubmonoid.inclusion <| le_iSup A i)`.
## Tags
graded ring, filtered ring, direct sum, add_submonoid
-/
variable {ι : Type*} [DecidableEq ι]
namespace DirectSum
open DirectSum
/-! ### Typeclasses -/
section Defs
variable (A : ι → Type*)
/-- A graded version of `NonUnitalNonAssocSemiring`. -/
class GNonUnitalNonAssocSemiring [Add ι] [∀ i, AddCommMonoid (A i)] extends
GradedMonoid.GMul A where
/-- Multiplication from the right with any graded component's zero vanishes. -/
mul_zero : ∀ {i j} (a : A i), mul a (0 : A j) = 0
/-- Multiplication from the left with any graded component's zero vanishes. -/
zero_mul : ∀ {i j} (b : A j), mul (0 : A i) b = 0
/-- Multiplication from the right between graded components distributes with respect to
addition. -/
mul_add : ∀ {i j} (a : A i) (b c : A j), mul a (b + c) = mul a b + mul a c
/-- Multiplication from the left between graded components distributes with respect to
addition. -/
add_mul : ∀ {i j} (a b : A i) (c : A j), mul (a + b) c = mul a c + mul b c
end Defs
section Defs
variable (A : ι → Type*)
/-- A graded version of `Semiring`. -/
class GSemiring [AddMonoid ι] [∀ i, AddCommMonoid (A i)] extends GNonUnitalNonAssocSemiring A,
GradedMonoid.GMonoid A where
/-- The canonical map from ℕ to the zeroth component of a graded semiring. -/
natCast : ℕ → A 0
/-- The canonical map from ℕ to a graded semiring respects zero. -/
natCast_zero : natCast 0 = 0
/-- The canonical map from ℕ to a graded semiring respects successors. -/
natCast_succ : ∀ n : ℕ, natCast (n + 1) = natCast n + GradedMonoid.GOne.one
/-- A graded version of `CommSemiring`. -/
class GCommSemiring [AddCommMonoid ι] [∀ i, AddCommMonoid (A i)] extends GSemiring A,
GradedMonoid.GCommMonoid A
/-- A graded version of `Ring`. -/
class GRing [AddMonoid ι] [∀ i, AddCommGroup (A i)] extends GSemiring A where
/-- The canonical map from ℤ to the zeroth component of a graded ring. -/
intCast : ℤ → A 0
/-- The canonical map from ℤ to a graded ring extends the canonical map from ℕ to the underlying
graded semiring. -/
intCast_ofNat : ∀ n : ℕ, intCast n = natCast n
/-- On negative integers, the canonical map from ℤ to a graded ring is the negative extension of
the canonical map from ℕ to the underlying graded semiring. -/
-- Porting note: -(n + 1) -> Int.negSucc
intCast_negSucc_ofNat : ∀ n : ℕ, intCast (Int.negSucc n) = -natCast (n + 1 : ℕ)
/-- A graded version of `CommRing`. -/
class GCommRing [AddCommMonoid ι] [∀ i, AddCommGroup (A i)] extends GRing A, GCommSemiring A
end Defs
theorem of_eq_of_gradedMonoid_eq {A : ι → Type*} [∀ i : ι, AddCommMonoid (A i)] {i j : ι} {a : A i}
{b : A j} (h : GradedMonoid.mk i a = GradedMonoid.mk j b) :
DirectSum.of A i a = DirectSum.of A j b :=
DFinsupp.single_eq_of_sigma_eq h
variable (A : ι → Type*)
/-! ### Instances for `⨁ i, A i` -/
section One
variable [Zero ι] [GradedMonoid.GOne A] [∀ i, AddCommMonoid (A i)]
instance : One (⨁ i, A i) where one := DirectSum.of A 0 GradedMonoid.GOne.one
theorem one_def : 1 = DirectSum.of A 0 GradedMonoid.GOne.one := rfl
end One
section Mul
variable [Add ι] [∀ i, AddCommMonoid (A i)] [GNonUnitalNonAssocSemiring A]
open AddMonoidHom (flip_apply coe_comp compHom)
/-- The piecewise multiplication from the `Mul` instance, as a bundled homomorphism. -/
@[simps]
def gMulHom {i j} : A i →+ A j →+ A (i + j) where
toFun a :=
{ toFun := fun b => GradedMonoid.GMul.mul a b
map_zero' := GNonUnitalNonAssocSemiring.mul_zero _
map_add' := GNonUnitalNonAssocSemiring.mul_add _ }
map_zero' := AddMonoidHom.ext fun a => GNonUnitalNonAssocSemiring.zero_mul a
map_add' _ _ := AddMonoidHom.ext fun _ => GNonUnitalNonAssocSemiring.add_mul _ _ _
/-- The multiplication from the `Mul` instance, as a bundled homomorphism. -/
-- See note [non-reducible instance]
@[reducible]
def mulHom : (⨁ i, A i) →+ (⨁ i, A i) →+ ⨁ i, A i :=
DirectSum.toAddMonoid fun _ =>
AddMonoidHom.flip <|
DirectSum.toAddMonoid fun _ =>
AddMonoidHom.flip <| (DirectSum.of A _).compHom.comp <| gMulHom A
instance instMul : Mul (⨁ i, A i) where
mul := fun a b => mulHom A a b
instance : NonUnitalNonAssocSemiring (⨁ i, A i) :=
{ (inferInstance : AddCommMonoid _) with
zero_mul := fun _ => by simp only [Mul.mul, HMul.hMul, map_zero, AddMonoidHom.zero_apply]
mul_zero := fun _ => by simp only [Mul.mul, HMul.hMul, AddMonoidHom.map_zero]
left_distrib := fun _ _ _ => by simp only [Mul.mul, HMul.hMul, AddMonoidHom.map_add]
right_distrib := fun _ _ _ => by
simp only [Mul.mul, HMul.hMul, AddMonoidHom.map_add, AddMonoidHom.add_apply] }
variable {A}
theorem mulHom_apply (a b : ⨁ i, A i) : mulHom A a b = a * b := rfl
theorem mulHom_of_of {i j} (a : A i) (b : A j) :
mulHom A (of A i a) (of A j b) = of A (i + j) (GradedMonoid.GMul.mul a b) := by
simp
theorem of_mul_of {i j} (a : A i) (b : A j) :
of A i a * of A j b = of _ (i + j) (GradedMonoid.GMul.mul a b) :=
mulHom_of_of a b
end Mul
section Semiring
variable [∀ i, AddCommMonoid (A i)] [AddMonoid ι] [GSemiring A]
open AddMonoidHom (flipHom coe_comp compHom flip_apply)
private nonrec theorem one_mul (x : ⨁ i, A i) : 1 * x = x := by
suffices mulHom A One.one = AddMonoidHom.id (⨁ i, A i) from DFunLike.congr_fun this x
apply addHom_ext; intro i xi
simp only [One.one]
rw [mulHom_of_of]
exact of_eq_of_gradedMonoid_eq (one_mul <| GradedMonoid.mk i xi)
private nonrec theorem mul_one (x : ⨁ i, A i) : x * 1 = x := by
suffices (mulHom A).flip One.one = AddMonoidHom.id (⨁ i, A i) from DFunLike.congr_fun this x
apply addHom_ext; intro i xi
simp only [One.one]
rw [flip_apply, mulHom_of_of]
exact of_eq_of_gradedMonoid_eq (mul_one <| GradedMonoid.mk i xi)
private theorem mul_assoc (a b c : ⨁ i, A i) : a * b * c = a * (b * c) := by
-- (`fun a b c => a * b * c` as a bundled hom) = (`fun a b c => a * (b * c)` as a bundled hom)
suffices AddMonoidHom.mulLeft₃ = AddMonoidHom.mulRight₃ by
simpa only [AddMonoidHom.mulLeft₃_apply, AddMonoidHom.mulRight₃_apply] using
DFunLike.congr_fun (DFunLike.congr_fun (DFunLike.congr_fun this a) b) c
ext ai ax bi bx ci cx : 6
dsimp only [coe_comp, Function.comp_apply, AddMonoidHom.mulLeft₃_apply,
AddMonoidHom.mulRight₃_apply]
simp_rw [of_mul_of]
exact of_eq_of_gradedMonoid_eq (_root_.mul_assoc (GradedMonoid.mk ai ax) ⟨bi, bx⟩ ⟨ci, cx⟩)
instance instNatCast : NatCast (⨁ i, A i) where
natCast := fun n => of _ _ (GSemiring.natCast n)
/-- The `Semiring` structure derived from `GSemiring A`. -/
instance semiring : Semiring (⨁ i, A i) :=
{ (inferInstance : NonUnitalNonAssocSemiring _) with
one_mul := one_mul A
mul_one := mul_one A
mul_assoc := mul_assoc A
toNatCast := instNatCast _
natCast_zero := by simp only [NatCast.natCast, GSemiring.natCast_zero, map_zero]
natCast_succ := fun n => by
simp_rw [NatCast.natCast, GSemiring.natCast_succ]
rw [map_add]
rfl }
theorem ofPow {i} (a : A i) (n : ℕ) :
of _ i a ^ n = of _ (n • i) (GradedMonoid.GMonoid.gnpow _ a) := by
induction n with
| zero => exact of_eq_of_gradedMonoid_eq (pow_zero <| GradedMonoid.mk _ a).symm
| succ n n_ih =>
rw [pow_succ, n_ih, of_mul_of]
exact of_eq_of_gradedMonoid_eq (pow_succ (GradedMonoid.mk _ a) n).symm
theorem ofList_dProd {α} (l : List α) (fι : α → ι) (fA : ∀ a, A (fι a)) :
of A _ (l.dProd fι fA) = (l.map fun a => of A (fι a) (fA a)).prod := by
induction l with
| nil => simp only [List.map_nil, List.prod_nil, List.dProd_nil]; rfl
| cons head tail =>
rename_i ih
simp only [List.map_cons, List.prod_cons, List.dProd_cons, ← ih]
rw [DirectSum.of_mul_of (fA head)]
rfl
theorem list_prod_ofFn_of_eq_dProd (n : ℕ) (fι : Fin n → ι) (fA : ∀ a, A (fι a)) :
(List.ofFn fun a => of A (fι a) (fA a)).prod = of A _ ((List.finRange n).dProd fι fA) := by
rw [List.ofFn_eq_map, ofList_dProd]
theorem mul_eq_dfinsuppSum [∀ (i : ι) (x : A i), Decidable (x ≠ 0)] (a a' : ⨁ i, A i) :
a * a'
= a.sum fun _ ai => a'.sum fun _ aj => DirectSum.of _ _ <| GradedMonoid.GMul.mul ai aj := by
change mulHom _ a a' = _
-- Porting note: I have no idea how the proof from ml3 worked it used to be
-- simpa only [mul_hom, to_add_monoid, dfinsupp.lift_add_hom_apply, dfinsupp.sum_add_hom_apply,
-- add_monoid_hom.dfinsupp_sum_apply, flip_apply, add_monoid_hom.dfinsupp_sum_add_hom_apply],
rw [mulHom, toAddMonoid, DFinsupp.liftAddHom_apply]
dsimp only [DirectSum]
rw [DFinsupp.sumAddHom_apply, AddMonoidHom.dfinsuppSum_apply]
apply congrArg _
simp_rw [flip_apply]
funext x
-- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
erw [DFinsupp.sumAddHom_apply]
simp only [gMulHom, AddMonoidHom.dfinsuppSum_apply, flip_apply, coe_comp, AddMonoidHom.coe_mk,
ZeroHom.coe_mk, Function.comp_apply, AddMonoidHom.compHom_apply_apply]
/-- A heavily unfolded version of the definition of multiplication -/
theorem mul_eq_sum_support_ghas_mul [∀ (i : ι) (x : A i), Decidable (x ≠ 0)] (a a' : ⨁ i, A i) :
a * a' =
∑ ij ∈ DFinsupp.support a ×ˢ DFinsupp.support a',
DirectSum.of _ _ (GradedMonoid.GMul.mul (a ij.fst) (a' ij.snd)) := by
simp only [mul_eq_dfinsuppSum, DFinsupp.sum, Finset.sum_product]
end Semiring
section CommSemiring
variable [∀ i, AddCommMonoid (A i)] [AddCommMonoid ι] [GCommSemiring A]
private theorem mul_comm (a b : ⨁ i, A i) : a * b = b * a := by
suffices mulHom A = (mulHom A).flip by
rw [← mulHom_apply, this, AddMonoidHom.flip_apply, mulHom_apply]
apply addHom_ext; intro ai ax; apply addHom_ext; intro bi bx
rw [AddMonoidHom.flip_apply, mulHom_of_of, mulHom_of_of]
exact of_eq_of_gradedMonoid_eq (GCommSemiring.mul_comm ⟨ai, ax⟩ ⟨bi, bx⟩)
/-- The `CommSemiring` structure derived from `GCommSemiring A`. -/
instance commSemiring : CommSemiring (⨁ i, A i) :=
{ DirectSum.semiring A with
mul_comm := mul_comm A }
end CommSemiring
section NonUnitalNonAssocRing
variable [∀ i, AddCommGroup (A i)] [Add ι] [GNonUnitalNonAssocSemiring A]
/-- The `Ring` derived from `GSemiring A`. -/
instance nonAssocRing : NonUnitalNonAssocRing (⨁ i, A i) :=
{ (inferInstance : NonUnitalNonAssocSemiring (⨁ i, A i)),
(inferInstance : AddCommGroup (⨁ i, A i)) with }
end NonUnitalNonAssocRing
section Ring
variable [∀ i, AddCommGroup (A i)] [AddMonoid ι] [GRing A]
-- Porting note: overspecified fields in ml4
/-- The `Ring` derived from `GSemiring A`. -/
instance ring : Ring (⨁ i, A i) :=
{ DirectSum.semiring A,
(inferInstance : AddCommGroup (⨁ i, A i)) with
toIntCast.intCast := fun z => of A 0 <| (GRing.intCast z)
intCast_ofNat := fun _ => congrArg (of A 0) <| GRing.intCast_ofNat _
intCast_negSucc := fun _ =>
(congrArg (of A 0) <| GRing.intCast_negSucc_ofNat _).trans <| map_neg _ _}
end Ring
section CommRing
variable [∀ i, AddCommGroup (A i)] [AddCommMonoid ι] [GCommRing A]
/-- The `CommRing` derived from `GCommSemiring A`. -/
instance commRing : CommRing (⨁ i, A i) :=
{ DirectSum.ring A,
DirectSum.commSemiring A with }
end CommRing
/-! ### Instances for `A 0`
The various `G*` instances are enough to promote the `AddCommMonoid (A 0)` structure to various
types of multiplicative structure.
-/
section GradeZero
section One
variable [Zero ι] [GradedMonoid.GOne A] [∀ i, AddCommMonoid (A i)]
@[simp]
theorem of_zero_one : of _ 0 (1 : A 0) = 1 :=
rfl
end One
section Mul
variable [AddZeroClass ι] [∀ i, AddCommMonoid (A i)] [GNonUnitalNonAssocSemiring A]
@[simp]
theorem of_zero_smul {i} (a : A 0) (b : A i) : of _ _ (a • b) = of _ _ a * of _ _ b :=
(of_eq_of_gradedMonoid_eq (GradedMonoid.mk_zero_smul a b)).trans (of_mul_of _ _).symm
@[simp]
theorem of_zero_mul (a b : A 0) : of _ 0 (a * b) = of _ 0 a * of _ 0 b :=
of_zero_smul A a b
instance GradeZero.nonUnitalNonAssocSemiring : NonUnitalNonAssocSemiring (A 0) :=
Function.Injective.nonUnitalNonAssocSemiring (of A 0) DFinsupp.single_injective (of A 0).map_zero
(of A 0).map_add (of_zero_mul A) (map_nsmul _)
instance GradeZero.smulWithZero (i : ι) : SMulWithZero (A 0) (A i) := by
letI := SMulWithZero.compHom (⨁ i, A i) (of A 0).toZeroHom
exact Function.Injective.smulWithZero (of A i).toZeroHom DFinsupp.single_injective
(of_zero_smul A)
end Mul
section Semiring
variable [∀ i, AddCommMonoid (A i)] [AddMonoid ι] [GSemiring A]
@[simp]
theorem of_zero_pow (a : A 0) : ∀ n : ℕ, of A 0 (a ^ n) = of A 0 a ^ n
| 0 => by rw [pow_zero, pow_zero, DirectSum.of_zero_one]
-- Porting note: Lean doesn't think this terminates if we only use `of_zero_pow` alone
| n + 1 => by rw [pow_succ, pow_succ, of_zero_mul, of_zero_pow _ n]
instance : NatCast (A 0) :=
⟨GSemiring.natCast⟩
-- TODO: These could be replaced by the general lemmas for `AddMonoidHomClass` (`map_natCast'` and
-- `map_ofNat'`) if those were marked `@[simp low]`.
@[simp]
theorem of_natCast (n : ℕ) : of A 0 n = n :=
rfl
@[simp]
theorem of_zero_ofNat (n : ℕ) [n.AtLeastTwo] : of A 0 ofNat(n) = ofNat(n) :=
of_natCast A n
/-- The `Semiring` structure derived from `GSemiring A`. -/
instance GradeZero.semiring : Semiring (A 0) :=
Function.Injective.semiring (of A 0) DFinsupp.single_injective (of A 0).map_zero (of_zero_one A)
(of A 0).map_add (of_zero_mul A) (fun _ _ ↦ (of A 0).map_nsmul _ _)
(fun _ _ => of_zero_pow _ _ _) (of_natCast A)
/-- `of A 0` is a `RingHom`, using the `DirectSum.GradeZero.semiring` structure. -/
def ofZeroRingHom : A 0 →+* ⨁ i, A i :=
{ of _ 0 with
map_one' := of_zero_one A
map_mul' := of_zero_mul A }
/-- Each grade `A i` derives an `A 0`-module structure from `GSemiring A`. Note that this results
in an overall `Module (A 0) (⨁ i, A i)` structure via `DirectSum.module`.
-/
instance GradeZero.module {i} : Module (A 0) (A i) :=
letI := Module.compHom (⨁ i, A i) (ofZeroRingHom A)
DFinsupp.single_injective.module (A 0) (of A i) fun a => of_zero_smul A a
end Semiring
section CommSemiring
variable [∀ i, AddCommMonoid (A i)] [AddCommMonoid ι] [GCommSemiring A]
/-- The `CommSemiring` structure derived from `GCommSemiring A`. -/
instance GradeZero.commSemiring : CommSemiring (A 0) :=
Function.Injective.commSemiring (of A 0) DFinsupp.single_injective (of A 0).map_zero
(of_zero_one A) (of A 0).map_add (of_zero_mul A) (fun _ _ ↦ map_nsmul _ _ _)
(fun _ _ => of_zero_pow _ _ _) (of_natCast A)
end CommSemiring
section Ring
variable [∀ i, AddCommGroup (A i)] [AddZeroClass ι] [GNonUnitalNonAssocSemiring A]
/-- The `NonUnitalNonAssocRing` derived from `GNonUnitalNonAssocSemiring A`. -/
instance GradeZero.nonUnitalNonAssocRing : NonUnitalNonAssocRing (A 0) :=
Function.Injective.nonUnitalNonAssocRing (of A 0) DFinsupp.single_injective (of A 0).map_zero
(of A 0).map_add (of_zero_mul A) (of A 0).map_neg (of A 0).map_sub (fun _ _ ↦ map_nsmul _ _ _)
(fun _ _ ↦ map_zsmul _ _ _)
end Ring
section Ring
variable [∀ i, AddCommGroup (A i)] [AddMonoid ι] [GRing A]
instance : IntCast (A 0) :=
⟨GRing.intCast⟩
@[simp]
theorem of_intCast (n : ℤ) : of A 0 n = n := by
rfl
/-- The `Ring` derived from `GSemiring A`. -/
instance GradeZero.ring : Ring (A 0) :=
Function.Injective.ring (of A 0) DFinsupp.single_injective (of A 0).map_zero (of_zero_one A)
(of A 0).map_add (of_zero_mul A) (of A 0).map_neg (of A 0).map_sub (fun _ _ ↦ map_nsmul _ _ _)
(fun _ _ ↦ map_zsmul _ _ _) (fun _ _ => of_zero_pow _ _ _) (of_natCast A) (of_intCast A)
end Ring
section CommRing
variable [∀ i, AddCommGroup (A i)] [AddCommMonoid ι] [GCommRing A]
/-- The `CommRing` derived from `GCommSemiring A`. -/
instance GradeZero.commRing : CommRing (A 0) :=
Function.Injective.commRing (of A 0) DFinsupp.single_injective (of A 0).map_zero (of_zero_one A)
(of A 0).map_add (of_zero_mul A) (of A 0).map_neg (of A 0).map_sub (fun _ _ ↦ map_nsmul _ _ _)
(fun _ _ ↦ map_zsmul _ _ _) (fun _ _ => of_zero_pow _ _ _) (of_natCast A) (of_intCast A)
end CommRing
end GradeZero
section ToSemiring
variable {R : Type*} [∀ i, AddCommMonoid (A i)] [AddMonoid ι] [GSemiring A] [Semiring R]
variable {A}
/-- If two ring homomorphisms from `⨁ i, A i` are equal on each `of A i y`,
then they are equal.
See note [partially-applied ext lemmas]. -/
@[ext]
theorem ringHom_ext' ⦃F G : (⨁ i, A i) →+* R⦄
(h : ∀ i, (↑F : _ →+ R).comp (of A i) = (↑G : _ →+ R).comp (of A i)) : F = G :=
RingHom.coe_addMonoidHom_injective <| DirectSum.addHom_ext' h
/-- Two `RingHom`s out of a direct sum are equal if they agree on the generators. -/
theorem ringHom_ext ⦃f g : (⨁ i, A i) →+* R⦄ (h : ∀ i x, f (of A i x) = g (of A i x)) : f = g :=
ringHom_ext' fun i => AddMonoidHom.ext <| h i
/-- A family of `AddMonoidHom`s preserving `DirectSum.One.one` and `DirectSum.Mul.mul`
describes a `RingHom`s on `⨁ i, A i`. This is a stronger version of `DirectSum.toMonoid`.
Of particular interest is the case when `A i` are bundled subobjects, `f` is the family of
coercions such as `AddSubmonoid.subtype (A i)`, and the `[GSemiring A]` structure originates from
`DirectSum.gsemiring.ofAddSubmonoids`, in which case the proofs about `GOne` and `GMul`
can be discharged by `rfl`. -/
@[simps]
def toSemiring (f : ∀ i, A i →+ R) (hone : f _ GradedMonoid.GOne.one = 1)
(hmul : ∀ {i j} (ai : A i) (aj : A j), f _ (GradedMonoid.GMul.mul ai aj) = f _ ai * f _ aj) :
(⨁ i, A i) →+* R :=
{ toAddMonoid f with
toFun := toAddMonoid f
map_one' := by
change (toAddMonoid f) (of _ 0 _) = 1
rw [toAddMonoid_of]
exact hone
map_mul' := by
rw [(toAddMonoid f).map_mul_iff]
refine DirectSum.addHom_ext' (fun xi ↦ AddMonoidHom.ext (fun xv ↦ ?_))
refine DirectSum.addHom_ext' (fun yi ↦ AddMonoidHom.ext (fun yv ↦ ?_))
change
toAddMonoid f (of A xi xv * of A yi yv) =
toAddMonoid f (of A xi xv) * toAddMonoid f (of A yi yv)
simp_rw [of_mul_of, toAddMonoid_of]
exact hmul _ _ }
theorem toSemiring_of (f : ∀ i, A i →+ R) (hone hmul) (i : ι) (x : A i) :
toSemiring f hone hmul (of _ i x) = f _ x :=
toAddMonoid_of f i x
@[simp]
theorem toSemiring_coe_addMonoidHom (f : ∀ i, A i →+ R) (hone hmul) :
(toSemiring f hone hmul : (⨁ i, A i) →+ R) = toAddMonoid f :=
rfl
/-- Families of `AddMonoidHom`s preserving `DirectSum.One.one` and `DirectSum.Mul.mul`
are isomorphic to `RingHom`s on `⨁ i, A i`. This is a stronger version of `DFinsupp.liftAddHom`.
-/
@[simps]
def liftRingHom :
{ f : ∀ {i}, A i →+ R //
f GradedMonoid.GOne.one = 1 ∧
∀ {i j} (ai : A i) (aj : A j), f (GradedMonoid.GMul.mul ai aj) = f ai * f aj } ≃
((⨁ i, A i) →+* R) where
toFun f := toSemiring (fun _ => f.1) f.2.1 f.2.2
invFun F :=
⟨by intro i; exact (F : (⨁ i, A i) →+ R).comp (of _ i),
by
simp only [AddMonoidHom.comp_apply]
rw [← F.map_one]
rfl,
by
intro i j ai aj
simp only [AddMonoidHom.comp_apply, AddMonoidHom.coe_coe]
rw [← F.map_mul (of A i ai), of_mul_of ai]⟩
left_inv f := by
ext xi xv
exact toAddMonoid_of (fun _ => f.1) xi xv
right_inv F := by
apply RingHom.coe_addMonoidHom_injective
refine DirectSum.addHom_ext' (fun xi ↦ AddMonoidHom.ext (fun xv ↦ ?_))
simp only [DirectSum.toAddMonoid_of, AddMonoidHom.comp_apply, toSemiring_coe_addMonoidHom]
end ToSemiring
end DirectSum
/-! ### Concrete instances -/
section Uniform
variable (ι)
/-- A direct sum of copies of a `NonUnitalNonAssocSemiring` inherits the multiplication structure.
-/
instance NonUnitalNonAssocSemiring.directSumGNonUnitalNonAssocSemiring {R : Type*} [AddMonoid ι]
[NonUnitalNonAssocSemiring R] : DirectSum.GNonUnitalNonAssocSemiring fun _ : ι => R :=
{ -- Porting note: removed Mul.gMul ι with and we seem ok
mul_zero := mul_zero
zero_mul := zero_mul
mul_add := mul_add
add_mul := add_mul }
/-- A direct sum of copies of a `Semiring` inherits the multiplication structure. -/
instance Semiring.directSumGSemiring {R : Type*} [AddMonoid ι] [Semiring R] :
DirectSum.GSemiring fun _ : ι => R where
__ := NonUnitalNonAssocSemiring.directSumGNonUnitalNonAssocSemiring ι
__ := Monoid.gMonoid ι
natCast n := n
natCast_zero := Nat.cast_zero
natCast_succ := Nat.cast_succ
/-- A direct sum of copies of a `Ring` inherits the multiplication structure. -/
instance Ring.directSumGRing {R : Type*} [AddMonoid ι] [Ring R] :
DirectSum.GRing fun _ : ι => R where
__ := Semiring.directSumGSemiring ι
intCast z := z
intCast_ofNat := Int.cast_natCast
intCast_negSucc_ofNat := Int.cast_negSucc
open DirectSum
-- To check `Mul.gmul_mul` matches
example {R : Type*} [AddMonoid ι] [Semiring R] (i j : ι) (a b : R) :
(DirectSum.of _ i a * DirectSum.of _ j b : ⨁ _, R) = DirectSum.of _ (i + j) (a * b) := by
rw [DirectSum.of_mul_of, Mul.gMul_mul]
/-- A direct sum of copies of a `CommSemiring` inherits the commutative multiplication structure. -/
instance CommSemiring.directSumGCommSemiring {R : Type*} [AddCommMonoid ι] [CommSemiring R] :
DirectSum.GCommSemiring fun _ : ι => R where
__ := Semiring.directSumGSemiring ι
__ := CommMonoid.gCommMonoid ι
/-- A direct sum of copies of a `CommRing` inherits the commutative multiplication structure. -/
instance CommRing.directSumGCommRing {R : Type*} [AddCommMonoid ι] [CommRing R] :
DirectSum.GCommRing fun _ : ι => R where
__ := Ring.directSumGRing ι
__ := CommMonoid.gCommMonoid ι
end Uniform |
.lake/packages/mathlib/Mathlib/Algebra/DirectSum/Internal.lean | import Mathlib.Algebra.Algebra.Operations
import Mathlib.Algebra.Algebra.Subalgebra.Basic
import Mathlib.Algebra.DirectSum.Algebra
import Mathlib.Algebra.Order.Antidiag.Prod
/-!
# Internally graded rings and algebras
This module provides `DirectSum.GSemiring` and `DirectSum.GCommSemiring` instances for a collection
of subobjects `A` when a `SetLike.GradedMonoid` instance is available:
* `SetLike.gnonUnitalNonAssocSemiring`
* `SetLike.gsemiring`
* `SetLike.gcommSemiring`
With these instances in place, it provides the bundled canonical maps out of a direct sum of
subobjects into their carrier type:
* `DirectSum.coeRingHom` (a `RingHom` version of `DirectSum.coeAddMonoidHom`)
* `DirectSum.coeAlgHom` (an `AlgHom` version of `DirectSum.coeLinearMap`)
Strictly the definitions in this file are not sufficient to fully define an "internal" direct sum;
to represent this case, `(h : DirectSum.IsInternal A) [SetLike.GradedMonoid A]` is
needed. In the future there will likely be a data-carrying, constructive, typeclass version of
`DirectSum.IsInternal` for providing an explicit decomposition function.
When `iSupIndep (Set.range A)` (a weaker condition than
`DirectSum.IsInternal A`), these provide a grading of `⨆ i, A i`, and the
mapping `⨁ i, A i →+ ⨆ i, A i` can be obtained as
`DirectSum.toAddMonoid (fun i ↦ AddSubmonoid.inclusion <| le_iSup A i)`.
This file also provides some extra structure on `A 0`, namely:
* `SetLike.GradeZero.subsemiring`, which leads to
* `SetLike.GradeZero.instSemiring`
* `SetLike.GradeZero.instCommSemiring`
* `SetLike.GradeZero.subring`, which leads to
* `SetLike.GradeZero.instRing`
* `SetLike.GradeZero.instCommRing`
* `SetLike.GradeZero.subalgebra`, which leads to
* `SetLike.GradeZero.instAlgebra`
## Tags
internally graded ring
-/
open DirectSum
variable {ι : Type*} {σ S R : Type*}
theorem SetLike.algebraMap_mem_graded [Zero ι] [CommSemiring S] [Semiring R] [Algebra S R]
(A : ι → Submodule S R) [SetLike.GradedOne A] (s : S) : algebraMap S R s ∈ A 0 := by
rw [Algebra.algebraMap_eq_smul_one]
exact (A 0).smul_mem s <| SetLike.one_mem_graded _
theorem SetLike.natCast_mem_graded [Zero ι] [AddMonoidWithOne R] [SetLike σ R]
[AddSubmonoidClass σ R] (A : ι → σ) [SetLike.GradedOne A] (n : ℕ) : (n : R) ∈ A 0 := by
induction n with
| zero =>
rw [Nat.cast_zero]
exact zero_mem (A 0)
| succ _ n_ih =>
rw [Nat.cast_succ]
exact add_mem n_ih (SetLike.one_mem_graded _)
theorem SetLike.intCast_mem_graded [Zero ι] [AddGroupWithOne R] [SetLike σ R]
[AddSubgroupClass σ R] (A : ι → σ) [SetLike.GradedOne A] (z : ℤ) : (z : R) ∈ A 0 := by
cases z
· rw [Int.ofNat_eq_coe, Int.cast_natCast]
exact SetLike.natCast_mem_graded _ _
· rw [Int.cast_negSucc]
exact neg_mem (SetLike.natCast_mem_graded _ _)
section DirectSum
variable [DecidableEq ι]
/-! #### From `AddSubmonoid`s and `AddSubgroup`s -/
namespace SetLike
/-- Build a `DirectSum.GNonUnitalNonAssocSemiring` instance for a collection of additive
submonoids. -/
instance gnonUnitalNonAssocSemiring [Add ι] [NonUnitalNonAssocSemiring R] [SetLike σ R]
[AddSubmonoidClass σ R] (A : ι → σ) [SetLike.GradedMul A] :
DirectSum.GNonUnitalNonAssocSemiring fun i => A i :=
{ SetLike.gMul A with
mul_zero := fun _ => Subtype.ext (mul_zero _)
zero_mul := fun _ => Subtype.ext (zero_mul _)
mul_add := fun _ _ _ => Subtype.ext (mul_add _ _ _)
add_mul := fun _ _ _ => Subtype.ext (add_mul _ _ _) }
/-- Build a `DirectSum.GSemiring` instance for a collection of additive submonoids. -/
instance gsemiring [AddMonoid ι] [Semiring R] [SetLike σ R] [AddSubmonoidClass σ R] (A : ι → σ)
[SetLike.GradedMonoid A] : DirectSum.GSemiring fun i => A i :=
{ SetLike.gMonoid A with
mul_zero := fun _ => Subtype.ext (mul_zero _)
zero_mul := fun _ => Subtype.ext (zero_mul _)
mul_add := fun _ _ _ => Subtype.ext (mul_add _ _ _)
add_mul := fun _ _ _ => Subtype.ext (add_mul _ _ _)
natCast := fun n => ⟨n, SetLike.natCast_mem_graded _ _⟩
natCast_zero := Subtype.ext Nat.cast_zero
natCast_succ := fun n => Subtype.ext (Nat.cast_succ n) }
/-- Build a `DirectSum.GCommSemiring` instance for a collection of additive submonoids. -/
instance gcommSemiring [AddCommMonoid ι] [CommSemiring R] [SetLike σ R] [AddSubmonoidClass σ R]
(A : ι → σ) [SetLike.GradedMonoid A] : DirectSum.GCommSemiring fun i => A i :=
{ SetLike.gCommMonoid A, SetLike.gsemiring A with }
/-- Build a `DirectSum.GRing` instance for a collection of additive subgroups. -/
instance gring [AddMonoid ι] [Ring R] [SetLike σ R] [AddSubgroupClass σ R] (A : ι → σ)
[SetLike.GradedMonoid A] : DirectSum.GRing fun i => A i :=
{ SetLike.gsemiring A with
intCast := fun z => ⟨z, SetLike.intCast_mem_graded _ _⟩
intCast_ofNat := fun _n => Subtype.ext <| Int.cast_natCast _
intCast_negSucc_ofNat := fun n => Subtype.ext <| Int.cast_negSucc n }
/-- Build a `DirectSum.GCommRing` instance for a collection of additive submonoids. -/
instance gcommRing [AddCommMonoid ι] [CommRing R] [SetLike σ R] [AddSubgroupClass σ R] (A : ι → σ)
[SetLike.GradedMonoid A] : DirectSum.GCommRing fun i => A i :=
{ SetLike.gCommMonoid A, SetLike.gring A with }
end SetLike
namespace DirectSum
section coe
variable [Semiring R] [SetLike σ R] [AddSubmonoidClass σ R] (A : ι → σ)
/-- The canonical ring isomorphism between `⨁ i, A i` and `R` -/
def coeRingHom [AddMonoid ι] [SetLike.GradedMonoid A] : (⨁ i, A i) →+* R :=
DirectSum.toSemiring (fun i => AddSubmonoidClass.subtype (A i)) rfl fun _ _ => rfl
/-- The canonical ring isomorphism between `⨁ i, A i` and `R` -/
@[simp]
theorem coeRingHom_of [AddMonoid ι] [SetLike.GradedMonoid A] (i : ι) (x : A i) :
(coeRingHom A : _ →+* R) (of (fun i => A i) i x) = x :=
DirectSum.toSemiring_of _ _ _ _ _
theorem coe_mul_apply [AddMonoid ι] [SetLike.GradedMonoid A]
[∀ (i : ι) (x : A i), Decidable (x ≠ 0)] (r r' : ⨁ i, A i) (n : ι) :
((r * r') n : R) =
∑ ij ∈ r.support ×ˢ r'.support with ij.1 + ij.2 = n, (r ij.1 * r' ij.2 : R) := by
rw [mul_eq_sum_support_ghas_mul, DFinsupp.finset_sum_apply, AddSubmonoidClass.coe_finset_sum]
simp_rw [coe_of_apply, apply_ite, ZeroMemClass.coe_zero, ← Finset.sum_filter, SetLike.coe_gMul]
theorem coe_mul_apply_eq_dfinsuppSum [AddMonoid ι] [SetLike.GradedMonoid A]
[∀ (i : ι) (x : A i), Decidable (x ≠ 0)] (r r' : ⨁ i, A i) (n : ι) :
((r * r') n : R) = r.sum fun i ri => r'.sum fun j rj => if i + j = n then (ri * rj : R)
else 0 := by
rw [mul_eq_dfinsuppSum]
iterate 2 rw [DFinsupp.sum_apply, DFinsupp.sum, AddSubmonoidClass.coe_finset_sum]; congr; ext
dsimp only
split_ifs with h
· subst h
rw [of_eq_same]
rfl
· rw [of_eq_of_ne _ _ _ (Ne.symm h)]
rfl
open Finset in
theorem coe_mul_apply_eq_sum_antidiagonal [AddMonoid ι] [HasAntidiagonal ι]
[SetLike.GradedMonoid A] (r r' : ⨁ i, A i) (n : ι) :
(r * r') n = ∑ ij ∈ antidiagonal n, (r ij.1 : R) * r' ij.2 := by
classical
rw [coe_mul_apply]
apply Finset.sum_subset (fun _ ↦ by simp)
aesop (erase simp not_and) (add simp not_and_or)
theorem coe_of_mul_apply_aux [AddMonoid ι] [SetLike.GradedMonoid A] {i : ι} (r : A i)
(r' : ⨁ i, A i) {j n : ι} (H : ∀ x : ι, i + x = n ↔ x = j) :
((of (fun i => A i) i r * r') n : R) = r * r' j := by
classical
rw [coe_mul_apply_eq_dfinsuppSum]
apply (DFinsupp.sum_single_index _).trans
swap
· simp_rw [ZeroMemClass.coe_zero, zero_mul, ite_self]
exact DFinsupp.sum_zero
simp_rw [DFinsupp.sum, H, Finset.sum_ite_eq']
split_ifs with h
· rfl
rw [DFinsupp.notMem_support_iff.mp h, ZeroMemClass.coe_zero, mul_zero]
theorem coe_mul_of_apply_aux [AddMonoid ι] [SetLike.GradedMonoid A] (r : ⨁ i, A i) {i : ι}
(r' : A i) {j n : ι} (H : ∀ x : ι, x + i = n ↔ x = j) :
((r * of (fun i => A i) i r') n : R) = r j * r' := by
classical
rw [coe_mul_apply_eq_dfinsuppSum, DFinsupp.sum_comm]
apply (DFinsupp.sum_single_index _).trans
swap
· simp_rw [ZeroMemClass.coe_zero, mul_zero, ite_self]
exact DFinsupp.sum_zero
simp_rw [DFinsupp.sum, H, Finset.sum_ite_eq']
split_ifs with h
· rfl
rw [DFinsupp.notMem_support_iff.mp h, ZeroMemClass.coe_zero, zero_mul]
theorem coe_of_mul_apply_add [AddLeftCancelMonoid ι] [SetLike.GradedMonoid A] {i : ι} (r : A i)
(r' : ⨁ i, A i) (j : ι) : ((of (fun i => A i) i r * r') (i + j) : R) = r * r' j :=
coe_of_mul_apply_aux _ _ _ fun _x => ⟨fun h => add_left_cancel h, fun h => h ▸ rfl⟩
theorem coe_mul_of_apply_add [AddRightCancelMonoid ι] [SetLike.GradedMonoid A] (r : ⨁ i, A i)
{i : ι} (r' : A i) (j : ι) : ((r * of (fun i => A i) i r') (j + i) : R) = r j * r' :=
coe_mul_of_apply_aux _ _ _ fun _x => ⟨fun h => add_right_cancel h, fun h => h ▸ rfl⟩
theorem coe_of_mul_apply_of_mem_zero [AddMonoid ι] [SetLike.GradedMonoid A] (r : A 0)
(r' : ⨁ i, A i) (j : ι) : ((of (fun i => A i) 0 r * r') j : R) = r * r' j :=
coe_of_mul_apply_aux _ _ _ fun _x => by rw [zero_add]
theorem coe_mul_of_apply_of_mem_zero [AddMonoid ι] [SetLike.GradedMonoid A] (r : ⨁ i, A i)
(r' : A 0) (j : ι) : ((r * of (fun i => A i) 0 r') j : R) = r j * r' :=
coe_mul_of_apply_aux _ _ _ fun _x => by rw [add_zero]
end coe
section CanonicallyOrderedAddCommMonoid
variable [Semiring R] [SetLike σ R] [AddSubmonoidClass σ R] (A : ι → σ)
variable [AddCommMonoid ι] [PartialOrder ι] [CanonicallyOrderedAdd ι] [SetLike.GradedMonoid A]
theorem coe_of_mul_apply_of_not_le {i : ι} (r : A i) (r' : ⨁ i, A i) (n : ι) (h : ¬i ≤ n) :
((of (fun i => A i) i r * r') n : R) = 0 := by
classical
rw [coe_mul_apply_eq_dfinsuppSum]
apply (DFinsupp.sum_single_index _).trans
swap
· simp_rw [ZeroMemClass.coe_zero, zero_mul, ite_self]
exact DFinsupp.sum_zero
· rw [DFinsupp.sum, Finset.sum_ite_of_false, Finset.sum_const_zero]
exact fun x _ H => h ((self_le_add_right i x).trans_eq H)
theorem coe_mul_of_apply_of_not_le (r : ⨁ i, A i) {i : ι} (r' : A i) (n : ι) (h : ¬i ≤ n) :
((r * of (fun i => A i) i r') n : R) = 0 := by
classical
rw [coe_mul_apply_eq_dfinsuppSum, DFinsupp.sum_comm]
apply (DFinsupp.sum_single_index _).trans
swap
· simp_rw [ZeroMemClass.coe_zero, mul_zero, ite_self]
exact DFinsupp.sum_zero
· rw [DFinsupp.sum, Finset.sum_ite_of_false, Finset.sum_const_zero]
exact fun x _ H => h ((self_le_add_left i x).trans_eq H)
variable [Sub ι] [OrderedSub ι] [AddLeftReflectLE ι]
/- The following two lemmas only require the same hypotheses as `eq_tsub_iff_add_eq_of_le`, but we
state them for the above typeclasses for convenience. -/
theorem coe_mul_of_apply_of_le (r : ⨁ i, A i) {i : ι} (r' : A i) (n : ι) (h : i ≤ n) :
((r * of (fun i => A i) i r') n : R) = r (n - i) * r' :=
coe_mul_of_apply_aux _ _ _ fun _x => (eq_tsub_iff_add_eq_of_le h).symm
theorem coe_of_mul_apply_of_le {i : ι} (r : A i) (r' : ⨁ i, A i) (n : ι) (h : i ≤ n) :
((of (fun i => A i) i r * r') n : R) = r * r' (n - i) :=
coe_of_mul_apply_aux _ _ _ fun x => by rw [eq_tsub_iff_add_eq_of_le h, add_comm]
theorem coe_mul_of_apply (r : ⨁ i, A i) {i : ι} (r' : A i) (n : ι) [Decidable (i ≤ n)] :
((r * of (fun i => A i) i r') n : R) = if i ≤ n then (r (n - i) : R) * r' else 0 := by
split_ifs with h
exacts [coe_mul_of_apply_of_le _ _ _ n h, coe_mul_of_apply_of_not_le _ _ _ n h]
theorem coe_of_mul_apply {i : ι} (r : A i) (r' : ⨁ i, A i) (n : ι) [Decidable (i ≤ n)] :
((of (fun i => A i) i r * r') n : R) = if i ≤ n then (r * r' (n - i) : R) else 0 := by
split_ifs with h
exacts [coe_of_mul_apply_of_le _ _ _ n h, coe_of_mul_apply_of_not_le _ _ _ n h]
end CanonicallyOrderedAddCommMonoid
end DirectSum
/-! #### From `Submodule`s -/
namespace Submodule
/-- Build a `DirectSum.GAlgebra` instance for a collection of `Submodule`s. -/
instance galgebra [AddMonoid ι] [CommSemiring S] [Semiring R] [Algebra S R] (A : ι → Submodule S R)
[SetLike.GradedMonoid A] : DirectSum.GAlgebra S fun i => A i where
toFun :=
((Algebra.linearMap S R).codRestrict (A 0) <| SetLike.algebraMap_mem_graded A).toAddMonoidHom
map_one := Subtype.ext <| (algebraMap S R).map_one
map_mul _x _y := Sigma.subtype_ext (add_zero 0).symm <| (algebraMap S R).map_mul _ _
commutes := fun _r ⟨i, _xi⟩ =>
Sigma.subtype_ext ((zero_add i).trans (add_zero i).symm) <| Algebra.commutes _ _
smul_def := fun _r ⟨i, _xi⟩ => Sigma.subtype_ext (zero_add i).symm <| Algebra.smul_def _ _
@[simp]
theorem setLike.coe_galgebra_toFun {ι} [AddMonoid ι] [CommSemiring S] [Semiring R] [Algebra S R]
(A : ι → Submodule S R) [SetLike.GradedMonoid A] (s : S) :
(DirectSum.GAlgebra.toFun (A := fun i => A i) s) = (algebraMap S R s : R) :=
rfl
/-- A direct sum of powers of a submodule of an algebra has a multiplicative structure. -/
instance nat_power_gradedMonoid [CommSemiring S] [Semiring R] [Algebra S R] (p : Submodule S R) :
SetLike.GradedMonoid fun i : ℕ => p ^ i where
one_mem := by
rw [← one_le, pow_zero]
mul_mem i j p q hp hq := by
rw [pow_add]
exact Submodule.mul_mem_mul hp hq
end Submodule
/-- The canonical algebra isomorphism between `⨁ i, A i` and `R`. -/
def DirectSum.coeAlgHom [AddMonoid ι] [CommSemiring S] [Semiring R] [Algebra S R]
(A : ι → Submodule S R) [SetLike.GradedMonoid A] : (⨁ i, A i) →ₐ[S] R :=
DirectSum.toAlgebra S _ (fun i => (A i).subtype) rfl (fun _ _ => rfl)
/-- The supremum of submodules that form a graded monoid is a subalgebra, and equal to the range of
`DirectSum.coeAlgHom`. -/
theorem Submodule.iSup_eq_toSubmodule_range [AddMonoid ι] [CommSemiring S] [Semiring R]
[Algebra S R] (A : ι → Submodule S R) [SetLike.GradedMonoid A] :
⨆ i, A i = Subalgebra.toSubmodule (DirectSum.coeAlgHom A).range :=
(Submodule.iSup_eq_range_dfinsupp_lsum A).trans <| SetLike.coe_injective rfl
@[simp]
theorem DirectSum.coeAlgHom_of [AddMonoid ι] [CommSemiring S] [Semiring R] [Algebra S R]
(A : ι → Submodule S R) [SetLike.GradedMonoid A] (i : ι) (x : A i) :
DirectSum.coeAlgHom A (DirectSum.of (fun i => A i) i x) = x :=
DirectSum.toSemiring_of _ (by rfl) (fun _ _ => (by rfl)) _ _
end DirectSum
/-! ### Facts about grade zero -/
namespace SetLike.GradeZero
section Semiring
variable [Semiring R] [AddMonoid ι] [SetLike σ R] [AddSubmonoidClass σ R]
variable (A : ι → σ) [SetLike.GradedMonoid A]
/-- The subsemiring `A 0` of `R`. -/
def subsemiring : Subsemiring R where
carrier := A 0
__ := submonoid A
add_mem' := add_mem
zero_mem' := zero_mem (A 0)
-- TODO: it might be expensive to unify `A` in this instance in practice
/-- The semiring `A 0` inherited from `R` in the presence of `SetLike.GradedMonoid A`. -/
instance instSemiring : Semiring (A 0) := (subsemiring A).toSemiring
@[simp, norm_cast] theorem coe_natCast (n : ℕ) : (n : A 0) = (n : R) := rfl
@[simp, norm_cast] theorem coe_ofNat (n : ℕ) [n.AtLeastTwo] :
(ofNat(n) : A 0) = (ofNat(n) : R) := rfl
end Semiring
section CommSemiring
variable [CommSemiring R] [AddMonoid ι] [SetLike σ R] [AddSubmonoidClass σ R]
variable (A : ι → σ) [SetLike.GradedMonoid A]
-- TODO: it might be expensive to unify `A` in this instance in practice
/-- The commutative semiring `A 0` inherited from `R` in the presence of
`SetLike.GradedMonoid A`. -/
instance instCommSemiring : CommSemiring (A 0) := (subsemiring A).toCommSemiring
instance : Algebra (A 0) R :=
Algebra.ofSubsemiring <| SetLike.GradeZero.subsemiring A
@[simp] lemma algebraMap_apply (x : A 0) : algebraMap (A 0) R x = x := rfl
end CommSemiring
section Ring
variable [Ring R] [AddMonoid ι] [SetLike σ R] [AddSubgroupClass σ R]
variable (A : ι → σ) [SetLike.GradedMonoid A]
/-- The subring `A 0` of `R`. -/
def subring : Subring R where
carrier := A 0
__ := subsemiring A
neg_mem' := neg_mem
-- TODO: it might be expensive to unify `A` in this instances in practice
/-- The ring `A 0` inherited from `R` in the presence of `SetLike.GradedMonoid A`. -/
instance instRing : Ring (A 0) := (subring A).toRing
theorem coe_intCast (z : ℤ) : (z : A 0) = (z : R) := rfl
end Ring
section CommRing
variable [CommRing R] [AddCommMonoid ι] [SetLike σ R] [AddSubgroupClass σ R]
variable (A : ι → σ) [SetLike.GradedMonoid A]
-- TODO: it might be expensive to unify `A` in this instances in practice
/-- The commutative ring `A 0` inherited from `R` in the presence of `SetLike.GradedMonoid A`. -/
instance instCommRing : CommRing (A 0) := (subring A).toCommRing
end CommRing
section Algebra
variable [CommSemiring S] [Semiring R] [Algebra S R] [AddMonoid ι]
variable (A : ι → Submodule S R) [SetLike.GradedMonoid A]
/-- The subalgebra `A 0` of `R`. -/
def subalgebra : Subalgebra S R where
carrier := A 0
__ := subsemiring A
algebraMap_mem' := algebraMap_mem_graded A
-- TODO: it might be expensive to unify `A` in this instances in practice
/-- The `S`-algebra `A 0` inherited from `R` in the presence of `SetLike.GradedMonoid A`. -/
instance instAlgebra : Algebra S (A 0) := inferInstanceAs <| Algebra S (subalgebra A)
@[simp, norm_cast] theorem coe_algebraMap (s : S) :
↑(algebraMap _ (A 0) s) = algebraMap _ R s := rfl
end Algebra
end SetLike.GradeZero
section HomogeneousElement
theorem SetLike.homogeneous_zero_submodule [Zero ι] [Semiring S] [AddCommMonoid R] [Module S R]
(A : ι → Submodule S R) : SetLike.IsHomogeneousElem A (0 : R) :=
⟨0, Submodule.zero_mem _⟩
theorem SetLike.Homogeneous.smul [CommSemiring S] [Semiring R] [Algebra S R] {A : ι → Submodule S R}
{s : S} {r : R} (hr : SetLike.IsHomogeneousElem A r) : SetLike.IsHomogeneousElem A (s • r) :=
let ⟨i, hi⟩ := hr
⟨i, Submodule.smul_mem _ _ hi⟩
end HomogeneousElement
/-! ### Gradings by canonically linearly ordered additive monoids -/
section LinearOrderedAddCommMonoid
variable [AddCommMonoid ι] [LinearOrder ι] [IsOrderedAddMonoid ι] [DecidableEq ι]
section Semiring
variable [Semiring R] [SetLike σ R] [AddSubmonoidClass σ R]
variable {A : ι → σ} [SetLike.GradedMonoid A]
theorem mul_apply_eq_zero {r r' : ⨁ i, A i} {m n : ι}
(hr : ∀ i < m, r i = 0) (hr' : ∀ i < n, r' i = 0) ⦃k : ι⦄ (hk : k < m + n) :
(r * r') k = 0 := by
classical
rw [Subtype.ext_iff, ZeroMemClass.coe_zero, coe_mul_apply]
apply Finset.sum_eq_zero fun x hx ↦ ?_
obtain (hx | hx) : x.1 < m ∨ x.2 < n := by
by_contra! h
obtain ⟨hm, hn⟩ := h
obtain rfl : x.1 + x.2 = k := by simp_all
apply lt_irrefl (m + n) <| lt_of_le_of_lt (by gcongr) hk
all_goals simp [hr, hr', hx]
variable [CanonicallyOrderedAdd ι]
/-- The difference with `DirectSum.listProd_apply_eq_zero` is that the indices at which
the terms of the list are zero is allowed to vary. -/
theorem listProd_apply_eq_zero' {l : List ((⨁ i, A i) × ι)}
(hl : ∀ xn ∈ l, ∀ k < xn.2, xn.1 k = 0) ⦃n : ι⦄ (hn : n < (l.map Prod.snd).sum) :
(l.map Prod.fst).prod n = 0 := by
induction l generalizing n with
| nil => simp [(zero_le n).not_gt] at hn
| cons head tail ih =>
simp only [List.mem_cons, forall_eq_or_imp, List.map_cons, List.sum_cons,
List.prod_cons] at hl hn ⊢
exact mul_apply_eq_zero hl.1 (ih hl.2) hn
theorem listProd_apply_eq_zero {l : List (⨁ i, A i)} {m : ι}
(hl : ∀ x ∈ l, ∀ k < m, x k = 0) ⦃n : ι⦄ (hn : n < l.length • m) :
l.prod n = 0 := by
-- a proof which uses `DirectSum.listProd_apply_eq_zero'` is actually more work
induction l generalizing n with
| nil => simp [(zero_le n).not_gt] at hn
| cons head tail ih =>
simp only [List.mem_cons, forall_eq_or_imp, List.length_cons, List.prod_cons] at hl hn ⊢
refine mul_apply_eq_zero hl.1 (ih hl.2) ?_
simpa [add_smul, add_comm m] using hn
end Semiring
variable [CanonicallyOrderedAdd ι]
section CommSemiring
variable [CommSemiring R] [SetLike σ R] [AddSubmonoidClass σ R]
variable {A : ι → σ} [SetLike.GradedMonoid A]
/-- The difference with `DirectSum.multisetProd_apply_eq_zero` is that the indices at which
the terms of the multiset are zero is allowed to vary. -/
theorem multisetProd_apply_eq_zero' {s : Multiset ((⨁ i, A i) × ι)}
(hs : ∀ xn ∈ s, ∀ k < xn.2, xn.1 k = 0) ⦃n : ι⦄ (hn : n < (s.map Prod.snd).sum) :
(s.map Prod.fst).prod n = 0 := by
have := listProd_apply_eq_zero' (l := s.toList) (by simpa using hs)
(by simpa [← Multiset.sum_coe, ← Multiset.map_coe])
simpa [← Multiset.prod_coe, ← Multiset.map_coe]
theorem multisetProd_apply_eq_zero {s : Multiset (⨁ i, A i)} {m : ι}
(hs : ∀ x ∈ s, ∀ k < m, x k = 0) ⦃n : ι⦄ (hn : n < s.card • m) :
s.prod n = 0 := by
have := listProd_apply_eq_zero (l := s.toList) (by simpa using hs)
(by simpa [← Multiset.sum_coe, ← Multiset.map_coe])
simpa [← Multiset.prod_coe, ← Multiset.map_coe]
/-- The difference with `DirectSum.finsetProd_apply_eq_zero` is that the indices at which
the terms of the multiset are zero is allowed to vary. -/
theorem finsetProd_apply_eq_zero' {s : Finset ((⨁ i, A i) × ι)}
(hs : ∀ xn ∈ s, ∀ k < xn.2, xn.1 k = 0) ⦃n : ι⦄ (hn : n < ∑ xn ∈ s, xn.2) :
(∏ xn ∈ s, xn.1) n = 0 := by
simpa using listProd_apply_eq_zero' (l := s.toList) (by simpa using hs) (by simpa)
theorem finsetProd_apply_eq_zero {s : Finset (⨁ i, A i)} {m : ι}
(hs : ∀ x ∈ s, ∀ k < m, x k = 0) ⦃n : ι⦄ (hn : n < s.card • m) :
(∏ x ∈ s, x) n = 0 := by
simpa using listProd_apply_eq_zero (l := s.toList) (by simpa using hs) (by simpa)
end CommSemiring
end LinearOrderedAddCommMonoid |
.lake/packages/mathlib/Mathlib/Algebra/DirectSum/Basic.lean | import Mathlib.Algebra.Group.Submonoid.Operations
import Mathlib.Data.DFinsupp.Sigma
import Mathlib.Data.DFinsupp.Submonoid
/-!
# Direct sum
This file defines the direct sum of abelian groups, indexed by a discrete type.
## Notation
`⨁ i, β i` is the n-ary direct sum `DirectSum`.
This notation is in the `DirectSum` locale, accessible after `open DirectSum`.
## References
* https://en.wikipedia.org/wiki/Direct_sum
-/
open Function
universe u v w u₁
variable (ι : Type v) (β : ι → Type w)
/-- `DirectSum ι β` is the direct sum of a family of additive commutative monoids `β i`.
Note: `open DirectSum` will enable the notation `⨁ i, β i` for `DirectSum ι β`. -/
def DirectSum [∀ i, AddCommMonoid (β i)] : Type _ :=
Π₀ i, β i
deriving AddCommMonoid, Inhabited, DFunLike, CoeFun
/-- `⨁ i, f i` is notation for `DirectSum _ f` and equals the direct sum of `fun i ↦ f i`.
Taking the direct sum over multiple arguments is possible, e.g. `⨁ (i) (j), f i j`. -/
scoped[DirectSum] notation3 "⨁ "(...)", "r:(scoped f => DirectSum _ f) => r
-- Porting note: The below recreates some of the lean3 notation, not fully yet
-- section
-- open Batteries.ExtendedBinder
-- syntax (name := bigdirectsum) "⨁ " extBinders ", " term : term
-- macro_rules (kind := bigdirectsum)
-- | `(⨁ $_:ident, $y:ident → $z:ident) => `(DirectSum _ (fun $y ↦ $z))
-- | `(⨁ $x:ident, $p) => `(DirectSum _ (fun $x ↦ $p))
-- | `(⨁ $_:ident : $t:ident, $p) => `(DirectSum _ (fun $t ↦ $p))
-- | `(⨁ ($x:ident) ($y:ident), $p) => `(DirectSum _ (fun $x ↦ fun $y ↦ $p))
-- end
instance [DecidableEq ι] [∀ i, AddCommMonoid (β i)] [∀ i, DecidableEq (β i)] :
DecidableEq (DirectSum ι β) :=
inferInstanceAs <| DecidableEq (Π₀ i, β i)
namespace DirectSum
variable {ι}
/-- Coercion from a `DirectSum` to a pi type is an `AddMonoidHom`. -/
def coeFnAddMonoidHom [∀ i, AddCommMonoid (β i)] : (⨁ i, β i) →+ (Π i, β i) where
toFun x := x
__ := DFinsupp.coeFnAddMonoidHom
@[simp]
lemma coeFnAddMonoidHom_apply [∀ i, AddCommMonoid (β i)] (v : ⨁ i, β i) :
coeFnAddMonoidHom β v = v :=
rfl
section AddCommGroup
variable [∀ i, AddCommGroup (β i)]
instance : AddCommGroup (DirectSum ι β) :=
inferInstanceAs (AddCommGroup (Π₀ i, β i))
variable {β}
@[simp]
theorem sub_apply (g₁ g₂ : ⨁ i, β i) (i : ι) : (g₁ - g₂) i = g₁ i - g₂ i :=
rfl
end AddCommGroup
variable [∀ i, AddCommMonoid (β i)]
@[ext] theorem ext {x y : DirectSum ι β} (w : ∀ i, x i = y i) : x = y :=
DFunLike.ext _ _ w
@[simp]
theorem zero_apply (i : ι) : (0 : ⨁ i, β i) i = 0 :=
rfl
variable {β}
@[simp]
theorem add_apply (g₁ g₂ : ⨁ i, β i) (i : ι) : (g₁ + g₂) i = g₁ i + g₂ i :=
rfl
section DecidableEq
variable [DecidableEq ι]
variable (β)
/-- `mk β s x` is the element of `⨁ i, β i` that is zero outside `s`
and has coefficient `x i` for `i` in `s`. -/
def mk (s : Finset ι) : (∀ i : (↑s : Set ι), β i.1) →+ ⨁ i, β i where
toFun := DFinsupp.mk s
map_add' _ _ := DFinsupp.mk_add
map_zero' := DFinsupp.mk_zero
/-- `of i` is the natural inclusion map from `β i` to `⨁ i, β i`. -/
def of (i : ι) : β i →+ ⨁ i, β i :=
DFinsupp.singleAddHom β i
variable {β}
@[simp]
theorem of_eq_same (i : ι) (x : β i) : (of _ i x) i = x :=
DFinsupp.single_eq_same
theorem of_eq_of_ne (i j : ι) (x : β i) (h : j ≠ i) : (of _ i x) j = 0 :=
DFinsupp.single_eq_of_ne h
lemma of_apply {i : ι} (j : ι) (x : β i) : of β i x j = if h : i = j then Eq.recOn h x else 0 :=
DFinsupp.single_apply
theorem mk_apply_of_mem {s : Finset ι} {f : ∀ i : (↑s : Set ι), β i.val} {n : ι} (hn : n ∈ s) :
mk β s f n = f ⟨n, hn⟩ := by
dsimp only [Finset.coe_sort_coe, mk, AddMonoidHom.coe_mk, ZeroHom.coe_mk, DFinsupp.mk_apply]
rw [dif_pos hn]
theorem mk_apply_of_notMem {s : Finset ι} {f : ∀ i : (↑s : Set ι), β i.val} {n : ι} (hn : n ∉ s) :
mk β s f n = 0 := by
dsimp only [Finset.coe_sort_coe, mk, AddMonoidHom.coe_mk, ZeroHom.coe_mk, DFinsupp.mk_apply]
rw [dif_neg hn]
@[deprecated (since := "2025-05-23")] alias mk_apply_of_not_mem := mk_apply_of_notMem
@[simp]
theorem support_zero [∀ (i : ι) (x : β i), Decidable (x ≠ 0)] : (0 : ⨁ i, β i).support = ∅ :=
DFinsupp.support_zero
@[simp]
theorem support_of [∀ (i : ι) (x : β i), Decidable (x ≠ 0)] (i : ι) (x : β i) (h : x ≠ 0) :
(of _ i x).support = {i} :=
DFinsupp.support_single_ne_zero h
theorem support_of_subset [∀ (i : ι) (x : β i), Decidable (x ≠ 0)] {i : ι} {b : β i} :
(of _ i b).support ⊆ {i} :=
DFinsupp.support_single_subset
theorem sum_support_of [∀ (i : ι) (x : β i), Decidable (x ≠ 0)] (x : ⨁ i, β i) :
(∑ i ∈ x.support, of β i (x i)) = x :=
DFinsupp.sum_single
theorem sum_univ_of [Fintype ι] (x : ⨁ i, β i) :
∑ i ∈ Finset.univ, of β i (x i) = x := by
apply DFinsupp.ext (fun i ↦ ?_)
rw [DFinsupp.finset_sum_apply]
simp [of_apply]
theorem mk_injective (s : Finset ι) : Function.Injective (mk β s) :=
DFinsupp.mk_injective s
theorem of_injective (i : ι) : Function.Injective (of β i) :=
DFinsupp.single_injective
@[elab_as_elim]
protected theorem induction_on {motive : (⨁ i, β i) → Prop} (x : ⨁ i, β i) (zero : motive 0)
(of : ∀ (i : ι) (x : β i), motive (of β i x))
(add : ∀ x y, motive x → motive y → motive (x + y)) : motive x := by
apply DFinsupp.induction x zero
intro i b f h1 h2 ih
solve_by_elim
/-- If two additive homomorphisms from `⨁ i, β i` are equal on each `of β i y`,
then they are equal. -/
theorem addHom_ext {γ : Type*} [AddZeroClass γ] ⦃f g : (⨁ i, β i) →+ γ⦄
(H : ∀ (i : ι) (y : β i), f (of _ i y) = g (of _ i y)) : f = g :=
DFinsupp.addHom_ext H
/-- If two additive homomorphisms from `⨁ i, β i` are equal on each `of β i y`,
then they are equal.
See note [partially-applied ext lemmas]. -/
@[ext high]
theorem addHom_ext' {γ : Type*} [AddZeroClass γ] ⦃f g : (⨁ i, β i) →+ γ⦄
(H : ∀ i : ι, f.comp (of _ i) = g.comp (of _ i)) : f = g :=
addHom_ext fun i => DFunLike.congr_fun <| H i
variable {γ : Type u₁} [AddCommMonoid γ]
section ToAddMonoid
variable (φ : ∀ i, β i →+ γ) (ψ : (⨁ i, β i) →+ γ)
-- Porting note: The elaborator is struggling with `liftAddHom`. Passing it `β` explicitly helps.
-- This applies to roughly the remainder of the file.
/-- `toAddMonoid φ` is the natural homomorphism from `⨁ i, β i` to `γ`
induced by a family `φ` of homomorphisms `β i → γ`. -/
def toAddMonoid : (⨁ i, β i) →+ γ :=
DFinsupp.liftAddHom (β := β) φ
@[simp]
theorem toAddMonoid_of (i) (x : β i) : toAddMonoid φ (of β i x) = φ i x :=
DFinsupp.liftAddHom_apply_single φ i x
theorem toAddMonoid.unique (f : ⨁ i, β i) : ψ f = toAddMonoid (fun i => ψ.comp (of β i)) f := by
congr
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `ext` applies addHom_ext' here, which isn't what we want.
apply DFinsupp.addHom_ext'
simp [toAddMonoid, of]
lemma toAddMonoid_injective : Injective (toAddMonoid : (∀ i, β i →+ γ) → (⨁ i, β i) →+ γ) :=
DFinsupp.liftAddHom.injective
@[simp] lemma toAddMonoid_inj {f g : ∀ i, β i →+ γ} : toAddMonoid f = toAddMonoid g ↔ f = g :=
toAddMonoid_injective.eq_iff
end ToAddMonoid
section FromAddMonoid
/-- `fromAddMonoid φ` is the natural homomorphism from `γ` to `⨁ i, β i`
induced by a family `φ` of homomorphisms `γ → β i`.
Note that this is not an isomorphism. Not every homomorphism `γ →+ ⨁ i, β i` arises in this way. -/
def fromAddMonoid : (⨁ i, γ →+ β i) →+ γ →+ ⨁ i, β i :=
toAddMonoid fun i => AddMonoidHom.compHom (of β i)
@[simp]
theorem fromAddMonoid_of (i : ι) (f : γ →+ β i) : fromAddMonoid (of _ i f) = (of _ i).comp f := by
rw [fromAddMonoid, toAddMonoid_of]
rfl
theorem fromAddMonoid_of_apply (i : ι) (f : γ →+ β i) (x : γ) :
fromAddMonoid (of _ i f) x = of _ i (f x) := by
rw [fromAddMonoid_of, AddMonoidHom.coe_comp, Function.comp]
end FromAddMonoid
variable (β)
-- TODO: generalize this to remove the assumption `S ⊆ T`.
/-- `setToSet β S T h` is the natural homomorphism `⨁ (i : S), β i → ⨁ (i : T), β i`,
where `h : S ⊆ T`. -/
def setToSet (S T : Set ι) (H : S ⊆ T) : (⨁ i : S, β i) →+ ⨁ i : T, β i :=
toAddMonoid fun i => of (fun i : Subtype T => β i) ⟨↑i, H i.2⟩
end DecidableEq
instance unique [∀ i, Subsingleton (β i)] : Unique (⨁ i, β i) :=
DFinsupp.unique
/-- A direct sum over an empty type is trivial. -/
instance uniqueOfIsEmpty [IsEmpty ι] : Unique (⨁ i, β i) :=
DFinsupp.uniqueOfIsEmpty
/-- The natural equivalence between `⨁ _ : ι, M` and `M` when `Unique ι`. -/
protected def id (M : Type v) (ι : Type* := PUnit) [AddCommMonoid M] [Unique ι] :
(⨁ _ : ι, M) ≃+ M :=
{
DirectSum.toAddMonoid fun _ =>
AddMonoidHom.id
M with
toFun := DirectSum.toAddMonoid fun _ => AddMonoidHom.id M
invFun := of (fun _ => M) default
left_inv := fun x =>
DirectSum.induction_on x (by rw [AddMonoidHom.map_zero, AddMonoidHom.map_zero])
(fun p x => by rw [Unique.default_eq p, toAddMonoid_of]; rfl) fun x y ihx ihy => by grind
right_inv := fun _ => toAddMonoid_of _ _ _ }
section CongrLeft
variable {κ : Type*}
/-- Reindexing terms of a direct sum. -/
def equivCongrLeft (h : ι ≃ κ) : (⨁ i, β i) ≃+ ⨁ k, β (h.symm k) :=
{ DFinsupp.equivCongrLeft h with map_add' := DFinsupp.comapDomain'_add _ h.right_inv}
@[simp]
theorem equivCongrLeft_apply (h : ι ≃ κ) (f : ⨁ i, β i) (k : κ) :
equivCongrLeft h f k = f (h.symm k) := by
exact DFinsupp.comapDomain'_apply _ h.right_inv _ _
end CongrLeft
section Option
variable {α : Option ι → Type w} [∀ i, AddCommMonoid (α i)]
/-- Isomorphism obtained by separating the term of index `none` of a direct sum over `Option ι`. -/
@[simps!]
noncomputable def addEquivProdDirectSum : (⨁ i, α i) ≃+ α none × ⨁ i, α (some i) :=
{ DFinsupp.equivProdDFinsupp with map_add' := DFinsupp.equivProdDFinsupp_add }
end Option
section Sigma
variable [DecidableEq ι] {α : ι → Type u} {δ : ∀ i, α i → Type w} [∀ i j, AddCommMonoid (δ i j)]
/-- The natural map between `⨁ (i : Σ i, α i), δ i.1 i.2` and `⨁ i (j : α i), δ i j`. -/
def sigmaCurry : (⨁ i : Σ _i, _, δ i.1 i.2) →+ ⨁ (i) (j), δ i j where
toFun := DFinsupp.sigmaCurry (δ := δ)
map_zero' := DFinsupp.sigmaCurry_zero
map_add' f g := DFinsupp.sigmaCurry_add f g
@[simp]
theorem sigmaCurry_apply (f : ⨁ i : Σ _i, _, δ i.1 i.2) (i : ι) (j : α i) :
sigmaCurry f i j = f ⟨i, j⟩ :=
DFinsupp.sigmaCurry_apply (δ := δ) _ i j
/-- The natural map between `⨁ i (j : α i), δ i j` and `Π₀ (i : Σ i, α i), δ i.1 i.2`, inverse of
`curry`. -/
def sigmaUncurry : (⨁ (i) (j), δ i j) →+ ⨁ i : Σ _i, _, δ i.1 i.2 where
toFun := DFinsupp.sigmaUncurry
map_zero' := DFinsupp.sigmaUncurry_zero
map_add' := DFinsupp.sigmaUncurry_add
@[simp]
theorem sigmaUncurry_apply (f : ⨁ (i) (j), δ i j) (i : ι) (j : α i) :
sigmaUncurry f ⟨i, j⟩ = f i j :=
DFinsupp.sigmaUncurry_apply f i j
/-- The natural map between `⨁ (i : Σ i, α i), δ i.1 i.2` and `⨁ i (j : α i), δ i j`. -/
def sigmaCurryEquiv : (⨁ i : Σ _i, _, δ i.1 i.2) ≃+ ⨁ (i) (j), δ i j :=
{ sigmaCurry, DFinsupp.sigmaCurryEquiv with }
end Sigma
/-- The canonical embedding from `⨁ i, A i` to `M` where `A` is a collection of `AddSubmonoid M`
indexed by `ι`.
When `S = Submodule _ M`, this is available as a `LinearMap`, `DirectSum.coe_linearMap`. -/
protected def coeAddMonoidHom {M S : Type*} [DecidableEq ι] [AddCommMonoid M] [SetLike S M]
[AddSubmonoidClass S M] (A : ι → S) : (⨁ i, A i) →+ M :=
toAddMonoid fun i => AddSubmonoidClass.subtype (A i)
theorem coeAddMonoidHom_eq_dfinsuppSum [DecidableEq ι]
{M S : Type*} [DecidableEq M] [AddCommMonoid M]
[SetLike S M] [AddSubmonoidClass S M] (A : ι → S) (x : DirectSum ι fun i => A i) :
DirectSum.coeAddMonoidHom A x = DFinsupp.sum x fun i => (fun x : A i => ↑x) := by
simp only [DirectSum.coeAddMonoidHom, toAddMonoid, DFinsupp.liftAddHom, AddEquiv.coe_mk,
Equiv.coe_fn_mk]
exact DFinsupp.sumAddHom_apply _ x
@[simp]
theorem coeAddMonoidHom_of {M S : Type*} [DecidableEq ι] [AddCommMonoid M] [SetLike S M]
[AddSubmonoidClass S M] (A : ι → S) (i : ι) (x : A i) :
DirectSum.coeAddMonoidHom A (of (fun i => A i) i x) = x :=
toAddMonoid_of _ _ _
theorem coe_of_apply {M S : Type*} [DecidableEq ι] [AddCommMonoid M] [SetLike S M]
[AddSubmonoidClass S M] {A : ι → S} (i j : ι) (x : A i) :
(of (fun i ↦ {x // x ∈ A i}) i x j : M) = if i = j then x else 0 := by
obtain rfl | h := Decidable.eq_or_ne j i
· rw [DirectSum.of_eq_same, if_pos rfl]
· rw [DirectSum.of_eq_of_ne _ _ _ h, if_neg h.symm, ZeroMemClass.coe_zero, ZeroMemClass.coe_zero]
/-- The `DirectSum` formed by a collection of additive submonoids (or subgroups, or submodules) of
`M` is said to be internal if the canonical map `(⨁ i, A i) →+ M` is bijective.
For the alternate statement in terms of independence and spanning, see
`DirectSum.subgroup_isInternal_iff_iSupIndep_and_supr_eq_top` and
`DirectSum.isInternal_submodule_iff_iSupIndep_and_iSup_eq_top`. -/
def IsInternal {M S : Type*} [DecidableEq ι] [AddCommMonoid M] [SetLike S M]
[AddSubmonoidClass S M] (A : ι → S) : Prop :=
Function.Bijective (DirectSum.coeAddMonoidHom A)
theorem IsInternal.addSubmonoid_iSup_eq_top {M : Type*} [DecidableEq ι] [AddCommMonoid M]
(A : ι → AddSubmonoid M) (h : IsInternal A) : iSup A = ⊤ := by
rw [AddSubmonoid.iSup_eq_mrange_dfinsuppSumAddHom, AddMonoidHom.mrange_eq_top]
exact Function.Bijective.surjective h
variable {M S : Type*} [AddCommMonoid M] [SetLike S M] [AddSubmonoidClass S M]
theorem support_subset [DecidableEq ι] [DecidableEq M] (A : ι → S) (x : DirectSum ι fun i => A i) :
(Function.support fun i => (x i : M)) ⊆ ↑(DFinsupp.support x) := by
intro m
simp only [Function.mem_support, Finset.mem_coe, DFinsupp.mem_support_toFun, not_imp_not,
ZeroMemClass.coe_eq_zero, imp_self]
theorem finite_support (A : ι → S) (x : DirectSum ι fun i => A i) :
(Function.support fun i => (x i : M)).Finite := by
classical
exact (DFinsupp.support x).finite_toSet.subset (DirectSum.support_subset _ x)
section map
variable {ι : Type*} {α : ι → Type*} {β : ι → Type*} [∀ i, AddCommMonoid (α i)]
variable [∀ i, AddCommMonoid (β i)] (f : ∀ (i : ι), α i →+ β i)
/-- create a homomorphism from `⨁ i, α i` to `⨁ i, β i` by giving the component-wise map `f`. -/
def map : (⨁ i, α i) →+ ⨁ i, β i := DFinsupp.mapRange.addMonoidHom f
@[simp] lemma map_of [DecidableEq ι] (i : ι) (x : α i) : map f (of α i x) = of β i (f i x) :=
DFinsupp.mapRange_single (hf := fun _ => map_zero _)
@[simp] lemma map_apply (i : ι) (x : ⨁ i, α i) : map f x i = f i (x i) :=
DFinsupp.mapRange_apply (hf := fun _ => map_zero _) _ _ _
@[simp] lemma map_id :
(map (fun i ↦ AddMonoidHom.id (α i))) = AddMonoidHom.id (⨁ i, α i) :=
DFinsupp.mapRange.addMonoidHom_id
@[simp] lemma map_comp {γ : ι → Type*} [∀ i, AddCommMonoid (γ i)]
(g : ∀ (i : ι), β i →+ γ i) :
(map (fun i ↦ (g i).comp (f i))) = (map g).comp (map f) :=
DFinsupp.mapRange.addMonoidHom_comp _ _
lemma map_injective : Function.Injective (map f) ↔ ∀ i, Function.Injective (f i) := by
classical exact DFinsupp.mapRange_injective (hf := fun _ ↦ map_zero _)
lemma map_surjective : Function.Surjective (map f) ↔ (∀ i, Function.Surjective (f i)) := by
classical exact DFinsupp.mapRange_surjective (hf := fun _ ↦ map_zero _)
lemma map_eq_iff (x y : ⨁ i, α i) :
map f x = map f y ↔ ∀ i, f i (x i) = f i (y i) := by
simp_rw [DirectSum.ext_iff, map_apply]
end map
end DirectSum
/-- The canonical isomorphism of a finite direct sum of additive commutative monoids
and the corresponding finite product. -/
def DirectSum.addEquivProd {ι : Type*} [Fintype ι] (G : ι → Type*) [(i : ι) → AddCommMonoid (G i)] :
DirectSum ι G ≃+ ((i : ι) → G i) :=
⟨DFinsupp.equivFunOnFintype, fun g h ↦ funext fun _ ↦ by
simp only [DFinsupp.equivFunOnFintype, Equiv.toFun_as_coe, Equiv.coe_fn_mk, add_apply,
Pi.add_apply]⟩ |
.lake/packages/mathlib/Mathlib/Algebra/DirectSum/Finsupp.lean | import Mathlib.Algebra.DirectSum.Module
import Mathlib.Data.Finsupp.ToDFinsupp
/-!
# Results on direct sums and finitely supported functions.
1. The linear equivalence between finitely supported functions `ι →₀ M` and
the direct sum of copies of `M` indexed by `ι`.
-/
universe u v w
noncomputable section
open DirectSum
open LinearMap Submodule
variable {R : Type u} {M : Type v} [Semiring R] [AddCommMonoid M] [Module R M]
section finsuppLequivDirectSum
variable (R M) (ι : Type*) [DecidableEq ι]
/-- The finitely supported functions `ι →₀ M` are in linear equivalence with the direct sum of
copies of M indexed by ι. -/
def finsuppLEquivDirectSum : (ι →₀ M) ≃ₗ[R] ⨁ _ : ι, M :=
haveI : ∀ m : M, Decidable (m ≠ 0) := Classical.decPred _
finsuppLequivDFinsupp R
@[simp]
theorem finsuppLEquivDirectSum_single (i : ι) (m : M) :
finsuppLEquivDirectSum R M ι (Finsupp.single i m) = DirectSum.lof R ι _ i m :=
Finsupp.toDFinsupp_single i m
@[simp]
theorem finsuppLEquivDirectSum_symm_lof (i : ι) (m : M) :
(finsuppLEquivDirectSum R M ι).symm (DirectSum.lof R ι _ i m) = Finsupp.single i m :=
letI : ∀ m : M, Decidable (m ≠ 0) := Classical.decPred _
DFinsupp.toFinsupp_single i m
end finsuppLequivDirectSum |
.lake/packages/mathlib/Mathlib/Algebra/DirectSum/LinearMap.lean | import Mathlib.LinearAlgebra.FreeModule.Finite.Basic
import Mathlib.LinearAlgebra.FreeModule.PID
import Mathlib.LinearAlgebra.Eigenspace.Basic
import Mathlib.LinearAlgebra.Trace
/-!
# Linear maps between direct sums
This file contains results about linear maps which respect direct sum decompositions of their
domain and codomain.
-/
open DirectSum Module Set
namespace LinearMap
variable {ι R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] {N : ι → Submodule R M}
section IsInternal
variable [DecidableEq ι]
/-- If a linear map `f : M₁ → M₂` respects direct sum decompositions of `M₁` and `M₂`, then it has a
block diagonal matrix with respect to bases compatible with the direct sum decompositions. -/
lemma toMatrix_directSum_collectedBasis_eq_blockDiagonal' {R M₁ M₂ : Type*} [CommSemiring R]
[AddCommMonoid M₁] [Module R M₁] {N₁ : ι → Submodule R M₁} (h₁ : IsInternal N₁)
[AddCommMonoid M₂] [Module R M₂] {N₂ : ι → Submodule R M₂} (h₂ : IsInternal N₂)
{κ₁ κ₂ : ι → Type*} [∀ i, Fintype (κ₁ i)] [∀ i, Finite (κ₂ i)] [∀ i, DecidableEq (κ₁ i)]
[Fintype ι] (b₁ : (i : ι) → Basis (κ₁ i) R (N₁ i)) (b₂ : (i : ι) → Basis (κ₂ i) R (N₂ i))
{f : M₁ →ₗ[R] M₂} (hf : ∀ i, MapsTo f (N₁ i) (N₂ i)) :
toMatrix (h₁.collectedBasis b₁) (h₂.collectedBasis b₂) f =
Matrix.blockDiagonal' fun i ↦ toMatrix (b₁ i) (b₂ i) (f.restrict (hf i)) := by
ext ⟨i, _⟩ ⟨j, _⟩
simp only [toMatrix_apply, Matrix.blockDiagonal'_apply]
rcases eq_or_ne i j with rfl | hij
· simp [h₂.collectedBasis_repr_of_mem _ (hf _ (Subtype.mem _)), restrict_apply]
· simp [hij, h₂.collectedBasis_repr_of_mem_ne _ hij.symm (hf _ (Subtype.mem _))]
lemma diag_toMatrix_directSum_collectedBasis_eq_zero_of_mapsTo_ne
{κ : ι → Type*} [∀ i, Fintype (κ i)] [∀ i, DecidableEq (κ i)]
{s : Finset ι} (h : IsInternal fun i : s ↦ N i)
(b : (i : s) → Basis (κ i) R (N i)) (σ : ι → ι) (hσ : ∀ i, σ i ≠ i)
{f : Module.End R M} (hf : ∀ i, MapsTo f (N i) (N <| σ i)) (hN : ∀ i, i ∉ s → N i = ⊥) :
Matrix.diag (toMatrix (h.collectedBasis b) (h.collectedBasis b) f) = 0 := by
ext ⟨i, k⟩
simp only [Matrix.diag_apply, Pi.zero_apply, toMatrix_apply, IsInternal.collectedBasis_coe]
by_cases hi : σ i ∈ s
· let j : s := ⟨σ i, hi⟩
replace hσ : j ≠ i := fun hij ↦ hσ i <| Subtype.ext_iff.mp hij
exact h.collectedBasis_repr_of_mem_ne b hσ <| hf _ <| Subtype.mem (b i k)
· suffices f (b i k) = 0 by simp [this]
simpa [hN _ hi] using hf i <| Subtype.mem (b i k)
variable [∀ i, Module.Finite R (N i)] [∀ i, Module.Free R (N i)]
/-- The trace of an endomorphism of a direct sum is the sum of the traces on each component.
See also `LinearMap.trace_restrict_eq_sum_trace_restrict`. -/
lemma trace_eq_sum_trace_restrict (h : IsInternal N) [Fintype ι]
{f : M →ₗ[R] M} (hf : ∀ i, MapsTo f (N i) (N i)) :
trace R M f = ∑ i, trace R (N i) (f.restrict (hf i)) := by
let b : (i : ι) → Basis _ R (N i) := fun i ↦ Module.Free.chooseBasis R (N i)
simp_rw [trace_eq_matrix_trace R (h.collectedBasis b),
toMatrix_directSum_collectedBasis_eq_blockDiagonal' h h b b hf, Matrix.trace_blockDiagonal',
← trace_eq_matrix_trace]
lemma trace_eq_sum_trace_restrict' (h : IsInternal N) (hN : {i | N i ≠ ⊥}.Finite)
{f : M →ₗ[R] M} (hf : ∀ i, MapsTo f (N i) (N i)) :
trace R M f = ∑ i ∈ hN.toFinset, trace R (N i) (f.restrict (hf i)) := by
let _ : Fintype {i // N i ≠ ⊥} := hN.fintype
let _ : Fintype {i | N i ≠ ⊥} := hN.fintype
rw [← Finset.sum_coe_sort, trace_eq_sum_trace_restrict (isInternal_ne_bot_iff.mpr h) (hf ·)]
exact Fintype.sum_equiv hN.subtypeEquivToFinset _ _ (fun i ↦ rfl)
lemma trace_eq_zero_of_mapsTo_ne (h : IsInternal N) [IsNoetherian R M]
(σ : ι → ι) (hσ : ∀ i, σ i ≠ i) {f : Module.End R M}
(hf : ∀ i, MapsTo f (N i) (N <| σ i)) :
trace R M f = 0 := by
have hN : {i | N i ≠ ⊥}.Finite := WellFoundedGT.finite_ne_bot_of_iSupIndep
h.submodule_iSupIndep
let s := hN.toFinset
let κ := fun i ↦ Module.Free.ChooseBasisIndex R (N i)
let b : (i : s) → Basis (κ i) R (N i) := fun i ↦ Module.Free.chooseBasis R (N i)
replace h : IsInternal fun i : s ↦ N i := by
convert DirectSum.isInternal_ne_bot_iff.mpr h <;> simp [s]
simp_rw [trace_eq_matrix_trace R (h.collectedBasis b), Matrix.trace,
diag_toMatrix_directSum_collectedBasis_eq_zero_of_mapsTo_ne h b σ hσ hf (by simp [s]),
Pi.zero_apply, Finset.sum_const_zero]
/-- If `f` and `g` are commuting endomorphisms of a finite, free `R`-module `M`, such that `f`
is triangularizable, then to prove that the trace of `g ∘ f` vanishes, it is sufficient to prove
that the trace of `g` vanishes on each generalized eigenspace of `f`. -/
lemma trace_comp_eq_zero_of_commute_of_trace_restrict_eq_zero
[IsDomain R] [IsPrincipalIdealRing R] [Module.Free R M] [Module.Finite R M]
{f g : Module.End R M}
(h_comm : Commute f g)
(hf : ⨆ μ, f.maxGenEigenspace μ = ⊤)
(hg : ∀ μ, trace R _ (g.restrict (f.mapsTo_maxGenEigenspace_of_comm h_comm μ)) = 0) :
trace R _ (g ∘ₗ f) = 0 := by
have hfg : ∀ μ,
MapsTo (g ∘ₗ f) ↑(f.maxGenEigenspace μ) ↑(f.maxGenEigenspace μ) :=
fun μ ↦ (f.mapsTo_maxGenEigenspace_of_comm h_comm μ).comp
(f.mapsTo_maxGenEigenspace_of_comm rfl μ)
suffices ∀ μ, trace R _ ((g ∘ₗ f).restrict (hfg μ)) = 0 by
classical
have hds := DirectSum.isInternal_submodule_of_iSupIndep_of_iSup_eq_top
f.independent_maxGenEigenspace hf
have h_fin : {μ | f.maxGenEigenspace μ ≠ ⊥}.Finite :=
WellFoundedGT.finite_ne_bot_of_iSupIndep f.independent_maxGenEigenspace
simp [trace_eq_sum_trace_restrict' hds h_fin hfg, this]
intro μ
have hf' := f.mapsTo_maxGenEigenspace_of_comm (Commute.refl _) μ
have hg' := f.mapsTo_maxGenEigenspace_of_comm h_comm μ
replace h_comm : Commute (g.restrict (f.mapsTo_maxGenEigenspace_of_comm h_comm μ))
(f.restrict (f.mapsTo_maxGenEigenspace_of_comm rfl μ)) :=
restrict_commute h_comm.symm _ _
have := f.isNilpotent_restrict_maxGenEigenspace_sub_algebraMap μ
rw [restrict_comp hf' hg', trace_comp_eq_mul_of_commute_of_isNilpotent μ h_comm this,
hg, mul_zero]
lemma mapsTo_biSup_of_mapsTo {ι : Type*} {N : ι → Submodule R M}
(s : Set ι) {f : Module.End R M} (hf : ∀ i, MapsTo f (N i) (N i)) :
MapsTo f ↑(⨆ i ∈ s, N i) ↑(⨆ i ∈ s, N i) := by
replace hf : ∀ i, (N i).map f ≤ N i := fun i ↦ Submodule.map_le_iff_le_comap.mpr (hf i)
suffices (⨆ i ∈ s, N i).map f ≤ ⨆ i ∈ s, N i from Submodule.map_le_iff_le_comap.mp this
simpa only [Submodule.map_iSup] using iSup₂_mono <| fun i _ ↦ hf i
end IsInternal
/-- The trace of an endomorphism of a direct sum is the sum of the traces on each component.
Note that it is important the statement gives the user definitional control over `p` since the
_type_ of the term `trace R p (f.restrict hp')` depends on `p`. -/
lemma trace_eq_sum_trace_restrict_of_eq_biSup
[∀ i, Module.Finite R (N i)] [∀ i, Module.Free R (N i)]
(s : Finset ι) (h : iSupIndep <| fun i : s ↦ N i)
{f : Module.End R M} (hf : ∀ i, MapsTo f (N i) (N i))
(p : Submodule R M) (hp : p = ⨆ i ∈ s, N i)
(hp' : MapsTo f p p := hp ▸ mapsTo_biSup_of_mapsTo (s : Set ι) hf) :
trace R p (f.restrict hp') = ∑ i ∈ s, trace R (N i) (f.restrict (hf i)) := by
classical
let N' : s → Submodule R p := fun i ↦ (N i).comap p.subtype
replace h : IsInternal N' := hp ▸ isInternal_biSup_submodule_of_iSupIndep (s : Set ι) h
have hf' : ∀ i, MapsTo (restrict f hp') (N' i) (N' i) := fun i x hx' ↦ by simpa using hf i hx'
let e : (i : s) → N' i ≃ₗ[R] N i := fun ⟨i, hi⟩ ↦ (N i).comapSubtypeEquivOfLe (hp ▸ le_biSup N hi)
have _i1 : ∀ i, Module.Finite R (N' i) := fun i ↦ Module.Finite.equiv (e i).symm
have _i2 : ∀ i, Module.Free R (N' i) := fun i ↦ Module.Free.of_equiv (e i).symm
rw [trace_eq_sum_trace_restrict h hf', ← s.sum_coe_sort]
have : ∀ i : s, f.restrict (hf i) = (e i).conj ((f.restrict hp').restrict (hf' i)) := fun _ ↦ rfl
simp [this]
end LinearMap |
.lake/packages/mathlib/Mathlib/Algebra/DirectSum/Algebra.lean | import Mathlib.Algebra.Algebra.Defs
import Mathlib.Algebra.DirectSum.Module
import Mathlib.Algebra.DirectSum.Ring
/-! # Additively-graded algebra structures on `⨁ i, A i`
This file provides `R`-algebra structures on external direct sums of `R`-modules.
Recall that if `A i` are a family of `AddCommMonoid`s indexed by an `AddMonoid`, then an instance
of `DirectSum.GMonoid A` is a multiplication `A i → A j → A (i + j)` giving `⨁ i, A i` the
structure of a semiring. In this file, we introduce the `DirectSum.GAlgebra R A` class for the case
where all `A i` are `R`-modules. This is the extra structure needed to promote `⨁ i, A i` to an
`R`-algebra.
## Main definitions
* `DirectSum.GAlgebra R A`, the typeclass.
* `DirectSum.toAlgebra` extends `DirectSum.toSemiring` to produce an `AlgHom`.
-/
universe uι uR uA uB
variable {ι : Type uι}
namespace DirectSum
open DirectSum
variable (R : Type uR) (A : ι → Type uA) {B : Type uB}
variable [CommSemiring R] [∀ i, AddCommMonoid (A i)] [∀ i, Module R (A i)]
variable [AddMonoid ι] [GSemiring A]
section
/-- A graded version of `Algebra`. An instance of `DirectSum.GAlgebra R A` endows `(⨁ i, A i)`
with an `R`-algebra structure. -/
class GAlgebra where
toFun : R →+ A 0
map_one : toFun 1 = GradedMonoid.GOne.one
map_mul :
∀ r s, GradedMonoid.mk _ (toFun (r * s)) = .mk _ (GradedMonoid.GMul.mul (toFun r) (toFun s))
commutes : ∀ (r) (x : GradedMonoid A), .mk _ (toFun r) * x = x * .mk _ (toFun r)
smul_def : ∀ (r) (x : GradedMonoid A), r • x = .mk _ (toFun r) * x
end
variable [Semiring B] [GAlgebra R A] [Algebra R B]
instance _root_.GradedMonoid.smulCommClass_right :
SMulCommClass R (GradedMonoid A) (GradedMonoid A) where
smul_comm s x y := by
dsimp
rw [GAlgebra.smul_def, GAlgebra.smul_def, ← mul_assoc, GAlgebra.commutes, mul_assoc]
instance _root_.GradedMonoid.isScalarTower_right :
IsScalarTower R (GradedMonoid A) (GradedMonoid A) where
smul_assoc s x y := by
dsimp
rw [GAlgebra.smul_def, GAlgebra.smul_def, ← mul_assoc]
variable [DecidableEq ι]
instance : Algebra R (⨁ i, A i) where
algebraMap :=
{ toFun := (DirectSum.of A 0).comp GAlgebra.toFun
map_zero' := AddMonoidHom.map_zero _
map_add' := AddMonoidHom.map_add _
map_one' := DFunLike.congr_arg (DirectSum.of A 0) GAlgebra.map_one
map_mul' a b := by
simp only [AddMonoidHom.comp_apply]
rw [of_mul_of]
apply DFinsupp.single_eq_of_sigma_eq (GAlgebra.map_mul a b) }
commutes' r x := by
change AddMonoidHom.mul (DirectSum.of _ _ _) x = AddMonoidHom.mul.flip (DirectSum.of _ _ _) x
apply DFunLike.congr_fun _ x
ext i xi : 2
dsimp only [AddMonoidHom.comp_apply, AddMonoidHom.mul_apply, AddMonoidHom.flip_apply]
rw [of_mul_of, of_mul_of]
apply DFinsupp.single_eq_of_sigma_eq (GAlgebra.commutes r ⟨i, xi⟩)
smul_def' r x := by
change DistribMulAction.toAddMonoidHom _ r x = AddMonoidHom.mul (DirectSum.of _ _ _) x
apply DFunLike.congr_fun _ x
ext i xi : 2
dsimp only [AddMonoidHom.comp_apply, DistribMulAction.toAddMonoidHom_apply,
AddMonoidHom.mul_apply]
rw [DirectSum.of_mul_of, ← of_smul]
apply DFinsupp.single_eq_of_sigma_eq (GAlgebra.smul_def r ⟨i, xi⟩)
theorem algebraMap_apply (r : R) :
algebraMap R (⨁ i, A i) r = DirectSum.of A 0 (GAlgebra.toFun r) :=
rfl
theorem algebraMap_toAddMonoid_hom :
↑(algebraMap R (⨁ i, A i)) = (DirectSum.of A 0).comp (GAlgebra.toFun : R →+ A 0) :=
rfl
/-- A family of `LinearMap`s preserving `DirectSum.GOne.one` and `DirectSum.GMul.mul`
describes an `AlgHom` on `⨁ i, A i`. This is a stronger version of `DirectSum.toSemiring`.
Of particular interest is the case when `A i` are bundled subobjects, `f` is the family of
coercions such as `Submodule.subtype (A i)`, and the `[GMonoid A]` structure originates from
`DirectSum.GMonoid.ofAddSubmodules`, in which case the proofs about `GOne` and `GMul`
can be discharged by `rfl`. -/
@[simps]
def toAlgebra (f : ∀ i, A i →ₗ[R] B) (hone : f _ GradedMonoid.GOne.one = 1)
(hmul : ∀ {i j} (ai : A i) (aj : A j), f _ (GradedMonoid.GMul.mul ai aj) = f _ ai * f _ aj) :
(⨁ i, A i) →ₐ[R] B :=
{ toSemiring (fun i => (f i).toAddMonoidHom) hone @hmul with
toFun := toSemiring (fun i => (f i).toAddMonoidHom) hone @hmul
commutes' := fun r => by
change toModule R _ _ f (algebraMap R _ r) = _
rw [Algebra.algebraMap_eq_smul_one, Algebra.algebraMap_eq_smul_one, map_smul, one_def,
← lof_eq_of R, toModule_lof, hone] }
/-- Two `AlgHom`s out of a direct sum are equal if they agree on the generators.
See note [partially-applied ext lemmas]. -/
@[ext]
theorem algHom_ext' ⦃f g : (⨁ i, A i) →ₐ[R] B⦄
(h : ∀ i, f.toLinearMap.comp (lof _ _ A i) = g.toLinearMap.comp (lof _ _ A i)) : f = g :=
AlgHom.toLinearMap_injective <| DirectSum.linearMap_ext _ h
theorem algHom_ext ⦃f g : (⨁ i, A i) →ₐ[R] B⦄ (h : ∀ i x, f (of A i x) = g (of A i x)) : f = g :=
algHom_ext' R A fun i => LinearMap.ext <| h i
/-- The piecewise multiplication from the `Mul` instance, as a bundled linear map.
This is the graded version of `LinearMap.mul`, and the linear version of `DirectSum.gMulHom` -/
@[simps]
def gMulLHom {i j} : A i →ₗ[R] A j →ₗ[R] A (i + j) where
toFun a :=
{ toFun := fun b => GradedMonoid.GMul.mul a b
map_smul' := fun r x => by
injection (smul_comm r (GradedMonoid.mk _ a) (GradedMonoid.mk _ x)).symm
map_add' := GNonUnitalNonAssocSemiring.mul_add _ }
map_smul' r x := LinearMap.ext fun y => by
injection smul_assoc r (GradedMonoid.mk _ x) (GradedMonoid.mk _ y)
map_add' _ _ := LinearMap.ext fun _ => GNonUnitalNonAssocSemiring.add_mul _ _ _
end DirectSum
/-! ### Concrete instances -/
/-- A direct sum of copies of an `Algebra` inherits the algebra structure. -/
@[simps]
instance Algebra.directSumGAlgebra {R A : Type*} [AddMonoid ι] [CommSemiring R]
[Semiring A] [Algebra R A] : DirectSum.GAlgebra R fun _ : ι => A where
toFun := (algebraMap R A).toAddMonoidHom
map_one := (algebraMap R A).map_one
map_mul a b := Sigma.ext (zero_add _).symm (heq_of_eq <| (algebraMap R A).map_mul a b)
commutes := fun _ ⟨_, _⟩ =>
Sigma.ext ((zero_add _).trans (add_zero _).symm) (heq_of_eq <| Algebra.commutes _ _)
smul_def := fun _ ⟨_, _⟩ => Sigma.ext (zero_add _).symm (heq_of_eq <| Algebra.smul_def _ _) |
.lake/packages/mathlib/Mathlib/Algebra/DirectSum/Idempotents.lean | import Mathlib.RingTheory.Idempotents
import Mathlib.Algebra.DirectSum.Decomposition
/-!
# Decomposition of the identity of a semiring into orthogonal idempotents
In this file we show that if a semiring `R` can be decomposed into a direct sum
of (left) ideals `R = V₁ ⊕ V₂ ⊕ ⋯ ⊕ Vₙ` then in the corresponding decomposition
`1 = e₁ + e₂ + ⋯ + eₙ` with `eᵢ ∈ Vᵢ`, each `eᵢ` is an idempotent and the
`eᵢ`'s form a family of complete orthogonal idempotents.
-/
namespace DirectSum
section OrthogonalIdempotents
variable {R I : Type*} [Semiring R] [DecidableEq I] (V : I → Ideal R) [Decomposition V]
/-- The decomposition of `(1 : R)` where `1 = e₁ + e₂ + ⋯ + eₙ` which is induced by
the decomposition of the semiring `R = V1 ⊕ V2 ⊕ ⋯ ⊕ Vn`. -/
def idempotent (i : I) : R :=
decompose V 1 i
lemma decompose_eq_mul_idempotent (x : R) (i : I) : decompose V x i = x * idempotent V i := by
rw [← smul_eq_mul (a := x), idempotent, ← Submodule.coe_smul, ← smul_apply, ← decompose_smul,
smul_eq_mul, mul_one]
lemma isIdempotentElem_idempotent (i : I) : IsIdempotentElem (idempotent V i : R) := by
rw [IsIdempotentElem, ← decompose_eq_mul_idempotent, idempotent, decompose_coe, of_eq_same]
/-- If a semiring can be decomposed into direct sum of finite left ideals `Vᵢ`
where `1 = e₁ + ... + eₙ` and `eᵢ ∈ Vᵢ`, then `eᵢ` is a family of complete
orthogonal idempotents. -/
theorem completeOrthogonalIdempotents_idempotent [Fintype I] :
CompleteOrthogonalIdempotents (idempotent V) where
idem := isIdempotentElem_idempotent V
ortho i j hij := by
simp only
rw [← decompose_eq_mul_idempotent, idempotent, decompose_coe,
of_eq_of_ne (h := hij.symm), Submodule.coe_zero]
complete := by
apply (decompose V).injective
refine DFunLike.ext _ _ fun i ↦ ?_
rw [decompose_sum, DFinsupp.finset_sum_apply]
simp [idempotent, of_apply]
end OrthogonalIdempotents
end DirectSum |
.lake/packages/mathlib/Mathlib/Algebra/DirectSum/AddChar.lean | import Mathlib.Algebra.DirectSum.Basic
import Mathlib.Algebra.Group.AddChar
/-!
# Direct sum of additive characters
This file defines the direct sum of additive characters.
-/
open Function
open scoped DirectSum
variable {ι R : Type*} {G : ι → Type*} [DecidableEq ι] [∀ i, AddCommGroup (G i)] [CommMonoid R]
namespace AddChar
section DirectSum
/-- Direct sum of additive characters. -/
@[simps!]
def directSum (ψ : ∀ i, AddChar (G i) R) : AddChar (⨁ i, G i) R :=
toAddMonoidHomEquiv.symm <| DirectSum.toAddMonoid fun i ↦ toAddMonoidHomEquiv (ψ i)
lemma directSum_injective :
Injective (directSum : (∀ i, AddChar (G i) R) → AddChar (⨁ i, G i) R) := by
refine toAddMonoidHomEquiv.symm.injective.comp <| DirectSum.toAddMonoid_injective.comp ?_
rintro ψ χ h
simpa [funext_iff] using h
end DirectSum
end AddChar |
.lake/packages/mathlib/Mathlib/Algebra/Category/CommBialgCat.lean | import Mathlib.Algebra.Category.CommAlgCat.Monoidal
import Mathlib.CategoryTheory.Monoidal.Mon_
import Mathlib.RingTheory.Bialgebra.Equiv
/-!
# The category of commutative bialgebras over a commutative ring
This file defines the bundled category `CommBialgCat R` of commutative bialgebras over a fixed
commutative ring `R` along with the forgetful functor to `CommAlgCat`.
-/
noncomputable section
open Bialgebra Coalgebra Opposite CategoryTheory Limits MonObj
open scoped MonoidalCategory
universe v u
variable {R : Type u} [CommRing R]
variable (R) in
/-- The category of commutative `R`-bialgebras and their morphisms. -/
structure CommBialgCat where
private mk ::
/-- The underlying type. -/
carrier : Type v
[commRing : CommRing carrier]
[bialgebra : Bialgebra R carrier]
namespace CommBialgCat
variable {A B C : CommBialgCat.{v} R} {X Y Z : Type v} [CommRing X] [Bialgebra R X]
[CommRing Y] [Bialgebra R Y] [CommRing Z] [Bialgebra R Z]
attribute [instance] commRing bialgebra
initialize_simps_projections CommBialgCat (-commRing, -bialgebra)
instance : CoeSort (CommBialgCat R) (Type v) := ⟨carrier⟩
attribute [coe] CommBialgCat.carrier
variable (R) in
/-- Turn an unbundled `R`-bialgebra into the corresponding object in the category of `R`-bialgebras.
This is the preferred way to construct a term of `CommBialgCat R`. -/
abbrev of (X : Type v) [CommRing X] [Bialgebra R X] : CommBialgCat.{v} R := ⟨X⟩
variable (R) in
lemma coe_of (X : Type v) [CommRing X] [Bialgebra R X] : (of R X : Type v) = X := rfl
/-- The type of morphisms in `CommBialgCat R`. -/
@[ext]
structure Hom (A B : CommBialgCat.{v} R) where
private mk ::
/-- The underlying bialgebra map. -/
hom' : A →ₐc[R] B
instance : Category (CommBialgCat.{v} R) where
Hom A B := Hom A B
id A := ⟨.id R A⟩
comp f g := ⟨g.hom'.comp f.hom'⟩
instance : ConcreteCategory (CommBialgCat.{v} R) (· →ₐc[R] ·) where
hom := Hom.hom'
ofHom := Hom.mk
/-- Turn a morphism in `CommBialgCat` back into a `BialgHom`. -/
abbrev Hom.hom (f : Hom A B) : A →ₐc[R] B := ConcreteCategory.hom (C := CommBialgCat R) f
/-- Typecheck a `BialgHom` as a morphism in `CommBialgCat R`. -/
abbrev ofHom {X Y : Type v} {_ : CommRing X} {_ : CommRing Y} {_ : Bialgebra R X}
{_ : Bialgebra R Y} (f : X →ₐc[R] Y) : of R X ⟶ of R Y :=
ConcreteCategory.ofHom (C := CommBialgCat R) f
/-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/
def Hom.Simps.hom (A B : CommBialgCat.{v} R) (f : Hom A B) := f.hom
initialize_simps_projections Hom (hom' → hom)
/-!
The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`.
-/
@[simp] lemma hom_id : (𝟙 A : A ⟶ A).hom = AlgHom.id R A := rfl
@[simp] lemma hom_comp (f : A ⟶ B) (g : B ⟶ C) : (f ≫ g).hom = g.hom.comp f.hom := rfl
lemma id_apply (A : CommBialgCat.{v} R) (a : A) : (𝟙 A : A ⟶ A) a = a := by simp
lemma comp_apply (f : A ⟶ B) (g : B ⟶ C) (a : A) : (f ≫ g) a = g (f a) := by simp
@[ext] lemma hom_ext {f g : A ⟶ B} (hf : f.hom = g.hom) : f = g := Hom.ext hf
@[simp] lemma hom_ofHom (f : X →ₐc[R] Y) : (ofHom f).hom = f := rfl
@[simp] lemma ofHom_hom (f : A ⟶ B) : ofHom f.hom = f := rfl
@[simp] lemma ofHom_id : ofHom (.id R X) = 𝟙 (of R X) := rfl
@[simp]
lemma ofHom_comp (f : X →ₐc[R] Y) (g : Y →ₐc[R] Z) : ofHom (g.comp f) = ofHom f ≫ ofHom g := rfl
lemma ofHom_apply (f : X →ₐc[R] Y) (x : X) : ofHom f x = f x := rfl
lemma inv_hom_apply (e : A ≅ B) (x : A) : e.inv (e.hom x) = x := by simp
lemma hom_inv_apply (e : A ≅ B) (x : B) : e.hom (e.inv x) = x := by simp
instance : Inhabited (CommBialgCat R) := ⟨of R R⟩
lemma forget_obj (A : CommBialgCat.{v} R) : (forget (CommBialgCat.{v} R)).obj A = A := rfl
lemma forget_map (f : A ⟶ B) : (forget (CommBialgCat.{v} R)).map f = f := rfl
instance : CommRing ((forget (CommBialgCat R)).obj A) := inferInstanceAs <| CommRing A
instance : Bialgebra R ((forget (CommBialgCat R)).obj A) := inferInstanceAs <| Bialgebra R A
instance hasForgetToCommAlgCat : HasForget₂ (CommBialgCat.{v} R) (CommAlgCat.{v} R) where
forget₂.obj M := .of R M
forget₂.map f := CommAlgCat.ofHom f.hom
@[simp] lemma forget₂_commAlgCat_obj (A : CommBialgCat.{v} R) :
(forget₂ (CommBialgCat.{v} R) (CommAlgCat.{v} R)).obj A = .of R A := rfl
@[simp] lemma forget₂_commAlgCat_map (f : A ⟶ B) :
(forget₂ (CommBialgCat.{v} R) (CommAlgCat.{v} R)).map f = CommAlgCat.ofHom f.hom := rfl
/-- Forgetting to the underlying type and then building the bundled object returns the original
bialgebra. -/
@[simps]
def ofSelfIso (M : CommBialgCat.{v} R) : of R M ≅ M where
hom := 𝟙 M
inv := 𝟙 M
/-- Build an isomorphism in the category `CommBialgCat R` from a `BialgEquiv` between
`Bialgebra`s. -/
@[simps]
def isoMk {X Y : Type v} {_ : CommRing X} {_ : CommRing Y} {_ : Bialgebra R X}
{_ : Bialgebra R Y} (e : X ≃ₐc[R] Y) : of R X ≅ of R Y where
hom := ofHom (e : X →ₐc[R] Y)
inv := ofHom (e.symm : Y →ₐc[R] X)
/-- Build a `BialgEquiv` from an isomorphism in the category `CommBialgCat R`. -/
@[simps apply, simps -isSimp symm_apply]
def bialgEquivOfIso (i : A ≅ B) : A ≃ₐc[R] B where
__ := i.hom.hom
toFun := i.hom
invFun := i.inv
left_inv x := by simp
right_inv x := by simp
/-- Bialgebra equivalences between `Bialgebra`s are the same as isomorphisms in `CommBialgCat`. -/
@[simps]
def isoEquivBialgEquiv : (of R X ≅ of R Y) ≃ (X ≃ₐc[R] Y) where
toFun := bialgEquivOfIso
invFun := isoMk
left_inv _ := rfl
right_inv _ := rfl
instance reflectsIsomorphisms_forget : (forget (CommBialgCat.{u} R)).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget (CommBialgCat.{u} R)).map f)
let e : X ≃ₐc[R] Y := { f.hom, i.toEquiv with }
exact (isoMk e).isIso_hom
end CommBialgCat
attribute [local ext] Quiver.Hom.unop_inj
instance CommAlgCat.monObjOpOf {A : Type u} [CommRing A] [Bialgebra R A] :
MonObj (op <| CommAlgCat.of R A) where
one := (CommAlgCat.ofHom <| counitAlgHom R A).op
mul := (CommAlgCat.ofHom <| comulAlgHom R A).op
one_mul := by ext; exact Coalgebra.rTensor_counit_comul _
mul_one := by ext; exact Coalgebra.lTensor_counit_comul _
mul_assoc := by ext; exact (Coalgebra.coassoc_symm_apply _).symm
@[simp]
lemma CommAlgCat.one_op_of_unop_hom {A : Type u} [CommRing A] [Bialgebra R A] :
η[op <| CommAlgCat.of R A].unop.hom = counitAlgHom R A := rfl
@[simp]
lemma CommAlgCat.mul_op_of_unop_hom {A : Type u} [CommRing A] [Bialgebra R A] :
μ[op <| CommAlgCat.of R A].unop.hom = comulAlgHom R A := rfl
instance {A : Type u} [CommRing A] [Bialgebra R A] [IsCocomm R A] :
IsCommMonObj (Opposite.op <| CommAlgCat.of R A) where
mul_comm := by ext; exact comm_comul R _
instance {A B : Type u} [CommRing A] [Bialgebra R A] [CommRing B] [Bialgebra R B]
(f : A →ₐc[R] B) : IsMonHom (CommAlgCat.ofHom (f : A →ₐ[R] B)).op where
instance (A : (CommAlgCat R)ᵒᵖ) [MonObj A] : Bialgebra R A.unop :=
.ofAlgHom μ[A].unop.hom η[A].unop.hom
congr(($((MonObj.mul_assoc_flip A).symm)).unop.hom)
congr(($(MonObj.one_mul A)).unop.hom)
congr(($(MonObj.mul_one A)).unop.hom)
variable (R) in
/-- Commutative bialgebras over a commutative ring `R` are the same thing as comonoid
`R`-algebras. -/
@[simps! functor_obj_unop_X inverse_obj unitIso_hom_app
unitIso_inv_app counitIso_hom_app counitIso_inv_app]
def commBialgCatEquivComonCommAlgCat : CommBialgCat R ≌ (Mon (CommAlgCat R)ᵒᵖ)ᵒᵖ where
functor.obj A := .op <| .mk <| .op <| .of R A
functor.map {A B} f := .op <| .mk' <| .op <| CommAlgCat.ofHom f.hom
inverse.obj A := .of R A.unop.X.unop
inverse.map {A B} f := CommBialgCat.ofHom <| .ofAlgHom f.unop.hom.unop.hom
congr(($(IsMonHom.one_hom (f := f.unop.hom))).unop.hom)
congr(($((IsMonHom.mul_hom (f := f.unop.hom)).symm)).unop.hom)
unitIso.hom := 𝟙 _
unitIso.inv := 𝟙 _
counitIso.hom := 𝟙 _
counitIso.inv := 𝟙 _
@[simp]
lemma commBialgCatEquivComonCommAlgCat_functor_map_unop_hom {A B : CommBialgCat R} (f : A ⟶ B) :
((commBialgCatEquivComonCommAlgCat R).functor.map f).unop.hom =
(CommAlgCat.ofHom (AlgHomClass.toAlgHom f.hom)).op := rfl
@[simp]
lemma commBialgCatEquivComonCommAlgCat_inverse_map_unop_hom
{A B : (Mon (CommAlgCat R)ᵒᵖ)ᵒᵖ} (f : A ⟶ B) :
AlgHomClass.toAlgHom ((commBialgCatEquivComonCommAlgCat R).inverse.map f).hom =
f.unop.hom.unop.hom := rfl
instance {A : CommBialgCat.{u} R} [IsCocomm R A] :
IsCommMonObj ((commBialgCatEquivComonCommAlgCat R).functor.obj A).unop.X :=
inferInstanceAs <| IsCommMonObj <| op <| CommAlgCat.of R A |
.lake/packages/mathlib/Mathlib/Algebra/Category/BoolRing.lean | import Mathlib.Algebra.Category.Ring.Basic
import Mathlib.Algebra.Ring.BooleanRing
import Mathlib.Order.Category.BoolAlg
/-!
# The category of Boolean rings
This file defines `BoolRing`, the category of Boolean rings.
## TODO
Finish the equivalence with `BoolAlg`.
-/
universe u
open CategoryTheory Order
/-- The category of Boolean rings. -/
structure BoolRing where
/-- Construct a bundled `BoolRing` from a `BooleanRing`. -/
of ::
/-- The underlying type. -/
carrier : Type u
[booleanRing : BooleanRing carrier]
namespace BoolRing
initialize_simps_projections BoolRing (-booleanRing)
instance : CoeSort BoolRing Type* :=
⟨carrier⟩
attribute [coe] carrier
attribute [instance] booleanRing
theorem coe_of (α : Type*) [BooleanRing α] : ↥(of α) = α :=
rfl
instance : Inhabited BoolRing :=
⟨of PUnit⟩
variable {R} in
/-- The type of morphisms in `BoolRing`. -/
@[ext]
structure Hom (R S : BoolRing) where
private mk ::
/-- The underlying ring hom. -/
hom' : R →+* S
instance : Category BoolRing where
Hom R S := Hom R S
id R := ⟨RingHom.id R⟩
comp f g := ⟨g.hom'.comp f.hom'⟩
instance : ConcreteCategory BoolRing (· →+* ·) where
hom f := f.hom'
ofHom f := ⟨f⟩
/-- Turn a morphism in `BoolRing` back into a `RingHom`. -/
abbrev Hom.hom {X Y : BoolRing} (f : Hom X Y) :=
ConcreteCategory.hom (C := BoolRing) f
/-- Typecheck a `RingHom` as a morphism in `BoolRing`. -/
abbrev ofHom {R S : Type u} [BooleanRing R] [BooleanRing S] (f : R →+* S) : of R ⟶ of S :=
ConcreteCategory.ofHom f
@[ext]
lemma hom_ext {R S : BoolRing} {f g : R ⟶ S} (hf : f.hom = g.hom) : f = g :=
Hom.ext hf
instance hasForgetToCommRing : HasForget₂ BoolRing CommRingCat where
forget₂ :=
{ obj := fun R ↦ CommRingCat.of R
map := fun f ↦ CommRingCat.ofHom f.hom }
/-- Constructs an isomorphism of Boolean rings from a ring isomorphism between them. -/
@[simps]
def Iso.mk {α β : BoolRing.{u}} (e : α ≃+* β) : α ≅ β where
hom := ⟨e⟩
inv := ⟨e.symm⟩
hom_inv_id := by ext; exact e.symm_apply_apply _
inv_hom_id := by ext; exact e.apply_symm_apply _
end BoolRing
/-! ### Equivalence between `BoolAlg` and `BoolRing` -/
-- We have to add this instance since Lean doesn't see through `X.toBddDistLat`.
instance {X : BoolAlg} :
BooleanAlgebra ↑(BddDistLat.toBddLat (X.toBddDistLat)).toLat :=
BoolAlg.str _
-- We have to add this instance since Lean doesn't see through `R.toBddDistLat`.
instance {R : Type u} [BooleanRing R] :
BooleanRing (BoolAlg.of (AsBoolAlg ↑R)).toBddDistLat.toBddLat.toLat :=
inferInstanceAs <| BooleanRing R
@[simps]
instance BoolRing.hasForgetToBoolAlg : HasForget₂ BoolRing BoolAlg where
forget₂.obj X := .of (AsBoolAlg X)
forget₂.map f := BoolAlg.ofHom f.hom.asBoolAlg
@[simps]
instance BoolAlg.hasForgetToBoolRing : HasForget₂ BoolAlg BoolRing where
forget₂.obj X := .of (AsBoolRing X)
forget₂.map f := BoolRing.ofHom <| BoundedLatticeHom.asBoolRing f.hom
/-- The equivalence between Boolean rings and Boolean algebras. This is actually an isomorphism. -/
@[simps functor inverse]
def boolRingCatEquivBoolAlg : BoolRing ≌ BoolAlg where
functor := forget₂ BoolRing BoolAlg
inverse := forget₂ BoolAlg BoolRing
unitIso := NatIso.ofComponents (fun X => BoolRing.Iso.mk <|
(RingEquiv.asBoolRingAsBoolAlg X).symm) fun {_ _} _ => rfl
counitIso := NatIso.ofComponents (fun X => BoolAlg.Iso.mk <|
OrderIso.asBoolAlgAsBoolRing X) fun {_ _} _ => rfl |
.lake/packages/mathlib/Mathlib/Algebra/Category/GrpWithZero.lean | import Mathlib.Algebra.Category.MonCat.Basic
import Mathlib.Algebra.GroupWithZero.WithZero
import Mathlib.CategoryTheory.Category.Bipointed
/-!
# The category of groups with zero
This file defines `GrpWithZero`, the category of groups with zero.
-/
assert_not_exists Ring
universe u
open CategoryTheory
/-- The category of groups with zero. -/
structure GrpWithZero where
/-- Construct a bundled `GrpWithZero` from a `GroupWithZero`. -/
of ::
/-- The underlying group with zero. -/
carrier : Type*
[str : GroupWithZero carrier]
attribute [instance] GrpWithZero.str
namespace GrpWithZero
instance : CoeSort GrpWithZero Type* :=
⟨carrier⟩
instance : Inhabited GrpWithZero :=
⟨of (WithZero PUnit)⟩
instance : LargeCategory.{u} GrpWithZero where
Hom X Y := MonoidWithZeroHom X Y
id X := MonoidWithZeroHom.id X
comp f g := g.comp f
instance groupWithZeroConcreteCategory : ConcreteCategory GrpWithZero (MonoidWithZeroHom · ·) where
hom f := f
ofHom f := f
/-- Typecheck a `MonoidWithZeroHom` as a morphism in `GrpWithZero`. -/
abbrev ofHom {X Y : Type u} [GroupWithZero X] [GroupWithZero Y]
(f : MonoidWithZeroHom X Y) : of X ⟶ of Y :=
ConcreteCategory.ofHom f
@[simp]
lemma hom_id {X : GrpWithZero} : ConcreteCategory.hom (𝟙 X : X ⟶ X) = MonoidWithZeroHom.id X := rfl
@[simp]
lemma hom_comp {X Y Z : GrpWithZero} {f : X ⟶ Y} {g : Y ⟶ Z} :
ConcreteCategory.hom (f ≫ g) = g.comp f := rfl
lemma coe_id {X : GrpWithZero} : (𝟙 X : X → X) = id := rfl
lemma coe_comp {X Y Z : GrpWithZero} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl
@[simp] lemma forget_map {X Y : GrpWithZero} (f : X ⟶ Y) : (forget GrpWithZero).map f = f := rfl
instance hasForgetToBipointed : HasForget₂ GrpWithZero Bipointed where
forget₂ :=
{ obj := fun X => ⟨X, 0, 1⟩
map := fun f => ⟨f, f.map_zero', f.map_one'⟩ }
instance hasForgetToMon : HasForget₂ GrpWithZero MonCat where
forget₂ :=
{ obj := fun X => MonCat.of X
map := fun f => MonCat.ofHom f.toMonoidHom }
/-- Constructs an isomorphism of groups with zero from a group isomorphism between them. -/
@[simps]
def Iso.mk {α β : GrpWithZero.{u}} (e : α ≃* β) : α ≅ β where
hom := ofHom e
inv := ofHom e.symm
hom_inv_id := by
ext
exact e.symm_apply_apply _
inv_hom_id := by
ext
exact e.apply_symm_apply _
end GrpWithZero |
.lake/packages/mathlib/Mathlib/Algebra/Category/AlgebraCat/Symmetric.lean | import Mathlib.Algebra.Category.AlgCat.Monoidal
import Mathlib.Algebra.Category.ModuleCat.Monoidal.Symmetric
deprecated_module (since := "2025-05-11") |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/Yoneda.lean | import Mathlib.Algebra.Category.Grp.Basic
import Mathlib.Algebra.Group.Pi.Lemmas
import Mathlib.CategoryTheory.Yoneda
/-!
# Yoneda embeddings
This file defines a few Yoneda embeddings for the category of commutative groups.
-/
open CategoryTheory
universe u
/-- The `CommGrpCat`-valued coyoneda embedding. -/
@[to_additive (attr := simps) /-- The `AddCommGrpCat`-valued coyoneda embedding. -/]
def CommGrpCat.coyoneda : CommGrpCatᵒᵖ ⥤ CommGrpCat ⥤ CommGrpCat where
obj M := { obj N := of (M.unop →* N), map f := ofHom (.compHom f.hom) }
map f := { app N := ofHom (.compHom' f.unop.hom) }
/-- The `CommGrpCat`-valued coyoneda embedding composed with the forgetful functor is the usual
coyoneda embedding. -/
@[to_additive (attr := simps!)
/-- The `AddCommGrpCat`-valued coyoneda embedding composed with the forgetful functor is the usual
coyoneda embedding. -/]
def CommGrpCat.coyonedaForget :
coyoneda ⋙ (Functor.whiskeringRight _ _ _).obj (forget _) ≅ CategoryTheory.coyoneda :=
NatIso.ofComponents fun X ↦ NatIso.ofComponents fun Y ↦ { hom f := ofHom f, inv f := f.hom }
/-- The Hom bifunctor sending a type `X` and a commutative group `G` to the commutative group
`X → G` with pointwise operations.
This is also the coyoneda embedding of `Type` into `CommGrpCat`-valued presheaves of commutative
groups. -/
@[to_additive (attr := simps)
/-- The Hom bifunctor sending a type `X` and a commutative group `G` to the commutative group
`X → G` with pointwise operations.
This is also the coyoneda embedding of `Type` into `AddCommGrpCat`-valued presheaves of commutative
groups. -/]
def CommGrpCat.coyonedaType : (Type u)ᵒᵖ ⥤ CommGrpCat.{u} ⥤ CommGrpCat.{u} where
obj X := { obj G := of <| X.unop → G
map f := ofHom <| Pi.monoidHom fun i ↦ f.hom.comp <| Pi.evalMonoidHom _ i }
map f := { app G := ofHom <| Pi.monoidHom fun i ↦ Pi.evalMonoidHom _ <| f.unop i } |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/Biproducts.lean | import Mathlib.Algebra.Group.Pi.Lemmas
import Mathlib.Algebra.Category.Grp.Preadditive
import Mathlib.CategoryTheory.Preadditive.Biproducts
import Mathlib.Algebra.Category.Grp.Limits
import Mathlib.Tactic.CategoryTheory.Elementwise
/-!
# The category of abelian groups has finite biproducts
-/
open CategoryTheory
open CategoryTheory.Limits
universe w u
namespace AddCommGrpCat
-- As `AddCommGrpCat` is preadditive, and has all limits, it automatically has biproducts.
instance : HasBinaryBiproducts AddCommGrpCat :=
HasBinaryBiproducts.of_hasBinaryProducts
instance : HasFiniteBiproducts AddCommGrpCat :=
HasFiniteBiproducts.of_hasFiniteProducts
-- We now construct explicit limit data,
-- so we can compare the biproducts to the usual unbundled constructions.
/-- Construct limit data for a binary product in `AddCommGrpCat`, using
`AddCommGrpCat.of (G × H)`.
-/
@[simps! cone_pt isLimit_lift]
def binaryProductLimitCone (G H : AddCommGrpCat.{u}) : Limits.LimitCone (pair G H) where
cone := BinaryFan.mk (ofHom (AddMonoidHom.fst G H)) (ofHom (AddMonoidHom.snd G H))
isLimit := BinaryFan.IsLimit.mk _ (fun l r => ofHom (AddMonoidHom.prod l.hom r.hom))
(fun _ _ => rfl) (fun _ _ => rfl) (by cat_disch)
@[simp]
theorem binaryProductLimitCone_cone_π_app_left (G H : AddCommGrpCat.{u}) :
(binaryProductLimitCone G H).cone.π.app ⟨WalkingPair.left⟩ = ofHom (AddMonoidHom.fst G H) :=
rfl
@[simp]
theorem binaryProductLimitCone_cone_π_app_right (G H : AddCommGrpCat.{u}) :
(binaryProductLimitCone G H).cone.π.app ⟨WalkingPair.right⟩ = ofHom (AddMonoidHom.snd G H) :=
rfl
/-- We verify that the biproduct in `AddCommGrpCat` is isomorphic to
the Cartesian product of the underlying types:
-/
noncomputable def biprodIsoProd (G H : AddCommGrpCat.{u}) :
(G ⊞ H : AddCommGrpCat) ≅ AddCommGrpCat.of (G × H) :=
IsLimit.conePointUniqueUpToIso (BinaryBiproduct.isLimit G H) (binaryProductLimitCone G H).isLimit
@[simp, elementwise]
theorem biprodIsoProd_inv_comp_fst (G H : AddCommGrpCat.{u}) :
(biprodIsoProd G H).inv ≫ biprod.fst = ofHom (AddMonoidHom.fst G H) :=
IsLimit.conePointUniqueUpToIso_inv_comp _ _ (Discrete.mk WalkingPair.left)
@[simp, elementwise]
theorem biprodIsoProd_inv_comp_snd (G H : AddCommGrpCat.{u}) :
(biprodIsoProd G H).inv ≫ biprod.snd = ofHom (AddMonoidHom.snd G H) :=
IsLimit.conePointUniqueUpToIso_inv_comp _ _ (Discrete.mk WalkingPair.right)
namespace HasLimit
variable {J : Type w} (f : J → AddCommGrpCat.{max w u})
/-- The map from an arbitrary cone over an indexed family of abelian groups
to the Cartesian product of those groups.
-/
@[simps!]
def lift (s : Fan f) : s.pt ⟶ AddCommGrpCat.of (∀ j, f j) :=
ofHom
{ toFun x j := s.π.app ⟨j⟩ x
map_zero' := by
simp only [Functor.const_obj_obj, map_zero]
rfl
map_add' x y := by
simp only [Functor.const_obj_obj, map_add]
rfl }
/-- Construct limit data for a product in `AddCommGrpCat`, using
`AddCommGrpCat.of (∀ j, F.obj j)`.
-/
@[simps]
def productLimitCone : Limits.LimitCone (Discrete.functor f) where
cone :=
{ pt := AddCommGrpCat.of (∀ j, f j)
π := Discrete.natTrans fun j => ofHom <| Pi.evalAddMonoidHom (fun j => f j) j.as }
isLimit :=
{ lift := lift.{_, u} f
fac := fun _ _ => rfl
uniq := fun s m w => by
ext x j
exact CategoryTheory.congr_fun (w ⟨j⟩) x }
end HasLimit
open HasLimit
variable {J : Type} [Finite J]
/-- We verify that the biproduct we've just defined is isomorphic to the `AddCommGrpCat` structure
on the dependent function type.
-/
noncomputable def biproductIsoPi (f : J → AddCommGrpCat.{u}) :
(⨁ f : AddCommGrpCat) ≅ AddCommGrpCat.of (∀ j, f j) :=
IsLimit.conePointUniqueUpToIso (biproduct.isLimit f) (productLimitCone f).isLimit
@[simp, elementwise]
theorem biproductIsoPi_inv_comp_π (f : J → AddCommGrpCat.{u}) (j : J) :
(biproductIsoPi f).inv ≫ biproduct.π f j = ofHom (Pi.evalAddMonoidHom (fun j => f j) j) :=
IsLimit.conePointUniqueUpToIso_inv_comp _ _ (Discrete.mk j)
end AddCommGrpCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/CartesianMonoidal.lean | import Mathlib.Algebra.Category.Grp.Biproducts
import Mathlib.Algebra.Category.Grp.Zero
import Mathlib.Algebra.Ring.PUnit
import Mathlib.CategoryTheory.Monoidal.Types.Basic
/-!
# Chosen finite products in `GrpCat` and friends
-/
open CategoryTheory Limits MonoidalCategory
universe u
namespace GrpCat
/-- Construct limit data for a binary product in `GrpCat`, using `GrpCat.of (G × H)` -/
@[simps! cone_pt isLimit_lift]
def binaryProductLimitCone (G H : GrpCat.{u}) : LimitCone (pair G H) where
cone := BinaryFan.mk (ofHom (MonoidHom.fst G H)) (ofHom (MonoidHom.snd G H))
isLimit := BinaryFan.IsLimit.mk _ (fun l r => ofHom (MonoidHom.prod l.hom r.hom))
(fun _ _ => rfl) (fun _ _ => rfl) (by cat_disch)
/-- We choose `GrpCat.of (G × H)` as the product of `G` and `H` and `GrpCat.of PUnit` as
the terminal object. -/
noncomputable instance cartesianMonoidalCategoryGrp : CartesianMonoidalCategory GrpCat.{u} :=
.ofChosenFiniteProducts ⟨_, (isZero_of_subsingleton (GrpCat.of PUnit.{u + 1})).isTerminal⟩
fun G H ↦ binaryProductLimitCone G H
noncomputable instance : BraidedCategory GrpCat.{u} := .ofCartesianMonoidalCategory
noncomputable instance : (forget GrpCat.{u}).Braided := .ofChosenFiniteProducts _
theorem tensorObj_eq (G H : GrpCat.{u}) : (G ⊗ H) = of (G × H) := rfl
@[simp]
theorem μ_forget_apply {G H : GrpCat.{u}} (p : G) (q : H) :
Functor.LaxMonoidal.μ (forget GrpCat.{u}) G H (p, q) = (p, q) := by
apply Prod.ext
· exact congrFun (Functor.Monoidal.μ_fst (forget GrpCat.{u}) G H) (p, q)
· exact congrFun (Functor.Monoidal.μ_snd (forget GrpCat.{u}) G H) (p, q)
end GrpCat
namespace AddGrpCat
/-- Construct limit data for a binary product in `AddGrpCat`, using `AddGrpCat.of (G × H)` -/
@[simps! cone_pt isLimit_lift]
def binaryProductLimitCone (G H : AddGrpCat.{u}) : LimitCone (pair G H) where
cone := BinaryFan.mk (ofHom (AddMonoidHom.fst G H)) (ofHom (AddMonoidHom.snd G H))
isLimit := BinaryFan.IsLimit.mk _ (fun l r => ofHom (AddMonoidHom.prod l.hom r.hom))
(fun _ _ => rfl) (fun _ _ => rfl) (by cat_disch)
/-- We choose `AddGrpCat.of (G × H)` as the product of `G` and `H` and `AddGrpCat.of PUnit` as
the terminal object. -/
noncomputable instance cartesianMonoidalCategoryAddGrp : CartesianMonoidalCategory AddGrpCat.{u} :=
.ofChosenFiniteProducts ⟨_, (isZero_of_subsingleton (AddGrpCat.of PUnit.{u + 1})).isTerminal⟩
fun G H ↦ binaryProductLimitCone G H
noncomputable instance : BraidedCategory AddGrpCat.{u} := .ofCartesianMonoidalCategory
noncomputable instance : (forget AddGrpCat.{u}).Braided := .ofChosenFiniteProducts _
theorem tensorObj_eq (G H : AddGrpCat.{u}) : (G ⊗ H) = of (G × H) := rfl
@[simp]
theorem μ_forget_apply {G H : AddGrpCat.{u}} (p : G) (q : H) :
Functor.LaxMonoidal.μ (forget AddGrpCat.{u}) G H (p, q) = (p, q) := by
apply Prod.ext
· exact congrFun (Functor.Monoidal.μ_fst (forget AddGrpCat.{u}) G H) (p, q)
· exact congrFun (Functor.Monoidal.μ_snd (forget AddGrpCat.{u}) G H) (p, q)
end AddGrpCat
namespace CommGrpCat
/-- Construct limit data for a binary product in `CommGrpCat`, using `CommGrpCat.of (G × H)` -/
@[simps! cone_pt isLimit_lift]
def binaryProductLimitCone (G H : CommGrpCat.{u}) : LimitCone (pair G H) where
cone := BinaryFan.mk (ofHom (MonoidHom.fst G H)) (ofHom (MonoidHom.snd G H))
isLimit := BinaryFan.IsLimit.mk _ (fun l r => ofHom (MonoidHom.prod l.hom r.hom))
(fun _ _ => rfl) (fun _ _ => rfl) (by cat_disch)
/-- We choose `CommGrpCat.of (G × H)` as the product of `G` and `H` and `CommGrpCat.of PUnit` as
the terminal object. -/
noncomputable instance cartesianMonoidalCategory : CartesianMonoidalCategory CommGrpCat.{u} :=
.ofChosenFiniteProducts ⟨_, (isZero_of_subsingleton (CommGrpCat.of PUnit.{u + 1})).isTerminal⟩
fun G H ↦ binaryProductLimitCone G H
noncomputable instance : BraidedCategory CommGrpCat.{u} := .ofCartesianMonoidalCategory
noncomputable instance : (forget CommGrpCat.{u}).Braided := .ofChosenFiniteProducts _
theorem tensorObj_eq (G H : CommGrpCat.{u}) : (G ⊗ H) = of (G × H) := rfl
@[simp]
theorem μ_forget_apply {G H : CommGrpCat.{u}} (p : G) (q : H) :
Functor.LaxMonoidal.μ (forget CommGrpCat.{u}) G H (p, q) = (p, q) := by
apply Prod.ext
· exact congrFun (Functor.Monoidal.μ_fst (forget CommGrpCat.{u}) G H) (p, q)
· exact congrFun (Functor.Monoidal.μ_snd (forget CommGrpCat.{u}) G H) (p, q)
end CommGrpCat
namespace AddCommGrpCat
/-- We choose `AddCommGrpCat.of (G × H)` as the product of `G` and `H` and
`AddCommGrpCat.of PUnit` as the terminal object. -/
noncomputable def cartesianMonoidalCategory : CartesianMonoidalCategory AddCommGrpCat.{u} :=
.ofChosenFiniteProducts ⟨_, (isZero_of_subsingleton (AddCommGrpCat.of PUnit.{u + 1})).isTerminal⟩
fun G H ↦ binaryProductLimitCone G H
@[deprecated (since := "2025-10-10")]
alias cartesianMonoidalCategoryAddCommGrp := cartesianMonoidalCategory
@[deprecated (since := "2025-05-15")]
alias chosenFiniteProductsAddCommGrp := cartesianMonoidalCategory
attribute [local instance] cartesianMonoidalCategory
noncomputable instance : BraidedCategory AddCommGrpCat.{u} := .ofCartesianMonoidalCategory
noncomputable instance : (forget AddCommGrpCat.{u}).Braided := .ofChosenFiniteProducts _
theorem tensorObj_eq (G H : AddCommGrpCat.{u}) : (G ⊗ H) = of (G × H) := rfl
@[simp]
theorem μ_forget_apply {G H : AddCommGrpCat.{u}} (p : G) (q : H) :
Functor.LaxMonoidal.μ (forget AddCommGrpCat.{u}) G H (p, q) = (p, q) := by
apply Prod.ext
· exact congrFun (Functor.Monoidal.μ_fst (forget AddCommGrpCat.{u}) G H) (p, q)
· exact congrFun (Functor.Monoidal.μ_snd (forget AddCommGrpCat.{u}) G H) (p, q)
end AddCommGrpCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/EpiMono.lean | import Mathlib.Algebra.Category.Grp.EquivalenceGroupAddGroup
import Mathlib.CategoryTheory.ConcreteCategory.EpiMono
import Mathlib.CategoryTheory.Limits.Constructions.EpiMono
import Mathlib.GroupTheory.Coset.Basic
import Mathlib.GroupTheory.QuotientGroup.Defs
/-!
# Monomorphisms and epimorphisms in `Group`
In this file, we prove monomorphisms in the category of groups are injective homomorphisms and
epimorphisms are surjective homomorphisms.
-/
noncomputable section
open scoped Pointwise
universe u v
namespace MonoidHom
open QuotientGroup
variable {A : Type u} {B : Type v}
section
variable [Group A] [Group B]
@[to_additive]
theorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :
f.ker = ⊥ := by simpa using congr_arg range (h f.ker.subtype 1 (by cat_disch))
end
section
variable [CommGroup A] [CommGroup B]
@[to_additive]
theorem range_eq_top_of_cancel {f : A →* B}
(h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by
specialize h 1 (QuotientGroup.mk' _) _
· ext1 x
simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]
rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,
one_mul]
exact ⟨x, rfl⟩
replace h : (QuotientGroup.mk' f.range).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]
rwa [ker_one, QuotientGroup.ker_mk'] at h
end
end MonoidHom
section
open CategoryTheory
namespace GrpCat
variable {A B : GrpCat.{u}} (f : A ⟶ B)
@[to_additive]
theorem ker_eq_bot_of_mono [Mono f] : f.hom.ker = ⊥ :=
MonoidHom.ker_eq_bot_of_cancel fun u v h => ConcreteCategory.ext_iff.mp <|
(@cancel_mono _ _ _ _ _ f _ (ofHom u) (ofHom v)).1 <| ConcreteCategory.ext h
@[to_additive]
theorem mono_iff_ker_eq_bot : Mono f ↔ f.hom.ker = ⊥ :=
⟨fun _ => ker_eq_bot_of_mono f, fun h =>
ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f.hom).1 h⟩
@[to_additive]
theorem mono_iff_injective : Mono f ↔ Function.Injective f :=
Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f.hom
namespace SurjectiveOfEpiAuxs
local notation3 "X" => Set.range (· • (f.hom.range : Set B) : B → Set B)
/-- Define `X'` to be the set of all left cosets with an extra point at "infinity".
-/
inductive XWithInfinity
| fromCoset : X → XWithInfinity
| infinity : XWithInfinity
open XWithInfinity Equiv.Perm
local notation "X'" => XWithInfinity f
local notation "∞" => XWithInfinity.infinity
local notation "SX'" => Equiv.Perm X'
instance : SMul B X' where
smul b x :=
match x with
| fromCoset y => fromCoset ⟨b • y, by
rw [← y.2.choose_spec, leftCoset_assoc]
let b' : B := y.2.choose
use b * b'⟩
| ∞ => ∞
theorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=
match x with
| fromCoset y => by
change fromCoset _ = fromCoset _
simp only [leftCoset_assoc]
| ∞ => rfl
theorem one_smul (x : X') : (1 : B) • x = x :=
match x with
| fromCoset y => by
change fromCoset _ = fromCoset _
simp only [one_leftCoset]
| ∞ => rfl
theorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.hom.range) :
fromCoset ⟨b • ↑f.hom.range, b, rfl⟩ = fromCoset ⟨f.hom.range, 1, one_leftCoset _⟩ := by
congr
nth_rw 2 [show (f.hom.range : Set B) = (1 : B) • f.hom.range from (one_leftCoset _).symm]
rw [leftCoset_eq_iff, mul_one]
exact Subgroup.inv_mem _ hb
example (G : Type) [Group G] (S : Subgroup G) : Set G := S
theorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.hom.range) :
fromCoset ⟨b • ↑f.hom.range, b, rfl⟩ ≠ fromCoset ⟨f.hom.range, 1, one_leftCoset _⟩ := by
intro r
simp only [fromCoset.injEq, Subtype.mk.injEq] at r
nth_rw 2 [show (f.hom.range : Set B) = (1 : B) • f.hom.range from (one_leftCoset _).symm] at r
rw [leftCoset_eq_iff, mul_one] at r
exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)
instance : DecidableEq X' :=
Classical.decEq _
/-- Let `τ` be the permutation on `X'` exchanging `f.hom.range` and the point at infinity.
-/
noncomputable def tau : SX' :=
Equiv.swap (fromCoset ⟨↑f.hom.range, ⟨1, one_leftCoset _⟩⟩) ∞
local notation "τ" => tau f
theorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.hom.range, 1, one_leftCoset _⟩ :=
Equiv.swap_apply_right _ _
theorem τ_apply_fromCoset : τ (fromCoset ⟨f.hom.range, 1, one_leftCoset _⟩) = ∞ :=
Equiv.swap_apply_left _ _
theorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.hom.range) :
τ (fromCoset ⟨x • ↑f.hom.range, ⟨x, rfl⟩⟩) = ∞ :=
(fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _
theorem τ_symm_apply_fromCoset :
Equiv.symm τ (fromCoset ⟨f.hom.range, 1, one_leftCoset _⟩) = ∞ := by
rw [tau, Equiv.symm_swap, Equiv.swap_apply_left]
theorem τ_symm_apply_infinity :
Equiv.symm τ ∞ = fromCoset ⟨f.hom.range, 1, one_leftCoset _⟩ := by
rw [tau, Equiv.symm_swap, Equiv.swap_apply_right]
/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending
point at infinity to point at infinity and sending coset `y` to `β • y`.
-/
def g : B →* SX' where
toFun β :=
{ toFun := fun x => β • x
invFun := fun x => β⁻¹ • x
left_inv := fun x => by
dsimp only
rw [← mul_smul, inv_mul_cancel, one_smul]
right_inv := fun x => by
dsimp only
rw [← mul_smul, mul_inv_cancel, one_smul] }
map_one' := by
ext
simp [one_smul]
map_mul' b1 b2 := by
ext
simp [mul_smul]
local notation "g" => g f
/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`
-/
def h : B →* SX' where
toFun β := ((τ).symm.trans (g β)).trans τ
map_one' := by
ext
simp
map_mul' b1 b2 := by
ext
simp
local notation "h" => h f
/-!
The strategy is the following: assuming `epi f`
* prove that `f.hom.range = {x | h x = g x}`;
* thus `f ≫ h = f ≫ g` so that `h = g`;
* but if `f` is not surjective, then some `x ∉ f.hom.range`, then `h x ≠ g x` at the coset
`f.hom.range`.
-/
theorem g_apply_fromCoset (x : B) (y : X) :
g x (fromCoset y) = fromCoset ⟨x • ↑y,
by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl
theorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl
theorem h_apply_infinity (x : B) (hx : x ∈ f.hom.range) : (h x) ∞ = ∞ := by
change ((τ).symm.trans (g x)).trans τ _ = _
simp only [Equiv.coe_trans, Function.comp_apply]
rw [τ_symm_apply_infinity, g_apply_fromCoset]
simpa only using τ_apply_fromCoset' f x hx
theorem h_apply_fromCoset (x : B) :
(h x) (fromCoset ⟨f.hom.range, 1, one_leftCoset _⟩) =
fromCoset ⟨f.hom.range, 1, one_leftCoset _⟩ := by
change ((τ).symm.trans (g x)).trans τ _ = _
simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]
theorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.hom.range) :
h x (fromCoset ⟨b • f.hom.range, b, rfl⟩) = fromCoset ⟨b • ↑f.hom.range, b, rfl⟩ :=
(fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x
theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.hom.range) (b : B) (hb : b ∉ f.hom.range) :
h x (fromCoset ⟨b • f.hom.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.hom.range, x * b, rfl⟩ := by
change ((τ).symm.trans (g x)).trans τ _ = _
simp only [tau, Equiv.coe_trans, Function.comp_apply]
rw [Equiv.symm_swap,
@Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.hom.range, 1, one_leftCoset _⟩) ∞
(fromCoset ⟨b • ↑f.hom.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]
simp only [g_apply_fromCoset, leftCoset_assoc]
refine Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb ?_) (by simp)
convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r
rw [← mul_assoc, inv_mul_cancel, one_mul]
theorem agree : f.hom.range = { x | h x = g x } := by
refine Set.ext fun b => ⟨?_, fun hb : h b = g b => by_contradiction fun r => ?_⟩
· rintro ⟨a, rfl⟩
change h (f a) = g (f a)
ext ⟨⟨_, ⟨y, rfl⟩⟩⟩
· rw [g_apply_fromCoset]
by_cases m : y ∈ f.hom.range
· rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]
change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩
simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]
· rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]
simp only [leftCoset_assoc]
· rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]
· have eq1 : (h b) (fromCoset ⟨f.hom.range, 1, one_leftCoset _⟩) =
fromCoset ⟨f.hom.range, 1, one_leftCoset _⟩ := by
change ((τ).symm.trans (g b)).trans τ _ = _
dsimp [tau]
simp [g_apply_infinity f]
have eq2 :
g b (fromCoset ⟨f.hom.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.hom.range, b, rfl⟩ :=
rfl
exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, DFunLike.congr_fun hb])
theorem comp_eq : (f ≫ ofHom g) = f ≫ ofHom h := by
ext a
simp only [hom_comp, hom_ofHom, MonoidHom.coe_comp, Function.comp_apply]
have : f a ∈ { b | h b = g b } := by
rw [← agree]
use a
rw [this]
theorem g_ne_h (x : B) (hx : x ∉ f.hom.range) : g ≠ h := by
intro r
apply fromCoset_ne_of_nin_range _ hx
replace r :=
DFunLike.congr_fun (DFunLike.congr_fun r x) (fromCoset ⟨f.hom.range, ⟨1, one_leftCoset _⟩⟩)
simpa [g_apply_fromCoset, «h», tau, g_apply_infinity] using r
end SurjectiveOfEpiAuxs
theorem surjective_of_epi [Epi f] : Function.Surjective f := by
dsimp [Function.Surjective]
by_contra! r; rcases r with ⟨b, hb⟩
exact
SurjectiveOfEpiAuxs.g_ne_h f b (fun ⟨c, hc⟩ => hb _ hc)
(congr_arg GrpCat.Hom.hom ((cancel_epi f).1 (SurjectiveOfEpiAuxs.comp_eq f)))
theorem epi_iff_surjective : Epi f ↔ Function.Surjective f :=
⟨fun _ => surjective_of_epi f, ConcreteCategory.epi_of_surjective f⟩
theorem epi_iff_range_eq_top : Epi f ↔ f.hom.range = ⊤ :=
Iff.trans (epi_iff_surjective _) (Subgroup.eq_top_iff' f.hom.range).symm
end GrpCat
namespace AddGrpCat
variable {A B : AddGrpCat.{u}} (f : A ⟶ B)
theorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by
have i1 : Epi f ↔ Epi (groupAddGroupEquivalence.inverse.map f) := by
refine ⟨?_, groupAddGroupEquivalence.inverse.epi_of_epi_map⟩
intro e'
apply groupAddGroupEquivalence.inverse.map_epi
rwa [GrpCat.epi_iff_surjective] at i1
theorem epi_iff_range_eq_top : Epi f ↔ f.hom.range = ⊤ :=
Iff.trans (epi_iff_surjective _) (AddSubgroup.eq_top_iff' f.hom.range).symm
end AddGrpCat
namespace GrpCat
variable {A B : GrpCat.{u}} (f : A ⟶ B)
@[to_additive AddGrpCat.forget_grp_preserves_mono]
instance forget_grp_preserves_mono : (forget GrpCat).PreservesMonomorphisms where
preserves f e := by rwa [mono_iff_injective, ← CategoryTheory.mono_iff_injective] at e
@[to_additive AddGrpCat.forget_grp_preserves_epi]
instance forget_grp_preserves_epi : (forget GrpCat).PreservesEpimorphisms where
preserves f e := by rwa [epi_iff_surjective, ← CategoryTheory.epi_iff_surjective] at e
end GrpCat
namespace CommGrpCat
variable {A B : CommGrpCat.{u}} (f : A ⟶ B)
@[to_additive]
theorem ker_eq_bot_of_mono [Mono f] : f.hom.ker = ⊥ :=
MonoidHom.ker_eq_bot_of_cancel fun u v h => ConcreteCategory.ext_iff.mp <|
(@cancel_mono _ _ _ _ _ f _ (ofHom u) (ofHom v)).1 <| ConcreteCategory.ext h
@[to_additive]
theorem mono_iff_ker_eq_bot : Mono f ↔ f.hom.ker = ⊥ :=
⟨fun _ => ker_eq_bot_of_mono f, fun h =>
ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f.hom).1 h⟩
@[to_additive]
theorem mono_iff_injective : Mono f ↔ Function.Injective f :=
Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f.hom
@[to_additive]
theorem range_eq_top_of_epi [Epi f] : f.hom.range = ⊤ :=
MonoidHom.range_eq_top_of_cancel fun u v h => ConcreteCategory.ext_iff.mp <|
(@cancel_epi _ _ _ _ _ f _ (ofHom u) (ofHom v)).1 (ConcreteCategory.ext h)
@[to_additive]
theorem epi_iff_range_eq_top : Epi f ↔ f.hom.range = ⊤ :=
⟨fun _ => range_eq_top_of_epi _, fun hf =>
ConcreteCategory.epi_of_surjective _ <| show Function.Surjective f.hom from
MonoidHom.range_eq_top.mp hf⟩
@[to_additive]
theorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by
rw [epi_iff_range_eq_top, MonoidHom.range_eq_top]
@[to_additive AddCommGrpCat.forget_commGrp_preserves_mono]
instance forget_commGrp_preserves_mono : (forget CommGrpCat).PreservesMonomorphisms where
preserves f e := by rwa [mono_iff_injective, ← CategoryTheory.mono_iff_injective] at e
@[to_additive AddCommGrpCat.forget_commGrp_preserves_epi]
instance forget_commGrp_preserves_epi : (forget CommGrpCat).PreservesEpimorphisms where
preserves f e := by rwa [epi_iff_surjective, ← CategoryTheory.epi_iff_surjective] at e
end CommGrpCat
end |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/IsFinite.lean | import Mathlib.Algebra.Category.Grp.Abelian
import Mathlib.Algebra.Category.Grp.EpiMono
import Mathlib.Algebra.Category.Grp.Zero
import Mathlib.Algebra.Homology.ShortComplex.Ab
import Mathlib.CategoryTheory.Abelian.SerreClass.Basic
import Mathlib.Data.Finite.Prod
/-!
# The Serre class of finite abelian groups
In this file, we define `isFinite : ObjectProperty AddCommGrpCat` and show
that it is a Serre class.
-/
universe u
open CategoryTheory Limits ZeroObject
namespace AddCommGrpCat
/-- The Serre class of finite abelian groups
in the category of abelian groups. -/
def isFinite : ObjectProperty AddCommGrpCat.{u} :=
fun M ↦ Finite M
@[simp]
lemma prop_isFinite_iff (M : AddCommGrpCat.{u}) : isFinite M ↔ Finite M := Iff.rfl
instance : isFinite.{u}.IsSerreClass where
exists_zero := ⟨.of PUnit, isZero_of_subsingleton _,
by rw [prop_isFinite_iff]; infer_instance⟩
prop_of_mono {M N} f hf hN := by
rw [AddCommGrpCat.mono_iff_injective] at hf
simp only [prop_isFinite_iff] at hN ⊢
exact Finite.of_injective _ hf
prop_of_epi {M N} f hf hM := by
rw [AddCommGrpCat.epi_iff_surjective] at hf
simp only [prop_isFinite_iff] at hM ⊢
exact Finite.of_surjective _ hf
prop_X₂_of_shortExact {S} hS h₁ h₃ := by
simp only [prop_isFinite_iff] at h₁ h₃ ⊢
have hg := hS.epi_g
rw [AddCommGrpCat.epi_iff_surjective] at hg
obtain ⟨s, hs⟩ := hg.hasRightInverse
have hφ : Function.Surjective (fun (x₁, x₃) ↦ S.f x₁ + s x₃) := fun x₂ ↦ by
obtain ⟨x₁, hx₁⟩ := (ShortComplex.ab_exact_iff S).1 hS.exact (x₂ - s (S.g x₂))
(by simp [hs (S.g x₂)])
exact ⟨⟨x₁, S.g x₂⟩, by simp [hx₁]⟩
exact Finite.of_surjective _ hφ
end AddCommGrpCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/Abelian.lean | import Mathlib.Algebra.Category.Grp.Colimits
import Mathlib.Algebra.Category.Grp.Limits
import Mathlib.Algebra.Category.Grp.ZModuleEquivalence
import Mathlib.Algebra.Category.ModuleCat.Abelian
import Mathlib.CategoryTheory.Adjunction.Limits
import Mathlib.CategoryTheory.Limits.ConcreteCategory.Basic
/-!
# The category of abelian groups is abelian
-/
open CategoryTheory Limits
universe u
noncomputable section
namespace AddCommGrpCat
variable {X Y Z : AddCommGrpCat.{u}} (f : X ⟶ Y) (g : Y ⟶ Z)
/-- In the category of abelian groups, every monomorphism is normal. -/
def normalMono (_ : Mono f) : NormalMono f :=
equivalenceReflectsNormalMono (forget₂ (ModuleCat.{u} ℤ) AddCommGrpCat.{u}).inv <|
ModuleCat.normalMono _ inferInstance
/-- In the category of abelian groups, every epimorphism is normal. -/
def normalEpi (_ : Epi f) : NormalEpi f :=
equivalenceReflectsNormalEpi (forget₂ (ModuleCat.{u} ℤ) AddCommGrpCat.{u}).inv <|
ModuleCat.normalEpi _ inferInstance
/-- The category of abelian groups is abelian. -/
instance : Abelian AddCommGrpCat.{u} where
normalMonoOfMono f hf := ⟨normalMono f hf⟩
normalEpiOfEpi f hf := ⟨normalEpi f hf⟩
end AddCommGrpCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/EnoughInjectives.lean | import Mathlib.Algebra.Module.CharacterModule
import Mathlib.Algebra.Category.Grp.EquivalenceGroupAddGroup
import Mathlib.Algebra.Category.Grp.EpiMono
import Mathlib.Algebra.Category.Grp.Injective
/-!
# Category of abelian groups has enough injectives
Given an abelian group `A`, then `i : A ⟶ ∏_{A⋆} ℚ ⧸ ℤ` defined by `i : a ↦ c ↦ c a` is an
injective presentation for `A`, hence category of abelian groups has enough injectives.
## Main results
- `AddCommGrpCat.enoughInjectives` : the category of abelian groups (written additively) has
enough injectives.
- `CommGrpCat.enoughInjectives` : the category of abelian groups (written multiplicatively) has
enough injectives.
## Implementation notes
This file is split from `Mathlib/Algebra/Category/GrpCat/Injective.lean` to prevent import loops.
-/
open CategoryTheory
universe u
namespace AddCommGrpCat
open CharacterModule
instance enoughInjectives : EnoughInjectives AddCommGrpCat.{u} where
presentation A_ := Nonempty.intro
{ J := of <| (CharacterModule A_) → ULift.{u} (AddCircle (1 : ℚ))
injective := injective_of_divisible _
f := ofHom ⟨⟨fun a i ↦ ULift.up (i a), by aesop⟩, by aesop⟩
mono := (AddCommGrpCat.mono_iff_injective _).mpr <| (injective_iff_map_eq_zero _).mpr
fun _ h0 ↦ eq_zero_of_character_apply (congr_arg ULift.down <| congr_fun h0 ·) }
end AddCommGrpCat
namespace CommGrpCat
instance enoughInjectives : EnoughInjectives CommGrpCat.{u} :=
EnoughInjectives.of_equivalence commGroupAddCommGroupEquivalence.functor
end CommGrpCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/FiniteGrp.lean | import Mathlib.Data.Finite.Defs
import Mathlib.Algebra.Category.Grp.Basic
/-!
## Main definitions and results
* `FiniteGrp` is the category of finite groups.
-/
universe u v
open CategoryTheory
/-- The category of finite groups. -/
@[pp_with_univ]
structure FiniteGrp where
/-- A group that is finite -/
toGrp : GrpCat
[isFinite : Finite toGrp]
/-- The category of finite additive groups. -/
@[pp_with_univ]
structure FiniteAddGrp where
/-- An additive group that is finite -/
toAddGrp : AddGrpCat
[isFinite : Finite toAddGrp]
attribute [to_additive] FiniteGrp
namespace FiniteGrp
@[to_additive]
instance : CoeSort FiniteGrp.{u} (Type u) where
coe G := G.toGrp
@[to_additive]
instance : Category FiniteGrp := InducedCategory.category FiniteGrp.toGrp
@[to_additive]
instance : ConcreteCategory FiniteGrp (· →* ·) := InducedCategory.concreteCategory FiniteGrp.toGrp
@[to_additive]
instance (G : FiniteGrp) : Group G := inferInstanceAs <| Group G.toGrp
@[to_additive]
instance (G : FiniteGrp) : Finite G := G.isFinite
/-- Construct a term of `FiniteGrp` from a type endowed with the structure of a finite group. -/
@[to_additive /-- Construct a term of `FiniteAddGrp` from a type endowed with the structure of a
finite additive group. -/]
def of (G : Type u) [Group G] [Finite G] : FiniteGrp where
toGrp := GrpCat.of G
isFinite := ‹_›
/-- The morphism in `FiniteGrp`, induced from a morphism of the category `GrpCat`. -/
@[to_additive
/-- The morphism in `FiniteAddGrp`, induced from a morphism of the category `AddGrpCat` -/]
def ofHom {X Y : Type u} [Group X] [Finite X] [Group Y] [Finite Y] (f : X →* Y) : of X ⟶ of Y :=
GrpCat.ofHom f
@[to_additive]
lemma ofHom_apply {X Y : Type u} [Group X] [Finite X] [Group Y] [Finite Y] (f : X →* Y) (x : X) :
ofHom f x = f x :=
rfl
end FiniteGrp |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/Preadditive.lean | import Mathlib.Algebra.Category.Grp.Basic
import Mathlib.CategoryTheory.Preadditive.Basic
/-!
# The category of additive commutative groups is preadditive.
-/
assert_not_exists Subgroup
open CategoryTheory
universe u
namespace AddCommGrpCat
variable {M N : AddCommGrpCat.{u}}
instance : Add (M ⟶ N) where
add f g := ofHom (f.hom + g.hom)
@[simp] lemma hom_add (f g : M ⟶ N) : (f + g).hom = f.hom + g.hom := rfl
lemma hom_add_apply {P Q : AddCommGrpCat} (f g : P ⟶ Q) (x : P) : (f + g) x = f x + g x := rfl
instance : Zero (M ⟶ N) where
zero := ofHom 0
@[simp] lemma hom_zero : (0 : M ⟶ N).hom = 0 := rfl
instance : SMul ℕ (M ⟶ N) where
smul n f := ofHom (n • f.hom)
@[simp] lemma hom_nsmul (n : ℕ) (f : M ⟶ N) : (n • f).hom = n • f.hom := rfl
instance : Neg (M ⟶ N) where
neg f := ofHom (-f.hom)
@[simp] lemma hom_neg (f : M ⟶ N) : (-f).hom = -f.hom := rfl
instance : Sub (M ⟶ N) where
sub f g := ofHom (f.hom - g.hom)
@[simp] lemma hom_sub (f g : M ⟶ N) : (f - g).hom = f.hom - g.hom := rfl
instance : SMul ℤ (M ⟶ N) where
smul n f := ofHom (n • f.hom)
@[simp] lemma hom_zsmul (n : ℕ) (f : M ⟶ N) : (n • f).hom = n • f.hom := rfl
instance (P Q : AddCommGrpCat) : AddCommGroup (P ⟶ Q) :=
Function.Injective.addCommGroup (Hom.hom) ConcreteCategory.hom_injective
rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
instance : Preadditive AddCommGrpCat where
/-- `AddCommGrpCat.Hom.hom` bundled as an additive equivalence. -/
@[simps!]
def homAddEquiv : (M ⟶ N) ≃+ (M →+ N) :=
{ ConcreteCategory.homEquiv (C := AddCommGrpCat) with
map_add' _ _ := rfl }
end AddCommGrpCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/Basic.lean | import Mathlib.Algebra.Category.MonCat.Basic
import Mathlib.Algebra.Group.End
import Mathlib.CategoryTheory.Endomorphism
import Mathlib.Data.Int.Cast.Lemmas
/-!
# Category instances for Group, AddGroup, CommGroup, and AddCommGroup.
We introduce the bundled categories:
* `GrpCat`
* `AddGrpCat`
* `CommGrpCat`
* `AddCommGrpCat`
along with the relevant forgetful functors between them, and to the bundled monoid categories.
-/
universe u v
open CategoryTheory
/-- The category of additive groups and group morphisms. -/
structure AddGrpCat : Type (u + 1) where
/-- The underlying type. -/
(carrier : Type u)
[str : AddGroup carrier]
/-- The category of groups and group morphisms. -/
@[to_additive]
structure GrpCat : Type (u + 1) where
/-- The underlying type. -/
(carrier : Type u)
[str : Group carrier]
attribute [instance] AddGrpCat.str GrpCat.str
initialize_simps_projections AddGrpCat (carrier → coe, -str)
initialize_simps_projections GrpCat (carrier → coe, -str)
namespace GrpCat
@[to_additive]
instance : CoeSort GrpCat (Type u) :=
⟨GrpCat.carrier⟩
attribute [coe] AddGrpCat.carrier GrpCat.carrier
/-- Construct a bundled `GrpCat` from the underlying type and typeclass. -/
@[to_additive /-- Construct a bundled `AddGrpCat` from the underlying type and typeclass. -/]
abbrev of (M : Type u) [Group M] : GrpCat := ⟨M⟩
end GrpCat
/-- The type of morphisms in `AddGrpCat R`. -/
@[ext]
structure AddGrpCat.Hom (A B : AddGrpCat.{u}) where
private mk ::
/-- The underlying monoid homomorphism. -/
hom' : A →+ B
/-- The type of morphisms in `GrpCat R`. -/
@[to_additive, ext]
structure GrpCat.Hom (A B : GrpCat.{u}) where
private mk ::
/-- The underlying monoid homomorphism. -/
hom' : A →* B
namespace GrpCat
@[to_additive]
instance : Category GrpCat.{u} where
Hom X Y := Hom X Y
id X := ⟨MonoidHom.id X⟩
comp f g := ⟨g.hom'.comp f.hom'⟩
@[to_additive]
instance : ConcreteCategory GrpCat (· →* ·) where
hom := Hom.hom'
ofHom := Hom.mk
/-- Turn a morphism in `GrpCat` back into a `MonoidHom`. -/
@[to_additive /-- Turn a morphism in `AddGrpCat` back into an `AddMonoidHom`. -/]
abbrev Hom.hom {X Y : GrpCat.{u}} (f : Hom X Y) :=
ConcreteCategory.hom (C := GrpCat) f
/-- Typecheck a `MonoidHom` as a morphism in `GrpCat`. -/
@[to_additive /-- Typecheck an `AddMonoidHom` as a morphism in `AddGrpCat`. -/]
abbrev ofHom {X Y : Type u} [Group X] [Group Y] (f : X →* Y) : of X ⟶ of Y :=
ConcreteCategory.ofHom (C := GrpCat) f
variable {R} in
/-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/
def Hom.Simps.hom (X Y : GrpCat.{u}) (f : Hom X Y) :=
f.hom
initialize_simps_projections Hom (hom' → hom)
initialize_simps_projections AddGrpCat.Hom (hom' → hom)
/-!
The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`.
-/
@[to_additive (attr := simp)]
lemma coe_id {X : GrpCat} : (𝟙 X : X → X) = id := rfl
@[to_additive (attr := simp)]
lemma coe_comp {X Y Z : GrpCat} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl
@[simp] lemma forget_map {X Y : GrpCat} (f : X ⟶ Y) : (forget GrpCat).map f = (f : X → Y) := rfl
@[to_additive (attr := ext)]
lemma ext {X Y : GrpCat} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g :=
ConcreteCategory.hom_ext _ _ w
@[to_additive]
-- This is not `simp` to avoid rewriting in types of terms.
theorem coe_of (R : Type u) [Group R] : ↑(GrpCat.of R) = R :=
rfl
@[to_additive (attr := simp)]
lemma hom_id {X : GrpCat} : (𝟙 X : X ⟶ X).hom = MonoidHom.id X := rfl
/- Provided for rewriting. -/
@[to_additive]
lemma id_apply (X : GrpCat) (x : X) :
(𝟙 X : X ⟶ X) x = x := by simp
@[to_additive (attr := simp)]
lemma hom_comp {X Y T : GrpCat} (f : X ⟶ Y) (g : Y ⟶ T) :
(f ≫ g).hom = g.hom.comp f.hom := rfl
/- Provided for rewriting. -/
@[to_additive]
lemma comp_apply {X Y T : GrpCat} (f : X ⟶ Y) (g : Y ⟶ T) (x : X) :
(f ≫ g) x = g (f x) := by simp
@[to_additive (attr := ext)]
lemma hom_ext {X Y : GrpCat} {f g : X ⟶ Y} (hf : f.hom = g.hom) : f = g :=
Hom.ext hf
@[to_additive (attr := simp)]
lemma hom_ofHom {R S : Type u} [Group R] [Group S] (f : R →* S) : (ofHom f).hom = f := rfl
@[to_additive (attr := simp)]
lemma ofHom_hom {X Y : GrpCat} (f : X ⟶ Y) :
ofHom (Hom.hom f) = f := rfl
@[to_additive (attr := simp)]
lemma ofHom_id {X : Type u} [Group X] : ofHom (MonoidHom.id X) = 𝟙 (of X) := rfl
@[to_additive (attr := simp)]
lemma ofHom_comp {X Y Z : Type u} [Group X] [Group Y] [Group Z]
(f : X →* Y) (g : Y →* Z) :
ofHom (g.comp f) = ofHom f ≫ ofHom g :=
rfl
@[to_additive]
lemma ofHom_apply {X Y : Type u} [Group X] [Group Y] (f : X →* Y) (x : X) :
(ofHom f) x = f x := rfl
-- This is essentially an alias for `Iso.hom_inv_id_apply`; consider deprecation?
@[to_additive]
lemma inv_hom_apply {X Y : GrpCat} (e : X ≅ Y) (x : X) : e.inv (e.hom x) = x := by
simp
-- This is essentially an alias for `Iso.inv_hom_id_apply`; consider deprecation?
@[to_additive]
lemma hom_inv_apply {X Y : GrpCat} (e : X ≅ Y) (s : Y) : e.hom (e.inv s) = s := by
simp
@[to_additive]
instance : Inhabited GrpCat :=
⟨GrpCat.of PUnit⟩
@[to_additive hasForgetToAddMonCat]
instance hasForgetToMonCat : HasForget₂ GrpCat MonCat where
forget₂.obj X := MonCat.of X
forget₂.map f := MonCat.ofHom f.hom
@[to_additive (attr := simp)] lemma forget₂_map_ofHom {X Y : Type u} [Group X] [Group Y]
(f : X →* Y) :
(forget₂ GrpCat MonCat).map (ofHom f) = MonCat.ofHom f := rfl
@[to_additive]
instance : Coe GrpCat.{u} MonCat.{u} where coe := (forget₂ GrpCat MonCat).obj
@[to_additive]
instance (G H : GrpCat) : One (G ⟶ H) where
one := ofHom 1
@[to_additive (attr := simp)]
theorem one_apply (G H : GrpCat) (g : G) : ((1 : G ⟶ H) : G → H) g = 1 :=
rfl
@[to_additive]
lemma ofHom_injective {X Y : Type u} [Group X] [Group Y] :
Function.Injective (fun (f : X →* Y) ↦ ofHom f) := by
intro _ _ h
ext
apply ConcreteCategory.congr_hom h
/-- The forgetful functor from groups to monoids is fully faithful. -/
@[to_additive fullyFaihtfulForget₂ToAddMonCat
/-- The forgetful functor from additive groups to additive monoids is fully faithful. -/]
def fullyFaithfulForget₂ToMonCat : (forget₂ GrpCat.{u} MonCat).FullyFaithful where
preimage f := ofHom f.hom
@[to_additive]
instance : (forget₂ GrpCat.{u} MonCat).Full :=
fullyFaithfulForget₂ToMonCat.full
-- We verify that simp lemmas apply when coercing morphisms to functions.
@[to_additive]
example {R S : GrpCat} (i : R ⟶ S) (r : R) (h : r = 1) : i r = 1 := by simp [h]
/-- Universe lift functor for groups. -/
@[to_additive (attr := simps obj map)
/-- Universe lift functor for additive groups. -/]
def uliftFunctor : GrpCat.{v} ⥤ GrpCat.{max v u} where
obj X := GrpCat.of (ULift.{u, v} X)
map {_ _} f := GrpCat.ofHom <|
MulEquiv.ulift.symm.toMonoidHom.comp <| f.hom.comp MulEquiv.ulift.toMonoidHom
map_id X := by rfl
map_comp {X Y Z} f g := by rfl
end GrpCat
/-- The category of additive groups and group morphisms. -/
structure AddCommGrpCat : Type (u + 1) where
/-- The underlying type. -/
(carrier : Type u)
[str : AddCommGroup carrier]
/-- The category of groups and group morphisms. -/
@[to_additive]
structure CommGrpCat : Type (u + 1) where
/-- The underlying type. -/
(carrier : Type u)
[str : CommGroup carrier]
attribute [instance] AddCommGrpCat.str CommGrpCat.str
initialize_simps_projections AddCommGrpCat (carrier → coe, -str)
initialize_simps_projections CommGrpCat (carrier → coe, -str)
/-- `Ab` is an abbreviation for `AddCommGroup`, for the sake of mathematicians' sanity. -/
abbrev Ab := AddCommGrpCat
namespace CommGrpCat
@[to_additive]
instance : CoeSort CommGrpCat (Type u) :=
⟨CommGrpCat.carrier⟩
attribute [coe] AddCommGrpCat.carrier CommGrpCat.carrier
/-- Construct a bundled `CommGrpCat` from the underlying type and typeclass. -/
@[to_additive /-- Construct a bundled `AddCommGrpCat` from the underlying type and typeclass. -/]
abbrev of (M : Type u) [CommGroup M] : CommGrpCat := ⟨M⟩
end CommGrpCat
/-- The type of morphisms in `AddCommGrpCat R`. -/
@[ext]
structure AddCommGrpCat.Hom (A B : AddCommGrpCat.{u}) where
private mk ::
/-- The underlying monoid homomorphism. -/
hom' : A →+ B
/-- The type of morphisms in `CommGrpCat R`. -/
@[to_additive, ext]
structure CommGrpCat.Hom (A B : CommGrpCat.{u}) where
private mk ::
/-- The underlying monoid homomorphism. -/
hom' : A →* B
namespace CommGrpCat
@[to_additive]
instance : Category CommGrpCat.{u} where
Hom X Y := Hom X Y
id X := ⟨MonoidHom.id X⟩
comp f g := ⟨g.hom'.comp f.hom'⟩
@[to_additive]
instance : ConcreteCategory CommGrpCat (· →* ·) where
hom := Hom.hom'
ofHom := Hom.mk
/-- Turn a morphism in `CommGrpCat` back into a `MonoidHom`. -/
@[to_additive /-- Turn a morphism in `AddCommGrpCat` back into an `AddMonoidHom`. -/]
abbrev Hom.hom {X Y : CommGrpCat.{u}} (f : Hom X Y) :=
ConcreteCategory.hom (C := CommGrpCat) f
/-- Typecheck a `MonoidHom` as a morphism in `CommGrpCat`. -/
@[to_additive /-- Typecheck an `AddMonoidHom` as a morphism in `AddCommGrpCat`. -/]
abbrev ofHom {X Y : Type u} [CommGroup X] [CommGroup Y] (f : X →* Y) : of X ⟶ of Y :=
ConcreteCategory.ofHom (C := CommGrpCat) f
/-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/
@[to_additive /-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/]
def Hom.Simps.hom (X Y : CommGrpCat.{u}) (f : Hom X Y) :=
f.hom
initialize_simps_projections Hom (hom' → hom)
initialize_simps_projections AddCommGrpCat.Hom (hom' → hom)
/-!
The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`.
-/
@[to_additive (attr := simp)]
lemma coe_id {X : CommGrpCat} : (𝟙 X : X → X) = id := rfl
@[to_additive (attr := simp)]
lemma coe_comp {X Y Z : CommGrpCat} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl
@[to_additive (attr := simp)]
lemma forget_map {X Y : CommGrpCat} (f : X ⟶ Y) :
(forget CommGrpCat).map f = (f : X → Y) :=
rfl
@[to_additive (attr := ext)]
lemma ext {X Y : CommGrpCat} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g :=
ConcreteCategory.hom_ext _ _ w
@[to_additive]
instance : Inhabited CommGrpCat :=
⟨CommGrpCat.of PUnit⟩
@[to_additive]
-- This is not `simp` to avoid rewriting in types of terms.
theorem coe_of (R : Type u) [CommGroup R] : ↑(CommGrpCat.of R) = R :=
rfl
@[to_additive (attr := simp)]
lemma hom_id {X : CommGrpCat} : (𝟙 X : X ⟶ X).hom = MonoidHom.id X := rfl
/- Provided for rewriting. -/
@[to_additive]
lemma id_apply (X : CommGrpCat) (x : X) :
(𝟙 X : X ⟶ X) x = x := by simp
@[to_additive (attr := simp)]
lemma hom_comp {X Y T : CommGrpCat} (f : X ⟶ Y) (g : Y ⟶ T) :
(f ≫ g).hom = g.hom.comp f.hom := rfl
/- Provided for rewriting. -/
@[to_additive]
lemma comp_apply {X Y T : CommGrpCat} (f : X ⟶ Y) (g : Y ⟶ T) (x : X) :
(f ≫ g) x = g (f x) := by simp
@[to_additive (attr := ext)]
lemma hom_ext {X Y : CommGrpCat} {f g : X ⟶ Y} (hf : f.hom = g.hom) : f = g :=
Hom.ext hf
@[to_additive (attr := simp)]
lemma hom_ofHom {X Y : Type u} [CommGroup X] [CommGroup Y] (f : X →* Y) : (ofHom f).hom = f := rfl
@[to_additive (attr := simp)]
lemma ofHom_hom {X Y : CommGrpCat} (f : X ⟶ Y) :
ofHom (Hom.hom f) = f := rfl
@[to_additive (attr := simp)]
lemma ofHom_id {X : Type u} [CommGroup X] : ofHom (MonoidHom.id X) = 𝟙 (of X) := rfl
@[to_additive (attr := simp)]
lemma ofHom_comp {X Y Z : Type u} [CommGroup X] [CommGroup Y] [CommGroup Z]
(f : X →* Y) (g : Y →* Z) :
ofHom (g.comp f) = ofHom f ≫ ofHom g :=
rfl
@[to_additive]
lemma ofHom_apply {X Y : Type u} [CommGroup X] [CommGroup Y] (f : X →* Y) (x : X) :
(ofHom f) x = f x := rfl
-- This is essentially an alias for `Iso.hom_inv_id_apply`; consider deprecation?
@[to_additive]
lemma inv_hom_apply {X Y : CommGrpCat} (e : X ≅ Y) (x : X) : e.inv (e.hom x) = x := by
simp
-- This is essentially an alias for `Iso.inv_hom_id_apply`; consider deprecation?
@[to_additive]
lemma hom_inv_apply {X Y : CommGrpCat} (e : X ≅ Y) (s : Y) : e.hom (e.inv s) = s := by
simp
@[to_additive]
instance hasForgetToGroup : HasForget₂ CommGrpCat GrpCat where
forget₂.obj X := GrpCat.of X
forget₂.map f := GrpCat.ofHom f.hom
@[to_additive (attr := simp)] lemma forget₂_grp_map_ofHom {X Y : Type u} [CommGroup X] [CommGroup Y]
(f : X →* Y) :
(forget₂ CommGrpCat GrpCat).map (ofHom f) = GrpCat.ofHom f := rfl
@[to_additive]
instance : Coe CommGrpCat.{u} GrpCat.{u} where coe := (forget₂ CommGrpCat GrpCat).obj
/-- The forgetful functor from commutative groups to groups is fully faithful. -/
@[to_additive fullyFaihtfulForget₂ToAddGrp
/-- The forgetful functor from additive commutative groups to additive groups is fully faithful. -/]
def fullyFaithfulForget₂ToGrp : (forget₂ CommGrpCat.{u} GrpCat).FullyFaithful where
preimage f := ofHom f.hom
@[to_additive]
instance : (forget₂ CommGrpCat.{u} GrpCat).Full :=
fullyFaithfulForget₂ToGrp.full
@[to_additive hasForgetToAddCommMonCat]
instance hasForgetToCommMonCat : HasForget₂ CommGrpCat CommMonCat where
forget₂.obj X := CommMonCat.of X
forget₂.map f := CommMonCat.ofHom f.hom
@[to_additive (attr := simp)] lemma forget₂_commMonCat_map_ofHom {X Y : Type u}
[CommGroup X] [CommGroup Y] (f : X →* Y) :
(forget₂ CommGrpCat CommMonCat).map (ofHom f) = CommMonCat.ofHom f := rfl
@[to_additive]
instance : Coe CommGrpCat.{u} CommMonCat.{u} where coe := (forget₂ CommGrpCat CommMonCat).obj
@[to_additive]
instance (G H : CommGrpCat) : One (G ⟶ H) where
one := ofHom 1
@[to_additive (attr := simp)]
theorem one_apply (G H : CommGrpCat) (g : G) : ((1 : G ⟶ H) : G → H) g = 1 :=
rfl
@[to_additive]
lemma ofHom_injective {X Y : Type u} [CommGroup X] [CommGroup Y] :
Function.Injective (fun (f : X →* Y) ↦ ofHom f) := by
intro _ _ h
ext
apply ConcreteCategory.congr_hom h
-- We verify that simp lemmas apply when coercing morphisms to functions.
@[to_additive]
example {R S : CommGrpCat} (i : R ⟶ S) (r : R) (h : r = 1) : i r = 1 := by simp [h]
/-- Universe lift functor for commutative groups. -/
@[to_additive (attr := simps obj map)
/-- Universe lift functor for additive commutative groups. -/]
def uliftFunctor : CommGrpCat.{v} ⥤ CommGrpCat.{max v u} where
obj X := CommGrpCat.of (ULift.{u, v} X)
map {_ _} f := CommGrpCat.ofHom <|
MulEquiv.ulift.symm.toMonoidHom.comp <| f.hom.comp MulEquiv.ulift.toMonoidHom
map_id X := by rfl
map_comp {X Y Z} f g := by rfl
end CommGrpCat
namespace AddCommGrpCat
-- Note that because `ℤ : Type 0`, this forces `G : AddCommGroup.{0}`,
-- so we write this explicitly to be clear.
-- TODO generalize this, requiring a `ULiftInstances.lean` file
/-- Any element of an abelian group gives a unique morphism from `ℤ` sending
`1` to that element. -/
@[simps!]
def asHom {G : AddCommGrpCat.{0}} (g : G) : AddCommGrpCat.of ℤ ⟶ G :=
ofHom (zmultiplesHom G g)
theorem asHom_injective {G : AddCommGrpCat.{0}} : Function.Injective (@asHom G) := fun h k w => by
simpa using CategoryTheory.congr_fun w 1
@[ext]
theorem int_hom_ext {G : AddCommGrpCat.{0}} (f g : AddCommGrpCat.of ℤ ⟶ G)
(w : f (1 : ℤ) = g (1 : ℤ)) : f = g :=
hom_ext (AddMonoidHom.ext_int w)
-- TODO: this argument should be generalised to the situation where
-- the forgetful functor is representable.
theorem injective_of_mono {G H : AddCommGrpCat.{0}} (f : G ⟶ H) [Mono f] : Function.Injective f :=
fun g₁ g₂ h => by
have t0 : asHom g₁ ≫ f = asHom g₂ ≫ f := by cat_disch
have t1 : asHom g₁ = asHom g₂ := (cancel_mono _).1 t0
apply asHom_injective t1
end AddCommGrpCat
/-- Build an isomorphism in the category `GrpCat` from a `MulEquiv` between `Group`s. -/
@[to_additive (attr := simps)]
def MulEquiv.toGrpIso {X Y : GrpCat} (e : X ≃* Y) : X ≅ Y where
hom := GrpCat.ofHom e.toMonoidHom
inv := GrpCat.ofHom e.symm.toMonoidHom
/-- Build an isomorphism in the category `AddGroup` from an `AddEquiv` between `AddGroup`s. -/
add_decl_doc AddEquiv.toAddGrpIso
/-- Build an isomorphism in the category `CommGrpCat` from a `MulEquiv`
between `CommGroup`s. -/
@[to_additive (attr := simps)]
def MulEquiv.toCommGrpIso {X Y : CommGrpCat} (e : X ≃* Y) : X ≅ Y where
hom := CommGrpCat.ofHom e.toMonoidHom
inv := CommGrpCat.ofHom e.symm.toMonoidHom
/-- Build an isomorphism in the category `AddCommGrpCat` from an `AddEquiv`
between `AddCommGroup`s. -/
add_decl_doc AddEquiv.toAddCommGrpIso
namespace CategoryTheory.Iso
/-- Build a `MulEquiv` from an isomorphism in the category `GrpCat`. -/
@[to_additive (attr := simp)]
def groupIsoToMulEquiv {X Y : GrpCat} (i : X ≅ Y) : X ≃* Y :=
MonoidHom.toMulEquiv i.hom.hom i.inv.hom (by ext; simp) (by ext; simp)
/-- Build an `addEquiv` from an isomorphism in the category `AddGroup` -/
add_decl_doc addGroupIsoToAddEquiv
/-- Build a `MulEquiv` from an isomorphism in the category `CommGroup`. -/
@[to_additive (attr := simps!)]
def commGroupIsoToMulEquiv {X Y : CommGrpCat} (i : X ≅ Y) : X ≃* Y :=
MonoidHom.toMulEquiv i.hom.hom i.inv.hom (by ext; simp) (by ext; simp)
/-- Build an `AddEquiv` from an isomorphism in the category `AddCommGroup`. -/
add_decl_doc addCommGroupIsoToAddEquiv
end CategoryTheory.Iso
/-- multiplicative equivalences between `Group`s are the same as (isomorphic to) isomorphisms
in `GrpCat` -/
@[to_additive]
def mulEquivIsoGroupIso {X Y : GrpCat.{u}} : X ≃* Y ≅ X ≅ Y where
hom e := e.toGrpIso
inv i := i.groupIsoToMulEquiv
/-- Additive equivalences between `AddGroup`s are the same
as (isomorphic to) isomorphisms in `AddGrpCat`. -/
add_decl_doc addEquivIsoAddGroupIso
/-- Multiplicative equivalences between `CommGroup`s are the same as (isomorphic to) isomorphisms
in `CommGrpCat`. -/
@[to_additive]
def mulEquivIsoCommGroupIso {X Y : CommGrpCat.{u}} : X ≃* Y ≅ X ≅ Y where
hom e := e.toCommGrpIso
inv i := i.commGroupIsoToMulEquiv
/-- Additive equivalences between `AddCommGroup`s are
the same as (isomorphic to) isomorphisms in `AddCommGrpCat`. -/
add_decl_doc addEquivIsoAddCommGroupIso
namespace CategoryTheory.Aut
/-- The (bundled) group of automorphisms of a type is isomorphic to the (bundled) group
of permutations. -/
def isoPerm {α : Type u} : GrpCat.of (Aut α) ≅ GrpCat.of (Equiv.Perm α) where
hom := GrpCat.ofHom
{ toFun := fun g => g.toEquiv
map_one' := by aesop
map_mul' := by aesop }
inv := GrpCat.ofHom
{ toFun := fun g => g.toIso
map_one' := by aesop
map_mul' := by aesop }
/-- The (unbundled) group of automorphisms of a type is `MulEquiv` to the (unbundled) group
of permutations. -/
def mulEquivPerm {α : Type u} : Aut α ≃* Equiv.Perm α :=
isoPerm.groupIsoToMulEquiv
end CategoryTheory.Aut
@[to_additive]
instance GrpCat.forget_reflects_isos : (forget GrpCat.{u}).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget GrpCat).map f)
let e : X ≃* Y := { i.toEquiv with map_mul' := map_mul _ }
exact e.toGrpIso.isIso_hom
@[to_additive]
instance CommGrpCat.forget_reflects_isos : (forget CommGrpCat.{u}).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget CommGrpCat).map f)
let e : X ≃* Y := { i.toEquiv with map_mul' := map_mul _}
exact e.toCommGrpIso.isIso_hom
-- note: in the following definitions, there is a problem with `@[to_additive]`
-- as the `Category` instance is not found on the additive variant
-- this variant is then renamed with a `Aux` suffix
/-- An alias for `GrpCat.{max u v}`, to deal around unification issues. -/
@[to_additive (attr := nolint checkUnivs) GrpMaxAux
/-- An alias for `AddGrpCat.{max u v}`, to deal around unification issues. -/]
abbrev GrpMax.{u1, u2} := GrpCat.{max u1 u2}
/-- An alias for `AddGrpCat.{max u v}`, to deal around unification issues. -/
@[nolint checkUnivs]
abbrev AddGrpMax.{u1, u2} := AddGrpCat.{max u1 u2}
/-- An alias for `CommGrpCat.{max u v}`, to deal around unification issues. -/
@[to_additive (attr := nolint checkUnivs) AddCommGrpMaxAux
/-- An alias for `AddCommGrpCat.{max u v}`, to deal around unification issues. -/]
abbrev CommGrpMax.{u1, u2} := CommGrpCat.{max u1 u2}
/-- An alias for `AddCommGrpCat.{max u v}`, to deal around unification issues. -/
@[nolint checkUnivs]
abbrev AddCommGrpMax.{u1, u2} := AddCommGrpCat.{max u1 u2} |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/Ulift.lean | import Mathlib.Algebra.Category.Grp.LargeColimits
import Mathlib.Algebra.Category.Grp.Limits
import Mathlib.Algebra.Module.CharacterModule
import Mathlib.CategoryTheory.Limits.Preserves.Ulift
/-!
# Properties of the universe lift functor for groups
This file shows that the functors `GrpCat.uliftFunctor` and `CommGrpCat.uliftFunctor`
(as well as the additive versions) are fully faithful, preserve all limits and
create small limits.
Full faithfulness is pretty obvious. To prove that the functors preserve limits,
we use the fact that the forgetful functor from `GrpCat` or `CommGrpCat` into `Type`
creates all limits (because of the way limits are constructed in `GrpCat` and `CommGrpCat`),
and that the universe lift functor on `Type` preserves all limits. Once we know
that `GrpCat.uliftFunctor` preserves all limits and is fully faithful, it will
automatically create all limits that exist, i.e. all small ones.
We then switch to `AddCommGrpCat` and show that `AddCommGrpCat.uliftFunctor` preserves zero
morphisms and is an additive functor, which again is pretty obvious.
The last result is a proof that `AddCommGrpCat.uliftFunctor` preserves all colimits
(and hence creates small colimits). This is the only non-formal part of this file,
as we follow the same strategy as for the categories `Type`.
Suppose that we have a functor `K : J ⥤ AddCommGrpCat.{u}` (with `J` any category), a
colimit cocone `c` of `K` and a cocone `lc` of `K ⋙ uliftFunctor.{u v}`. We want to
construct a morphism of cocones `uliftFunctor.mapCocone c → lc` witnessing the fact
that `uliftFunctor.mapCocone c` is also a colimit cocone, but we have no direct way
to do this. The idea is to use that `AddCommGrpCat.{max v u}` has a small cogenerator,
which is just the additive (rational) circle `ℚ / ℤ`, so any abelian group of
any size can be recovered from its morphisms into `ℚ / ℤ`. More precisely, the functor
sending an abelian group `A` to its dual `A →+ ℚ / ℤ` is fully faithful, *if* we consider
the dual as a (right) module over the endomorphism ring of `ℚ / ℤ`. So an abelian
group `C` is totally determined by the restriction of the coyoneda
functor `A ↦ (C →+ A)` to the category of abelian groups at a smaller universe level.
We do not develop this totally here but do a direct construction. Every time we have
a morphism from `lc.pt` into `ℚ / ℤ`, or more generally into any small abelian group
`A`, we can construct a cocone of `K ⋙ uliftFunctor` by sticking `ULift A` at the
cocone point (this is `CategoryTheory.Limits.Cocone.extensions`), and this cocone is
actually made up of `u`-small abelian groups, hence gives a cocone of `K`. Using
the universal property of `c`, we get a morphism `c.pt →+ A`. So we have constructed
a map `(lc.pt →+ A) → (c.pt →+ A)`, and it is easy to prove that it is compatible with
postcomposition of morphisms of small abelian groups. To actually get the
morphism `c.pt →+ lc.pt`, we apply this to the canonical embedding of `lc.pt` into
`Π (_ : lc.pt →+ ℚ / ℤ), ℚ / ℤ` (this group is not small but is a product of small
groups, so our construction extends). To show that the image of `c.pt` in this product
is contained in that of `lc.pt`, we use the compatibility with postcomposition and the
fact that we can detect elements of the image just by applying morphisms from
`Π (_ : lc.pt →+ ℚ / ℤ), ℚ / ℤ` to `ℚ / ℤ`.
Note that this does *not* work for noncommutative groups, because the existence of
simple groups of arbitrary size implies that a general object `G` of `GrpCat` is not
determined by the restriction of `coyoneda.obj G` to the category of groups at
a smaller universe level. Indeed, the functor `GrpCat.uliftFunctor` does not commute
with arbitrary colimits: if we take an increasing family `K` of simple groups in
`GrpCat.{u}` of unbounded cardinality indexed by a linearly ordered type
(for example finitary alternating groups on a family of types in `u` of unbounded cardinality),
then the colimit of `K` in `GrpCat.{u}` exists and is the trivial group; meanwhile, the colimit
of `K ⋙ GrpCat.uliftFunctor.{u + 1}` is nontrivial (it is the "union" of all the `K j`, which is
too big to be in `GrpCat.{u}`).
-/
universe v w w' u
open CategoryTheory Limits
namespace GrpCat
/-- The universe lift functor for groups is fully faithful.
-/
@[to_additive
/-- The universe lift functor for additive groups is fully faithful. -/]
def uliftFunctorFullyFaithful : uliftFunctor.{u, v}.FullyFaithful where
preimage f := GrpCat.ofHom (MulEquiv.ulift.toMonoidHom.comp
(f.hom.comp MulEquiv.ulift.symm.toMonoidHom))
map_preimage _ := rfl
preimage_map _ := rfl
/-- The universe lift functor for groups is faithful.
-/
@[to_additive
/-- The universe lift functor for additive groups is faithful. -/]
instance : uliftFunctor.{u, v}.Faithful := uliftFunctorFullyFaithful.faithful
/-- The universe lift functor for groups is full.
-/
@[to_additive
/-- The universe lift functor for additive groups is full. -/]
instance : uliftFunctor.{u, v}.Full := uliftFunctorFullyFaithful.full
@[to_additive]
noncomputable instance uliftFunctor_preservesLimit {J : Type w} [Category.{w'} J]
(K : J ⥤ GrpCat.{u}) : PreservesLimit K uliftFunctor.{v, u} where
preserves lc := ⟨isLimitOfReflects (forget GrpCat.{max u v})
(isLimitOfPreserves CategoryTheory.uliftFunctor (isLimitOfPreserves (forget GrpCat) lc))⟩
@[to_additive]
noncomputable instance uliftFunctor_preservesLimitsOfShape {J : Type w} [Category.{w'} J] :
PreservesLimitsOfShape J uliftFunctor.{v, u} where
/--
The universe lift for groups preserves limits of arbitrary size.
-/
@[to_additive
/-- The universe lift functor for additive groups preserves limits of arbitrary size. -/]
noncomputable instance uliftFunctor_preservesLimitsOfSize :
PreservesLimitsOfSize.{w', w} uliftFunctor.{v, u} where
/--
The universe lift functor on `GrpCat.{u}` creates `u`-small limits.
-/
@[to_additive
/-- The universe lift functor on `AddGrpCat.{u}` creates `u`-small limits. -/]
noncomputable instance : CreatesLimitsOfSize.{w, u} uliftFunctor.{v, u} where
CreatesLimitsOfShape := { CreatesLimit := fun {_} ↦ createsLimitOfFullyFaithfulOfPreserves }
end GrpCat
namespace CommGrpCat
/-- The universe lift functor for commutative groups is fully faithful.
-/
@[to_additive
/-- The universe lift functor for commutative additive groups is fully faithful. -/]
def uliftFunctorFullyFaithful : uliftFunctor.{u, v}.FullyFaithful where
preimage f := CommGrpCat.ofHom (MulEquiv.ulift.toMonoidHom.comp
(f.hom.comp MulEquiv.ulift.symm.toMonoidHom))
map_preimage _ := rfl
preimage_map _ := rfl
-- The universe lift functor for commutative groups is faithful. -/
@[to_additive
/-- The universe lift functor for commutative additive groups is faithful. -/]
instance : uliftFunctor.{u, v}.Faithful := uliftFunctorFullyFaithful.faithful
-- The universe lift functor for commutative groups is full. -/
@[to_additive
/-- The universe lift functor for commutative additive groups is full. -/]
instance : uliftFunctor.{u, v}.Full := uliftFunctorFullyFaithful.full
@[to_additive]
noncomputable instance uliftFunctor_preservesLimit {J : Type w} [Category.{w'} J]
(K : J ⥤ CommGrpCat.{u}) : PreservesLimit K uliftFunctor.{v, u} where
preserves lc := ⟨isLimitOfReflects (forget CommGrpCat.{max u v})
(isLimitOfPreserves CategoryTheory.uliftFunctor (isLimitOfPreserves (forget CommGrpCat) lc))⟩
@[to_additive]
noncomputable instance uliftFunctor_preservesLimitsOfShape {J : Type w} [Category.{w'} J] :
PreservesLimitsOfShape J uliftFunctor.{v, u} where
/--
The universe lift for commutative groups preserves limits of arbitrary size.
-/
@[to_additive /-- The universe lift functor for commutative additive groups preserves limits of
arbitrary size. -/]
noncomputable instance uliftFunctor_preservesLimitsOfSize :
PreservesLimitsOfSize.{w', w} uliftFunctor.{v, u} where
/--
The universe lift functor on `CommGrpCat.{u}` creates `u`-small limits.
-/
@[to_additive
/-- The universe lift functor on `AddCommGrpCat.{u}` creates `u`-small limits. -/]
noncomputable instance : CreatesLimitsOfSize.{w, u} uliftFunctor.{v, u} where
CreatesLimitsOfShape := { CreatesLimit := fun {_} ↦ createsLimitOfFullyFaithfulOfPreserves }
end CommGrpCat
namespace AddCommGrpCat
/-- The universe lift for commutative additive groups is additive.
-/
instance uliftFunctor_additive :
AddCommGrpCat.uliftFunctor.{u,v}.Additive where
open Colimits in
/--
The functor `uliftFunctor : AddCommGrpCat.{u} ⥤ AddCommGrpCat.{max u v}` preserves colimits
of arbitrary size.
-/
noncomputable instance : PreservesColimitsOfSize.{w', w} uliftFunctor.{v, u} where
preservesColimitsOfShape {J _} :=
{ preservesColimit := fun {F} ↦
{ preserves := fun {c} hc ↦ by
classical
rw [isColimit_iff_bijective_desc, ← Function.Bijective.of_comp_iff _
(quotQuotUliftAddEquiv F).bijective, ← AddEquiv.coe_toAddMonoidHom,
← AddMonoidHom.coe_comp, Quot.desc_quotQuotUliftAddEquiv]
exact ULift.up_bijective.comp ((isColimit_iff_bijective_desc c).mp (Nonempty.intro hc)) } }
/--
The functor `uliftFunctor : AddCommGrpCat.{u} ⥤ AddCommGrpCat.{max u v}` creates `u`-small colimits.
-/
noncomputable instance : CreatesColimitsOfSize.{w, u} uliftFunctor.{v, u} where
CreatesColimitsOfShape :=
{ CreatesColimit := fun {_} ↦ createsColimitOfReflectsIsomorphismsOfPreserves }
end AddCommGrpCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/FilteredColimits.lean | import Mathlib.Algebra.Category.Grp.Basic
import Mathlib.Algebra.Category.MonCat.FilteredColimits
/-!
# The forgetful functor from (commutative) (additive) groups preserves filtered colimits.
Forgetful functors from algebraic categories usually don't preserve colimits. However, they tend
to preserve _filtered_ colimits.
In this file, we start with a small filtered category `J` and a functor `F : J ⥤ GrpCat`.
We show that the colimit of `F ⋙ forget₂ GrpCat MonCat` (in `MonCat`) carries the structure of a
group,
thereby showing that the forgetful functor `forget₂ GrpCat MonCat` preserves filtered colimits.
In particular, this implies that `forget GrpCat` preserves filtered colimits.
Similarly for `AddGrpCat`, `CommGrpCat` and `AddCommGrpCat`.
-/
universe v u
noncomputable section
open CategoryTheory Limits
open IsFiltered renaming max → max' -- avoid name collision with `_root_.max`.
namespace GrpCat.FilteredColimits
section
-- Mathlib3 used parameters here, mainly so we could have the abbreviations `G` and `G.mk` below,
-- without passing around `F` all the time.
variable {J : Type v} [SmallCategory J] [IsFiltered J] (F : J ⥤ GrpCat.{max v u})
/-- The colimit of `F ⋙ forget₂ GrpCat MonCat` in the category `MonCat`.
In the following, we will show that this has the structure of a group.
-/
@[to_additive
/-- The colimit of `F ⋙ forget₂ AddGrpCat AddMonCat` in the category `AddMonCat`.
In the following, we will show that this has the structure of an additive group. -/]
noncomputable abbrev G : MonCat :=
MonCat.FilteredColimits.colimit.{v, u} (F ⋙ forget₂ GrpCat MonCat.{max v u})
/-- The canonical projection into the colimit, as a quotient type. -/
@[to_additive /-- The canonical projection into the colimit, as a quotient type. -/]
abbrev G.mk : (Σ j, F.obj j) → G.{v, u} F :=
fun x ↦ (F ⋙ forget GrpCat).ιColimitType x.1 x.2
@[to_additive]
theorem G.mk_eq (x y : Σ j, F.obj j)
(h : ∃ (k : J) (f : x.1 ⟶ k) (g : y.1 ⟶ k), F.map f x.2 = F.map g y.2) :
G.mk.{v, u} F x = G.mk F y :=
Quot.eqvGen_sound (Types.FilteredColimit.eqvGen_colimitTypeRel_of_rel (F ⋙ forget GrpCat) x y h)
@[to_additive]
theorem colimit_one_eq (j : J) : (1 : G.{v, u} F) = G.mk F ⟨j, 1⟩ :=
MonCat.FilteredColimits.colimit_one_eq _ _
@[to_additive]
theorem colimit_mul_mk_eq (x y : Σ j, F.obj j) (k : J) (f : x.1 ⟶ k) (g : y.1 ⟶ k) :
G.mk.{v, u} F x * G.mk F y = G.mk F ⟨k, F.map f x.2 * F.map g y.2⟩ :=
MonCat.FilteredColimits.colimit_mul_mk_eq _ _ _ _ _ _
@[to_additive]
lemma colimit_mul_mk_eq' {j : J} (x y : F.obj j) :
G.mk.{v, u} F ⟨j, x⟩ * G.mk.{v, u} F ⟨j, y⟩ = G.mk.{v, u} F ⟨j, x * y⟩ := by
simpa using colimit_mul_mk_eq F ⟨j, x⟩ ⟨j, y⟩ j (𝟙 _) (𝟙 _)
/-- The "unlifted" version of taking inverses in the colimit. -/
@[to_additive /-- The "unlifted" version of negation in the colimit. -/]
def colimitInvAux (x : Σ j, F.obj j) : G.{v, u} F :=
G.mk F ⟨x.1, x.2⁻¹⟩
@[to_additive]
theorem colimitInvAux_eq_of_rel (x y : Σ j, F.obj j)
(h : Types.FilteredColimit.Rel (F ⋙ forget GrpCat) x y) :
colimitInvAux.{v, u} F x = colimitInvAux F y := by
apply G.mk_eq
obtain ⟨k, f, g, hfg⟩ := h
use k, f, g
rw [MonoidHom.map_inv, MonoidHom.map_inv, inv_inj]
exact hfg
/-- Taking inverses in the colimit. See also `colimitInvAux`. -/
@[to_additive /-- Negation in the colimit. See also `colimitNegAux`. -/]
instance colimitInv : Inv (G.{v, u} F) where
inv x := by
refine Quot.lift (colimitInvAux.{v, u} F) ?_ x
intro x y h
apply colimitInvAux_eq_of_rel
apply Types.FilteredColimit.rel_of_colimitTypeRel
exact h
@[to_additive (attr := simp)]
theorem colimit_inv_mk_eq (x : Σ j, F.obj j) : (G.mk.{v, u} F x)⁻¹ = G.mk F ⟨x.1, x.2⁻¹⟩ :=
rfl
@[to_additive]
noncomputable instance colimitGroup : Group (G.{v, u} F) :=
{ colimitInv.{v, u} F, (G.{v, u} F).str with
inv_mul_cancel := fun x => by
refine Quot.inductionOn x ?_; clear x; intro x
change (G.mk _ _)⁻¹ * G.mk _ _ = _
obtain ⟨j, x⟩ := x
simp [colimit_inv_mk_eq, colimit_mul_mk_eq F ⟨j, _⟩ ⟨j, _⟩ j (𝟙 j) (𝟙 j),
colimit_one_eq F j] }
/-- The bundled group giving the filtered colimit of a diagram. -/
@[to_additive /-- The bundled additive group giving the filtered colimit of a diagram. -/]
noncomputable def colimit : GrpCat.{max v u} :=
GrpCat.of (G.{v, u} F)
/-- The cocone over the proposed colimit group. -/
@[to_additive /-- The cocone over the proposed colimit additive group. -/]
noncomputable def colimitCocone : Cocone F where
pt := colimit.{v, u} F
ι.app J := GrpCat.ofHom ((MonCat.FilteredColimits.colimitCocone
(F ⋙ forget₂ GrpCat MonCat)).ι.app J).hom
ι.naturality _ _ f := (forget₂ _ MonCat).map_injective
((MonCat.FilteredColimits.colimitCocone _).ι.naturality f)
/-- The proposed colimit cocone is a colimit in `GrpCat`. -/
@[to_additive /-- The proposed colimit cocone is a colimit in `AddGroup`. -/]
noncomputable def colimitCoconeIsColimit : IsColimit (colimitCocone.{v, u} F) :=
isColimitOfReflects (forget₂ _ MonCat)
(MonCat.FilteredColimits.colimitCoconeIsColimit (F ⋙ forget₂ GrpCat MonCat))
@[to_additive forget₂AddMon_preservesFilteredColimits]
noncomputable instance forget₂Mon_preservesFilteredColimits :
PreservesFilteredColimits.{u} (forget₂ GrpCat.{u} MonCat.{u}) where
preserves_filtered_colimits x hx1 _ :=
letI : Category.{u, u} x := hx1
⟨fun {F} => preservesColimit_of_preserves_colimit_cocone (colimitCoconeIsColimit.{u, u} F)
(MonCat.FilteredColimits.colimitCoconeIsColimit.{u, u} _)⟩
@[to_additive]
noncomputable instance forget_preservesFilteredColimits :
PreservesFilteredColimits (forget GrpCat.{u}) :=
Limits.comp_preservesFilteredColimits (forget₂ GrpCat MonCat) (forget MonCat.{u})
end
end GrpCat.FilteredColimits
namespace CommGrpCat.FilteredColimits
section
-- We use parameters here, mainly so we can have the abbreviation `G` below, without
-- passing around `F` all the time.
variable {J : Type v} [SmallCategory J] [IsFiltered J] (F : J ⥤ CommGrpCat.{max v u})
/-- The colimit of `F ⋙ forget₂ CommGrpCat GrpCat` in the category `GrpCat`.
In the following, we will show that this has the structure of a _commutative_ group.
-/
@[to_additive
/-- The colimit of `F ⋙ forget₂ AddCommGrpCat AddGrpCat` in the category `AddGrpCat`.
In the following, we will show that this has the structure of a _commutative_ additive group. -/]
noncomputable abbrev G : GrpCat.{max v u} :=
GrpCat.FilteredColimits.colimit.{v, u} (F ⋙ forget₂ CommGrpCat.{max v u} GrpCat.{max v u})
@[to_additive]
noncomputable instance colimitCommGroup : CommGroup.{max v u} (G.{v, u} F) :=
{ (G F).str,
CommMonCat.FilteredColimits.colimitCommMonoid
(F ⋙ forget₂ CommGrpCat CommMonCat.{max v u}) with }
/-- The bundled commutative group giving the filtered colimit of a diagram. -/
@[to_additive
/-- The bundled additive commutative group giving the filtered colimit of a diagram. -/]
noncomputable def colimit : CommGrpCat :=
CommGrpCat.of (G.{v, u} F)
/-- The cocone over the proposed colimit commutative group. -/
@[to_additive /-- The cocone over the proposed colimit additive commutative group. -/]
noncomputable def colimitCocone : Cocone F where
pt := colimit.{v, u} F
ι.app J := CommGrpCat.ofHom
((GrpCat.FilteredColimits.colimitCocone (F ⋙ forget₂ CommGrpCat GrpCat)).ι.app J).hom
ι.naturality _ _ f := (forget₂ _ GrpCat).map_injective
((GrpCat.FilteredColimits.colimitCocone _).ι.naturality f)
/-- The proposed colimit cocone is a colimit in `CommGrpCat`. -/
@[to_additive /-- The proposed colimit cocone is a colimit in `AddCommGroup`. -/]
noncomputable def colimitCoconeIsColimit : IsColimit (colimitCocone.{v, u} F) :=
isColimitOfReflects (forget₂ _ GrpCat)
(GrpCat.FilteredColimits.colimitCoconeIsColimit (F ⋙ forget₂ CommGrpCat GrpCat))
@[to_additive]
noncomputable instance forget₂Group_preservesFilteredColimits :
PreservesFilteredColimits (forget₂ CommGrpCat GrpCat.{u}) where
preserves_filtered_colimits J hJ1 _ :=
letI : Category J := hJ1
{ preservesColimit := fun {F} =>
preservesColimit_of_preserves_colimit_cocone (colimitCoconeIsColimit.{u, u} F)
(GrpCat.FilteredColimits.colimitCoconeIsColimit.{u, u}
(F ⋙ forget₂ CommGrpCat GrpCat.{u})) }
@[to_additive]
noncomputable instance forget_preservesFilteredColimits :
PreservesFilteredColimits (forget CommGrpCat.{u}) :=
Limits.comp_preservesFilteredColimits (forget₂ CommGrpCat GrpCat) (forget GrpCat.{u})
end
end CommGrpCat.FilteredColimits |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/Subobject.lean | import Mathlib.Algebra.Category.Grp.ZModuleEquivalence
import Mathlib.Algebra.Category.ModuleCat.Subobject
/-!
# The category of abelian groups is well-powered
-/
open CategoryTheory
universe u
namespace AddCommGrpCat
instance wellPowered_addCommGrp : WellPowered.{u} AddCommGrpCat.{u} :=
wellPowered_of_equiv.{u} (forget₂ (ModuleCat.{u} ℤ) AddCommGrpCat.{u}).asEquivalence
end AddCommGrpCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/ZModuleEquivalence.lean | import Mathlib.Algebra.Category.ModuleCat.Basic
/-!
The forgetful functor from ℤ-modules to additive commutative groups is
an equivalence of categories.
TODO:
either use this equivalence to transport the monoidal structure from `Module ℤ` to `Ab`,
or, having constructed that monoidal structure directly, show this functor is monoidal.
-/
open CategoryTheory
open CategoryTheory.Equivalence
universe u
namespace ModuleCat
/-- The forgetful functor from `ℤ` modules to `AddCommGrpCat` is full. -/
instance forget₂_addCommGroup_full : (forget₂ (ModuleCat ℤ) AddCommGrpCat.{u}).Full where
map_surjective {A B}
-- `AddMonoidHom.toIntLinearMap` doesn't work here because `A` and `B` are not
-- definitionally equal to the canonical `AddCommGroup.toIntModule` module
-- instances it expects.
f := ⟨@ModuleCat.ofHom _ _ _ _ _ A.isModule _ B.isModule <|
@LinearMap.mk _ _ _ _ _ _ _ _ _ A.isModule B.isModule
{ toFun := f,
map_add' := AddMonoidHom.map_add f.hom }
(fun n x => by
convert AddMonoidHom.map_zsmul f.hom x n <;>
ext <;> apply int_smul_eq_zsmul), rfl⟩
/-- The forgetful functor from `ℤ` modules to `AddCommGrpCat` is essentially surjective. -/
instance forget₂_addCommGrp_essSurj : (forget₂ (ModuleCat ℤ) AddCommGrpCat.{u}).EssSurj where
mem_essImage A :=
⟨ModuleCat.of ℤ A,
⟨{ hom := 𝟙 A
inv := 𝟙 A }⟩⟩
noncomputable instance forget₂AddCommGroupIsEquivalence :
(forget₂ (ModuleCat ℤ) AddCommGrpCat.{u}).IsEquivalence where
end ModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/ChosenFiniteProducts.lean | import Mathlib.Algebra.Category.Grp.CartesianMonoidal
deprecated_module (since := "2025-05-15") |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/ForgetCorepresentable.lean | import Mathlib.Algebra.Category.Grp.Basic
import Mathlib.CategoryTheory.Yoneda
/-!
# The forget functor is corepresentable
It is shown that the forget functor `AddCommGrpCat.{u} ⥤ Type u` is corepresentable
by `ULift ℤ`. Similar results are obtained for the variants `CommGrpCat`, `AddGrpCat`
and `GrpCat`.
-/
universe u
open CategoryTheory Opposite
/-!
### `(ULift ℤ →+ G) ≃ G`
These universe-monomorphic variants of `zmultiplesHom`/`zpowersHom` are put here since they
shouldn't be useful outside of category theory.
-/
/-- The equivalence `(ULift ℤ →+ G) ≃ G` for any additive group `G`. -/
@[simps!]
def uliftZMultiplesHom (G : Type u) [AddGroup G] : G ≃ (ULift.{u} ℤ →+ G) :=
(zmultiplesHom _).trans AddEquiv.ulift.symm.addMonoidHomCongrLeftEquiv
/-- The equivalence `(ULift (Multiplicative ℤ) →* G) ≃ G` for any group `G`. -/
@[simps!]
def uliftZPowersHom (G : Type u) [Group G] : G ≃ (ULift.{u} (Multiplicative ℤ) →* G) :=
(zpowersHom _).trans MulEquiv.ulift.symm.monoidHomCongrLeftEquiv
namespace MonoidHom
/-- The equivalence `(Multiplicative ℤ →* α) ≃ α` for any group `α`. -/
@[deprecated zpowersHom (since := "2025-05-11")]
def fromMultiplicativeIntEquiv (α : Type u) [Group α] : (Multiplicative ℤ →* α) ≃ α :=
(zpowersHom _).symm
/-- The equivalence `(ULift (Multiplicative ℤ) →* α) ≃ α` for any group `α`. -/
@[deprecated uliftZPowersHom (since := "2025-05-11")]
def fromULiftMultiplicativeIntEquiv (α : Type u) [Group α] :
(ULift.{u} (Multiplicative ℤ) →* α) ≃ α :=
(uliftZPowersHom _).symm
end MonoidHom
namespace AddMonoidHom
/-- The equivalence `(ℤ →+ α) ≃ α` for any additive group `α`. -/
@[deprecated zmultiplesHom (since := "2025-05-11")]
def fromIntEquiv (α : Type u) [AddGroup α] : (ℤ →+ α) ≃ α := (zmultiplesHom _).symm
/-- The equivalence `(ULift ℤ →+ α) ≃ α` for any additive group `α`. -/
@[deprecated uliftZMultiplesHom (since := "2025-05-11")]
def fromULiftIntEquiv (α : Type u) [AddGroup α] : (ULift.{u} ℤ →+ α) ≃ α :=
(uliftZMultiplesHom _).symm
end AddMonoidHom
/-- The forget functor `GrpCat.{u} ⥤ Type u` is corepresentable. -/
def GrpCat.coyonedaObjIsoForget :
coyoneda.obj (op (of (ULift.{u} (Multiplicative ℤ)))) ≅ forget GrpCat.{u} :=
NatIso.ofComponents fun M ↦
(ConcreteCategory.homEquiv.trans (uliftZPowersHom M.carrier).symm).toIso
/-- The forget functor `CommGrpCat.{u} ⥤ Type u` is corepresentable. -/
def CommGrpCat.coyonedaObjIsoForget :
coyoneda.obj (op (of (ULift.{u} (Multiplicative ℤ)))) ≅ forget CommGrpCat.{u} :=
NatIso.ofComponents fun M ↦
(ConcreteCategory.homEquiv.trans (uliftZPowersHom M.carrier).symm).toIso
/-- The forget functor `AddGrpCat.{u} ⥤ Type u` is corepresentable. -/
def AddGrpCat.coyonedaObjIsoForget :
coyoneda.obj (op (of (ULift.{u} ℤ))) ≅ forget AddGrpCat.{u} :=
NatIso.ofComponents fun M ↦
(ConcreteCategory.homEquiv.trans (uliftZMultiplesHom M.carrier).symm).toIso
/-- The forget functor `AddCommGrpCat.{u} ⥤ Type u` is corepresentable. -/
def AddCommGrpCat.coyonedaObjIsoForget :
coyoneda.obj (op (of (ULift.{u} ℤ))) ≅ forget AddCommGrpCat.{u} :=
NatIso.ofComponents fun M ↦
(ConcreteCategory.homEquiv.trans (uliftZMultiplesHom M.carrier).symm).toIso
instance GrpCat.forget_isCorepresentable :
(forget GrpCat.{u}).IsCorepresentable :=
Functor.IsCorepresentable.mk' GrpCat.coyonedaObjIsoForget
instance CommGrpCat.forget_isCorepresentable :
(forget CommGrpCat.{u}).IsCorepresentable :=
Functor.IsCorepresentable.mk' CommGrpCat.coyonedaObjIsoForget
instance AddGrpCat.forget_isCorepresentable :
(forget AddGrpCat.{u}).IsCorepresentable :=
Functor.IsCorepresentable.mk' AddGrpCat.coyonedaObjIsoForget
instance AddCommGrpCat.forget_isCorepresentable :
(forget AddCommGrpCat.{u}).IsCorepresentable :=
Functor.IsCorepresentable.mk' AddCommGrpCat.coyonedaObjIsoForget |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/Kernels.lean | import Mathlib.Algebra.Category.Grp.EpiMono
import Mathlib.Algebra.Category.Grp.Preadditive
import Mathlib.CategoryTheory.Limits.Shapes.Kernels
/-!
# The concrete (co)kernels in the category of abelian groups are categorical (co)kernels.
-/
namespace AddCommGrpCat
open AddMonoidHom CategoryTheory Limits QuotientAddGroup
universe u
variable {G H : AddCommGrpCat.{u}} (f : G ⟶ H)
/-- The kernel cone induced by the concrete kernel. -/
def kernelCone : KernelFork f :=
KernelFork.ofι (Z := of f.hom.ker) (ofHom f.hom.ker.subtype) <| ext fun x =>
x.casesOn fun _ hx => hx
/-- The kernel of a group homomorphism is a kernel in the categorical sense. -/
def kernelIsLimit : IsLimit <| kernelCone f :=
Fork.IsLimit.mk _
(fun s => ofHom <| s.ι.hom.codRestrict _ fun c => mem_ker.mpr <|
ConcreteCategory.congr_hom s.condition c)
(fun _ => by rfl)
(fun _ _ h => ext fun x => Subtype.ext_iff.mpr <| ConcreteCategory.congr_hom h x)
/-- The cokernel cocone induced by the projection onto the quotient. -/
def cokernelCocone : CokernelCofork f :=
CokernelCofork.ofπ (Z := of <| H ⧸ f.hom.range) (ofHom (mk' f.hom.range)) <| ext fun x =>
(eq_zero_iff _).mpr ⟨x, rfl⟩
/-- The projection onto the quotient is a cokernel in the categorical sense. -/
def cokernelIsColimit : IsColimit <| cokernelCocone f :=
Cofork.IsColimit.mk _
(fun s => ofHom <| lift _ _ <| (range_le_ker_iff _ _).mpr <|
congr_arg Hom.hom (CokernelCofork.condition s))
(fun _ => rfl)
(fun _ _ h => have : Epi (cokernelCocone f).π := (epi_iff_surjective _).mpr <| mk'_surjective _
(cancel_epi (cokernelCocone f).π).mp <| by simpa only [parallelPair_obj_one] using h)
end AddCommGrpCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/LeftExactFunctor.lean | import Mathlib.Algebra.Category.Grp.CartesianMonoidal
import Mathlib.Algebra.Category.Grp.EquivalenceGroupAddGroup
import Mathlib.CategoryTheory.Monoidal.Internal.Types.CommGrp_
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.CategoryTheory.Preadditive.CommGrp_
/-!
# The forgetful functor `(C ⥤ₗ AddCommGroup) ⥤ (C ⥤ₗ Type v)` is an equivalence
This is true as long as `C` is additive.
Here, `C ⥤ₗ D` is the category of finite-limits-preserving functors from `C` to `D`.
To construct a functor from `C ⥤ₗ Type v` to `C ⥤ₗ AddCommGrpCat.{v}`, notice that a left-exact
functor `F : C ⥤ Type v` induces a functor `CommGrp C ⥤ CommGrp (Type v)`. But `CommGrp C` is
equivalent to `C`, and `CommGrp (Type v)` is equivalent to `AddCommGrpCat.{v}`, so we turn this
into a functor `C ⥤ AddCommGrpCat.{v}`. By construction, composing with the forgetful
functor recovers the functor we started with, so since the forgetful functor reflects finite
limits and `F` preserves finite limits, our constructed functor also preserves finite limits. It
can be shown that this construction gives a quasi-inverse to the whiskering operation
`(C ⥤ₗ AddCommGrpCat.{v}) ⥤ (C ⥤ₗ Type v)`.
-/
open CategoryTheory MonoidalCategory Limits
universe v v' u u'
namespace AddCommGrpCat
section
variable {C : Type u} [Category.{v} C] [Preadditive C] [HasFiniteBiproducts C]
namespace leftExactFunctorForgetEquivalence
attribute [local instance] hasFiniteProducts_of_hasFiniteBiproducts
attribute [local instance] AddCommGrpCat.cartesianMonoidalCategoryAddCommGrp
private noncomputable local instance : CartesianMonoidalCategory C := .ofHasFiniteProducts
private noncomputable local instance : BraidedCategory C := .ofCartesianMonoidalCategory
/-- Implementation, see `leftExactFunctorForgetEquivalence`. -/
noncomputable def inverseAux : (C ⥤ₗ Type v) ⥤ C ⥤ AddCommGrpCat.{v} :=
Functor.mapCommGrpFunctor ⋙
(Functor.whiskeringLeft _ _ _).obj Preadditive.commGrpEquivalence.functor ⋙
(Functor.whiskeringRight _ _ _).obj
(commGrpTypeEquivalenceCommGrp.functor ⋙ commGroupAddCommGroupEquivalence.functor)
instance (F : C ⥤ₗ Type v) : PreservesFiniteLimits (inverseAux.obj F) where
preservesFiniteLimits J _ _ :=
have : PreservesLimitsOfShape J (inverseAux.obj F ⋙ forget AddCommGrpCat) :=
inferInstanceAs (PreservesLimitsOfShape J F.1)
preservesLimitsOfShape_of_reflects_of_preserves _ (forget AddCommGrpCat)
/-- Implementation, see `leftExactFunctorForgetEquivalence`. -/
noncomputable def inverse : (C ⥤ₗ Type v) ⥤ (C ⥤ₗ AddCommGrpCat.{v}) :=
ObjectProperty.lift _ inverseAux inferInstance
open scoped MonObj
attribute [-instance] Functor.LaxMonoidal.comp Functor.Monoidal.instComp in
/-- Implementation, see `leftExactFunctorForgetEquivalence`.
This is the complicated bit, where we show that forgetting the group structure in the image of
`F` and then reconstructing it recovers the group structure we started with. -/
noncomputable def unitIsoAux (F : C ⥤ AddCommGrpCat.{v}) [PreservesFiniteLimits F] (X : C) :
letI : (F ⋙ forget AddCommGrpCat).Braided := .ofChosenFiniteProducts _
commGrpTypeEquivalenceCommGrp.inverse.obj (AddCommGrpCat.toCommGrp.obj (F.obj X)) ≅
(F ⋙ forget AddCommGrpCat).mapCommGrp.obj (Preadditive.commGrpEquivalence.functor.obj X) := by
letI : (F ⋙ forget AddCommGrpCat).Braided := .ofChosenFiniteProducts _
letI : F.Monoidal := .ofChosenFiniteProducts _
refine CommGrp.mkIso Multiplicative.toAdd.toIso (by
erw [Functor.mapCommGrp_obj_grp_one]
cat_disch) ?_
dsimp [-Functor.comp_map, -ConcreteCategory.forget_map_eq_coe, -forget_map]
have : F.Additive := Functor.additive_of_preserves_binary_products _
simp only [Category.id_comp]
erw [Functor.mapCommGrp_obj_grp_mul]
erw [Functor.comp_map, F.map_add, Functor.Monoidal.μ_comp F (forget AddCommGrpCat) X X,
Category.assoc, ← Functor.map_comp, Preadditive.comp_add, Functor.Monoidal.μ_fst,
Functor.Monoidal.μ_snd]
cat_disch
/-- Implementation, see `leftExactFunctorForgetEquivalence`. -/
noncomputable def unitIso : 𝟭 (C ⥤ₗ AddCommGrpCat) ≅
(LeftExactFunctor.whiskeringRight _ _ _).obj (LeftExactFunctor.of (forget _)) ⋙ inverse :=
NatIso.ofComponents (fun F => InducedCategory.isoMk (NatIso.ofComponents (fun X =>
commGroupAddCommGroupEquivalence.counitIso.app _ ≪≫
(CommGrpCat.toAddCommGrp.mapIso (commGrpTypeEquivalenceCommGrp.counitIso.app
(AddCommGrpCat.toCommGrp.obj (F.obj.obj X)))).symm ≪≫
CommGrpCat.toAddCommGrp.mapIso
(CommGrpTypeEquivalenceCommGrp.functor.mapIso (unitIsoAux F.obj X)))))
end leftExactFunctorForgetEquivalence
variable (C) in
/-- If `C` is an additive category, the forgetful functor `(C ⥤ₗ AddCommGroup) ⥤ (C ⥤ₗ Type v)` is
an equivalence. -/
noncomputable def leftExactFunctorForgetEquivalence : (C ⥤ₗ AddCommGrpCat.{v}) ≌ (C ⥤ₗ Type v) where
functor := (LeftExactFunctor.whiskeringRight _ _ _).obj (LeftExactFunctor.of (forget _))
inverse := leftExactFunctorForgetEquivalence.inverse
unitIso := leftExactFunctorForgetEquivalence.unitIso
counitIso := Iso.refl _
end
end AddCommGrpCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/Injective.lean | import Mathlib.Algebra.Category.Grp.ZModuleEquivalence
import Mathlib.Algebra.Category.ModuleCat.Injective
import Mathlib.Algebra.EuclideanDomain.Int
import Mathlib.GroupTheory.Divisible
import Mathlib.RingTheory.PrincipalIdealDomain
/-!
# Injective objects in the category of abelian groups
In this file we prove that divisible groups are injective objects in category of (additive) abelian
groups. The proof that the category of abelian groups has enough injective objects can be found
in `Mathlib/Algebra/Category/GrpCat/EnoughInjectives.lean`.
## Main results
- `AddCommGrpCat.injective_of_divisible` : a divisible group is also an injective object.
-/
open CategoryTheory
open Pointwise
universe u
variable (A : Type u) [AddCommGroup A]
theorem Module.Baer.of_divisible [DivisibleBy A ℤ] : Module.Baer ℤ A := fun I g ↦ by
rcases IsPrincipalIdealRing.principal I with ⟨m, rfl⟩
obtain rfl | h0 := eq_or_ne m 0
· refine ⟨0, fun n hn ↦ ?_⟩
rw [Submodule.span_zero_singleton] at hn
subst hn
exact (map_zero g).symm
let gₘ := g ⟨m, Submodule.subset_span (Set.mem_singleton _)⟩
refine ⟨LinearMap.toSpanSingleton ℤ A (DivisibleBy.div gₘ m), fun n hn ↦ ?_⟩
rcases Submodule.mem_span_singleton.mp hn with ⟨n, rfl⟩
rw [map_zsmul, LinearMap.toSpanSingleton_apply, DivisibleBy.div_cancel gₘ h0, ← map_zsmul g,
SetLike.mk_smul_mk]
namespace AddCommGrpCat
theorem injective_as_module_iff : Injective (ModuleCat.of ℤ A) ↔
Injective (C := AddCommGrpCat) (AddCommGrpCat.of A) :=
((forget₂ (ModuleCat ℤ) AddCommGrpCat).asEquivalence.map_injective_iff (ModuleCat.of ℤ A)).symm
instance injective_of_divisible [DivisibleBy A ℤ] :
Injective (C := AddCommGrpCat) (AddCommGrpCat.of A) :=
(injective_as_module_iff A).mp <|
Module.injective_object_of_injective_module (inj := (Module.Baer.of_divisible A).injective)
end AddCommGrpCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/Colimits.lean | import Mathlib.Algebra.Category.Grp.Preadditive
import Mathlib.Algebra.Group.Shrink
import Mathlib.CategoryTheory.ConcreteCategory.Elementwise
import Mathlib.Data.DFinsupp.BigOperators
import Mathlib.Data.DFinsupp.Small
import Mathlib.GroupTheory.QuotientGroup.Defs
/-!
# The category of additive commutative groups has all colimits.
This file constructs colimits in the category of additive commutative groups, as
quotients of finitely supported functions.
-/
universe u' w u v
open CategoryTheory Limits
namespace AddCommGrpCat
variable {J : Type u} [Category.{v} J] (F : J ⥤ AddCommGrpCat.{w})
namespace Colimits
/-!
We build the colimit of a diagram in `AddCommGrpCat` by constructing the
free group on the disjoint union of all the abelian groups in the diagram,
then taking the quotient by the abelian group laws within each abelian group,
and the identifications given by the morphisms in the diagram.
-/
/--
The relations between elements of the direct sum of the `F.obj j` given by the
morphisms in the diagram `J`.
-/
abbrev Relations [DecidableEq J] : AddSubgroup (DFinsupp (fun j ↦ F.obj j)) :=
AddSubgroup.closure {x | ∃ (j j' : J) (u : j ⟶ j') (a : F.obj j),
x = DFinsupp.single j' (F.map u a) - DFinsupp.single j a}
/--
The candidate for the colimit of `F`, defined as the quotient of the direct sum
of the commutative groups `F.obj j` by the relations given by the morphisms in
the diagram.
-/
def Quot [DecidableEq J] : Type (max u w) :=
DFinsupp (fun j ↦ F.obj j) ⧸ Relations F
instance [DecidableEq J] : AddCommGroup (Quot F) :=
QuotientAddGroup.Quotient.addCommGroup (Relations F)
/-- Inclusion of `F.obj j` into the candidate colimit.
-/
def Quot.ι [DecidableEq J] (j : J) : F.obj j →+ Quot F :=
(QuotientAddGroup.mk' _).comp (DFinsupp.singleAddHom (fun j ↦ F.obj j) j)
lemma Quot.addMonoidHom_ext [DecidableEq J] {α : Type*} [AddMonoid α] {f g : Quot F →+ α}
(h : ∀ (j : J) (x : F.obj j), f (Quot.ι F j x) = g (Quot.ι F j x)) : f = g :=
QuotientAddGroup.addMonoidHom_ext _ (DFinsupp.addHom_ext h)
variable (c : Cocone F)
/-- (implementation detail) Part of the universal property of the colimit cocone, but without
assuming that `Quot F` lives in the correct universe. -/
def Quot.desc [DecidableEq J] : Quot.{w} F →+ c.pt := by
refine QuotientAddGroup.lift _ (DFinsupp.sumAddHom fun x => (c.ι.app x).hom) ?_
dsimp
rw [AddSubgroup.closure_le]
intro _ ⟨_, _, _, _, eq⟩
rw [eq]
simp only [SetLike.mem_coe, AddMonoidHom.mem_ker, map_sub, DFinsupp.sumAddHom_single]
change (F.map _ ≫ c.ι.app _) _ - _ = 0
rw [c.ι.naturality]
simp only [Functor.const_obj_obj, Functor.const_obj_map, Category.comp_id, sub_self]
@[simp]
lemma Quot.ι_desc [DecidableEq J] (j : J) (x : F.obj j) :
Quot.desc F c (Quot.ι F j x) = c.ι.app j x := by
dsimp [desc, ι]
erw [QuotientAddGroup.lift_mk']
simp
@[simp]
lemma Quot.map_ι [DecidableEq J] {j j' : J} {f : j ⟶ j'} (x : F.obj j) :
Quot.ι F j' (F.map f x) = Quot.ι F j x := by
dsimp [ι]
refine eq_of_sub_eq_zero ?_
erw [← (QuotientAddGroup.mk' (Relations F)).map_sub, ← AddMonoidHom.mem_ker]
rw [QuotientAddGroup.ker_mk']
simp only [DFinsupp.singleAddHom_apply]
exact AddSubgroup.subset_closure ⟨j, j', f, x, rfl⟩
/--
The obvious additive map from `Quot F` to `Quot (F ⋙ uliftFunctor.{u'})`.
-/
def quotToQuotUlift [DecidableEq J] : Quot F →+ Quot (F ⋙ uliftFunctor.{u'}) := by
refine QuotientAddGroup.lift (Relations F) (DFinsupp.sumAddHom (fun j ↦ (Quot.ι _ j).comp
AddEquiv.ulift.symm.toAddMonoidHom)) ?_
rw [AddSubgroup.closure_le]
intro _ hx
obtain ⟨j, j', u, a, rfl⟩ := hx
rw [SetLike.mem_coe, AddMonoidHom.mem_ker, map_sub, DFinsupp.sumAddHom_single,
DFinsupp.sumAddHom_single]
change Quot.ι (F ⋙ uliftFunctor) j' ((F ⋙ uliftFunctor).map u (AddEquiv.ulift.symm a)) - _ = _
rw [Quot.map_ι]
dsimp
rw [sub_self]
lemma quotToQuotUlift_ι [DecidableEq J] (j : J) (x : F.obj j) :
quotToQuotUlift F (Quot.ι F j x) = Quot.ι _ j (ULift.up x) := by
dsimp [quotToQuotUlift, Quot.ι]
conv_lhs => erw [AddMonoidHom.comp_apply (QuotientAddGroup.mk' (Relations F))
(DFinsupp.singleAddHom _ j), QuotientAddGroup.lift_mk']
simp only [DFinsupp.singleAddHom_apply, DFinsupp.sumAddHom_single, AddMonoidHom.coe_comp,
AddMonoidHom.coe_coe, Function.comp_apply]
rfl
/--
The obvious additive map from `Quot (F ⋙ uliftFunctor.{u'})` to `Quot F`.
-/
def quotUliftToQuot [DecidableEq J] : Quot (F ⋙ uliftFunctor.{u'}) →+ Quot F := by
refine QuotientAddGroup.lift (Relations (F ⋙ uliftFunctor))
(DFinsupp.sumAddHom (fun j ↦ (Quot.ι _ j).comp AddEquiv.ulift.toAddMonoidHom)) ?_
rw [AddSubgroup.closure_le]
intro _ hx
obtain ⟨j, j', u, a, rfl⟩ := hx
simp
lemma quotUliftToQuot_ι [DecidableEq J] (j : J) (x : (F ⋙ uliftFunctor.{u'}).obj j) :
quotUliftToQuot F (Quot.ι _ j x) = Quot.ι F j x.down := by
dsimp [quotUliftToQuot, Quot.ι]
conv_lhs => erw [AddMonoidHom.comp_apply (QuotientAddGroup.mk' (Relations (F ⋙ uliftFunctor)))
(DFinsupp.singleAddHom _ j), QuotientAddGroup.lift_mk']
simp only [Functor.comp_obj, uliftFunctor_obj, DFinsupp.singleAddHom_apply,
DFinsupp.sumAddHom_single, AddMonoidHom.coe_comp, AddMonoidHom.coe_coe, Function.comp_apply]
rfl
/--
The additive equivalence between `Quot F` and `Quot (F ⋙ uliftFunctor.{u'})`.
-/
@[simp]
def quotQuotUliftAddEquiv [DecidableEq J] : Quot F ≃+ Quot (F ⋙ uliftFunctor.{u'}) where
toFun := quotToQuotUlift F
invFun := quotUliftToQuot F
left_inv x := by
conv_rhs => rw [← AddMonoidHom.id_apply _ x]
rw [← AddMonoidHom.comp_apply, Quot.addMonoidHom_ext F (f := (quotUliftToQuot F).comp
(quotToQuotUlift F)) (fun j a ↦ ?_)]
rw [AddMonoidHom.comp_apply, AddMonoidHom.id_apply, quotToQuotUlift_ι, quotUliftToQuot_ι]
right_inv x := by
conv_rhs => rw [← AddMonoidHom.id_apply _ x]
rw [← AddMonoidHom.comp_apply, Quot.addMonoidHom_ext _ (f := (quotToQuotUlift F).comp
(quotUliftToQuot F)) (fun j a ↦ ?_)]
rw [AddMonoidHom.comp_apply, AddMonoidHom.id_apply, quotUliftToQuot_ι, quotToQuotUlift_ι]
rfl
map_add' _ _ := by simp
lemma Quot.desc_quotQuotUliftAddEquiv [DecidableEq J] (c : Cocone F) :
(Quot.desc (F ⋙ uliftFunctor.{u'}) (uliftFunctor.{u'}.mapCocone c)).comp
(quotQuotUliftAddEquiv F).toAddMonoidHom =
AddEquiv.ulift.symm.toAddMonoidHom.comp (Quot.desc F c) := by
refine Quot.addMonoidHom_ext _ (fun j a ↦ ?_)
dsimp
simp only [quotToQuotUlift_ι, Functor.comp_obj, uliftFunctor_obj, ι_desc, Functor.const_obj_obj,
ι_desc]
erw [Quot.ι_desc]
rfl
/-- (implementation detail) A morphism of commutative additive groups `Quot F →+ A`
induces a cocone on `F` as long as the universes work out.
-/
@[simps]
def toCocone [DecidableEq J] {A : Type w} [AddCommGroup A] (f : Quot F →+ A) : Cocone F where
pt := AddCommGrpCat.of A
ι.app j := ofHom <| f.comp (Quot.ι F j)
lemma Quot.desc_toCocone_desc [DecidableEq J] {A : Type w} [AddCommGroup A] (f : Quot F →+ A)
(hc : IsColimit c) : (hc.desc (toCocone F f)).hom.comp (Quot.desc F c) = f := by
refine Quot.addMonoidHom_ext F (fun j x ↦ ?_)
rw [AddMonoidHom.comp_apply, ι_desc]
change (c.ι.app j ≫ hc.desc (toCocone F f)) _ = _
rw [hc.fac]
simp
lemma Quot.desc_toCocone_desc_app [DecidableEq J] {A : Type w} [AddCommGroup A] (f : Quot F →+ A)
(hc : IsColimit c) (x : Quot F) : hc.desc (toCocone F f) (Quot.desc F c x) = f x := by
conv_rhs => rw [← Quot.desc_toCocone_desc F c f hc]
dsimp
/--
If `c` is a cocone of `F` such that `Quot.desc F c` is bijective, then `c` is a colimit
cocone of `F`.
-/
noncomputable def isColimit_of_bijective_desc [DecidableEq J]
(h : Function.Bijective (Quot.desc F c)) : IsColimit c where
desc s := AddCommGrpCat.ofHom ((Quot.desc F s).comp (AddEquiv.ofBijective
(Quot.desc F c) h).symm.toAddMonoidHom)
fac s j := by
ext x
dsimp
conv_lhs => erw [← Quot.ι_desc F c j x]
rw [← AddEquiv.ofBijective_apply _ h, AddEquiv.symm_apply_apply]
simp only [Quot.ι_desc, Functor.const_obj_obj]
uniq s m hm := by
ext x
obtain ⟨x, rfl⟩ := h.2 x
dsimp
rw [← AddEquiv.ofBijective_apply _ h, AddEquiv.symm_apply_apply]
suffices eq : m.hom.comp (AddEquiv.ofBijective (Quot.desc F c) h) = Quot.desc F s by
rw [← eq]; rfl
exact Quot.addMonoidHom_ext F (by simp [← hm])
/-- (internal implementation) The colimit cocone of a functor `F`, implemented as a quotient of
`DFinsupp (fun j ↦ F.obj j)`, under the assumption that said quotient is small.
-/
@[simps pt ι_app]
noncomputable def colimitCocone [DecidableEq J] [Small.{w} (Quot.{w} F)] : Cocone F where
pt := AddCommGrpCat.of (Shrink (Quot F))
ι :=
{ app j :=
AddCommGrpCat.ofHom (Shrink.addEquiv.symm.toAddMonoidHom.comp (Quot.ι F j))
naturality _ _ _ := by
ext
dsimp
change Shrink.addEquiv.symm _ = _
rw [Quot.map_ι] }
@[simp]
theorem Quot.desc_colimitCocone [DecidableEq J] (F : J ⥤ AddCommGrpCat.{w}) [Small.{w} (Quot F)] :
Quot.desc F (colimitCocone F) = (Shrink.addEquiv (α := Quot F)).symm.toAddMonoidHom := by
refine Quot.addMonoidHom_ext F (fun j x ↦ ?_)
simpa only [colimitCocone_pt, AddEquiv.toAddMonoidHom_eq_coe, AddMonoidHom.coe_coe]
using Quot.ι_desc F (colimitCocone F) j x
/-- (internal implementation) The fact that the candidate colimit cocone constructed in
`colimitCocone` is the colimit.
-/
noncomputable def colimitCoconeIsColimit [DecidableEq J] [Small.{w} (Quot F)] :
IsColimit (colimitCocone F) := by
refine isColimit_of_bijective_desc F _ ?_
rw [Quot.desc_colimitCocone]
exact Shrink.addEquiv.symm.bijective
end Colimits
open Colimits
lemma hasColimit_of_small_quot [DecidableEq J] (h : Small.{w} (Quot F)) : HasColimit F :=
⟨_, colimitCoconeIsColimit F⟩
instance [DecidableEq J] [Small.{w} J] : Small.{w} (Quot F) :=
small_of_surjective (QuotientAddGroup.mk'_surjective _)
instance hasColimit [Small.{w} J] (F : J ⥤ AddCommGrpCat.{w}) : HasColimit F := by
classical
exact hasColimit_of_small_quot F inferInstance
/--
If `J` is `w`-small, then any functor `J ⥤ AddCommGrpCat.{w}` has a colimit.
-/
instance hasColimitsOfShape [Small.{w} J] : HasColimitsOfShape J (AddCommGrpCat.{w}) where
/-- The category of additive commutative groups has all small colimits.
-/
instance (priority := 1300) hasColimitsOfSize [UnivLE.{u, w}] :
HasColimitsOfSize.{v, u} (AddCommGrpCat.{w}) where
end AddCommGrpCat
namespace AddCommGrpCat
open QuotientAddGroup
/-- The categorical cokernel of a morphism in `AddCommGrpCat`
agrees with the usual group-theoretical quotient.
-/
noncomputable def cokernelIsoQuotient {G H : AddCommGrpCat.{u}} (f : G ⟶ H) :
cokernel f ≅ AddCommGrpCat.of (H ⧸ AddMonoidHom.range f.hom) where
hom := cokernel.desc f (ofHom (mk' _)) <| by
ext x
simp
inv := ofHom <|
QuotientAddGroup.lift _ (cokernel.π f).hom <| by
rintro _ ⟨x, rfl⟩
exact cokernel.condition_apply f x
hom_inv_id := by
refine coequalizer.hom_ext ?_
simp only [coequalizer_as_cokernel, cokernel.π_desc_assoc, Category.comp_id]
rfl
inv_hom_id := by
ext x
dsimp only [hom_comp, hom_ofHom, hom_zero, AddMonoidHom.coe_comp, coe_mk',
Function.comp_apply, AddMonoidHom.zero_apply, id_eq, lift_mk, hom_id, AddMonoidHom.coe_id]
exact QuotientAddGroup.induction_on (α := H) x <| cokernel.π_desc_apply f _ _
end AddCommGrpCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/AB.lean | import Mathlib.Algebra.Category.Grp.Biproducts
import Mathlib.Algebra.Category.Grp.FilteredColimits
import Mathlib.Algebra.Homology.ShortComplex.Ab
import Mathlib.CategoryTheory.Abelian.GrothendieckAxioms.Basic
import Mathlib.CategoryTheory.Limits.FunctorCategory.EpiMono
/-!
# AB axioms for the category of abelian groups
This file proves that the category of abelian groups satisfies Grothendieck's axioms AB5, AB4, and
AB4*.
-/
universe u
open CategoryTheory Limits
instance {J C : Type*} [Category J] [Category C] [HasColimitsOfShape J C] [Preadditive C] :
(colim (J := J) (C := C)).Additive where
variable {J : Type u} [SmallCategory J] [IsFiltered J]
noncomputable instance :
(colim (J := J) (C := AddCommGrpCat.{u})).PreservesHomology :=
Functor.preservesHomology_of_map_exact _ (fun S hS ↦ by
replace hS := fun j => hS.map ((evaluation _ _).obj j)
simp only [ShortComplex.ab_exact_iff_ker_le_range] at hS ⊢
intro x (hx : _ = _)
dsimp at hx
rcases Concrete.colimit_exists_rep S.X₂ x with ⟨j, y, rfl⟩
rw [← ConcreteCategory.comp_apply, colimMap_eq, colimit.ι_map, ConcreteCategory.comp_apply,
← map_zero (colimit.ι S.X₃ j).hom] at hx
rcases Concrete.colimit_exists_of_rep_eq.{u, u, u} S.X₃ _ _ hx with ⟨k, e₁, e₂, hk⟩
rw [map_zero, ← ConcreteCategory.comp_apply, ← NatTrans.naturality, ConcreteCategory.comp_apply]
at hk
rcases hS k hk with ⟨t, ht⟩
use colimit.ι S.X₁ k t
erw [← ConcreteCategory.comp_apply, colimit.ι_map, ConcreteCategory.comp_apply, ht]
exact colimit.w_apply S.X₂ e₁ y)
noncomputable instance :
PreservesFiniteLimits <| colim (J := J) (C := AddCommGrpCat.{u}) := by
apply Functor.preservesFiniteLimits_of_preservesHomology
instance : HasFilteredColimits (AddCommGrpCat.{u}) where
HasColimitsOfShape := inferInstance
noncomputable instance : AB5 (AddCommGrpCat.{u}) where
ofShape _ := { preservesFiniteLimits := inferInstance }
attribute [local instance] Abelian.hasFiniteBiproducts
instance : AB4 AddCommGrpCat.{u} := AB4.of_AB5 _
instance : HasExactLimitsOfShape (Discrete J) (AddCommGrpCat.{u}) := by
apply (config := { allowSynthFailures := true }) hasExactLimitsOfShape_of_preservesEpi
exact {
preserves {X Y} f hf := by
let iX : limit X ≅ AddCommGrpCat.of ((i : J) → X.obj ⟨i⟩) := (Pi.isoLimit X).symm ≪≫
(limit.isLimit _).conePointUniqueUpToIso (AddCommGrpCat.HasLimit.productLimitCone _).isLimit
let iY : limit Y ≅ AddCommGrpCat.of ((i : J) → Y.obj ⟨i⟩) := (Pi.isoLimit Y).symm ≪≫
(limit.isLimit _).conePointUniqueUpToIso (AddCommGrpCat.HasLimit.productLimitCone _).isLimit
have : Pi.map (fun i ↦ f.app ⟨i⟩) = iX.inv ≫ lim.map f ≫ iY.hom := by
simp only [Discrete.functor_obj_eq_as, Discrete.mk_as, Pi.isoLimit,
IsLimit.conePointUniqueUpToIso, limit.cone, AddCommGrpCat.HasLimit.productLimitCone,
Iso.trans_inv, Functor.mapIso_inv, IsLimit.uniqueUpToIso_inv, Cones.forget_map,
IsLimit.liftConeMorphism_hom, limit.isLimit_lift, Iso.symm_inv, Functor.mapIso_hom,
IsLimit.uniqueUpToIso_hom, lim_obj, lim_map, Iso.trans_hom, Iso.symm_hom,
AddCommGrpCat.HasLimit.lift, Functor.const_obj_obj, Category.assoc, limit.lift_map_assoc,
Pi.cone_pt, iX, iY]
ext g j
change _ = (_ ≫ limit.π (Discrete.functor fun j ↦ Y.obj { as := j }) ⟨j⟩) _
simp only [Discrete.functor_obj_eq_as, productIsProduct', limit.lift_π, Fan.mk_pt,
Fan.mk_π_app, Pi.map_apply]
change _ = (_ ≫ _ ≫ limit.π Y ⟨j⟩) _
simp
suffices Epi (iX.hom ≫ (iX.inv ≫ lim.map f ≫ iY.hom) ≫ iY.inv) by simpa using this
suffices Epi (iX.inv ≫ lim.map f ≫ iY.hom) from inferInstance
rw [AddCommGrpCat.epi_iff_surjective, ← this]
simp_rw [CategoryTheory.NatTrans.epi_iff_epi_app, AddCommGrpCat.epi_iff_surjective] at hf
refine fun b ↦ ⟨fun i ↦ (hf ⟨i⟩ (b i)).choose, ?_⟩
funext i
exact (hf ⟨i⟩ (b i)).choose_spec }
instance : AB4Star AddCommGrpCat.{u} where
ofShape _ := inferInstance |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/LargeColimits.lean | import Mathlib.Algebra.Category.Grp.Colimits
import Mathlib.Algebra.Module.CharacterModule
import Mathlib.Algebra.Group.Equiv.Basic
/-!
# Existence of "big" colimits in the category of additive commutative groups
If `F : J ⥤ AddCommGrpCat.{w}` is a functor, we show that `F` admits a colimit if and only
if `Colimits.Quot F` (the quotient of the direct sum of the commutative groups `F.obj j`
by the relations given by the morphisms in the diagram) is `w`-small.
-/
universe w u v
open CategoryTheory Limits
namespace AddCommGrpCat
variable {J : Type u} [Category.{v} J] {F : J ⥤ AddCommGrpCat.{w}} (c : Cocone F)
open Colimits
/--
If `c` is a cocone of `F` such that `Quot.desc F c` is bijective, then `c` is a colimit
cocone of `F`.
-/
lemma isColimit_iff_bijective_desc [DecidableEq J] :
Nonempty (IsColimit c) ↔ Function.Bijective (Quot.desc F c) := by
refine ⟨fun ⟨hc⟩ => ?_, fun h ↦ Nonempty.intro (isColimit_of_bijective_desc F c h)⟩
change Function.Bijective (Quot.desc F c).toIntLinearMap
rw [← CharacterModule.dual_bijective_iff_bijective]
refine ⟨fun χ ψ eq ↦ ?_, fun χ ↦ ?_⟩
· apply AddEquiv.ulift.symm.addMonoidHomCongrRightEquiv.injective
apply ofHom_injective
refine hc.hom_ext (fun j ↦ ?_)
ext x
rw [ConcreteCategory.comp_apply, ConcreteCategory.comp_apply, ← Quot.ι_desc _ c j x]
exact DFunLike.congr_fun eq (Quot.ι F j x)
· set c' : Cocone F :=
{ pt := AddCommGrpCat.of (ULift (AddCircle (1 : ℚ)))
ι :=
{ app j := AddCommGrpCat.ofHom (((@AddEquiv.ulift _ _).symm.toAddMonoidHom.comp χ).comp
(Quot.ι F j))
naturality {j j'} u := by
ext
dsimp
rw [Quot.map_ι F (f := u)] } }
use AddEquiv.ulift.toAddMonoidHom.comp (hc.desc c').hom
refine Quot.addMonoidHom_ext _ (fun j x ↦ ?_)
dsimp
rw [Quot.ι_desc]
change AddEquiv.ulift ((c.ι.app j ≫ hc.desc c') x) = _
rw [hc.fac]
dsimp [c']
rw [AddEquiv.apply_symm_apply]
/--
A functor `F : J ⥤ AddCommGrpCat.{w}` has a colimit if and only if `Colimits.Quot F` is
`w`-small.
-/
lemma hasColimit_iff_small_quot [DecidableEq J] : HasColimit F ↔ Small.{w} (Quot F) :=
⟨fun _ ↦ Small.mk ⟨_, ⟨(Equiv.ofBijective _ ((isColimit_iff_bijective_desc (colimit.cocone F)).mp
⟨colimit.isColimit _⟩))⟩⟩, hasColimit_of_small_quot F⟩
end AddCommGrpCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/Limits.lean | import Mathlib.Algebra.Category.Grp.ForgetCorepresentable
import Mathlib.Algebra.Category.Grp.Preadditive
import Mathlib.Algebra.Category.MonCat.ForgetCorepresentable
import Mathlib.Algebra.Category.MonCat.Limits
import Mathlib.Algebra.Group.Subgroup.Ker
import Mathlib.CategoryTheory.ConcreteCategory.ReflectsIso
import Mathlib.CategoryTheory.Limits.ConcreteCategory.Basic
/-!
# The category of (commutative) (additive) groups has all limits
Further, these limits are preserved by the forgetful functor --- that is,
the underlying types are just the limits in the category of types.
-/
open CategoryTheory CategoryTheory.Limits
universe v u w
noncomputable section
variable {J : Type v} [Category.{w} J]
namespace GrpCat
variable (F : J ⥤ GrpCat.{u})
@[to_additive]
instance groupObj (j) : Group ((F ⋙ forget GrpCat).obj j) :=
inferInstanceAs <| Group (F.obj j)
/-- The flat sections of a functor into `GrpCat` form a subgroup of all sections. -/
@[to_additive
/-- The flat sections of a functor into `AddGrpCat` form an additive subgroup of all sections. -/]
def sectionsSubgroup : Subgroup (∀ j, F.obj j) :=
{ MonCat.sectionsSubmonoid (F ⋙ forget₂ GrpCat MonCat) with
carrier := (F ⋙ forget GrpCat).sections
inv_mem' := fun {a} ah j j' f => by
simp only [Functor.comp_map, Pi.inv_apply]
dsimp [Functor.sections] at ah ⊢
rw [(F.map f).hom.map_inv (a j), ah f] }
@[to_additive]
instance sectionsGroup : Group (F ⋙ forget GrpCat.{u}).sections :=
(sectionsSubgroup F).toGroup
/-- The projection from `Functor.sections` to a factor as a `MonoidHom`. -/
@[to_additive /-- The projection from `Functor.sections` to a factor as an `AddMonoidHom`. -/]
def sectionsπMonoidHom (j : J) : (F ⋙ forget GrpCat.{u}).sections →* F.obj j where
toFun x := x.val j
map_one' := rfl
map_mul' _ _ := rfl
section
variable [Small.{u} (Functor.sections (F ⋙ forget GrpCat))]
@[to_additive]
noncomputable instance limitGroup :
Group (Types.Small.limitCone.{v, u} (F ⋙ forget GrpCat.{u})).pt :=
inferInstanceAs <| Group (Shrink (F ⋙ forget GrpCat.{u}).sections)
@[to_additive]
instance : Small.{u} (Functor.sections ((F ⋙ forget₂ GrpCat MonCat) ⋙ forget MonCat)) :=
inferInstanceAs <| Small.{u} (Functor.sections (F ⋙ forget GrpCat))
/-- We show that the forgetful functor `GrpCat ⥤ MonCat` creates limits.
All we need to do is notice that the limit point has a `Group` instance available, and then reuse
the existing limit. -/
@[to_additive /-- We show that the forgetful functor `AddGrpCat ⥤ AddMonCat` creates limits.
All we need to do is notice that the limit point has an `AddGroup` instance available, and then
reuse the existing limit. -/]
noncomputable instance Forget₂.createsLimit :
CreatesLimit F (forget₂ GrpCat.{u} MonCat.{u}) :=
-- Porting note: need to add `forget₂ GrpCat MonCat` reflects isomorphism
letI : (forget₂ GrpCat.{u} MonCat.{u}).ReflectsIsomorphisms :=
CategoryTheory.reflectsIsomorphisms_forget₂ _ _
createsLimitOfReflectsIso (K := F) (F := (forget₂ GrpCat.{u} MonCat.{u}))
fun c' t =>
have : Small.{u} (Functor.sections ((F ⋙ forget₂ GrpCat MonCat) ⋙ forget MonCat)) := by
have : HasLimit (F ⋙ forget₂ GrpCat MonCat) := ⟨_, t⟩
apply Concrete.small_sections_of_hasLimit (F ⋙ forget₂ GrpCat MonCat)
have : Small.{u} (Functor.sections (F ⋙ forget GrpCat)) := inferInstanceAs <| Small.{u}
(Functor.sections ((F ⋙ forget₂ GrpCat MonCat) ⋙ forget MonCat))
{ liftedCone :=
{ pt := GrpCat.of (Types.Small.limitCone (F ⋙ forget GrpCat)).pt
π :=
{ app j := ofHom <| MonCat.limitπMonoidHom (F ⋙ forget₂ GrpCat MonCat) j
naturality i j h:= hom_ext <| congr_arg MonCat.Hom.hom <|
(MonCat.HasLimits.limitCone
(F ⋙ forget₂ GrpCat MonCat.{u})).π.naturality h } }
validLift := by apply IsLimit.uniqueUpToIso (MonCat.HasLimits.limitConeIsLimit.{v, u} _) t
makesLimit :=
IsLimit.ofFaithful (forget₂ GrpCat MonCat.{u}) (MonCat.HasLimits.limitConeIsLimit _)
(fun _ => _) fun _ => rfl }
/-- A choice of limit cone for a functor into `GrpCat`.
(Generally, you'll just want to use `limit F`.) -/
@[to_additive /-- A choice of limit cone for a functor into `GrpCat`.
(Generally, you'll just want to use `limit F`.) -/]
noncomputable def limitCone : Cone F :=
liftLimit (limit.isLimit (F ⋙ forget₂ GrpCat.{u} MonCat.{u}))
/-- The chosen cone is a limit cone.
(Generally, you'll just want to use `limit.cone F`.) -/
@[to_additive /-- The chosen cone is a limit cone.
(Generally, you'll just want to use `limit.cone F`.) -/]
noncomputable def limitConeIsLimit : IsLimit (limitCone F) :=
liftedLimitIsLimit _
/-- If `(F ⋙ forget GrpCat).sections` is `u`-small, `F` has a limit. -/
@[to_additive /-- If `(F ⋙ forget AddGrpCat).sections` is `u`-small, `F` has a limit. -/]
instance hasLimit : HasLimit F :=
HasLimit.mk {
cone := limitCone F
isLimit := limitConeIsLimit F
}
end
/-- A functor `F : J ⥤ GrpCat.{u}` has a limit iff `(F ⋙ forget GrpCat).sections` is
`u`-small. -/
@[to_additive /-- A functor `F : J ⥤ AddGrpCat.{u}` has a limit iff
`(F ⋙ forget AddGrpCat).sections` is `u`-small. -/]
lemma hasLimit_iff_small_sections :
HasLimit F ↔ Small.{u} (F ⋙ forget GrpCat).sections := by
constructor
· apply Concrete.small_sections_of_hasLimit
· intro
infer_instance
/-- If `J` is `u`-small, `GrpCat.{u}` has limits of shape `J`. -/
@[to_additive /-- If `J` is `u`-small, `AddGrpCat.{u}` has limits of shape `J`. -/]
instance hasLimitsOfShape [Small.{u} J] : HasLimitsOfShape J GrpCat.{u} where
has_limit _ := inferInstance
/-- The category of groups has all limits. -/
@[to_additive (relevant_arg := 100) /-- The category of additive groups has all limits. -/]
instance hasLimitsOfSize [UnivLE.{v, u}] : HasLimitsOfSize.{w, v} GrpCat.{u} where
has_limits_of_shape J _ := { }
@[to_additive]
instance hasLimits : HasLimits GrpCat.{u} :=
GrpCat.hasLimitsOfSize.{u, u}
/-- The forgetful functor from groups to monoids preserves all limits.
This means the underlying monoid of a limit can be computed as a limit in the category of monoids.
-/
@[to_additive (relevant_arg := 100) AddGrpCat.forget₂AddMonPreservesLimitsOfSize
/-- The forgetful functor from additive groups to additive monoids preserves all limits.
This means the underlying additive monoid of a limit can be computed as a limit in the category of
additive monoids. -/]
instance forget₂Mon_preservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget₂ GrpCat.{u} MonCat.{u}) where
preservesLimitsOfShape {J _} := { }
@[to_additive]
instance forget₂Mon_preservesLimits : PreservesLimits (forget₂ GrpCat.{u} MonCat.{u}) :=
GrpCat.forget₂Mon_preservesLimitsOfSize.{u, u}
/-- If `J` is `u`-small, the forgetful functor from `GrpCat.{u}` preserves limits of shape `J`. -/
@[to_additive /-- If `J` is `u`-small, the forgetful functor from `AddGrpCat.{u}` preserves limits
of shape `J`. -/]
instance forget_preservesLimitsOfShape [Small.{u} J] :
PreservesLimitsOfShape J (forget GrpCat.{u}) where
preservesLimit {F} := preservesLimit_of_preserves_limit_cone (limitConeIsLimit F)
(Types.Small.limitConeIsLimit (F ⋙ forget _))
/-- The forgetful functor from groups to types preserves all limits.
This means the underlying type of a limit can be computed as a limit in the category of types. -/
@[to_additive (relevant_arg := 100)
/-- The forgetful functor from additive groups to types preserves all limits.
This means the underlying type of a limit can be computed as a limit in the category of types. -/]
instance forget_preservesLimitsOfSize :
PreservesLimitsOfSize.{w, v} (forget GrpCat.{u}) := inferInstance
@[to_additive]
instance forget_preservesLimits : PreservesLimits (forget GrpCat.{u}) :=
GrpCat.forget_preservesLimitsOfSize.{u, u}
@[to_additive]
noncomputable instance forget_createsLimit :
CreatesLimit F (forget GrpCat.{u}) := by
set e : forget₂ GrpCat.{u} MonCat.{u} ⋙ forget MonCat.{u} ≅ forget GrpCat.{u} := Iso.refl _
exact createsLimitOfNatIso e
@[to_additive]
noncomputable instance forget_createsLimitsOfShape :
CreatesLimitsOfShape J (forget GrpCat.{u}) where
CreatesLimit := inferInstance
/-- The forgetful functor from groups to types creates all limits.
-/
@[to_additive (relevant_arg := 100)
/-- The forgetful functor from additive groups to types creates all limits. -/]
noncomputable instance forget_createsLimitsOfSize :
CreatesLimitsOfSize.{w, v} (forget GrpCat.{u}) where
CreatesLimitsOfShape := inferInstance
end GrpCat
namespace CommGrpCat
variable (F : J ⥤ CommGrpCat.{u})
@[to_additive]
instance commGroupObj (j) : CommGroup ((F ⋙ forget CommGrpCat).obj j) :=
inferInstanceAs <| CommGroup (F.obj j)
@[to_additive]
noncomputable instance limitCommGroup
[Small.{u} (Functor.sections (F ⋙ forget CommGrpCat))] :
CommGroup (Types.Small.limitCone.{v, u} (F ⋙ forget CommGrpCat.{u})).pt :=
letI : CommGroup (F ⋙ forget CommGrpCat.{u}).sections :=
@Subgroup.toCommGroup (∀ j, F.obj j) _
(GrpCat.sectionsSubgroup (F ⋙ forget₂ CommGrpCat.{u} GrpCat.{u}))
inferInstanceAs <| CommGroup (Shrink (F ⋙ forget CommGrpCat.{u}).sections)
@[to_additive]
instance : (forget₂ CommGrpCat.{u} GrpCat.{u}).ReflectsIsomorphisms :=
reflectsIsomorphisms_forget₂ _ _
/-- We show that the forgetful functor `CommGrpCat ⥤ GrpCat` creates limits.
All we need to do is notice that the limit point has a `CommGroup` instance available,
and then reuse the existing limit.
-/
@[to_additive /-- We show that the forgetful functor `AddCommGrpCat ⥤ AddGrpCat` creates limits.
All we need to do is notice that the limit point has an `AddCommGroup` instance available,
and then reuse the existing limit. -/]
noncomputable instance Forget₂.createsLimit :
CreatesLimit F (forget₂ CommGrpCat GrpCat.{u}) :=
createsLimitOfReflectsIso (fun c hc => by
have : HasLimit _ := ⟨_, hc⟩
have : Small.{u} (F ⋙ forget CommGrpCat).sections :=
Concrete.small_sections_of_hasLimit (F ⋙ forget₂ CommGrpCat GrpCat)
have : Small.{u} ((F ⋙ forget₂ CommGrpCat GrpCat ⋙ forget₂ GrpCat MonCat) ⋙
forget MonCat).sections := this
have : Small.{u} ((F ⋙ forget₂ CommGrpCat GrpCat) ⋙ forget GrpCat).sections := this
exact
{ liftedCone :=
{ pt := CommGrpCat.of (Types.Small.limitCone.{v, u} (F ⋙ forget CommGrpCat)).pt
π :=
{ app j := ofHom <| MonCat.limitπMonoidHom
(F ⋙ forget₂ CommGrpCat GrpCat.{u} ⋙ forget₂ GrpCat MonCat.{u}) j
naturality i j h := hom_ext <| congr_arg MonCat.Hom.hom <|
(MonCat.HasLimits.limitCone _).π.naturality h } }
validLift := by apply IsLimit.uniqueUpToIso (GrpCat.limitConeIsLimit _) hc
makesLimit :=
IsLimit.ofFaithful (forget₂ _ GrpCat.{u} ⋙ forget₂ _ MonCat.{u})
(by apply MonCat.HasLimits.limitConeIsLimit _) (fun s => _) fun s => rfl })
section
variable [Small.{u} (Functor.sections (F ⋙ forget CommGrpCat))]
/-- A choice of limit cone for a functor into `CommGrpCat`.
(Generally, you'll just want to use `limit F`.) -/
@[to_additive
/-- A choice of limit cone for a functor into `AddCommGrpCat`.
(Generally, you'll just want to use `limit F`.) -/]
noncomputable def limitCone : Cone F :=
letI : Small.{u} (Functor.sections ((F ⋙ forget₂ CommGrpCat GrpCat) ⋙ forget GrpCat)) :=
inferInstanceAs <| Small (Functor.sections (F ⋙ forget CommGrpCat))
liftLimit (limit.isLimit (F ⋙ forget₂ CommGrpCat.{u} GrpCat.{u}))
/-- The chosen cone is a limit cone.
(Generally, you'll just want to use `limit.cone F`.) -/
@[to_additive
/-- The chosen cone is a limit cone.
(Generally, you'll just want to use `limit.cone F`.) -/]
noncomputable def limitConeIsLimit : IsLimit (limitCone.{v, u} F) :=
liftedLimitIsLimit _
/-- If `(F ⋙ forget CommGrpCat).sections` is `u`-small, `F` has a limit. -/
@[to_additive /-- If `(F ⋙ forget AddCommGrpCat).sections` is `u`-small, `F` has a limit. -/]
instance hasLimit : HasLimit F :=
HasLimit.mk {
cone := limitCone F
isLimit := limitConeIsLimit F
}
end
/-- A functor `F : J ⥤ CommGrpCat.{u}` has a limit iff `(F ⋙ forget CommGrpCat).sections` is
`u`-small. -/
@[to_additive /-- A functor `F : J ⥤ AddCommGrpCat.{u}` has a limit iff
`(F ⋙ forget AddCommGrpCat).sections` is `u`-small. -/]
lemma hasLimit_iff_small_sections :
HasLimit F ↔ Small.{u} (F ⋙ forget CommGrpCat).sections := by
constructor
· apply Concrete.small_sections_of_hasLimit
· intro
infer_instance
/-- If `J` is `u`-small, `CommGrpCat.{u}` has limits of shape `J`. -/
@[to_additive /-- If `J` is `u`-small, `AddCommGrpCat.{u}` has limits of shape `J`. -/]
instance hasLimitsOfShape [Small.{u} J] : HasLimitsOfShape J CommGrpCat.{u} where
has_limit _ := inferInstance
/-- The category of commutative groups has all limits. -/
@[to_additive (relevant_arg := 100)
/-- The category of additive commutative groups has all limits. -/]
instance hasLimitsOfSize [UnivLE.{v, u}] : HasLimitsOfSize.{w, v} CommGrpCat.{u} where
has_limits_of_shape _ _ := { }
@[to_additive]
instance hasLimits : HasLimits CommGrpCat.{u} :=
CommGrpCat.hasLimitsOfSize.{u, u}
@[to_additive]
instance forget₂Group_preservesLimit :
PreservesLimit F (forget₂ CommGrpCat.{u} GrpCat.{u}) where
preserves {c} hc := ⟨by
have : HasLimit (F ⋙ forget₂ CommGrpCat GrpCat) := by
rw [GrpCat.hasLimit_iff_small_sections]
change Small.{u} (F ⋙ forget CommGrpCat).sections
rw [← CommGrpCat.hasLimit_iff_small_sections]
exact ⟨_, hc⟩
exact isLimitOfPreserves _ hc⟩
@[to_additive]
instance forget₂Group_preservesLimitsOfShape :
PreservesLimitsOfShape J (forget₂ CommGrpCat.{u} GrpCat.{u}) where
/-- The forgetful functor from commutative groups to groups preserves all limits.
(That is, the underlying group could have been computed instead as limits in the category
of groups.)
-/
@[to_additive (relevant_arg := 100)
/-- The forgetful functor from additive commutative groups to additive groups preserves all
limits. (That is, the underlying group could have been computed instead as limits in the
category of additive groups.) -/]
instance forget₂Group_preservesLimitsOfSize :
PreservesLimitsOfSize.{w, v} (forget₂ CommGrpCat.{u} GrpCat.{u}) where
@[to_additive]
instance forget₂Group_preservesLimits :
PreservesLimits (forget₂ CommGrpCat GrpCat.{u}) :=
CommGrpCat.forget₂Group_preservesLimitsOfSize.{u, u}
/-- An auxiliary declaration to speed up typechecking. -/
@[to_additive AddCommGrpCat.forget₂AddCommMon_preservesLimitsAux
/-- An auxiliary declaration to speed up typechecking. -/]
noncomputable def forget₂CommMon_preservesLimitsAux
[Small.{u} (F ⋙ forget CommGrpCat).sections] :
IsLimit ((forget₂ CommGrpCat.{u} CommMonCat.{u}).mapCone (limitCone.{v, u} F)) :=
letI : Small.{u} (Functor.sections ((F ⋙ forget₂ _ CommMonCat) ⋙ forget CommMonCat)) :=
inferInstanceAs <| Small (Functor.sections (F ⋙ forget CommGrpCat))
CommMonCat.limitConeIsLimit.{v, u} (F ⋙ forget₂ CommGrpCat.{u} CommMonCat.{u})
/-- If `J` is `u`-small, the forgetful functor from `CommGrpCat.{u}` to `CommMonCat.{u}`
preserves limits of shape `J`. -/
@[to_additive AddCommGrpCat.forget₂AddCommMon_preservesLimitsOfShape
/-- If `J` is `u`-small, the forgetful functor from `AddCommGrpCat.{u}`
to `AddCommMonCat.{u}` preserves limits of shape `J`. -/]
instance forget₂CommMon_preservesLimitsOfShape [Small.{u} J] :
PreservesLimitsOfShape J (forget₂ CommGrpCat.{u} CommMonCat.{u}) where
preservesLimit {F} := preservesLimit_of_preserves_limit_cone (limitConeIsLimit.{v, u} F)
(forget₂CommMon_preservesLimitsAux.{v, u} F)
/-- The forgetful functor from commutative groups to commutative monoids preserves all limits.
(That is, the underlying commutative monoids could have been computed instead as limits
in the category of commutative monoids.)
-/
@[to_additive AddCommGrpCat.forget₂AddCommMon_preservesLimitsOfSize
/-- The forgetful functor from additive commutative groups to additive commutative monoids
preserves all limits. (That is, the underlying additive commutative monoids could have been
computed instead as limits in the category of additive commutative monoids.) -/]
instance forget₂CommMon_preservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget₂ CommGrpCat CommMonCat.{u}) where
preservesLimitsOfShape := { }
/-- If `J` is `u`-small, the forgetful functor from `CommGrpCat.{u}` preserves limits of
shape `J`. -/
@[to_additive /-- If `J` is `u`-small, the forgetful functor from `AddCommGrpCat.{u}`
preserves limits of shape `J`. -/]
instance forget_preservesLimitsOfShape [Small.{u} J] :
PreservesLimitsOfShape J (forget CommGrpCat.{u}) where
preservesLimit {F} := preservesLimit_of_preserves_limit_cone (limitConeIsLimit F)
(Types.Small.limitConeIsLimit (F ⋙ forget _))
/-- The forgetful functor from commutative groups to types preserves all limits. (That is, the
underlying types could have been computed instead as limits in the category of types.)
-/
@[to_additive
/-- The forgetful functor from additive commutative groups to types preserves all limits.
(That is, the underlying types could have been computed instead as limits in the category of
types.) -/]
instance forget_preservesLimitsOfSize :
PreservesLimitsOfSize.{w, v} (forget CommGrpCat.{u}) := inferInstance
noncomputable instance _root_.AddCommGrpCat.forget_preservesLimits :
PreservesLimits (forget AddCommGrpCat.{u}) :=
AddCommGrpCat.forget_preservesLimitsOfSize.{u, u}
@[to_additive existing]
noncomputable instance forget_preservesLimits : PreservesLimits (forget CommGrpCat.{u}) :=
CommGrpCat.forget_preservesLimitsOfSize.{u, u}
@[to_additive]
noncomputable instance forget_createsLimit :
CreatesLimit F (forget CommGrpCat.{u}) := by
set e : forget₂ CommGrpCat.{u} GrpCat.{u} ⋙ forget GrpCat.{u} ≅ forget CommGrpCat.{u} := .refl _
exact createsLimitOfNatIso e
@[to_additive]
noncomputable instance forget_createsLimitsOfShape (J : Type v) [Category.{w} J] :
CreatesLimitsOfShape J (forget CommGrpCat.{u}) where
CreatesLimit := inferInstance
/-- The forgetful functor from commutative groups to types creates all limits.
-/
@[to_additive (relevant_arg := 100)
/-- The forgetful functor from additive commutative groups to types creates all limits. -/]
noncomputable instance forget_createsLimitsOfSize :
CreatesLimitsOfSize.{w, v} (forget CommGrpCat.{u}) where
CreatesLimitsOfShape := inferInstance
-- Verify we can form limits indexed over smaller categories.
example (f : ℕ → AddCommGrpCat) : HasProduct f := by infer_instance
end CommGrpCat
namespace AddCommGrpCat
/-- The categorical kernel of a morphism in `AddCommGrpCat`
agrees with the usual group-theoretical kernel.
-/
def kernelIsoKer {G H : AddCommGrpCat.{u}} (f : G ⟶ H) :
kernel f ≅ AddCommGrpCat.of f.hom.ker where
hom := ofHom
{ toFun := fun g => ⟨kernel.ι f g, ConcreteCategory.congr_hom (kernel.condition f) g⟩
map_zero' := by
refine Subtype.ext ?_
simp only [map_zero, ZeroMemClass.coe_zero]
map_add' := fun g g' => by
refine Subtype.ext ?_
simp }
inv := kernel.lift f (ofHom (AddSubgroup.subtype f.hom.ker)) <| by ext x; exact x.2
hom_inv_id := by
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): it would be nice to do the next two steps by a single `ext`,
-- but this will require thinking carefully about the relative priorities of `@[ext]` lemmas.
refine equalizer.hom_ext ?_
ext
simp
inv_hom_id := by
apply AddCommGrpCat.ext
rintro ⟨x, mem⟩
refine Subtype.ext ?_
apply ConcreteCategory.congr_hom (kernel.lift_ι f _ _)
@[simp]
theorem kernelIsoKer_hom_comp_subtype {G H : AddCommGrpCat.{u}} (f : G ⟶ H) :
(kernelIsoKer f).hom ≫ ofHom (AddSubgroup.subtype f.hom.ker) = kernel.ι f := by ext; rfl
@[simp]
theorem kernelIsoKer_inv_comp_ι {G H : AddCommGrpCat.{u}} (f : G ⟶ H) :
(kernelIsoKer f).inv ≫ kernel.ι f = ofHom (AddSubgroup.subtype f.hom.ker) := by
simp [kernelIsoKer]
/-- The categorical kernel inclusion for `f : G ⟶ H`, as an object over `G`,
agrees with the `AddSubgroup.subtype` map.
-/
def kernelIsoKerOver {G H : AddCommGrpCat.{u}} (f : G ⟶ H) :
Over.mk (kernel.ι f) ≅ @Over.mk _ _ G (AddCommGrpCat.of f.hom.ker)
(ofHom (AddSubgroup.subtype f.hom.ker)) :=
Over.isoMk (kernelIsoKer f)
end AddCommGrpCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/Adjunctions.lean | import Mathlib.Algebra.Category.Grp.Preadditive
import Mathlib.GroupTheory.FreeAbelianGroup
import Mathlib.CategoryTheory.Adjunction.Limits
import Mathlib.CategoryTheory.Limits.Types.Coproducts
/-!
# Adjunctions regarding the category of (abelian) groups
This file contains construction of basic adjunctions concerning the category of groups and the
category of abelian groups.
## Main definitions
* `AddCommGrpCat.free`: constructs the functor associating to a type `X` the free abelian group
with generators `x : X`.
* `GrpCat.free`: constructs the functor associating to a type `X` the free group with
generators `x : X`.
* `GrpCat.abelianize`: constructs the functor which sends a group `G` to its abelianization `Gᵃᵇ`.
## Main statements
* `AddCommGrpCat.adj`: proves that `AddCommGrpCat.free` is the left adjoint
of the forgetful functor from abelian groups to types.
* `GrpCat.adj`: proves that `GrpCat.free` is the left adjoint of the forgetful functor
from groups to types.
* `abelianizeAdj`: proves that `GrpCat.abelianize` is left adjoint to the forgetful functor from
abelian groups to groups.
-/
assert_not_exists Cardinal
noncomputable section
universe u
open CategoryTheory Limits
namespace AddCommGrpCat
/-- The free functor `Type u ⥤ AddCommGroup` sending a type `X` to the
free abelian group with generators `x : X`.
-/
def free : Type u ⥤ AddCommGrpCat where
obj α := of (FreeAbelianGroup α)
map f := ofHom (FreeAbelianGroup.map f)
map_id _ := AddCommGrpCat.ext FreeAbelianGroup.map_id_apply
map_comp _ _ := AddCommGrpCat.ext FreeAbelianGroup.map_comp_apply
@[simp]
theorem free_obj_coe {α : Type u} : (free.obj α : Type u) = FreeAbelianGroup α :=
rfl
-- This currently can't be a `simp` lemma,
-- because `free_obj_coe` will simplify implicit arguments in the LHS.
-- (The `simpNF` linter will, correctly, complain.)
theorem free_map_coe {α β : Type u} {f : α → β} (x : FreeAbelianGroup α) :
(free.map f) x = f <$> x :=
rfl
/-- The free-forgetful adjunction for abelian groups.
-/
def adj : free ⊣ forget AddCommGrpCat.{u} :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun _ _ => ConcreteCategory.homEquiv.trans FreeAbelianGroup.lift.symm
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): used to be just `by intros; ext; rfl`.
homEquiv_naturality_left_symm := by
intros
ext
simpa using FreeAbelianGroup.lift_comp .. }
instance : free.{u}.IsLeftAdjoint :=
⟨_, ⟨adj⟩⟩
instance : (forget AddCommGrpCat.{u}).IsRightAdjoint :=
⟨_, ⟨adj⟩⟩
/-- As an example, we now give a high-powered proof that
the monomorphisms in `AddCommGroup` are just the injective functions.
(This proof works in all universes.)
-/
example {G H : AddCommGrpCat.{u}} (f : G ⟶ H) [Mono f] : Function.Injective f :=
(mono_iff_injective (f : G → H)).mp (Functor.map_mono (forget AddCommGrpCat) f)
instance : (free.{u}).PreservesMonomorphisms where
preserves {X Y} f _ := by
by_cases! hX : IsEmpty X
· constructor
intros
apply (IsInitial.isInitialObj free _
((Types.initial_iff_empty X).2 hX).some).isZero.eq_of_tgt
· have hf : Function.Injective f := by rwa [← mono_iff_injective]
obtain ⟨g, hg⟩ := hf.hasLeftInverse
have : IsSplitMono f := IsSplitMono.mk' { retraction := g }
infer_instance
end AddCommGrpCat
namespace GrpCat
/-- The free functor `Type u ⥤ Group` sending a type `X` to the free group with generators `x : X`.
-/
def free : Type u ⥤ GrpCat where
obj α := of (FreeGroup α)
map f := ofHom (FreeGroup.map f)
/-- The free-forgetful adjunction for groups.
-/
def adj : free ⊣ forget GrpCat.{u} :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun _ _ => ConcreteCategory.homEquiv.trans FreeGroup.lift.symm
homEquiv_naturality_left_symm := by
intros
ext : 1
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `ext` doesn't apply this theorem anymore
apply FreeGroup.ext_hom
intros
rfl }
instance : (forget GrpCat.{u}).IsRightAdjoint :=
⟨_, ⟨adj⟩⟩
section Abelianization
/-- The abelianization functor `Group ⥤ CommGroup` sending a group `G` to its abelianization `Gᵃᵇ`.
-/
def abelianize : GrpCat.{u} ⥤ CommGrpCat.{u} where
obj G := CommGrpCat.of (Abelianization G)
map f := CommGrpCat.ofHom (Abelianization.lift (Abelianization.of.comp f.hom))
map_id := by
intros
ext : 1
apply (Equiv.apply_eq_iff_eq_symm_apply Abelianization.lift).mpr
rfl
map_comp := by
intros
ext : 1
apply (Equiv.apply_eq_iff_eq_symm_apply Abelianization.lift).mpr
rfl
/-- The abelianization-forgetful adjunction from `Group` to `CommGroup`. -/
def abelianizeAdj : abelianize ⊣ forget₂ CommGrpCat.{u} GrpCat.{u} :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun _ _ => ((ConcreteCategory.homEquiv (C := CommGrpCat)).trans
Abelianization.lift.symm).trans
(ConcreteCategory.homEquiv (C := GrpCat)).symm
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): used to be just `by intros; ext1; rfl`.
homEquiv_naturality_left_symm := by
intros
ext
simp only
apply Eq.symm
apply Abelianization.lift_unique
intros
apply Abelianization.lift_apply_of }
end Abelianization
end GrpCat
/-- The functor taking a monoid to its subgroup of units. -/
@[simps!]
def MonCat.units : MonCat.{u} ⥤ GrpCat.{u} where
obj R := GrpCat.of Rˣ
map f := GrpCat.ofHom <| Units.map f.hom
map_id _ := GrpCat.ext fun _ => Units.ext rfl
map_comp _ _ := GrpCat.ext fun _ => Units.ext rfl
/-- The forgetful-units adjunction between `GrpCat` and `MonCat`. -/
def GrpCat.forget₂MonAdj : forget₂ GrpCat MonCat ⊣ MonCat.units.{u} := Adjunction.mk' {
homEquiv _ Y :=
{ toFun f := ofHom (MonoidHom.toHomUnits f.hom)
invFun f := MonCat.ofHom ((Units.coeHom Y).comp f.hom) }
unit :=
{ app X := ofHom (@toUnits X _)
naturality _ _ _ := GrpCat.ext fun _ => Units.ext rfl }
counit :=
{ app X := MonCat.ofHom (Units.coeHom X)
naturality _ _ _ := MonCat.ext fun _ => rfl } }
instance : MonCat.units.{u}.IsRightAdjoint :=
⟨_, ⟨GrpCat.forget₂MonAdj⟩⟩
/-- The functor taking a monoid to its subgroup of units. -/
@[simps!]
def CommMonCat.units : CommMonCat.{u} ⥤ CommGrpCat.{u} where
obj R := CommGrpCat.of Rˣ
map f := CommGrpCat.ofHom <| Units.map f.hom
map_id _ := CommGrpCat.ext fun _ => Units.ext rfl
map_comp _ _ := CommGrpCat.ext fun _ => Units.ext rfl
/-- The forgetful-units adjunction between `CommGrpCat` and `CommMonCat`. -/
def CommGrpCat.forget₂CommMonAdj : forget₂ CommGrpCat CommMonCat ⊣ CommMonCat.units.{u} :=
Adjunction.mk' {
homEquiv := fun _ Y ↦
{ toFun f := ofHom (MonoidHom.toHomUnits f.hom)
invFun f := CommMonCat.ofHom ((Units.coeHom Y).comp f.hom) }
unit.app X := ofHom toUnits.toMonoidHom
-- `aesop` can find the following proof but it takes `0.5`s.
unit.naturality _ _ _ := CommGrpCat.ext fun _ => Units.ext rfl
counit.app X := CommMonCat.ofHom (Units.coeHom X)
-- `aesop` can find the following proof but it takes `0.5`s.
counit.naturality _ _ _ := CommMonCat.ext fun _ => rfl
-- `aesop` can find the following proof but it takes `0.2`s.
homEquiv_unit := by intros; rfl
-- `aesop` can find the following proof but it takes `0.2`s.
homEquiv_counit := by intros; rfl }
instance : CommMonCat.units.{u}.IsRightAdjoint :=
⟨_, ⟨CommGrpCat.forget₂CommMonAdj⟩⟩ |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/Images.lean | import Mathlib.Algebra.Category.Grp.Abelian
import Mathlib.CategoryTheory.Limits.Shapes.Images
/-!
# The category of commutative additive groups has images.
Note that we don't need to register any of the constructions here as instances, because we get them
from the fact that `AddCommGrpCat` is an abelian category.
-/
open CategoryTheory
open CategoryTheory.Limits
universe u
namespace AddCommGrpCat
-- Note that because `injective_of_mono` is currently only proved in `Type 0`,
-- we restrict to the lowest universe here for now.
variable {G H : AddCommGrpCat.{0}} (f : G ⟶ H)
attribute [local ext] Subtype.ext
section
-- implementation details of `IsImage` for `AddCommGrpCat`; use the API, not these
/-- the image of a morphism in `AddCommGrpCat` is just the bundling of `AddMonoidHom.range f` -/
def image : AddCommGrpCat :=
AddCommGrpCat.of (AddMonoidHom.range f.hom)
/-- the inclusion of `image f` into the target -/
def image.ι : image f ⟶ H :=
ofHom f.hom.range.subtype
instance : Mono (image.ι f) :=
ConcreteCategory.mono_of_injective (image.ι f) Subtype.val_injective
/-- the corestriction map to the image -/
def factorThruImage : G ⟶ image f :=
ofHom f.hom.rangeRestrict
theorem image.fac : factorThruImage f ≫ image.ι f = f := by
ext
rfl
attribute [local simp] image.fac
variable {f}
/-- the universal property for the image factorisation -/
noncomputable def image.lift (F' : MonoFactorisation f) : image f ⟶ F'.I :=
ofHom
{ toFun := (fun x => F'.e (Classical.indefiniteDescription _ x.2).1 : image f → F'.I)
map_zero' := by
haveI := F'.m_mono
apply injective_of_mono F'.m
change (F'.e ≫ F'.m) _ = _
rw [F'.fac, AddMonoidHom.map_zero]
exact (Classical.indefiniteDescription (fun y => f y = 0) _).2
map_add' := by
intro x y
haveI := F'.m_mono
apply injective_of_mono F'.m
rw [AddMonoidHom.map_add]
change (F'.e ≫ F'.m) _ = (F'.e ≫ F'.m) _ + (F'.e ≫ F'.m) _
rw [F'.fac]
rw [(Classical.indefiniteDescription (fun z => f z = _) _).2]
rw [(Classical.indefiniteDescription (fun z => f z = _) _).2]
rw [(Classical.indefiniteDescription (fun z => f z = _) _).2]
rfl }
theorem image.lift_fac (F' : MonoFactorisation f) : image.lift F' ≫ F'.m = image.ι f := by
ext x
change (F'.e ≫ F'.m) _ = _
rw [F'.fac, (Classical.indefiniteDescription _ x.2).2]
rfl
end
/-- the factorisation of any morphism in `AddCommGrpCat` through a mono. -/
def monoFactorisation : MonoFactorisation f where
I := image f
m := image.ι f
e := factorThruImage f
/-- the factorisation of any morphism in `AddCommGrpCat` through a mono has
the universal property of the image. -/
noncomputable def isImage : IsImage (monoFactorisation f) where
lift := image.lift
lift_fac := image.lift_fac
/-- The categorical image of a morphism in `AddCommGrpCat`
agrees with the usual group-theoretical range.
-/
noncomputable def imageIsoRange {G H : AddCommGrpCat.{0}} (f : G ⟶ H) :
Limits.image f ≅ AddCommGrpCat.of f.hom.range :=
IsImage.isoExt (Image.isImage f) (isImage f)
end AddCommGrpCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/Zero.lean | import Mathlib.Algebra.Category.Grp.Basic
import Mathlib.CategoryTheory.Limits.Shapes.ZeroObjects
/-!
# The category of (commutative) (additive) groups has a zero object.
`AddCommGroup` also has zero morphisms. For definitional reasons, we infer this from preadditivity
rather than from the existence of a zero object.
-/
open CategoryTheory
open CategoryTheory.Limits
universe u
namespace GrpCat
@[to_additive]
theorem isZero_of_subsingleton (G : GrpCat) [Subsingleton G] : IsZero G := by
refine ⟨fun X => ⟨⟨⟨1⟩, fun f => ?_⟩⟩, fun X => ⟨⟨⟨1⟩, fun f => ?_⟩⟩⟩
· ext x
have : x = 1 := Subsingleton.elim _ _
rw [this, map_one, map_one]
· ext
subsingleton
@[to_additive AddGrpCat.hasZeroObject]
instance : HasZeroObject GrpCat :=
⟨⟨of PUnit, isZero_of_subsingleton _⟩⟩
end GrpCat
namespace CommGrpCat
@[to_additive]
theorem isZero_of_subsingleton (G : CommGrpCat) [Subsingleton G] : IsZero G := by
refine ⟨fun X => ⟨⟨⟨1⟩, fun f => ?_⟩⟩, fun X => ⟨⟨⟨1⟩, fun f => ?_⟩⟩⟩
· ext x
have : x = 1 := Subsingleton.elim _ _
rw [this, map_one, map_one]
· ext
subsingleton
@[to_additive AddCommGrpCat.hasZeroObject]
instance : HasZeroObject CommGrpCat :=
⟨⟨of PUnit, isZero_of_subsingleton _⟩⟩
end CommGrpCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Grp/EquivalenceGroupAddGroup.lean | import Mathlib.Algebra.Category.Grp.Basic
/-!
# Equivalence between `Group` and `AddGroup`
This file contains two equivalences:
* `groupAddGroupEquivalence` : the equivalence between `GrpCat` and `AddGrpCat` by sending
`X : GrpCat` to `Additive X` and `Y : AddGrpCat` to `Multiplicative Y`.
* `commGroupAddCommGroupEquivalence` : the equivalence between `CommGrpCat` and `AddCommGrpCat`
by sending `X : CommGrpCat` to `Additive X` and `Y : AddCommGrpCat` to `Multiplicative Y`.
-/
open CategoryTheory
namespace GrpCat
/-- The functor `GrpCat ⥤ AddGrpCat` by sending `X ↦ Additive X` and `f ↦ f`.
-/
@[simps]
def toAddGrp : GrpCat ⥤ AddGrpCat where
obj X := AddGrpCat.of (Additive X)
map {_} {_} f := AddGrpCat.ofHom f.hom.toAdditive
end GrpCat
namespace CommGrpCat
/-- The functor `CommGrpCat ⥤ AddCommGrpCat` by sending `X ↦ Additive X` and `f ↦ f`.
-/
@[simps]
def toAddCommGrp : CommGrpCat ⥤ AddCommGrpCat where
obj X := AddCommGrpCat.of (Additive X)
map {_} {_} f := AddCommGrpCat.ofHom f.hom.toAdditive
end CommGrpCat
namespace AddGrpCat
/-- The functor `AddGrpCat ⥤ GrpCat` by sending `X ↦ Multiplicative X` and `f ↦ f`.
-/
@[simps]
def toGrp : AddGrpCat ⥤ GrpCat where
obj X := GrpCat.of (Multiplicative X)
map {_} {_} f := GrpCat.ofHom f.hom.toMultiplicative
end AddGrpCat
namespace AddCommGrpCat
/-- The functor `AddCommGrpCat ⥤ CommGrpCat` by sending `X ↦ Multiplicative X` and `f ↦ f`.
-/
@[simps]
def toCommGrp : AddCommGrpCat ⥤ CommGrpCat where
obj X := CommGrpCat.of (Multiplicative X)
map {_} {_} f := CommGrpCat.ofHom f.hom.toMultiplicative
end AddCommGrpCat
/-- The equivalence of categories between `GrpCat` and `AddGrpCat`
-/
@[simps]
def groupAddGroupEquivalence : GrpCat ≌ AddGrpCat where
functor := GrpCat.toAddGrp
inverse := AddGrpCat.toGrp
unitIso := Iso.refl _
counitIso := Iso.refl _
/-- The equivalence of categories between `CommGrpCat` and `AddCommGrpCat`.
-/
@[simps]
def commGroupAddCommGroupEquivalence : CommGrpCat ≌ AddCommGrpCat where
functor := CommGrpCat.toAddCommGrp
inverse := AddCommGrpCat.toCommGrp
unitIso := Iso.refl _
counitIso := Iso.refl _ |
.lake/packages/mathlib/Mathlib/Algebra/Category/AlgCat/Monoidal.lean | import Mathlib.CategoryTheory.Monoidal.Transport
import Mathlib.Algebra.Category.AlgCat.Basic
import Mathlib.Algebra.Category.ModuleCat.Monoidal.Basic
import Mathlib.RingTheory.TensorProduct.Maps
/-!
# The monoidal category structure on R-algebras
-/
open CategoryTheory
open scoped MonoidalCategory
universe v u
variable {R : Type u} [CommRing R]
namespace AlgCat
noncomputable section
namespace instMonoidalCategory
open scoped TensorProduct
/-- Auxiliary definition used to fight a timeout when building
`AlgCat.instMonoidalCategory`. -/
@[simps!]
noncomputable abbrev tensorObj (X Y : AlgCat.{u} R) : AlgCat.{u} R :=
of R (X ⊗[R] Y)
/-- Auxiliary definition used to fight a timeout when building
`AlgCat.instMonoidalCategory`. -/
noncomputable abbrev tensorHom {W X Y Z : AlgCat.{u} R} (f : W ⟶ X) (g : Y ⟶ Z) :
tensorObj W Y ⟶ tensorObj X Z :=
ofHom <| Algebra.TensorProduct.map f.hom g.hom
open MonoidalCategory
end instMonoidalCategory
open instMonoidalCategory
instance : MonoidalCategoryStruct (AlgCat.{u} R) where
tensorObj := instMonoidalCategory.tensorObj
whiskerLeft X _ _ f := tensorHom (𝟙 X) f
whiskerRight {X₁ X₂} (f : X₁ ⟶ X₂) Y := tensorHom f (𝟙 Y)
tensorHom := tensorHom
tensorUnit := of R R
associator X Y Z := (Algebra.TensorProduct.assoc R R X Y Z).toAlgebraIso
leftUnitor X := (Algebra.TensorProduct.lid R X).toAlgebraIso
rightUnitor X := (Algebra.TensorProduct.rid R R X).toAlgebraIso
theorem hom_tensorHom {K L M N : AlgCat.{u} R} (f : K ⟶ L) (g : M ⟶ N) :
(f ⊗ₘ g).hom = Algebra.TensorProduct.map f.hom g.hom :=
rfl
theorem hom_whiskerLeft (L : AlgCat.{u} R) {M N : AlgCat.{u} R} (f : M ⟶ N) :
(L ◁ f).hom = Algebra.TensorProduct.map (.id _ _) f.hom :=
rfl
theorem hom_whiskerRight {L M : AlgCat.{u} R} (f : L ⟶ M) (N : AlgCat.{u} R) :
(f ▷ N).hom = Algebra.TensorProduct.map f.hom (.id _ _) :=
rfl
theorem hom_hom_leftUnitor {M : AlgCat.{u} R} :
(λ_ M).hom.hom = (Algebra.TensorProduct.lid _ _).toAlgHom :=
rfl
theorem hom_inv_leftUnitor {M : AlgCat.{u} R} :
(λ_ M).inv.hom = (Algebra.TensorProduct.lid _ _).symm.toAlgHom :=
rfl
theorem hom_hom_rightUnitor {M : AlgCat.{u} R} :
(ρ_ M).hom.hom = (Algebra.TensorProduct.rid _ _ _).toAlgHom :=
rfl
theorem hom_inv_rightUnitor {M : AlgCat.{u} R} :
(ρ_ M).inv.hom = (Algebra.TensorProduct.rid _ _ _).symm.toAlgHom :=
rfl
theorem hom_hom_associator {M N K : AlgCat.{u} R} :
(α_ M N K).hom.hom = (Algebra.TensorProduct.assoc R R M N K).toAlgHom :=
rfl
theorem hom_inv_associator {M N K : AlgCat.{u} R} :
(α_ M N K).inv.hom = (Algebra.TensorProduct.assoc R R M N K).symm.toAlgHom :=
rfl
noncomputable instance instMonoidalCategory : MonoidalCategory (AlgCat.{u} R) :=
Monoidal.induced
(forget₂ (AlgCat R) (ModuleCat R))
{ μIso := fun _ _ => Iso.refl _
εIso := Iso.refl _
associator_eq := fun _ _ _ =>
ModuleCat.hom_ext <| TensorProduct.ext_threefold (fun _ _ _ => rfl)
leftUnitor_eq := fun _ => ModuleCat.hom_ext <| TensorProduct.ext' (fun _ _ => rfl)
rightUnitor_eq := fun _ => ModuleCat.hom_ext <| TensorProduct.ext' (fun _ _ => rfl) }
/-- `forget₂ (AlgCat R) (ModuleCat R)` as a monoidal functor. -/
example : (forget₂ (AlgCat R) (ModuleCat R)).Monoidal := inferInstance
end
end AlgCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/AlgCat/Basic.lean | import Mathlib.Algebra.Algebra.Subalgebra.Basic
import Mathlib.Algebra.FreeAlgebra
import Mathlib.Algebra.Category.Ring.Basic
import Mathlib.Algebra.Category.ModuleCat.Basic
/-!
# Category instance for algebras over a commutative ring
We introduce the bundled category `AlgCat` of algebras over a fixed commutative ring `R` along
with the forgetful functors to `RingCat` and `ModuleCat`. We furthermore show that the functor
associating to a type the free `R`-algebra on that type is left adjoint to the forgetful functor.
-/
open CategoryTheory Limits
universe v u
variable (R : Type u) [CommRing R]
/-- The category of R-algebras and their morphisms. -/
structure AlgCat where
private mk ::
/-- The underlying type. -/
carrier : Type v
[isRing : Ring carrier]
[isAlgebra : Algebra R carrier]
attribute [instance] AlgCat.isRing AlgCat.isAlgebra
initialize_simps_projections AlgCat (-isRing, -isAlgebra)
namespace AlgCat
instance : CoeSort (AlgCat R) (Type v) :=
⟨AlgCat.carrier⟩
attribute [coe] AlgCat.carrier
/-- The object in the category of R-algebras associated to a type equipped with the appropriate
typeclasses. This is the preferred way to construct a term of `AlgCat R`. -/
abbrev of (X : Type v) [Ring X] [Algebra R X] : AlgCat.{v} R :=
⟨X⟩
lemma coe_of (X : Type v) [Ring X] [Algebra R X] : (of R X : Type v) = X :=
rfl
variable {R} in
/-- The type of morphisms in `AlgCat R`. -/
@[ext]
structure Hom (A B : AlgCat.{v} R) where
private mk ::
/-- The underlying algebra map. -/
hom' : A →ₐ[R] B
instance : Category (AlgCat.{v} R) where
Hom A B := Hom A B
id A := ⟨AlgHom.id R A⟩
comp f g := ⟨g.hom'.comp f.hom'⟩
instance : ConcreteCategory (AlgCat.{v} R) (· →ₐ[R] ·) where
hom := Hom.hom'
ofHom := Hom.mk
variable {R} in
/-- Turn a morphism in `AlgCat` back into an `AlgHom`. -/
abbrev Hom.hom {A B : AlgCat.{v} R} (f : Hom A B) :=
ConcreteCategory.hom (C := AlgCat R) f
variable {R} in
/-- Typecheck an `AlgHom` as a morphism in `AlgCat`. -/
abbrev ofHom {A B : Type v} [Ring A] [Ring B] [Algebra R A] [Algebra R B] (f : A →ₐ[R] B) :
of R A ⟶ of R B :=
ConcreteCategory.ofHom (C := AlgCat R) f
variable {R} in
/-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/
def Hom.Simps.hom (A B : AlgCat.{v} R) (f : Hom A B) :=
f.hom
initialize_simps_projections Hom (hom' → hom)
/-!
The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`.
-/
@[simp]
lemma hom_id {A : AlgCat.{v} R} : (𝟙 A : A ⟶ A).hom = AlgHom.id R A := rfl
/- Provided for rewriting. -/
lemma id_apply (A : AlgCat.{v} R) (a : A) :
(𝟙 A : A ⟶ A) a = a := by simp
@[simp]
lemma hom_comp {A B C : AlgCat.{v} R} (f : A ⟶ B) (g : B ⟶ C) :
(f ≫ g).hom = g.hom.comp f.hom := rfl
/- Provided for rewriting. -/
lemma comp_apply {A B C : AlgCat.{v} R} (f : A ⟶ B) (g : B ⟶ C) (a : A) :
(f ≫ g) a = g (f a) := by simp
@[ext]
lemma hom_ext {A B : AlgCat.{v} R} {f g : A ⟶ B} (hf : f.hom = g.hom) : f = g :=
Hom.ext hf
@[simp]
lemma hom_ofHom {R : Type u} [CommRing R] {X Y : Type v} [Ring X] [Algebra R X] [Ring Y]
[Algebra R Y] (f : X →ₐ[R] Y) : (ofHom f).hom = f := rfl
@[simp]
lemma ofHom_hom {A B : AlgCat.{v} R} (f : A ⟶ B) :
ofHom (Hom.hom f) = f := rfl
@[simp]
lemma ofHom_id {X : Type v} [Ring X] [Algebra R X] : ofHom (AlgHom.id R X) = 𝟙 (of R X) := rfl
@[simp]
lemma ofHom_comp {X Y Z : Type v} [Ring X] [Ring Y] [Ring Z] [Algebra R X] [Algebra R Y]
[Algebra R Z] (f : X →ₐ[R] Y) (g : Y →ₐ[R] Z) :
ofHom (g.comp f) = ofHom f ≫ ofHom g :=
rfl
lemma ofHom_apply {R : Type u} [CommRing R] {X Y : Type v} [Ring X] [Algebra R X] [Ring Y]
[Algebra R Y] (f : X →ₐ[R] Y) (x : X) : ofHom f x = f x := rfl
lemma inv_hom_apply {A B : AlgCat.{v} R} (e : A ≅ B) (x : A) : e.inv (e.hom x) = x := by
simp
lemma hom_inv_apply {A B : AlgCat.{v} R} (e : A ≅ B) (x : B) : e.hom (e.inv x) = x := by
simp
instance : Inhabited (AlgCat R) :=
⟨of R R⟩
lemma forget_obj {A : AlgCat.{v} R} : (forget (AlgCat.{v} R)).obj A = A := rfl
lemma forget_map {A B : AlgCat.{v} R} (f : A ⟶ B) :
(forget (AlgCat.{v} R)).map f = f :=
rfl
instance {S : AlgCat.{v} R} : Ring ((forget (AlgCat R)).obj S) :=
(inferInstance : Ring S.carrier)
instance {S : AlgCat.{v} R} : Algebra R ((forget (AlgCat R)).obj S) :=
(inferInstance : Algebra R S.carrier)
instance hasForgetToRing : HasForget₂ (AlgCat.{v} R) RingCat.{v} where
forget₂ :=
{ obj := fun A => RingCat.of A
map := fun f => RingCat.ofHom f.hom.toRingHom }
instance hasForgetToModule : HasForget₂ (AlgCat.{v} R) (ModuleCat.{v} R) where
forget₂ :=
{ obj := fun M => ModuleCat.of R M
map := fun f => ModuleCat.ofHom f.hom.toLinearMap }
@[simp]
lemma forget₂_module_obj (X : AlgCat.{v} R) :
(forget₂ (AlgCat.{v} R) (ModuleCat.{v} R)).obj X = ModuleCat.of R X :=
rfl
@[simp]
lemma forget₂_module_map {X Y : AlgCat.{v} R} (f : X ⟶ Y) :
(forget₂ (AlgCat.{v} R) (ModuleCat.{v} R)).map f = ModuleCat.ofHom f.hom.toLinearMap :=
rfl
variable {R} in
/-- Forgetting to the underlying type and then building the bundled object returns the original
algebra. -/
@[deprecated Iso.refl (since := "2025-05-15")]
def ofSelfIso (M : AlgCat.{v} R) : AlgCat.of R M ≅ M where
hom := 𝟙 M
inv := 𝟙 M
/-- The "free algebra" functor, sending a type `S` to the free algebra on `S`. -/
@[simps! obj map]
def free : Type u ⥤ AlgCat.{u} R where
obj S := of R (FreeAlgebra R S)
map f := ofHom <| FreeAlgebra.lift _ <| FreeAlgebra.ι _ ∘ f
/-- The free/forget adjunction for `R`-algebras. -/
def adj : free.{u} R ⊣ forget (AlgCat.{u} R) :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun _ _ =>
{ toFun := fun f ↦ (FreeAlgebra.lift _).symm f.hom
invFun := fun f ↦ ofHom <| (FreeAlgebra.lift _) f
left_inv := fun f ↦ by aesop
right_inv := fun f ↦ by simp [forget_obj] } }
instance : (forget (AlgCat.{u} R)).IsRightAdjoint := (adj R).isRightAdjoint
end AlgCat
variable {R}
variable {X₁ X₂ : Type u}
/-- Build an isomorphism in the category `AlgCat R` from a `AlgEquiv` between `Algebra`s. -/
@[simps]
def AlgEquiv.toAlgebraIso {g₁ : Ring X₁} {g₂ : Ring X₂} {m₁ : Algebra R X₁} {m₂ : Algebra R X₂}
(e : X₁ ≃ₐ[R] X₂) : AlgCat.of R X₁ ≅ AlgCat.of R X₂ where
hom := AlgCat.ofHom (e : X₁ →ₐ[R] X₂)
inv := AlgCat.ofHom (e.symm : X₂ →ₐ[R] X₁)
namespace CategoryTheory.Iso
/-- Build a `AlgEquiv` from an isomorphism in the category `AlgCat R`. -/
@[simps]
def toAlgEquiv {X Y : AlgCat R} (i : X ≅ Y) : X ≃ₐ[R] Y :=
{ i.hom.hom with
toFun := i.hom
invFun := i.inv
left_inv := fun x ↦ by simp
right_inv := fun x ↦ by simp }
end CategoryTheory.Iso
/-- Algebra equivalences between `Algebra`s are the same as (isomorphic to) isomorphisms in
`AlgCat`. -/
@[simps]
def algEquivIsoAlgebraIso {X Y : Type u} [Ring X] [Ring Y] [Algebra R X] [Algebra R Y] :
(X ≃ₐ[R] Y) ≅ AlgCat.of R X ≅ AlgCat.of R Y where
hom e := e.toAlgebraIso
inv i := i.toAlgEquiv
instance AlgCat.forget_reflects_isos : (forget (AlgCat.{u} R)).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget (AlgCat.{u} R)).map f)
let e : X ≃ₐ[R] Y := { f.hom, i.toEquiv with }
exact e.toAlgebraIso.isIso_hom |
.lake/packages/mathlib/Mathlib/Algebra/Category/AlgCat/Symmetric.lean | import Mathlib.Algebra.Category.AlgCat.Monoidal
import Mathlib.Algebra.Category.ModuleCat.Monoidal.Symmetric
/-!
# The monoidal structure on `AlgCat` is symmetric.
In this file we show:
* `AlgCat.instSymmetricCategory : SymmetricCategory (AlgCat.{u} R)`
-/
open CategoryTheory
noncomputable section
universe v u
variable {R : Type u} [CommRing R]
namespace AlgCat
instance : BraidedCategory (AlgCat.{u} R) :=
.ofFaithful (forget₂ (AlgCat R) (ModuleCat R))
fun X Y ↦ (Algebra.TensorProduct.comm R X Y).toAlgebraIso
instance : (forget₂ (AlgCat R) (ModuleCat R)).Braided where
instance instSymmetricCategory : SymmetricCategory (AlgCat.{u} R) :=
.ofFaithful (forget₂ (AlgCat R) (ModuleCat R))
end AlgCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/AlgCat/Limits.lean | import Mathlib.Algebra.Algebra.Pi
import Mathlib.Algebra.Algebra.Shrink
import Mathlib.Algebra.Category.AlgCat.Basic
import Mathlib.Algebra.Category.ModuleCat.Basic
import Mathlib.Algebra.Category.ModuleCat.Limits
import Mathlib.Algebra.Category.Ring.Limits
/-!
# The category of R-algebras has all limits
Further, these limits are preserved by the forgetful functor --- that is,
the underlying types are just the limits in the category of types.
-/
open CategoryTheory Limits
universe v w u t
-- `u` is determined by the ring, so can come later
noncomputable section
namespace AlgCat
variable {R : Type u} [CommRing R]
variable {J : Type v} [Category.{t} J] (F : J ⥤ AlgCat.{w} R)
instance semiringObj (j) : Semiring ((F ⋙ forget (AlgCat R)).obj j) :=
inferInstanceAs <| Semiring (F.obj j)
instance algebraObj (j) :
Algebra R ((F ⋙ forget (AlgCat R)).obj j) :=
inferInstanceAs <| Algebra R (F.obj j)
/-- The flat sections of a functor into `AlgCat R` form a submodule of all sections.
-/
def sectionsSubalgebra : Subalgebra R (∀ j, F.obj j) :=
{ SemiRingCat.sectionsSubsemiring
(F ⋙ forget₂ (AlgCat R) RingCat.{w} ⋙ forget₂ RingCat SemiRingCat.{w}) with
algebraMap_mem' := fun r _ _ f => (F.map f).hom.commutes r }
instance (F : J ⥤ AlgCat.{w} R) : Ring (F ⋙ forget _).sections :=
inferInstanceAs <| Ring (sectionsSubalgebra F)
instance (F : J ⥤ AlgCat.{w} R) : Algebra R (F ⋙ forget _).sections :=
inferInstanceAs <| Algebra R (sectionsSubalgebra F)
variable [Small.{w} (F ⋙ forget (AlgCat.{w} R)).sections]
instance : Small.{w} (sectionsSubalgebra F) :=
inferInstanceAs <| Small.{w} (F ⋙ forget _).sections
instance limitSemiring :
Ring.{w} (Types.Small.limitCone.{v, w} (F ⋙ forget (AlgCat.{w} R))).pt :=
inferInstanceAs <| Ring (Shrink (sectionsSubalgebra F))
instance limitAlgebra :
Algebra R (Types.Small.limitCone (F ⋙ forget (AlgCat.{w} R))).pt :=
inferInstanceAs <| Algebra R (Shrink (sectionsSubalgebra F))
/-- `limit.π (F ⋙ forget (AlgCat R)) j` as a `AlgHom`. -/
def limitπAlgHom (j) :
(Types.Small.limitCone (F ⋙ forget (AlgCat R))).pt →ₐ[R]
(F ⋙ forget (AlgCat.{w} R)).obj j :=
letI : Small.{w}
(Functor.sections ((F ⋙ forget₂ _ RingCat ⋙ forget₂ _ SemiRingCat) ⋙ forget _)) :=
inferInstanceAs <| Small.{w} (F ⋙ forget _).sections
{ SemiRingCat.limitπRingHom
(F ⋙ forget₂ (AlgCat R) RingCat.{w} ⋙ forget₂ RingCat SemiRingCat.{w}) j with
toFun := (Types.Small.limitCone (F ⋙ forget (AlgCat.{w} R))).π.app j
commutes' := fun x => by
simp only [Types.Small.limitCone_π_app, ← Shrink.algEquiv_apply R,
Types.Small.limitCone_pt, AlgEquiv.commutes]
rfl
}
namespace HasLimits
-- The next two definitions are used in the construction of `HasLimits (AlgCat R)`.
-- After that, the limits should be constructed using the generic limits API,
-- e.g. `limit F`, `limit.cone F`, and `limit.isLimit F`.
/-- Construction of a limit cone in `AlgCat R`.
(Internal use only; use the limits API.)
-/
def limitCone : Cone F where
pt := AlgCat.of R (Types.Small.limitCone (F ⋙ forget _)).pt
π :=
{ app := fun j ↦ ofHom <| limitπAlgHom F j
naturality := fun _ _ f => by
ext : 1
exact AlgHom.coe_fn_injective ((Types.Small.limitCone (F ⋙ forget _)).π.naturality f) }
/-- Witness that the limit cone in `AlgCat R` is a limit cone.
(Internal use only; use the limits API.)
-/
def limitConeIsLimit : IsLimit (limitCone.{v, w} F) := by
refine
IsLimit.ofFaithful (forget (AlgCat R)) (Types.Small.limitConeIsLimit.{v, w} _)
(fun s => ofHom
{ toFun := _, map_one' := ?_, map_mul' := ?_, map_zero' := ?_, map_add' := ?_,
commutes' := ?_ })
(fun s => rfl)
· congr
ext j
simp only [Functor.mapCone_π_app, forget_map, map_one, Pi.one_apply]
· intro x y
ext j
simp only [Functor.comp_obj, forget_obj, Functor.mapCone_pt,
Functor.mapCone_π_app, forget_map, Equiv.symm_apply_apply,
Types.Small.limitCone_pt, equivShrink_symm_mul, EquivLike.coe_apply]
apply map_mul
· ext j
simp only [Functor.comp_obj, forget_obj, Functor.mapCone_pt,
Functor.mapCone_π_app, forget_map, Equiv.symm_apply_apply,
equivShrink_symm_zero, EquivLike.coe_apply]
apply map_zero
· intro x y
ext j
simp only [Functor.comp_obj, forget_obj, Functor.mapCone_pt,
Functor.mapCone_π_app, forget_map, Equiv.symm_apply_apply,
Types.Small.limitCone_pt, equivShrink_symm_add, EquivLike.coe_apply]
apply map_add
· intro r
simp only [Equiv.algebraMap_def, Equiv.symm_symm]
apply congrArg
apply Subtype.ext
ext j
exact (s.π.app j).hom.commutes r
end HasLimits
open HasLimits
/-- The category of R-algebras has all limits. -/
lemma hasLimitsOfSize [UnivLE.{v, w}] : HasLimitsOfSize.{t, v} (AlgCat.{w} R) :=
{ has_limits_of_shape := fun _ _ =>
{ has_limit := fun F => HasLimit.mk
{ cone := limitCone F
isLimit := limitConeIsLimit F } } }
instance hasLimits : HasLimits (AlgCat.{w} R) :=
AlgCat.hasLimitsOfSize.{w, w, u}
/-- The forgetful functor from R-algebras to rings preserves all limits.
-/
instance forget₂Ring_preservesLimitsOfSize [UnivLE.{v, w}] :
PreservesLimitsOfSize.{t, v} (forget₂ (AlgCat.{w} R) RingCat.{w}) where
preservesLimitsOfShape :=
{ preservesLimit := fun {K} ↦
preservesLimit_of_preserves_limit_cone (limitConeIsLimit K)
(RingCat.limitConeIsLimit.{v, w}
(_ ⋙ forget₂ (AlgCat.{w} R) RingCat.{w})) }
instance forget₂Ring_preservesLimits : PreservesLimits (forget₂ (AlgCat R) RingCat.{w}) :=
AlgCat.forget₂Ring_preservesLimitsOfSize.{w, w}
/-- The forgetful functor from R-algebras to R-modules preserves all limits.
-/
instance forget₂Module_preservesLimitsOfSize [UnivLE.{v, w}] : PreservesLimitsOfSize.{t, v}
(forget₂ (AlgCat.{w} R) (ModuleCat.{w} R)) where
preservesLimitsOfShape :=
{ preservesLimit := fun {K} ↦
preservesLimit_of_preserves_limit_cone (limitConeIsLimit K)
(ModuleCat.HasLimits.limitConeIsLimit
(K ⋙ forget₂ (AlgCat.{w} R) (ModuleCat.{w} R))) }
instance forget₂Module_preservesLimits :
PreservesLimits (forget₂ (AlgCat R) (ModuleCat.{w} R)) :=
AlgCat.forget₂Module_preservesLimitsOfSize.{w, w}
/-- The forgetful functor from R-algebras to types preserves all limits.
-/
instance forget_preservesLimitsOfSize [UnivLE.{v, w}] :
PreservesLimitsOfSize.{t, v} (forget (AlgCat.{w} R)) where
preservesLimitsOfShape :=
{ preservesLimit := fun {K} ↦
preservesLimit_of_preserves_limit_cone (limitConeIsLimit K)
(Types.Small.limitConeIsLimit.{v} (K ⋙ forget _)) }
instance forget_preservesLimits : PreservesLimits (forget (AlgCat.{w} R)) :=
AlgCat.forget_preservesLimitsOfSize.{w, w}
end AlgCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/BialgCat/Monoidal.lean | import Mathlib.Algebra.Category.AlgCat.Monoidal
import Mathlib.Algebra.Category.BialgCat.Basic
import Mathlib.Algebra.Category.CoalgCat.Monoidal
import Mathlib.RingTheory.Bialgebra.TensorProduct
/-!
# The monoidal structure on the category of bialgebras
In `Mathlib/RingTheory/Bialgebra/TensorProduct.lean`, given two `R`-bialgebras `A, B`, we define a
bialgebra instance on `A ⊗[R] B` as well as the tensor product of two `BialgHom`s as a
`BialgHom`, and the associator and left/right unitors for bialgebras as `BialgEquiv`s.
In this file, we declare a `MonoidalCategory` instance on the category of bialgebras, with data
fields given by the definitions in `Mathlib/RingTheory/Bialgebra/TensorProduct.lean`, and Prop
fields proved by pulling back the `MonoidalCategory` instance on the category of algebras,
using `Monoidal.induced`.
-/
universe u
namespace BialgCat
open CategoryTheory MonoidalCategory TensorProduct
variable (R : Type u) [CommRing R]
@[simps]
noncomputable instance instMonoidalCategoryStruct :
MonoidalCategoryStruct.{u} (BialgCat R) where
tensorObj X Y := of R (X ⊗[R] Y)
whiskerLeft X _ _ f := ofHom (f.1.lTensor X)
whiskerRight f X := ofHom (f.1.rTensor X)
tensorHom f g := ofHom (Bialgebra.TensorProduct.map f.1 g.1)
tensorUnit := of R R
associator X Y Z := (Bialgebra.TensorProduct.assoc R R X Y Z).toBialgIso
leftUnitor X := (Bialgebra.TensorProduct.lid R X).toBialgIso
rightUnitor X := (Bialgebra.TensorProduct.rid R R X).toBialgIso
/-- The data needed to induce a `MonoidalCategory` structure via
`BialgCat.instMonoidalCategoryStruct` and the forgetful functor to algebras. -/
@[simps]
noncomputable def MonoidalCategory.inducingFunctorData :
Monoidal.InducingFunctorData (forget₂ (BialgCat R) (AlgCat R)) where
μIso _ _ := Iso.refl _
whiskerLeft_eq _ _ _ _ := by ext; rfl
whiskerRight_eq _ _ := by ext; rfl
tensorHom_eq _ _ := by ext; rfl
εIso := Iso.refl _
associator_eq _ _ _ := AlgCat.hom_ext _ <| Algebra.TensorProduct.ext
(Algebra.TensorProduct.ext (by ext; rfl) (by ext; rfl)) (by ext; rfl)
leftUnitor_eq _ := AlgCat.hom_ext _ <| Algebra.TensorProduct.ext rfl (by ext; rfl)
rightUnitor_eq _ := AlgCat.hom_ext _ <| Algebra.TensorProduct.ext (by ext; rfl) rfl
noncomputable instance instMonoidalCategory : MonoidalCategory (BialgCat R) :=
Monoidal.induced (forget₂ _ (AlgCat R)) (MonoidalCategory.inducingFunctorData R)
/-- `forget₂ (BialgCat R) (AlgCat R)` as a monoidal functor. -/
noncomputable instance : (forget₂ (BialgCat R) (AlgCat R)).Monoidal where
/-- `forget₂ (BialgCat R) (CoalgCat R)` as a monoidal functor. -/
noncomputable instance : (forget₂ (BialgCat R) (CoalgCat R)).Monoidal :=
Functor.CoreMonoidal.toMonoidal {
εIso := Iso.refl _
μIso _ _ := Iso.refl _ }
end BialgCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/BialgCat/Basic.lean | import Mathlib.Algebra.Category.CoalgCat.Basic
import Mathlib.Algebra.Category.AlgCat.Basic
import Mathlib.RingTheory.Bialgebra.Equiv
/-!
# The category of bialgebras over a commutative ring
We introduce the bundled category `BialgCat` of bialgebras over a fixed commutative ring `R`
along with the forgetful functors to `CoalgCat` and `AlgCat`.
This file mimics `Mathlib/LinearAlgebra/QuadraticForm/QuadraticModuleCat.lean`.
-/
open CategoryTheory
universe v u
variable (R : Type u) [CommRing R]
/-- The category of `R`-bialgebras. -/
structure BialgCat where
/-- The underlying type. -/
carrier : Type v
[instRing : Ring carrier]
[instBialgebra : Bialgebra R carrier]
attribute [instance] BialgCat.instBialgebra BialgCat.instRing
variable {R}
namespace BialgCat
open Bialgebra
instance : CoeSort (BialgCat.{v} R) (Type v) :=
⟨(·.carrier)⟩
variable (R) in
/-- The object in the category of `R`-bialgebras associated to an `R`-bialgebra. -/
@[simps]
def of (X : Type v) [Ring X] [Bialgebra R X] :
BialgCat R where
carrier := X
@[simp]
lemma of_comul {X : Type v} [Ring X] [Bialgebra R X] :
Coalgebra.comul (A := of R X) = Coalgebra.comul (R := R) (A := X) := rfl
@[simp]
lemma of_counit {X : Type v} [Ring X] [Bialgebra R X] :
Coalgebra.counit (A := of R X) = Coalgebra.counit (R := R) (A := X) := rfl
/-- A type alias for `BialgHom` to avoid confusion between the categorical and
algebraic spellings of composition. -/
@[ext]
structure Hom (V W : BialgCat.{v} R) where
/-- The underlying `BialgHom` -/
toBialgHom' : V →ₐc[R] W
instance category : Category (BialgCat.{v} R) where
Hom X Y := Hom X Y
id X := ⟨BialgHom.id R X⟩
comp f g := ⟨BialgHom.comp g.toBialgHom' f.toBialgHom'⟩
instance concreteCategory : ConcreteCategory (BialgCat.{v} R) (· →ₐc[R] ·) where
hom f := f.toBialgHom'
ofHom f := ⟨f⟩
/-- Turn a morphism in `BialgCat` back into a `BialgHom`. -/
abbrev Hom.toBialgHom {X Y : BialgCat R} (f : Hom X Y) :=
ConcreteCategory.hom (C := BialgCat R) f
/-- Typecheck a `BialgHom` as a morphism in `BialgCat R`. -/
abbrev ofHom {X Y : Type v} [Ring X] [Ring Y]
[Bialgebra R X] [Bialgebra R Y] (f : X →ₐc[R] Y) :
of R X ⟶ of R Y :=
ConcreteCategory.ofHom f
lemma Hom.toBialgHom_injective (V W : BialgCat.{v} R) :
Function.Injective (Hom.toBialgHom : Hom V W → _) :=
fun ⟨f⟩ ⟨g⟩ _ => by congr
-- TODO: if `Quiver.Hom` and the instance above were `reducible`, this wouldn't be needed.
@[ext]
lemma hom_ext {X Y : BialgCat.{v} R} (f g : X ⟶ Y) (h : f.toBialgHom = g.toBialgHom) :
f = g :=
Hom.ext h
@[simp] theorem toBialgHom_comp {X Y Z : BialgCat.{v} R} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).toBialgHom = g.toBialgHom.comp f.toBialgHom :=
rfl
@[simp] theorem toBialgHom_id {M : BialgCat.{v} R} :
Hom.toBialgHom (𝟙 M) = BialgHom.id _ _ :=
rfl
instance hasForget : HasForget.{v} (BialgCat.{v} R) where
forget :=
{ obj := fun M => M
map := fun f => f.toBialgHom }
forget_faithful :=
{ map_injective := fun {_ _} => DFunLike.coe_injective.comp <| Hom.toBialgHom_injective _ _ }
instance hasForgetToAlgebra : HasForget₂ (BialgCat R) (AlgCat R) where
forget₂ :=
{ obj := fun X => AlgCat.of R X
map := fun {X Y} f => AlgCat.ofHom f.toBialgHom }
@[simp]
theorem forget₂_algebra_obj (X : BialgCat R) :
(forget₂ (BialgCat R) (AlgCat R)).obj X = AlgCat.of R X :=
rfl
@[simp]
theorem forget₂_algebra_map (X Y : BialgCat R) (f : X ⟶ Y) :
(forget₂ (BialgCat R) (AlgCat R)).map f = AlgCat.ofHom f.toBialgHom :=
rfl
instance hasForgetToCoalgebra : HasForget₂ (BialgCat R) (CoalgCat R) where
forget₂ :=
{ obj := fun X => CoalgCat.of R X
map := fun {_ _} f => CoalgCat.ofHom f.toBialgHom }
@[simp]
theorem forget₂_coalgebra_obj (X : BialgCat R) :
(forget₂ (BialgCat R) (CoalgCat R)).obj X = CoalgCat.of R X :=
rfl
@[simp]
theorem forget₂_coalgebra_map (X Y : BialgCat R) (f : X ⟶ Y) :
(forget₂ (BialgCat R) (CoalgCat R)).map f = CoalgCat.ofHom f.toBialgHom :=
rfl
end BialgCat
namespace BialgEquiv
open BialgCat
variable {X Y Z : Type v}
variable [Ring X] [Ring Y] [Ring Z]
variable [Bialgebra R X] [Bialgebra R Y] [Bialgebra R Z]
/-- Build an isomorphism in the category `BialgCat R` from a
`BialgEquiv`. -/
@[simps]
def toBialgIso (e : X ≃ₐc[R] Y) : BialgCat.of R X ≅ BialgCat.of R Y where
hom := BialgCat.ofHom e
inv := BialgCat.ofHom e.symm
hom_inv_id := Hom.ext <| DFunLike.ext _ _ e.left_inv
inv_hom_id := Hom.ext <| DFunLike.ext _ _ e.right_inv
@[simp] theorem toBialgIso_refl : toBialgIso (BialgEquiv.refl R X) = .refl _ :=
rfl
@[simp] theorem toBialgIso_symm (e : X ≃ₐc[R] Y) :
toBialgIso e.symm = (toBialgIso e).symm :=
rfl
@[simp] theorem toBialgIso_trans (e : X ≃ₐc[R] Y) (f : Y ≃ₐc[R] Z) :
toBialgIso (e.trans f) = toBialgIso e ≪≫ toBialgIso f :=
rfl
end BialgEquiv
namespace CategoryTheory.Iso
open Bialgebra
variable {X Y Z : BialgCat.{v} R}
/-- Build a `BialgEquiv` from an isomorphism in the category
`BialgCat R`. -/
def toBialgEquiv (i : X ≅ Y) : X ≃ₐc[R] Y :=
{ i.hom.toBialgHom with
invFun := i.inv.toBialgHom
left_inv := fun x => BialgHom.congr_fun (congr_arg BialgCat.Hom.toBialgHom i.3) x
right_inv := fun x => BialgHom.congr_fun (congr_arg BialgCat.Hom.toBialgHom i.4) x }
@[simp] theorem toBialgEquiv_toBialgHom (i : X ≅ Y) :
(i.toBialgEquiv : X →ₐc[R] Y) = i.hom.1 := rfl
@[simp] theorem toBialgEquiv_refl : toBialgEquiv (.refl X) = .refl _ _ :=
rfl
@[simp] theorem toBialgEquiv_symm (e : X ≅ Y) :
toBialgEquiv e.symm = (toBialgEquiv e).symm :=
rfl
@[simp] theorem toBialgEquiv_trans (e : X ≅ Y) (f : Y ≅ Z) :
toBialgEquiv (e ≪≫ f) = e.toBialgEquiv.trans f.toBialgEquiv :=
rfl
end CategoryTheory.Iso
instance BialgCat.forget_reflects_isos :
(forget (BialgCat.{v} R)).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget (BialgCat.{v} R)).map f)
let e : X ≃ₐc[R] Y := { f.toBialgHom, i.toEquiv with }
exact ⟨e.toBialgIso.isIso_hom.1⟩ |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Biproducts.lean | import Mathlib.Algebra.Group.Pi.Lemmas
import Mathlib.CategoryTheory.Limits.Shapes.BinaryBiproducts
import Mathlib.Algebra.Category.ModuleCat.Abelian
import Mathlib.Algebra.Homology.ShortComplex.ModuleCat
/-!
# The category of `R`-modules has finite biproducts
-/
open CategoryTheory
open CategoryTheory.Limits
universe w v u
namespace ModuleCat
variable {R : Type u} [Ring R]
-- As `ModuleCat R` is preadditive, and has all limits, it automatically has biproducts.
instance : HasBinaryBiproducts (ModuleCat.{v} R) :=
HasBinaryBiproducts.of_hasBinaryProducts
instance : HasFiniteBiproducts (ModuleCat.{v} R) :=
HasFiniteBiproducts.of_hasFiniteProducts
-- We now construct explicit limit data,
-- so we can compare the biproducts to the usual unbundled constructions.
/-- Construct limit data for a binary product in `ModuleCat R`, using `ModuleCat.of R (M × N)`.
-/
@[simps cone_pt isLimit_lift]
def binaryProductLimitCone (M N : ModuleCat.{v} R) : Limits.LimitCone (pair M N) where
cone :=
{ pt := ModuleCat.of R (M × N)
π :=
{ app := fun j =>
Discrete.casesOn j fun j =>
WalkingPair.casesOn j (ofHom <| LinearMap.fst R M N) (ofHom <| LinearMap.snd R M N)
naturality := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ ⟨⟨⟨⟩⟩⟩ <;> rfl } }
isLimit :=
{ lift := fun s => ofHom <| LinearMap.prod
(s.π.app ⟨WalkingPair.left⟩).hom
(s.π.app ⟨WalkingPair.right⟩).hom
fac := by rintro s (⟨⟩ | ⟨⟩) <;> rfl
uniq := fun s m w => by
simp_rw [← w ⟨WalkingPair.left⟩, ← w ⟨WalkingPair.right⟩]
rfl }
@[simp]
theorem binaryProductLimitCone_cone_π_app_left (M N : ModuleCat.{v} R) :
(binaryProductLimitCone M N).cone.π.app ⟨WalkingPair.left⟩ = ofHom (LinearMap.fst R M N) :=
rfl
@[simp]
theorem binaryProductLimitCone_cone_π_app_right (M N : ModuleCat.{v} R) :
(binaryProductLimitCone M N).cone.π.app ⟨WalkingPair.right⟩ = ofHom (LinearMap.snd R M N) :=
rfl
/-- We verify that the biproduct in `ModuleCat R` is isomorphic to
the Cartesian product of the underlying types:
-/
noncomputable def biprodIsoProd (M N : ModuleCat.{v} R) :
(M ⊞ N : ModuleCat.{v} R) ≅ ModuleCat.of R (M × N) :=
IsLimit.conePointUniqueUpToIso (BinaryBiproduct.isLimit M N) (binaryProductLimitCone M N).isLimit
@[simp, elementwise]
theorem biprodIsoProd_inv_comp_fst (M N : ModuleCat.{v} R) :
(biprodIsoProd M N).inv ≫ biprod.fst = ofHom (LinearMap.fst R M N) :=
IsLimit.conePointUniqueUpToIso_inv_comp _ _ (Discrete.mk WalkingPair.left)
@[simp, elementwise]
theorem biprodIsoProd_inv_comp_snd (M N : ModuleCat.{v} R) :
(biprodIsoProd M N).inv ≫ biprod.snd = ofHom (LinearMap.snd R M N) :=
IsLimit.conePointUniqueUpToIso_inv_comp _ _ (Discrete.mk WalkingPair.right)
namespace HasLimit
variable {J : Type w} (f : J → ModuleCat.{max w v} R)
/-- The map from an arbitrary cone over an indexed family of abelian groups
to the Cartesian product of those groups.
-/
@[simps!]
def lift (s : Fan f) : s.pt ⟶ ModuleCat.of R (∀ j, f j) :=
ofHom
{ toFun := fun x j => s.π.app ⟨j⟩ x
map_add' := fun x y => by
simp only [Functor.const_obj_obj, map_add]
rfl
map_smul' := fun r x => by
simp only [Functor.const_obj_obj, map_smul]
rfl }
/-- Construct limit data for a product in `ModuleCat R`, using `ModuleCat.of R (∀ j, F.obj j)`.
-/
@[simps]
def productLimitCone : Limits.LimitCone (Discrete.functor f) where
cone :=
{ pt := ModuleCat.of R (∀ j, f j)
π := Discrete.natTrans fun j => ofHom (LinearMap.proj j.as : (∀ j, f j) →ₗ[R] f j.as) }
isLimit :=
{ lift := lift.{_, v} f
fac := fun _ _ => rfl
uniq := fun s m w => by
ext x j
exact congr_arg (fun g : s.pt ⟶ f j => (g : s.pt → f j) x) (w ⟨j⟩) }
end HasLimit
open HasLimit
variable {J : Type} (f : J → ModuleCat.{v} R)
/-- We verify that the biproduct we've just defined is isomorphic to the `ModuleCat R` structure
on the dependent function type.
-/
noncomputable def biproductIsoPi [Finite J] (f : J → ModuleCat.{v} R) :
((⨁ f) : ModuleCat.{v} R) ≅ ModuleCat.of R (∀ j, f j) :=
IsLimit.conePointUniqueUpToIso (biproduct.isLimit f) (productLimitCone f).isLimit
@[simp, elementwise]
theorem biproductIsoPi_inv_comp_π [Finite J] (f : J → ModuleCat.{v} R) (j : J) :
(biproductIsoPi f).inv ≫ biproduct.π f j = ofHom (LinearMap.proj j : (∀ j, f j) →ₗ[R] f j) :=
IsLimit.conePointUniqueUpToIso_inv_comp _ _ (Discrete.mk j)
end ModuleCat
section SplitExact
open ModuleCat
section universe_monomorphic
variable {R : Type u} {A M B : Type v} [Ring R] [AddCommGroup A] [Module R A] [AddCommGroup B]
[Module R B] [AddCommGroup M] [Module R M]
variable {j : A →ₗ[R] M} {g : M →ₗ[R] B}
private noncomputable def lequivProdOfRightSplitExact' {f : B →ₗ[R] M} (hj : Function.Injective j)
(exac : LinearMap.range j = LinearMap.ker g) (h : g.comp f = LinearMap.id) : (A × B) ≃ₗ[R] M :=
((ShortComplex.Splitting.ofExactOfSection _
(ShortComplex.Exact.moduleCat_of_range_eq_ker (ModuleCat.ofHom j)
(ModuleCat.ofHom g) exac) (ofHom f) (hom_ext h)
(by simpa only [ModuleCat.mono_iff_injective])).isoBinaryBiproduct ≪≫
biprodIsoProd _ _ ).symm.toLinearEquiv
private noncomputable def lequivProdOfLeftSplitExact' {f : M →ₗ[R] A} (hg : Function.Surjective g)
(exac : LinearMap.range j = LinearMap.ker g) (h : f.comp j = LinearMap.id) : (A × B) ≃ₗ[R] M :=
((ShortComplex.Splitting.ofExactOfRetraction _
(ShortComplex.Exact.moduleCat_of_range_eq_ker (ModuleCat.ofHom j)
(ModuleCat.ofHom g) exac) (ModuleCat.ofHom f) (hom_ext h)
(by simpa only [ModuleCat.epi_iff_surjective] using hg)).isoBinaryBiproduct ≪≫
biprodIsoProd _ _).symm.toLinearEquiv
end universe_monomorphic
section universe_polymorphic
universe uA uM uB
variable {R : Type u} {A : Type uA} {M : Type uM} {B : Type uB}
variable [Ring R] [AddCommGroup A] [AddCommGroup B] [AddCommGroup M]
variable [Module R A] [Module R B] [Module R M]
variable {j : A →ₗ[R] M} {g : M →ₗ[R] B}
/-- The isomorphism `A × B ≃ₗ[R] M` coming from a right split exact sequence `0 ⟶ A ⟶ M ⟶ B ⟶ 0`
of modules. -/
noncomputable def lequivProdOfRightSplitExact {f : B →ₗ[R] M} (hj : Function.Injective j)
(exac : LinearMap.range j = LinearMap.ker g) (h : g.comp f = LinearMap.id) : (A × B) ≃ₗ[R] M :=
have := lequivProdOfRightSplitExact'
(A := ULift.{max uA uM uB} A) (M := ULift.{max uA uM uB} M) (B := ULift.{max uA uM uB} B)
(f := ULift.moduleEquiv.symm.toLinearMap ∘ₗ f ∘ₗ ULift.moduleEquiv.toLinearMap)
(j := ULift.moduleEquiv.symm.toLinearMap ∘ₗ j ∘ₗ ULift.moduleEquiv.toLinearMap)
(g := ULift.moduleEquiv.symm.toLinearMap ∘ₗ g ∘ₗ ULift.moduleEquiv.toLinearMap)
(by simpa using hj)
(by simp [LinearMap.range_comp, LinearMap.ker_comp, exac, Submodule.comap_equiv_eq_map_symm])
(by ext x; simpa using congr($h x.down))
ULift.moduleEquiv.symm.prodCongr ULift.moduleEquiv.symm ≪≫ₗ this ≪≫ₗ ULift.moduleEquiv
/-- The isomorphism `A × B ≃ₗ[R] M` coming from a left split exact sequence `0 ⟶ A ⟶ M ⟶ B ⟶ 0`
of modules. -/
noncomputable def lequivProdOfLeftSplitExact {f : M →ₗ[R] A} (hg : Function.Surjective g)
(exac : LinearMap.range j = LinearMap.ker g) (h : f.comp j = LinearMap.id) : (A × B) ≃ₗ[R] M :=
have := lequivProdOfLeftSplitExact'
(A := ULift.{max uA uM uB} A) (M := ULift.{max uA uM uB} M) (B := ULift.{max uA uM uB} B)
(f := ULift.moduleEquiv.symm.toLinearMap ∘ₗ f ∘ₗ ULift.moduleEquiv.toLinearMap)
(j := ULift.moduleEquiv.symm.toLinearMap ∘ₗ j ∘ₗ ULift.moduleEquiv.toLinearMap)
(g := ULift.moduleEquiv.symm.toLinearMap ∘ₗ g ∘ₗ ULift.moduleEquiv.toLinearMap)
(by simpa using hg)
(by simp [LinearMap.range_comp, LinearMap.ker_comp, exac, Submodule.comap_equiv_eq_map_symm])
(by ext x; simpa using congr($h x.down))
ULift.moduleEquiv.symm.prodCongr ULift.moduleEquiv.symm ≪≫ₗ this ≪≫ₗ ULift.moduleEquiv
end universe_polymorphic
end SplitExact |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/EpiMono.lean | import Mathlib.LinearAlgebra.Quotient.Basic
import Mathlib.Algebra.Category.ModuleCat.Basic
import Mathlib.CategoryTheory.ConcreteCategory.EpiMono
/-!
# Monomorphisms in `Module R`
This file shows that an `R`-linear map is a monomorphism in the category of `R`-modules
if and only if it is injective, and similarly an epimorphism if and only if it is surjective.
-/
universe v u
open CategoryTheory
namespace ModuleCat
variable {R : Type u} [Ring R] {X Y : ModuleCat.{v} R} (f : X ⟶ Y)
variable {M : Type v} [AddCommGroup M] [Module R M]
theorem ker_eq_bot_of_mono [Mono f] : LinearMap.ker f.hom = ⊥ :=
LinearMap.ker_eq_bot_of_cancel fun u v h => ModuleCat.hom_ext_iff.mp <|
(@cancel_mono _ _ _ _ _ f _ (↟u) (↟v)).1 <| ModuleCat.hom_ext_iff.mpr h
theorem range_eq_top_of_epi [Epi f] : LinearMap.range f.hom = ⊤ :=
LinearMap.range_eq_top_of_cancel fun u v h => ModuleCat.hom_ext_iff.mp <|
(@cancel_epi _ _ _ _ _ f _ (↟u) (↟v)).1 <| ModuleCat.hom_ext_iff.mpr h
theorem mono_iff_ker_eq_bot : Mono f ↔ LinearMap.ker f.hom = ⊥ :=
⟨fun _ => ker_eq_bot_of_mono _, fun hf =>
ConcreteCategory.mono_of_injective _ <| by convert LinearMap.ker_eq_bot.1 hf⟩
theorem mono_iff_injective : Mono f ↔ Function.Injective f := by
rw [mono_iff_ker_eq_bot, LinearMap.ker_eq_bot]
theorem epi_iff_range_eq_top : Epi f ↔ LinearMap.range f.hom = ⊤ :=
⟨fun _ => range_eq_top_of_epi _, fun hf =>
ConcreteCategory.epi_of_surjective _ <| by convert LinearMap.range_eq_top.1 hf⟩
theorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by
rw [epi_iff_range_eq_top, LinearMap.range_eq_top]
/-- If the zero morphism is an epi then the codomain is trivial. -/
def uniqueOfEpiZero (X) [h : Epi (0 : X ⟶ of R M)] : Unique M :=
uniqueOfSurjectiveZero X ((ModuleCat.epi_iff_surjective _).mp h)
instance mono_as_hom'_subtype (U : Submodule R X) : Mono (ModuleCat.ofHom U.subtype) :=
(mono_iff_ker_eq_bot _).mpr (Submodule.ker_subtype U)
instance epi_as_hom''_mkQ (U : Submodule R X) : Epi (ModuleCat.ofHom U.mkQ) :=
(epi_iff_range_eq_top _).mpr <| Submodule.range_mkQ _
instance forget_preservesEpimorphisms : (forget (ModuleCat.{v} R)).PreservesEpimorphisms where
preserves f hf := by
rw [CategoryTheory.epi_iff_surjective, ConcreteCategory.forget_map_eq_coe,
← epi_iff_surjective]
exact hf
instance forget_preservesMonomorphisms : (forget (ModuleCat.{v} R)).PreservesMonomorphisms where
preserves f hf := by
rw [CategoryTheory.mono_iff_injective, ConcreteCategory.forget_map_eq_coe,
← mono_iff_injective]
exact hf
end ModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Products.lean | import Mathlib.Algebra.Category.ModuleCat.Basic
import Mathlib.LinearAlgebra.Pi
import Mathlib.Algebra.DirectSum.Module
import Mathlib.Tactic.CategoryTheory.Elementwise
/-!
# The concrete products in the category of modules are products in the categorical sense.
-/
open CategoryTheory
open CategoryTheory.Limits
universe u v w
namespace ModuleCat
variable {R : Type u} [Ring R]
variable {ι : Type v} (Z : ι → ModuleCat.{max v w} R)
section product
/-- The product cone induced by the concrete product. -/
def productCone : Fan Z :=
Fan.mk (ModuleCat.of R (∀ i : ι, Z i)) fun i =>
ofHom (LinearMap.proj i : (∀ i : ι, Z i) →ₗ[R] Z i)
/-- The concrete product cone is limiting. -/
def productConeIsLimit : IsLimit (productCone Z) where
lift s := ofHom (LinearMap.pi fun j => (s.π.app ⟨j⟩).hom : s.pt →ₗ[R] ∀ i : ι, Z i)
uniq s m w := by
ext x
funext i
exact DFunLike.congr_fun (congr_arg Hom.hom (w ⟨i⟩)) x
-- While we could use this to construct a `HasProducts (ModuleCat R)` instance,
-- we already have `HasLimits (ModuleCat R)` in `Algebra.Category.ModuleCat.Limits`.
variable [HasProduct Z]
/-- The categorical product of a family of objects in `ModuleCat`
agrees with the usual module-theoretical product.
-/
noncomputable def piIsoPi : ∏ᶜ Z ≅ ModuleCat.of R (∀ i, Z i) :=
limit.isoLimitCone ⟨_, productConeIsLimit Z⟩
-- We now show this isomorphism commutes with the inclusion of the kernel into the source.
@[simp, elementwise]
theorem piIsoPi_inv_kernel_ι (i : ι) :
(piIsoPi Z).inv ≫ Pi.π Z i = ofHom (LinearMap.proj i : (∀ i : ι, Z i) →ₗ[R] Z i) :=
limit.isoLimitCone_inv_π _ _
@[simp, elementwise]
theorem piIsoPi_hom_ker_subtype (i : ι) :
(piIsoPi Z).hom ≫ ofHom (LinearMap.proj i : (∀ i : ι, Z i) →ₗ[R] Z i) = Pi.π Z i :=
IsLimit.conePointUniqueUpToIso_inv_comp _ (limit.isLimit _) (Discrete.mk i)
end product
section coproduct
open DirectSum
variable [DecidableEq ι]
/-- The coproduct cone induced by the concrete coproduct. -/
def coproductCocone : Cofan Z :=
Cofan.mk (ModuleCat.of R (⨁ i : ι, Z i)) fun i => ofHom (DirectSum.lof R ι (fun i ↦ Z i) i)
/-- The concrete coproduct cone is colimiting. -/
def coproductCoconeIsColimit : IsColimit (coproductCocone Z) where
desc s := ofHom <| DirectSum.toModule R ι _ fun i ↦ (s.ι.app ⟨i⟩).hom
fac := by
rintro s ⟨i⟩
ext (x : Z i)
simpa only [Discrete.functor_obj_eq_as, coproductCocone, Cofan.mk_pt, Functor.const_obj_obj,
Cofan.mk_ι_app, hom_comp, LinearMap.coe_comp, Function.comp_apply] using
DirectSum.toModule_lof (ι := ι) R (M := fun i ↦ Z i) i x
uniq := by
rintro s f h
ext : 1
refine DirectSum.linearMap_ext _ fun i ↦ ?_
ext x
simpa only [LinearMap.coe_comp, Function.comp_apply, hom_ofHom, toModule_lof] using
congr($(h ⟨i⟩) x)
variable [HasCoproduct Z]
/-- The categorical coproduct of a family of objects in `ModuleCat`
agrees with direct sum.
-/
noncomputable def coprodIsoDirectSum : ∐ Z ≅ ModuleCat.of R (⨁ i, Z i) :=
colimit.isoColimitCocone ⟨_, coproductCoconeIsColimit Z⟩
@[simp, elementwise]
theorem ι_coprodIsoDirectSum_hom (i : ι) :
Sigma.ι Z i ≫ (coprodIsoDirectSum Z).hom = ofHom (DirectSum.lof R ι (fun i ↦ Z i) i) :=
colimit.isoColimitCocone_ι_hom _ _
@[simp, elementwise]
theorem lof_coprodIsoDirectSum_inv (i : ι) :
ofHom (DirectSum.lof R ι (fun i ↦ Z i) i) ≫ (coprodIsoDirectSum Z).inv = Sigma.ι Z i :=
(coproductCoconeIsColimit Z).comp_coconePointUniqueUpToIso_hom (colimit.isColimit _) _
end coproduct
end ModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Abelian.lean | import Mathlib.LinearAlgebra.Isomorphisms
import Mathlib.Algebra.Category.ModuleCat.Kernels
import Mathlib.Algebra.Category.ModuleCat.Limits
import Mathlib.CategoryTheory.Abelian.Basic
/-!
# The category of left R-modules is abelian.
Additionally, two linear maps are exact in the categorical sense iff `range f = ker g`.
-/
open CategoryTheory
open CategoryTheory.Limits
noncomputable section
universe w v u
namespace ModuleCat
variable {R : Type u} [Ring R] {M N : ModuleCat.{v} R} (f : M ⟶ N)
/-- In the category of modules, every monomorphism is normal. -/
def normalMono (hf : Mono f) : NormalMono f where
Z := of R (N ⧸ LinearMap.range f.hom)
g := ofHom (LinearMap.range f.hom).mkQ
w := hom_ext <| LinearMap.range_mkQ_comp _
isLimit :=
/- The following [invalid Lean code](https://github.com/leanprover-community/lean/issues/341)
might help you understand what's going on here:
```
calc
M ≃ₗ[R] f.ker.quotient : (Submodule.quotEquivOfEqBot _ (ker_eq_bot_of_mono _)).symm
... ≃ₗ[R] f.range : LinearMap.quotKerEquivRange f
... ≃ₗ[R] r.range.mkQ.ker : LinearEquiv.ofEq _ _ (Submodule.ker_mkQ _).symm
```
-/
IsKernel.isoKernel _ _ (kernelIsLimit _)
(LinearEquiv.toModuleIso
((Submodule.quotEquivOfEqBot _ (ker_eq_bot_of_mono _)).symm ≪≫ₗ
(LinearMap.quotKerEquivRange f.hom ≪≫ₗ
LinearEquiv.ofEq _ _ (Submodule.ker_mkQ _).symm))) <| by ext; rfl
/-- In the category of modules, every epimorphism is normal. -/
def normalEpi (hf : Epi f) : NormalEpi f where
W := of R (LinearMap.ker f.hom)
g := ofHom (LinearMap.ker f.hom).subtype
w := hom_ext <| LinearMap.comp_ker_subtype _
isColimit :=
/- The following invalid Lean code might help you understand what's going on here:
```
calc f.ker.subtype.range.quotient
≃ₗ[R] f.ker.quotient : Submodule.quotEquivOfEq _ _ (Submodule.range_subtype _)
... ≃ₗ[R] f.range : LinearMap.quotKerEquivRange f
... ≃ₗ[R] N : LinearEquiv.ofTop _ (range_eq_top_of_epi _)
```
-/
IsCokernel.cokernelIso _ _ (cokernelIsColimit _)
(LinearEquiv.toModuleIso
(Submodule.quotEquivOfEq _ _ (Submodule.range_subtype _) ≪≫ₗ
LinearMap.quotKerEquivRange f.hom ≪≫ₗ
LinearEquiv.ofTop _ (range_eq_top_of_epi _))) <| by ext; rfl
/-- The category of R-modules is abelian. -/
instance abelian : Abelian (ModuleCat.{v} R) where
has_cokernels := hasCokernels_moduleCat
normalMonoOfMono f hf := ⟨normalMono f hf⟩
normalEpiOfEpi f hf := ⟨normalEpi f hf⟩
section ReflectsLimits
/-- Add this instance to help Lean with universe levels. -/
instance : HasLimitsOfSize.{v,v} (ModuleCat.{max v w} R) :=
ModuleCat.hasLimitsOfSize.{v, v, max v w}
/- We need to put this in this weird spot because we need to know that the category of modules
is balanced. -/
instance forget_reflectsLimitsOfSize :
ReflectsLimitsOfSize.{v, v} (forget (ModuleCat.{max v w} R)) :=
reflectsLimits_of_reflectsIsomorphisms
instance forget₂_reflectsLimitsOfSize :
ReflectsLimitsOfSize.{v, v} (forget₂ (ModuleCat.{max v w} R) AddCommGrpCat.{max v w}) :=
reflectsLimits_of_reflectsIsomorphisms
instance forget_reflectsLimits : ReflectsLimits (forget (ModuleCat.{v} R)) :=
ModuleCat.forget_reflectsLimitsOfSize.{v, v}
instance forget₂_reflectsLimits : ReflectsLimits (forget₂ (ModuleCat.{v} R) AddCommGrpCat.{v}) :=
ModuleCat.forget₂_reflectsLimitsOfSize.{v, v}
end ReflectsLimits
end ModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Presheaf.lean | import Mathlib.Algebra.Category.ModuleCat.ChangeOfRings
import Mathlib.Algebra.Category.Ring.Basic
/-!
# Presheaves of modules over a presheaf of rings.
Given a presheaf of rings `R : Cᵒᵖ ⥤ RingCat`, we define the category `PresheafOfModules R`.
An object `M : PresheafOfModules R` consists of a family of modules
`M.obj X : ModuleCat (R.obj X)` for all `X : Cᵒᵖ`, together with the data, for all `f : X ⟶ Y`,
of a functorial linear map `M.map f` from `M.obj X` to the restriction
of scalars of `M.obj Y` via `R.map f`.
## Future work
* Compare this to the definition as a presheaf of pairs `(R, M)` with specified first part.
* Compare this to the definition as a module object of the presheaf of rings
thought of as a monoid object.
* Presheaves of modules over a presheaf of commutative rings form a monoidal category.
* Pushforward and pullback.
-/
universe v v₁ u₁ u
open CategoryTheory LinearMap Opposite
variable {C : Type u₁} [Category.{v₁} C] {R : Cᵒᵖ ⥤ RingCat.{u}}
variable (R) in
/-- A presheaf of modules over `R : Cᵒᵖ ⥤ RingCat` consists of family of
objects `obj X : ModuleCat (R.obj X)` for all `X : Cᵒᵖ` together with
functorial maps `obj X ⟶ (ModuleCat.restrictScalars (R.map f)).obj (obj Y)`
for all `f : X ⟶ Y` in `Cᵒᵖ`. -/
structure PresheafOfModules where
/-- a family of modules over `R.obj X` for all `X` -/
obj (X : Cᵒᵖ) : ModuleCat.{v} (R.obj X)
/-- the restriction maps of a presheaf of modules -/
map {X Y : Cᵒᵖ} (f : X ⟶ Y) : obj X ⟶ (ModuleCat.restrictScalars (R.map f).hom).obj (obj Y)
map_id (X : Cᵒᵖ) :
map (𝟙 X) = (ModuleCat.restrictScalarsId' (R.map (𝟙 X)).hom
(congrArg RingCat.Hom.hom (R.map_id X))).inv.app _ := by
cat_disch
map_comp {X Y Z : Cᵒᵖ} (f : X ⟶ Y) (g : Y ⟶ Z) :
map (f ≫ g) = map f ≫ (ModuleCat.restrictScalars _).map (map g) ≫
(ModuleCat.restrictScalarsComp' (R.map f).hom (R.map g).hom (R.map (f ≫ g)).hom
(congrArg RingCat.Hom.hom <| R.map_comp f g)).inv.app _ := by cat_disch
namespace PresheafOfModules
attribute [simp] map_id map_comp
attribute [reassoc] map_comp
variable (M M₁ M₂ : PresheafOfModules.{v} R)
protected lemma map_smul {X Y : Cᵒᵖ} (f : X ⟶ Y) (r : R.obj X) (m : M.obj X) :
M.map f (r • m) = R.map f r • M.map f m := by simp
lemma congr_map_apply {X Y : Cᵒᵖ} {f g : X ⟶ Y} (h : f = g) (m : M.obj X) :
M.map f m = M.map g m := by rw [h]
/-- A morphism of presheaves of modules consists of a family of linear maps which
satisfy the naturality condition. -/
@[ext]
structure Hom where
/-- a family of linear maps `M₁.obj X ⟶ M₂.obj X` for all `X`. -/
app (X : Cᵒᵖ) : M₁.obj X ⟶ M₂.obj X
naturality {X Y : Cᵒᵖ} (f : X ⟶ Y) :
M₁.map f ≫ (ModuleCat.restrictScalars (R.map f).hom).map (app Y) =
app X ≫ M₂.map f := by cat_disch
attribute [reassoc (attr := simp)] Hom.naturality
instance : Category (PresheafOfModules.{v} R) where
Hom := Hom
id _ := { app := fun _ ↦ 𝟙 _ }
comp f g := { app := fun _ ↦ f.app _ ≫ g.app _ }
variable {M₁ M₂}
@[ext]
lemma hom_ext {f g : M₁ ⟶ M₂} (h : ∀ (X : Cᵒᵖ), f.app X = g.app X) :
f = g := Hom.ext (by ext1; apply h)
@[simp]
lemma id_app (M : PresheafOfModules R) (X : Cᵒᵖ) : Hom.app (𝟙 M) X = 𝟙 _ := by
rfl
@[simp]
lemma comp_app {M₁ M₂ M₃ : PresheafOfModules R} (f : M₁ ⟶ M₂) (g : M₂ ⟶ M₃) (X : Cᵒᵖ) :
(f ≫ g).app X = f.app X ≫ g.app X := by
rfl
lemma naturality_apply (f : M₁ ⟶ M₂) {X Y : Cᵒᵖ} (g : X ⟶ Y) (x : M₁.obj X) :
Hom.app f Y (M₁.map g x) = M₂.map g (Hom.app f X x) :=
CategoryTheory.congr_fun (Hom.naturality f g) x
/-- Constructor for isomorphisms in the category of presheaves of modules. -/
@[simps!]
def isoMk (app : ∀ (X : Cᵒᵖ), M₁.obj X ≅ M₂.obj X)
(naturality : ∀ ⦃X Y : Cᵒᵖ⦄ (f : X ⟶ Y),
M₁.map f ≫ (ModuleCat.restrictScalars (R.map f).hom).map (app Y).hom =
(app X).hom ≫ M₂.map f := by cat_disch) : M₁ ≅ M₂ where
hom := { app := fun X ↦ (app X).hom }
inv :=
{ app := fun X ↦ (app X).inv
naturality := fun {X Y} f ↦ by
rw [← cancel_epi (app X).hom, ← reassoc_of% (naturality f), Iso.map_hom_inv_id,
Category.comp_id, Iso.hom_inv_id_assoc]}
/-- The underlying presheaf of abelian groups of a presheaf of modules. -/
noncomputable def presheaf : Cᵒᵖ ⥤ Ab where
obj X := (forget₂ _ _).obj (M.obj X)
map f := AddCommGrpCat.ofHom <| AddMonoidHom.mk' (M.map f) (by simp)
@[simp]
lemma presheaf_obj_coe (X : Cᵒᵖ) :
(M.presheaf.obj X : Type _) = M.obj X := rfl
@[simp]
lemma presheaf_map_apply_coe {X Y : Cᵒᵖ} (f : X ⟶ Y) (x : M.obj X) :
DFunLike.coe (α := M.obj X) (β := fun _ ↦ M.obj Y) (M.presheaf.map f).hom x = M.map f x := rfl
instance (M : PresheafOfModules R) (X : Cᵒᵖ) :
Module (R.obj X) (M.presheaf.obj X) :=
inferInstanceAs (Module (R.obj X) (M.obj X))
variable (R) in
/-- The forgetful functor `PresheafOfModules R ⥤ Cᵒᵖ ⥤ Ab`. -/
noncomputable def toPresheaf : PresheafOfModules.{v} R ⥤ Cᵒᵖ ⥤ Ab where
obj M := M.presheaf
map f :=
{ app := fun X ↦ AddCommGrpCat.ofHom <| AddMonoidHom.mk' (Hom.app f X) (by simp)
naturality := fun X Y g ↦ by ext x; exact naturality_apply f g x }
@[simp]
lemma toPresheaf_obj_coe (X : Cᵒᵖ) :
(((toPresheaf R).obj M).obj X : Type _) = M.obj X := rfl
@[simp]
lemma toPresheaf_map_app_apply (f : M₁ ⟶ M₂) (X : Cᵒᵖ) (x : M₁.obj X) :
DFunLike.coe (α := M₁.obj X) (β := fun _ ↦ M₂.obj X)
(((toPresheaf R).map f).app X).hom x = f.app X x := rfl
instance : (toPresheaf R).Faithful where
map_injective {_ _ f g} h := by
ext X x
exact congr_fun (((evaluation _ _).obj X ⋙ forget _).congr_map h) x
section
variable (M : Cᵒᵖ ⥤ Ab.{v}) [∀ X, Module (R.obj X) (M.obj X)]
(map_smul : ∀ ⦃X Y : Cᵒᵖ⦄ (f : X ⟶ Y) (r : R.obj X) (m : M.obj X),
M.map f (r • m) = R.map f r • M.map f m)
/-- The object in `PresheafOfModules R` that is obtained from `M : Cᵒᵖ ⥤ Ab.{v}` such
that for all `X : Cᵒᵖ`, `M.obj X` is a `R.obj X` module, in such a way that the
restriction maps are semilinear. (This constructor should be used only in cases
when the preferred constructor `PresheafOfModules.mk` is not as convenient as this one.) -/
@[simps]
noncomputable def ofPresheaf : PresheafOfModules.{v} R where
obj X := ModuleCat.of _ (M.obj X)
-- TODO: after https://github.com/leanprover-community/mathlib4/pull/19511 we need to hint `(Y := ...)`.
-- This suggests `restrictScalars` needs to be redesigned.
map {X Y} f := ModuleCat.ofHom
(Y := (ModuleCat.restrictScalars (R.map f).hom).obj (ModuleCat.of _ (M.obj Y)))
{ toFun := fun x ↦ M.map f x
map_add' := by simp
map_smul' := fun r m ↦ map_smul f r m }
@[simp]
lemma ofPresheaf_presheaf : (ofPresheaf M map_smul).presheaf = M := rfl
end
/-- The morphism of presheaves of modules `M₁ ⟶ M₂` given by a morphism
of abelian presheaves `M₁.presheaf ⟶ M₂.presheaf`
which satisfy a suitable linearity condition. -/
@[simps]
noncomputable def homMk (φ : M₁.presheaf ⟶ M₂.presheaf)
(hφ : ∀ (X : Cᵒᵖ) (r : R.obj X) (m : M₁.obj X), φ.app X (r • m) = r • φ.app X m) :
M₁ ⟶ M₂ where
app X := ModuleCat.ofHom
{ toFun := φ.app X
map_add' := by simp
map_smul' := hφ X }
naturality := fun f ↦ by
ext x
exact CategoryTheory.congr_fun (φ.naturality f) x
instance : Zero (M₁ ⟶ M₂) where
zero := { app := fun _ ↦ 0 }
variable (M₁ M₂) in
@[simp] lemma zero_app (X : Cᵒᵖ) : (0 : M₁ ⟶ M₂).app X = 0 := rfl
instance : Neg (M₁ ⟶ M₂) where
neg f :=
{ app := fun X ↦ -f.app X
naturality := fun {X Y} h ↦ by
ext x
simp [← naturality_apply] }
instance : Add (M₁ ⟶ M₂) where
add f g :=
{ app := fun X ↦ f.app X + g.app X
naturality := fun {X Y} h ↦ by
ext x
simp [← naturality_apply] }
instance : Sub (M₁ ⟶ M₂) where
sub f g :=
{ app := fun X ↦ f.app X - g.app X
naturality := fun {X Y} h ↦ by
ext x
simp [← naturality_apply] }
@[simp] lemma neg_app (f : M₁ ⟶ M₂) (X : Cᵒᵖ) : (-f).app X = -f.app X := rfl
@[simp] lemma add_app (f g : M₁ ⟶ M₂) (X : Cᵒᵖ) : (f + g).app X = f.app X + g.app X := rfl
@[simp] lemma sub_app (f g : M₁ ⟶ M₂) (X : Cᵒᵖ) : (f - g).app X = f.app X - g.app X := rfl
instance : AddCommGroup (M₁ ⟶ M₂) where
add_assoc := by intros; ext1; simp only [add_app, add_assoc]
zero_add := by intros; ext1; simp only [add_app, zero_app, zero_add]
neg_add_cancel := by intros; ext1; simp only [add_app, neg_app, neg_add_cancel, zero_app]
add_zero := by intros; ext1; simp only [add_app, zero_app, add_zero]
add_comm := by intros; ext1; simp only [add_app]; apply add_comm
sub_eq_add_neg := by intros; ext1; simp only [add_app, sub_app, neg_app, sub_eq_add_neg]
nsmul := nsmulRec
zsmul := zsmulRec
instance : Preadditive (PresheafOfModules R) where
instance : (toPresheaf R).Additive where
lemma zsmul_app (n : ℤ) (f : M₁ ⟶ M₂) (X : Cᵒᵖ) : (n • f).app X = n • f.app X := by
ext x
change (toPresheaf R ⋙ (evaluation _ _).obj X).map (n • f) x = _
rw [Functor.map_zsmul]
rfl
variable (R)
/-- Evaluation on an object `X` gives a functor
`PresheafOfModules R ⥤ ModuleCat (R.obj X)`. -/
@[simps]
def evaluation (X : Cᵒᵖ) : PresheafOfModules.{v} R ⥤ ModuleCat (R.obj X) where
obj M := M.obj X
map f := f.app X
instance (X : Cᵒᵖ) : (evaluation.{v} R X).Additive where
/-- The restriction natural transformation on presheaves of modules, considered as linear maps
to restriction of scalars. -/
@[simps]
noncomputable def restriction {X Y : Cᵒᵖ} (f : X ⟶ Y) :
evaluation R X ⟶ evaluation R Y ⋙ ModuleCat.restrictScalars (R.map f).hom where
app M := M.map f
/-- The obvious free presheaf of modules of rank `1`. -/
noncomputable def unit : PresheafOfModules R where
obj X := ModuleCat.of _ (R.obj X)
-- TODO: after https://github.com/leanprover-community/mathlib4/pull/19511 we need to hint `(Y := ...)`.
-- This suggests `restrictScalars` needs to be redesigned.
map {X Y} f := ModuleCat.ofHom
(Y := (ModuleCat.restrictScalars (R.map f).hom).obj (ModuleCat.of (R.obj Y) (R.obj Y)))
{ toFun := fun x ↦ R.map f x
map_add' := by simp
map_smul' := by cat_disch }
lemma unit_map_one {X Y : Cᵒᵖ} (f : X ⟶ Y) : (unit R).map f (1 : R.obj X) = (1 : R.obj Y) :=
(R.map f).hom.map_one
variable {R}
/-- The type of sections of a presheaf of modules. -/
def sections (M : PresheafOfModules.{v} R) : Type _ := (M.presheaf ⋙ forget _).sections
/-- Given a presheaf of modules `M`, `s : M.sections` and `X : Cᵒᵖ`, this is the induced
element in `M.obj X`. -/
abbrev sections.eval {M : PresheafOfModules.{v} R} (s : M.sections) (X : Cᵒᵖ) : M.obj X := s.1 X
@[simp]
lemma sections_property {M : PresheafOfModules.{v} R} (s : M.sections)
{X Y : Cᵒᵖ} (f : X ⟶ Y) : M.map f (s.1 X) = s.1 Y := s.2 f
/-- Constructor for sections of a presheaf of modules. -/
@[simps]
def sectionsMk {M : PresheafOfModules.{v} R} (s : ∀ X, M.obj X)
(hs : ∀ ⦃X Y : Cᵒᵖ⦄ (f : X ⟶ Y), M.map f (s X) = s Y) : M.sections where
val := s
property f := hs f
@[ext]
lemma sections_ext {M : PresheafOfModules.{v} R} (s t : M.sections)
(h : ∀ (X : Cᵒᵖ), s.val X = t.val X) : s = t :=
Subtype.ext (by ext; apply h)
/-- The map `M.sections → N.sections` induced by a morphisms `M ⟶ N` of presheaves of modules. -/
@[simps!]
def sectionsMap {M N : PresheafOfModules.{v} R} (f : M ⟶ N) (s : M.sections) : N.sections :=
N.sectionsMk (fun X ↦ f.app X (s.1 _))
(fun X Y g ↦ by rw [← naturality_apply, sections_property])
@[simp]
lemma sectionsMap_comp {M N P : PresheafOfModules.{v} R} (f : M ⟶ N) (g : N ⟶ P) (s : M.sections) :
sectionsMap (f ≫ g) s = sectionsMap g (sectionsMap f s) := rfl
@[simp]
lemma sectionsMap_id {M : PresheafOfModules.{v} R} (s : M.sections) :
sectionsMap (𝟙 M) s = s := rfl
/-- The bijection `(unit R ⟶ M) ≃ M.sections` for `M : PresheafOfModules R`. -/
@[simps! apply_coe]
noncomputable def unitHomEquiv (M : PresheafOfModules R) :
(unit R ⟶ M) ≃ M.sections where
toFun f := sectionsMk (fun X ↦ Hom.app f X (1 : R.obj X))
(by intros; rw [← naturality_apply, unit_map_one])
invFun s :=
{ app := fun X ↦ ModuleCat.ofHom
((LinearMap.ringLmapEquivSelf (R.obj X) ℤ (M.obj X)).symm (s.val X))
naturality := fun {X Y} f ↦ by
ext
dsimp
change R.map f 1 • s.eval Y = M.map f (1 • s.eval X)
simp }
left_inv f := by
ext X : 2
exact (LinearMap.ringLmapEquivSelf (R.obj X) ℤ (M.obj X)).symm_apply_apply (f.app X).hom
right_inv s := by
ext X
exact (LinearMap.ringLmapEquivSelf (R.obj X) ℤ (M.obj X)).apply_symm_apply (s.val X)
section module_over_initial
variable (X : Cᵒᵖ) (hX : Limits.IsInitial X)
/-!
## `PresheafOfModules R ⥤ Cᵒᵖ ⥤ ModuleCat (R.obj X)` when `X` is initial
When `X` is initial, we have `Module (R.obj X) (M.obj c)` for any `c : Cᵒᵖ`.
-/
section
variable (M : PresheafOfModules.{v} R)
/-- Auxiliary definition for `forgetToPresheafModuleCatObj`. -/
noncomputable abbrev forgetToPresheafModuleCatObjObj (Y : Cᵒᵖ) : ModuleCat (R.obj X) :=
(ModuleCat.restrictScalars (R.map (hX.to Y)).hom).obj (M.obj Y)
-- This should not be a `simp` lemma because `M.obj Y` is missing the `Module (R.obj X)` instance,
-- so `simp`ing breaks downstream proofs.
lemma forgetToPresheafModuleCatObjObj_coe (Y : Cᵒᵖ) :
(forgetToPresheafModuleCatObjObj X hX M Y : Type _) = M.obj Y := rfl
/-- Auxiliary definition for `forgetToPresheafModuleCatObj`. -/
noncomputable def forgetToPresheafModuleCatObjMap {Y Z : Cᵒᵖ} (f : Y ⟶ Z) :
forgetToPresheafModuleCatObjObj X hX M Y ⟶
forgetToPresheafModuleCatObjObj X hX M Z :=
ModuleCat.ofHom
(X := forgetToPresheafModuleCatObjObj X hX M Y) (Y := forgetToPresheafModuleCatObjObj X hX M Z)
{ toFun := fun x => M.map f x
map_add' := by simp
map_smul' := fun r x => by
simp only [ModuleCat.restrictScalars.smul_def, RingHom.id_apply, M.map_smul]
rw [← RingCat.comp_apply, ← R.map_comp]
congr
apply hX.hom_ext }
@[simp]
lemma forgetToPresheafModuleCatObjMap_apply {Y Z : Cᵒᵖ} (f : Y ⟶ Z) (m : M.obj Y) :
(forgetToPresheafModuleCatObjMap X hX M f).hom m = M.map f m := rfl
/--
Implementation of the functor `PresheafOfModules R ⥤ Cᵒᵖ ⥤ ModuleCat (R.obj X)`
when `X` is initial.
The functor is implemented as, on object level `M ↦ (c ↦ M(c))` where the `R(X)`-module structure
on `M(c)` is given by restriction of scalars along the unique morphism `R(c) ⟶ R(X)`; and on
morphism level `(f : M ⟶ N) ↦ (c ↦ f(c))`.
-/
@[simps]
noncomputable def forgetToPresheafModuleCatObj
(X : Cᵒᵖ) (hX : Limits.IsInitial X) (M : PresheafOfModules.{v} R) :
Cᵒᵖ ⥤ ModuleCat (R.obj X) where
obj Y := forgetToPresheafModuleCatObjObj X hX M Y
map f := forgetToPresheafModuleCatObjMap X hX M f
end
/--
Implementation of the functor `PresheafOfModules R ⥤ Cᵒᵖ ⥤ ModuleCat (R.obj X)`
when `X` is initial.
The functor is implemented as, on object level `M ↦ (c ↦ M(c))` where the `R(X)`-module structure
on `M(c)` is given by restriction of scalars along the unique morphism `R(c) ⟶ R(X)`; and on
morphism level `(f : M ⟶ N) ↦ (c ↦ f(c))`.
-/
noncomputable def forgetToPresheafModuleCatMap
(X : Cᵒᵖ) (hX : Limits.IsInitial X) {M N : PresheafOfModules.{v} R} (f : M ⟶ N) :
forgetToPresheafModuleCatObj X hX M ⟶ forgetToPresheafModuleCatObj X hX N where
app Y := ModuleCat.ofHom
(X := (forgetToPresheafModuleCatObj X hX M).obj Y)
(Y := (forgetToPresheafModuleCatObj X hX N).obj Y)
{ toFun := f.app Y
map_add' := by simp
map_smul' := fun r ↦ (f.app Y).hom.map_smul (R.map (hX.to Y) _) }
naturality Y Z g := by
ext x
exact naturality_apply f g x
/--
The forgetful functor from presheaves of modules over a presheaf of rings `R` to presheaves of
`R(X)`-modules where `X` is an initial object.
The functor is implemented as, on object level `M ↦ (c ↦ M(c))` where the `R(X)`-module structure
on `M(c)` is given by restriction of scalars along the unique morphism `R(c) ⟶ R(X)`; and on
morphism level `(f : M ⟶ N) ↦ (c ↦ f(c))`.
-/
@[simps]
noncomputable def forgetToPresheafModuleCat (X : Cᵒᵖ) (hX : Limits.IsInitial X) :
PresheafOfModules.{v} R ⥤ Cᵒᵖ ⥤ ModuleCat (R.obj X) where
obj M := forgetToPresheafModuleCatObj X hX M
map f := forgetToPresheafModuleCatMap X hX f
end module_over_initial
end PresheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Pseudofunctor.lean | import Mathlib.Algebra.Category.ModuleCat.ChangeOfRings
import Mathlib.Algebra.Category.Ring.Basic
import Mathlib.CategoryTheory.Bicategory.Functor.LocallyDiscrete
import Mathlib.CategoryTheory.Adjunction.Mates
/-!
# The pseudofunctors which send a commutative ring to its category of modules
In this file, we construct the pseudofunctors
`CommRingCat.moduleCatRestrictScalarsPseudofunctor` and
`RingCat.moduleCatRestrictScalarsPseudofunctor` which send a (commutative) ring
to its category of modules: the contravariant functoriality is given
by the restriction of scalars functors.
We also define a pseudofunctor
`CommRingCat.moduleCatExtendScalarsPseudofunctor`: the covariant functoriality
is given by the extension of scalars functors.
-/
universe v u
open CategoryTheory ModuleCat
/-- The pseudofunctor from `LocallyDiscrete CommRingCatᵒᵖ` to `Cat` which sends
a commutative ring `R` to its category of modules. The functoriality is given by
the restriction of scalars. -/
@[simps! obj map mapId mapComp]
noncomputable def CommRingCat.moduleCatRestrictScalarsPseudofunctor :
Pseudofunctor (LocallyDiscrete CommRingCat.{u}ᵒᵖ) Cat :=
LocallyDiscrete.mkPseudofunctor
(fun R ↦ Cat.of (ModuleCat.{v} R.unop))
(fun f ↦ restrictScalars f.unop.hom)
(fun R ↦ restrictScalarsId R.unop)
(fun f g ↦ restrictScalarsComp g.unop.hom f.unop.hom)
/-- The pseudofunctor from `LocallyDiscrete RingCatᵒᵖ` to `Cat` which sends a ring `R`
to its category of modules. The functoriality is given by the restriction of scalars. -/
@[simps! obj map mapId mapComp]
noncomputable def RingCat.moduleCatRestrictScalarsPseudofunctor :
Pseudofunctor (LocallyDiscrete RingCat.{u}ᵒᵖ) Cat :=
LocallyDiscrete.mkPseudofunctor
(fun R ↦ Cat.of (ModuleCat.{v} R.unop))
(fun f ↦ restrictScalars f.unop.hom)
(fun R ↦ restrictScalarsId R.unop)
(fun f g ↦ restrictScalarsComp g.unop.hom f.unop.hom)
/-- The pseudofunctor from `LocallyDiscrete CommRingCat` to `Cat` which sends
a commutative ring `R` to its category of modules. The functoriality is given by
the extension of scalars. -/
@[simps! obj map mapId mapComp]
noncomputable def CommRingCat.moduleCatExtendScalarsPseudofunctor :
Pseudofunctor (LocallyDiscrete CommRingCat.{u}) Cat :=
LocallyDiscrete.mkPseudofunctor
(fun R ↦ Cat.of (ModuleCat.{u} R))
(fun f ↦ extendScalars f.hom)
(fun R ↦ extendScalarsId R)
(fun f g ↦ extendScalarsComp f.hom g.hom)
(fun _ _ _ ↦ extendScalars_assoc' _ _ _)
(fun _ ↦ extendScalars_id_comp _)
(fun _ ↦ extendScalars_comp_id _) |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/ExteriorPower.lean | import Mathlib.LinearAlgebra.ExteriorPower.Basic
import Mathlib.Algebra.Category.ModuleCat.Basic
/-!
# The exterior powers as functors on the category of modules
In this file, given `M : ModuleCat R` and `n : ℕ`, we define `M.exteriorPower n : ModuleCat R`,
and this extends to a functor `ModuleCat.exteriorPower.functor : ModuleCat R ⥤ ModuleCat R`.
-/
universe v u
open CategoryTheory
namespace ModuleCat
variable {R : Type u} [CommRing R]
/-- The exterior power of an object in `ModuleCat R`. -/
def exteriorPower (M : ModuleCat.{v} R) (n : ℕ) : ModuleCat.{max u v} R :=
ModuleCat.of R (⋀[R]^n M)
-- this could be an abbrev, but using a def eases automation
/-- The type of `n`-alternating maps on `M : ModuleCat R` to `N : ModuleCat R`. -/
def AlternatingMap (M : ModuleCat.{v} R) (N : ModuleCat.{max u v} R) (n : ℕ) :=
_root_.AlternatingMap R M N (Fin n)
instance (M : ModuleCat.{v} R) (N : ModuleCat.{max u v} R) (n : ℕ) :
FunLike (M.AlternatingMap N n) (Fin n → M) N :=
inferInstanceAs (FunLike (M [⋀^(Fin n)]→ₗ[R] N) (Fin n → M) N)
namespace AlternatingMap
variable {M : ModuleCat.{v} R} {N : ModuleCat.{max u v} R} {n : ℕ}
@[ext]
lemma ext {φ φ' : M.AlternatingMap N n} (h : ∀ (x : Fin n → M), φ x = φ' x) :
φ = φ' :=
_root_.AlternatingMap.ext h
variable (φ : M.AlternatingMap N n) {N' : ModuleCat.{max u v} R} (g : N ⟶ N')
/-- The postcomposition of an alternating map by a linear map. -/
def postcomp : M.AlternatingMap N' n :=
g.hom.compAlternatingMap φ
@[simp]
lemma postcomp_apply (x : Fin n → M) :
φ.postcomp g x = g (φ x) := rfl
end AlternatingMap
namespace exteriorPower
/-- Constructor for elements in `M.exteriorPower n` when `M` is an object of `ModuleCat R`
and `n : ℕ`. -/
def mk {M : ModuleCat.{v} R} {n : ℕ} :
M.AlternatingMap (M.exteriorPower n) n :=
exteriorPower.ιMulti _ _
@[ext]
lemma hom_ext {M : ModuleCat.{v} R} {N : ModuleCat.{max u v} R} {n : ℕ}
{f g : M.exteriorPower n ⟶ N}
(h : mk.postcomp f = mk.postcomp g) : f = g := by
ext : 1
exact exteriorPower.linearMap_ext h
/-- The morphism `M.exteriorPower n ⟶ N` induced by an alternating map. -/
noncomputable def desc {M : ModuleCat.{v} R} {n : ℕ} {N : ModuleCat.{max u v} R}
(φ : M.AlternatingMap N n) : M.exteriorPower n ⟶ N :=
ofHom (exteriorPower.alternatingMapLinearEquiv φ)
@[simp]
lemma desc_mk {M : ModuleCat.{v} R} {n : ℕ} {N : ModuleCat.{max u v} R}
(φ : M.AlternatingMap N n) (x : Fin n → M) :
desc φ (mk x) = φ x := by
apply exteriorPower.alternatingMapLinearEquiv_apply_ιMulti
/-- The morphism `M.exteriorPower n ⟶ N.exteriorPower n` induced by a morphism `M ⟶ N`
in `ModuleCat R`. -/
noncomputable def map {M N : ModuleCat.{v} R} (f : M ⟶ N) (n : ℕ) :
M.exteriorPower n ⟶ N.exteriorPower n :=
ofHom (_root_.exteriorPower.map n f.hom)
@[simp]
lemma map_mk {M N : ModuleCat.{v} R} (f : M ⟶ N) {n : ℕ} (x : Fin n → M) :
map f n (mk x) = mk (f ∘ x) := by
apply exteriorPower.map_apply_ιMulti
variable (R) in
/-- The functor `ModuleCat R ⥤ ModuleCat R` which sends a module to its
`n`th exterior power. -/
@[simps]
noncomputable def functor (n : ℕ) : ModuleCat.{v} R ⥤ ModuleCat.{max u v} R where
obj M := M.exteriorPower n
map f := map f n
/-- The isomorphism `M.exteriorPower 0 ≅ ModuleCat.of R R`. -/
noncomputable def iso₀ (M : ModuleCat.{u} R) : M.exteriorPower 0 ≅ ModuleCat.of R R :=
(exteriorPower.zeroEquiv R M).toModuleIso
@[simp]
lemma iso₀_hom_apply {M : ModuleCat.{u} R} (f : Fin 0 → M) :
(iso₀ M).hom (mk f) = 1 :=
exteriorPower.zeroEquiv_ιMulti _
@[reassoc (attr := simp)]
lemma iso₀_hom_naturality {M N : ModuleCat.{u} R} (f : M ⟶ N) :
map f 0 ≫ (iso₀ N).hom = (iso₀ M).hom :=
ModuleCat.hom_ext (exteriorPower.zeroEquiv_naturality f.hom)
/-- The isomorphism `M.exteriorPower 1 ≅ M`. -/
noncomputable def iso₁ (M : ModuleCat.{u} R) : M.exteriorPower 1 ≅ M :=
(exteriorPower.oneEquiv R M).toModuleIso
@[simp]
lemma iso₁_hom_apply {M : ModuleCat.{u} R} (f : Fin 1 → M) :
(iso₁ M).hom (mk f) = f 0 :=
exteriorPower.oneEquiv_ιMulti _
@[reassoc (attr := simp)]
lemma iso₁_hom_naturality {M N : ModuleCat.{u} R} (f : M ⟶ N) :
map f 1 ≫ (iso₁ N).hom = (iso₁ M).hom ≫ f :=
ModuleCat.hom_ext (exteriorPower.oneEquiv_naturality f.hom)
variable (R)
/-- The natural isomorphism `M.exteriorPower 0 ≅ ModuleCat.of R R`. -/
noncomputable def natIso₀ : functor.{u} R 0 ≅ (Functor.const _).obj (ModuleCat.of R R) :=
NatIso.ofComponents iso₀
/-- The natural isomorphism `M.exteriorPower 1 ≅ M`. -/
noncomputable def natIso₁ : functor.{u} R 1 ≅ 𝟭 _ :=
NatIso.ofComponents iso₁
end exteriorPower
end ModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/EnoughInjectives.lean | import Mathlib.Algebra.Category.Grp.EnoughInjectives
import Mathlib.Algebra.Category.ModuleCat.ChangeOfRings
import Mathlib.Algebra.Ring.Shrink
/-!
# Category of $R$-modules has enough injectives
We lift enough injectives of abelian groups to arbitrary $R$-modules by adjoint functors
`restrictScalars ⊣ coextendScalars`
-/
open CategoryTheory
universe v u
variable (R : Type u) [Ring R]
instance : EnoughInjectives (ModuleCat.{v} ℤ) :=
EnoughInjectives.of_equivalence (forget₂ (ModuleCat ℤ) AddCommGrpCat)
lemma ModuleCat.enoughInjectives : EnoughInjectives (ModuleCat.{max v u} R) :=
EnoughInjectives.of_adjunction (ModuleCat.restrictCoextendScalarsAdj.{max v u} (algebraMap ℤ R))
open ModuleCat in
instance [Small.{v} R] : EnoughInjectives (ModuleCat.{v} R) :=
letI := enoughInjectives.{v} (Shrink.{v} R)
EnoughInjectives.of_equivalence (restrictScalars (equivShrink R).symm.ringEquiv.toRingHom) |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Tannaka.lean | import Mathlib.Algebra.Category.ModuleCat.Basic
import Mathlib.LinearAlgebra.Span.Basic
/-!
# Tannaka duality for rings
A ring `R` is equivalent to
the endomorphisms of the additive forgetful functor `Module R ⥤ AddCommGroup`.
-/
universe u
open CategoryTheory
/-- An ingredient of Tannaka duality for rings:
A ring `R` is equivalent to
the endomorphisms of the additive forgetful functor `Module R ⥤ AddCommGroup`.
-/
def ringEquivEndForget₂ (R : Type u) [Ring R] :
R ≃+* End (AdditiveFunctor.of (forget₂ (ModuleCat.{u} R) AddCommGrpCat.{u})) where
toFun r :=
{ app := fun M =>
@AddCommGrpCat.ofHom M.carrier M.carrier _ _ (DistribMulAction.toAddMonoidHom M r) }
invFun φ := φ.app (ModuleCat.of R R) (1 : R)
left_inv := by
intro r
simp
right_inv := by
intro φ
apply NatTrans.ext
ext M (x : M)
have w := CategoryTheory.congr_fun
(φ.naturality (ModuleCat.ofHom (LinearMap.toSpanSingleton R M x))) (1 : R)
exact w.symm.trans (congr_arg (φ.app M) (one_smul R x))
map_add' := by
intros
apply NatTrans.ext
ext
simp only [AdditiveFunctor.of_fst, ModuleCat.forget₂_obj, DistribMulAction.toAddMonoidHom_apply,
add_smul, AddCommGrpCat.hom_ofHom]
rfl
map_mul' := by
intros
apply NatTrans.ext
ext
simp only [AdditiveFunctor.of_fst, ModuleCat.forget₂_obj, DistribMulAction.toAddMonoidHom_apply,
mul_smul, AddCommGrpCat.hom_ofHom]
rfl |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Basic.lean | import Mathlib.Algebra.Category.ModuleCat.Semi
import Mathlib.Algebra.Category.Grp.Preadditive
import Mathlib.CategoryTheory.Linear.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
/-!
# The category of `R`-modules
`ModuleCat.{v} R` is the category of bundled `R`-modules with carrier in the universe `v`. We show
that it is preadditive and show that being an isomorphism, monomorphism and epimorphism is
equivalent to being a linear equivalence, an injective linear map and a surjective linear map,
respectively.
## Implementation details
To construct an object in the category of `R`-modules from a type `M` with an instance of the
`Module` typeclass, write `of R M`. There is a coercion in the other direction.
The roundtrip `↑(of R M)` is definitionally equal to `M` itself (when `M` is a type with `Module`
instance), and so is `of R ↑M` (when `M : ModuleCat R M`).
The morphisms are given their own type, not identified with `LinearMap`.
There is a cast from morphisms in `Module R` to linear maps, written `f.hom` (`ModuleCat.Hom.hom`).
To go from linear maps to morphisms in `Module R`, use `ModuleCat.ofHom`.
Similarly, given an isomorphism `f : M ≅ N` use `f.toLinearEquiv` and given a linear equiv
`f : M ≃ₗ[R] N`, use `f.toModuleIso`.
-/
open CategoryTheory
open CategoryTheory.Limits
open CategoryTheory.Limits.WalkingParallelPair
universe v u
variable (R : Type u) [Ring R]
/-- The category of R-modules and their morphisms.
Note that in the case of `R = ℤ`, we cannot
impose here that the `ℤ`-multiplication field from the module structure is defeq to the one coming
from the `isAddCommGroup` structure (contrary to what we do for all module structures in
mathlib), which creates some difficulties down the road. -/
structure ModuleCat where
private mk ::
/-- the underlying type of an object in `ModuleCat R` -/
carrier : Type v
[isAddCommGroup : AddCommGroup carrier]
[isModule : Module R carrier]
attribute [instance] ModuleCat.isAddCommGroup ModuleCat.isModule
namespace ModuleCat
instance : CoeSort (ModuleCat.{v} R) (Type v) :=
⟨ModuleCat.carrier⟩
attribute [coe] ModuleCat.carrier
/-- The object in the category of R-algebras associated to a type equipped with the appropriate
typeclasses. This is the preferred way to construct a term of `ModuleCat R`. -/
abbrev of (X : Type v) [AddCommGroup X] [Module R X] : ModuleCat.{v} R :=
⟨X⟩
lemma coe_of (X : Type v) [Ring X] [Module R X] : (of R X : Type v) = X :=
rfl
-- Ensure the roundtrips are reducibly defeq (so tactics like `rw` can see through them).
example (X : Type v) [Ring X] [Module R X] : (of R X : Type v) = X := by with_reducible rfl
example (M : ModuleCat.{v} R) : of R M = M := by with_reducible rfl
variable {R} in
/-- The type of morphisms in `ModuleCat R`. -/
@[ext]
structure Hom (M N : ModuleCat.{v} R) where
private mk ::
/-- The underlying linear map. -/
hom' : M →ₗ[R] N
instance moduleCategory : Category.{v, max (v + 1) u} (ModuleCat.{v} R) where
Hom M N := Hom M N
id _ := ⟨LinearMap.id⟩
comp f g := ⟨g.hom'.comp f.hom'⟩
instance : ConcreteCategory (ModuleCat.{v} R) (· →ₗ[R] ·) where
hom := Hom.hom'
ofHom := Hom.mk
section
variable {R}
/-- Turn a morphism in `ModuleCat` back into a `LinearMap`. -/
abbrev Hom.hom {A B : ModuleCat.{v} R} (f : Hom A B) :=
ConcreteCategory.hom (C := ModuleCat R) f
/-- Typecheck a `LinearMap` as a morphism in `ModuleCat`. -/
abbrev ofHom {X Y : Type v} [AddCommGroup X] [Module R X] [AddCommGroup Y] [Module R Y]
(f : X →ₗ[R] Y) : of R X ⟶ of R Y :=
ConcreteCategory.ofHom (C := ModuleCat R) f
/-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/
def Hom.Simps.hom (A B : ModuleCat.{v} R) (f : Hom A B) :=
f.hom
initialize_simps_projections Hom (hom' → hom)
/-!
The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`.
-/
@[simp]
lemma hom_id {M : ModuleCat.{v} R} : (𝟙 M : M ⟶ M).hom = LinearMap.id := rfl
/- Provided for rewriting. -/
lemma id_apply (M : ModuleCat.{v} R) (x : M) :
(𝟙 M : M ⟶ M) x = x := by simp
@[simp]
lemma hom_comp {M N O : ModuleCat.{v} R} (f : M ⟶ N) (g : N ⟶ O) :
(f ≫ g).hom = g.hom.comp f.hom := rfl
/- Provided for rewriting. -/
lemma comp_apply {M N O : ModuleCat.{v} R} (f : M ⟶ N) (g : N ⟶ O) (x : M) :
(f ≫ g) x = g (f x) := by simp
@[ext]
lemma hom_ext {M N : ModuleCat.{v} R} {f g : M ⟶ N} (hf : f.hom = g.hom) : f = g :=
Hom.ext hf
lemma hom_bijective {M N : ModuleCat.{v} R} :
Function.Bijective (Hom.hom : (M ⟶ N) → (M →ₗ[R] N)) where
left f g h := by cases f; cases g; simpa using h
right f := ⟨⟨f⟩, rfl⟩
/-- Convenience shortcut for `ModuleCat.hom_bijective.injective`. -/
lemma hom_injective {M N : ModuleCat.{v} R} :
Function.Injective (Hom.hom : (M ⟶ N) → (M →ₗ[R] N)) :=
hom_bijective.injective
/-- Convenience shortcut for `ModuleCat.hom_bijective.surjective`. -/
lemma hom_surjective {M N : ModuleCat.{v} R} :
Function.Surjective (Hom.hom : (M ⟶ N) → (M →ₗ[R] N)) :=
hom_bijective.surjective
@[simp]
lemma hom_ofHom {X Y : Type v} [AddCommGroup X] [Module R X] [AddCommGroup Y]
[Module R Y] (f : X →ₗ[R] Y) : (ofHom f).hom = f := rfl
@[simp]
lemma ofHom_hom {M N : ModuleCat.{v} R} (f : M ⟶ N) :
ofHom (Hom.hom f) = f := rfl
@[simp]
lemma ofHom_id {M : Type v} [AddCommGroup M] [Module R M] : ofHom LinearMap.id = 𝟙 (of R M) := rfl
@[simp]
lemma ofHom_comp {M N O : Type v} [AddCommGroup M] [AddCommGroup N] [AddCommGroup O] [Module R M]
[Module R N] [Module R O] (f : M →ₗ[R] N) (g : N →ₗ[R] O) :
ofHom (g.comp f) = ofHom f ≫ ofHom g :=
rfl
/- Doesn't need to be `@[simp]` since `simp only` can solve this. -/
lemma ofHom_apply {M N : Type v} [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N]
(f : M →ₗ[R] N) (x : M) : ofHom f x = f x := rfl
lemma inv_hom_apply {M N : ModuleCat.{v} R} (e : M ≅ N) (x : M) : e.inv (e.hom x) = x := by
simp
lemma hom_inv_apply {M N : ModuleCat.{v} R} (e : M ≅ N) (x : N) : e.hom (e.inv x) = x := by
simp
/-- `ModuleCat.Hom.hom` bundled as an `Equiv`. -/
def homEquiv {M N : ModuleCat.{v} R} : (M ⟶ N) ≃ (M →ₗ[R] N) where
toFun := Hom.hom
invFun := ofHom
/-- The categorical equivalence between `ModuleCat` and `SemimoduleCat`.
In the inverse direction, data (such as the negation operation) is created which may lead to
diamonds when applied to semi-modules that already have an existing additive group structure. -/
def equivalenceSemimoduleCat : ModuleCat.{v} R ≌ SemimoduleCat.{v} R where
functor :=
{ obj M := .of R M
map f := SemimoduleCat.ofHom f.hom' }
inverse := letI := Module.addCommMonoidToAddCommGroup
{ obj M := of R M
map {M N} f := ofHom f.hom }
unitIso := NatIso.ofComponents fun _ ↦ { hom := ⟨.id⟩, inv := ⟨.id⟩ }
counitIso := NatIso.ofComponents fun _ ↦ { hom := ⟨.id⟩, inv := ⟨.id⟩ }
end
/- Not a `@[simp]` lemma since it will rewrite the (co)domain of maps and cause
definitional equality issues. -/
lemma forget_obj {M : ModuleCat.{v} R} : (forget (ModuleCat.{v} R)).obj M = M := rfl
@[simp]
lemma forget_map {M N : ModuleCat.{v} R} (f : M ⟶ N) :
(forget (ModuleCat.{v} R)).map f = f :=
rfl
instance hasForgetToAddCommGroup : HasForget₂ (ModuleCat R) AddCommGrpCat where
forget₂ :=
{ obj := fun M => AddCommGrpCat.of M
map := fun f => AddCommGrpCat.ofHom f.hom.toAddMonoidHom }
@[simp]
theorem forget₂_obj (X : ModuleCat R) :
(forget₂ (ModuleCat R) AddCommGrpCat).obj X = AddCommGrpCat.of X :=
rfl
theorem forget₂_obj_moduleCat_of (X : Type v) [AddCommGroup X] [Module R X] :
(forget₂ (ModuleCat R) AddCommGrpCat).obj (of R X) = AddCommGrpCat.of X :=
rfl
@[simp]
theorem forget₂_map (X Y : ModuleCat R) (f : X ⟶ Y) :
(forget₂ (ModuleCat R) AddCommGrpCat).map f = AddCommGrpCat.ofHom f.hom :=
rfl
instance : Inhabited (ModuleCat R) :=
⟨of R PUnit⟩
@[simp] theorem of_coe (X : ModuleCat R) : of R X = X := rfl
variable {R}
/-- Forgetting to the underlying type and then building the bundled object returns the original
module. -/
@[deprecated Iso.refl (since := "2025-05-15")]
def ofSelfIso (M : ModuleCat R) : ModuleCat.of R M ≅ M where
hom := 𝟙 M
inv := 𝟙 M
theorem isZero_of_subsingleton (M : ModuleCat R) [Subsingleton M] : IsZero M where
unique_to X := ⟨⟨⟨ofHom (0 : M →ₗ[R] X)⟩, fun f => by
ext x
rw [Subsingleton.elim x (0 : M)]
simp⟩⟩
unique_from X := ⟨⟨⟨ofHom (0 : X →ₗ[R] M)⟩, fun f => by
ext x
subsingleton⟩⟩
instance : HasZeroObject (ModuleCat.{v} R) :=
⟨⟨of R PUnit, isZero_of_subsingleton _⟩⟩
end ModuleCat
variable {R}
variable {X₁ X₂ : Type v}
open ModuleCat
/-- Reinterpreting a linear map in the category of `R`-modules -/
scoped[ModuleCat] notation "↟" f:1024 => ModuleCat.ofHom f
section
/-- Build an isomorphism in the category `Module R` from a `LinearEquiv` between `Module`s. -/
@[simps]
def LinearEquiv.toModuleIso {g₁ : AddCommGroup X₁} {g₂ : AddCommGroup X₂} {m₁ : Module R X₁}
{m₂ : Module R X₂} (e : X₁ ≃ₗ[R] X₂) : ModuleCat.of R X₁ ≅ ModuleCat.of R X₂ where
hom := ofHom (e : X₁ →ₗ[R] X₂)
inv := ofHom (e.symm : X₂ →ₗ[R] X₁)
hom_inv_id := by ext; apply e.left_inv
inv_hom_id := by ext; apply e.right_inv
namespace CategoryTheory.Iso
variable {X Y : ModuleCat R}
/-- Build a `LinearEquiv` from an isomorphism in the category `ModuleCat R`. -/
def toLinearEquiv (i : X ≅ Y) : X ≃ₗ[R] Y :=
.ofLinear i.hom.hom i.inv.hom (by aesop) (by aesop)
@[simp] lemma toLinearEquiv_apply (i : X ≅ Y) (x : X) : i.toLinearEquiv x = i.hom x := rfl
@[simp] lemma toLinearEquiv_symm (i : X ≅ Y) : i.toLinearEquiv.symm = i.symm.toLinearEquiv := rfl
@[simp] lemma toLinearMap_toLinearEquiv (i : X ≅ Y) : i.toLinearEquiv = i.hom.hom := rfl
end CategoryTheory.Iso
/-- linear equivalences between `Module`s are the same as (isomorphic to) isomorphisms
in `ModuleCat` -/
@[simps]
def linearEquivIsoModuleIso {X Y : Type u} [AddCommGroup X] [AddCommGroup Y] [Module R X]
[Module R Y] : (X ≃ₗ[R] Y) ≅ ModuleCat.of R X ≅ ModuleCat.of R Y where
hom e := e.toModuleIso
inv i := i.toLinearEquiv
end
namespace ModuleCat
section AddCommGroup
variable {M N : ModuleCat.{v} R}
instance : Add (M ⟶ N) where
add f g := ⟨f.hom + g.hom⟩
@[simp] lemma hom_add (f g : M ⟶ N) : (f + g).hom = f.hom + g.hom := rfl
instance : Zero (M ⟶ N) where
zero := ⟨0⟩
@[simp] lemma hom_zero : (0 : M ⟶ N).hom = 0 := rfl
instance : SMul ℕ (M ⟶ N) where
smul n f := ⟨n • f.hom⟩
@[simp] lemma hom_nsmul (n : ℕ) (f : M ⟶ N) : (n • f).hom = n • f.hom := rfl
instance : Neg (M ⟶ N) where
neg f := ⟨-f.hom⟩
@[simp] lemma hom_neg (f : M ⟶ N) : (-f).hom = -f.hom := rfl
instance : Sub (M ⟶ N) where
sub f g := ⟨f.hom - g.hom⟩
@[simp] lemma hom_sub (f g : M ⟶ N) : (f - g).hom = f.hom - g.hom := rfl
instance : SMul ℤ (M ⟶ N) where
smul n f := ⟨n • f.hom⟩
@[simp] lemma hom_zsmul (n : ℕ) (f : M ⟶ N) : (n • f).hom = n • f.hom := rfl
instance : AddCommGroup (M ⟶ N) :=
Function.Injective.addCommGroup (Hom.hom) hom_injective
rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
@[simp] lemma hom_sum {ι : Type*} (f : ι → (M ⟶ N)) (s : Finset ι) :
(∑ i ∈ s, f i).hom = ∑ i ∈ s, (f i).hom :=
map_sum ({ toFun := ModuleCat.Hom.hom, map_zero' := ModuleCat.hom_zero, map_add' := hom_add } :
(M ⟶ N) →+ (M →ₗ[R] N)) _ _
instance : Preadditive (ModuleCat.{v} R) where
instance forget₂_addCommGrp_additive :
(forget₂ (ModuleCat.{v} R) AddCommGrpCat).Additive where
/-- `ModuleCat.Hom.hom` bundled as an additive equivalence. -/
@[simps!]
def homAddEquiv : (M ⟶ N) ≃+ (M →ₗ[R] N) :=
{ homEquiv with
map_add' := fun _ _ => rfl }
theorem subsingleton_of_isZero (h : IsZero M) : Subsingleton M := by
refine subsingleton_of_forall_eq 0 (fun x ↦ ?_)
rw [← LinearMap.id_apply (R := R) x, ← ModuleCat.hom_id]
simp only [(CategoryTheory.Limits.IsZero.iff_id_eq_zero M).mp h, hom_zero, LinearMap.zero_apply]
lemma isZero_iff_subsingleton : IsZero M ↔ Subsingleton M where
mp := subsingleton_of_isZero
mpr _ := isZero_of_subsingleton M
@[simp]
lemma isZero_of_iff_subsingleton {M : Type*} [AddCommGroup M] [Module R M] :
IsZero (of R M) ↔ Subsingleton M := isZero_iff_subsingleton
end AddCommGroup
section SMul
variable {M N : ModuleCat.{v} R} {S : Type*} [Monoid S] [DistribMulAction S N] [SMulCommClass R S N]
instance : SMul S (M ⟶ N) where
smul c f := ⟨c • f.hom⟩
@[simp] lemma hom_smul (s : S) (f : M ⟶ N) : (s • f).hom = s • f.hom := rfl
end SMul
section Module
variable {M N : ModuleCat.{v} R} {S : Type*} [Semiring S] [Module S N] [SMulCommClass R S N]
instance Hom.instModule : Module S (M ⟶ N) :=
Function.Injective.module S
{ toFun := Hom.hom, map_zero' := hom_zero, map_add' := hom_add }
hom_injective
(fun _ _ => rfl)
/-- `ModuleCat.Hom.hom` bundled as a linear equivalence. -/
@[simps]
def homLinearEquiv : (M ⟶ N) ≃ₗ[S] (M →ₗ[R] N) :=
{ homAddEquiv with
map_smul' := fun _ _ => rfl }
end Module
section
universe u₀
namespace Algebra
variable {S₀ : Type u₀} [CommSemiring S₀] {S : Type u} [Ring S] [Algebra S₀ S]
variable {M N : ModuleCat.{v} S}
/--
Let `S` be an `S₀`-algebra. Then `S`-modules are modules over `S₀`.
-/
scoped instance : Module S₀ M := Module.compHom _ (algebraMap S₀ S)
scoped instance : IsScalarTower S₀ S M where
smul_assoc _ _ _ := by rw [Algebra.smul_def, mul_smul]; rfl
scoped instance : SMulCommClass S S₀ M where
smul_comm s s₀ n :=
show s • algebraMap S₀ S s₀ • n = algebraMap S₀ S s₀ • s • n by
rw [← smul_assoc, smul_eq_mul, ← Algebra.commutes, mul_smul]
/--
Let `S` be an `S₀`-algebra. Then the category of `S`-modules is `S₀`-linear.
-/
scoped instance instLinear : Linear S₀ (ModuleCat.{v} S) where
smul_comp _ M N s₀ f g := by ext; simp
end Algebra
section
variable {S : Type u} [CommRing S]
instance : Linear S (ModuleCat.{v} S) := ModuleCat.Algebra.instLinear
variable {X Y X' Y' : ModuleCat.{v} S}
theorem Iso.homCongr_eq_arrowCongr (i : X ≅ X') (j : Y ≅ Y') (f : X ⟶ Y) :
Iso.homCongr i j f = ⟨LinearEquiv.arrowCongr i.toLinearEquiv j.toLinearEquiv f.hom⟩ :=
rfl
theorem Iso.conj_eq_conj (i : X ≅ X') (f : End X) :
Iso.conj i f = ⟨LinearEquiv.conj i.toLinearEquiv f.hom⟩ :=
rfl
end
end
variable (M N : ModuleCat.{v} R)
/-- `ModuleCat.Hom.hom` as an isomorphism of rings. -/
@[simps!] def endRingEquiv : End M ≃+* (M →ₗ[R] M) where
toFun := ModuleCat.Hom.hom
invFun := ModuleCat.ofHom
map_mul' _ _ := rfl
map_add' _ _ := rfl
/-- The scalar multiplication on an object of `ModuleCat R` considered as
a morphism of rings from `R` to the endomorphisms of the underlying abelian group. -/
def smul : R →+* End ((forget₂ (ModuleCat R) AddCommGrpCat).obj M) where
toFun r := AddCommGrpCat.ofHom
{ toFun := fun (m : M) => r • m
map_zero' := by rw [smul_zero]
map_add' := fun x y => by rw [smul_add] }
map_one' := AddCommGrpCat.ext (fun x => by simp)
map_zero' := AddCommGrpCat.ext (fun x => by simp)
map_mul' r s := AddCommGrpCat.ext (fun (x : M) => (smul_smul r s x).symm)
map_add' r s := AddCommGrpCat.ext (fun (x : M) => add_smul r s x)
lemma smul_naturality {M N : ModuleCat.{v} R} (f : M ⟶ N) (r : R) :
(forget₂ (ModuleCat R) AddCommGrpCat).map f ≫ N.smul r =
M.smul r ≫ (forget₂ (ModuleCat R) AddCommGrpCat).map f := by
ext x
exact (f.hom.map_smul r x).symm
variable (R) in
/-- The scalar multiplication on `ModuleCat R` considered as a morphism of rings
to the endomorphisms of the forgetful functor to `AddCommGrpCat)`. -/
@[simps]
def smulNatTrans : R →+* End (forget₂ (ModuleCat R) AddCommGrpCat) where
toFun r :=
{ app := fun M => M.smul r
naturality := fun _ _ _ => smul_naturality _ r }
map_one' := NatTrans.ext (by cat_disch)
map_zero' := NatTrans.ext (by cat_disch)
map_mul' _ _ := NatTrans.ext (by cat_disch)
map_add' _ _ := NatTrans.ext (by cat_disch)
/-- Given `A : AddCommGrpCat` and a ring morphism `R →+* End A`, this is a type synonym
for `A`, on which we shall define a structure of `R`-module. -/
@[nolint unusedArguments]
def mkOfSMul' {A : AddCommGrpCat} (_ : R →+* End A) := A
section
variable {A : AddCommGrpCat} (φ : R →+* End A)
instance : AddCommGroup (mkOfSMul' φ) := by
dsimp only [mkOfSMul']
infer_instance
instance : SMul R (mkOfSMul' φ) := ⟨fun r (x : A) => (show A ⟶ A from φ r) x⟩
@[simp]
lemma mkOfSMul'_smul (r : R) (x : mkOfSMul' φ) :
r • x = (show A ⟶ A from φ r) x := rfl
instance : Module R (mkOfSMul' φ) where
smul_zero _ := map_zero (N := A) _
smul_add _ _ _ := map_add (N := A) _ _ _
one_smul := by simp
mul_smul := by simp
add_smul _ _ _ := by simp; rfl
zero_smul := by simp
/-- Given `A : AddCommGrpCat` and a ring morphism `R →+* End A`, this is an object in
`ModuleCat R`, whose underlying abelian group is `A` and whose scalar multiplication is
given by `R`. -/
abbrev mkOfSMul := ModuleCat.of R (mkOfSMul' φ)
lemma mkOfSMul_smul (r : R) : (mkOfSMul φ).smul r = φ r := rfl
end
section
variable {M N}
(φ : (forget₂ (ModuleCat R) AddCommGrpCat).obj M ⟶
(forget₂ (ModuleCat R) AddCommGrpCat).obj N)
(hφ : ∀ (r : R), φ ≫ N.smul r = M.smul r ≫ φ)
/-- Constructor for morphisms in `ModuleCat R` which takes as inputs
a morphism between the underlying objects in `AddCommGrpCat` and the compatibility
with the scalar multiplication. -/
@[simps]
def homMk : M ⟶ N where
hom'.toFun := φ
hom'.map_add' _ _ := φ.hom.map_add _ _
hom'.map_smul' r x := (congr_hom (hφ r) x).symm
lemma forget₂_map_homMk :
(forget₂ (ModuleCat R) AddCommGrpCat).map (homMk φ hφ) = φ := rfl
end
instance : (forget (ModuleCat.{v} R)).ReflectsIsomorphisms where
reflects f _ :=
(inferInstance : IsIso ((LinearEquiv.mk f.hom
(asIso ((forget (ModuleCat R)).map f)).toEquiv.invFun
(Equiv.left_inv _) (Equiv.right_inv _)).toModuleIso).hom)
instance : (forget₂ (ModuleCat.{v} R) AddCommGrpCat.{v}).ReflectsIsomorphisms where
reflects f _ := by
have : IsIso ((forget _).map f) := by
change IsIso ((forget _).map ((forget₂ _ AddCommGrpCat).map f))
infer_instance
apply isIso_of_reflects_iso _ (forget _)
end ModuleCat
section Bilinear
variable {R : Type*} [CommRing R]
namespace ModuleCat
/-- Turn a bilinear map into a homomorphism. -/
@[simps!]
def ofHom₂ {M N P : ModuleCat.{u} R} (f : M →ₗ[R] N →ₗ[R] P) :
M ⟶ of R (N ⟶ P) :=
ofHom <| homLinearEquiv.symm.toLinearMap ∘ₗ f
/-- Turn a homomorphism into a bilinear map. -/
@[simps!]
def Hom.hom₂ {M N P : ModuleCat.{u} R}
-- We write `Hom` instead of `M ⟶ (of R (N ⟶ P))`, otherwise dot notation breaks
-- since it is expecting the type of `f` to be `ModuleCat.Hom`, not `Quiver.Hom`.
(f : Hom M (of R (N ⟶ P))) :
M →ₗ[R] N →ₗ[R] P :=
Hom.hom (by convert (f ≫ ofHom homLinearEquiv.toLinearMap))
@[simp] lemma Hom.hom₂_ofHom₂ {M N P : ModuleCat.{u} R} (f : M →ₗ[R] N →ₗ[R] P) :
(ofHom₂ f).hom₂ = f := rfl
@[simp] lemma ofHom₂_hom₂ {M N P : ModuleCat.{u} R} (f : M ⟶ of R (N ⟶ P)) :
ofHom₂ f.hom₂ = f := rfl
end ModuleCat
end Bilinear
/-!
`@[simp]` lemmas for `LinearMap.comp` and categorical identities.
-/
@[simp] theorem LinearMap.comp_id_moduleCat
{R} [Ring R] {G : ModuleCat.{u} R} {H : Type u} [AddCommGroup H] [Module R H] (f : G →ₗ[R] H) :
f.comp (𝟙 G : G ⟶ G).hom = f := by simp
@[simp] theorem LinearMap.id_moduleCat_comp
{R} [Ring R] {G : Type u} [AddCommGroup G] [Module R G] {H : ModuleCat.{u} R} (f : G →ₗ[R] H) :
LinearMap.comp (𝟙 H : H ⟶ H).hom f = f := by simp |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Simple.lean | import Mathlib.Algebra.Category.ModuleCat.Algebra
import Mathlib.Algebra.Category.ModuleCat.Subobject
import Mathlib.CategoryTheory.Simple
import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas
import Mathlib.RingTheory.SimpleModule.Basic
/-!
# Simple objects in the category of `R`-modules
We prove simple modules are exactly simple objects in the category of `R`-modules.
-/
variable {R M : Type*} [Ring R] [AddCommGroup M] [Module R M]
open CategoryTheory ModuleCat
theorem simple_iff_isSimpleModule : Simple (of R M) ↔ IsSimpleModule R M := by
rw [simple_iff_subobject_isSimpleOrder, (subobjectModule (of R M)).isSimpleOrder_iff,
isSimpleModule_iff]
theorem simple_iff_isSimpleModule' (M : ModuleCat R) : Simple M ↔ IsSimpleModule R M :=
simple_iff_isSimpleModule
/-- A simple module is a simple object in the category of modules. -/
instance simple_of_isSimpleModule [IsSimpleModule R M] : Simple (of R M) :=
simple_iff_isSimpleModule.mpr ‹_›
/-- A simple object in the category of modules is a simple module. -/
instance isSimpleModule_of_simple (M : ModuleCat R) [Simple M] : IsSimpleModule R M :=
simple_iff_isSimpleModule.mp ‹_›
open Module
attribute [local instance] moduleOfAlgebraModule isScalarTower_of_algebra_moduleCat
/-- Any `k`-algebra module which is 1-dimensional over `k` is simple. -/
theorem simple_of_finrank_eq_one {k : Type*} [Field k] [Algebra k R] {V : ModuleCat R}
(h : finrank k V = 1) : Simple V :=
(simple_iff_isSimpleModule' V).mpr <| (isSimpleModule_iff ..).mpr <|
is_simple_module_of_finrank_eq_one h |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/FilteredColimits.lean | import Mathlib.Algebra.Category.Grp.FilteredColimits
import Mathlib.Algebra.Category.ModuleCat.Colimits
/-!
# The forgetful functor from `R`-modules preserves filtered colimits.
Forgetful functors from algebraic categories usually don't preserve colimits. However, they tend
to preserve _filtered_ colimits.
In this file, we start with a ring `R`, a small filtered category `J` and a functor
`F : J ⥤ ModuleCat R`. We show that the colimit of `F ⋙ forget₂ (ModuleCat R) AddCommGrpCat`
(in `AddCommGrpCat`) carries the structure of an `R`-module, thereby showing that the forgetful
functor `forget₂ (ModuleCat R) AddCommGrpCat` preserves filtered colimits. In particular, this
implies that `forget (ModuleCat R)` preserves filtered colimits.
-/
universe v u
noncomputable section
open CategoryTheory CategoryTheory.Limits
open CategoryTheory.IsFiltered renaming max → max' -- avoid name collision with `_root_.max`.
namespace ModuleCat.FilteredColimits
section
variable {R : Type u} [Ring R] {J : Type v} [SmallCategory J] [IsFiltered J]
variable (F : J ⥤ ModuleCat.{max v u, u} R)
/-- The colimit of `F ⋙ forget₂ (ModuleCat R) AddCommGrpCat` in the category `AddCommGrpCat`.
In the following, we will show that this has the structure of an `R`-module.
-/
def M : AddCommGrpCat :=
AddCommGrpCat.FilteredColimits.colimit.{v, u}
(F ⋙ forget₂ (ModuleCat R) AddCommGrpCat.{max v u})
/-- The canonical projection into the colimit, as a quotient type. -/
def M.mk : (Σ j, F.obj j) → M F :=
fun x ↦ (F ⋙ forget (ModuleCat R)).ιColimitType x.1 x.2
lemma M.mk_surjective (m : M F) :
∃ (j : J) (x : F.obj j), M.mk F ⟨j, x⟩ = m :=
(F ⋙ forget (ModuleCat R)).ιColimitType_jointly_surjective m
theorem M.mk_eq (x y : Σ j, F.obj j)
(h : ∃ (k : J) (f : x.1 ⟶ k) (g : y.1 ⟶ k), F.map f x.2 = F.map g y.2) : M.mk F x = M.mk F y :=
Quot.eqvGen_sound (Types.FilteredColimit.eqvGen_colimitTypeRel_of_rel
(F ⋙ forget (ModuleCat R)) x y h)
lemma M.mk_map {j k : J} (f : j ⟶ k) (x : F.obj j) :
M.mk F ⟨k, F.map f x⟩ = M.mk F ⟨j, x⟩ :=
M.mk_eq _ _ _ ⟨k, 𝟙 _, f, by simp⟩
/-- The "unlifted" version of scalar multiplication in the colimit. -/
def colimitSMulAux (r : R) (x : Σ j, F.obj j) : M F :=
M.mk F ⟨x.1, r • x.2⟩
theorem colimitSMulAux_eq_of_rel (r : R) (x y : Σ j, F.obj j)
(h : Types.FilteredColimit.Rel (F ⋙ forget (ModuleCat R)) x y) :
colimitSMulAux F r x = colimitSMulAux F r y := by
apply M.mk_eq
obtain ⟨k, f, g, hfg⟩ := h
use k, f, g
simp only [Functor.comp_obj, Functor.comp_map, forget_map] at hfg
simp [hfg]
/-- Scalar multiplication in the colimit. See also `colimitSMulAux`. -/
instance colimitHasSMul : SMul R (M F) where
smul r x := by
refine Quot.lift (colimitSMulAux F r) ?_ x
intro x y h
apply colimitSMulAux_eq_of_rel
apply Types.FilteredColimit.rel_of_colimitTypeRel
exact h
lemma colimit_zero_eq (j : J) :
0 = M.mk F ⟨j, 0⟩ := by
apply AddMonCat.FilteredColimits.colimit_zero_eq
lemma colimit_add_mk_eq (x y : Σ j, F.obj j) (k : J)
(f : x.1 ⟶ k) (g : y.1 ⟶ k) :
M.mk _ x + M.mk _ y = M.mk _ ⟨k, F.map f x.2 + F.map g y.2⟩ := by
apply AddMonCat.FilteredColimits.colimit_add_mk_eq
lemma colimit_add_mk_eq' {j : J} (x y : F.obj j) :
M.mk F ⟨j, x⟩ + M.mk F ⟨j, y⟩ = M.mk F ⟨j, x + y⟩ := by
apply AddMonCat.FilteredColimits.colimit_add_mk_eq'
@[simp]
theorem colimit_smul_mk_eq (r : R) (x : Σ j, F.obj j) : r • M.mk F x = M.mk F ⟨x.1, r • x.2⟩ :=
rfl
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11083): writing directly the `Module` instance makes things very slow.
instance colimitMulAction : MulAction R (M F) where
one_smul x := by
obtain ⟨j, x, rfl⟩ := M.mk_surjective F x
simp
mul_smul r s x := by
obtain ⟨j, x, rfl⟩ := M.mk_surjective F x
simp [mul_smul]
instance colimitSMulWithZero : SMulWithZero R (M F) :=
{ colimitMulAction F with
smul_zero := fun r => by
rw [colimit_zero_eq _ (IsFiltered.nonempty.some : J), colimit_smul_mk_eq, smul_zero]
zero_smul := fun x => by
obtain ⟨j, x, rfl⟩ := M.mk_surjective F x
simp [← colimit_zero_eq] }
instance colimitModule : Module R (M F) :=
{ colimitMulAction F,
colimitSMulWithZero F with
smul_add := fun r x y => by
obtain ⟨i, x, rfl⟩ := M.mk_surjective F x
obtain ⟨j, y, rfl⟩ := M.mk_surjective F y
rw [colimit_smul_mk_eq, colimit_smul_mk_eq,
colimit_add_mk_eq _ ⟨i, _⟩ ⟨j, _⟩ (max' i j) (IsFiltered.leftToMax i j)
(IsFiltered.rightToMax i j), colimit_smul_mk_eq, smul_add,
colimit_add_mk_eq _ ⟨i, _⟩ ⟨j, _⟩ (max' i j) (IsFiltered.leftToMax i j)
(IsFiltered.rightToMax i j), LinearMap.map_smul, LinearMap.map_smul]
add_smul r s x := by
obtain ⟨i, x, rfl⟩ := M.mk_surjective F x
simp [_root_.add_smul, colimit_add_mk_eq'] }
/-- The bundled `R`-module giving the filtered colimit of a diagram. -/
def colimit : ModuleCat.{max v u, u} R :=
ModuleCat.of R (M F)
/-- The linear map from a given `R`-module in the diagram to the colimit module. -/
def coconeMorphism (j : J) : F.obj j ⟶ colimit F :=
ofHom
{ ((AddCommGrpCat.FilteredColimits.colimitCocone
(F ⋙ forget₂ (ModuleCat R) AddCommGrpCat.{max v u})).ι.app j).hom with
map_smul' := by solve_by_elim }
/-- The cocone over the proposed colimit module. -/
def colimitCocone : Cocone F where
pt := colimit F
ι :=
{ app := coconeMorphism F
naturality := fun _ _' f =>
hom_ext <| LinearMap.coe_injective
((Types.TypeMax.colimitCocone (F ⋙ forget (ModuleCat R))).ι.naturality f) }
/-- Given a cocone `t` of `F`, the induced monoid linear map from the colimit to the cocone point.
We already know that this is a morphism between additive groups. The only thing left to see is that
it is a linear map, i.e. preserves scalar multiplication.
-/
def colimitDesc (t : Cocone F) : colimit F ⟶ t.pt :=
let h := (AddCommGrpCat.FilteredColimits.colimitCoconeIsColimit (F ⋙ forget₂ _ _))
let f : colimit F →+ t.pt := (h.desc ((forget₂ _ _).mapCocone t)).hom
have hf {j : J} (x : F.obj j) : f (M.mk _ ⟨j, x⟩) = t.ι.app j x :=
congr_fun ((forget _).congr_map (h.fac ((forget₂ _ _).mapCocone t) j)) x
ofHom
{ f with
map_smul' := fun r x => by
obtain ⟨j, x, rfl⟩ := M.mk_surjective F x
simp [hf] }
@[reassoc (attr := simp)]
lemma ι_colimitDesc (t : Cocone F) (j : J) :
(colimitCocone F).ι.app j ≫ colimitDesc F t = t.ι.app j :=
(forget₂ _ AddCommGrpCat).map_injective
((AddCommGrpCat.FilteredColimits.colimitCoconeIsColimit (F ⋙ forget₂ _ _)).fac _ _)
/-- The proposed colimit cocone is a colimit in `ModuleCat R`. -/
def colimitCoconeIsColimit : IsColimit (colimitCocone F) where
desc := colimitDesc F
fac t j := by simp
uniq t _ h := by
ext ⟨j, x⟩
exact (congr_fun ((forget _).congr_map (h j)) x).trans
(congr_fun ((forget _).congr_map (ι_colimitDesc F t j)) x).symm
instance forget₂AddCommGroup_preservesFilteredColimits :
PreservesFilteredColimits (forget₂ (ModuleCat.{u} R) AddCommGrpCat.{u}) where
preserves_filtered_colimits _ _ _ :=
{ preservesColimit := fun {F} =>
preservesColimit_of_preserves_colimit_cocone (colimitCoconeIsColimit F)
(AddCommGrpCat.FilteredColimits.colimitCoconeIsColimit
(F ⋙ forget₂ (ModuleCat.{u} R) AddCommGrpCat.{u})) }
instance forget_preservesFilteredColimits : PreservesFilteredColimits (forget (ModuleCat.{u} R)) :=
Limits.comp_preservesFilteredColimits (forget₂ (ModuleCat R) AddCommGrpCat)
(forget AddCommGrpCat)
instance forget_reflectsFilteredColimits : ReflectsFilteredColimits (forget (ModuleCat.{u} R)) where
reflects_filtered_colimits _ := { reflectsColimit := reflectsColimit_of_reflectsIsomorphisms _ _ }
end
end ModuleCat.FilteredColimits |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Subobject.lean | import Mathlib.Algebra.Category.ModuleCat.EpiMono
import Mathlib.Algebra.Category.ModuleCat.Kernels
import Mathlib.CategoryTheory.Subobject.WellPowered
import Mathlib.CategoryTheory.Subobject.Limits
/-!
# Subobjects in the category of `R`-modules
We construct an explicit order isomorphism between the categorical subobjects of an `R`-module `M`
and its submodules. This immediately implies that the category of `R`-modules is well-powered.
-/
open CategoryTheory
open CategoryTheory.Subobject
open CategoryTheory.Limits
open ModuleCat
universe v u
namespace ModuleCat
variable {R : Type u} [Ring R] (M : ModuleCat.{v} R)
/-- The categorical subobjects of a module `M` are in one-to-one correspondence with its
submodules. -/
noncomputable def subobjectModule : Subobject M ≃o Submodule R M :=
OrderIso.symm
{ invFun := fun S => LinearMap.range S.arrow.hom
toFun := fun N => Subobject.mk (ofHom N.subtype)
right_inv := fun S => Eq.symm (by
fapply eq_mk_of_comm
· apply LinearEquiv.toModuleIso
apply LinearEquiv.ofBijective (LinearMap.codRestrict
(LinearMap.range S.arrow.hom) S.arrow.hom _)
constructor
· simp [← LinearMap.ker_eq_bot, ker_eq_bot_of_mono]
· rw [← LinearMap.range_eq_top, LinearMap.range_codRestrict,
Submodule.comap_subtype_self]
exact LinearMap.mem_range_self _
· ext x
rfl)
left_inv := fun N => by
convert congr_arg LinearMap.range (ModuleCat.hom_ext_iff.mp
(underlyingIso_arrow (ofHom N.subtype))) using 1
· have :
(underlyingIso (ofHom N.subtype)).inv =
ofHom (underlyingIso (ofHom N.subtype)).symm.toLinearEquiv.toLinearMap := by
ext x
rfl
rw [this, hom_comp, hom_ofHom, LinearEquiv.range_comp]
· exact (Submodule.range_subtype _).symm
map_rel_iff' := fun {S T} => by
refine ⟨fun h => ?_, fun h => mk_le_mk_of_comm (↟(Submodule.inclusion h)) rfl⟩
convert LinearMap.range_comp_le_range (ofMkLEMk _ _ h).hom (ofHom T.subtype).hom
· rw [← hom_comp, ofMkLEMk_comp]
exact (Submodule.range_subtype _).symm
· exact (Submodule.range_subtype _).symm }
instance wellPowered_moduleCat : WellPowered.{v} (ModuleCat.{v} R) :=
⟨fun M => ⟨⟨_, ⟨(subobjectModule M).toEquiv⟩⟩⟩⟩
attribute [local instance] hasKernels_moduleCat
/-- Bundle an element `m : M` such that `f m = 0` as a term of `kernelSubobject f`. -/
noncomputable def toKernelSubobject {M N : ModuleCat.{v} R} {f : M ⟶ N} :
LinearMap.ker f.hom →ₗ[R] kernelSubobject f :=
(kernelSubobjectIso f ≪≫ ModuleCat.kernelIsoKer f).inv.hom
@[simp]
theorem toKernelSubobject_arrow {M N : ModuleCat R} {f : M ⟶ N} (x : LinearMap.ker f.hom) :
(kernelSubobject f).arrow (toKernelSubobject x) = x.1 := by
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/10959): the whole proof was just `simp [toKernelSubobject]`.
simp [toKernelSubobject, -hom_comp, ← ConcreteCategory.comp_apply]
/-- An extensionality lemma showing that two elements of a cokernel by an image
are equal if they differ by an element of the image.
The application is for homology:
two elements in homology are equal if they differ by a boundary.
-/
theorem cokernel_π_imageSubobject_ext {L M N : ModuleCat.{v} R} (f : L ⟶ M) [HasImage f]
(g : (imageSubobject f : ModuleCat.{v} R) ⟶ N) [HasCokernel g] {x y : N} (l : L)
(w : x = y + g (factorThruImageSubobject f l)) : cokernel.π g x = cokernel.π g y := by
subst w
simp
end ModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Semi.lean | import Mathlib.Algebra.Algebra.Defs
import Mathlib.Algebra.BigOperators.Group.Finset.Defs
import Mathlib.Algebra.Category.MonCat.Basic
import Mathlib.Algebra.Module.Equiv.Basic
import Mathlib.Algebra.Module.PUnit
import Mathlib.CategoryTheory.Conj
import Mathlib.CategoryTheory.Limits.Shapes.ZeroMorphisms
/-!
# The category of `R`-modules
If `R` is a semiring, `SemimoduleCat.{v} R` is the category of bundled `R`-modules with carrier
in the universe `v`. We show that it is preadditive and show that being an isomorphism and
monomorphism are equivalent to being a linear equivalence and an injective linear map respectively.
## Implementation details
To construct an object in the category of `R`-modules from a type `M` with an instance of the
`Module` typeclass, write `of R M`. There is a coercion in the other direction.
The roundtrip `↑(of R M)` is definitionally equal to `M` itself (when `M` is a type with `Module`
instance), and so is `of R ↑M` (when `M : SemimoduleCat R M`).
The morphisms are given their own type, not identified with `LinearMap`.
There is a cast from morphisms in `Module R` to linear maps,
written `f.hom` (`SemimoduleCat.Hom.hom`).
To go from linear maps to morphisms in `Module R`, use `SemimoduleCat.ofHom`.
Similarly, given an isomorphism `f : M ≅ N` use `f.toLinearEquiv` and given a linear equiv
`f : M ≃ₗ[R] N`, use `f.toModuleIso`.
-/
open CategoryTheory Limits WalkingParallelPair
universe v u
variable (R : Type u) [Semiring R]
/-- The category of R-modules and their morphisms.
Note that in the case of `R = ℕ`, we can not
impose here that the `ℕ`-multiplication field from the module structure is defeq to the one coming
from the `isAddCommMonoid` structure (contrary to what we do for all module structures in
mathlib), which creates some difficulties down the road. -/
structure SemimoduleCat where
private mk ::
/-- the underlying type of an object in `SemimoduleCat R` -/
carrier : Type v
[isAddCommMonoid : AddCommMonoid carrier]
[isModule : Module R carrier]
attribute [instance] SemimoduleCat.isAddCommMonoid SemimoduleCat.isModule
namespace SemimoduleCat
instance : CoeSort (SemimoduleCat.{v} R) (Type v) :=
⟨SemimoduleCat.carrier⟩
attribute [coe] SemimoduleCat.carrier
/-- The object in the category of R-algebras associated to a type equipped with the appropriate
typeclasses. This is the preferred way to construct a term of `SemimoduleCat R`. -/
abbrev of (X : Type v) [AddCommMonoid X] [Module R X] : SemimoduleCat.{v} R :=
⟨X⟩
lemma coe_of (X : Type v) [Semiring X] [Module R X] : (of R X : Type v) = X :=
rfl
-- Ensure the roundtrips are reducibly defeq (so tactics like `rw` can see through them).
example (X : Type v) [Semiring X] [Module R X] : (of R X : Type v) = X := by with_reducible rfl
example (M : SemimoduleCat.{v} R) : of R M = M := by with_reducible rfl
variable {R} in
/-- The type of morphisms in `SemimoduleCat R`. -/
@[ext]
structure Hom (M N : SemimoduleCat.{v} R) where
mk ::
/-- The underlying linear map. -/
hom' : M →ₗ[R] N
instance moduleCategory : Category.{v, max (v+1) u} (SemimoduleCat.{v} R) where
Hom M N := Hom M N
id _ := ⟨LinearMap.id⟩
comp f g := ⟨g.hom'.comp f.hom'⟩
instance : ConcreteCategory (SemimoduleCat.{v} R) (· →ₗ[R] ·) where
hom := Hom.hom'
ofHom := Hom.mk
section
variable {R}
/-- Turn a morphism in `SemimoduleCat` back into a `LinearMap`. -/
abbrev Hom.hom {A B : SemimoduleCat.{v} R} (f : Hom A B) :=
ConcreteCategory.hom (C := SemimoduleCat R) f
/-- Typecheck a `LinearMap` as a morphism in `SemimoduleCat`. -/
abbrev ofHom {X Y : Type v} [AddCommMonoid X] [Module R X] [AddCommMonoid Y] [Module R Y]
(f : X →ₗ[R] Y) : of R X ⟶ of R Y :=
ConcreteCategory.ofHom (C := SemimoduleCat R) f
/-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/
def Hom.Simps.hom (A B : SemimoduleCat.{v} R) (f : Hom A B) :=
f.hom
initialize_simps_projections Hom (hom' → hom)
/-!
The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`.
-/
@[simp]
lemma hom_id {M : SemimoduleCat.{v} R} : (𝟙 M : M ⟶ M).hom = LinearMap.id := rfl
/- Provided for rewriting. -/
lemma id_apply (M : SemimoduleCat.{v} R) (x : M) :
(𝟙 M : M ⟶ M) x = x := by simp
@[simp]
lemma hom_comp {M N O : SemimoduleCat.{v} R} (f : M ⟶ N) (g : N ⟶ O) :
(f ≫ g).hom = g.hom.comp f.hom := rfl
/- Provided for rewriting. -/
lemma comp_apply {M N O : SemimoduleCat.{v} R} (f : M ⟶ N) (g : N ⟶ O) (x : M) :
(f ≫ g) x = g (f x) := by simp
@[ext]
lemma hom_ext {M N : SemimoduleCat.{v} R} {f g : M ⟶ N} (hf : f.hom = g.hom) : f = g :=
Hom.ext hf
lemma hom_bijective {M N : SemimoduleCat.{v} R} :
Function.Bijective (Hom.hom : (M ⟶ N) → (M →ₗ[R] N)) where
left f g h := by cases f; cases g; simpa using h
right f := ⟨⟨f⟩, rfl⟩
/-- Convenience shortcut for `SemimoduleCat.hom_bijective.injective`. -/
lemma hom_injective {M N : SemimoduleCat.{v} R} :
Function.Injective (Hom.hom : (M ⟶ N) → (M →ₗ[R] N)) :=
hom_bijective.injective
/-- Convenience shortcut for `SemimoduleCat.hom_bijective.surjective`. -/
lemma hom_surjective {M N : SemimoduleCat.{v} R} :
Function.Surjective (Hom.hom : (M ⟶ N) → (M →ₗ[R] N)) :=
hom_bijective.surjective
@[simp]
lemma hom_ofHom {X Y : Type v} [AddCommMonoid X] [Module R X] [AddCommMonoid Y]
[Module R Y] (f : X →ₗ[R] Y) : (ofHom f).hom = f := rfl
@[simp]
lemma ofHom_hom {M N : SemimoduleCat.{v} R} (f : M ⟶ N) :
ofHom (Hom.hom f) = f := rfl
@[simp]
lemma ofHom_id {M : Type v} [AddCommMonoid M] [Module R M] : ofHom LinearMap.id = 𝟙 (of R M) := rfl
@[simp]
lemma ofHom_comp {M N O : Type v} [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid O] [Module R M]
[Module R N] [Module R O] (f : M →ₗ[R] N) (g : N →ₗ[R] O) :
ofHom (g.comp f) = ofHom f ≫ ofHom g :=
rfl
/- Doesn't need to be `@[simp]` since `simp only` can solve this. -/
lemma ofHom_apply {M N : Type v} [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N]
(f : M →ₗ[R] N) (x : M) : ofHom f x = f x := rfl
lemma inv_hom_apply {M N : SemimoduleCat.{v} R} (e : M ≅ N) (x : M) : e.inv (e.hom x) = x := by
simp
lemma hom_inv_apply {M N : SemimoduleCat.{v} R} (e : M ≅ N) (x : N) : e.hom (e.inv x) = x := by
simp
/-- `SemimoduleCat.Hom.hom` bundled as an `Equiv`. -/
def homEquiv {M N : SemimoduleCat.{v} R} : (M ⟶ N) ≃ (M →ₗ[R] N) where
toFun := Hom.hom
invFun := ofHom
end
/- Not a `@[simp]` lemma since it will rewrite the (co)domain of maps and cause
definitional equality issues. -/
lemma forget_obj {M : SemimoduleCat.{v} R} : (forget (SemimoduleCat.{v} R)).obj M = M := rfl
@[simp]
lemma forget_map {M N : SemimoduleCat.{v} R} (f : M ⟶ N) :
(forget (SemimoduleCat.{v} R)).map f = f :=
rfl
instance hasForgetToAddCommMonoid : HasForget₂ (SemimoduleCat R) AddCommMonCat where
forget₂ :=
{ obj := fun M => .of M
map := fun f => AddCommMonCat.ofHom f.hom.toAddMonoidHom }
@[simp]
theorem forget₂_obj (X : SemimoduleCat R) :
(forget₂ (SemimoduleCat R) AddCommMonCat).obj X = .of X :=
rfl
theorem forget₂_obj_moduleCat_of (X : Type v) [AddCommMonoid X] [Module R X] :
(forget₂ (SemimoduleCat R) AddCommMonCat).obj (of R X) = .of X :=
rfl
@[simp]
theorem forget₂_map (X Y : SemimoduleCat R) (f : X ⟶ Y) :
(forget₂ (SemimoduleCat R) AddCommMonCat).map f = AddCommMonCat.ofHom f.hom :=
rfl
instance : Inhabited (SemimoduleCat R) :=
⟨of R PUnit⟩
@[simp] theorem of_coe (X : SemimoduleCat R) : of R X = X := rfl
variable {R}
/-- Forgetting to the underlying type and then building the bundled object returns the original
module. -/
@[deprecated Iso.refl (since := "2025-05-15")]
def ofSelfIso (M : SemimoduleCat R) : SemimoduleCat.of R M ≅ M where
hom := 𝟙 M
inv := 𝟙 M
theorem isZero_of_subsingleton (M : SemimoduleCat R) [Subsingleton M] : IsZero M where
unique_to X := ⟨⟨⟨ofHom (0 : M →ₗ[R] X)⟩, fun f => by
ext x
rw [Subsingleton.elim x (0 : M)]
simp⟩⟩
unique_from X := ⟨⟨⟨ofHom (0 : X →ₗ[R] M)⟩, fun f => by
ext x
subsingleton⟩⟩
instance : HasZeroObject (SemimoduleCat.{v} R) :=
⟨⟨of R PUnit, isZero_of_subsingleton _⟩⟩
end SemimoduleCat
variable {R}
variable {X₁ X₂ : Type v}
open SemimoduleCat
/-- Reinterpreting a linear map in the category of `R`-modules -/
scoped[SemimoduleCat] notation "↟" f:1024 => SemimoduleCat.ofHom f
section
/-- Build an isomorphism in the category `Module R` from a `LinearEquiv` between `Module`s. -/
@[simps]
def LinearEquiv.toModuleIsoₛ {g₁ : AddCommMonoid X₁} {g₂ : AddCommMonoid X₂} {m₁ : Module R X₁}
{m₂ : Module R X₂} (e : X₁ ≃ₗ[R] X₂) : SemimoduleCat.of R X₁ ≅ SemimoduleCat.of R X₂ where
hom := ofHom (e : X₁ →ₗ[R] X₂)
inv := ofHom (e.symm : X₂ →ₗ[R] X₁)
hom_inv_id := by ext; apply e.left_inv
inv_hom_id := by ext; apply e.right_inv
namespace CategoryTheory.Iso
/-- Build a `LinearEquiv` from an isomorphism in the category `SemimoduleCat R`. -/
def toLinearEquivₛ {X Y : SemimoduleCat R} (i : X ≅ Y) : X ≃ₗ[R] Y :=
LinearEquiv.ofLinear i.hom.hom i.inv.hom (by aesop) (by aesop)
end CategoryTheory.Iso
/-- linear equivalences between `Module`s are the same as (isomorphic to) isomorphisms
in `SemimoduleCat` -/
@[simps]
def linearEquivIsoModuleIsoₛ {X Y : Type u} [AddCommMonoid X] [AddCommMonoid Y] [Module R X]
[Module R Y] : (X ≃ₗ[R] Y) ≅ SemimoduleCat.of R X ≅ SemimoduleCat.of R Y where
hom e := e.toModuleIsoₛ
inv i := i.toLinearEquivₛ
end
namespace SemimoduleCat
section AddCommMonoid
variable {M N : SemimoduleCat.{v} R}
instance : Add (M ⟶ N) where
add f g := ⟨f.hom + g.hom⟩
@[simp] lemma hom_add (f g : M ⟶ N) : (f + g).hom = f.hom + g.hom := rfl
instance : Zero (M ⟶ N) where
zero := ⟨0⟩
@[simp] lemma hom_zero : (0 : M ⟶ N).hom = 0 := rfl
instance : SMul ℕ (M ⟶ N) where
smul n f := ⟨n • f.hom⟩
@[simp] lemma hom_nsmul (n : ℕ) (f : M ⟶ N) : (n • f).hom = n • f.hom := rfl
instance : SMul ℕ (M ⟶ N) where
smul n f := ⟨n • f.hom⟩
@[simp] lemma hom_zsmul (n : ℕ) (f : M ⟶ N) : (n • f).hom = n • f.hom := rfl
instance : AddCommMonoid (M ⟶ N) :=
Function.Injective.addCommMonoid Hom.hom hom_injective rfl (fun _ _ => rfl) (fun _ _ => rfl)
@[simp] lemma hom_sum {ι : Type*} (f : ι → (M ⟶ N)) (s : Finset ι) :
(∑ i ∈ s, f i).hom = ∑ i ∈ s, (f i).hom :=
map_sum ({ toFun := SemimoduleCat.Hom.hom, map_zero' := SemimoduleCat.hom_zero,
map_add' := hom_add } : (M ⟶ N) →+ (M →ₗ[R] N)) _ _
/- TODO: generalize Preadditive and Functor.Additive, see #28826.
instance : Presemiadditive (SemimoduleCat.{v} R) where
instance : (forget₂ (SemimoduleCat.{v} R) AddCommMonCat).Additive where -/
instance : HasZeroMorphisms (SemimoduleCat.{v} R) where
/-- `SemimoduleCat.Hom.hom` bundled as an additive equivalence. -/
@[simps!]
def homAddEquiv : (M ⟶ N) ≃+ (M →ₗ[R] N) :=
{ homEquiv with
map_add' := fun _ _ => rfl }
theorem subsingleton_of_isZero (h : IsZero M) : Subsingleton M := by
refine subsingleton_of_forall_eq 0 (fun x ↦ ?_)
rw [← LinearMap.id_apply (R := R) x, ← SemimoduleCat.hom_id]
simp only [(CategoryTheory.Limits.IsZero.iff_id_eq_zero M).mp h, hom_zero, LinearMap.zero_apply]
lemma isZero_iff_subsingleton : IsZero M ↔ Subsingleton M where
mp := subsingleton_of_isZero
mpr _ := isZero_of_subsingleton M
@[simp]
lemma isZero_of_iff_subsingleton {M : Type*} [AddCommMonoid M] [Module R M] :
IsZero (of R M) ↔ Subsingleton M := isZero_iff_subsingleton
end AddCommMonoid
section SMul
variable {M N : SemimoduleCat.{v} R}
variable {S : Type*} [Monoid S] [DistribMulAction S N] [SMulCommClass R S N]
instance : SMul S (M ⟶ N) where
smul c f := ⟨c • f.hom⟩
@[simp] lemma hom_smul (s : S) (f : M ⟶ N) : (s • f).hom = s • f.hom := rfl
end SMul
section Module
variable {M N : SemimoduleCat.{v} R} {S : Type*} [Semiring S] [Module S N] [SMulCommClass R S N]
instance Hom.instModule : Module S (M ⟶ N) :=
Function.Injective.module S
{ toFun := Hom.hom, map_zero' := hom_zero, map_add' := hom_add }
hom_injective
(fun _ _ => rfl)
/-- `SemimoduleCat.Hom.hom` bundled as a linear equivalence. -/
@[simps]
def homLinearEquiv : (M ⟶ N) ≃ₗ[S] (M →ₗ[R] N) :=
{ homAddEquiv with
map_smul' := fun _ _ => rfl }
end Module
section
universe u₀
namespace Algebra
variable {S₀ : Type u₀} [CommSemiring S₀] {S : Type u} [Semiring S] [Algebra S₀ S]
variable {M N : SemimoduleCat.{v} S}
/--
Let `S` be an `S₀`-algebra. Then `S`-modules are modules over `S₀`.
-/
scoped instance : Module S₀ M := Module.compHom _ (algebraMap S₀ S)
scoped instance : IsScalarTower S₀ S M where
smul_assoc _ _ _ := by rw [Algebra.smul_def, mul_smul]; rfl
scoped instance : SMulCommClass S S₀ M where
smul_comm s s₀ n :=
show s • algebraMap S₀ S s₀ • n = algebraMap S₀ S s₀ • s • n by
rw [← smul_assoc, smul_eq_mul, ← Algebra.commutes, mul_smul]
/- TODO: generalize `Functor.Linear`, see #28826.
Let `S` be an `S₀`-algebra. Then the category of `S`-modules is `S₀`-linear.
scoped instance instLinear : Linear S₀ (SemimoduleCat.{v} S) where
smul_comp _ M N s₀ f g := by ext; simp -/
end Algebra
section
variable {S : Type u} [CommSemiring S]
/- TODO: generalize `Functor.Linear`, see #28826.
instance : Linear S (SemimoduleCat.{v} S) := SemimoduleCat.Algebra.instLinear -/
variable {X Y X' Y' : SemimoduleCat.{v} S}
theorem Iso.homCongr_eq_arrowCongr (i : X ≅ X') (j : Y ≅ Y') (f : X ⟶ Y) :
Iso.homCongr i j f = ⟨LinearEquiv.arrowCongr i.toLinearEquivₛ j.toLinearEquivₛ f.hom⟩ :=
rfl
theorem Iso.conj_eq_conj (i : X ≅ X') (f : End X) :
Iso.conj i f = ⟨LinearEquiv.conj i.toLinearEquivₛ f.hom⟩ :=
rfl
end
end
/- TODO: Declarations in #28826 from `endSemiringEquiv` to `forget₂_map_homMk` can be added back
after appropriate generalizations. -/
instance : (forget (SemimoduleCat.{v} R)).ReflectsIsomorphisms where
reflects f _ :=
(inferInstance : IsIso ((LinearEquiv.mk f.hom
(asIso ((forget (SemimoduleCat R)).map f)).toEquiv.invFun
(Equiv.left_inv _) (Equiv.right_inv _)).toModuleIsoₛ).hom)
instance : (forget₂ (SemimoduleCat.{v} R) AddCommMonCat.{v}).ReflectsIsomorphisms where
reflects f _ := by
have : IsIso ((forget _).map f) := by
change IsIso ((forget _).map ((forget₂ _ AddCommMonCat).map f))
infer_instance
apply isIso_of_reflects_iso _ (forget _)
end SemimoduleCat
section Bilinear
variable {R : Type*} [CommSemiring R]
namespace SemimoduleCat
/-- Turn a bilinear map into a homomorphism. -/
@[simps!]
def ofHom₂ {M N P : SemimoduleCat.{u} R} (f : M →ₗ[R] N →ₗ[R] P) :
M ⟶ of R (N ⟶ P) :=
ofHom <| homLinearEquiv.symm.toLinearMap ∘ₗ f
/-- Turn a homomorphism into a bilinear map. -/
@[simps!]
def Hom.hom₂ {M N P : SemimoduleCat.{u} R}
-- We write `Hom` instead of `M ⟶ (of R (N ⟶ P))`, otherwise dot notation breaks
-- since it is expecting the type of `f` to be `SemimoduleCat.Hom`, not `Quiver.Hom`.
(f : Hom M (of R (N ⟶ P))) :
M →ₗ[R] N →ₗ[R] P :=
Hom.hom (by convert (f ≫ ofHom homLinearEquiv.toLinearMap))
@[simp] lemma Hom.hom₂_ofHom₂ {M N P : SemimoduleCat.{u} R} (f : M →ₗ[R] N →ₗ[R] P) :
(ofHom₂ f).hom₂ = f := rfl
@[simp] lemma ofHom₂_hom₂ {M N P : SemimoduleCat.{u} R} (f : M ⟶ of R (N ⟶ P)) :
ofHom₂ f.hom₂ = f := rfl
end SemimoduleCat
end Bilinear
/-!
`@[simp]` lemmas for `LinearMap.comp` and categorical identities.
-/
@[simp] theorem LinearMap.comp_id_semiModuleCat {R} [Semiring R]
{G : SemimoduleCat.{u} R} {H : Type u} [AddCommMonoid H] [Module R H] (f : G →ₗ[R] H) :
f.comp (𝟙 G : G ⟶ G).hom = f := by simp
@[simp] theorem LinearMap.id_semiModuleCat_comp {R} [Semiring R]
{G : Type u} [AddCommMonoid G] [Module R G] {H : SemimoduleCat.{u} R} (f : G →ₗ[R] H) :
LinearMap.comp (𝟙 H : H ⟶ H).hom f = f := by simp |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Kernels.lean | import Mathlib.Algebra.Category.ModuleCat.EpiMono
import Mathlib.CategoryTheory.ConcreteCategory.Elementwise
/-!
# The concrete (co)kernels in the category of modules are (co)kernels in the categorical sense.
-/
open CategoryTheory CategoryTheory.Limits
universe u v
namespace ModuleCat
variable {R : Type u} [Ring R]
section
variable {M N : ModuleCat.{v} R} (f : M ⟶ N)
/-- The kernel cone induced by the concrete kernel. -/
def kernelCone : KernelFork f :=
KernelFork.ofι (ofHom (LinearMap.ker f.hom).subtype) <| by aesop
/-- The kernel of a linear map is a kernel in the categorical sense. -/
def kernelIsLimit : IsLimit (kernelCone f) :=
Fork.IsLimit.mk _
(fun s => ofHom <|
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11036): broken dot notation on LinearMap.ker
LinearMap.codRestrict (LinearMap.ker f.hom) (Fork.ι s).hom fun c =>
LinearMap.mem_ker.2 <| by simp [← ConcreteCategory.comp_apply])
(fun _ => hom_ext <| LinearMap.subtype_comp_codRestrict _ _ _) fun s m h =>
hom_ext <| LinearMap.ext fun x => Subtype.ext_iff.2 (by simp [← h]; rfl)
/-- The cokernel cocone induced by the projection onto the quotient. -/
def cokernelCocone : CokernelCofork f :=
CokernelCofork.ofπ (ofHom (LinearMap.range f.hom).mkQ) <| hom_ext <| LinearMap.range_mkQ_comp _
/-- The projection onto the quotient is a cokernel in the categorical sense. -/
def cokernelIsColimit : IsColimit (cokernelCocone f) :=
Cofork.IsColimit.mk _
(fun s => ofHom <| (LinearMap.range f.hom).liftQ (Cofork.π s).hom <|
LinearMap.range_le_ker_iff.2 <| ModuleCat.hom_ext_iff.mp <| CokernelCofork.condition s)
(fun s => hom_ext <| (LinearMap.range f.hom).liftQ_mkQ (Cofork.π s).hom _) fun s m h => by
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11036): broken dot notation
haveI : Epi (ofHom (LinearMap.range f.hom).mkQ) :=
(epi_iff_range_eq_top _).mpr (Submodule.range_mkQ _)
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11036): broken dot notation
apply (cancel_epi (ofHom (LinearMap.range f.hom).mkQ)).1
exact h
end
/-- The category of R-modules has kernels, given by the inclusion of the kernel submodule. -/
theorem hasKernels_moduleCat : HasKernels (ModuleCat R) :=
⟨fun f => HasLimit.mk ⟨_, kernelIsLimit f⟩⟩
/-- The category of R-modules has cokernels, given by the projection onto the quotient. -/
theorem hasCokernels_moduleCat : HasCokernels (ModuleCat R) :=
⟨fun f => HasColimit.mk ⟨_, cokernelIsColimit f⟩⟩
open ModuleCat
attribute [local instance] hasKernels_moduleCat
attribute [local instance] hasCokernels_moduleCat
variable {G H : ModuleCat.{v} R} (f : G ⟶ H)
/-- The categorical kernel of a morphism in `ModuleCat`
agrees with the usual module-theoretical kernel.
-/
noncomputable def kernelIsoKer {G H : ModuleCat.{v} R} (f : G ⟶ H) :
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11036): broken dot notation
kernel f ≅ ModuleCat.of R (LinearMap.ker f.hom) :=
limit.isoLimitCone ⟨_, kernelIsLimit f⟩
-- We now show this isomorphism commutes with the inclusion of the kernel into the source.
@[simp, elementwise]
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11036): broken dot notation
theorem kernelIsoKer_inv_kernel_ι : (kernelIsoKer f).inv ≫ kernel.ι f =
ofHom (LinearMap.ker f.hom).subtype :=
limit.isoLimitCone_inv_π _ _
@[simp, elementwise]
theorem kernelIsoKer_hom_ker_subtype :
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11036): broken dot notation
(kernelIsoKer f).hom ≫ ofHom (LinearMap.ker f.hom).subtype = kernel.ι f :=
IsLimit.conePointUniqueUpToIso_inv_comp _ (limit.isLimit _) WalkingParallelPair.zero
/-- The categorical cokernel of a morphism in `ModuleCat`
agrees with the usual module-theoretical quotient.
-/
noncomputable def cokernelIsoRangeQuotient {G H : ModuleCat.{v} R} (f : G ⟶ H) :
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11036): broken dot notation
cokernel f ≅ ModuleCat.of R (H ⧸ LinearMap.range f.hom) :=
colimit.isoColimitCocone ⟨_, cokernelIsColimit f⟩
-- We now show this isomorphism commutes with the projection of target to the cokernel.
@[simp, elementwise]
theorem cokernel_π_cokernelIsoRangeQuotient_hom :
cokernel.π f ≫ (cokernelIsoRangeQuotient f).hom = ofHom (LinearMap.range f.hom).mkQ :=
colimit.isoColimitCocone_ι_hom _ _
@[simp, elementwise]
theorem range_mkQ_cokernelIsoRangeQuotient_inv :
ofHom (LinearMap.range f.hom).mkQ ≫ (cokernelIsoRangeQuotient f).inv = cokernel.π f :=
colimit.isoColimitCocone_ι_inv ⟨_, cokernelIsColimit f⟩ WalkingParallelPair.one
theorem cokernel_π_ext {M N : ModuleCat.{u} R} (f : M ⟶ N) {x y : N} (m : M) (w : x = y + f m) :
cokernel.π f x = cokernel.π f y := by
subst w
simpa only [map_add, add_eq_left] using cokernel.condition_apply f m
end ModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Injective.lean | import Mathlib.Algebra.Module.Injective
import Mathlib.CategoryTheory.Preadditive.Injective.Basic
import Mathlib.Algebra.Category.ModuleCat.EpiMono
/-!
# Injective objects in the category of $R$-modules
-/
open CategoryTheory
universe u v
variable (R : Type u) (M : Type v) [Ring R] [AddCommGroup M] [Module R M]
namespace Module
theorem injective_object_of_injective_module [inj : Injective R M] :
CategoryTheory.Injective (ModuleCat.of R M) where
factors g f m :=
have ⟨l, h⟩ := inj.out f.hom ((ModuleCat.mono_iff_injective f).mp m) g.hom
⟨ModuleCat.ofHom l, by ext x; simpa using h x⟩
theorem injective_module_of_injective_object
[inj : CategoryTheory.Injective <| ModuleCat.of R M] :
Module.Injective R M where
out X Y _ _ _ _ f hf g := by
have : CategoryTheory.Mono (ModuleCat.ofHom f) := (ModuleCat.mono_iff_injective _).mpr hf
obtain ⟨l, h⟩ := inj.factors (ModuleCat.ofHom g) (ModuleCat.ofHom f)
obtain rfl := ModuleCat.hom_ext_iff.mp h
exact ⟨l.hom, fun _ => rfl⟩
theorem injective_iff_injective_object :
Module.Injective R M ↔
CategoryTheory.Injective (ModuleCat.of R M) :=
⟨fun _ => injective_object_of_injective_module R M,
fun _ => injective_module_of_injective_object R M⟩
end Module
instance ModuleCat.ulift_injective_of_injective.{v'}
[Small.{v} R] [AddCommGroup M] [Module R M]
[CategoryTheory.Injective <| ModuleCat.of R M] :
CategoryTheory.Injective <| ModuleCat.of R (ULift.{v'} M) :=
Module.injective_object_of_injective_module
(inj := Module.ulift_injective_of_injective
(inj := Module.injective_module_of_injective_object _ _)) |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Projective.lean | import Mathlib.Algebra.Category.ModuleCat.EpiMono
import Mathlib.Algebra.Group.Shrink
import Mathlib.Algebra.Module.Projective
import Mathlib.CategoryTheory.Preadditive.Projective.Basic
/-!
# The category of `R`-modules has enough projectives.
-/
universe v u w
open CategoryTheory Module ModuleCat
variable {R : Type u} [Ring R] (P : ModuleCat.{v} R)
instance ModuleCat.projective_of_categoryTheory_projective [Module.Projective R P] :
CategoryTheory.Projective P := by
refine ⟨fun E X epi => ?_⟩
obtain ⟨f, h⟩ := Module.projective_lifting_property X.hom E.hom
((ModuleCat.epi_iff_surjective _).mp epi)
exact ⟨ofHom f, hom_ext h⟩
instance ModuleCat.projective_of_module_projective [Small.{v} R] [Projective P] :
Module.Projective R P := by
refine Module.Projective.of_lifting_property ?_
intro _ _ _ _ _ _ f g s
have : Epi (↟f) := (ModuleCat.epi_iff_surjective (↟f)).mpr s
exact ⟨(Projective.factorThru (↟g) (↟f)).hom,
ModuleCat.hom_ext_iff.mp <| Projective.factorThru_comp (↟g) (↟f)⟩
/-- The categorical notion of projective object agrees with the explicit module-theoretic notion. -/
theorem IsProjective.iff_projective [Small.{v} R] (P : Type v) [AddCommGroup P] [Module R P] :
Module.Projective R P ↔ Projective (of R P) :=
⟨fun _ => (of R P).projective_of_categoryTheory_projective,
fun _ => (of R P).projective_of_module_projective⟩
namespace ModuleCat
variable {M : ModuleCat.{v} R}
-- We transport the corresponding result from `Module.Projective`.
/-- Modules that have a basis are projective. -/
theorem projective_of_free {ι : Type w} (b : Basis ι R M) : Projective M :=
have : Module.Projective R M := Module.Projective.of_basis b
M.projective_of_categoryTheory_projective
/-- The category of modules has enough projectives, since every module is a quotient of a free
module. -/
instance enoughProjectives [Small.{v} R] : EnoughProjectives (ModuleCat.{v} R) where
presentation M :=
let e : Basis M R (M →₀ Shrink.{v} R) := ⟨Finsupp.mapRange.linearEquiv (Shrink.linearEquiv R R)⟩
⟨{p := ModuleCat.of R (M →₀ Shrink.{v} R)
projective := projective_of_free e
f := ofHom <| e.constr ℕ _root_.id
epi := by
rw [epi_iff_range_eq_top, LinearMap.range_eq_top]
refine fun m ↦ ⟨Finsupp.single m 1, ?_⟩
simp [e, Basis.constr_apply] }⟩
end ModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Colimits.lean | import Mathlib.Algebra.Category.ModuleCat.Basic
import Mathlib.CategoryTheory.ConcreteCategory.Elementwise
import Mathlib.Algebra.Category.Grp.Colimits
/-!
# The category of R-modules has all colimits.
From the existence of colimits in `AddCommGrpCat`, we deduce the existence of colimits
in `ModuleCat R`. This way, we get for free that the functor
`forget₂ (ModuleCat R) AddCommGrpCat` commutes with colimits.
Note that finite colimits can already be obtained from the instance `Abelian (Module R)`.
TODO:
In fact, in `ModuleCat R` there is a much nicer model of colimits as quotients
of finitely supported functions, and we really should implement this as well.
-/
universe w' w u v
open CategoryTheory Category Limits
variable {R : Type w} [Ring R]
namespace ModuleCat
variable {J : Type u} [Category.{v} J] (F : J ⥤ ModuleCat.{w'} R)
namespace HasColimit
variable [HasColimit (F ⋙ forget₂ _ AddCommGrpCat)]
/-- The induced scalar multiplication on
`colimit (F ⋙ forget₂ _ AddCommGrpCat)`. -/
@[simps]
noncomputable def coconePointSMul :
R →+* End (colimit (F ⋙ forget₂ _ AddCommGrpCat)) where
toFun r := colimMap
{ app := fun j => (F.obj j).smul r
naturality := fun _ _ _ => smul_naturality _ _ }
map_zero' := colimit.hom_ext (by simp)
map_one' := colimit.hom_ext (by simp)
map_add' r s := colimit.hom_ext (fun j => by
simp only [Functor.comp_obj, forget₂_obj, map_add, ι_colimMap]
rw [Preadditive.add_comp, Preadditive.comp_add]
simp only [ι_colimMap, Functor.comp_obj, forget₂_obj])
map_mul' r s := colimit.hom_ext (fun j => by simp)
/-- The cocone for `F` constructed from the colimit of
`(F ⋙ forget₂ (ModuleCat R) AddCommGrpCat)`. -/
@[simps]
noncomputable def colimitCocone : Cocone F where
pt := mkOfSMul (coconePointSMul F)
ι :=
{ app := fun j => homMk (colimit.ι (F ⋙ forget₂ _ AddCommGrpCat) j) (fun r => by
dsimp
-- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
erw [mkOfSMul_smul]
simp)
naturality := fun i j f => by
apply (forget₂ _ AddCommGrpCat).map_injective
simp only [Functor.map_comp, forget₂_map_homMk]
dsimp
erw [colimit.w (F ⋙ forget₂ _ AddCommGrpCat), comp_id] }
/-- The cocone for `F` constructed from the colimit of
`(F ⋙ forget₂ (ModuleCat R) AddCommGrpCat)` is a colimit cocone. -/
noncomputable def isColimitColimitCocone : IsColimit (colimitCocone F) where
desc s := homMk (colimit.desc _ ((forget₂ _ AddCommGrpCat).mapCocone s)) (fun r => by
apply colimit.hom_ext
intro j
dsimp
rw [colimit.ι_desc_assoc]
-- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
erw [mkOfSMul_smul]
dsimp
simp only [ι_colimMap_assoc, Functor.comp_obj, forget₂_obj, colimit.ι_desc,
Functor.mapCocone_pt, Functor.mapCocone_ι_app, forget₂_map]
exact smul_naturality (s.ι.app j) r)
fac s j := by
apply (forget₂ _ AddCommGrpCat).map_injective
exact colimit.ι_desc ((forget₂ _ AddCommGrpCat).mapCocone s) j
uniq s m hm := by
apply (forget₂ _ AddCommGrpCat).map_injective
apply colimit.hom_ext
intro j
erw [colimit.ι_desc ((forget₂ _ AddCommGrpCat).mapCocone s) j]
dsimp
rw [← hm]
rfl
instance : HasColimit F := ⟨_, isColimitColimitCocone F⟩
noncomputable instance : PreservesColimit F (forget₂ _ AddCommGrpCat) :=
preservesColimit_of_preserves_colimit_cocone (isColimitColimitCocone F) (colimit.isColimit _)
noncomputable instance reflectsColimit :
ReflectsColimit F (forget₂ (ModuleCat.{w'} R) AddCommGrpCat) :=
reflectsColimit_of_reflectsIsomorphisms _ _
end HasColimit
variable (J R)
instance hasColimitsOfShape [HasColimitsOfShape J AddCommGrpCat.{w'}] :
HasColimitsOfShape J (ModuleCat.{w'} R) where
noncomputable instance reflectsColimitsOfShape [HasColimitsOfShape J AddCommGrpCat.{w'}] :
ReflectsColimitsOfShape J (forget₂ (ModuleCat.{w'} R) AddCommGrpCat) where
instance hasColimitsOfSize [HasColimitsOfSize.{v, u} AddCommGrpCat.{w'}] :
HasColimitsOfSize.{v, u} (ModuleCat.{w'} R) where
noncomputable instance forget₂PreservesColimitsOfShape
[HasColimitsOfShape J AddCommGrpCat.{w'}] :
PreservesColimitsOfShape J (forget₂ (ModuleCat.{w'} R) AddCommGrpCat) where
noncomputable instance forget₂PreservesColimitsOfSize
[HasColimitsOfSize.{u, v} AddCommGrpCat.{w'}] :
PreservesColimitsOfSize.{u, v} (forget₂ (ModuleCat.{w'} R) AddCommGrpCat) where
noncomputable instance
[HasColimitsOfSize.{u, v} AddCommGrpMax.{w, w'}] :
PreservesColimitsOfSize.{u, v} (forget₂ (ModuleCat.{max w w'} R) AddCommGrpCat) where
instance : HasFiniteColimits (ModuleCat.{w'} R) := inferInstance
-- Sanity checks, just to make sure typeclass search can find the instances we want.
example (R : Type u) [Ring R] : HasColimits (ModuleCat.{max v u} R) :=
inferInstance
example (R : Type u) [Ring R] : HasColimits (ModuleCat.{max u v} R) :=
inferInstance
example (R : Type u) [Ring R] : HasColimits (ModuleCat.{u} R) :=
inferInstance
example (R : Type u) [Ring R] : HasCoequalizers (ModuleCat.{u} R) := by
infer_instance
-- for some reason, this instance is not found automatically later on
instance : HasCoequalizers (ModuleCat.{v} R) where
noncomputable example (R : Type u) [Ring R] :
PreservesColimits (forget₂ (ModuleCat.{u} R) AddCommGrpCat) := inferInstance
end ModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Sheaf.lean | import Mathlib.Algebra.Category.ModuleCat.Presheaf
import Mathlib.Algebra.Category.ModuleCat.Limits
import Mathlib.CategoryTheory.Sites.LocallyBijective
import Mathlib.CategoryTheory.Sites.Whiskering
/-!
# Sheaves of modules over a sheaf of rings
In this file, we define the category `SheafOfModules R` when `R : Sheaf J RingCat`
is a sheaf of rings on a category `C` equipped with a Grothendieck topology `J`.
-/
universe v v₁ u₁ u w
open CategoryTheory
variable {C : Type u₁} [Category.{v₁} C] {J : GrothendieckTopology C}
(R : Sheaf J RingCat.{u})
/-- A sheaf of modules is a presheaf of modules such that the underlying presheaf
of abelian groups is a sheaf. -/
structure SheafOfModules where
/-- the underlying presheaf of modules of a sheaf of modules -/
val : PresheafOfModules.{v} R.val
isSheaf : Presheaf.IsSheaf J val.presheaf
namespace SheafOfModules
variable {R}
/-- A morphism between sheaves of modules is a morphism between the underlying
presheaves of modules. -/
@[ext]
structure Hom (X Y : SheafOfModules.{v} R) where
/-- a morphism between the underlying presheaves of modules -/
val : X.val ⟶ Y.val
instance : Category (SheafOfModules.{v} R) where
Hom := Hom
id _ := ⟨𝟙 _⟩
comp f g := ⟨f.val ≫ g.val⟩
@[ext]
lemma hom_ext {X Y : SheafOfModules.{v} R} {f g : X ⟶ Y} (h : f.val = g.val) : f = g :=
Hom.ext h
@[simp]
lemma id_val (X : SheafOfModules.{v} R) : Hom.val (𝟙 X) = 𝟙 X.val := rfl
@[simp, reassoc]
lemma comp_val {X Y Z : SheafOfModules.{v} R} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).val = f.val ≫ g.val := rfl
variable (R)
/-- The forgetful functor `SheafOfModules.{v} R ⥤ PresheafOfModules R.val`. -/
@[simps]
def forget : SheafOfModules.{v} R ⥤ PresheafOfModules R.val where
obj F := F.val
map φ := φ.val
/-- The forget functor `SheafOfModules R ⥤ PresheafOfModules R.val` is fully faithful. -/
@[simps]
def fullyFaithfulForget : (forget.{v} R).FullyFaithful where
preimage φ := ⟨φ⟩
instance : (forget.{v} R).Faithful := (fullyFaithfulForget R).faithful
instance : (forget.{v} R).Full := (fullyFaithfulForget R).full
instance : (forget.{v} R).ReflectsIsomorphisms := (fullyFaithfulForget R).reflectsIsomorphisms
/-- Evaluation on an object `X` gives a functor
`SheafOfModules R ⥤ ModuleCat (R.val.obj X)`. -/
def evaluation (X : Cᵒᵖ) : SheafOfModules.{v} R ⥤ ModuleCat.{v} (R.val.obj X) :=
forget _ ⋙ PresheafOfModules.evaluation _ X
/-- The forget functor `SheafOfModules R ⥤ Sheaf J AddCommGrpCat`. -/
@[simps]
noncomputable def toSheaf : SheafOfModules.{v} R ⥤ Sheaf J AddCommGrpCat.{v} where
obj M := ⟨_, M.isSheaf⟩
map f := { val := (forget R ⋙ PresheafOfModules.toPresheaf R.val).map f }
/--
The forgetful functor from sheaves of modules over sheaf of ring `R` to sheaves of `R(X)`-module
when `X` is initial.
-/
@[simps]
noncomputable def forgetToSheafModuleCat
(X : Cᵒᵖ) (hX : Limits.IsInitial X) :
SheafOfModules.{w} R ⥤ Sheaf J (ModuleCat.{w} (R.1.obj X)) where
obj M := ⟨(PresheafOfModules.forgetToPresheafModuleCat X hX).obj M.1,
Presheaf.isSheaf_of_isSheaf_comp _ _
(forget₂ (ModuleCat.{w} (R.1.obj X)) AddCommGrpCat.{w}) M.isSheaf⟩
map f := { val := (PresheafOfModules.forgetToPresheafModuleCat X hX).map f.1 }
/-- The canonical isomorphism between
`SheafOfModules.toSheaf R ⋙ sheafToPresheaf J AddCommGrpCat.{v}`
and `SheafOfModules.forget R ⋙ PresheafOfModules.toPresheaf R.val`. -/
noncomputable def toSheafCompSheafToPresheafIso :
toSheaf R ⋙ sheafToPresheaf J AddCommGrpCat.{v} ≅
forget R ⋙ PresheafOfModules.toPresheaf R.val := Iso.refl _
instance : (toSheaf.{v} R).Faithful :=
Functor.Faithful.of_comp_iso (toSheafCompSheafToPresheafIso.{v} R)
instance (M N : SheafOfModules.{v} R) : AddCommGroup (M ⟶ N) :=
(fullyFaithfulForget R).homEquiv.addCommGroup
@[simp]
lemma add_val {M N : SheafOfModules.{v} R} (f g : M ⟶ N) :
(f + g).val = f.val + g.val := rfl
instance : Preadditive (SheafOfModules.{v} R) where
add_comp := by intros; ext1; dsimp; simp only [Preadditive.add_comp]
comp_add := by tauto
instance : (forget R).Additive where
instance : (toSheaf R).Additive where
variable {R}
/-- The type of sections of a sheaf of modules. -/
abbrev sections (M : SheafOfModules.{v} R) : Type _ := M.val.sections
/-- The map `M.sections → N.sections` induced by a morphism `M ⟶ N` of sheaves of modules. -/
abbrev sectionsMap {M N : SheafOfModules.{v} R} (f : M ⟶ N) (s : M.sections) : N.sections :=
PresheafOfModules.sectionsMap f.val s
@[simp]
lemma sectionsMap_comp {M N P : SheafOfModules.{v} R} (f : M ⟶ N) (g : N ⟶ P) (s : M.sections) :
sectionsMap (f ≫ g) s = sectionsMap g (sectionsMap f s) := rfl
@[simp]
lemma sectionsMap_id {M : SheafOfModules.{v} R} (s : M.sections) :
sectionsMap (𝟙 M) s = s := rfl
variable (R) in
/-- The functor which sends a sheaf of modules to its type of sections. -/
@[simps]
def sectionsFunctor : SheafOfModules.{v} R ⥤ Type _ where
obj := sections
map f := sectionsMap f
variable [J.HasSheafCompose (forget₂ RingCat.{u} AddCommGrpCat.{u})]
variable (R) in
/-- The obvious free sheaf of modules of rank `1`. -/
@[simps]
noncomputable def unit : SheafOfModules R where
val := PresheafOfModules.unit R.val
isSheaf := ((sheafCompose J (forget₂ RingCat.{u} AddCommGrpCat.{u})).obj R).cond
/-- The bijection `(unit R ⟶ M) ≃ M.sections` for `M : SheafOfModules R`. -/
noncomputable def unitHomEquiv (M : SheafOfModules R) :
(unit R ⟶ M) ≃ M.sections :=
(fullyFaithfulForget R).homEquiv.trans M.val.unitHomEquiv
@[simp]
lemma unitHomEquiv_apply_coe (M : SheafOfModules R) (f : unit R ⟶ M) (X : Cᵒᵖ) :
(M.unitHomEquiv f).val X = f.val.app X (1 : R.val.obj X) := rfl
lemma unitHomEquiv_comp_apply {M N : SheafOfModules.{u} R}
(f : unit R ⟶ M) (p : M ⟶ N) :
N.unitHomEquiv (f ≫ p) = sectionsMap p (M.unitHomEquiv f) := rfl
lemma unitHomEquiv_symm_comp {M N : SheafOfModules.{u} R} (s : M.sections) (p : M ⟶ N) :
M.unitHomEquiv.symm s ≫ p = N.unitHomEquiv.symm (sectionsMap p s) :=
N.unitHomEquiv.injective (by simp [unitHomEquiv_comp_apply])
end SheafOfModules
namespace PresheafOfModules
variable (J)
variable {R : Cᵒᵖ ⥤ RingCat.{u}} {M₁ M₂ : PresheafOfModules.{v} R} (f : M₁ ⟶ M₂)
/-- A morphism of presheaves of modules is locally surjective
if the underlying morphism of presheaves of abelian groups is. -/
abbrev IsLocallySurjective : Prop :=
Presheaf.IsLocallySurjective J ((PresheafOfModules.toPresheaf R).map f)
/-- A morphism of presheaves of modules is locally injective
if the underlying morphism of presheaves of abelian groups is. -/
abbrev IsLocallyInjective : Prop :=
Presheaf.IsLocallyInjective J ((PresheafOfModules.toPresheaf R).map f)
variable {N : PresheafOfModules.{v} R} (hN : Presheaf.IsSheaf J N.presheaf)
[J.WEqualsLocallyBijective AddCommGrpCat.{v}]
[IsLocallySurjective J f] [IsLocallyInjective J f]
variable {J}
/-- The bijection `(M₂ ⟶ N) ≃ (M₁ ⟶ N)` induced by a locally bijective morphism
`f : M₁ ⟶ M₂` of presheaves of modules, when `N` is a sheaf. -/
@[simps]
noncomputable def homEquivOfIsLocallyBijective : (M₂ ⟶ N) ≃ (M₁ ⟶ N) where
toFun φ := f ≫ φ
invFun ψ := homMk (((J.W_of_isLocallyBijective
((PresheafOfModules.toPresheaf R).map f)).homEquiv _ hN).symm
((PresheafOfModules.toPresheaf R).map ψ)) (by
obtain ⟨φ, hφ⟩ := ((J.W_of_isLocallyBijective
((PresheafOfModules.toPresheaf R).map f)).homEquiv _ hN).surjective
((PresheafOfModules.toPresheaf R).map ψ)
simp only [← hφ, Equiv.symm_apply_apply]
replace hφ : ∀ (Z : Cᵒᵖ) (x : M₁.obj Z), φ.app Z (f.app Z x) = ψ.app Z x :=
fun Z x ↦ CategoryTheory.congr_fun (congr_app hφ Z) x
intro X r y
apply hN.isSeparated _ _
(Presheaf.imageSieve_mem J ((toPresheaf R).map f) y)
rintro Y p ⟨x : M₁.obj _, hx : f.app _ x = M₂.map p.op y⟩
have hφ' : ∀ (z : M₂.obj X), φ.app _ (M₂.map p.op z) =
N.map p.op (φ.app _ z) := CategoryTheory.congr_fun (φ.naturality p.op)
change N.map p.op (φ.app X (r • y)) = N.map p.op (r • φ.app X y)
rw [← hφ', M₂.map_smul, ← hx, ← (f.app _).hom.map_smul, hφ, (ψ.app _).hom.map_smul,
← hφ, hx, N.map_smul, hφ'])
left_inv φ := (toPresheaf _).map_injective
(((J.W_of_isLocallyBijective
((PresheafOfModules.toPresheaf R).map f)).homEquiv _ hN).left_inv
((PresheafOfModules.toPresheaf R).map φ))
right_inv ψ := (toPresheaf _).map_injective
(((J.W_of_isLocallyBijective
((PresheafOfModules.toPresheaf R).map f)).homEquiv _ hN).right_inv
((PresheafOfModules.toPresheaf R).map ψ))
end PresheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/LeftResolution.lean | import Mathlib.Algebra.Category.ModuleCat.Adjunctions
import Mathlib.Algebra.Category.ModuleCat.EpiMono
import Mathlib.Algebra.Homology.LeftResolution.Basic
/-!
# Functorial projective resolutions of modules
The fact that a `R`-module `M` can be functorially written as a quotient of a
projective `R`-module is expressed as the definition `ModuleCat.projectiveResolution`.
Using the construction in the file `Algebra.Homology.LeftResolution.Basic`,
we may obtain a functor `(projectiveResolution R).chainComplexFunctor` which
sends `M : ModuleCat R` to a projective resolution.
-/
universe u
variable (R : Type u) [Ring R]
namespace ModuleCat
open CategoryTheory Abelian
instance (X : Type u) : Projective ((free R).obj X) where
factors {M N} f p hp := by
rw [epi_iff_surjective] at hp
obtain ⟨s, hs⟩ := hp.hasRightInverse
exact ⟨freeDesc (fun x ↦ s (f (freeMk x))), by cat_disch⟩
/-- A `R`-module `M` can be functorially written as a quotient of a
projective `R`-module. -/
noncomputable def projectiveResolution :
LeftResolution (ObjectProperty.ι (isProjective (ModuleCat.{u} R))) where
F := ObjectProperty.lift _ (forget _ ⋙ free R) (by dsimp; infer_instance)
π := (adj R).counit
end ModuleCat |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.