Skip to content

Commit 75066fe

Browse files
authored
Merge pull request #1953 from Alizter/monoids
monoids and comonoids in a monoidal category
2 parents 1a1edfa + 2301b2e commit 75066fe

File tree

7 files changed

+504
-65
lines changed

7 files changed

+504
-65
lines changed
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
Require Import Basics.Overture Basics.Tactics.
2+
Require Import WildCat.Core WildCat.Equiv WildCat.Monoidal WildCat.Bifunctor
3+
WildCat.NatTrans WildCat.Opposite WildCat.Products.
4+
Require Import abstract_algebra.
5+
6+
(** * Monoids and Comonoids *)
7+
8+
(** Here we define a monoid internal to a monoidal category. Note that we don't actually need the full monoidal structure so we assume only the parts we need. This allows us to keep the definitions general between various flavours of monoidal category.
9+
10+
Many algebraic theories such as groups and rings may also be internalized, however these specifically require a cartesian monoidal structure. The theory of monoids however has no such requirement and can therefore be developed in much greater generality. This can be used to define a range of objects such as R-algebras, H-spaces, Hopf algebras and more. *)
11+
12+
(** * Monoid objects *)
13+
14+
Section MonoidObject.
15+
Context {A : Type} {tensor : A -> A -> A} {unit : A}
16+
`{HasEquivs A, !Is0Bifunctor tensor, !Is1Bifunctor tensor}
17+
`{!Associator tensor, !LeftUnitor tensor unit, !RightUnitor tensor unit}.
18+
19+
(** An object [x] of [A] is a monoid object if it comes with the following data: *)
20+
Class IsMonoidObject (x : A) := {
21+
(** A multiplication map from the tensor product of [x] with itself to [x]. *)
22+
mo_mult : tensor x x $-> x;
23+
(** A unit of the multplication. *)
24+
mo_unit : unit $-> x;
25+
(** The multiplication map is associative. *)
26+
mo_assoc : mo_mult $o fmap10 tensor mo_mult x $o associator x x x
27+
$== mo_mult $o fmap01 tensor x mo_mult;
28+
(** The multiplication map is left unital. *)
29+
mo_left_unit : mo_mult $o fmap10 tensor mo_unit x $== left_unitor x;
30+
(** The multiplication map is right unital. *)
31+
mo_right_unit : mo_mult $o fmap01 tensor x mo_unit $== right_unitor x;
32+
}.
33+
34+
Context `{!Braiding tensor}.
35+
36+
(** An object [x] of [A] is a commutative monoid object if: *)
37+
Class IsCommutativeMonoidObject (x : A) := {
38+
(** It is a monoid object. *)
39+
cmo_mo :: IsMonoidObject x;
40+
(** The multiplication map is commutative. *)
41+
cmo_comm : mo_mult $o braid x x $== mo_mult;
42+
}.
43+
44+
End MonoidObject.
45+
46+
Arguments IsMonoidObject {A} tensor unit {_ _ _ _ _ _ _ _ _ _} x.
47+
Arguments IsCommutativeMonoidObject {A} tensor unit {_ _ _ _ _ _ _ _ _ _ _} x.
48+
49+
Section ComonoidObject.
50+
Context {A : Type} (tensor : A -> A -> A) (unit : A)
51+
`{HasEquivs A, !Is0Bifunctor tensor, !Is1Bifunctor tensor}
52+
`{!Associator tensor, !LeftUnitor tensor unit, !RightUnitor tensor unit}.
53+
54+
(** A comonoid object is a monoid object in the opposite category. *)
55+
Class IsComonoidObject (x : A)
56+
:= ismonoid_comonoid_op :: IsMonoidObject (A:=A^op) tensor unit x.
57+
58+
(** We can build comonoid objects from the following data: *)
59+
Definition Build_IsComonoidObject (x : A)
60+
(** A comultplication map. *)
61+
(co_comult : x $-> tensor x x)
62+
(** A counit. *)
63+
(co_counit : x $-> unit)
64+
(** The comultiplication is coassociative. *)
65+
(co_coassoc : associator x x x $o fmap01 tensor x co_comult $o co_comult
66+
$== fmap10 tensor co_comult x $o co_comult)
67+
(** The comultiplication is left counital. *)
68+
(co_left_counit : left_unitor x $o fmap10 tensor co_counit x $o co_comult $== Id x)
69+
(** The comultiplication is right counital. *)
70+
(co_right_counit : right_unitor x $o fmap01 tensor x co_counit $o co_comult $== Id x)
71+
: IsComonoidObject x.
72+
Proof.
73+
snrapply Build_IsMonoidObject.
74+
- exact co_comult.
75+
- exact co_counit.
76+
- nrapply cate_moveR_eV.
77+
symmetry.
78+
nrefine (cat_assoc _ _ _ $@ _).
79+
rapply co_coassoc.
80+
- simpl; nrefine (_ $@ cat_idr _).
81+
nrapply cate_moveL_Ve.
82+
nrefine (cat_assoc_opp _ _ _ $@ _).
83+
exact co_left_counit.
84+
- simpl; nrefine (_ $@ cat_idr _).
85+
nrapply cate_moveL_Ve.
86+
nrefine (cat_assoc_opp _ _ _ $@ _).
87+
exact co_right_counit.
88+
Defined.
89+
90+
(** Comultiplication *)
91+
Definition co_comult {x : A} `{!IsComonoidObject x} : x $-> tensor x x
92+
:= mo_mult (A:=A^op) (tensor:=tensor) (unit:=unit) (x:=x).
93+
94+
(** Counit *)
95+
Definition co_counit {x : A} `{!IsComonoidObject x} : x $-> unit
96+
:= mo_unit (A:=A^op) (tensor:=tensor) (unit:=unit) (x:=x).
97+
98+
Context `{!Braiding tensor}.
99+
100+
(** A cocommutative comonoid objects is a commutative monoid object in the opposite category. *)
101+
Class IsCocommutativeComonoidObject (x : A)
102+
:= iscommuatativemonoid_cocomutativemonoid_op
103+
:: IsCommutativeMonoidObject (A:=A^op) tensor unit x.
104+
105+
(** We can build cocommutative comonoid objects from the following data: *)
106+
Definition Build_IsCocommutativeComonoidObject (x : A)
107+
(** A comonoid. *)
108+
`{!IsComonoidObject x}
109+
(** Together with a proof of cocommutativity. *)
110+
(cco_cocomm : braid x x $o co_comult $== co_comult)
111+
: IsCocommutativeComonoidObject x.
112+
Proof.
113+
snrapply Build_IsCommutativeMonoidObject.
114+
- exact _.
115+
- exact cco_cocomm.
116+
Defined.
117+
118+
End ComonoidObject.
119+
120+
(** ** Monoid enrichment *)
121+
122+
(** A hom [x $-> y] in a cartesian category where [y] is a monoid object has the structure of a monoid. Equivalently, a hom [x $-> y] in a cartesian category where [x] is a comonoid object has the structure of a monoid. *)
123+
124+
Section MonoidEnriched.
125+
Context {A : Type} `{HasEquivs A} `{!HasBinaryProducts A}
126+
(unit : A) `{!IsTerminal unit} {x y : A}
127+
`{!HasMorExt A} `{forall x y, IsHSet (x $-> y)}.
128+
129+
Section Monoid.
130+
Context `{!IsMonoidObject _ _ y}.
131+
132+
Local Instance sgop_hom : SgOp (x $-> y)
133+
:= fun f g => mo_mult $o cat_binprod_corec f g.
134+
135+
Local Instance monunit_hom : MonUnit (x $-> y) := mo_unit $o mor_terminal _ _.
136+
137+
Local Instance associative_hom : Associative sgop_hom.
138+
Proof.
139+
intros f g h.
140+
unfold sgop_hom.
141+
rapply path_hom.
142+
refine ((_ $@L cat_binprod_fmap01_corec _ _ _)^$ $@ _).
143+
nrefine (cat_assoc_opp _ _ _ $@ _).
144+
refine ((mo_assoc $@R _)^$ $@ _).
145+
nrefine (_ $@ (_ $@L cat_binprod_fmap10_corec _ _ _)).
146+
refine (cat_assoc _ _ _ $@ (_ $@L _) $@ cat_assoc _ _ _).
147+
nrapply cat_binprod_associator_corec.
148+
Defined.
149+
150+
Local Instance leftidentity_hom : LeftIdentity sgop_hom mon_unit.
151+
Proof.
152+
intros f.
153+
unfold sgop_hom, mon_unit.
154+
rapply path_hom.
155+
refine ((_ $@L (cat_binprod_fmap10_corec _ _ _)^$) $@ cat_assoc_opp _ _ _ $@ _).
156+
nrefine (((mo_left_unit $@ _) $@R _) $@ _).
157+
1: nrapply cate_buildequiv_fun.
158+
unfold trans_nattrans.
159+
nrefine ((((_ $@R _) $@ _) $@R _) $@ _).
160+
1: nrapply cate_buildequiv_fun.
161+
1: nrapply cat_binprod_beta_pr1.
162+
nrapply cat_binprod_beta_pr2.
163+
Defined.
164+
165+
Local Instance rightidentity_hom : RightIdentity sgop_hom mon_unit.
166+
Proof.
167+
intros f.
168+
unfold sgop_hom, mon_unit.
169+
rapply path_hom.
170+
refine ((_ $@L (cat_binprod_fmap01_corec _ _ _)^$) $@ cat_assoc_opp _ _ _ $@ _).
171+
nrefine (((mo_right_unit $@ _) $@R _) $@ _).
172+
1: nrapply cate_buildequiv_fun.
173+
nrapply cat_binprod_beta_pr1.
174+
Defined.
175+
176+
Local Instance issemigroup_hom : IsSemiGroup (x $-> y) := {}.
177+
Local Instance ismonoid_hom : IsMonoid (x $-> y) := {}.
178+
179+
End Monoid.
180+
181+
Context `{!IsCommutativeMonoidObject _ _ y}.
182+
Local Existing Instances sgop_hom monunit_hom ismonoid_hom.
183+
184+
Local Instance commutative_hom : Commutative sgop_hom.
185+
Proof.
186+
intros f g.
187+
unfold sgop_hom.
188+
rapply path_hom.
189+
refine ((_ $@L _^$) $@ cat_assoc_opp _ _ _ $@ (cmo_comm $@R _)).
190+
nrapply cat_binprod_swap_corec.
191+
Defined.
192+
193+
Local Instance iscommutativemonoid_hom : IsCommutativeMonoid (x $-> y) := {}.
194+
195+
End MonoidEnriched.
196+
197+
198+
199+

