Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit a574db1

Browse files
committed
refactor(algebra/category/*/limits): refactor concrete limits (#3463)
We used to construct categorical limits for `AddCommGroup` and `CommRing`. Now we construct them for * `(Add)(Comm)Mon` * `(Add)(Comm)Group` * `(Comm)(Semi)Ring` * `Module R` * `Algebra R` Even better, we reuse structure along the way, and show that all the relevant forgetful functors preserve limits. We're still not at the point were this can either be done by * automation, or * noticing that everything is a model of a Lawvere theory but ... maybe one day. Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
1 parent ce70305 commit a574db1

File tree

18 files changed

+990
-190
lines changed

18 files changed

+990
-190
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/-
2+
Copyright (c) 2020 Scott Morrison. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Scott Morrison
5+
-/
6+
import algebra.category.Algebra.basic
7+
import algebra.category.Module.limits
8+
import algebra.category.CommRing.limits
9+
10+
/-!
11+
# The category of R-algebras has all limits
12+
13+
Further, these limits are preserved by the forgetful functor --- that is,
14+
the underlying types are just the limits in the category of types.
15+
-/
16+
17+
open category_theory
18+
open category_theory.limits
19+
20+
universe u
21+
22+
namespace Algebra
23+
24+
variables {R : Type u} [comm_ring R]
25+
variables {J : Type u} [small_category J]
26+
27+
instance semiring_obj (F : J ⥤ Algebra R) (j) :
28+
semiring ((F ⋙ forget (Algebra R)).obj j) :=
29+
by { change semiring (F.obj j), apply_instance }
30+
31+
instance algebra_obj (F : J ⥤ Algebra R) (j) :
32+
algebra R ((F ⋙ forget (Algebra R)).obj j) :=
33+
by { change algebra R (F.obj j), apply_instance }
34+
35+
/--
36+
The flat sections of a functor into `Algebra R` form a submodule of all sections.
37+
-/
38+
def sections_subalgebra (F : J ⥤ Algebra R) :
39+
subalgebra R (Π j, F.obj j) :=
40+
{ carrier := SemiRing.sections_subsemiring (F ⋙ forget₂ (Algebra R) Ring ⋙ forget₂ Ring SemiRing),
41+
algebra_map_mem' := λ r j j' f, (F.map f).commutes r, }
42+
43+
44+
instance limit_semiring (F : J ⥤ Algebra R) :
45+
ring (limit (F ⋙ forget (Algebra R))) :=
46+
begin
47+
change ring (sections_subalgebra F),
48+
apply_instance,
49+
end
50+
51+
instance limit_algebra (F : J ⥤ Algebra R) :
52+
algebra R (limit (F ⋙ forget (Algebra R))) :=
53+
begin
54+
change algebra R (sections_subalgebra F),
55+
apply_instance,
56+
end
57+
58+
/-- `limit.π (F ⋙ forget (Algebra R)) j` as a `alg_hom`. -/
59+
def limit_π_alg_hom (F : J ⥤ Algebra R) (j) :
60+
limit (F ⋙ forget (Algebra R)) →ₐ[R] (F ⋙ forget (Algebra R)).obj j :=
61+
{ commutes' := λ r, rfl,
62+
..SemiRing.limit_π_ring_hom (F ⋙ forget₂ (Algebra R) Ring ⋙ forget₂ Ring SemiRing) j }
63+
64+
namespace has_limits
65+
-- The next two definitions are used in the construction of `has_limits (Algebra R)`.
66+
-- After that, the limits should be constructed using the generic limits API,
67+
-- e.g. `limit F`, `limit.cone F`, and `limit.is_limit F`.
68+
69+
/--
70+
Construction of a limit cone in `Algebra R`.
71+
(Internal use only; use the limits API.)
72+
-/
73+
def limit (F : J ⥤ Algebra R) : cone F :=
74+
{ X := Algebra.of R (limit (F ⋙ forget _)),
75+
π :=
76+
{ app := limit_π_alg_hom F,
77+
naturality' := λ j j' f,
78+
alg_hom.coe_fn_inj ((limit.cone (F ⋙ forget _)).π.naturality f) } }
79+
80+
/--
81+
Witness that the limit cone in `Algebra R` is a limit cone.
82+
(Internal use only; use the limits API.)
83+
-/
84+
def limit_is_limit (F : J ⥤ Algebra R) : is_limit (limit F) :=
85+
begin
86+
refine is_limit.of_faithful
87+
(forget (Algebra R)) (limit.is_limit _)
88+
(λ s, { .. }) (λ s, rfl),
89+
{ simp only [forget_map_eq_coe, alg_hom.map_one, functor.map_cone_π], refl, },
90+
{ intros x y, simp only [forget_map_eq_coe, alg_hom.map_mul, functor.map_cone_π], refl, },
91+
{ simp only [forget_map_eq_coe, alg_hom.map_zero, functor.map_cone_π], refl, },
92+
{ intros x y, simp only [forget_map_eq_coe, alg_hom.map_add, functor.map_cone_π], refl, },
93+
{ intros r, ext j, dsimp, erw (s.π.app j).commutes r, refl, },
94+
end
95+
96+
end has_limits
97+
98+
open has_limits
99+
100+
/-- The category of R-algebras has all limits. -/
101+
instance has_limits : has_limits (Algebra R) :=
102+
{ has_limits_of_shape := λ J 𝒥,
103+
{ has_limit := λ F, by exactI
104+
{ cone := limit F,
105+
is_limit := limit_is_limit F } } }
106+
107+
/--
108+
The forgetful functor from R-algebras to rings preserves all limits.
109+
-/
110+
instance forget₂_Ring_preserves_limits : preserves_limits (forget₂ (Algebra R) Ring) :=
111+
{ preserves_limits_of_shape := λ J 𝒥,
112+
{ preserves_limit := λ F,
113+
by exactI preserves_limit_of_preserves_limit_cone
114+
(limit.is_limit F) (limit.is_limit (F ⋙ forget₂ (Algebra R) Ring)) } }
115+
116+
/--
117+
The forgetful functor from R-algebras to R-modules preserves all limits.
118+
-/
119+
instance forget₂_Module_preserves_limits : preserves_limits (forget₂ (Algebra R) (Module R)) :=
120+
{ preserves_limits_of_shape := λ J 𝒥,
121+
{ preserves_limit := λ F,
122+
by exactI preserves_limit_of_preserves_limit_cone
123+
(limit.is_limit F) (limit.is_limit (F ⋙ forget₂ (Algebra R) (Module R))) } }
124+
125+
/--
126+
The forgetful functor from R-algebras to types preserves all limits.
127+
-/
128+
instance forget_preserves_limits : preserves_limits (forget (Algebra R)) :=
129+
{ preserves_limits_of_shape := λ J 𝒥,
130+
{ preserves_limit := λ F,
131+
by exactI preserves_limit_of_preserves_limit_cone
132+
(limit.is_limit F) (limit.is_limit (F ⋙ forget _)) } }
133+
134+
end Algebra

src/algebra/category/CommRing/basic.lean

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ Copyright (c) 2018 Scott Morrison. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Scott Morrison, Johannes Hölzl, Yury Kudryashov
55
-/
6-
import algebra.category.Group
6+
import algebra.category.Group.basic
7+
import category_theory.reflect_isomorphisms
78
import data.equiv.ring
89

910
/-!
@@ -124,6 +125,9 @@ instance has_forget_to_Ring : has_forget₂ CommRing Ring := bundled_hom.forget
124125
instance has_forget_to_CommSemiRing : has_forget₂ CommRing CommSemiRing :=
125126
has_forget₂.mk' (λ R : CommRing, CommSemiRing.of R) (λ R, rfl) (λ R₁ R₂ f, f) (by tidy)
126127

128+
instance : full (forget₂ CommRing CommSemiRing) :=
129+
{ preimage := λ X Y f, f, }
130+
127131
end CommRing
128132

129133
-- This example verifies an improvement possible in Lean 3.8.
@@ -149,6 +153,16 @@ variables {X Y : Type u}
149153

150154
end ring_equiv
151155

156+
namespace Ring
157+
158+
instance : reflects_isomorphisms (forget₂ Ring AddCommGroup) :=
159+
{ reflects := λ R S f i, by exactI
160+
{ ..ring_equiv.to_Ring_iso
161+
{ ..(as_iso ((forget₂ Ring AddCommGroup).map f)).AddCommGroup_iso_to_add_equiv,
162+
..f } } }
163+
164+
end Ring
165+
152166
namespace category_theory.iso
153167

154168
/-- Build a `ring_equiv` from an isomorphism in the category `Ring`. -/

src/algebra/category/CommRing/colimits.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Scott Morrison
55
-/
66
import algebra.category.CommRing.basic
7+
import category_theory.limits.limits
8+
import category_theory.limits.concrete_category
79

810
/-!
911
# The category of commutative rings has all colimits.

0 commit comments

Comments
 (0)