Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(order/category/DecLinOrder): updates to concrete_category, and instances for order categories #1438

Closed
wants to merge 115 commits into from
Closed
Show file tree
Hide file tree
Changes from 106 commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
9b875aa
trying to use bundled homs
semorrison Aug 31, 2019
0513b80
bundled monoids should use bundled homs
semorrison Aug 31, 2019
c040732
fixes
semorrison Sep 1, 2019
fc9a5b8
Merge branch 'master' into Mon_bundled_hom
semorrison Sep 1, 2019
e3d7958
fixes
semorrison Sep 1, 2019
5d8fe7d
refactor(*): rewrite concrete categories
urkud Sep 1, 2019
99e6ce2
Add module documentation
urkud Sep 2, 2019
54e7bfd
local instance
semorrison Sep 2, 2019
229d49b
Merge branch 'Mon_bundled_hom' into concrete-categories
urkud Sep 2, 2019
82cb41f
Move files around; don't touch content yet
urkud Sep 2, 2019
eb74f1d
Move code around, fix some compile errors
urkud Sep 3, 2019
def6ca9
Add `unbundled_hom.lean`
urkud Sep 3, 2019
5f45bb9
Merge branch 'master' into concrete-categories
urkud Sep 3, 2019
03b8a1f
Turn `hom` into an argument of `(un)bundled_hom`
urkud Sep 5, 2019
0f5c068
Define `unbundled_hom.mk_has_forget`; fix compile
urkud Sep 5, 2019
98406b5
Merge branch 'master' into concrete-categories
urkud Sep 5, 2019
f25c7f5
Add some documentation
urkud Sep 6, 2019
8bc4db1
Fix compile
urkud Sep 6, 2019
3a39467
chore(category_theory): require morphisms live in Type
semorrison Sep 6, 2019
647b9ec
move back to Type
semorrison Sep 6, 2019
43a293f
tweaks to doc-comments
semorrison Sep 8, 2019
a998991
fixing some formatting
semorrison Sep 8, 2019
055dd85
Revert most of the changes to `data/mv_polynomials`
urkud Sep 9, 2019
5f52b89
Merge branch 'master' into concrete-categories
urkud Sep 10, 2019
e6ccb90
Merge branch 'concrete-categories' of ssh://github.com/urkud/mathlib …
urkud Sep 10, 2019
4fe5f57
Drop unused argument, add a comment
urkud Sep 10, 2019
a036399
Merge branch 'master' into concrete-categories
urkud Sep 10, 2019
3df346f
merge
semorrison Sep 11, 2019
dea5bad
Merge branch 'master' into concrete-categories
urkud Sep 13, 2019
d9700b9
Merge remote-tracking branch 'origin/master' into category_no_sorts
semorrison Sep 13, 2019
1ef98cb
Simplify universe levels in `concrete_category/basic`.
urkud Sep 13, 2019
e8701ee
Simplify universe levels in `concrete_category/{un,}bundled_hom`
urkud Sep 13, 2019
8bc5a4a
Merge branch 'concrete-categories' of ssh://github.com/urkud/mathlib …
urkud Sep 13, 2019
ec618c1
fixes
semorrison Sep 13, 2019
5d686e8
Fix an `import`
urkud Sep 13, 2019
e493d28
Merge branch 'master' into concrete-categories
urkud Sep 13, 2019
3bcb348
Doc cleanup
urkud Sep 13, 2019
7f75dc8
Merge branch 'concrete-categories' of ssh://github.com/urkud/mathlib …
urkud Sep 13, 2019
8d8c1c9
Merge branch 'master' into concrete-categories
urkud Sep 15, 2019
0107097
feat(order/category/DecLinOrder): updates to concrete_category, and i…
semorrison Sep 15, 2019
7991de6
fix
semorrison Sep 15, 2019
1f1474e
fix
semorrison Sep 15, 2019
56a173a
fix
semorrison Sep 15, 2019
40a3dda
fixes
semorrison Sep 15, 2019
c08a7a2
...
semorrison Sep 15, 2019
6002ee9
...
semorrison Sep 15, 2019
ffc0d65
Merge branch 'category_no_sorts' into concrete-categories
semorrison Sep 17, 2019
70698db
update post #1412
semorrison Sep 17, 2019
a017e5b
Merge remote-tracking branch 'origin/master' into concrete-categories
semorrison Sep 17, 2019
bea333b
merge
semorrison Sep 17, 2019
154e24f
Drop `simp`
urkud Sep 17, 2019
71ff1c4
Merge branch 'concrete-categories' of ssh://github.com/urkud/mathlib …
urkud Sep 17, 2019
35ab1a4
Rename variable
urkud Sep 17, 2019
3845f28
Rename variable
urkud Sep 17, 2019
fcf20ff
Merge remote-tracking branch 'urkud/concrete-categories' into DecLinO…
Sep 17, 2019
fe3fd0e
Fix more issues reported by @rwbarton
urkud Sep 18, 2019
372a57f
Merge branch 'concrete-categories' of ssh://github.com/urkud/mathlib …
urkud Sep 18, 2019
5a4032c
Rename variable
urkud Sep 18, 2019
c0a284c
Merge branch 'concrete-categories' of ssh://github.com/urkud/mathlib …
urkud Sep 18, 2019
d0d0ed8
Merge branch 'master' into concrete-categories
urkud Sep 18, 2019
d692310
Merge branch 'concrete-categories' of ssh://github.com/urkud/mathlib …
urkud Sep 18, 2019
b638d2c
merge
Sep 18, 2019
19388a0
Use `subtype.eq` instead of `subtype.ext.2`
urkud Sep 18, 2019
a6c8d72
Cleanup
urkud Sep 18, 2019
aaa8b1e
Fix compile: now `ring_hom.ext` takes fewer explicit args
urkud Sep 18, 2019
5a6b125
Fix compile
urkud Sep 18, 2019
8b36efa
Run `sanity_check` on all files modified in this branch
urkud Sep 18, 2019
62c06cc
ring_hom.ext changed signature
Sep 18, 2019
2088c36
fix signatures
Sep 18, 2019
09d790c
more signatures
Sep 18, 2019
e256721
Review `∀` vs `Π`
urkud Sep 18, 2019
310ddfd
Remove some unnecessary parentheses
urkud Sep 18, 2019
6ad51ef
add comment
semorrison Sep 18, 2019
0195d6f
punit_instances: no need to explicitly provide constants and operations
urkud Sep 18, 2019
531e15e
Rename `has_forget` to `has_forget₂`
urkud Sep 18, 2019
d04e53c
add comment, simplify comm_ring punit
semorrison Sep 18, 2019
6819855
Merge branch 'concrete-categories' of ssh://github.com/urkud/mathlib …
urkud Sep 18, 2019
e2f66fe
Drop `private def free_obj`
urkud Sep 18, 2019
24e1502
documentation
semorrison Sep 18, 2019
a158c9c
merge
semorrison Sep 18, 2019
6a68686
merge
semorrison Sep 18, 2019
8077b3f
merge
semorrison Sep 19, 2019
8599fe5
fixes
semorrison Sep 19, 2019
eff5570
fix typo
semorrison Sep 19, 2019
a2051b4
fix
semorrison Sep 19, 2019
99fcd0d
partial fixes, probably all still borked
semorrison Sep 19, 2019
da1df4d
ugh, I mangled the merge
semorrison Sep 19, 2019
fe26fb1
fixes
semorrison Sep 19, 2019
66cdbd9
comments on uniform space categories
semorrison Sep 19, 2019
7d98dde
cleanup
semorrison Sep 19, 2019
9470d2f
fix botched merge
semorrison Sep 20, 2019
d0e8c14
Update src/algebra/category/Mon/basic.lean
semorrison Sep 20, 2019
594128d
Update src/order/category/DecLinOrder.lean
semorrison Sep 20, 2019
456cdcf
Update src/algebra/category/Mon/basic.lean
semorrison Sep 20, 2019
39628ca
change examples to `concrete_category`
semorrison Sep 20, 2019
c68ba5a
Rename types to match mathematical usage
semorrison Sep 20, 2019
8f65712
Merge branch 'DecLinOrder' of github.com:leanprover-community/mathlib…
semorrison Sep 20, 2019
98bfb55
fixing cases
semorrison Sep 20, 2019
5818c95
rename notation to `U`
semorrison Sep 20, 2019
57a11a3
make module doc string
semorrison Sep 20, 2019
bc1a912
solved coercion problem
semorrison Sep 21, 2019
360a361
experiments
semorrison Sep 21, 2019
4cb28ab
huh, maybe okay
semorrison Sep 21, 2019
08b0590
cleanup of UniformSpace
semorrison Sep 21, 2019
9b03aa6
minor cleanup
semorrison Sep 21, 2019
e6ae377
Merge branch 'master' into DecLinOrder
semorrison Sep 21, 2019
8af7dd7
comment
semorrison Sep 21, 2019
adbc906
Add a docstring, reuse an instance
urkud Sep 21, 2019
65a09bd
Formulate naturality of (co)cones over functors to concrete categorie…
urkud Sep 21, 2019
da67e28
Fix a typo
urkud Sep 21, 2019
47844e9
Merge branch 'DecLinOrder' of github.com:leanprover-community/mathlib…
semorrison Sep 21, 2019
0b79837
only reducible locally
semorrison Sep 22, 2019
a301735
oops, update Group and Mon too
semorrison Sep 22, 2019
be66fde
cleanup, rfl lemma
Sep 23, 2019
df0fe2c
Merge branch 'master' into DecLinOrder
semorrison Sep 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/algebra/category/CommRing/adjunctions.lean
Expand Up @@ -31,7 +31,7 @@ def free : Type u ⥤ CommRing.{u} :=
{ obj := λ α, of (mv_polynomial α ℤ),
-- TODO this should just be `ring_hom.of (rename f)`, but this causes a mysterious deterministic timeout!
map := λ X Y f, @ring_hom.of _ _ _ _ (rename f) (by apply_instance),
-- TODO these next two fields can be done by `tidy`, but the calls in `dsimp` and `simp` it generates are too slow.
-- TODO these next two fields can be done by `tidy`, but the calls in `dsimp` and `simp` it generates are rather slow.
map_id' := λ X, ring_hom.ext $ funext $ rename_id,
map_comp' := λ X Y Z f g, ring_hom.ext $ funext $ λ p, (rename_rename f g p).symm }

Expand All @@ -41,12 +41,19 @@ def free : Type u ⥤ CommRing.{u} :=
@[simp] lemma free_map_coe {α β : Type u} {f : α → β} :
⇑(free.map f) = rename f := rfl

namespace adj
-- The next two definitions are (unfortunate) "implementation details", helping the elaborator / typeclass search.
def hom_equiv (X : Type u) (R : CommRing) := hom_equiv R X
instance (R : CommRing) : is_ring_hom (λ (n : ℤ), (n : R)) := by tidy
end adj
open adj

/--
The free-forgetful adjunction for commutative rings.
-/
def adj : free ⊣ forget CommRing :=
def adj : free ⊣ forget CommRing.{u} :=
semorrison marked this conversation as resolved.
Show resolved Hide resolved
adjunction.mk_of_hom_equiv
{ hom_equiv := λ X R, hom_equiv,
hom_equiv_naturality_left_symm' := by {intros, ext, dsimp, apply eval₂_cast_comp} }
{ hom_equiv := λ X R, hom_equiv X R,
hom_equiv_naturality_left_symm' := by { intros, ext, dsimp, apply eval₂_cast_comp } }

end CommRing
63 changes: 22 additions & 41 deletions src/algebra/category/CommRing/basic.lean
Expand Up @@ -32,89 +32,70 @@ namespace SemiRing
/-- Construct a bundled SemiRing from the underlying type and typeclass. -/
def of (R : Type u) [semiring R] : SemiRing := bundled.of R

instance (R : SemiRing) : semiring R := R.str

instance bundled_hom : bundled_hom @ring_hom :=
⟨@ring_hom.to_fun, @ring_hom.id, @ring_hom.comp, @ring_hom.ext⟩

instance (R : SemiRing) : semiring R := R.str

instance has_forget_to_Mon : has_forget₂ SemiRing.{u} Mon.{u} :=
bundled_hom.mk_has_forget₂ @semiring.to_monoid (λ R₁ R₂ f, f.to_monoid_hom) (λ _ _ _, rfl)

end SemiRing

/-- The category of rings. -/
@[reducible] def Ring : Type (u+1) := bundled ring
@[reducible] def Ring : Type (u+1) := induced_category SemiRing (bundled.map @ring.to_semiring.{u})

namespace Ring

instance (R : Ring) : ring R := R.str

/-- Construct a bundled Ring from the underlying type and typeclass. -/
def of (R : Type u) [ring R] : Ring := bundled.of R

instance bundled_hom : bundled_hom _ :=
SemiRing.bundled_hom.full_subcategory @ring.to_semiring
instance (R : Ring) : ring R := R.str

instance has_forget_to_SemiRing : has_forget₂ Ring.{u} SemiRing.{u} :=
SemiRing.bundled_hom.full_subcategory_has_forget₂ _
example : concrete_category Ring.{u} := infer_instance
example : has_forget₂ Ring.{u} SemiRing.{u} := infer_instance

end Ring

/-- The category of commutative semirings. -/
@[reducible] def CommSemiRing : Type (u+1) := bundled comm_semiring
@[reducible] def CommSemiRing : Type (u+1) := induced_category SemiRing (bundled.map comm_semiring.to_semiring.{u})

namespace CommSemiRing

instance (R : CommSemiRing) : comm_semiring R := R.str

/-- Construct a bundled CommSemiRing from the underlying type and typeclass. -/
def of (R : Type u) [comm_semiring R] : CommSemiRing := bundled.of R

instance bundled_hom : bundled_hom _ :=
SemiRing.bundled_hom.full_subcategory @comm_semiring.to_semiring
instance (R : CommSemiRing) : comm_semiring R := R.str

instance has_forget_to_SemiRing : has_forget₂ CommSemiRing.{u} SemiRing.{u} :=
bundled_hom.full_subcategory_has_forget₂ _ _
-- These examples verify that we have successfully provided the expected instances.
example : concrete_category CommSemiRing.{u} := infer_instance
example : has_forget₂ CommSemiRing.{u} SemiRing.{u} := infer_instance

/-- The forgetful functor from commutative rings to (multiplicative) commutative monoids. -/
instance has_forget_to_CommMon : has_forget₂ CommSemiRing.{u} CommMon.{u} :=
bundled_hom.mk_has_forget₂
@comm_semiring.to_comm_monoid
(λ R₁ R₂ f, f.to_monoid_hom)
(by intros; refl)
has_forget₂.mk'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there any particular reason to change this one and the next, but not the one above?

(λ R : CommSemiRing.{u}, CommMon.of R) (λ R, rfl)
(λ R₁ R₂ f, f.to_monoid_hom) (by tidy)

end CommSemiRing

/-- The category of commutative rings. -/
@[reducible] def CommRing : Type (u+1) := bundled comm_ring
-- TODO experiment with making @[reducible] local
@[reducible] def CommRing : Type (u+1) := induced_category Ring (bundled.map comm_ring.to_ring.{u})

namespace CommRing

instance (R : CommRing) : comm_ring R := R.str

/-- Construct a bundled CommRing from the underlying type and typeclass. -/
def of (R : Type u) [comm_ring R] : CommRing := bundled.of R

instance bundled_hom : bundled_hom _ :=
Ring.bundled_hom.full_subcategory @comm_ring.to_ring

@[simp] lemma id_eq (R : CommRing) : 𝟙 R = ring_hom.id R := rfl
@[simp] lemma comp_eq {R₁ R₂ R₃ : CommRing} (f : R₁ ⟶ R₂) (g : R₂ ⟶ R₃) :
f ≫ g = g.comp f := rfl

@[simp] lemma forget_obj_eq_coe {R : CommRing} : (forget CommRing).obj R = R := rfl
@[simp] lemma forget_map_eq_coe {R₁ R₂ : CommRing} (f : R₁ ⟶ R₂) :
(forget CommRing).map f = f :=
rfl
instance (R : CommRing) : comm_ring R := R.str

instance has_forget_to_Ring : has_forget₂ CommRing.{u} Ring.{u} :=
by apply bundled_hom.full_subcategory_has_forget₂
-- These examples verify that we have successfully provided the expected instances.
example : concrete_category CommRing.{u} := infer_instance
example : has_forget₂ CommRing.{u} Ring.{u} := infer_instance

/-- The forgetful functor from commutative rings to (multiplicative) commutative monoids. -/
/-- The forgetful functor from commutative rings to commutative semirings. -/
instance has_forget_to_CommSemiRing : has_forget₂ CommRing.{u} CommSemiRing.{u} :=
bundled_hom.mk_has_forget₂
@comm_ring.to_comm_semiring
(λ _ _, id)
(by intros; refl)
has_forget₂.mk' (λ R : CommRing.{u}, CommSemiRing.of R) (λ R, rfl) (λ R₁ R₂ f, f) (by tidy)

end CommRing
46 changes: 18 additions & 28 deletions src/algebra/category/CommRing/colimits.lean
Expand Up @@ -53,7 +53,7 @@ variables {J : Type v} [small_category J] (F : J ⥤ CommRing.{v})

inductive prequotient
-- There's always `of`
| of : Π (j : J) (x : (F.obj j).α), prequotient
| of : Π (j : J) (x : F.obj j), prequotient
-- Then one generator for each operation
| zero {} : prequotient
| one {} : prequotient
Expand All @@ -69,13 +69,13 @@ inductive relation : prequotient F → prequotient F → Prop
| symm : Π (x y) (h : relation x y), relation y x
| trans : Π (x y z) (h : relation x y) (k : relation y z), relation x z
-- There's always a `map` relation
| map : Π (j j' : J) (f : j ⟶ j') (x : (F.obj j).α), relation (of j' (F.map f x)) (of j x)
| map : Π (j j' : J) (f : j ⟶ j') (x : F.obj j), relation (of j' (F.map f x)) (of j x)
-- Then one relation per operation, describing the interaction with `of`
| zero : Π (j), relation (of j 0) zero
| one : Π (j), relation (of j 1) one
| neg : Π (j) (x : (F.obj j).α), relation (of j (-x)) (neg (of j x))
| add : Π (j) (x y : (F.obj j).α), relation (of j (x + y)) (add (of j x) (of j y))
| mul : Π (j) (x y : (F.obj j).α), relation (of j (x * y)) (mul (of j x) (of j y))
| neg : Π (j) (x : F.obj j), relation (of j (-x)) (neg (of j x))
| add : Π (j) (x y : F.obj j), relation (of j (x + y)) (add (of j x) (of j y))
| mul : Π (j) (x y : F.obj j), relation (of j (x * y)) (mul (of j x) (of j y))
-- Then one relation per argument of each operation
| neg_1 : Π (x x') (r : relation x x'), relation (neg x) (neg x')
| add_1 : Π (x x' y) (r : relation x x'), relation (add x y) (add x' y)
Expand Down Expand Up @@ -272,7 +272,7 @@ instance : comm_ring (colimit_type F) :=

def colimit : CommRing := CommRing.of (colimit_type F)

def cocone_fun (j : J) (x : (F.obj j).α) : colimit_type F :=
def cocone_fun (j : J) (x : F.obj j) : colimit_type F :=
quot.mk _ (of j x)

def cocone_morphism (j : J) : F.obj j ⟶ colimit F :=
Expand All @@ -296,8 +296,7 @@ by { rw ←cocone_naturality F f, refl }

def colimit_cocone : cocone F :=
{ X := colimit F,
ι :=
{ app := cocone_morphism F } }.
ι := { app := cocone_morphism F } }.

@[simp] def desc_fun_lift (s : cocone F) : prequotient F → s.X
| (of j x) := (s.ι.app j) x
Expand All @@ -320,17 +319,17 @@ begin
-- trans
{ exact eq.trans r_ih_h r_ih_k },
-- map
{ rw cocone.naturality_bundled, },
{ apply cocone.naturality_bundled', },
-- zero
{ erw is_ring_hom.map_zero ⇑((s.ι).app r), refl },
{ exact ((s.ι).app r).map_zero, }, -- TODO why doesn't `simp only [ring_hom.map_zero]` work?
-- one
{ erw is_ring_hom.map_one ⇑((s.ι).app r), refl },
{ exact ((s.ι).app r).map_one },
-- neg
{ rw is_ring_hom.map_neg ⇑((s.ι).app r_j) },
{ simp only [ring_hom.map_neg], },
-- add
{ rw is_ring_hom.map_add ⇑((s.ι).app r_j) },
{ simp only [ring_hom.map_add], },
-- mul
{ rw is_ring_hom.map_mul ⇑((s.ι).app r_j) },
{ simp only [ring_hom.map_mul], },
-- neg_1
{ rw r_ih, },
-- add_1
Expand Down Expand Up @@ -384,23 +383,14 @@ def colimit_is_colimit : is_colimit (colimit_cocone F) :=
erw w',
refl, },
{ simp only [desc_morphism, quot_zero],
erw is_ring_hom.map_zero ⇑m,
erw m.map_zero, -- TODO why doesn't simp only [ring_hom.map_zero] work?
refl, },
{ simp only [desc_morphism, quot_one],
erw is_ring_hom.map_one ⇑m,
refl, },
{ simp only [desc_morphism, quot_neg],
erw is_ring_hom.map_neg ⇑m,
rw [x_ih],
refl, },
{ simp only [desc_morphism, quot_add],
erw is_ring_hom.map_add ⇑m,
rw [x_ih_a, x_ih_a_1],
refl, },
{ simp only [desc_morphism, quot_mul],
erw is_ring_hom.map_mul ⇑m,
rw [x_ih_a, x_ih_a_1],
erw m.map_one,
refl, },
{ simp only [desc_morphism, quot_neg, ring_hom.map_neg, x_ih], },
{ simp only [desc_morphism, quot_add, ring_hom.map_add, x_ih_a, x_ih_a_1], },
{ simp only [desc_morphism, quot_mul, ring_hom.map_mul, x_ih_a, x_ih_a_1], },
refl
end }.

Expand Down
21 changes: 13 additions & 8 deletions src/algebra/category/CommRing/limits.lean
Expand Up @@ -12,7 +12,7 @@ import algebra.pi_instances
/-!
# The category of commutative rings has all limits

Further, these limits are preserves by the forgetful functor --- that is,
Further, these limits are preserved by the forgetful functor --- that is,
the underlying types are just the limits in the category of types.

## Further work
Expand Down Expand Up @@ -71,10 +71,10 @@ instance sections_add_subgroup (F : J ⥤ CommRing.{u}) :
is_add_subgroup (F ⋙ forget CommRing).sections :=
{ neg_mem := λ a ah j j' f,
begin
erw [functor.comp_map, forget_map_eq_coe, (F.map f).map_neg],
dsimp,
dsimp [functor.sections] at ah,
rw ah f,
refl,
-- pi.neg_apply is hard to use as a `simp` lemma; you need to specify the arguments by hand
simp only [ring_hom.map_neg, pi.neg_apply a j, pi.neg_apply a j', neg_inj', ah],
end,
..(CommRing.sections_add_submonoid F) }

Expand All @@ -88,24 +88,26 @@ instance limit_comm_ring (F : J ⥤ CommRing.{u}) :
@subtype.comm_ring ((Π (j : J), (F ⋙ forget _).obj j)) (by apply_instance) _
(by convert (CommRing.sections_subring F))

instance limit_π_is_ring_hom (F : J ⥤ CommRing.{u}) (j) :
is_ring_hom (limit.π (F ⋙ forget CommRing) j) :=
instance limit_π_is_semiring_hom (F : J ⥤ CommRing.{u}) (j) :
is_semiring_hom (limit.π (F ⋙ forget CommRing) j) :=
{ map_one := by { simp only [types.types_limit_π], refl },
map_zero := by { simp only [types.types_limit_π], refl },
map_mul := λ x y, by { simp only [types.types_limit_π], refl },
map_add := λ x y, by { simp only [types.types_limit_π], refl } }

namespace CommRing_has_limits
-- The next two definitions are used in the construction of `has_limits CommRing`.
-- After that, the limits should be constructed using the generic limits API,
-- e.g. `limit F`, `limit.cone F`, and `limit.is_limit F`.

private def limit (F : J ⥤ CommRing.{u}) : cone F :=
def limit (F : J ⥤ CommRing.{u}) : cone F :=
{ X := ⟨limit (F ⋙ forget _), by apply_instance⟩,
π :=
{ app := λ j, ring_hom.of $ limit.π (F ⋙ forget _) j,
naturality' := λ j j' f,
ring_hom.ext ((limit.cone (F ⋙ forget _)).π.naturality f) } }

private def limit_is_limit (F : J ⥤ CommRing.{u}) : is_limit (limit F) :=
def limit_is_limit (F : J ⥤ CommRing.{u}) : is_limit (limit F) :=
begin
refine is_limit.of_faithful
(forget CommRing) (limit.is_limit _)
Expand All @@ -120,6 +122,9 @@ begin
erw (s.π.app j).map_add, refl }
end

end CommRing_has_limits
open CommRing_has_limits

/-- The category of commutative rings has all limits. -/
instance CommRing_has_limits : has_limits.{u} CommRing.{u} :=
{ has_limits_of_shape := λ J 𝒥,
Expand Down
33 changes: 13 additions & 20 deletions src/algebra/category/Group.lean
Expand Up @@ -24,52 +24,45 @@ open category_theory

/-- The category of groups and group morphisms. -/
@[reducible, to_additive AddGroup]
def Group : Type (u+1) := bundled group
def Group : Type (u+1) := induced_category Mon (bundled.map group.to_monoid.{u})

namespace Group

@[to_additive add_group]
instance (G : Group) : group G := G.str

/-- Construct a bundled Group from the underlying type and typeclass. -/
@[to_additive] def of (X : Type u) [group X] : Group := bundled.of X

@[to_additive]
instance bundled_hom : bundled_hom _ :=
Mon.bundled_hom.full_subcategory @group.to_monoid
@[to_additive add_group]
instance (G : Group) : group G := G.str

@[to_additive]
instance : has_one Group := ⟨Group.of punit⟩

@[to_additive has_forget_to_AddMon]
instance has_forget_to_Mon : has_forget₂ Group.{u} Mon.{u} :=
Mon.bundled_hom.full_subcategory_has_forget₂ _
-- These examples verify that we have successfully provided the expected instances.
example : concrete_category Group.{u} := infer_instance
example : has_forget₂ Group.{u} Mon.{u} := infer_instance

end Group


/-- The category of commutative groups and group morphisms. -/
@[reducible, to_additive AddCommGroup]
def CommGroup : Type (u+1) := bundled comm_group
def CommGroup : Type (u+1) := induced_category Group (bundled.map comm_group.to_group.{u})

namespace CommGroup

@[to_additive add_comm_group]
instance (G : CommGroup) : comm_group G := G.str

/-- Construct a bundled CommGroup from the underlying type and typeclass. -/
@[to_additive] def of (G : Type u) [comm_group G] : CommGroup := bundled.of G

@[to_additive] instance : bundled_hom _ :=
Group.bundled_hom.full_subcategory @comm_group.to_group
@[to_additive add_comm_group]
instance (G : CommGroup) : comm_group G := G.str

@[to_additive has_forget_to_AddGroup]
instance has_forget_to_Group : has_forget₂ CommGroup.{u} Group.{u} :=
Group.bundled_hom.full_subcategory_has_forget₂ _
-- These examples verify that we have successfully provided the expected instances.
example : concrete_category CommGroup.{u} := infer_instance
example : has_forget₂ CommGroup.{u} Group.{u} := infer_instance

@[to_additive has_forget_to_AddCommMon]
instance has_forget_to_CommMon : has_forget₂ CommGroup.{u} CommMon.{u} :=
CommMon.bundled_hom.full_subcategory_has_forget₂ comm_group.to_comm_monoid
induced_category.has_forget₂ (λ G : CommGroup, CommMon.of G)

@[to_additive] instance : has_one CommGroup := ⟨CommGroup.of punit⟩

Expand Down