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

Commit 080746f

Browse files
committed
feat(algebra/category/*/limits): don't rely on definitions (#3873)
This is a second attempt (which works **much** better) at #3860, after @TwoFX explained how to do it properly. This PR takes the constructions of limits in the concrete categories `(Add)(Comm)[Mon|Group]`, `(Comm)(Semi)Ring`, `Module R`, and `Algebra R`, and makes sure that they never rely on the actual definitions of limits in "prior" categories. Of course, at this stage the `has_limit` typeclasses still contain data, so it's hard to judge whether we're really not relying on the definitions. I've marked all the `has_limits` instances in these files as irreducible, but the real proof is just that this same code is working over on the `prop_limits` branch. Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
1 parent 2d9ab61 commit 080746f

6 files changed

Lines changed: 357 additions & 211 deletions

File tree

src/algebra/category/Algebra/limits.lean

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,22 @@ def sections_subalgebra (F : J ⥤ Algebra R) :
4242

4343

4444
instance limit_semiring (F : J ⥤ Algebra R) :
45-
ring (limit (F ⋙ forget (Algebra R))) :=
45+
ring (types.limit_cone (F ⋙ forget (Algebra R))).X :=
4646
begin
4747
change ring (sections_subalgebra F),
4848
apply_instance,
4949
end
5050

5151
instance limit_algebra (F : J ⥤ Algebra R) :
52-
algebra R (limit (F ⋙ forget (Algebra R))) :=
52+
algebra R (types.limit_cone (F ⋙ forget (Algebra R))).X :=
5353
begin
5454
change algebra R (sections_subalgebra F),
5555
apply_instance,
5656
end
5757

5858
/-- `limit.π (F ⋙ forget (Algebra R)) j` as a `alg_hom`. -/
5959
def limit_π_alg_hom (F : J ⥤ Algebra R) (j) :
60-
limit (F ⋙ forget (Algebra R)) →ₐ[R] (F ⋙ forget (Algebra R)).obj j :=
60+
(types.limit_cone (F ⋙ forget (Algebra R))).X →ₐ[R] (F ⋙ forget (Algebra R)).obj j :=
6161
{ commutes' := λ r, rfl,
6262
..SemiRing.limit_π_ring_hom (F ⋙ forget₂ (Algebra R) Ring ⋙ forget₂ Ring SemiRing) j }
6363

@@ -70,21 +70,21 @@ namespace has_limits
7070
Construction of a limit cone in `Algebra R`.
7171
(Internal use only; use the limits API.)
7272
-/
73-
def limit (F : J ⥤ Algebra R) : cone F :=
74-
{ X := Algebra.of R (limit (F ⋙ forget _)),
73+
def limit_cone (F : J ⥤ Algebra R) : cone F :=
74+
{ X := Algebra.of R (types.limit_cone (F ⋙ forget _)).X,
7575
π :=
7676
{ app := limit_π_alg_hom F,
7777
naturality' := λ j j' f,
78-
alg_hom.coe_fn_inj ((limit.cone (F ⋙ forget _)).π.naturality f) } }
78+
alg_hom.coe_fn_inj ((types.limit_cone (F ⋙ forget _)).π.naturality f) } }
7979

8080
/--
8181
Witness that the limit cone in `Algebra R` is a limit cone.
8282
(Internal use only; use the limits API.)
8383
-/
84-
def limit_is_limit (F : J ⥤ Algebra R) : is_limit (limit F) :=
84+
def limit_cone_is_limit (F : J ⥤ Algebra R) : is_limit (limit_cone F) :=
8585
begin
8686
refine is_limit.of_faithful
87-
(forget (Algebra R)) (limit.is_limit _)
87+
(forget (Algebra R)) (types.limit_cone_is_limit _)
8888
(λ s, { .. }) (λ s, rfl),
8989
{ simp only [forget_map_eq_coe, alg_hom.map_one, functor.map_cone_π], refl, },
9090
{ intros x y, simp only [forget_map_eq_coe, alg_hom.map_mul, functor.map_cone_π], refl, },
@@ -98,37 +98,49 @@ end has_limits
9898
open has_limits
9999

100100
/-- The category of R-algebras has all limits. -/
101+
@[irreducible]
101102
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 } } }
103+
{ has_limits_of_shape := λ J 𝒥, by exactI
104+
{ has_limit := λ F,
105+
{ cone := limit_cone F,
106+
is_limit := limit_cone_is_limit F } } }
107+
108+
/--
109+
An auxiliary declaration to speed up typechecking.
110+
-/
111+
def forget₂_Ring_preserves_limits_aux (F : J ⥤ Algebra R) :
112+
is_limit ((forget₂ (Algebra R) Ring).map_cone (limit_cone F)) :=
113+
Ring.limit_cone_is_limit (F ⋙ forget₂ (Algebra R) Ring)
106114

107115
/--
108116
The forgetful functor from R-algebras to rings preserves all limits.
109117
-/
110118
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)) } }
119+
{ preserves_limits_of_shape := λ J 𝒥, by exactI
120+
{ preserves_limit := λ F, preserves_limit_of_preserves_limit_cone
121+
(limit_cone_is_limit F) (forget₂_Ring_preserves_limits_aux F) } }
122+
123+
/--
124+
An auxiliary declaration to speed up typechecking.
125+
-/
126+
def forget₂_Module_preserves_limits_aux (F : J ⥤ Algebra R) :
127+
is_limit ((forget₂ (Algebra R) (Module R)).map_cone (limit_cone F)) :=
128+
Module.has_limits.limit_cone_is_limit (F ⋙ forget₂ (Algebra R) (Module R))
115129

116130
/--
117131
The forgetful functor from R-algebras to R-modules preserves all limits.
118132
-/
119133
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))) } }
134+
{ preserves_limits_of_shape := λ J 𝒥, by exactI
135+
{ preserves_limit := λ F, preserves_limit_of_preserves_limit_cone
136+
(limit_cone_is_limit F) (forget₂_Module_preserves_limits_aux F) } }
124137

125138
/--
126139
The forgetful functor from R-algebras to types preserves all limits.
127140
-/
128141
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 _)) } }
142+
{ preserves_limits_of_shape := λ J 𝒥, by exactI
143+
{ preserves_limit := λ F, preserves_limit_of_preserves_limit_cone
144+
(limit_cone_is_limit F) (types.limit_cone_is_limit (F ⋙ forget _)) } }
133145

134146
end Algebra

0 commit comments

Comments
 (0)