-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lists.v
1046 lines (916 loc) · 22.7 KB
/
Lists.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
From Coq Require Import FunctionalExtensionality ProofIrrelevance
List Lia Eqdep IndefiniteDescription.
Import ListNotations Nat.
From Corec Require Export Sum Exp.
Definition LIST(T:Type) : Type :=
SUM (fun n => EXP (BELOW n) T).
Definition LIST_Poset(P:Poset) : Poset :=
SUM_Poset (fun n => EXP_Poset (BELOW n) P).
Definition LIST_PPO(P:PPO) : PPO :=
SUM_PPO (fun n => EXP_PPO (BELOW n) P).
Definition LIST_bot(P:PPO) :=
sum_bot (fun x : nat => BELOW x -> P).
Definition LIST_CPO(C:CPO) : CPO :=
SUM_CPO (fun n => EXP_CPO (BELOW n) C).
Definition LIST_ALGEBRAIC(A:ALGEBRAIC) : ALGEBRAIC :=
SUM_ALGEBRAIC (fun n => EXP_BELOW_ALGEBRAIC n A).
Definition LIST_completion(P:PPO)(T:COMPLETION P):COMPLETION (LIST_PPO P) :=
sum_completion (fun n => EXP_PPO (BELOW n) _) (fun n => exp_below_completion n _ T).
Definition list2EXP{T:Type}(d:T) (N: nat)(l : list T):
EXP (BELOW N) T := (fun i => nth i l d).
Program Definition EXP2list{T:Type}(N: nat) (e :EXP (BELOW N) T) :
list T :=
match N with
| 0 => []
| S N' => bEXP2list N' e
end .
Next Obligation.
intros.
exact Heq_N.
Defined.
Lemma length_EXP2list{T:Type}: forall N (e: EXP (BELOW N) T),
length (EXP2list N e) = N.
Proof.
destruct N; intro e; auto.
apply blength_EXP2list.
Qed.
Lemma nth_EXP2LIST{T:Type}(d:T):
forall N (e: EXP (BELOW N) T) (i: nat) (Hi : (i < N)%nat),
nth i (EXP2list N e) d = e {| nval:= i; is_below := Hi |}.
Proof.
destruct N ; intros; try lia.
cbn.
now rewrite bnth_EXP2list with (Hi := Hi).
Qed.
Lemma EXP2list2EXP{T:Type}: forall (d:T) n e, (
list2EXP d n (EXP2list n e)) = e.
Proof.
intros d n e.
extensionality x.
unfold list2EXP.
unshelve erewrite nth_EXP2LIST.
+
now destruct x.
+
do 2 f_equal.
Qed.
Lemma blist2EXP2list{T:Type}:
forall (d:T) N l, length l = S N -> bEXP2list N (list2EXP d (S N) l) = l.
Proof.
intro d.
induction N; intros l Heq.
-
destruct l; cbn in Heq ; try lia.
destruct l; cbn in Heq ; try lia.
reflexivity.
-
destruct l; cbn in Heq; try lia.
apply eq_add_S in Heq.
specialize (IHN _ Heq).
cbn in *.
f_equal.
replace (list2EXP d (S N) l) with
(bshift N
(fun x : BELOW (S (S N)) =>
match nval (S (S N)) x with
| 0 => t
| S m => nth m l d
end)); auto.
Qed.
Lemma list2EXP2list{T:Type}:
forall (d:T) N l, length l = N -> EXP2list N (list2EXP d N l) = l.
Proof.
intros d N l Heq.
destruct N.
-
destruct l ;cbn in Heq; try lia.
reflexivity.
-
cbn.
now apply blist2EXP2list.
Qed.
Inductive List(T:Type) : Type :=
|list_inj : list T -> List T
|list_bot : List T.
Definition List2LIST{T:Type}(d:T)(l : List T) : LIST T :=
match l with
| list_inj _ l' =>
sum_inj _ (length l') (list2EXP d (length l') l')
| list_bot _ => sum_bot _
end.
Definition LIST2List{T:Type}(L:LIST T) : List T :=
match L with
| sum_inj _ j x =>
list_inj _ (EXP2list j x)
| sum_bot _ => list_bot _
end.
Lemma List2LIST2List{T:Type} (d:T): forall (l : List T),
LIST2List(List2LIST d l) = l.
Proof.
intro l.
destruct l ; auto.
cbn.
f_equal.
rewrite list2EXP2list; auto.
Qed.
Lemma LIST2List2LIST{T:Type} (d:T): forall (L : LIST T),
List2LIST d (LIST2List L) = L.
Proof.
intro L.
destruct L ; auto.
cbn.
f_equal.
rewrite length_EXP2list.
now rewrite EXP2list2EXP.
Qed.
Inductive List_le{P: PPO} : List P -> List P -> Prop :=
|List_le_bot : forall l, List_le (list_bot P) l
|List_le_list : forall l1 l2, length l1 = length l2 ->
(forall i, (i < length l1)%nat ->
(nth i l1 ppo_bot) <=(nth i l2 ppo_bot))
-> List_le (list_inj _ l1) (list_inj _ l2).
Lemma List_le_refl{P:PPO} : forall (l : List P), List_le l l.
Proof.
induction l.
- constructor; auto.
intros; apply poset_refl.
-
constructor.
Qed.
Lemma List_le_trans{P:PPO} : forall (l1 l2 l3:List P),
List_le l1 l2 -> List_le l2 l3 -> List_le l1 l3.
Proof.
intros l1 l2 l3 Hl1l2.
revert l3.
induction Hl1l2; intros l3 Hl2l3.
-
constructor.
-
inversion Hl2l3; subst.
constructor.
+
congruence.
+
intros i Hlt.
specialize (H0 _ Hlt).
rewrite H in Hlt.
specialize (H3 _ Hlt).
eapply poset_trans; eauto.
Qed.
Lemma List_le_antisym{P:PPO} : forall (l1 l2:List P),
List_le l1 l2 -> List_le l2 l1 -> l1 = l2.
Proof.
intros l1 l2 Hl1l2.
induction Hl1l2; intro Hl2l3.
-
now inversion Hl2l3.
-
f_equal.
apply nth_ext with (d := ppo_bot) (d' := ppo_bot); auto.
intros n Hlt.
apply poset_antisym.
+
now apply H0.
+
inversion Hl2l3; subst.
apply H4.
now rewrite H3.
Qed.
Definition List_Poset(P:PPO) : Poset :=
{|
poset_carrier := List P;
poset_le := List_le;
poset_refl := List_le_refl;
poset_trans := List_le_trans;
poset_antisym := List_le_antisym
|}.
Definition List_PPO(P:PPO) : PPO :=
{|
ppo_poset := List_Poset P;
ppo_bot := list_bot P;
ppo_bot_least := List_le_bot
|}.
Lemma LIST2List_monotonic{P:PPO}:
forall (L1 L2 : LIST_PPO P), L1 <= L2 ->
List_le (LIST2List L1) (LIST2List L2).
Proof.
intros L1 L2 Hle.
unfold LIST2List; cbn.
inversion Hle; subst; cbn.
-
constructor.
-
cbn.
constructor.
+
now do 2 rewrite length_EXP2list.
+
intros i Hlt.
rewrite length_EXP2list in Hlt.
do 2 (erewrite nth_EXP2LIST; eauto).
Unshelve.
assumption.
Qed.
Lemma List2LIST_monotonic{P:PPO}:
forall (L1 L2 : List_PPO P), List_le L1 L2 ->
@poset_le (LIST_PPO P) (List2LIST (@ppo_bot P) L1)
(List2LIST ppo_bot L2).
Proof.
intros L1 L2 Hle.
unfold List2LIST.
inversion Hle.
-
cbn.
constructor.
-
destruct l1, l2; cbn in H; try lia.
*
apply sum_le_refl.
*
cbn.
unfold list2EXP.
cbn.
apply PeanoNat.Nat.succ_inj in H.
rewrite H.
constructor.
intro j.
destruct j; cbn.
destruct nval.
--
apply (H0 0); cbn; lia.
--
apply (H0 (S nval)); cbn; lia.
Qed.
Lemma LIST2List_rev_monotonic{P:PPO}:
forall (L1 L2 : LIST_PPO P),
List_le (LIST2List L1) (LIST2List L2) -> L1 <= L2.
Proof.
intros L1 L2 Hle.
replace L1 with (List2LIST ppo_bot (LIST2List L1));
[| now rewrite LIST2List2LIST].
replace L2 with (List2LIST ppo_bot (LIST2List L2));
[| now rewrite LIST2List2LIST].
now apply List2LIST_monotonic.
Qed.
Lemma LIST2List_injective{P:PPO}: forall (L1 L2 : LIST_PPO P),
(LIST2List L1) =
(LIST2List L2) -> L1 = L2.
Proof.
intros L1 L2 Heq.
apply poset_antisym;
apply LIST2List_rev_monotonic;
rewrite Heq;
apply List_le_refl.
Qed.
Lemma List2LIST_rev_monotonic{P:PPO}:
forall (L1 L2 : List_PPO P),
@poset_le (LIST_PPO P) (List2LIST (@ppo_bot P) L1)
(List2LIST ppo_bot L2) -> List_le L1 L2.
Proof.
intros l1 l2 Hle.
replace l1 with (LIST2List (List2LIST ppo_bot l1));
[| now rewrite List2LIST2List].
replace l2 with (LIST2List (List2LIST ppo_bot l2));
[| now rewrite List2LIST2List].
now apply LIST2List_monotonic.
Qed.
Lemma List2LIST_injective{P:PPO}: forall (L1 L2 : List_PPO P),
(List2LIST ppo_bot L1) =
(List2LIST ppo_bot L2) -> L1 = L2.
Proof.
intros L1 L2 Heq.
apply poset_antisym;
apply List2LIST_rev_monotonic;
rewrite Heq;
apply poset_refl.
Qed.
Definition bij_LIST_PPO_List_PPO{P:PPO}: BIJECTION (LIST_PPO P) (List_PPO P):=
{|
to := LIST2List;
from := List2LIST ppo_bot;
to_from := List2LIST2List ppo_bot;
from_to := LIST2List2LIST ppo_bot
|}.
Definition ppo_iso_LIST_PPO_List_PPO{P:PPO} : Poset_ISOMORPHISM (LIST_PPO P) (List_PPO P):=
{|
b:= bij_LIST_PPO_List_PPO;
to_mono := LIST2List_monotonic;
from_mono := List2LIST_monotonic
|}.
Program
Definition List_CPO(C:CPO) : CPO :=
{|
cpo_ppo := List_PPO C;
cpo_lub :=
fun S => match (oracle (is_directed S )) with
left Hd => (proj1_sig
(@cpo_from_poset_iso (LIST_CPO C) (List_PPO C)
ppo_iso_LIST_PPO_List_PPO S Hd))
| right _ => list_bot _
end
;
cpo_lub_prop :=_
|}.
Next Obligation.
cbn.
intros.
destruct ( oracle (is_directed (P := List_Poset C) S) );
[| contradiction].
apply (proj2_sig
(@cpo_from_poset_iso (LIST_CPO C) (List_PPO C)
ppo_iso_LIST_PPO_List_PPO S i)).
Qed.
Lemma LIST2List_cont{P: CPO}:
is_continuous (P1:= LIST_CPO P)(P2 := List_CPO P) LIST2List.
Proof.
remember (@ppo_iso_cpo_iso (LIST_CPO P) (List_CPO P)
(@ppo_iso_LIST_PPO_List_PPO P)) as Hci.
replace LIST2List with (to Hci); [| now rewrite HeqHci].
apply to_is_continuous.
Qed.
Lemma List2LIST_cont{P: CPO}:
is_continuous (P1:= List_CPO P)(P2 := LIST_CPO P)
(List2LIST ppo_bot).
Proof.
remember (@ppo_iso_cpo_iso (LIST_CPO P) (List_CPO P)
(@ppo_iso_LIST_PPO_List_PPO P)) as Hci.
replace (List2LIST ppo_bot) with (from Hci); [| now rewrite HeqHci].
apply from_is_continuous.
Qed.
Lemma my_algebraic_dir{A : ALGEBRAIC}:
forall (c : List_CPO A), is_directed (compacts_le c).
Proof.
intro c.
cbn in c.
specialize (@ppo_iso_LIST_PPO_List_PPO A) as Hi.
apply Poset_ISOMORPHISM_sym in Hi.
eapply isomorphic_directed_rev with (Iso := Hi).
specialize (@algebraic_dir (LIST_ALGEBRAIC A) (to Hi c)) as Had.
replace
((@fmap (List_PPO A) (LIST_PPO A) (@compacts_le
(List_CPO A) c) (@to (List_PPO A) (LIST_PPO A) Hi))) with
(@compacts_le (LIST_ALGEBRAIC A)(@to (List_PPO A)(LIST_PPO A) Hi c)); auto.
remember (Poset_ISOMORPHISM_sym _ _ Hi) as Hi'.
specialize (@ppo_isomorphic_compact_le (LIST_CPO A)(List_CPO A) Hi' (from Hi' c)) as Hcle.
rewrite to_from in *.
now subst.
Qed.
Lemma my_algebraic_lub{A:ALGEBRAIC}:
forall (c : List_CPO A), c = cpo_lub (compacts_le c).
Proof.
intro c.
apply is_lub_cpo_lub_eq.
specialize (@ppo_iso_LIST_PPO_List_PPO A) as Hi.
apply Poset_ISOMORPHISM_sym in Hi.
unshelve erewrite <- ppo_isomorphic_compact_le.
-
exact (LIST_ALGEBRAIC A).
-
apply Hi.
-
cbn in c.
specialize (@algebraic_lub (LIST_ALGEBRAIC A) (to Hi c)) as Hala.
specialize (cpo_lub_prop (compacts_le (P:= LIST_ALGEBRAIC A) (to Hi c)) (algebraic_dir (a:= LIST_ALGEBRAIC A) (to Hi c))) as Hclp.
rewrite <- Hala in Hclp.
clear Hala.
remember (to Hi c) as c'.
replace c with (from Hi (to Hi c)); [|apply from_to].
rewrite <- Heqc'.
rewrite to_from.
remember ((compacts_le (P:= LIST_ALGEBRAIC A) c')) as S'.
now apply lub_fmap_iso.
-
apply my_algebraic_dir.
Qed.
Lemma LIST2List_compact{P:CPO}:
forall (L : LIST P), is_compact (P:= LIST_CPO P) L ->
is_compact (P := List_CPO P) (LIST2List L).
Proof.
intros L Hc.
remember (@ppo_iso_cpo_iso (LIST_CPO P) (List_CPO P)
(@ppo_iso_LIST_PPO_List_PPO P)) as Hci.
remember (@isomorphic_compact _ _ Hci) as Hic.
replace LIST2List with (to Hci); [| now rewrite HeqHci].
now apply Hic.
Qed.
Lemma List2LIST_compact{P:CPO}:
forall (L : List P), is_compact (P:= List_CPO P) L ->
is_compact (P := LIST_CPO P) (List2LIST ppo_bot L).
Proof.
intros L Hc.
remember (@ppo_iso_cpo_iso (LIST_CPO P) (List_CPO P)
(@ppo_iso_LIST_PPO_List_PPO P)) as Hci.
remember (CPO_ISOMORPHISM_sym _ _ Hci) as Hci'.
remember (@isomorphic_compact _ _ Hci') as Hic'.
replace (List2LIST ppo_bot) with (to Hci');
[now apply Hic' |].
now subst.
Qed.
Definition List_ALGEBRAIC (A:ALGEBRAIC): ALGEBRAIC :=
{|
algebraic_cpo := List_CPO A;
algebraic_dir := my_algebraic_dir;
algebraic_lub :=my_algebraic_lub
|}.
Program Definition List_completion (P:PPO)(M:COMPLETION P) :
COMPLETION (List_PPO P) :=
{|
alg := List_ALGEBRAIC M;
inject := fun x =>
LIST2List (@inject _ (LIST_completion P M) ((List2LIST ppo_bot x)));
rev_inj := fun c =>
match (oracle (is_compact c)) with
left _ => LIST2List (@rev_inj _ (LIST_completion P M) (List2LIST ppo_bot c))
| right _ => list_bot _
end
|}.
Next Obligation.
intros; reflexivity.
Qed.
Next Obligation.
intros P M p p'.
split; intro Hle.
-
apply LIST2List_monotonic; auto.
rewrite <- (inject_bimono (LIST_completion P M)).
now apply List2LIST_monotonic.
-
apply LIST2List_rev_monotonic in Hle.
rewrite <- (inject_bimono (LIST_completion P M)) in Hle.
now apply List2LIST_rev_monotonic in Hle.
Qed.
Next Obligation.
intros.
apply LIST2List_compact.
apply (@inject_compact (LIST_PPO P) (LIST_completion P M)).
Qed.
Next Obligation.
intros.
unfold "°".
destruct (oracle (is_compact cc)) as [Hc | n];
[| exfalso; now apply n].
split; intro Heq.
-
rewrite <- Heq.
rewrite LIST2List2LIST.
rewrite inject_rev_inj;
[now rewrite List2LIST2List |].
now apply List2LIST_compact.
-
rewrite <- Heq.
rewrite LIST2List2LIST.
rewrite rev_inj_inject.
now rewrite List2LIST2List.
Qed.
Program Definition nrev{N: nat} (i : BELOW N) : BELOW N :=
{|nval := N - 1 - (nval _ i) |}.
Next Obligation.
intros N i.
destruct i.
cbn.
lia.
Qed.
Lemma nrev_inv{N:nat} : forall (i : BELOW N),
nrev (nrev i) = i.
Proof.
intro i.
destruct i.
unfold nrev.
cbn.
apply BELOW_equal.
lia.
Qed.
Definition frev{C:CPO} (L : LIST_CPO C) :=
match L with
| sum_bot _ => sum_bot _
| sum_inj _ N f => sum_inj _ N (fun i : BELOW N => f (nrev i))
end.
Lemma frev_inv{C:CPO} (L : LIST_CPO C) : frev (frev L) = L.
Proof.
destruct L; auto.
cbn.
f_equal.
extensionality i.
now rewrite nrev_inv.
Qed.
Lemma frev_mono{C:CPO} :
is_monotonic (P1 := LIST_CPO C) (P2 := LIST_CPO C) frev.
Proof.
intros L L' Hle.
inversion Hle; subst.
-
constructor.
-
constructor.
intros i .
assert (Ha : forall i, p1 i <= p2 i); [apply H |].
apply Ha.
Qed.
Lemma frev_is_continuous{C:CPO} :
is_continuous (P1 := LIST_CPO C) (P2 := LIST_CPO C) frev.
Proof.
rewrite continuous_iff_mono_commutes.
split; [apply frev_mono |].
intros S l Hd Hl.
destruct Hl as (Hu & Hl) .
split.
-
intros y (z & Hm & Heq); subst.
apply frev_mono.
now apply Hu.
-
intros y Huy.
replace y with (frev (frev y)); [| now apply frev_inv].
apply frev_mono.
apply Hl.
intros u Hmu.
replace u with (frev (frev u)); [| now apply frev_inv].
apply frev_mono.
apply Huy.
now apply member_fmap.
Qed.
Definition revb{T:Type}(f : List T) : List T :=
match f with
list_bot _ => list_bot _
|list_inj _ l => list_inj _ (rev l)
end.
Lemma revb_frev{P:CPO}: (*forall (f : List_CPO P),*)
revb = (LIST2List ° (frev(C:= P)° (List2LIST ppo_bot ))).
Proof.
extensionality f.
destruct f; auto.
cbn.
f_equal.
apply nth_ext with (d := ppo_bot)(d' := ppo_bot).
-
cbn.
rewrite length_EXP2list.
apply rev_length.
-
rewrite rev_length.
intros n Hlt.
unshelve erewrite nth_EXP2LIST; eauto.
unfold list2EXP.
cbn.
rewrite rev_nth; auto.
f_equal.
lia.
Qed.
Lemma revb_is_monotonic{P:CPO}:
is_monotonic (P1 := List_Poset P)(P2 := List_Poset P) revb.
Proof.
rewrite revb_frev.
apply (comp_is_monotonic
(P1 := List_Poset P)
(P2 := LIST_Poset P)
(P3 := List_Poset P)).
-
intros x y Hle.
now apply LIST2List_monotonic.
-
apply (comp_is_monotonic
(P1 := List_Poset P)
(P2 := LIST_Poset P)
(P3 := LIST_Poset P)).
+
apply frev_mono.
+
intros x y Hle.
now apply List2LIST_monotonic.
Qed.
Lemma revb_is_continuous{P:CPO}:
is_continuous (P1 := List_CPO P)(P2 := List_CPO P) revb.
Proof.
rewrite revb_frev.
apply (comp_is_continous
(P1 := List_CPO P)
(P2 := LIST_CPO P)
(P3 := List_CPO P)).
-
apply LIST2List_cont.
-
apply (comp_is_continous
(P1 := List_CPO P)
(P2 := LIST_CPO P)
(P3 := LIST_CPO P)).
+
apply frev_is_continuous.
+
apply List2LIST_cont.
Qed.
Definition mapb{T1 T2: Type}(f : T1 -> T2)(l : List T1):
List T2 :=
match l with
list_bot _ => list_bot _
| list_inj _ l' => list_inj _ (map f l')
end.
Lemma mapb_monotonic_in_func{P1 P2: CPO} : forall (f g:P1->P2),
(forall x, f x <= g x) ->
forall l,
List_le (mapb f l) (mapb g l).
Proof.
intros f g Ha l.
destruct l ; [ | apply List_le_refl].
destruct l ; [apply List_le_refl|].
cbn.
constructor.
-
cbn.
now do 2 rewrite map_length.
-
cbn.
rewrite map_length.
intros i Hlt.
destruct i; [apply Ha |].
rewrite nth_indep with (d' := f ppo_bot);
[| rewrite map_length;lia].
rewrite map_nth.
rewrite nth_indep with (d' := g ppo_bot);
[| rewrite map_length; lia].
rewrite map_nth.
apply Ha.
Qed.
Definition list_le{P:PPO}(l1 l2 : list P) := List_le (list_inj _ l1) (list_inj _ l2).
Lemma list_le_refl{P:PPO}: forall (l: list P),
list_le l l.
Proof.
intro l.
apply List_le_refl.
Qed.
Lemma list_le_trans{P:PPO}: forall (l1 l2 l3: list P),
list_le l1 l2 -> list_le l2 l3 -> list_le l1 l3.
Proof.
intros l1 l2 l3 Hle1 Hle2.
eapply List_le_trans ; eauto.
Qed.
Lemma list_le_antisym{P:PPO}: forall (l1 l2: list P),
list_le l1 l2 -> list_le l2 l1 -> l1 = l2.
Proof.
intros l1 l2 Hle1 Hle2.
apply List_le_antisym in Hle1; auto.
injection Hle1; intros; now subst.
Qed.
Definition list_Poset(P:PPO) : Poset :=
{|
poset_carrier := list P;
poset_le := list_le;
poset_refl := list_le_refl;
poset_trans := list_le_trans;
poset_antisym := list_le_antisym
|}.
Definition get_list{X:Type}(L : List X):
list X :=
match L with
list_bot _ => nil
| list_inj _ l => l
end.
Lemma get_list_mono{P:PPO} :
forall (l1 l2 : list P),
list_le l1 l2 ->
list_le (P := P)
(get_list ((list_inj _) l1) )
(get_list ((list_inj _) l2)).
Proof.
now intros l1 l2 Hle.
Qed.
Lemma list_inj_get_list{P:Type}:
forall (L : List P),
L <> list_bot P ->
L = (list_inj P) (get_list L).
Proof.
intros [l |] Hne; auto.
contradiction.
Qed.
Definition dcpo_lub{P:CPO} (S: Setof (list P)) :=
get_list (cpo_lub (c := List_CPO P) (fmap S (list_inj P))).
Lemma list_inj_mono{P:PPO}:
is_monotonic (P1 := list_Poset P)(P2 := List_Poset P)
(list_inj P).
Proof.
now intros x y Hle.
Qed.
Lemma list_inj_rev_mono{P:PPO}:
is_rev_monotonic (P1 := list_Poset P)(P2 := List_Poset P)
(list_inj P).
Proof.
now intros x y Hle.
Qed.
Lemma list_inj_injective{P:Type} : is_injective (list_inj P).
Proof.
intros x y Heq.
now inversion Heq.
Qed.
Lemma directed_cpo_fmap_ne{P:CPO}:
forall (S : Setof (list P)),
is_directed (P := list_Poset P) S ->
cpo_lub (c:= List_CPO P) (fmap S (list_inj P)) <> list_bot P.
Proof.
intros S Hd Habs.
assert (HdT : is_directed (P := List_Poset P) (fmap S
(list_inj P))).
{
apply (monotonic_directed (P1 := list_Poset P) (P2 := List_Poset P));
auto.
apply list_inj_mono.
}
specialize (cpo_lub_prop (c := List_CPO P)_ HdT) as Hcp.
destruct Hcp as (Hu' & _).
rewrite Habs in Hu'.
destruct HdT as (Hne & _).
rewrite not_empty_member in Hne.
destruct Hne as (y & Hy).
specialize (Hu' _ Hy).
apply (le_bot_eq (P := List_PPO P) y) in Hu'.
subst.
destruct Hy as (w & Hmw & Heqw).
discriminate.
Qed.
Lemma dcpo_lub_is_lub{P:CPO} : forall (S: Setof (list P)),
is_directed (P := list_Poset P) S ->
is_lub (P := list_Poset P) S (dcpo_lub S).
Proof.
intros S Hd.
remember (fmap S (list_inj P)) as T.
assert (HdT : is_directed (P := List_Poset P) T).
{
subst.
apply (monotonic_directed (P1 := list_Poset P) (P2 := List_Poset P));
auto.
apply list_inj_mono.
}
specialize (cpo_lub_prop (c := List_CPO P)_ HdT) as Hcp.
specialize Hcp as Hcp'.
destruct Hcp' as (Hu & Hm).
specialize (directed_cpo_fmap_ne _ Hd) as HnT.
split.
-
intros x Hmx.
apply list_inj_rev_mono.
assert (Hmx': member T (list_inj _ x)) by
(subst; now exists x).
eapply poset_trans ; eauto.
unfold dcpo_lub.
rewrite <- list_inj_get_list;
[subst ; apply poset_refl |].
apply HnT.
-
intros y Huy.
cbn in y.
assert (Hle' : cpo_lub (c:= List_CPO P) T <= list_inj _ y).
{
apply Hm.
subst.
intros x Hmx.
destruct Hmx as (w & Hmw & Heq); subst.
specialize (Huy _ Hmw).
now apply list_inj_mono.
}
remember (cpo_lub (c:= List_CPO P) T) as C.
destruct C.
+
unfold dcpo_lub.
subst.
now rewrite <- HeqC.
+
exfalso.
subst.
now apply HnT.
Qed.
Lemma map_mono_in_func{P1 P2:PPO} :
forall (l : list P1),
is_monotonic (P1 := EXP_Poset P1 P2) (P2 := list_Poset P2)
(fun g : EXP_Poset P1 P2 => map g l).
Proof.
intros l f g Hle.
cbn in Hle.
cbn.
constructor.
-
now do 2 rewrite map_length.
-
rewrite map_length.
intros i Hlt.
rewrite nth_indep with (d' := f ppo_bot); [|now rewrite map_length].
rewrite map_nth.
remember (f (nth i l ppo_bot)) as u.
rewrite nth_indep with (d' := g ppo_bot); [|now rewrite map_length].
rewrite map_nth.
subst.
apply Hle.
Qed.
Lemma fmap_preserves_dir{P1 P2: PPO}:
forall (l: list P1)(S : Setof (EXP P1 P2)),
is_directed (P := EXP_Poset P1 P2) S ->
is_directed (P := list_Poset P2)
(fmap S (fun g => map g l)).
Proof.
intros l S Hd.
apply (@monotonic_directed (EXP_Poset P1 P2)
(list_Poset P2)); auto.
apply map_mono_in_func.
Qed.
Lemma mapb_continuous_in_func{P1 P2: CPO} :
forall (l : List P1),
is_continuous (P1 := EXP_CPO P1 P2) (P2 := List_CPO P2)
(fun g => mapb g l).
Proof.
intros [l|];
[| cbn ; apply
(@cst_is_continous(EXP_CPO P1 P2) (List_CPO P2))].
intros S Hd; split.
{
apply monotonic_directed; auto.
intros x y Hle.
now apply mapb_monotonic_in_func.
}
cbn [mapb].
replace (fun g:(EXP_CPO P1 P2) => list_inj P2 (map g l))
with ((list_inj P2) ° (fun g => (map g l))); auto.
rewrite fmap_comp.
specialize Hd as Hd'.
apply fmap_preserves_dir with (l := l) in Hd'.
unfold EXP in Hd'.
specialize Hd' as Hd''.
apply directed_cpo_fmap_ne in Hd''.
Opaque cpo_lub.
cbn in *.
remember (fmap S (fun g : P1 -> P2 => map g l)) as S2.
cbn in *.
unfold EXP in HeqS2.
specialize Hd' as Hd3.
rewrite <- HeqS2 in Hd''.
remember
(cpo_lub (c:= List_CPO P2) (fmap S2 (list_inj P2))) as ll.
destruct ll; [|contradiction].
rewrite Heqll in Hd''.
rewrite list_inj_get_list in Heqll; auto.
f_equal.
injection Heqll ; clear Heqll ; intro Heqll.
rewrite Heqll; clear Heqll.
change (get_list
(cpo_lub (c := List_CPO P2)(fmap S2 (list_inj P2))))
with
(dcpo_lub (P := P2) S2).
symmetry.
apply dcpo_lub_is_lub in Hd'.
rewrite <- HeqS2 in Hd'.
specialize (@lub_proj _ _ S Hd) as Hlp.
specialize (cpo_lub_prop (c:= EXP_CPO P1 P2) _ Hd) as Hcp.
apply is_lub_unique with (x := cpo_lub (c:= EXP_CPO P1 P2) S) in Hlp; auto.
rewrite Hlp; clear Hlp.
assert (Hlub' : is_lub (P := list_Poset P2)S2
(map (fun d : P1 =>
cpo_lub (proj S d)) l));
[ | apply is_lub_unique
with (x := dcpo_lub S2) in Hlub'; auto ].
subst.
split.
-
intros x Hmx.
destruct Hmx as (u & Hmu & Heq); subst.
apply map_mono_in_func.