-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCcpo.v
2142 lines (1718 loc) · 66.7 KB
/
Ccpo.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
(** * Ccpo.v: Specification and properties of a cpo *)
From Coq Require Export Setoid.
From Coq Require Export Arith.
From Coq Require Export Lia.
Set Implicit Arguments.
Unset Strict Implicit.
Open Scope nat_scope.
(** ** Ordered type *)
Record ord : Type := mk_ord
{ tord:>Type;
Ole : tord->tord->Prop;
Ole_refl : forall x :tord, Ole x x;
Ole_trans : forall x y z:tord, Ole x y -> Ole y z -> Ole x z }.
Hint Resolve Ole_refl Ole_trans: core.
Hint Extern 2 (@Ole ?X1 ?X2 ?X3 ) => simpl Ole: core.
Declare Scope O_scope.
Infix "<=" := Ole : O_scope.
Open Scope O_scope.
(** *** Associated equality *)
Definition Oeq (O:ord) (x y : O) := x <= y /\ y <= x.
(** printing == %\ensuremath{\equiv}% #≡# *)
Infix "==" := Oeq (at level 70) : O_scope.
Lemma Ole_refl_eq : forall (O:ord) (x y:O), x=y -> x <= y.
intros O x y H; rewrite H; auto.
Qed.
Hint Resolve Ole_refl_eq: core.
Lemma Ole_antisym : forall (O:ord) (x y:O), x<=y -> y <=x -> x==y.
red; auto.
Qed.
Hint Immediate Ole_antisym: core.
Lemma Oeq_refl : forall (O:ord) (x:O), x == x.
red; auto.
Qed.
Hint Resolve Oeq_refl: core.
Lemma Oeq_refl_eq : forall (O:ord) (x y:O), x=y -> x == y.
intros O x y H; rewrite H; auto.
Qed.
Hint Resolve Oeq_refl_eq: core.
Lemma Oeq_sym : forall (O:ord) (x y:O), x == y -> y == x.
unfold Oeq; intuition.
Qed.
Lemma Oeq_le : forall (O:ord) (x y:O), x == y -> x <= y.
unfold Oeq; intuition.
Qed.
Lemma Oeq_le_sym : forall (O:ord) (x y:O), x == y -> y <= x.
unfold Oeq; intuition.
Qed.
Hint Resolve Oeq_le: core.
Hint Immediate Oeq_sym Oeq_le_sym: core.
Lemma Oeq_trans : forall (O:ord) (x y z:O), x == y -> y == z -> x == z.
unfold Oeq; split; apply Ole_trans with y; auto.
Qed.
Hint Resolve Oeq_trans: core.
(** *** Setoid relations *)
Add Parametric Relation (o:ord) : (tord o) (Oeq (O:=o))
reflexivity proved by (Oeq_refl (O:=o))
symmetry proved by (Oeq_sym (O:=o))
transitivity proved by (Oeq_trans (O:=o)) as Oeq_Relation.
Add Parametric Relation (o:ord) : (tord o) (Ole (o:=o))
reflexivity proved by (Ole_refl (o:=o))
transitivity proved by (Ole_trans (o:=o)) as Ole_Relation.
(** printing ==> %\ensuremath\Longrightarrow% #⇾# *)
Add Parametric Morphism (o:ord) : (Ole (o:=o))
with signature (Oeq (O:=o)) ==> (Oeq (O:=o)) ==> iff
as Ole_eq_compat_iff.
Proof.
split; firstorder.
apply Ole_trans with x; trivial.
apply Ole_trans with x0; trivial.
apply Ole_trans with y; trivial.
apply Ole_trans with y0; trivial.
Qed.
Lemma Ole_eq_compat :
forall (O : ord) (x1 x2 : O),
x1 == x2 -> forall x3 x4 : O, x3 == x4 -> x1 <= x3 -> x2 <= x4.
firstorder; apply Ole_trans with x1; trivial.
apply Ole_trans with x3; trivial.
Qed.
Lemma Ole_eq_right : forall (O : ord) (x y z: O),
x <= y -> y == z -> x <= z.
intros; apply Ole_eq_compat with x y; auto.
Qed.
Lemma Ole_eq_left : forall (O : ord) (x y z: O),
x == y -> y <= z -> x <= z.
intros; apply Ole_eq_compat with y z; auto.
Qed.
(** *** Dual order *)
(** - Iord x y := y <= x *)
Definition Iord: ord -> ord.
intros O; exists O (fun x y : O => y <= x); intros; auto.
apply Ole_trans with y; auto.
Defined.
(** *** Order on functions *)
(** - ford f g := forall x, f x <= g x *)
Definition ford : Type -> ord -> ord.
intros A O; exists (A->O) (fun f g:A->O => forall x, f x <= g x); intros; auto.
apply Ole_trans with (y x0); auto.
Defined.
(** printing -o> %\ensuremath{\stackrel{o}{\rightarrow}}% *)
Infix "-o>" := ford (right associativity, at level 30) : O_scope .
Lemma ford_le_elim : forall A (O:ord) (f g:A -o> O), f <= g ->forall n, f n <= g n.
auto.
Qed.
Hint Immediate ford_le_elim: core.
Lemma ford_le_intro : forall A (O:ord) (f g:A -o> O), (forall n, f n <= g n) -> f <= g.
auto.
Qed.
Hint Resolve ford_le_intro: core.
Lemma ford_eq_elim : forall A (O:ord) (f g:A -o> O), f == g ->forall n, f n == g n.
firstorder.
Qed.
Hint Immediate ford_eq_elim: core.
Lemma ford_eq_intro : forall A (O:ord) (f g:A -o> O), (forall n, f n == g n) -> f == g.
red; auto.
Qed.
Hint Resolve ford_eq_intro: core.
Hint Extern 2 (Ole (o:=ford ?X1 ?X2) ?X3 ?X4) => intro: core.
(** ** Monotonicity *)
(** *** Definition and properties *)
Definition monotonic (O1 O2:ord) (f : O1 -> O2) := forall x y, x <= y -> f x <= f y.
Hint Unfold monotonic: core.
Definition stable (O1 O2:ord) (f : O1 -> O2) := forall x y, x == y -> f x == f y.
Hint Unfold stable: core.
Lemma monotonic_stable : forall (O1 O2 : ord) (f:O1 -> O2),
monotonic f -> stable f.
unfold monotonic, stable; firstorder.
Qed.
Hint Resolve monotonic_stable: core.
(** *** Type of monotonic functions *)
Record fmono (O1 O2:ord) : Type := mk_fmono
{fmonot :> O1 -> O2; fmonotonic: monotonic fmonot}.
Hint Resolve fmonotonic: core.
(** - fmon O1 O2 (f g : fmono O1 O2) := forall x, f x <= g x *)
Definition fmon: ord -> ord -> ord.
intros O1 O2; exists (fmono O1 O2) (fun f g:fmono O1 O2 => forall x, f x <= g x); intros; auto.
apply Ole_trans with (y x0); auto.
Defined.
(** printing -m> %\ensuremath{\stackrel{m}{\rightarrow}}%*)
Infix "-m>" := fmon (at level 30, right associativity) : O_scope.
Lemma fmon_stable : forall (O1 O2:ord) (f:O1 -m> O2), stable f.
intros; apply monotonic_stable; auto.
Qed.
Hint Resolve fmon_stable: core.
Lemma fmon_le_elim : forall (O1 O2:ord) (f g:O1 -m> O2), f <= g -> forall n, f n <= g n.
auto.
Qed.
Hint Immediate fmon_le_elim: core.
Lemma fmon_le_intro : forall (O1 O2:ord) (f g:O1 -m> O2), (forall n, f n <= g n) -> f <= g.
auto.
Qed.
Hint Resolve fmon_le_intro: core.
Lemma fmon_eq_elim : forall (O1 O2:ord) (f g:O1 -m> O2), f == g ->forall n, f n == g n.
firstorder.
Qed.
Hint Immediate fmon_eq_elim: core.
Lemma fmon_eq_intro : forall (O1 O2:ord) (f g:O1 -m> O2), (forall n, f n == g n) -> f == g.
red; auto.
Qed.
Hint Resolve fmon_eq_intro: core.
Hint Extern 2 (Ole (o:=fmon ?X1 ?X2) ?X3 ?X4) => intro: core.
(** *** Monotonicity and dual order *)
(** - [lmon f] uses f as monotonic function over the dual order. *)
Definition Imon : forall O1 O2, (O1 -m> O2) -> Iord O1 -m> Iord O2.
intros O1 O2 f; exists (f: Iord O1 -> Iord O2); red; simpl; intros.
apply (fmonotonic f); auto.
Defined.
Definition Imon2 : forall O1 O2 O3, (O1 -m> O2 -m> O3) -> Iord O1 -m> Iord O2 -m> Iord O3.
intros O1 O2 O3 f; exists (fun (x:Iord O1) => Imon (f x)); red; simpl; intros.
apply (fmonotonic f); auto.
Defined.
(** *** Monotonic functions with 2 arguments *)
Definition le_compat2_mon : forall (O1 O2 O3:ord)(f:O1 -> O2 -> O3),
(forall (x y:O1) (z t:O2), x<=y -> z <= t -> f x z <= f y t) -> (O1 -m> O2 -m> O3).
intros O1 O2 O3 f Hle; exists (fun (x:O1) => mk_fmono (fun z t => Hle x x z t (Ole_refl x))).
red; intros; intro a; simpl; auto.
Defined.
(** ** Sequences *)
(** *** Order on natural numbers *)
(** - natO n m = n <= m *)
Definition natO : ord.
exists nat (fun n m : nat => (n <= m)%nat); intros; auto with arith.
apply le_trans with y; auto.
Defined.
Definition fnatO_intro : forall (O:ord) (f:nat -> O), (forall n, f n <= f (S n)) -> natO -m> O.
intros; exists f; red; simpl; intros.
elim H0; intros; auto.
apply Ole_trans with (f m); trivial.
Defined.
Lemma fnatO_elim : forall (O:ord) (f:natO -m> O) (n:nat), f n <= f (S n).
intros; apply (fmonotonic f); auto.
Qed.
Hint Resolve fnatO_elim: core.
(** - (mseq_lift_left f n) k = f (n+k) *)
Definition mseq_lift_left : forall (O:ord) (f:natO -m> O) (n:nat), natO -m> O.
intros; exists (fun k => f (n+k)%nat); red; intros.
apply (fmonotonic f); auto with arith.
Defined.
Lemma mseq_lift_left_simpl : forall (O:ord) (f:natO -m> O) (n k:nat),
mseq_lift_left f n k = f (n+k)%nat.
trivial.
Qed.
Lemma mseq_lift_left_le_compat : forall (O:ord) (f g:natO -m> O) (n:nat),
f <= g -> mseq_lift_left f n <= mseq_lift_left g n.
intros; intro; simpl; auto.
Qed.
Hint Resolve mseq_lift_left_le_compat: core.
Add Parametric Morphism (o:ord) : (mseq_lift_left (O:=o))
with signature (Oeq (O:=natO -m> o)) ==> eq (A:=nat) ==> (Oeq (O:=natO -m> o))
as mseq_lift_left_eq_compat.
intros; apply Ole_antisym; auto.
Qed.
Hint Resolve mseq_lift_left_eq_compat: core.
(** - (mseq_lift_right f n) k = f (k+n) *)
Definition mseq_lift_right : forall (O:ord) (f:natO -m> O) (n:nat), natO -m> O.
intros; exists (fun k => f (k+n)%nat); red; intros.
apply (fmonotonic f); auto with arith.
Defined.
Lemma mseq_lift_right_simpl : forall (O:ord) (f:natO -m> O) (n k:nat),
mseq_lift_right f n k = f (k+n)%nat.
trivial.
Qed.
Lemma mseq_lift_right_le_compat : forall (O:ord) (f g:natO -m> O) (n:nat),
f <= g -> mseq_lift_right f n <= mseq_lift_right g n.
intros; intro; simpl; auto.
Qed.
Hint Resolve mseq_lift_right_le_compat: core.
Add Parametric Morphism (o:ord) : (mseq_lift_right (O:=o))
with signature Oeq (O:=natO -m> o) ==> eq (A:=nat) ==> Oeq (O:=natO -m> o)
as mseq_lift_right_eq_compat.
intros; apply Ole_antisym; auto.
Qed.
Lemma mseq_lift_right_left : forall (O:ord) (f:natO -m> O) n,
mseq_lift_left f n == mseq_lift_right f n.
intros; apply fmon_eq_intro; unfold mseq_lift_left,mseq_lift_right; simpl; intros.
replace (n0+n)%nat with (n+n0)%nat; auto with arith.
Qed.
(** *** Monotonicity and functions *)
(** - (ford_app f x) n = f n x *)
Definition ford_app : forall (A:Type)(O1 O2:ord)(f:O1 -m> (A -o> O2))(x:A), O1 -m> O2.
intros; exists (fun n => f n x); intros.
intro n; intros.
assert (f n <= f y); auto.
apply (fmonotonic f); trivial.
Defined.
(** printing <o> %\ensuremath{\stackrel{o}{\diamond}}% *)
Infix "<o>" := ford_app (at level 30, no associativity) : O_scope.
Lemma ford_app_simpl : forall (A:Type)(O1 O2:ord) (f : O1 -m> A -o> O2) (x:A)(y:O1),
(f <o> x) y = f y x.
trivial.
Qed.
Lemma ford_app_le_compat : forall (A:Type)(O1 O2:ord) (f g:O1 -m> A -o> O2) (x:A),
f <= g -> f <o> x <= g <o> x.
intros; intro; simpl.
apply (H x0).
Qed.
Hint Resolve ford_app_le_compat: core.
Add Parametric Morphism (A:Type)(O1 O2:ord) : (ford_app (A:=A) (O1:=O1) (O2:=O2))
with signature Oeq (O:=O1 -m> (A -o> O2)) ==> eq (A:=A) ==> Oeq (O:=O1 -m> O2)
as ford_app_eq_compat.
intros; apply Ole_antisym; auto.
Qed.
(** - ford_shift f x y == f y x *)
Definition ford_shift : forall (A:Type)(O1 O2:ord)(f:A -o> (O1 -m> O2)), O1 -m> (A -o> O2).
intros; exists (fun x y => f y x); intros.
intros n x H y.
apply (fmonotonic (f y)); trivial.
Defined.
Lemma ford_shift_le_compat : forall (A:Type)(O1 O2:ord) (f g: A -o> (O1 -m> O2)),
f <= g -> ford_shift f <= ford_shift g.
intros; intro; simpl; auto.
Qed.
Hint Resolve ford_shift_le_compat: core.
Add Parametric Morphism (A:Type)(O1 O2:ord) : (ford_shift (A:=A) (O1:=O1) (O2:=O2))
with signature Oeq (O:=A -o> (O1 -m> O2)) ==> Oeq (O:=O1 -m> (A -o> O2))
as ford_shift_eq_compat.
intros; apply Ole_antisym; auto.
Qed.
(** - (fmon_app f x) n = f n x *)
Definition fmon_app : forall (O1 O2 O3:ord)(f:O1 -m> O2 -m> O3)(x:O2), O1 -m> O3.
intros; exists (fun n => f n x); intros.
intro n; intros.
assert (f n <= f y); auto.
apply (fmonotonic f); trivial.
Defined.
(** printing <_> %\ensuremath{\leftrightarroweq}%*)
Infix "<_>" := fmon_app (at level 35, no associativity) : O_scope.
Lemma fmon_app_simpl : forall (O1 O2 O3:ord)(f:O1 -m> O2 -m> O3)(x:O2)(y:O1),
(f <_> x) y = f y x.
trivial.
Qed.
Lemma fmon_app_le_compat : forall (O1 O2 O3:ord) (f g:O1 -m> (O2 -m> O3)) (x y:O2),
f <= g -> x <= y -> f <_> x <= g <_> y.
red; intros; simpl; intros; auto.
apply Ole_trans with (f x0 y); auto.
apply (fmonotonic (f x0)); auto.
Qed.
Hint Resolve fmon_app_le_compat: core.
Add Parametric Morphism (O1 O2 O3:ord) : (fmon_app (O1:=O1) (O2:=O2) (O3:=O3))
with signature Oeq (O:=O1 -m> O2 -m> O3) ==> Oeq (O:=O2) ==> Oeq (O:=O1-m>O3)
as fmon_app_eq_compat.
intros; apply Ole_antisym; intros; auto.
Qed.
(** - fmon_id c = c *)
Definition fmon_id : forall (O:ord), O -m> O.
intros; exists (fun (x:O)=>x).
intro n; auto.
Defined.
Lemma fmon_id_simpl : forall (O:ord) (x:O), fmon_id O x = x.
trivial.
Qed.
(** - (fmon_cte c) n = c *)
Definition fmon_cte : forall (O1 O2:ord)(c:O2), O1 -m> O2.
intros; exists (fun (x:O1)=>c).
intro n; auto.
Defined.
Lemma fmon_cte_simpl : forall (O1 O2:ord)(c:O2)(c:O2) (x:O1), fmon_cte O1 c x = c.
trivial.
Qed.
Definition mseq_cte : forall O:ord, O -> natO -m> O := fmon_cte natO.
Lemma fmon_cte_le_compat : forall (O1 O2:ord) (c1 c2:O2),
c1 <= c2 -> fmon_cte O1 c1 <= fmon_cte O1 c2.
intros; intro; auto.
Qed.
Add Parametric Morphism (O1 O2:ord) : (fmon_cte O1 (O2:=O2))
with signature Oeq (O:=O2) ==> Oeq (O:=O1 -m> O2)
as fmon_cte_eq_compat.
intros; apply Ole_antisym; auto.
Qed.
(** - (fmon_diag h) n = h n n *)
Definition fmon_diag : forall (O1 O2:ord)(h:O1 -m> (O1 -m> O2)), O1 -m> O2.
intros; exists (fun n => h n n).
red; intros.
apply Ole_trans with (h x y); auto.
apply (fmonotonic (h x)); auto.
assert (h x <= h y); auto.
apply (fmonotonic h); trivial.
Defined.
Lemma fmon_diag_le_compat : forall (O1 O2:ord) (f g:O1 -m> (O1 -m> O2)),
f <= g -> fmon_diag f <= fmon_diag g.
intros; intro; simpl; auto.
Qed.
Hint Resolve fmon_diag_le_compat: core.
Lemma fmon_diag_simpl : forall (O1 O2:ord) (f:O1 -m> (O1 -m> O2)) (x:O1),
fmon_diag f x = f x x.
trivial.
Qed.
Add Parametric Morphism (O1 O2:ord) : (fmon_diag (O1:=O1) (O2:=O2))
with signature Oeq (O:=O1 -m> (O1 -m> O2)) ==> Oeq (O:=O1 -m> O2)
as fmon_diag_eq_compat.
intros; apply Ole_antisym; auto.
Qed.
(** - (fmon_shift h) n m = h m n *)
Definition fmon_shift : forall (O1 O2 O3:ord)(h:O1 -m> O2 -m> O3), O2 -m> O1 -m> O3.
intros; exists (fun m => h <_> m).
intro n; simpl; intros.
apply (fmonotonic (h x)); trivial.
Defined.
Lemma fmon_shift_simpl : forall (O1 O2 O3:ord)(h:O1 -m> O2 -m> O3) (x : O2) (y:O1),
fmon_shift h x y = h y x.
trivial.
Qed.
Lemma fmon_shift_le_compat : forall (O1 O2 O3:ord) (f g:O1 -m> O2 -m> O3),
f <= g -> fmon_shift f <= fmon_shift g.
intros; intro; simpl; intros.
assert (f x0 <= g x0); auto.
Qed.
Hint Resolve fmon_shift_le_compat: core.
Add Parametric Morphism (O1 O2 O3:ord) : (fmon_shift (O1:=O1) (O2:=O2) (O3:=O3))
with signature Oeq (O:=O1 -m> O2 -m> O3) ==> Oeq (O:=O2 -m> O1 -m> O3)
as fmon_shift_eq_compat.
intros; apply Ole_antisym; auto.
Qed.
Lemma fmon_shift_shift_eq : forall (O1 O2 O3:ord) (h : O1 -m> O2 -m> O3),
fmon_shift (fmon_shift h) == h.
intros; apply fmon_eq_intro; unfold fmon_shift; simpl; auto.
Qed.
(** - (f@g) x = f (g x) *)
Definition fmon_comp : forall O1 O2 O3:ord, (O2 -m> O3) -> (O1 -m> O2) -> O1 -m> O3.
intros O1 O2 O3 f g; exists (fun n => f (g n)); red; intros.
apply (fmonotonic f).
apply (fmonotonic g); auto.
Defined.
(** printing @ %\ensuremath{\stackrel{m}{\circ}}% *)
Infix "@" := fmon_comp (at level 35) : O_scope.
Lemma fmon_comp_simpl : forall (O1 O2 O3:ord) (f :O2 -m> O3) (g:O1 -m> O2) (x:O1),
(f @ g) x = f (g x).
trivial.
Qed.
(** - (f@2 g) h x = f (g x) (h x) *)
Definition fmon_comp2 :
forall O1 O2 O3 O4:ord, (O2 -m> O3 -m> O4) -> (O1 -m> O2) -> (O1 -m> O3) -> O1-m>O4.
intros O1 O2 O3 O4 f g h; exists (fun n => f (g n) (h n)); red; intros.
apply Ole_trans with (f (g x) (h y)); auto.
apply (fmonotonic (f (g x))).
apply (fmonotonic h); auto.
apply (fmonotonic f); auto.
apply (fmonotonic g); auto.
Defined.
(** printing @2 %\ensuremath{\stackrel{m}{\circ_2}}% *)
Infix "@2" := fmon_comp2 (at level 70) : O_scope.
Lemma fmon_comp2_simpl :
forall (O1 O2 O3 O4:ord) (f:O2 -m> O3 -m> O4) (g:O1 -m> O2) (h:O1 -m> O3) (x:O1),
(f @2 g) h x = f (g x) (h x).
trivial.
Qed.
Add Parametric Morphism (O1 O2 O3:ord) : (fmon_comp (O1:=O1) (O2:=O2) (O3:=O3))
with signature Ole (o:=O2 -m> O3) ++> Ole (o:=O1 -m> O2) ++> Ole (o:=O1 -m> O3)
as fmon_comp_le_compat_morph.
red; intros f1 f2 H g1 g2 H1 x; simpl.
apply Ole_trans with (f2 (g1 x)); auto.
apply (fmonotonic f2); auto.
Qed.
Lemma fmon_comp_le_compat :
forall (O1 O2 O3:ord) (f1 f2: O2 -m> O3) (g1 g2:O1 -m> O2),
f1 <= f2 -> g1<= g2 -> f1 @ g1 <= f2 @ g2.
intros; exact (fmon_comp_le_compat_morph H H0).
Qed.
Hint Immediate fmon_comp_le_compat: core.
Add Parametric Morphism (O1 O2 O3:ord) : (fmon_comp (O1:=O1) (O2:=O2) (O3:=O3))
with signature Oeq (O:=O2 -m> O3) ==> Oeq (O:=O1 -m> O2) ==> Oeq (O:=O1 -m> O3)
as fmon_comp_eq_compat.
intros; apply Ole_antisym; apply fmon_comp_le_compat; auto.
Qed.
Hint Immediate fmon_comp_eq_compat: core.
Lemma fmon_comp_monotonic2 :
forall (O1 O2 O3:ord) (f: O2 -m> O3) (g1 g2:O1 -m> O2),
g1<= g2 -> f @ g1 <= f @ g2.
auto.
Qed.
Hint Resolve fmon_comp_monotonic2: core.
Lemma fmon_comp_monotonic1 :
forall (O1 O2 O3:ord) (f1 f2: O2 -m> O3) (g:O1 -m> O2),
f1<= f2 -> f1 @ g <= f2 @ g.
auto.
Qed.
Hint Resolve fmon_comp_monotonic1: core.
Definition fcomp : forall O1 O2 O3:ord, (O2 -m> O3) -m> (O1 -m> O2) -m> (O1 -m> O3).
intros; exists (fun f : O2 -m> O3 =>
mk_fmono (fmonot:=fun g : O1 -m> O2 => fmon_comp f g)
(fmon_comp_monotonic2 f)).
red; intros; simpl; intros.
apply H.
Defined.
Lemma fcomp_simpl : forall (O1 O2 O3:ord) (f:O2 -m> O3) (g:O1 -m> O2),
fcomp O1 O2 O3 f g = f @ g.
trivial.
Qed.
Definition fcomp2 : forall O1 O2 O3 O4:ord,
(O3 -m> O4) -m> (O1 -m> O2-m>O3) -m> (O1 -m> O2 -m> O4).
intros; exists (fun f : O3 -m> O4 =>
fcomp O1 (O2-m> O3) (O2-m>O4) (fcomp O2 O3 O4 f)).
red; intros; simpl; intros.
apply H.
Defined.
Lemma fcomp2_simpl : forall (O1 O2 O3 O4:ord) (f:O3 -m> O4) (g:O1 -m> O2-m>O3) (x:O1)(y:O2),
fcomp2 O1 O2 O3 O4 f g x y = f (g x y).
trivial.
Qed.
Lemma fmon_le_compat : forall (O1 O2:ord) (f: O1 -m> O2) (x y:O1), x<=y -> f x <= f y.
intros; apply (fmonotonic f); auto.
Qed.
Hint Resolve fmon_le_compat: core.
Lemma fmon_le_compat2 : forall (O1 O2 O3:ord) (f: O1 -m> O2 -m> O3) (x y:O1) (z t:O2),
x<=y -> z <=t -> f x z <= f y t.
intros; apply Ole_trans with (f x t).
apply (fmonotonic (f x)); auto.
apply (fmonotonic f); auto.
Qed.
Hint Resolve fmon_le_compat2: core.
Lemma fmon_cte_comp : forall (O1 O2 O3:ord)(c:O3)(f:O1-m>O2),
fmon_cte O2 c @ f == fmon_cte O1 c.
intros; apply fmon_eq_intro; intro x; auto.
Qed.
(** ** Basic operators of omega-cpos *)
(** - Constant : $0$
- lub : limit of monotonic sequences
*)
(** *** Definition of cpos *)
Record cpo : Type := mk_cpo
{
tcpo :> ord;
D0 : tcpo;
lub: (natO -m> tcpo) -> tcpo;
Dbot : forall x : tcpo, D0 <= x;
le_lub : forall (f : natO -m> tcpo) (n : nat), f n <= lub f;
lub_le : forall (f : natO -m> tcpo) (x : tcpo), (forall n, f n <= x) -> lub f <= x
}.
Arguments D0 {c}.
Notation "0" := D0 : O_scope.
Hint Resolve Dbot le_lub lub_le: core.
(** *** Least upper bounds *)
Add Parametric Morphism (c:cpo) : (lub (c:=c))
with signature Ole (o:=natO -m> c) ++> Ole (o:=c)
as lub_le_compat_morph.
intros f g H; apply lub_le; intros.
apply Ole_trans with (g n); auto.
Qed.
Hint Resolve lub_le_compat_morph: core.
Lemma lub_le_compat : forall (D:cpo) (f g:natO -m> D), f <= g -> lub f <= lub g.
intros; apply lub_le; intros.
apply Ole_trans with (g n); auto.
Qed.
Hint Resolve lub_le_compat: core.
Definition Lub : forall (D:cpo), (natO -m> D) -m> D.
intro D; exists (fun (f :natO-m>D) => lub f); red; auto.
Defined.
Add Parametric Morphism (c:cpo) : (lub (c:=c))
with signature Oeq (O:=natO -m> c) ==> Oeq (O:=c)
as lub_eq_compat.
intros; apply Ole_antisym; auto.
Qed.
Hint Resolve lub_eq_compat: core.
Lemma lub_cte : forall (D:cpo) (c:D), lub (fmon_cte natO c) == c.
intros; apply Ole_antisym; auto.
apply le_lub with (f:=fmon_cte natO c) (n:=O); auto.
Qed.
Hint Resolve lub_cte: core.
Lemma lub_lift_right : forall (D:cpo) (f:natO -m> D) n, lub f == lub (mseq_lift_right f n).
intros; apply Ole_antisym; auto.
apply lub_le_compat; intro.
unfold mseq_lift_right; simpl.
apply (fmonotonic f); auto with arith.
Qed.
Hint Resolve lub_lift_right: core.
Lemma lub_lift_left : forall (D:cpo) (f:natO -m> D) n, lub f == lub (mseq_lift_left f n).
intros; apply Ole_antisym; auto.
apply lub_le_compat; intro.
unfold mseq_lift_left; simpl.
apply (fmonotonic f); auto with arith.
Qed.
Hint Resolve lub_lift_left: core.
Lemma lub_le_lift : forall (D:cpo) (f g:natO -m> D) (n:natO),
(forall k, n <= k -> f k <= g k) -> lub f <= lub g.
intros; apply lub_le; intros.
apply Ole_trans with (f (n+n0)).
apply (fmonotonic f); simpl; auto with arith.
apply Ole_trans with (g (n+n0)); auto.
apply H; simpl; auto with arith.
Qed.
Lemma lub_eq_lift : forall (D:cpo) (f g:natO -m> D) (n:natO),
(forall k, n <= k -> f k == g k) -> lub f == lub g.
intros; apply Ole_antisym; apply lub_le_lift with n; intros; auto.
apply Oeq_le_sym; auto.
Qed.
(** - (lub_fun h) x = lub_n (h n x) *)
Definition lub_fun : forall (O:ord) (D:cpo) (h : natO -m> O -m> D), O -m> D.
intros; exists (fun m => lub (h <_> m)).
red; intros.
apply lub_le_compat; simpl; intros.
apply (fmonotonic (h x0)); auto.
Defined.
Lemma lub_fun_eq : forall (O:ord) (D:cpo) (h : natO -m> O -m> D) (x:O),
lub_fun h x == lub (h <_> x).
auto.
Qed.
Lemma lub_fun_shift : forall (D:cpo) (h : natO -m> (natO -m> D)),
lub_fun h == Lub D @ (fmon_shift h).
intros; apply fmon_eq_intro; unfold lub_fun; simpl; auto.
Qed.
Lemma double_lub_simpl : forall (D:cpo) (h : natO -m> natO -m> D),
lub (Lub D @ h) == lub (fmon_diag h).
intros; apply Ole_antisym.
apply lub_le; intros; simpl; apply lub_le; intros.
apply Ole_trans with (h n (n+n0)).
apply (fmonotonic (h n)); auto with arith.
apply Ole_trans with (h (n+n0) (n+n0)).
apply (fmonotonic h); auto with arith.
apply le_lub with (f:=fmon_diag h) (n:=(n + n0)%nat).
apply lub_le_compat.
unfold fmon_diag; simpl; auto.
Qed.
Lemma lub_exch_le : forall (D:cpo) (h : natO -m> (natO -m> D)),
lub (Lub D @ h) <= lub (lub_fun h).
intros; apply lub_le; intros; simpl.
apply lub_le; intros.
apply Ole_trans with (lub (h n)); auto.
apply lub_le_compat; intro.
unfold lub_fun; simpl.
apply le_lub with (f:=h <_> x) (n:=n).
Qed.
Hint Resolve lub_exch_le: core.
Lemma lub_exch_eq : forall (D:cpo) (h : natO -m> (natO -m> D)),
lub (Lub D @ h) == lub (lub_fun h).
intros; apply Ole_antisym; auto.
Qed.
Hint Resolve lub_exch_eq: core.
(** *** Functional cpos *)
Definition fcpo : Type -> cpo -> cpo.
intros A D; exists (ford A D) (fun x:A => (0:D)) (fun f (x:A) => lub(c:=D) (f <o> x)); intros; auto.
intro x; apply Ole_trans with ((f <o> x) n); auto.
Defined.
(** printing -O-> %\ensuremath{\stackrel{O}{\longleftarrow}}% *)
Infix "-O->" := fcpo (right associativity, at level 30) : O_scope.
Lemma fcpo_lub_simpl : forall A (D:cpo) (h:natO-m> A-O->D)(x:A),
(lub h) x = lub(c:=D) (h <o> x).
trivial.
Qed.
(** ** Continuity *)
Lemma lub_comp_le :
forall (D1 D2 : cpo) (f:D1 -m> D2) (h : natO -m> D1), lub (f @ h) <= f (lub h).
intros; apply lub_le; simpl; intros.
apply (fmonotonic f); auto.
Qed.
Hint Resolve lub_comp_le: core.
Lemma lub_comp2_le : forall (D1 D2 D3: cpo) (F:D1 -m> D2-m>D3) (f : natO -m> D1) (g: natO -m> D2),
lub ((F @2 f) g) <= F (lub f) (lub g).
intros; apply lub_le; simpl; auto.
Qed.
Hint Resolve lub_comp2_le: core.
Definition continuous (D1 D2 : cpo) (f:D1 -m> D2)
:= forall h : natO -m> D1, f (lub h) <= lub (f @ h).
Lemma continuous_eq_compat : forall (D1 D2 : cpo) (f g:D1 -m> D2),
f==g -> continuous f -> continuous g.
red; intros.
apply Ole_trans with (f (lub h)).
assert (g <= f); auto.
rewrite <- H; auto.
Qed.
Add Parametric Morphism (D1 D2 : cpo) : (continuous (D1:=D1) (D2:=D2))
with signature Oeq (O:=D1 -m> D2) ==> iff
as continuous_eq_compat_iff.
split; intros.
apply continuous_eq_compat with x; trivial.
apply continuous_eq_compat with y; auto.
Qed.
Lemma lub_comp_eq :
forall (D1 D2 : cpo) (f:D1 -m> D2) (h : natO -m> D1), continuous f -> f (lub h) == lub (f @ h).
intros; apply Ole_antisym; auto.
Qed.
Hint Resolve lub_comp_eq: core.
(** - mon0 x == 0 *)
Definition mon0 (O1:ord) (D2 : cpo) : O1 -m> D2 := fmon_cte O1 (0:D2).
Lemma cont0 : forall (D1 D2 : cpo), continuous (mon0 D1 D2).
red; simpl; auto.
Qed.
Arguments cont0 : clear implicits.
(** - double_app f g n m = f m (g n) *)
Definition double_app (O1 O2 O3 O4: ord) (f:O1 -m> O3 -m> O4) (g:O2 -m> O3)
: O2 -m> (O1 -m> O4) := (fmon_shift f) @ g.
(** ** Cpo of monotonic functions *)
Definition fmon_cpo : forall (O:ord) (D:cpo), cpo.
intros; exists (fmon O D) (mon0 O D) (lub_fun (O:=O) (D:=D)); auto.
simpl; intros.
apply le_lub with (f:=fmon_app f x) (n:=n); auto.
Defined.
(** printing -M-> %\ensuremath{\stackrel{M}{\longleftarrow}}% *)
Infix "-M->" := fmon_cpo (at level 30, right associativity) : O_scope.
Lemma fmon_lub_simpl : forall (O:ord) (D:cpo) (h:natO-m>O-M->D) (x:O),
(lub h) x = lub (h <_> x).
trivial.
Qed.
Lemma double_lub_diag : forall (D:cpo) (h:natO-m>natO-M->D),
lub (lub h) == lub (fmon_diag h).
intros.
intros; apply Ole_antisym.
apply lub_le; intros; simpl; apply lub_le; intros; simpl.
apply Ole_trans with (h (n+n0) (n+n0)); auto with arith.
apply le_lub with (f:=fmon_diag h) (n:=(n + n0)%nat).
apply lub_le_compat.
unfold fmon_diag; simpl; intros.
apply le_lub with (f:=h <_> x) (n:=x).
Qed.
(** *** Continuity *)
Definition continuous2 (D1 D2 D3: cpo) (F:D1 -m> D2 -m> D3)
:= forall (f : natO-m>D1) (g :natO-m>D2), F (lub f) (lub g) <= lub ((F @2 f) g).
Lemma continuous2_app : forall (D1 D2 D3:cpo) (F : D1-m>D2-m>D3),
continuous2 F -> forall k, continuous (F k).
red; intros.
apply Ole_trans with (F (lub (mseq_cte k)) (lub h)); auto.
apply Ole_trans with (lub ((F @2 (mseq_cte k)) h)); auto.
Qed.
Lemma continuous2_continuous : forall (D1 D2 D3:cpo) (F : D1-m>D2-M->D3),
continuous2 F -> continuous F.
red; intros; intro k.
apply Ole_trans with (F (lub h) (lub (mseq_cte k)) ); auto.
apply Ole_trans with (lub ((F @2 h) (mseq_cte k))); auto.
Qed.
Lemma continuous2_left : forall (D1 D2 D3:cpo) (F : D1-m>D2-M->D3) (h:natO-m>D1) (x:D2),
continuous2 F -> F (lub h) x <= lub ((F <_> x) @h).
intros; apply (continuous2_continuous H h x).
Qed.
Lemma continuous2_right : forall (D1 D2 D3:cpo) (F : D1-m>D2-M->D3) (x:D1)(h:natO-m>D2),
continuous2 F -> F x (lub h) <= lub (F x @h).
intros; apply (continuous2_app H x).
Qed.
Lemma continuous_continuous2 : forall (D1 D2 D3:cpo) (F : D1-m>D2-M->D3),
(forall k:D1, continuous (F k)) -> continuous F -> continuous2 F.
red; intros.
apply Ole_trans with (lub (F (lub f) @ g)); auto.
apply lub_le; simpl; intros.
apply Ole_trans with (lub ((F <_> (g n))@f)).
apply Ole_trans with (lub (c:=D2 -M-> D3) (F@f) (g n)); auto.
rewrite (lub_lift_right ((F @2 f) g) n).
apply lub_le_compat; simpl; intros.
apply Ole_trans with (F (f x) (g (x+n))); auto with arith.
Qed.
Hint Resolve continuous2_app continuous2_continuous continuous_continuous2: core.
Lemma lub_comp2_eq : forall (D1 D2 D3:cpo) (F : D1 -m> D2 -M-> D3),
(forall k:D1, continuous (F k)) -> continuous F ->
forall (f : natO-m>D1) (g :natO-m>D2),
F (lub f) (lub g) == lub ((F@2 f) g).
intros; apply Ole_antisym; auto.
apply (continuous_continuous2 (F:=F)); trivial.
Qed.
Lemma lub_cont2_comp2_eq : forall (D1 D2 D3:cpo) (F : D1 -m> D2 -M-> D3),
continuous2 F -> forall (f : natO-m>D1) (g :natO-m>D2), F (lub f) (lub g) == lub ((F@2 f) g).
intros; apply lub_comp2_eq; auto.
intro; apply (continuous2_app H).
Qed.
Lemma continuous_sym : forall (D1 D2:cpo) (F : D1-m> D1 -M-> D2),
(forall x y, F x y == F y x) -> (forall k:D1, continuous (F k)) -> continuous F.
red; intros; intro k.
apply Ole_trans with (F k (lub h)); auto.
apply Ole_trans with (lub ((F k) @ h)); auto.
Qed.
Lemma continuous2_sym : forall (D1 D2:cpo) (F : D1-m>D1-m>D2),
(forall x y, F x y == F y x) -> (forall k, continuous (F k)) -> continuous2 F.
intros; apply continuous_continuous2; auto.
apply continuous_sym; auto.
Qed.
Hint Resolve continuous2_sym: core.
(** - continuity is preserved by composition *)
Lemma continuous_comp : forall (D1 D2 D3:cpo) (f:D2-m>D3)(g:D1-m>D2),
continuous f -> continuous g -> continuous (f@g).
red; intros.
rewrite fmon_comp_simpl.
apply Ole_trans with (f (lub (g@h))); auto.
apply Ole_trans with (lub (f@(g@h))); auto.
Qed.
Hint Resolve continuous_comp: core.
Lemma continuous2_comp : forall (D1 D2 D3 D4:cpo) (f:D1-m>D2)(g:D2-m>D3-M->D4),
continuous f -> continuous2 g -> continuous2 (g @ f).
intros; apply continuous_continuous2; auto.
red; intros.
rewrite fmon_comp_simpl.
apply (continuous2_right (F:=g) (f k) h); trivial.
Qed.
Hint Resolve continuous2_comp: core.
Lemma continuous2_comp2 : forall (D1 D2 D3 D4:cpo) (f:D3-m>D4)(g:D1-m>D2-M->D3),
continuous f -> continuous2 g -> continuous2 (fcomp2 D1 D2 D3 D4 f g).
red; intros.
rewrite fcomp2_simpl.
apply Ole_trans with (f (lub ((g@2 f0) g0))); auto.
apply Ole_trans with (lub (f@((g@2 f0) g0))); auto.
Qed.
Hint Resolve continuous2_comp2: core.
(** ** Cpo of continuous functions *)
Lemma cont_lub : forall (D1 D2 : cpo) (f:natO -m> (D1 -m> D2)),
(forall n, continuous (f n)) ->
continuous (lub (c:=D1-M->D2) f).
red; intros; simpl.
apply Ole_trans with
(lub (c:=D2) (Lub D2 @ (fmon_shift (double_app f h)))).
apply lub_le_compat; intro n; simpl.
apply Ole_trans with (lub ((f n) @ h)); auto.
rewrite lub_exch_eq.
apply lub_le_compat; intro n; simpl.
apply lub_le_compat; intro m; simpl; auto.
Qed.
Record fconti (D1 D2:cpo): Type
:= mk_fconti {fcontit : D1 -m> D2; fcontinuous : continuous fcontit}.
Hint Resolve fcontinuous: core.
Definition fconti_fun (D1 D2 :cpo) (f:fconti D1 D2) : D1-> D2 :=fun x => fcontit f x.
Coercion fconti_fun : fconti >-> Funclass.
Definition fcont_ord : cpo -> cpo -> ord.
intros D1 D2; exists (fconti D1 D2) (fun (f g: fconti D1 D2) => fcontit f <= fcontit g); intros; auto.
apply Ole_trans with (fcontit y); auto.
Defined.
(** printing -c-> %\ensuremath{\stackrel{c}{\leftarrow}}% *)
Infix "-c>" := fcont_ord (at level 30, right associativity) : O_scope.
Lemma fcont_le_intro : forall (D1 D2:cpo) (f g : D1 -c> D2), (forall x, f x <= g x) -> f <= g.
trivial.
Qed.
Lemma fcont_le_elim : forall (D1 D2:cpo) (f g : D1 -c> D2), f <= g -> forall x, f x <= g x.
trivial.
Qed.
Lemma fcont_eq_intro : forall (D1 D2:cpo) (f g : D1 -c> D2), (forall x, f x == g x) -> f == g.
intros; apply Ole_antisym; apply fcont_le_intro; auto.
Qed.
Lemma fcont_eq_elim : forall (D1 D2:cpo) (f g : D1 -c> D2), f == g -> forall x, f x == g x.
intros; apply Ole_antisym; apply fcont_le_elim; auto.
Qed.
Lemma fcont_monotonic : forall (D1 D2:cpo) (f : D1 -c> D2) (x y : D1),
x <= y -> f x <= f y.
intros; apply (fmonotonic (fcontit f) H).
Qed.
Hint Resolve fcont_monotonic: core.
Lemma fcont_stable : forall (D1 D2:cpo) (f : D1 -c> D2) (x y : D1),
x == y -> f x == f y.
intros; apply (fmon_stable (fcontit f) H).
Qed.
Hint Resolve fcont_monotonic: core.
Definition fcont0 (D1 D2:cpo) : D1 -c> D2 := mk_fconti (cont0 D1 D2).
Definition Fcontit (D1 D2:cpo) : (D1 -c> D2) -m> D1-m> D2.
exists (fcontit (D1:=D1) (D2:=D2)); auto.
Defined.
Definition fcont_lub (D1 D2:cpo) : (natO -m> D1 -c> D2) -> D1 -c> D2.
intros f; exists (lub (c:=D1-M->D2) (Fcontit D1 D2 @f)).
apply cont_lub; intros; simpl; auto.
Defined.
Definition fcont_cpo : cpo -> cpo -> cpo.
intros D1 D2; exists (fcont_ord D1 D2) (fcont0 D1 D2) (fcont_lub (D1:=D1) (D2:=D2));