-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGraphs.v
162 lines (140 loc) · 5.46 KB
/
Graphs.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
Require Import FunctionalExtensionality.
Require Export Functor SetCategory SmallCat FunctorCategory Paths.
Require Import Common FEqualDep.
Set Implicit Arguments.
Generalizable All Variables.
Set Asymmetric Patterns.
Set Universe Polymorphism.
Section GraphObj.
Context `(C : @SpecializedCategory objC).
Inductive GraphIndex := GraphIndexSource | GraphIndexTarget.
Definition GraphIndex_Morphism (a b : GraphIndex) : Set :=
match (a, b) with
| (GraphIndexSource, GraphIndexSource) => unit
| (GraphIndexTarget, GraphIndexTarget) => unit
| (GraphIndexTarget, GraphIndexSource) => Empty_set
| (GraphIndexSource, GraphIndexTarget) => GraphIndex
end.
Global Arguments GraphIndex_Morphism a b /.
Definition GraphIndex_Compose s d d' (m1 : GraphIndex_Morphism d d') (m2 : GraphIndex_Morphism s d) :
GraphIndex_Morphism s d'.
destruct s, d, d'; simpl in *; trivial.
Defined.
Definition GraphIndexingCategory : @SpecializedCategory GraphIndex.
refine (@Build_SpecializedCategory _
GraphIndex_Morphism
(fun x => match x with GraphIndexSource => tt | GraphIndexTarget => tt end)
GraphIndex_Compose
_
_
_);
abstract (
intros; destruct_type GraphIndex; simpl in *; destruct_type Empty_set; trivial
).
Defined.
Definition UnderlyingGraph_ObjectOf x :=
match x with
| GraphIndexSource => { sd : objC * objC & C.(Morphism) (fst sd) (snd sd) }
| GraphIndexTarget => objC
end.
Global Arguments UnderlyingGraph_ObjectOf x /.
Definition UnderlyingGraph_MorphismOf s d (m : Morphism GraphIndexingCategory s d) :
UnderlyingGraph_ObjectOf s -> UnderlyingGraph_ObjectOf d :=
match (s, d) as sd return
Morphism GraphIndexingCategory (fst sd) (snd sd) ->
UnderlyingGraph_ObjectOf (fst sd) -> UnderlyingGraph_ObjectOf (snd sd)
with
| (GraphIndexSource, GraphIndexSource) => fun _ => @id _
| (GraphIndexSource, GraphIndexTarget) => fun m' =>
match m' with
| GraphIndexSource => fun sdm => fst (projT1 sdm)
| GraphIndexTarget => fun sdm => snd (projT1 sdm)
end
| (GraphIndexTarget, GraphIndexSource) => fun m' => match m' with end
| (GraphIndexTarget, GraphIndexTarget) => fun _ => @id _
end m.
Definition UnderlyingGraph : SpecializedFunctor GraphIndexingCategory TypeCat.
Proof.
match goal with
| [ |- SpecializedFunctor ?C ?D ] =>
refine (Build_SpecializedFunctor C D
UnderlyingGraph_ObjectOf
UnderlyingGraph_MorphismOf
_
_
)
end;
abstract (
unfold UnderlyingGraph_MorphismOf; simpl; intros;
destruct_type GraphIndex;
autorewrite with morphism;
trivial; try destruct_to_empty_set
).
Defined.
End GraphObj.
Section GraphFunctor.
Let UnderlyingGraphFunctor_ObjectOf (C : SmallCat) : SpecializedFunctor GraphIndexingCategory TypeCat :=
UnderlyingGraph C.
Local Ltac t :=
intros; destruct_head GraphIndex;
repeat match goal with
| [ H : Empty_set |- _ ] => destruct H
| _ => reflexivity
| _ => progress destruct_head GraphIndex; simpl in *
| _ => progress repeat (apply functional_extensionality_dep; intro)
| _ => progress simpl_eq
| _ => progress destruct_sig; simpl in *
end.
Definition UnderlyingGraphFunctor_MorphismOf C D (F : Morphism SmallCat C D) :
Morphism (TypeCat ^ GraphIndexingCategory) (UnderlyingGraph C) (UnderlyingGraph D).
Proof.
exists (fun c => match c as c return (UnderlyingGraph C) c -> (UnderlyingGraph D) c with
| GraphIndexSource => fun sdm => existT _ (F (fst (projT1 sdm)), F (snd (projT1 sdm))) (F.(MorphismOf) (projT2 sdm))
| GraphIndexTarget => ObjectOf F
end);
abstract t.
Defined.
Definition UnderlyingGraphFunctor : SpecializedFunctor SmallCat (TypeCat ^ GraphIndexingCategory).
Proof.
match goal with
| [ |- SpecializedFunctor ?C ?D ] =>
refine (Build_SpecializedFunctor C D
UnderlyingGraphFunctor_ObjectOf
UnderlyingGraphFunctor_MorphismOf
_
_
)
end;
abstract (
repeat match goal with
| _ => progress simpl in *
| _ => progress functor_eq
| _ => progress nt_eq
| _ => progress t
| _ => progress unfold ComponentsOf
| [ |- appcontext[match ?x with _ => _ end] ] => destruct x
end
).
Defined.
End GraphFunctor.
Section FreeCategory.
Variable F : SpecializedFunctor GraphIndexingCategory TypeCat.
Let vertices := F GraphIndexTarget.
Hint Rewrite concatenate_p_noedges concatenate_noedges_p concatenate_associative.
Definition FreeCategory : SpecializedCategory vertices.
Proof.
refine (@Build_SpecializedCategory
vertices
_
(@NoEdges _ _)
(fun s d d' m m' => @concatenate _ _ s d d' m' m)
_
_
_
);
intros; autorewrite with core; reflexivity.
Grab Existential Variables.
(* what goes here, of type [vertices -> vertices -> Type]? *)
(* morphisms are paths *)
Admitted.
End FreeCategory.