A Coq library for domain theory (http://rwd.rdockins.name/domains/)

root / sumprod_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
(* Copyright (c) 2014, Robert Dockins *)

Require Import List.
Require Import NArith.

Require Import basics.
Require Import categories.
Require Import preord.
Require Import sets.
Require Import finsets.
Require Import esets.
Require Import effective.
Require Import plotkin.
Require Import profinite.
Require Import embed.
Require Import joinable.
Require Import directed.
Require Import cont_functors.
Require Import bilimit.

(**  * Sum and product functors 

     Here we define the functors for sum and produce in the category
     of embeddings and show that they are continuous.
  *)

Section prod_functor.
  Variable hf:bool.
  Variables A B C D:ob (EMBED hf).

  Variable f:A ⇀ B.
  Variable g:C ⇀ D.

  Program Definition prod_fmap : PLT.prod A C ⇀ PLT.prod B D
    := Embedding hf (PLT.prod A C) (PLT.prod B D) (fun x => (f (fst x), g (snd x)))
         _ _ _ _.
  Next Obligation.
    intros. destruct a as [a c]. destruct a' as [a' c']. simpl.
    destruct H. simpl in *.
    split; simpl; apply embed_mono; auto.
  Qed.
  Next Obligation.
    intros. destruct a as [a c]. destruct a' as [a' c']. simpl.
    destruct H. simpl in *.
    split; simpl.
    apply embed_reflects in H. auto.
    apply embed_reflects in H0. auto.
  Qed.
  Next Obligation.
    intros [b d]. simpl.
    destruct hf. auto.
    simpl.
    destruct (embed_directed0 f b).
    destruct (embed_directed0 g d).
    exists (x,x0). simpl. split; auto.
  Qed.
  Next Obligation.
    intros.
    destruct a as [a c].
    destruct b as [a' c']. simpl in *.
    destruct (embed_directed2 f (fst y) a a') as [p [?[??]]].
    destruct H; auto. destruct H0; auto.
    destruct (embed_directed2 g (snd y) c c') as [q [?[??]]].
    destruct H; auto. destruct H0; auto.
    exists (p,q). simpl. 
    repeat split; auto.
  Qed.

End prod_functor.

Program Definition prodF hf
  : functor (PROD (EMBED hf) (EMBED hf)) (EMBED hf) :=

  Functor (PROD (EMBED hf) (EMBED hf)) (EMBED hf) 
     (fun (AB:ob (PROD (EMBED hf) (EMBED hf))) =>
         PLT.prod (@obl (EMBED hf) (EMBED hf) AB)
                  (@obr (EMBED hf) (EMBED hf) AB))
     (fun (AB CD:ob (PROD (EMBED hf) (EMBED hf))) (f:AB → CD) => 
       prod_fmap hf _ _ _ _
         (@homl (EMBED hf) (EMBED hf) AB CD f)
         (@homr (EMBED hf) (EMBED hf) AB CD f))
     _ _ _.
Next Obligation.
  simpl; intros.
  destruct f; simpl in *.
  apply embed_lift'; simpl; intros.
  destruct x as [x y]. simpl.
  destruct H. simpl in *.
  destruct H; destruct H0; split; split; simpl; auto.
  apply H. apply H0. apply H1. apply H2.
Qed.
Next Obligation.
  simpl; intros.
  destruct f; simpl in *.
  destruct g; simpl in *.
  destruct h; simpl in *.
  destruct H; simpl in *.
  apply embed_lift'; simpl; intros.
  split; split; simpl.
  rewrite H. auto.
  rewrite H0; auto.
  rewrite H; auto.
  rewrite H0; auto.
Qed.
Next Obligation.
  simpl; intros.
  destruct f; simpl in *.
  destruct g; simpl in *.
  destruct H; simpl in *.
  apply embed_lift'; simpl; intros.
  split; split; simpl.
  rewrite H. auto.
  rewrite H0; auto.
  rewrite H; auto.
  rewrite H0; auto.
Qed.


Lemma prodF_continuous hf : continuous_functor (prodF hf).
Proof.
  hnf; intros.
  apply decompose_is_colimit.
  simpl. intros.
  destruct x as [x y].
  generalize (fstF_continuous _ _ I DS CC X). intros.
  generalize (sndF_continuous _ _ I DS CC X). intros.
  destruct (colimit_decompose hf I _ _ X0 x) as [i [x' ?]].
  destruct (colimit_decompose hf I _ _ X1 y) as [j [y' ?]].
  simpl in *.
  destruct (choose_ub I i j) as [k [??]].
  exists k.
  exists (homl (ds_hom DS i k H) x', homr (ds_hom DS j k H0) y').
  simpl.
  generalize (cocone_commute CC i k H).
  generalize (cocone_commute CC j k H0).
  intros. destruct H1. destruct H2.
  rewrite H2 in e.
  rewrite H3 in e0.
  simpl in *.
  destruct e; destruct e0; split; split; auto.
Qed.


Section sum_functor.
  Variable hf:bool.
  Variables A B C D:ob (EMBED hf).

  Variable f:A ⇀ B.
  Variable g:C ⇀ D.

  Definition sum_fmap_func (x:A+C) : B+D :=
    match x with
    | inl a => inl (f a)
    | inr b => inr (g b)
    end.

  Program Definition sum_fmap : PLT.sum A C ⇀ PLT.sum B D
    := Embedding hf (PLT.sum A C) (PLT.sum B D) sum_fmap_func _ _ _ _.
  Next Obligation.
    intros. destruct a as [a|c]. destruct a' as [a'|c']; simpl.
    apply embed_mono; auto.
    elim H.
    destruct a' as [a'|c']; simpl.
    elim H.
    apply embed_mono; auto.
  Qed.
  Next Obligation.
    intros.
    destruct a as [a|c]. 
    destruct a' as [a'|c']. simpl.
    simpl in H. red in H. simpl in H.
    apply embed_reflects in H. auto.
    elim H.
    destruct a' as [a'|c']. simpl.
    destruct H.
    red in H. simpl in H.
    apply embed_reflects in H. auto.
  Qed.
  Next Obligation.
    intro y. simpl in *. unfold sum_fmap_func.
    destruct hf. auto.
    destruct y as [b|d]. simpl.
    destruct (embed_directed0 f b).
    exists (inl x). auto.
    destruct (embed_directed0 g d).
    exists (inr x). auto.
  Qed.
  Next Obligation.
    intros.
    destruct y as [y|y].
    destruct a as [a|a]. 2: elim H.
    destruct b as [b|b]. 2: elim H0.
    unfold sum_fmap_func in *.
    destruct (embed_directed2 f y a b) as [p [?[??]]]; auto.
    exists (inl p). auto.
    destruct a as [a|a]. elim H.
    destruct b as [b|b]. elim H0.
    unfold sum_fmap_func in *.
    destruct (embed_directed2 g y a b) as [p [?[??]]]; auto.
    exists (inr p). auto.
  Qed.
End sum_functor.

Program Definition sumF hf
  : functor (PROD (EMBED hf) (EMBED hf)) (EMBED hf) :=

  Functor (PROD (EMBED hf) (EMBED hf)) (EMBED hf) 
     (fun (AB:ob (PROD (EMBED hf) (EMBED hf))) =>
         PLT.sum (@obl (EMBED hf) (EMBED hf) AB)
                 (@obr (EMBED hf) (EMBED hf) AB))
     (fun (AB CD:ob (PROD (EMBED hf) (EMBED hf))) (f:AB → CD) => 
       sum_fmap hf _ _ _ _
         (@homl (EMBED hf) (EMBED hf) AB CD f)
         (@homr (EMBED hf) (EMBED hf) AB CD f))
     _ _ _.
Next Obligation.
  simpl; intros.
  destruct f; simpl in *.
  apply embed_lift'; simpl; intros.
  destruct x as [x|x]. simpl.
  destruct H. simpl in *.
  destruct H; split. apply H. apply H1.
  simpl.
  destruct H. simpl in *.
  destruct H0. split. apply H0. apply H1.
Qed.
Next Obligation.
  simpl; intros.
  destruct f; simpl in *.
  destruct g; simpl in *.
  destruct h; simpl in *.
  destruct H; simpl in *.
  apply embed_lift'; simpl; intros.
  unfold sum_fmap_func.
  destruct x as [x|x].
  destruct H; split.
  apply H. apply H1.
  destruct H0; split.
  apply H0. apply H1.
Qed.
Next Obligation.
  simpl; intros.
  destruct f; simpl in *.
  destruct g; simpl in *.
  destruct H; simpl in *.
  apply embed_lift'; simpl; intros.
  unfold sum_fmap_func.
  destruct x as [x|x].
  destruct H; split.
  apply H. apply H1.
  destruct H0; split.
  apply H0. apply H1.
Qed.


Lemma sumF_continuous hf : continuous_functor (sumF hf).
Proof.
  hnf; intros.
  apply decompose_is_colimit.
  simpl. intros.
  destruct x as [x|x].
  generalize (fstF_continuous _ _ I DS CC X). intros.
  destruct (colimit_decompose hf I _ _ X0 x) as [i [x' ?]].
  exists i. exists (inl x').
  simpl. destruct e; auto.
  generalize (sndF_continuous _ _ I DS CC X). intros.
  destruct (colimit_decompose hf I _ _ X0 x) as [i [x' ?]].
  exists i. exists (inr x').
  simpl. destruct e; auto.
Qed.