Skip to content

Commit 43cb7ab

Browse files
AbEnriched: wild categories enriched in abelian groups
Co-authored-by: Thomas Wilskow Thorbjørnsen <[email protected]>
1 parent ea71c02 commit 43cb7ab

File tree

3 files changed

+388
-0
lines changed

3 files changed

+388
-0
lines changed

test/WildCat/AbEnriched.v

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
From HoTT Require Import WildCat.SetoidRewrite WildCat.Core WildCat.AbEnriched.
2+
From HoTT Require Import Basics.Overture.
3+
4+
Local Open Scope mc_add_scope.
5+
6+
(** Test that setoid rewriting works with the additive structure. *)
7+
8+
Definition test1 (A : Type) `{IsAbGroup_0gpd A}
9+
{a b c d : A} (p : b $== c) (q : c $== d)
10+
: b + a $== d + a.
11+
Proof.
12+
rewrite p.
13+
rewrite <- q.
14+
reflexivity.
15+
Defined.
16+
17+
Definition test2 (A : Type) `{IsAbGroup_0gpd A}
18+
{a b c d : A} (p : b $== c) (q : c $== d)
19+
: a + b $== a + d.
20+
Proof.
21+
rewrite p.
22+
rewrite <- q.
23+
reflexivity.
24+
Defined.
25+
26+
Definition test3 (A : Type) `{IsAbGroup_0gpd A}
27+
{a b c d : A} (p : a $== c) (q : b $== d)
28+
: a - b $== c - d.
29+
Proof.
30+
rewrite p.
31+
rewrite <- q.
32+
reflexivity.
33+
Defined.
34+
35+
Definition test4 (A : Type) `{IsAbGroup_0gpd A}
36+
{a b : A} (p : a $== b)
37+
: - a $== - b.
38+
Proof.
39+
rewrite p.
40+
reflexivity.
41+
Defined.
42+
43+

theories/WildCat.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Require Export WildCat.Coproducts.
1818
Require Export WildCat.Displayed.
1919
Require Export WildCat.DisplayedEquiv.
2020
Require Export WildCat.Pullbacks.
21+
Require Export WildCat.AbEnriched.
2122

2223
Require Export WildCat.SetoidRewrite.
2324

theories/WildCat/AbEnriched.v