theories/WildCat/Adjoint.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ Proof.
388388
snrapply Build_Adjunction_natequiv_nat_right.
389389
{ intros y.
390390
refine (natequiv_compose (natequiv_adjunction_l adj _) _).
391-
rapply (natequiv_postwhisker _ (natequiv_op _ _ e)). }
391+
rapply (natequiv_postwhisker _ (natequiv_op e)). }
392392
intros x.
393393
rapply is1natural_comp.
394394
Defined.

theories/WildCat/Bifunctor.v

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Require Import Basics.Overture Basics.Tactics.
22
Require Import Types.Forall Types.Prod.
3-
Require Import WildCat.Core WildCat.Prod WildCat.Equiv WildCat.NatTrans WildCat.Square.
3+
Require Import WildCat.Core WildCat.Prod WildCat.Equiv WildCat.NatTrans
4+
WildCat.Square WildCat.Opposite.
45

56
(** * Bifunctors between WildCats *)
67

@@ -14,6 +15,11 @@ Class Is0Bifunctor {A B C : Type}
1415
is0functor10_bifunctor :: forall b, Is0Functor (flip F b);
1516
}.
1617

18+
Arguments Is0Bifunctor {A B C _ _ _} F.
19+
Arguments is0functor_bifunctor_uncurried {A B C _ _ _} F {_}.
20+
Arguments is0functor01_bifunctor {A B C _ _ _} F {_} a : rename.
21+
Arguments is0functor10_bifunctor {A B C _ _ _} F {_} b : rename.
22+
1723
(** We provide two alternate constructors, allowing the user to provide just the first field or the last two fields. *)
1824
Definition Build_Is0Bifunctor' {A B C : Type}
1925
`{Is01Cat A, Is01Cat B, IsGraph C} (F : A -> B -> C)
@@ -32,7 +38,7 @@ Definition Build_Is0Bifunctor'' {A B C : Type}
3238
: Is0Bifunctor F.
3339
Proof.
3440
(* The first condition follows from [is0functor_prod_is0functor]. *)
35-
rapply Build_Is0Bifunctor.
41+
nrapply Build_Is0Bifunctor; exact _.
3642
Defined.
3743

3844
(** *** 1-functorial action *)
@@ -72,6 +78,9 @@ Class Is1Bifunctor {A B C : Type}
7278

7379
Arguments Is1Bifunctor {A B C _ _ _ _ _ _ _ _ _ _ _ _} F {Is0Bifunctor} : rename.
7480
Arguments Build_Is1Bifunctor {A B C _ _ _ _ _ _ _ _ _ _ _ _} F {_} _ _ _ _ _.
81+
Arguments is1functor_bifunctor_uncurried {A B C _ _ _ _ _ _ _ _ _ _ _ _} F {_ _}.
82+
Arguments is1functor01_bifunctor {A B C _ _ _ _ _ _ _ _ _ _ _ _} F {_ _} a : rename.
83+
Arguments is1functor10_bifunctor {A B C _ _ _ _ _ _ _ _ _ _ _ _} F {_ _} b : rename.
7584
Arguments fmap11_is_fmap01_fmap10 {A B C _ _ _ _ _ _ _ _ _ _ _ _} F
7685
{Is0Bifunctor Is1Bifunctor} {a0 a1} f {b0 b1} g : rename.
7786
Arguments fmap11_is_fmap10_fmap01 {A B C _ _ _ _ _ _ _ _ _ _ _ _} F
@@ -285,14 +294,14 @@ Global Instance is0bifunctor_postcompose {A B C D : Type}
285294
`{IsGraph A, IsGraph B, IsGraph C, IsGraph D}
286295
(F : A -> B -> C) {bf : Is0Bifunctor F}
287296
(G : C -> D) `{!Is0Functor G}
288-
: Is0Bifunctor (fun a b => G (F a b))
297+
: Is0Bifunctor (fun a b => G (F a b)) | 10
289298
:= {}.
290299

291300
Global Instance is1bifunctor_postcompose {A B C D : Type}
292301
`{Is1Cat A, Is1Cat B, Is1Cat C, Is1Cat D}
293302
(F : A -> B -> C) (G : C -> D) `{!Is0Functor G, !Is1Functor G}
294303
`{!Is0Bifunctor F} {bf : Is1Bifunctor F}
295-
: Is1Bifunctor (fun a b => G (F a b)).
304+
: Is1Bifunctor (fun a b => G (F a b)) | 10.
296305
Proof.
297306
snrapply Build_Is1Bifunctor.
298307
1-3: exact _.
@@ -306,7 +315,7 @@ Global Instance is0bifunctor_precompose {A B C D E : Type}
306315
`{IsGraph A, IsGraph B, IsGraph C, IsGraph D, IsGraph E}
307316
(G : A -> B) (K : E -> C) (F : B -> C -> D)
308317
`{!Is0Functor G, !Is0Bifunctor F, !Is0Functor K}
309-
: Is0Bifunctor (fun a b => F (G a) (K b)).
318+
: Is0Bifunctor (fun a b => F (G a) (K b)) | 10.
310319
Proof.
311320
snrapply Build_Is0Bifunctor.
312321
- change (Is0Functor (uncurry F o functor_prod G K)).
@@ -322,7 +331,7 @@ Global Instance is1bifunctor_precompose {A B C D E : Type}
322331
(G : A -> B) (K : E -> C) (F : B -> C -> D)
323332
`{!Is0Functor G, !Is1Functor G, !Is0Bifunctor F, !Is1Bifunctor F,
324333
!Is0Functor K, !Is1Functor K}
325-
: Is1Bifunctor (fun a b => F (G a) (K b)).
334+
: Is1Bifunctor (fun a b => F (G a) (K b)) | 10.
326335
Proof.
327336
snrapply Build_Is1Bifunctor.
328337
- change (Is1Functor (uncurry F o functor_prod G K)).
@@ -372,10 +381,8 @@ Definition fmap11_square {A B C : Type} `{Is1Cat A, Is1Cat B, Is1Cat C}
372381
(** We can show that an uncurried natural transformation between uncurried bifunctors by composing the naturality square in each variable. *)
373382
Global Instance is1natural_uncurry {A B C : Type}
374383
`{Is1Cat A, Is1Cat B, Is1Cat C}
375-
(F : A -> B -> C)
376-
`{!Is0Bifunctor F, !Is1Bifunctor F}
377-
(G : A -> B -> C)
378-
`{!Is0Bifunctor G, !Is1Bifunctor G}
384+
(F : A -> B -> C) `{!Is0Bifunctor F, !Is1Bifunctor F}
385+
(G : A -> B -> C) `{!Is0Bifunctor G, !Is1Bifunctor G}
379386
(alpha : uncurry F $=> uncurry G)
380387
(nat_l : forall b, Is1Natural (flip F b) (flip G b) (fun x : A => alpha (x, b)))
381388
(nat_r : forall a, Is1Natural (F a) (G a) (fun y : B => alpha (a, y)))
@@ -389,3 +396,63 @@ Proof.
389396
2: rapply (fmap11_is_fmap01_fmap10 G).
390397
exact (hconcat (nat_l _ _ _ f) (nat_r _ _ _ f')).
391398
Defined.
399+
400+
(** Flipping a natural transformation between bifunctors. *)
401+
Definition nattrans_flip {A B C : Type}
402+
`{Is1Cat A, Is1Cat B, Is1Cat C}
403+
{F : A -> B -> C} `{!Is0Bifunctor F, !Is1Bifunctor F}
404+
{G : A -> B -> C} `{!Is0Bifunctor G, !Is1Bifunctor G}
405+
: NatTrans (uncurry F) (uncurry G)
406+
-> NatTrans (uncurry (flip F)) (uncurry (flip G)).
407+
Proof.
408+
intros [alpha nat].
409+
snrapply Build_NatTrans.
410+
- exact (alpha o equiv_prod_symm _ _).
411+
- intros [b a] [b' a'] [g f].
412+
exact (nat (a, b) (a', b') (f, g)).
413+
Defined.
414+
415+
(** ** Opposite Bifunctors *)
416+
417+
(** There are a few more combinations we can do for this, such as profunctors, but we will leave those for later. *)
418+
419+
Global Instance is0bifunctor_op A B C (F : A -> B -> C) `{Is0Bifunctor A B C F}
420+
: Is0Bifunctor (F : A^op -> B^op -> C^op).
421+
Proof.
422+
snrapply Build_Is0Bifunctor.
423+
- exact (is0functor_op _ _ (uncurry F)).
424+
- intros a.
425+
nrapply is0functor_op.
426+
exact (is0functor01_bifunctor F a).
427+
- intros b.
428+
nrapply is0functor_op.
429+
exact (is0functor10_bifunctor F b).
430+
Defined.
431+
432+
Global Instance is1bifunctor_op A B C (F : A -> B -> C) `{Is1Bifunctor A B C F}
433+
: Is1Bifunctor (F : A^op -> B^op -> C^op).
434+
Proof.
435+
snrapply Build_Is1Bifunctor.
436+
- exact (is1functor_op _ _ (uncurry F)).
437+
- intros a.
438+
nrapply is1functor_op.
439+
exact (is1functor01_bifunctor F a).
440+
- intros b.
441+
nrapply is1functor_op.
442+
exact (is1functor10_bifunctor F b).
443+
- intros a0 a1 f b0 b1 g; cbn in f, g.
444+
exact (fmap11_is_fmap10_fmap01 F f g).
445+
- intros a0 a1 f b0 b1 g; cbn in f, g.
446+
exact (fmap11_is_fmap01_fmap10 F f g).
447+
Defined.
448+
449+
Global Instance is0bifunctor_op' A B C (F : A^op -> B^op -> C^op)
450+
`{IsGraph A, IsGraph B, IsGraph C, Fop : !Is0Bifunctor (F : A^op -> B^op -> C^op)}
451+
: Is0Bifunctor (F : A -> B -> C)
452+
:= is0bifunctor_op A^op B^op C^op F.
453+
454+
Global Instance is1bifunctor_op' A B C (F : A^op -> B^op -> C^op)
455+
`{Is1Cat A, Is1Cat B, Is1Cat C,
456+
!Is0Bifunctor (F : A^op -> B^op -> C^op), !Is1Bifunctor (F : A^op -> B^op -> C^op)}
457+
: Is1Bifunctor (F : A -> B -> C)
458+
:= is1bifunctor_op A^op B^op C^op F.

theories/WildCat/Equiv.v

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,13 @@ Proof.
413413
apply cate_inv_adjointify.
414414
Defined.
415415

416+
Definition cate_inv_compose' {A} `{HasEquivs A} {a b c : A} (e : a $<~> b) (f : b $<~> c)
417+
: cate_fun (f $oE e)^-1$ $== e^-1$ $o f^-1$.
418+
Proof.
419+
nrefine (_ $@ cate_buildequiv_fun _).
420+
nrapply cate_inv_compose.
421+
Defined.
422+
416423
Definition cate_inv_V {A} `{HasEquivs A} {a b : A} (e : a $<~> b)
417424
: cate_fun (e^-1$)^-1$ $== cate_fun e.
418425
Proof.

0 commit comments

Comments
 (0)