-
Notifications
You must be signed in to change notification settings - Fork 2
/
powerdom.v
5681 lines (5341 loc) · 206 KB
/
powerdom.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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(* Copyright (c) 2014, Robert Dockins *)
Require Import Setoid.
Require Import List.
Require Import basics.
Require Import preord.
Require Import categories.
Require Import sets.
Require Import finsets.
Require Import esets.
Require Import effective.
Require Import directed.
Require Import plotkin.
Require Import joinable.
Require Import approx_rels.
Require Import profinite.
Require Import embed.
(** * Powerdomains
Here we construct the lower, upper and convex powerdomains, and show that they
form continuous functors in the category of embeddings.
Powerdomains over a domain X are defined as preorders consisting of
finite h-inhabited subsets of X with the upper, lower and convex ordering,
respectively.
Notably, the convex powerdomain over unpointed domains has a representative
for the empty set, which the convex powerdomain over pointed domains lacks.
This fact might be previously known (I am not actually sure), but it does not
seem to be widely appreciated.
*)
Inductive pdom_sort :=
| Lower
| Upper
| Convex.
Module powerdom.
Section powerdom.
Variable hf:bool.
Record pdom_elem (X:preord) :=
PdomElem
{ elem : finset X
; elem_inh : inh hf elem
}.
Arguments elem [X] p.
Arguments elem_inh [X] p.
Section orders.
Variable X:preord.
Definition lower_ord (P Q:pdom_elem X) :=
forall x, x ∈ elem P ->
exists y, y ∈ elem Q /\ x ≤ y.
Definition upper_ord (P Q:pdom_elem X) :=
forall y, y ∈ elem Q ->
exists x, x ∈ elem P /\ x ≤ y.
Definition convex_ord (P Q:pdom_elem X) :=
lower_ord P Q /\ upper_ord P Q.
Lemma lower_ord_refl P : lower_ord P P.
Proof.
repeat intro; eauto.
Qed.
Lemma upper_ord_refl P : upper_ord P P.
Proof.
repeat intro; eauto.
Qed.
Lemma convex_ord_refl P : convex_ord P P.
Proof.
split; [ apply lower_ord_refl | apply upper_ord_refl ].
Qed.
Lemma lower_ord_trans P Q R :
lower_ord P Q -> lower_ord Q R -> lower_ord P R.
Proof.
unfold lower_ord. intros.
destruct (H x) as [y [??]]; auto.
destruct (H0 y) as [z [??]]; auto.
exists z; split; eauto.
Qed.
Lemma upper_ord_trans P Q R :
upper_ord P Q -> upper_ord Q R -> upper_ord P R.
Proof.
unfold upper_ord. intros.
rename y into z.
destruct (H0 z) as [y [??]]; auto.
destruct (H y) as [x [??]]; auto.
exists x; split; eauto.
Qed.
Lemma convex_ord_trans P Q R :
convex_ord P Q -> convex_ord Q R -> convex_ord P R.
Proof.
unfold convex_ord; intuition.
- eapply lower_ord_trans; eassumption.
- eapply upper_ord_trans; eassumption.
Qed.
Definition lower_preord_mixin :=
Preord.Mixin (pdom_elem X) lower_ord lower_ord_refl lower_ord_trans.
Definition upper_preord_mixin :=
Preord.Mixin (pdom_elem X) upper_ord upper_ord_refl upper_ord_trans.
Definition convex_preord_mixin :=
Preord.Mixin (pdom_elem X) convex_ord convex_ord_refl convex_ord_trans.
Hypothesis Xeff : effective_order X.
Lemma lower_ord_dec : forall x y, {lower_ord x y}+{~lower_ord x y}.
Proof.
unfold lower_ord.
destruct x as [xs Hxs]. simpl. clear Hxs.
induction xs; simpl; intros.
- left. intros. apply nil_elem in H. elim H.
- destruct (IHxs y).
+ assert ({exists q, q ∈ elem y /\ a ≤ q}+
{forall q, q ∈ elem y -> a ≰ q}).
{ clear -Xeff. destruct y as [ys Hys]. simpl. clear Hys.
induction ys.
- right. intros. apply nil_elem in H. elim H.
- destruct (eff_ord_dec X Xeff a a0).
+ left. exists a0. split; auto. apply cons_elem; auto.
+ destruct IHys.
* left. destruct e as [q [??]]. exists q. split; auto.
apply cons_elem; auto.
* right. simpl; intros.
apply cons_elem in H. destruct H.
** intro. apply n. rewrite <- H; auto.
** apply n0; auto.
}
destruct H.
* left; intros.
apply cons_elem in H. destruct H.
** destruct e0 as [q [??]]. exists q. split; auto.
rewrite H; auto.
** apply (e x); auto.
* right; intro.
destruct (H a) as [q [??]].
** apply cons_elem; auto.
** apply (n q); auto.
+ right. intro.
apply n. intros.
apply (H x); auto.
apply cons_elem; auto.
Qed.
Lemma upper_ord_dec : forall x y, {upper_ord x y}+{~upper_ord x y}.
Proof.
unfold upper_ord. intros [x Hx] [y Hy]. simpl. clear Hx Hy.
revert x. induction y; intros.
- left. intros. apply nil_elem in H. elim H.
- destruct (IHy x).
+ assert ({exists q, q ∈ x /\ q ≤ a}+
{forall q, q ∈ x -> q ≰ a}).
{ clear -Xeff. induction x.
- right. intros. apply nil_elem in H. elim H.
- destruct (eff_ord_dec X Xeff a0 a).
+ left. exists a0. split; auto. apply cons_elem; auto.
+ destruct IHx.
* left. destruct e as [q [??]]. exists q. split; auto.
apply cons_elem; auto.
* right; intros. apply cons_elem in H. destruct H.
** intro. apply n. rewrite <- H; auto.
** apply n0; auto.
}
destruct H.
* left. intros. apply cons_elem in H. destruct H.
** destruct e0 as [q [??]]. exists q. split; auto.
rewrite H; auto.
** apply e; auto.
* right; intro.
destruct (H a) as [q [??]].
** apply cons_elem; auto.
** apply (n q); auto.
+ right; intro.
apply n; intros.
apply (H y0); auto. apply cons_elem; auto.
Qed.
Definition pdom_ord (sort:pdom_sort) :=
Preord.Pack
(pdom_elem X)
match sort with
| Lower => lower_preord_mixin
| Upper => upper_preord_mixin
| Convex => convex_preord_mixin
end.
Lemma pdom_ord_dec sort : forall (x y:pdom_ord sort), {x≤y}+{x≰y}.
Proof.
destruct sort.
- apply lower_ord_dec.
- apply upper_ord_dec.
- intros x y.
destruct (lower_ord_dec x y).
+ destruct (upper_ord_dec x y).
* left; split; auto.
* right; intros [??]; contradiction.
+ right; intros [??]; contradiction.
Qed.
Lemma pdom_elem_eq_lower sort (x y:pdom_ord sort) :
elem x ⊆ elem y -> lower_ord x y.
Proof.
repeat intro.
apply H in H0. exists x0. split; auto.
Qed.
Lemma pdom_elem_eq_upper sort (x y:pdom_ord sort) :
elem y ⊆ elem x -> upper_ord x y.
Proof.
repeat intro.
apply H in H0. exists y0. split; auto.
Qed.
Lemma pdom_elem_eq_le sort (x y:pdom_ord sort) :
elem x ≈ elem y -> x ≤ y.
Proof.
intros [??]; destruct sort; simpl.
- apply pdom_elem_eq_lower; auto.
- apply pdom_elem_eq_upper; auto.
- split.
+ apply pdom_elem_eq_lower; auto.
+ apply pdom_elem_eq_upper; auto.
Qed.
Lemma pdom_elem_eq_eq sort (x y:pdom_ord sort) :
elem x ≈ elem y -> x ≈ y.
Proof.
intros; split; apply pdom_elem_eq_le; auto.
Qed.
Definition enum_elems sort : eset (pdom_ord sort)
:= fun n =>
match finsubsets X (eff_enum X Xeff) n with
| None => None
| Some l =>
match inh_dec X hf l with
| left Hinh => Some (PdomElem X l Hinh)
| right _ => None
end
end.
Lemma enum_elems_complete sort (x:pdom_ord sort) :
x ∈ enum_elems sort.
Proof.
assert (elem x ∈ finsubsets X (eff_enum X Xeff)).
{ apply (finsubsets_complete X (eff_enum X Xeff) (elem x)).
red; intros. apply eff_complete.
}
destruct H as [n ?].
exists n. unfold enum_elems. simpl in *.
destruct (finsubsets X (eff_enum X Xeff) n).
- destruct (inh_dec X hf c).
+ apply pdom_elem_eq_eq. simpl; auto.
+ apply n0. generalize (elem_inh x).
apply inh_eq; auto.
- auto.
Qed.
Definition pdom_effective sort : effective_order (pdom_ord sort) :=
EffectiveOrder
(pdom_ord sort) (pdom_ord_dec sort)
(enum_elems sort) (enum_elems_complete sort).
Hypothesis Xplt : plotkin_order hf X.
Definition all_tokens sort (M:finset (pdom_ord sort)) : finset X :=
mub_closure Xplt (concat _ (map (@elem _) M)).
Fixpoint select_pdom_elems sort (ls:finset (finset X)) : finset (pdom_ord sort) :=
match ls with
| nil => nil
| x::xs =>
match inh_dec X hf x with
| left H => PdomElem X x H :: select_pdom_elems sort xs
| right _ => select_pdom_elems sort xs
end
end.
Lemma select_pdoms_in sort ls :
forall x:pdom_ord sort,
elem x ∈ ls -> x ∈ select_pdom_elems sort ls.
Proof.
induction ls; simpl; intuition.
- apply nil_elem in H; elim H.
- destruct (inh_dec X hf a).
+ apply cons_elem in H. destruct H.
* apply cons_elem. left.
apply pdom_elem_eq_eq. simpl. auto.
* apply cons_elem. right. apply IHls; auto.
+ apply cons_elem in H. destruct H.
* elim n. generalize (elem_inh x).
apply inh_eq. auto.
* apply IHls; auto.
Qed.
Lemma select_pdoms_in' sort ls :
forall x:pdom_ord sort,
x ∈ select_pdom_elems sort ls ->
exists x', x ≈ x' /\ elem x' ∈ ls.
Proof.
intros.
induction ls; simpl in *; intros.
- apply nil_elem in H. elim H.
- destruct (inh_dec X hf a).
+ apply cons_elem in H. destruct H.
* econstructor. split.
** apply H.
** simpl. apply cons_elem; auto.
* destruct IHls as [x' [??]]; auto.
exists x'; split; auto. apply cons_elem; auto.
+ destruct IHls as [x' [??]]; auto.
exists x'; split; auto. apply cons_elem; auto.
Qed.
Definition normal_pdoms sort (M:finset (pdom_ord sort)) :=
select_pdom_elems sort (list_finsubsets (all_tokens sort M)).
Lemma normal_pdoms_in sort M :
forall P:pdom_ord sort,
(forall x, x ∈ elem P -> x ∈ all_tokens sort M) ->
P ∈ normal_pdoms sort M.
Proof.
intros. unfold normal_pdoms.
apply select_pdoms_in.
apply list_finsubsets_complete; auto.
apply eff_to_ord_dec. auto.
Qed.
Lemma normal_pdoms_in' sort M :
forall P:pdom_ord sort,
P ∈ normal_pdoms sort M ->
exists P', P ≈ P' /\
(forall x, x ∈ elem P' -> x ∈ all_tokens sort M).
Proof.
intros. unfold normal_pdoms.
apply select_pdoms_in' in H.
destruct H as [x' [??]]. exists x'; split; auto.
intros. apply list_finsubsets_correct in H0.
apply H0; auto.
Qed.
Lemma pdom_has_normals sort :
has_normals (pdom_ord sort) (pdom_effective sort) hf.
Proof.
intros M HM.
exists (normal_pdoms sort M).
assert (M ⊆ normal_pdoms sort M).
{ red; intros.
destruct H as [q [??]].
rewrite H0.
apply normal_pdoms_in.
intros.
unfold all_tokens.
clear -H H1.
induction M; simpl in *; [ elim H |].
destruct H.
- subst q.
apply mub_clos_incl.
apply app_elem. auto.
- eapply mub_clos_mono; [ | apply IHM; auto ].
red; intros. apply app_elem; auto.
}
split; auto.
split.
{ revert HM.
case hf; auto.
intros [m ?]. exists m.
apply H; auto.
}
intro z.
apply prove_directed.
- case_eq hf; intros; auto.
assert (exists z0:finset X,
(forall x, x ∈ z0 -> exists x', x' ∈ elem z /\ x ≤ x') /\
(forall x', x' ∈ elem z -> exists x, x ∈ z0 /\ x ≤ x') /\
(forall x, x ∈ z0 -> x ∈ all_tokens sort M)).
{ generalize (elem z).
induction c.
- exists nil. repeat split; intros.
+ apply nil_elem in H1; elim H1.
+ apply nil_elem in H1; elim H1.
+ apply nil_elem in H1; elim H1.
- destruct IHc as [z0 [?[??]]].
destruct (mub_complete Xplt nil a) as [a' [??]].
{ rewrite H0. hnf. auto. }
{ apply ub_nil. }
exists (a'::z0).
repeat split; intros.
+ apply cons_elem in H6. destruct H6.
* exists a. split.
** apply cons_elem; auto.
** rewrite H6; auto.
* destruct (H1 x) as [x' [??]]; auto.
exists x'; split; auto. apply cons_elem; auto.
+ apply cons_elem in H6. destruct H6.
* exists a'. split; auto.
** apply cons_elem; auto.
** rewrite H6; auto.
* destruct (H2 x') as [x [??]]; auto.
exists x; split; auto. apply cons_elem; auto.
+ apply cons_elem in H6. destruct H6.
* rewrite H6.
unfold all_tokens.
apply (mub_clos_mub Xplt _ nil); auto.
** rewrite H0; hnf; auto.
** apply nil_subset.
* apply H3; auto.
}
destruct H1 as [z0 [?[??]]].
assert (inh hf z0).
{ rewrite H0; hnf; auto. }
exists (PdomElem X z0 H4). apply finsubset_elem.
+ intros. rewrite <- H5; auto.
+ split; auto.
* apply normal_pdoms_in. simpl. auto.
* destruct sort; hnf; auto.
- intros.
apply finsubset_elem in H0.
apply finsubset_elem in H1.
+ destruct H0. destruct H1.
apply normal_pdoms_in' in H0.
apply normal_pdoms_in' in H1.
destruct H0 as [x' [??]].
destruct H1 as [y' [??]].
set (Q m :=
(exists n, n ∈ elem x' /\ n ≤ m) /\
(exists n, n ∈ elem y' /\ n ≤ m) /\
(exists n, n ∈ elem z /\ m ≤ n)).
assert (exists qelems:finset X,
forall m, m ∈ qelems <-> Q m /\ m ∈ all_tokens sort M).
{ assert (Qdec : forall m, {Q m}+{~Q m}).
{ intro m. unfold Q. apply dec_conj.
- destruct (finset_find_dec _ (fun n => n ≤ m)) with (elem x').
+ simpl. intros. rewrite <- H6; auto.
+ intro. apply (eff_ord_dec X Xeff).
+ left. destruct s; eauto.
+ right. intros [??]. apply (n x0); auto.
* destruct H6; auto.
* destruct H6; auto.
- apply dec_conj.
+ destruct (finset_find_dec _ (fun n => n ≤ m)) with (elem y').
* simpl; intros. rewrite <- H6; auto.
* intro. apply (eff_ord_dec X Xeff).
* left. destruct s; eauto.
* right. intros [??]. apply (n x0); auto.
** destruct H6; auto.
** destruct H6; auto.
+ destruct (finset_find_dec _ (fun n => m ≤ n)) with (elem z).
* simpl; intros. rewrite <- H6; auto.
* intro. apply (eff_ord_dec X Xeff).
* left. destruct s; eauto.
* right. intros [??]. apply (n x0); auto.
** destruct H6; auto.
** destruct H6; auto.
}
exists (finsubset X Q Qdec (all_tokens sort M)).
intro. rewrite finsubset_elem; [ intuition |].
intros. destruct H7 as [?[??]].
split.
- destruct H7 as [n [??]]. exists n. rewrite <- H6; auto.
- split.
+ destruct H8 as [n [??]]. exists n. rewrite <- H6; auto.
+ destruct H9 as [n [??]]. exists n. rewrite <- H6; auto.
}
destruct H6 as [qelems Hq].
assert (sort <> Lower -> inh hf qelems).
{ case_eq hf; intros; hnf; auto.
{ assert (upper_ord x' z /\ upper_ord y' z).
{ rewrite H0 in H2. rewrite H1 in H3.
destruct sort; [ elim H7; auto | | ].
- split; auto.
- destruct H2; destruct H3; split; auto.
}
generalize (elem_inh z).
rewrite H6. intros [m ?].
destruct H8.
destruct (H8 m) as [mx [??]]; auto.
destruct (H10 m) as [my [??]]; auto.
destruct (mub_complete Xplt (mx::my::nil) m) as [q0 [??]].
{ apply directed.elem_inh with mx. apply cons_elem; auto. }
{ apply ub_cons; auto. apply ub_cons; auto. apply ub_nil. }
exists q0. apply Hq.
split.
- split.
+ exists mx. split; auto. apply H15. apply cons_elem; auto.
+ split.
* exists my. split; auto. apply H15.
apply cons_elem; right. apply cons_elem; auto.
* exists m. split; auto.
- unfold all_tokens.
apply (mub_clos_mub Xplt _ (mx::my::nil)); auto.
{ eapply directed.elem_inh. apply cons_elem; auto. }
apply cons_subset; auto.
apply cons_subset; auto.
apply nil_subset.
}
}
destruct sort.
* assert (inh hf (elem x' ++ elem y')).
{ generalize (elem_inh x').
case hf; auto.
intros [n ?]. exists n. apply app_elem; auto.
}
exists (PdomElem X (elem x'++elem y') H7).
split.
** rewrite H0.
hnf; simpl; intros. exists x0. split; auto. apply app_elem; auto.
** split.
*** rewrite H1.
hnf; simpl; intros. exists x0. split; auto. apply app_elem; auto.
*** apply finsubset_elem.
**** intros. rewrite <- H8; auto.
**** split.
***** apply normal_pdoms_in.
simpl. intros.
apply app_elem in H8. destruct H8; auto.
***** hnf; simpl; intros.
apply app_elem in H8. destruct H8.
****** rewrite H0 in H2.
apply H2; auto.
****** rewrite H1 in H3.
apply H3; auto.
* assert (Hq' : inh hf qelems).
{ apply H6. discriminate. }
exists (PdomElem X qelems Hq').
simpl.
rewrite H0. rewrite H1.
repeat split.
** hnf; simpl; intros.
apply Hq in H7. destruct H7.
destruct H7 as [?[??]]. auto.
** hnf; simpl; intros.
apply Hq in H7. destruct H7.
destruct H7 as [?[??]]. auto.
** apply finsubset_elem.
{ intros. rewrite <- H7; auto. }
split.
*** apply normal_pdoms_in.
simpl. intros.
apply Hq in H7. destruct H7; auto.
*** hnf; intros.
rewrite H0 in H2.
rewrite H1 in H3.
destruct (H2 y0) as [q1 [??]]; auto.
destruct (H3 y0) as [q2 [??]]; auto.
destruct (mub_complete Xplt (q1::q2::nil) y0).
{ eapply directed.elem_inh. apply cons_elem. left; eauto. }
{ apply ub_cons; auto. apply ub_cons; auto. apply ub_nil. }
destruct H12.
exists x0. split; auto.
apply Hq.
split.
**** split. { exists q1. split; auto. apply H12. apply cons_elem; auto. }
split. { exists q2. split; auto. apply H12.
apply cons_elem; right. apply cons_elem; auto.
}
exists y0; split; auto.
**** unfold all_tokens.
apply mub_clos_mub with (q1::q2::nil).
{ eapply directed.elem_inh. apply cons_elem. left; eauto. }
{ red; intros.
apply cons_elem in H14. destruct H14. rewrite H14.
apply H4; auto.
apply cons_elem in H14. destruct H14. rewrite H14.
apply H5; auto.
apply nil_elem in H14. elim H14.
}
auto.
* assert (Hq' : inh hf qelems).
{ apply H6. discriminate. }
exists (PdomElem X qelems Hq').
rewrite H0. rewrite H1.
rewrite H0 in H2.
rewrite H1 in H3.
split.
** hnf; simpl; intros.
split; hnf; simpl; intros.
*** destruct H2.
destruct (H2 x0) as [q1 [??]]; auto.
destruct H3.
destruct (H11 q1) as [q2 [??]]; auto.
destruct (mub_complete Xplt (x0::q2::nil) q1).
{ eapply directed.elem_inh. apply cons_elem. left; eauto. }
{ apply ub_cons. auto. apply ub_cons; auto. apply ub_nil. }
destruct H14.
exists x1. split.
**** apply Hq. split.
***** split. { exists x0. split; auto. apply H14. apply cons_elem; auto. }
split. { exists q2. split; auto. apply H14.
apply cons_elem. right. apply cons_elem; auto. }
exists q1. split; auto.
***** apply mub_clos_mub with (x0::q2::nil).
{ eapply directed.elem_inh. apply cons_elem. left; eauto. }
{ red; intros.
apply cons_elem in H16. destruct H16. rewrite H16.
apply H4; auto.
apply cons_elem in H16. destruct H16. rewrite H16.
apply H5; auto.
apply nil_elem in H16. elim H16.
}
auto.
**** apply H14. apply cons_elem; auto.
*** apply Hq in H7. destruct H7.
destruct H7 as [?[??]]. auto.
** split.
*** split.
**** hnf; simpl; intros.
destruct H3.
destruct (H3 x0) as [q1 [??]]; auto.
destruct H2.
destruct (H11 q1) as [q2 [??]]; auto.
destruct (mub_complete Xplt (x0::q2::nil) q1).
{ eapply directed.elem_inh. apply cons_elem. left; eauto. }
{ apply ub_cons; auto. apply ub_cons; auto. apply ub_nil. }
destruct H14.
exists x1. split.
***** apply Hq. split.
****** split. { exists q2. split; auto. apply H14.
apply cons_elem. right. apply cons_elem; auto. }
split. { exists x0. split; auto. apply H14.
apply cons_elem; auto. }
exists q1. split; auto.
****** apply mub_clos_mub with (x0::q2::nil).
{ eapply directed.elem_inh. apply cons_elem. left; eauto. }
{ red; intros.
apply cons_elem in H16. destruct H16. rewrite H16.
apply H5; auto.
apply cons_elem in H16. destruct H16. rewrite H16.
apply H4; auto.
apply nil_elem in H16. elim H16.
}
auto.
***** apply H14. apply cons_elem; auto.
**** hnf; intros.
apply Hq in H7. destruct H7.
destruct H7 as [?[??]]. auto.
*** apply finsubset_elem.
{ intros. rewrite <- H7; auto. }
split.
**** apply normal_pdoms_in.
simpl. intros.
apply Hq in H7. destruct H7; auto.
**** split.
***** hnf; intros.
apply Hq in H7.
destruct H7. destruct H7 as [?[??]].
auto.
***** hnf; intros.
destruct H2.
destruct H3.
destruct (H8 y0) as [q1 [??]]; auto.
destruct (H9 y0) as [q2 [??]]; auto.
destruct (mub_complete Xplt (q1::q2::nil) y0).
{ eapply directed.elem_inh. apply cons_elem. left; eauto. }
{ apply ub_cons; auto. apply ub_cons; auto. apply ub_nil. }
destruct H14.
exists x0. split; auto.
apply Hq.
split.
****** split. { exists q1. split; auto. apply H14. apply cons_elem; auto. }
split. { exists q2. split; auto. apply H14.
apply cons_elem; right. apply cons_elem; auto.
}
exists y0; split; auto.
****** unfold all_tokens.
apply mub_clos_mub with (q1::q2::nil).
{ eapply directed.elem_inh. apply cons_elem. left; eauto. }
{ red; intros.
apply cons_elem in H16. destruct H16. rewrite H16.
apply H4; auto.
apply cons_elem in H16. destruct H16. rewrite H16.
apply H5; auto.
apply nil_elem in H16. elim H16.
}
auto.
+ simpl; intros. rewrite <- H3; auto.
+ simpl; intros. rewrite <- H3; auto.
Qed.
Definition pdom_plt sort : plotkin_order hf (pdom_ord sort) :=
norm_plt (pdom_ord sort) (pdom_effective sort) hf
(pdom_has_normals sort).
End orders.
Program Definition single_elem (X:preord) (x:X) : pdom_elem X :=
PdomElem X (x::nil) _.
Next Obligation.
repeat intro.
apply directed.elem_inh with x. apply cons_elem; auto.
Qed.
Program Definition union_elem (X:preord) (p q:pdom_elem X) :=
PdomElem X (elem p ++ elem q) _.
Next Obligation.
intros. generalize (elem_inh q).
case hf; auto.
intros [n ?]. exists n. apply app_elem; auto.
Qed.
Program Definition concat_elem sort (X:preord)
(xs:list (pdom_ord X sort)) (H:inh hf xs) :=
PdomElem X (concat _ (map (@elem _) xs)) _.
Next Obligation.
intros.
revert H.
case_eq hf; intros; auto.
destruct H0 as [x [??]]. destruct H0. clear H1 x.
induction xs; simpl; intros.
- elim H0.
- destruct H0.
+ subst x0.
generalize (elem_inh a).
rewrite H. intros [q ?].
exists q. apply app_elem. auto.
+ destruct IHxs as [q ?]; auto.
exists q. apply app_elem; auto.
Qed.
Definition powerdomain sort (X:PLT.PLT hf) :=
PLT.Ob hf (pdom_elem X)
(PLT.Class _ _
(match sort with
| Lower => lower_preord_mixin (PLT.ord X)
| Upper => upper_preord_mixin (PLT.ord X)
| Convex => convex_preord_mixin (PLT.ord X)
end)
(pdom_effective (PLT.ord X) (PLT.effective X) sort)
(pdom_plt (PLT.ord X) (PLT.effective X) (PLT.plotkin X) sort)).
Section powerdomain_fmap.
Variables X Y:PLT.PLT hf.
Variable f: X → Y.
Definition fmap_upper (x:pdom_elem X) (y:pdom_elem Y) :=
forall a, a ∈ elem x -> exists b, b ∈ elem y /\ (a,b) ∈ PLT.hom_rel f.
Definition fmap_lower (x:pdom_elem X) (y:pdom_elem Y) :=
forall b, b ∈ elem y -> exists a, a ∈ elem x /\ (a,b) ∈ PLT.hom_rel f.
Definition fmap_convex x y :=
fmap_lower x y /\ fmap_upper x y.
Lemma fmap_upper_semidec x y : semidec (fmap_upper x y).
Proof.
unfold fmap_upper.
apply all_finset_semidec.
- intros.
destruct H0 as [q [??]]. exists q; split; auto.
apply member_eq with (a,q); auto.
destruct H; split; split; auto.
- intros.
apply ex_finset_semidec.
+ intros.
apply member_eq with (a,a0); auto.
destruct H; split; split; auto.
+ intros. apply semidec_in.
apply OrdDec.
apply (eff_ord_dec (PLT.prod X Y)).
apply PLT.effective.
Qed.
Lemma fmap_lower_semidec x y : semidec (fmap_lower x y).
Proof.
unfold fmap_lower.
apply all_finset_semidec.
- intros.
destruct H0 as [q [??]]. exists q; split; auto.
apply member_eq with (q,a); auto.
destruct H; split; split; auto.
- intros.
apply ex_finset_semidec.
+ intros.
apply member_eq with (a0,a); auto.
destruct H; split; split; auto.
+ intros. apply semidec_in.
apply OrdDec.
apply (eff_ord_dec (PLT.prod X Y)).
apply PLT.effective.
Qed.
Lemma fmap_convex_semidec x y : semidec (fmap_convex x y).
Proof.
unfold fmap_convex. apply semidec_conj.
- apply fmap_lower_semidec.
- apply fmap_upper_semidec.
Qed.
Definition fmap_lower_rel : erel (pdom_ord X Lower) (pdom_ord Y Lower) :=
@esubset (prod_preord (pdom_ord X Lower) (pdom_ord Y Lower))
(fun z => fmap_lower (fst z) (snd z))
(fun z => fmap_lower_semidec (fst z) (snd z))
(eff_enum _ (effective_prod (pdom_effective X (PLT.effective X) Lower)
(pdom_effective Y (PLT.effective Y) Lower))).
Definition fmap_upper_rel : erel (pdom_ord X Upper) (pdom_ord Y Upper) :=
@esubset (prod_preord (pdom_ord X Upper) (pdom_ord Y Upper))
(fun z => fmap_upper (fst z) (snd z))
(fun z => fmap_upper_semidec (fst z) (snd z))
(eff_enum _ (effective_prod (pdom_effective X (PLT.effective X) Upper)
(pdom_effective Y (PLT.effective Y) Upper))).
Definition fmap_convex_rel :=
@esubset (prod_preord (pdom_ord X Convex) (pdom_ord Y Convex))
(fun z => fmap_convex (fst z) (snd z))
(fun z => fmap_convex_semidec (fst z) (snd z))
(eff_enum _ (effective_prod (pdom_effective X (PLT.effective X) Convex)
(pdom_effective Y (PLT.effective Y) Convex))).
Definition fmap_rel sort :=
match sort with
| Lower => fmap_lower_rel
| Upper => fmap_upper_rel
| Convex => fmap_convex_rel
end.
Definition fmap_spec sort x y :=
match sort with
| Lower => fmap_lower x y
| Upper => fmap_upper x y
| Convex => fmap_convex x y
end.
Lemma fmap_convex_swell
(z : powerdomain Convex X)
(x y: powerdomain Convex Y) :
fmap_spec Convex z x ->
fmap_spec Convex z y ->
exists z0:finset Y,
(forall b, b ∈ z0 -> exists a, a ∈ elem z /\ (a,b) ∈ PLT.hom_rel f) /\
(forall a, a ∈ elem z -> exists b, b ∈ z0 /\ (a,b) ∈ PLT.hom_rel f) /\
(forall c, c ∈ elem x -> exists m, m ∈ z0 /\ c ≤ m) /\
(forall d, d ∈ elem y -> exists m, m ∈ z0 /\ d ≤ m) /\
(forall m, m ∈ z0 -> exists c, c ∈ elem x /\ c ≤ m) /\
(forall m, m ∈ z0 -> exists d, d ∈ elem y /\ d ≤ m).
Proof.
intros [??] [??].
hnf in H, H0, H1, H2.
set (M := mub_closure (PLT.plotkin Y) (elem x ++ elem y)).
set (INV (z0:finset Y) :=
(forall b, b ∈ z0 -> exists a, a ∈ elem z /\ (a,b) ∈ PLT.hom_rel f) /\
(forall a, a ∈ elem z -> exists b, b ∈ z0 /\ (a,b) ∈ PLT.hom_rel f) /\
(forall m, m ∈ z0 -> exists c, c ∈ elem x /\ c ≤ m) /\
(forall m, m ∈ z0 -> exists d, d ∈ elem y /\ d ≤ m)).
set (P (z0:finset Y) :=
(forall c, c ∈ elem x -> exists m, m ∈ z0 /\ c ≤ m) /\
(forall d, d ∈ elem y -> exists m, m ∈ z0 /\ d ≤ m)).
destruct (swelling_lemma Y (PLT.effective Y) M INV P)
as [z0 [?[??]]]; [ | | exists z0; hnf in H4, H5; intuition ].
- intros. unfold P.
destruct (finset_find_dec' Y (fun c => exists m, m ∈ z0 /\ c ≤ m))
with (elem x).
+ intros. destruct H6 as [m [??]].
exists m; split; auto. rewrite <- H5; auto.
+ intro c.
destruct (finset_find_dec Y (fun m => c ≤ m)) with z0.
* simpl; intros. rewrite <- H5; auto.
* apply (eff_ord_dec _ (PLT.effective Y)).
* destruct s as [s [??]]. left; eauto.
* right; intros [?[??]]. apply (n x0); auto.
+ right.
destruct s as [c [??]].
destruct (H c) as [a [??]]; auto.
destruct (H2 a) as [d [??]]; auto.
destruct (PLT.hom_directed hf X Y f a (c::d::nil)) as [q [??]].
{ eapply directed.elem_inh. apply cons_elem; left; auto. }
{ red; intros.
apply cons_elem in H11. destruct H11. rewrite H11.
apply erel_image_elem. auto.
apply cons_elem in H11. destruct H11. rewrite H11.
apply erel_image_elem. auto.
apply nil_elem in H11. elim H11.
}
apply erel_image_elem in H12.
destruct (mub_complete (PLT.plotkin Y) (c::d::nil) q) as [q' [??]].
{ eapply directed.elem_inh. apply cons_elem; left; auto. }
{ auto. }
exists q'. split.
* unfold M.
apply (mub_clos_mub (PLT.plotkin Y) (elem x ++ elem y) (c::d::nil)).
{ eapply directed.elem_inh. apply cons_elem; left; auto. }
{ apply cons_subset.
apply mub_clos_incl. apply app_elem; auto.
apply cons_subset.
apply mub_clos_incl. apply app_elem; auto.
apply nil_subset.
}
auto.
* split.
** intro.
elim H6.
exists q'. split; auto. apply H13.
apply cons_elem; auto.
** hnf. repeat split; intros.
*** apply cons_elem in H15. destruct H15.
**** exists a. split; auto.
apply PLT.hom_order with a q; auto.
rewrite H15; auto.
**** destruct H4 as [?[?[??]]].
apply H4; auto.
*** destruct H4 as [?[?[??]]].
destruct (H16 a0) as [t [??]]; auto.
exists t; split; auto.
apply cons_elem; auto.
*** apply cons_elem in H15. destruct H15.
**** exists c. split; auto.
rewrite H15. apply H13. apply cons_elem; auto.
**** destruct H4 as [?[?[??]]].
apply H17; auto.
*** apply cons_elem in H15. destruct H15.
**** exists d. split; auto.
rewrite H15. apply H13.
apply cons_elem; right.
apply cons_elem; auto.
**** destruct H4 as [?[?[??]]].
apply H18; auto.
+ destruct (finset_find_dec' Y (fun c => exists m, m ∈ z0 /\ c ≤ m))
with (elem y).
* intros. destruct H6 as [m [??]].
exists m; split; auto. rewrite <- H5; auto.
* intro c.
destruct (finset_find_dec Y (fun m => c ≤ m)) with z0.
** simpl; intros. rewrite <- H5; auto.
** apply (eff_ord_dec _ (PLT.effective Y)).
** destruct s as [s [??]]. left; eauto.
** right; intros [?[??]]. apply (n x0); auto.
* right.
destruct s as [d [??]].
destruct (H1 d) as [a [??]]; auto.
destruct (H0 a) as [c [??]]; auto.
destruct (PLT.hom_directed hf X Y f a (c::d::nil)) as [q [??]].
{ eapply directed.elem_inh. apply cons_elem; left; auto. }
{ red; intros.
apply cons_elem in H11. destruct H11. rewrite H11.
apply erel_image_elem. auto.
apply cons_elem in H11. destruct H11. rewrite H11.
apply erel_image_elem. auto.
apply nil_elem in H11. elim H11.
}
apply erel_image_elem in H12.
destruct (mub_complete (PLT.plotkin Y) (c::d::nil) q) as [q' [??]].
{ eapply directed.elem_inh. apply cons_elem; left; auto. }
{ auto. }
exists q'. split.
** unfold M.
apply (mub_clos_mub (PLT.plotkin Y) (elem x ++ elem y) (c::d::nil)).
{ eapply directed.elem_inh. apply cons_elem; left; auto. }
{ apply cons_subset.
apply mub_clos_incl. apply app_elem; auto.
apply cons_subset.
apply mub_clos_incl. apply app_elem; auto.
apply nil_subset.
}
auto.
** split.
*** intro.
elim H6.
exists q'. split; auto. apply H13.
apply cons_elem; right.
apply cons_elem; auto.
*** hnf. repeat split; intros.
**** apply cons_elem in H15. destruct H15.
***** exists a. split; auto.
apply PLT.hom_order with a q; auto.
rewrite H15; auto.
***** destruct H4 as [?[?[??]]].
apply H4; auto.