-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFunctor.v
327 lines (285 loc) · 12.8 KB
/
Functor.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
Require Import JMeq ProofIrrelevance FunctionalExtensionality.
Require Export Notations SpecializedCategory Category.
Require Import Common StructureEquality FEqualDep.
Set Implicit Arguments.
Generalizable All Variables.
Set Asymmetric Patterns.
Set Universe Polymorphism.
Local Infix "==" := JMeq.
Section SpecializedFunctor.
Context `(C : @SpecializedCategory objC).
Context `(D : @SpecializedCategory objD).
(**
Quoting from the lecture notes for 18.705, Commutative Algebra:
A map of categories is known as a functor. Namely, given
categories [C] and [C'], a (covariant) functor [F : C -> C'] is a rule that assigns to
each object [A] of [C] an object [F A] of [C'] and to each map [m : A -> B] of [C] a map
[F m : F A -> F B] of [C'] preserving composition and identity; that is,
(1) [F (m' ○ m) = (F m') ○ (F m)] for maps [m : A -> B] and [m' : B -> C] of [C], and
(2) [F (id A) = id (F A)] for any object [A] of [C], where [id A] is the identity morphism of [A].
**)
Record SpecializedFunctor :=
{
ObjectOf :> objC -> objD;
MorphismOf : forall s d, C.(Morphism) s d -> D.(Morphism) (ObjectOf s) (ObjectOf d);
FCompositionOf : forall s d d' (m1 : C.(Morphism) s d) (m2: C.(Morphism) d d'),
MorphismOf _ _ (Compose m2 m1) = Compose (MorphismOf _ _ m2) (MorphismOf _ _ m1);
FIdentityOf : forall x, MorphismOf _ _ (Identity x) = Identity (ObjectOf x)
}.
End SpecializedFunctor.
Section Functor.
Variable C : Category.
Variable D : Category.
Definition Functor := SpecializedFunctor C D.
End Functor.
Bind Scope functor_scope with SpecializedFunctor.
Bind Scope functor_scope with Functor.
Create HintDb functor discriminated.
Identity Coercion Functor_SpecializedFunctor_Id : Functor >-> SpecializedFunctor.
Definition GeneralizeFunctor objC C objD D (F : @SpecializedFunctor objC C objD D) : Functor C D := F.
Coercion GeneralizeFunctor : SpecializedFunctor >-> Functor.
(* try to always unfold [GeneralizeFunctor]; it's in there
only for coercions *)
Arguments GeneralizeFunctor [objC C objD D] F /.
Hint Extern 0 => unfold GeneralizeFunctor : category functor.
Arguments SpecializedFunctor {objC} C {objD} D.
Arguments Functor C D.
Arguments ObjectOf {objC%type C%category objD%type D%category} F%functor c%object : rename, simpl nomatch.
Arguments MorphismOf {objC%type} [C%category] {objD%type} [D%category] F%functor [s%object d%object] m%morphism : rename, simpl nomatch.
Arguments FCompositionOf [objC C objD D] F _ _ _ _ _ : rename.
Arguments FIdentityOf [objC C objD D] F _ : rename.
Hint Resolve @FCompositionOf @FIdentityOf : category functor.
Hint Rewrite @FIdentityOf : category.
Hint Rewrite @FIdentityOf : functor.
Ltac functor_hideProofs :=
repeat match goal with
| [ |- context[{|
ObjectOf := _;
MorphismOf := _;
FCompositionOf := ?pf0;
FIdentityOf := ?pf1
|}] ] =>
hideProofs pf0 pf1
end.
Ltac functor_tac_abstract_trailing_props F tac :=
let F' := (eval hnf in F) in
let F'' := (tac F') in
let H := fresh in
pose F'' as H;
hnf in H;
revert H; clear; intro H; clear H;
match F'' with
| @Build_SpecializedFunctor ?objC ?C
?objD ?D
?OO
?MO
?FCO
?FIO =>
refine (@Build_SpecializedFunctor objC C objD D
OO
MO
_
_);
[ abstract exact FCO | abstract exact FIO ]
end.
Ltac functor_abstract_trailing_props F := functor_tac_abstract_trailing_props F ltac:(fun F' => F').
Ltac functor_simpl_abstract_trailing_props F := functor_tac_abstract_trailing_props F ltac:(fun F' => let F'' := eval simpl in F' in F'').
Section Functors_Equal.
Lemma Functor_contr_eq' objC C objD D (F G : @SpecializedFunctor objC C objD D)
(D_morphism_proof_irrelevance
: forall s d (m1 m2 : Morphism D s d) (pf1 pf2 : m1 = m2),
pf1 = pf2)
: forall HO : ObjectOf F = ObjectOf G,
match HO in (_ = f) return forall s d, Morphism C s d -> Morphism D (f s) (f d) with
| eq_refl => MorphismOf F
end = MorphismOf G
-> F = G.
intros.
destruct F, G; simpl in *.
subst.
f_equal;
repeat (apply functional_extensionality_dep; intro);
trivial.
Qed.
Lemma Functor_contr_eq objC C objD D (F G : @SpecializedFunctor objC C objD D)
(D_object_proof_irrelevance
: forall (x : D) (pf : x = x),
pf = eq_refl)
(D_morphism_proof_irrelevance
: forall s d (m1 m2 : Morphism D s d) (pf1 pf2 : m1 = m2),
pf1 = pf2)
: forall HO : (forall x, ObjectOf F x = ObjectOf G x),
(forall s d (m : Morphism C s d),
match HO s in (_ = y) return (Morphism D y _) with
| eq_refl =>
match HO d in (_ = y) return (Morphism D _ y) with
| eq_refl => MorphismOf F m
end
end = MorphismOf G m)
-> F = G.
intros HO HM.
apply Functor_contr_eq' with (HO := (functional_extensionality_dep F G HO));
try assumption.
repeat (apply functional_extensionality_dep; intro).
rewrite <- HM; clear HM.
generalize_eq_match.
destruct F, G; simpl in *; subst.
subst_eq_refl_dec.
reflexivity.
Qed.
Lemma Functor_eq' objC C objD D : forall (F G : @SpecializedFunctor objC C objD D),
ObjectOf F = ObjectOf G
-> MorphismOf F == MorphismOf G
-> F = G.
destruct F, G; simpl; intros; specialize_all_ways; repeat subst;
f_equal; apply proof_irrelevance.
Qed.
Lemma Functor_eq objC C objD D :
forall (F G : @SpecializedFunctor objC C objD D),
(forall x, ObjectOf F x = ObjectOf G x)
-> (forall s d m, MorphismOf F (s := s) (d := d) m == MorphismOf G (s := s) (d := d) m)
-> F = G.
intros; cut (ObjectOf F = ObjectOf G); intros; try apply Functor_eq'; destruct F, G; simpl in *; repeat subst;
try apply eq_JMeq;
repeat (apply functional_extensionality_dep; intro); trivial;
try apply JMeq_eq; trivial.
Qed.
Lemma Functor_JMeq objC C objD D objC' C' objD' D' :
forall (F : @SpecializedFunctor objC C objD D) (G : @SpecializedFunctor objC' C' objD' D'),
objC = objC'
-> objD = objD'
-> C == C'
-> D == D'
-> ObjectOf F == ObjectOf G
-> MorphismOf F == MorphismOf G
-> F == G.
simpl; intros; intuition; repeat subst; destruct F, G; simpl in *;
repeat subst; JMeq_eq.
f_equal; apply proof_irrelevance.
Qed.
End Functors_Equal.
Ltac functor_eq_step_with tac :=
structures_eq_step_with_tac ltac:(apply Functor_eq || apply Functor_JMeq) tac.
Ltac functor_eq_with tac := repeat functor_eq_step_with tac.
Ltac functor_eq_step := functor_eq_step_with idtac.
Ltac functor_eq := functor_hideProofs; functor_eq_with idtac.
Ltac functor_tac_abstract_trailing_props_with_equality_do tac F thm :=
let F' := (eval hnf in F) in
let F'' := (tac F') in
let H := fresh in
pose F'' as H;
hnf in H;
revert H; clear; intro H; clear H;
match F'' with
| @Build_SpecializedFunctor ?objC ?C
?objD ?D
?OO
?MO
?FCO
?FIO =>
let FCO' := fresh in
let FIO' := fresh in
let FCOT' := type of FCO in
let FIOT' := type of FIO in
let FCOT := (eval simpl in FCOT') in
let FIOT := (eval simpl in FIOT') in
assert (FCO' : FCOT) by abstract exact FCO;
assert (FIO' : FIOT) by (clear FCO'; abstract exact FIO);
exists (@Build_SpecializedFunctor objC C objD D
OO
MO
FCO'
FIO');
expand; abstract (apply thm; reflexivity) || (apply thm; try reflexivity)
end.
Ltac functor_tac_abstract_trailing_props_with_equality tac :=
pre_abstract_trailing_props;
match goal with
| [ |- { F0 : SpecializedFunctor _ _ | F0 = ?F } ] =>
functor_tac_abstract_trailing_props_with_equality_do tac F @Functor_eq'
| [ |- { F0 : SpecializedFunctor _ _ | F0 == ?F } ] =>
functor_tac_abstract_trailing_props_with_equality_do tac F @Functor_JMeq
end.
Ltac functor_abstract_trailing_props_with_equality := functor_tac_abstract_trailing_props_with_equality ltac:(fun F' => F').
Ltac functor_simpl_abstract_trailing_props_with_equality := functor_tac_abstract_trailing_props_with_equality ltac:(fun F' => let F'' := eval simpl in F' in F'').
Section FunctorComposition.
Context `(B : @SpecializedCategory objB).
Context `(C : @SpecializedCategory objC).
Context `(D : @SpecializedCategory objD).
Context `(E : @SpecializedCategory objE).
Variable G : SpecializedFunctor D E.
Variable F : SpecializedFunctor C D.
Definition ComposeFunctors' : SpecializedFunctor C E
:= Build_SpecializedFunctor C E
(fun c => G (F c))
(fun _ _ m => G.(MorphismOf) (F.(MorphismOf) m))
(fun _ _ _ m1 m2 =>
match FCompositionOf G _ _ _ (MorphismOf F m1) (MorphismOf F m2) with
| eq_refl =>
match
FCompositionOf F _ _ _ m1 m2 in (_ = y)
return
(MorphismOf G (MorphismOf F (Compose m2 m1)) =
MorphismOf G y)
with
| eq_refl => eq_refl
end
end)
(fun x =>
match FIdentityOf G (F x) with
| eq_refl =>
match
FIdentityOf F x in (_ = y)
return
(MorphismOf G (MorphismOf F (Identity x)) =
MorphismOf G y)
with
| eq_refl => eq_refl
end
end).
Hint Rewrite @FCompositionOf : functor.
Definition ComposeFunctors : SpecializedFunctor C E.
refine (Build_SpecializedFunctor C E
(fun c => G (F c))
(fun _ _ m => G.(MorphismOf) (F.(MorphismOf) m))
_
_);
abstract (
intros; autorewrite with functor; reflexivity
).
Defined.
End FunctorComposition.
Section IdentityFunctor.
Context `(C : @SpecializedCategory objC).
(** There is an identity functor. It does the obvious thing. *)
Definition IdentityFunctor : SpecializedFunctor C C
:= Build_SpecializedFunctor C C
(fun x => x)
(fun _ _ x => x)
(fun _ _ _ _ _ => eq_refl)
(fun _ => eq_refl).
End IdentityFunctor.
Section IdentityFunctorLemmas.
Context `(C : @SpecializedCategory objC).
Context `(D : @SpecializedCategory objD).
Lemma LeftIdentityFunctor (F : SpecializedFunctor D C) : ComposeFunctors (IdentityFunctor _) F = F.
functor_eq.
Qed.
Lemma RightIdentityFunctor (F : SpecializedFunctor C D) : ComposeFunctors F (IdentityFunctor _) = F.
functor_eq.
Qed.
End IdentityFunctorLemmas.
Hint Rewrite @LeftIdentityFunctor @RightIdentityFunctor : category.
Hint Rewrite @LeftIdentityFunctor @RightIdentityFunctor : functor.
Hint Immediate @LeftIdentityFunctor @RightIdentityFunctor : category functor.
Section FunctorCompositionLemmas.
Context `(B : @SpecializedCategory objB).
Context `(C : @SpecializedCategory objC).
Context `(D : @SpecializedCategory objD).
Context `(E : @SpecializedCategory objE).
Lemma ComposeFunctorsAssociativity (F : SpecializedFunctor B C) (G : SpecializedFunctor C D) (H : SpecializedFunctor D E) :
ComposeFunctors (ComposeFunctors H G) F = ComposeFunctors H (ComposeFunctors G F).
functor_eq.
Qed.
End FunctorCompositionLemmas.
Hint Resolve @ComposeFunctorsAssociativity : category functor.