Lines changed: 344 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,344 @@
1+
Require Import WildCat.SetoidRewrite.
2+
Import CMorphisms.ProperNotations.
3+
4+
Require Import Basics.Overture Basics.Tactics.
5+
Require Import WildCat.Core WildCat.FunctorCat WildCat.ZeroGroupoid WildCat.Yoneda WildCat.UnitCat WildCat.Equiv WildCat.Products WildCat.Prod WildCat.Bifunctor WildCat.Monoidal.
6+
7+
(** See Groups/Group.v and AbGroups/AbelianGroup.v for additional things that it might be useful to export in the future. *)
8+
Require Export Classes.interfaces.canonical_names (SgOp, sg_op,
9+
MonUnit, mon_unit, Inverse, inv).
10+
Export canonical_names.BinOpNotations.
11+
12+
(** * Wild categories enriched in abelian groups *)
13+
14+
(** ** 0-groupoid abelian groups *)
15+
16+
(** Hom sets in wild categories are 0-groupoids, and we'd like to put an abelian group structure on these hom sets that satisfies the axioms up to 1-cells, to avoid needing function extensionality. So we define the abstract idea of a 0-groupoid with an abelian group structure. Because we use 1-cells, not paths, we can't reuse any of the work done in Algebra/Groups or Algebra/AbGroups. *)
17+
18+
Local Open Scope mc_add_scope.
19+
20+
Class IsAbGroup_0gpd (A : Type) `{Is0Gpd A} := {
21+
(* Data: *)
22+
sgop_0gpd :: SgOp A;
23+
mon_unit_0gpd :: MonUnit A;
24+
inverse_0gpd :: Inverse A;
25+
26+
(* 0-functoriality: *)
27+
is0bifunctor_sgop_0gpd :: Is0Bifunctor sgop_0gpd;
28+
is0functor_inverse_0gpd :: Is0Functor inverse_0gpd;
29+
30+
(* Axioms (with some redundancy): *)
31+
assoc_0gpd : forall a b c, (a + b) + c $== a + (b + c);
32+
mon_unit_l_0gpd : forall a, 0 + a $== a;
33+
mon_unit_r_0gpd : forall a, a + 0 $== a;
34+
inverse_l_0gpd : forall a, (-a) + a $== 0;
35+
inverse_r_0gpd : forall a, a - a $== 0;
36+
comm_0gpd : forall a b, a + b $== b + a;
37+
}.
38+
39+
(** ** Setoid rewriting *)
40+
41+
(** [forall x y : A, x $== y -> forall x' y' : A, x' $== y' -> x + x' $== y + y']. *)
42+
Instance IsProper_sgop_0gpd (A : Type) `{IsAbGroup_0gpd A}
43+
: CMorphisms.Proper (GpdHom ==> GpdHom ==> GpdHom) (sg_op (A:=A))
44+
:= @fmap11 _ _ _ _ _ _ sg_op _.
45+
46+
(** [forall a x y : A, x $== y -> a + x $== a + y]. This is needed to rewrite on the RHS of a sum. LHS is handled by the two-argument version, but this isn't. *)
47+
Instance IsProper_sgop_0gpd1 (A : Type) `{IsAbGroup_0gpd A} {a : A}
48+
: CMorphisms.Proper (GpdHom ==> GpdHom) (sg_op (A:=A) a)
49+
:= @fmap01 _ _ _ _ _ _ sg_op _ a.
50+
51+
Instance IsProper_inverse_0gpd (A : Type) `{IsAbGroup_0gpd A}
52+
: CMorphisms.Proper (GpdHom ==> GpdHom) (inv (A:=A))
53+
:= @fmap _ _ _ _ inv _.
54+
55+
(** ** A few lemmas about 0-groupoid abelian groups *)
56+
57+
(** We will try to parallel the naming in Group.v, when applicable. *)
58+
59+
Section Lemmas.
60+
61+
Context {A : Type} `{IsAbGroup_0gpd A}.
62+
Context (x y : A).
63+
64+
Definition inv_V_gg_0gpd : (-x) + (x + y) $== y
65+
:= (assoc_0gpd _ _ _)^$ $@ fmap10 sg_op (inverse_l_0gpd x) y $@ mon_unit_l_0gpd _.
66+
67+
Definition inv_g_Vg_0gpd : x + (-x + y) $== y
68+
:= (assoc_0gpd _ _ _)^$ $@ fmap10 sg_op (inverse_r_0gpd x) y $@ mon_unit_l_0gpd _.
69+
70+
Definition inv_gg_V_0gpd : (x + y) - y $== x
71+
:= assoc_0gpd _ _ _ $@ fmap01 sg_op x (inverse_r_0gpd y) $@ mon_unit_r_0gpd _.
72+
73+
Definition inv_gV_g_0gpd : (x - y) + y $== x
74+
:= assoc_0gpd _ _ _ $@ fmap01 sg_op x (inverse_l_0gpd y) $@ mon_unit_r_0gpd _.
75+
76+
Definition inv_inv_0gpd : - (-x) $== x.
77+
Proof.
78+
rhs_V' rapply mon_unit_l_0gpd.
79+
rewrite <- (inverse_l_0gpd (-x)).
80+
rhs' napply assoc_0gpd.
81+
rewrite inverse_l_0gpd.
82+
symmetry; apply mon_unit_r_0gpd.
83+
Defined.
84+
85+
End Lemmas.
86+
87+
(** ** We express the operations as maps of 0-groupoids *)
88+
89+
Definition zerogpd_0gpd (A : Type) `{IsAbGroup_0gpd A} : ZeroGpd
90+
:= Build_ZeroGpd _ _ _ _.
91+
92+
Definition left_op_0gpd {A : Type} `{IsAbGroup_0gpd A} (a : A)
93+
: zerogpd_0gpd A $-> zerogpd_0gpd A
94+
:= Build_Fun01' (fun b : A => a + b) (fun _ _ => fmap01 sg_op a).
95+
96+
Definition right_op_0gpd {A : Type} `{IsAbGroup_0gpd A} (a : A)
97+
: zerogpd_0gpd A $-> zerogpd_0gpd A
98+
:= Build_Fun01' (fun b : A => b + a) (fun b b' p => fmap10 sg_op p a).
99+
100+
Definition inv_0gpd {A : Type} `{IsAbGroup_0gpd A}
101+
: zerogpd_0gpd A $-> zerogpd_0gpd A
102+
:= Build_Fun01 inverse_0gpd.
103+
104+
(** ** The operations are equivalences *)
105+
106+
(** Addition on the left is biinvertible. *)
107+
Instance cat_isbiinv_left_op_0gpd {A : Type} `{IsAbGroup_0gpd A} (a : A)
108+
: Cat_IsBiInv (left_op_0gpd a).
109+
Proof.
110+
snapply Build_Cat_IsBiInv.
111+
1,3: exact (left_op_0gpd (-a)).
112+
all: intro b; simpl.
113+
- apply inv_g_Vg_0gpd.
114+
- apply inv_V_gg_0gpd.
115+
Defined.
116+
117+
Definition left_op_0gpd' {A : Type} `{IsAbGroup_0gpd A} (a : A)
118+
:= Build_Cat_BiInv _ _ _ _ _ _ _ (left_op_0gpd a) _.
119+
120+
(** Addition on the right is biinvertible. *)
121+
Instance cat_isbiinv_right_op_0gpd {A : Type} `{IsAbGroup_0gpd A} (a : A)
122+
: Cat_IsBiInv (right_op_0gpd a).
123+
Proof.
124+
snapply Build_Cat_IsBiInv.
125+
1,3: exact (right_op_0gpd (-a)).
126+
all: intro b; simpl.
127+
- apply inv_gV_g_0gpd.
128+
- apply inv_gg_V_0gpd.
129+
Defined.
130+
131+
Definition right_op_0gpd' {A : Type} `{IsAbGroup_0gpd A} (a : A)
132+
:= Build_Cat_BiInv _ _ _ _ _ _ _ (right_op_0gpd a) _.
133+
134+
(** Inversion is biinvertible. *)
135+
Instance cat_isbiinv_inverse_0gpd {A : Type} `{IsAbGroup_0gpd A}
136+
: Cat_IsBiInv (inv_0gpd (A:=A)).
137+
Proof.
138+
snapply Build_Cat_IsBiInv.
139+
1,3: exact inv_0gpd.
140+
all: intro b; simpl.
141+
all: apply inv_inv_0gpd.
142+
Defined.
143+
144+
Definition inv_0gpd' {A : Type} `{IsAbGroup_0gpd A}
145+
:= Build_Cat_BiInv _ _ _ _ _ _ _ (inv_0gpd (A:=A)) _.
146+
147+
(** ** General properties of a 0-groupoid abelian group *)
148+
149+
(** None of these use commutativity. *)
150+
151+
Section GroupProperties.
152+
153+
Context {A : Type} `{IsAbGroup_0gpd A}.
154+
155+
Definition cancelL_0gpd (a b c : A) (p : a + b $== a + c)
156+
: b $== c
157+
:= isinj_equiv_0gpd (left_op_0gpd' a) p.
158+
159+
Definition cancelR_0gpd (a b c : A) (p : b + a $== c + a)
160+
: b $== c
161+
:= isinj_equiv_0gpd (right_op_0gpd' a) p.
162+
163+
Definition inv_unit_0gpd : -0 $== 0
164+
:= (mon_unit_l_0gpd (-0))^$ $@ inverse_r_0gpd 0.
165+
166+
Definition moveL_gM_0gpd {a b c : A} (p : a - c $== b)
167+
: a $== b + c
168+
:= moveL_equiv_M_0gpd (right_op_0gpd' c) p.
169+
170+
Definition moveL_Mg_0gpd {a b c : A} (p : - b + a $== c)
171+
: a $== b + c
172+
:= moveL_equiv_M_0gpd (left_op_0gpd' b) p.
173+
174+
Definition moveR_gM_0gpd {a b c : A} (p : a $== c - b)
175+
: a + b $== c
176+
:= moveR_equiv_M_0gpd (right_op_0gpd' b) p.
177+
178+
Definition moveR_Mg_0gpd {a b c : A} (p : b $== - a + c)
179+
: a + b $== c
180+
:= moveR_equiv_M_0gpd (left_op_0gpd' a) p.
181+
182+
(** The next four are the inverses of the previous four. *)
183+
Definition moveR_gV_0gpd {a b c : A} (p : a $== c + b)
184+
: a - b $== c
185+
:= moveR_equiv_V_0gpd (right_op_0gpd' b) p.
186+
187+
Definition moveR_Vg_0gpd {a b c : A} (p : b $== a + c)
188+
: -a + b $== c
189+
:= moveR_equiv_V_0gpd (left_op_0gpd' a) p.
190+
191+
Definition moveL_gV_0gpd {a b c : A} (p : a + c $== b)
192+
: a $== b - c
193+
:= moveL_equiv_V_0gpd (right_op_0gpd' c) p.
194+
195+
Definition moveL_Vg_0gpd {a b c : A} (p : b + a $== c)
196+
: a $== -b + c
197+
:= moveL_equiv_V_0gpd (left_op_0gpd' b) p.
198+
199+
(** Versions of the above involving the unit. *)
200+
Definition moveL_0M_0gpd {a b : A} (p : a - b $== 0) : a $== b
201+
:= moveL_gM_0gpd p $@ mon_unit_l_0gpd _.
202+
203+
Definition moveL_M0_0gpd {a b : A} (p : -b + a $== 0) : a $== b
204+
:= moveL_Mg_0gpd p $@ mon_unit_r_0gpd _.
205+
206+
Definition moveL_0V_0gpd {a b : A} (p : a + b $== 0) : a $== -b
207+
:= moveL_gV_0gpd p $@ mon_unit_l_0gpd _.
208+
209+
Definition moveL_V0_0gpd {a b : A} (p : b + a $== 0) : a $== -b
210+
:= moveL_Vg_0gpd p $@ mon_unit_r_0gpd _.
211+
212+
Definition moveR_0M_0gpd {a b : A} (p : 0 $== b - a) : a $== b
213+
:= (mon_unit_l_0gpd _)^$ $@ moveR_gM_0gpd p.
214+
215+
Definition moveR_M0_0gpd {a b : A} (p : 0 $== -a + b) : a $== b
216+
:= (mon_unit_r_0gpd _)^$ $@ moveR_Mg_0gpd p.
217+
218+
Definition moveR_0V_0gpd {a b : A} (p : 0 $== b + a) : -a $== b
219+
:= (mon_unit_l_0gpd _)^$ $@ moveR_gV_0gpd p.
220+
221+
Definition moveR_V0_0gpd {a b : A} (p : 0 $== a + b) : -a $== b
222+
:= (mon_unit_r_0gpd _)^$ $@ moveR_Vg_0gpd p.
223+
224+
(** Equal things have zero difference. *)
225+
Definition inverse_r_homotopy_0gpd {a b : A} (p : a $== b)
226+
: a - b $== 0.
227+
Proof.
228+
rewrite p; apply inverse_r_0gpd.
229+
Defined.
230+
231+
Definition inverse_l_homotopy_0gpd {a b : A} (p : a $== b)
232+
: -a + b $== 0.
233+
Proof.
234+
rewrite p; apply inverse_l_0gpd.
235+
Defined.
236+
237+
(** Adding the inverse of the unit. *)
238+
Definition mon_unit_l_inv_0gpd {a : A} : a - 0 $== a.
239+
Proof.
240+
apply moveR_gV_0gpd.
241+
symmetry; apply mon_unit_r_0gpd.
242+
Defined.
243+
244+
Definition mon_unit_r_inv_0gpd {a : A} : -0 + a $== a.
245+
Proof.
246+
apply moveR_Vg_0gpd.
247+
symmetry; apply mon_unit_l_0gpd.
248+
Defined.
249+
250+
End GroupProperties.
251+
252+
(** ** Homomorphisms between 0-groupoid abelian groups *)
253+
254+
Section Homomorphism.
255+
256+
Context {A B : Type} `{IsAbGroup_0gpd A} `{IsAbGroup_0gpd B}.
257+
258+
(** A homomorphism is a 0-functor that respects the operation up to 1-cells. *)
259+
Class IsGroupHom_0gpd (f : A -> B) `{!Is0Functor f} :=
260+
grp_homo_op_0gpd : forall (a a' : A), f (a + a') $== f a + f a'.
261+
262+
(** It follows that it respects the unit and inversion. *)
263+
Definition grp_homo_unit_0gpd (f : A -> B) `{IsGroupHom_0gpd f}
264+
: f 0 $== 0.
265+
Proof.
266+
apply (cancelL_0gpd (f 0)).
267+
rhs' napply mon_unit_r_0gpd.
268+
rhs_V' rapply (fmap f (mon_unit_l_0gpd 0)).
269+
symmetry.
270+
apply grp_homo_op_0gpd.
271+
Defined.
272+
273+
Definition grp_homo_inv_0gpd (f : A -> B) `{IsGroupHom_0gpd f} (a : A)
274+
: f (-a) $== -f(a).
275+
Proof.
276+
apply (cancelL_0gpd (f a)).
277+
lhs_V' rapply grp_homo_op_0gpd.
278+
lhs' rapply (fmap f (inverse_r_0gpd _)).
279+
rhs' rapply inverse_r_0gpd.
280+
rapply grp_homo_unit_0gpd.
281+
Defined.
282+
283+
Definition grp_homo_op_inv_0gpd (f : A -> B) `{IsGroupHom_0gpd f} (a b : A)
284+
: f (a - b) $== f a - f b.
285+
Proof.
286+
lhs' rapply grp_homo_op_0gpd.
287+
apply (fmap (sgop_0gpd _)).
288+
rapply grp_homo_inv_0gpd.
289+
Defined.
290+
291+
End Homomorphism.
292+
293+
(** ** Definition of a wild category enriched in abelian groups *)
294+
295+
(** It must a 1-category with 0-groupoid abelian group structures on its hom types, such that pre- and post-composition are homomorphism. *)
296+
Class IsAbEnriched (A : Type) `{Is1Cat A} := {
297+
abgroup_abenriched :: forall (a b : A), IsAbGroup_0gpd (a $-> b);
298+
issgpreserving_postcomp_abenriched
299+
:: forall (a b c : A) (g : b $-> c), IsGroupHom_0gpd (cat_postcomp a g) ;
300+
issgpreserving_precomp_abenriched
301+
:: forall (a b c : A) (f : a $-> b), IsGroupHom_0gpd (cat_precomp c f) ;
302+
}.
303+
304+
(** ** Results involving pre- and post-composition *)
305+
306+
(** All of these except [precomp_zero] may not be needed, since Rocq is usually able to infer which homomorphism is involved, but we include them for completeness. *)
307+
308+
Section AbEnriched.
309+
310+
Context {A : Type} `{IsAbEnriched A}.
311+
312+
Definition postcomp_op {B C D : A} (f : C $-> D) (g h : B $-> C)
313+
: f $o (g + h) $== (f $o g) + (f $o h)
314+
:= grp_homo_op_0gpd g h.
315+
316+
Definition precomp_op {B C D : A} (f : B $-> C) (g h : C $-> D)
317+
: (g + h) $o f $== (g $o f) + (h $o f)
318+
:= grp_homo_op_0gpd g h.
319+
320+
Definition postcomp_zero {B C D : A} (f : C $-> D)
321+
: f $o 0 $== (0 : B $-> D)
322+
:= grp_homo_unit_0gpd _.
323+
324+
Definition precomp_zero {B C D : A} (f : B $-> C)
325+
: 0 $o f $== (0 : B $-> D)
326+
:= grp_homo_unit_0gpd (cat_precomp _ _).
327+
328+
Definition postcomp_inv {B C D : A} (f : C $-> D) (g : B $-> C)
329+
: f $o (-g) $== -(f $o g)
330+
:= grp_homo_inv_0gpd _ g.
331+
332+
Definition precomp_inv {B C D : A} (f : C $-> D) (g : B $-> C)
333+
: (-f) $o g $== -(f $o g)
334+
:= grp_homo_inv_0gpd _ f.
335+
336+
Definition postcomp_op_inv {B C D : A} (f : C $-> D) (g h : B $-> C)
337+
: f $o (g - h) $== (f $o g) - (f $o h)
338+
:= grp_homo_op_inv_0gpd _ _ _.
339+
340+
Definition precomp_op_inv {B C D : A} (f : B $-> C) (g h : C $-> D)
341+
: (g - h) $o f $== (g $o f) - (h $o f)
342+
:= grp_homo_op_inv_0gpd _ g h.
343+
344+
End AbEnriched.

0 commit comments

Comments
 (0)