-
Notifications
You must be signed in to change notification settings - Fork 2
/
SATtypes.v
1784 lines (1601 loc) · 47.4 KB
/
SATtypes.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
Require Import ZF ZFpairs ZFsum Sat.
Require Import ZFlambda.
Require Import Lambda.
Set Implicit Arguments.
(** Unit type *)
Definition unitSAT :=
interSAT (fun C => prodSAT C C).
Definition ID := Abs (Ref 0).
Lemma ID_intro0 S : inSAT ID (prodSAT S S).
apply prodSAT_intro; intros.
unfold subst; simpl subst_rec.
rewrite lift0.
trivial.
Qed.
Lemma ID_intro : inSAT ID unitSAT.
apply interSAT_intro with (1:=snSAT).
apply ID_intro0.
Qed.
(** Disjoint sum *)
Definition INL (t:term) :=
Abs (Abs (App (Ref 1) (lift 2 t))).
Definition INR (t:term) :=
Abs (Abs (App (Ref 0) (lift 2 t))).
Lemma INL_iota t1 t2 a :
redp (App2 (INL a) t1 t2) (App t1 a).
unfold INL.
eapply t_trans;[apply redp_app_l;apply t_step;apply red1_beta; reflexivity|].
unfold subst; simpl.
rewrite simpl_subst; trivial.
apply t_step; apply red1_beta.
unfold subst; simpl.
repeat rewrite simpl_subst; trivial.
repeat rewrite lift0; trivial.
Qed.
Lemma INR_iota t1 t2 a :
redp (App2 (INR a) t1 t2) (App t2 a).
unfold INR.
eapply t_trans;[apply redp_app_l;apply t_step;apply red1_beta; reflexivity|].
unfold subst; simpl.
rewrite simpl_subst; trivial.
apply t_step; apply red1_beta.
unfold subst; simpl.
rewrite simpl_subst; trivial.
repeat rewrite lift0; trivial.
Qed.
Definition WHEN_SUM :=
Abs (App2 (Ref 0) (Abs ID) (Abs ID)).
Definition WHEN_SUM_INL a u :
redp (App2 WHEN_SUM (INL a) u) u.
unfold WHEN_SUM.
eapply t_trans.
apply redp_app_l.
apply t_step; apply beta.
unfold subst; simpl.
rewrite lift0.
eapply t_trans.
apply redp_app_l.
apply INL_iota.
eapply t_trans.
apply redp_app_l.
apply t_step; apply beta.
unfold subst; simpl.
apply t_step; apply red1_beta.
unfold subst; simpl.
rewrite lift0; reflexivity.
Qed.
Definition WHEN_SUM_INR a u :
redp (App2 WHEN_SUM (INR a) u) u.
unfold WHEN_SUM.
eapply t_trans.
apply redp_app_l.
apply t_step; apply beta.
unfold subst; simpl.
rewrite lift0.
eapply t_trans.
apply redp_app_l.
apply INR_iota.
eapply t_trans.
apply redp_app_l.
apply t_step; apply beta.
unfold subst; simpl.
apply t_step; apply red1_beta.
unfold subst; simpl.
rewrite lift0; reflexivity.
Qed.
Lemma WHEN_SUM_neutral t :
inSAT t (prodSAT snSAT (prodSAT snSAT neuSAT)) ->
inSAT (App WHEN_SUM t) neuSAT.
intros.
unfold WHEN_SUM.
apply inSAT_exp;[simpl;auto|].
unfold subst; simpl; rewrite lift0.
apply prodSAT_elim with snSAT.
2:apply snSAT_intro; auto.
apply prodSAT_elim with snSAT; trivial.
apply snSAT_intro; auto.
Qed.
(*
Definition sumSAT X Y : SAT :=
interSAT (fun C => prodSAT (prodSAT X C) (prodSAT (prodSAT Y C) C)).
Lemma sumSAT_intro1 X Y t :
inSAT t X ->
inSAT (INL t) (sumSAT X Y).
intros tsat.
apply interSAT_intro;[exact snSAT|].
intros C.
apply prodSAT_intro; intros b1 b1sat.
unfold subst; simpl.
rewrite simpl_subst; auto with *.
apply prodSAT_intro; intros b2 b2sat.
unfold subst; simpl.
rewrite !simpl_subst, !lift0; auto with *.
apply prodSAT_elim with X; trivial.
Qed.
Lemma sumSAT_intro2 X Y t :
inSAT t Y ->
inSAT (INR t) (sumSAT X Y).
intros tsat.
apply interSAT_intro;[exact snSAT|].
intros C.
apply prodSAT_intro; intros b1 b1sat.
unfold subst; simpl.
rewrite simpl_subst; auto with *.
apply prodSAT_intro; intros b2 b2sat.
unfold subst; simpl.
rewrite !simpl_subst, !lift0; auto with *.
apply prodSAT_elim with Y; trivial.
Qed.
Lemma sumSAT_case X Y C t b1 b2 :
inSAT t (sumSAT X Y) ->
inSAT b1 (prodSAT X C) ->
inSAT b2 (prodSAT Y C) ->
inSAT (App2 t b1 b2) C.
intros tsat b1sat b2sat.
apply prodSAT_elim with (2:=b2sat).
apply prodSAT_elim with (2:=b1sat).
apply interSAT_elim with (1:=tsat).
Qed.
Definition sumReal (X Y:set->SAT) (a:set) : SAT :=
sumSAT
(depSAT (fun x => a==inl x) X)
(depSAT (fun y => a==inr y) Y).
Lemma Real_inl RX RY x t :
Proper (eq_set ==> eqSAT) RX ->
inSAT t (RX x) ->
inSAT (INL t) (sumReal RX RY (inl x)).
intros Xm tsat.
apply sumSAT_intro1.
apply depSAT_intro; eauto using sat_sn.
intros x' eqs; apply couple_injection in eqs; destruct eqs as (_,eqx).
rewrite <- eqx; trivial.
Qed.
Lemma Real_inr RX RY x t :
Proper (eq_set ==> eqSAT) RY ->
inSAT t (RY x) ->
inSAT (INR t) (sumReal RX RY (inr x)).
intros Ym tsat.
apply sumSAT_intro2.
apply depSAT_intro; eauto using sat_sn.
intros x' eqs; apply couple_injection in eqs; destruct eqs as (_,eqx).
rewrite <- eqx; trivial.
Qed.
Lemma Real_sum_case X Y a RX RY C t b1 b2 :
a ∈ sum X Y ->
inSAT t (sumReal RX RY a) ->
inSAT b1 (piSAT0 (fun x => a==inl x) RX (fun _ => C)) ->
inSAT b2 (piSAT0 (fun x => a==inr x) RY (fun _ => C)) ->
inSAT (App2 t b1 b2) C.
intros.
apply sum_ind with (3:=H); intros.
apply sumSAT_case with (1:=H0).
apply prodSAT_intro'; intros.
apply piSAT0_elim with (1:=H1) (2:=H4); auto.
apply depSAT_elim' in H5; red in H5; auto.
apply prodSAT_intro'; intros.
apply sum_ind with (3:=H); intros.
apply sumSAT_case with (1:=H0).
apply prodSAT_intro'; intros.
apply depSAT_elim' in H3; red in H3.
apply sum_ind with (3:=H); intros.
apply piSAT0_elim with (1:=H1) (2:=H5); auto.
Definition sumReal (X Y:set->SAT) (a:set) : SAT :=
sumSAT
(condSAT (a==inl (dest_sum a)) (X (dest_sum a)))
(condSAT (a==inr (dest_sum a)) (Y (dest_sum a))).
Lemma Real_inl RX RY x t :
Proper (eq_set ==> eqSAT) RX ->
inSAT t (RX x) ->
inSAT (INL t) (sumReal RX RY (inl x)).
intros Xm tsat.
apply sumSAT_intro1.
rewrite condSAT_ok.
rewrite dest_sum_inl; trivial.
rewrite dest_sum_inl; reflexivity.
Qed.
Lemma Real_inr RX RY x t :
Proper (eq_set ==> eqSAT) RY ->
inSAT t (RY x) ->
inSAT (INR t) (sumReal RX RY (inr x)).
intros Ym tsat.
apply sumSAT_intro2.
rewrite condSAT_ok.
rewrite dest_sum_inr; trivial.
rewrite dest_sum_inr; reflexivity.
Qed.
Lemma Real_sum_case X Y a RX RY C t b1 b2 :
a ∈ sum X Y ->
inSAT t (sumReal RX RY a) ->
inSAT b1 (piSAT0 (fun x => a==inl x) RX (fun _ => C)) ->
inSAT b2 (piSAT0 (fun x => a==inr x) RY (fun _ => C)) ->
inSAT (App2 t b1 b2) C.
intros.
apply sumSAT_case with (1:=H0).
apply prodSAT_intro'; intros.
apply sum_ind with (3:=H); intros.
rewrite condSAT_ok in H3.
apply piSAT0_elim' in H1.
rewrite H5 in H3.
apply depSAT_elim' in H3.
rewrite condSAT_def in H3.
apply interSAT_elim with (x:=C) in H0.
eapply prodSAT_elim;[apply prodSAT_elim with (1:=H0)|]; trivial.
Qed.
*)
Definition sumReal (X Y:set->SAT) (a:set) : SAT :=
interSAT (fun C =>
prodSAT (piSAT0 (fun x => a==inl x) X (fun _ => C))
(prodSAT (piSAT0 (fun x => a==inr x) Y (fun _ => C))
C)).
Lemma Real_inl RX RY x t :
Proper (eq_set ==> eqSAT) RX ->
inSAT t (RX x) ->
inSAT (INL t) (sumReal RX RY (inl x)).
intros.
apply interSAT_intro; auto.
intros.
apply prodSAT_intro; intros.
unfold subst; simpl subst_rec.
unfold subst; rewrite simpl_subst; auto.
apply prodSAT_intro; intros.
unfold subst; simpl subst_rec.
unfold subst; repeat rewrite simpl_subst; auto.
repeat rewrite lift0.
apply piSAT0_elim with (x:=x) (u:=t) in H1; auto with *.
Qed.
Lemma Real_inr RX RY x t :
Proper (eq_set ==> eqSAT) RY ->
inSAT t (RY x) ->
inSAT (INR t) (sumReal RX RY (inr x)).
intros.
apply interSAT_intro; auto.
intros.
apply prodSAT_intro; intros.
unfold subst; simpl subst_rec.
unfold subst; rewrite simpl_subst; auto.
apply prodSAT_intro; intros.
unfold subst; simpl subst_rec.
unfold subst; repeat rewrite simpl_subst; auto.
repeat rewrite lift0.
apply piSAT0_elim with (x:=x) (u:=t) in H2; auto with *.
Qed.
Lemma Real_sum_case a RX RY C t b1 b2 :
inSAT t (sumReal RX RY a) ->
inSAT b1 (piSAT0 (fun x => a==inl x) RX (fun _ => C)) ->
inSAT b2 (piSAT0 (fun x => a==inr x) RY (fun _ => C)) ->
inSAT (App2 t b1 b2) C.
intros.
apply interSAT_elim with (x:=C) in H.
eapply prodSAT_elim;[apply prodSAT_elim with (1:=H)|]; trivial.
Qed.
Lemma sumReal_mt RX RY :
inclSAT (sumReal RX RY empty) (prodSAT snSAT (prodSAT snSAT neuSAT)).
red; intros.
apply prodSAT_intro'; intros.
apply sat_sn in H0.
apply prodSAT_intro'; intros.
apply sat_sn in H1.
apply Real_sum_case with (1:=H).
apply piSAT0_intro; trivial.
intros.
apply discr_mt_couple in H2; contradiction.
apply piSAT0_intro; trivial.
intros.
apply discr_mt_couple in H2; contradiction.
Qed.
Lemma WHEN_SUM_sat RA RB S x t m :
inSAT t (sumReal RA RB x) ->
inSAT m S ->
inSAT (App2 WHEN_SUM t m) S.
intros tsat msat.
unfold WHEN_SUM.
eapply inSAT_context.
intros.
apply inSAT_exp;[simpl;auto|].
unfold subst; simpl.
rewrite lift0.
exact H.
apply prodSAT_elim with S; trivial.
apply Real_sum_case with (1:=tsat); auto.
apply piSAT0_intro; intros; auto.
apply inSAT_exp;[right; apply sat_sn in H0;trivial|].
unfold subst; simpl.
apply ID_intro0.
apply piSAT0_intro; intros; auto.
apply inSAT_exp;[right; apply sat_sn in H0;trivial|].
unfold subst; simpl.
apply ID_intro0.
Qed.
(** * Sigma-types *)
Definition COUPLE t1 t2 :=
Abs (App2 (Ref 0) (lift 1 t1) (lift 1 t2)).
Lemma COUPLE_iota t1 t2 b:
redp (App (COUPLE t1 t2) b) (App2 b t1 t2).
unfold COUPLE.
apply t_step; apply red1_beta.
unfold subst; simpl.
repeat rewrite simpl_subst; trivial.
repeat rewrite lift0; trivial.
Qed.
Definition is_couple t := exists a b, t = Abs (App2 (Ref 0) a b).
(** (WHEN_COUPLE t) reduces to the identity when t is a couple, or is
neutral when t is. *)
Definition WHEN_COUPLE :=
Abs (App (Ref 0) (Abs (Abs ID))).
Lemma WHEN_COUPLE_iota t u :
is_couple t ->
redp (App2 WHEN_COUPLE t u) u.
intros (a,(b,eqt)).
subst t.
unfold WHEN_COUPLE.
eapply t_trans.
apply redp_app_l.
apply t_step.
apply beta.
unfold subst; simpl.
rewrite lift0.
eapply t_trans.
apply redp_app_l.
apply t_step.
apply beta.
unfold subst; simpl.
rewrite lift0.
eapply t_trans.
apply redp_app_l.
apply redp_app_l.
apply t_step.
apply beta.
unfold subst; simpl.
eapply t_trans.
apply redp_app_l.
apply t_step.
apply beta.
unfold subst; simpl.
apply t_step; apply red1_beta.
unfold subst; simpl.
rewrite lift0; reflexivity.
Qed.
Lemma WHEN_COUPLE_neutral t :
inSAT t (prodSAT snSAT neuSAT) ->
inSAT (App WHEN_COUPLE t) neuSAT.
intros.
unfold WHEN_COUPLE.
apply inSAT_exp;[simpl;auto|].
unfold subst; simpl; rewrite lift0.
apply prodSAT_elim with snSAT; trivial.
apply snSAT_intro; auto.
Qed.
Definition cartSAT (X Y:SAT) : SAT :=
interSAT (fun C => prodSAT (prodSAT X (prodSAT Y C)) C).
Instance cartSAT_mono : Proper (inclSAT ==> inclSAT ==> inclSAT) cartSAT.
unfold cartSAT.
do 3 red; intros.
apply interSAT_mono; intros C.
apply prodSAT_mono; auto with *.
apply prodSAT_mono; auto with *.
apply prodSAT_mono; auto with *.
Qed.
Instance cartSAT_morph : Proper (eqSAT ==> eqSAT ==> eqSAT) cartSAT.
do 3 red; intros.
apply interSAT_morph.
apply indexed_relation_id.
intros C.
rewrite H,H0; reflexivity.
Qed.
Lemma cartSAT_intro X Y t1 t2 :
inSAT t1 X ->
inSAT t2 Y ->
inSAT (COUPLE t1 t2) (cartSAT X Y).
intros.
apply interSAT_intro.
exact snSAT.
intros C.
apply prodSAT_intro; intros.
unfold subst; simpl subst_rec.
repeat rewrite simpl_subst; auto.
repeat rewrite lift0.
apply prodSAT_elim with (2:=H0).
apply prodSAT_elim with (2:=H).
trivial.
Qed.
Lemma cartSAT_case X Y C t b :
inSAT t (cartSAT X Y) ->
inSAT b (prodSAT X (prodSAT Y C)) ->
inSAT (App t b) C.
intros.
apply prodSAT_elim with (2:=H0).
apply interSAT_elim with (1:=H).
Qed.
Lemma WHEN_COUPLE_sat A B S t m :
inSAT t (cartSAT A B) ->
inSAT m S ->
inSAT (App2 WHEN_COUPLE t m) S.
intros tsat msat.
unfold WHEN_COUPLE.
eapply inSAT_context.
intros.
apply inSAT_exp;[simpl;auto|].
unfold subst; simpl.
rewrite lift0.
exact H.
apply prodSAT_elim with S; trivial.
apply cartSAT_case with (1:=tsat).
apply prodSAT_intro; intros a asat.
unfold subst; simpl.
apply prodSAT_intro; intros b bsat.
unfold subst; simpl.
apply prodSAT_intro; intros c csat.
unfold subst; simpl.
rewrite lift0; trivial.
Qed.
Definition sigmaReal (X:set->SAT) (Y:set->set->SAT) (a:set) : SAT :=
cartSAT (X (fst a)) (Y (fst a) (snd a)).
Instance sigmaReal_morph_gen :
Proper ((eq_set ==> eqSAT) ==> (eq_set ==> eq_set ==> eqSAT) ==>
eq_set ==> eqSAT) sigmaReal.
do 4 red; intros.
apply cartSAT_morph.
apply H; rewrite H1; reflexivity.
apply H0; rewrite H1; reflexivity.
Qed.
Instance sigmaReal_morph X Y :
Proper (eq_set ==> eqSAT) X ->
Proper (eq_set ==> eq_set ==> eqSAT) Y ->
Proper (eq_set ==> eqSAT) (sigmaReal X Y).
intros; apply sigmaReal_morph_gen; auto with *.
Qed.
Lemma Real_couple x y X Y t1 t2 :
Proper (eq_set ==> eqSAT) X ->
Proper (eq_set ==> eq_set ==> eqSAT) Y ->
inSAT t1 (X x) ->
inSAT t2 (Y x y) ->
inSAT (COUPLE t1 t2) (sigmaReal X Y (couple x y)).
intros.
unfold sigmaReal.
rewrite fst_def,snd_def.
apply cartSAT_intro; trivial.
Qed.
(*
Lemma Real_sigma_elim X Y a C t b :
inSAT t (sigmaReal X Y a) ->
inSAT b (prodSAT (X (fst a)) (prodSAT (Y (fst a) (snd a)) C)) ->
inSAT (App t b) C.
intros.
apply interSAT_elim with (x:=C) in H.
apply prodSAT_elim with (1:=H) (2:=H0).
Qed.
*)
Lemma Real_sigma_elim X Y RX RY a C t b :
ext_fun X Y ->
Proper (eq_set ==> eqSAT) C ->
a ∈ sigma X Y ->
inSAT t (sigmaReal RX RY a) ->
inSAT b (piSAT0 (fun x => x∈X) RX
(fun x => piSAT0 (fun y => y ∈ Y x) (RY x) (fun y => C(couple x y)))) ->
inSAT (App t b) (C a).
intros.
apply sigma_elim in H1; auto with *.
destruct H1 as (eqa,(ty1,ty2)).
apply cartSAT_case with (1:=H2).
apply prodSAT_intro'.
intros ta asat.
apply piSAT0_elim with (2:=ty1)(3:=asat) in H3.
apply prodSAT_intro'.
intros tb bsat.
apply piSAT0_elim with (2:=ty2)(3:=bsat) in H3.
rewrite <- eqa in H3.
trivial.
Qed.
(** * Structural fixpoint. *)
(** To avoid non-termination, we need to insert a "guard" operator G to control
the self-application of the fixpoint.
*)
Definition GUARD G :=
Abs (Abs (App (App (App (App (lift 2 G) (Ref 0)) (Ref 1)) (Ref 1)) (Ref 0))).
Lemma GUARD_sim G m t :
(forall u, redp (App2 G t u) u) ->
redp (App2 (GUARD G) m t) (App2 m m t).
intros; unfold GUARD.
eapply t_trans.
apply redp_app_l.
apply t_step; apply beta.
unfold subst; simpl.
rewrite simpl_subst; auto.
eapply t_trans.
apply t_step; apply beta.
unfold subst; simpl.
rewrite !simpl_subst; trivial.
rewrite !lift0.
apply redp_app_l.
apply redp_app_l.
apply H.
Qed.
Lemma GUARD_sat G m t S :
inSAT (App2 (App2 G t m) m t) S ->
inSAT (App2 (GUARD G) m t) S.
intros.
eapply inSAT_context.
intros.
apply inSAT_exp;[simpl;rewrite Bool.orb_true_r;auto|].
unfold subst; simpl.
rewrite simpl_subst; auto.
exact H0.
apply inSAT_exp;[simpl;rewrite Bool.orb_true_r;auto|].
unfold subst; simpl subst_rec.
repeat rewrite simpl_subst; auto.
repeat rewrite lift0.
trivial.
Qed.
Lemma GUARD_neutral G m t :
sn m ->
inSAT (App G t) (prodSAT snSAT (prodSAT snSAT (prodSAT snSAT neuSAT))) ->
inSAT (App2 (GUARD G) m t) neuSAT.
intros.
apply GUARD_sat.
apply snSAT_intro in H.
apply prodSAT_elim with snSAT.
apply prodSAT_elim with (2:=H).
apply prodSAT_elim with (2:=H).
trivial.
apply snSAT_intro.
apply sat_sn in H0.
apply subterm_sn with (1:=H0); auto.
Qed.
Definition guard_sum := GUARD WHEN_SUM.
Lemma guard_sum_INL : forall m n,
redp (App2 guard_sum m (INL n)) (App2 m m (INL n)).
intros.
apply GUARD_sim.
intro; apply WHEN_SUM_INL.
Qed.
Lemma guard_sum_INR : forall m n,
redp (App2 guard_sum m (INR n)) (App2 m m (INR n)).
intros.
apply GUARD_sim.
intro; apply WHEN_SUM_INR.
Qed.
Lemma guard_sum_neutral m t :
sn m ->
inSAT t (prodSAT snSAT (prodSAT snSAT neuSAT)) ->
inSAT (App2 guard_sum m t) neuSAT.
unfold guard_sum; intros.
apply GUARD_neutral; trivial.
apply neuSAT_def.
apply WHEN_SUM_neutral; trivial.
Qed.
Definition guard_couple := GUARD WHEN_COUPLE.
Lemma guard_couple_iota : forall m a b,
redp (App2 guard_couple m (COUPLE a b)) (App2 m m (COUPLE a b)).
intros.
apply GUARD_sim.
intro; apply WHEN_COUPLE_iota.
unfold is_couple, COUPLE; eauto.
Qed.
Lemma guard_couple_neutral m t :
sn m ->
inSAT t (prodSAT snSAT neuSAT) ->
inSAT (App2 guard_couple m t) neuSAT.
unfold guard_couple; intros.
apply GUARD_neutral; trivial.
apply neuSAT_def.
apply WHEN_COUPLE_neutral; trivial.
Qed.
Definition FIXP G m :=
App (GUARD G) (Abs (App (lift 1 m) (App (lift 1 (GUARD G)) (Ref 0)))).
(** when the guard expands when applied to n (e.g. when it's a constructor),
then the fixpoint unrolls once. *)
Lemma FIXP_sim : forall G m n,
(forall u, redp (App2 G n u) u) ->
redp (App (FIXP G m) n) (App2 m (FIXP G m) n).
intros G m n Gsim.
unfold FIXP at 1.
eapply t_trans.
apply GUARD_sim; trivial.
apply redp_app_l.
apply t_step.
apply red1_beta.
set (t1 := Abs (App (lift 1 m) (App (lift 1 (GUARD G)) (Ref 0)))).
unfold subst; simpl.
rewrite !simpl_subst; auto.
rewrite simpl_subst_rec; auto.
rewrite !lift0.
rewrite lift_rec0.
reflexivity.
Qed.
Lemma FIXP_sn G m:
(forall m, sn m -> sn (App (GUARD G) m)) ->
sn (App m (App (GUARD G) (Ref 0))) ->
sn (FIXP G m).
intros snG satm.
unfold FIXP.
apply snG; trivial.
apply sn_abs.
apply sn_subst with (Ref 0).
unfold subst; simpl.
rewrite simpl_subst; auto.
rewrite simpl_subst_rec; auto.
rewrite lift0.
rewrite lift_rec0.
exact satm.
Qed.
Require Import ZFord.
(*
Lemma FIXP_neutral G m t S A B C:
(exists w, w ∈ A) ->
(forall t, inSAT t (piSAT0 (fun x => x ∈ A) B C) -> sn (App m t)) ->
(forall S, inSAT G (piSAT0 (fun x => x ∈ A) B (fun _ => prodSAT S S))) ->
inSAT (App G t) (interSAT (fun S => S)) ->
inSAT (App (FIXP G m) t) S.
intros Awit msat Gsat Gneutr.
apply GUARD_neutral; trivial.
eapply sat_sn with (prodSAT (interSAT(fun S=>S)) _).
apply prodSAT_intro; intros.
unfold subst, subst_rec; fold subst_rec.
rewrite !simpl_subst, !lift0; auto.
simpl.
apply snSAT_intro.
apply msat.
apply piSAT0_intro'; intros; trivial.
apply GUARD_sat.
apply prodSAT_elim with (2:=H1).
apply prodSAT_elim with (2:=H).
unfold piSAT0 in Gsat.
unfold depSAT in Gsat.
eapply piSAT0_elim' in Gsat.
red in Gsat; specialize Gsat with (1:=H0) (2:=H1).
apply prodSAT_elim with (2:=H).
exact Gsat.
eapply Gsat.
apply Gsat with (2:=H1); trivial.
apply interSAT_elim with (1:=H).
Qed.
*)
Lemma FIXP_neutral G m t A B C:
(exists w, w ∈ A) ->
(forall t, inSAT t (piSAT0 (fun x => x ∈ A) B C) -> sn (App m t)) ->
(forall x n t S,
x ∈ A ->
inSAT n (B x) -> inSAT t S -> inSAT (App2 G n t) S) ->
inSAT (App G t) (prodSAT snSAT (prodSAT snSAT (prodSAT snSAT neuSAT))) ->
inSAT (App (FIXP G m) t) neuSAT.
intros Awit msat Gsat Gneutr.
apply GUARD_neutral; trivial.
eapply sat_sn with (prodSAT neuSAT _).
apply prodSAT_intro; intros.
unfold subst, subst_rec; fold subst_rec.
rewrite !simpl_subst, !lift0; auto.
simpl.
apply snSAT_intro.
apply msat.
apply piSAT0_intro'; intros; trivial.
apply GUARD_sat.
apply prodSAT_elim with (2:=H1).
apply prodSAT_elim with (2:=H).
apply Gsat with (2:=H1); trivial.
apply neuSAT_def; trivial.
Qed.
(*Require Import ZFcoc.*)
Section FIXP_Reducibility.
(*Lemma FIXP_sat0 G o T U RT m X :
let FIX_bot o := piSAT0 (fun n => n ∈ U o) (RT o) (X o) in
let FIX_strict o := piSAT0 (fun n => n ∈ T o) (RT o) (X o) in
isOrd o ->
(* strict domain values form a continuous sequence *)
(forall y n, isOrd y -> y ⊆ o -> n ∈ U y ->
~ n ∈ T y \/ exists2 y', y' ∈ y & n ∈ T (osucc y')) ->
(* U is not empty *)
(forall o, isOrd o -> exists w, w ∈ U o) ->
(* monotonicity of RT and X *)
(forall y y' n, isOrd y -> isOrd y' -> n ∈ T y -> y ⊆ y' -> y' ⊆ o ->
eqSAT (RT y n) (RT y' n)) ->
(forall y y' n, isOrd y -> isOrd y' -> y ⊆ y' -> y' ⊆ o -> n ∈ T y ->
inclSAT (X y n) (X y' n)) ->
(* Saturation property of guard G *)
(forall o (X:SAT),
isOrd o ->
inSAT G (piSAT0 (fun x => x ∈ U o) (RT o) (fun x => condSAT (x ∈ T o) (prodSAT X X)))) ->
inSAT m (piSAT0 (fun o' => o' ∈ osucc o)
(fun o' => FIX_bot o') (fun o' => FIX_strict (osucc o'))) ->
inSAT (FIXP G m) (FIX_bot o).
intros FIX_bot FIX_strict oo Tcont Ubot Rirrel Xmono Gsat msat.
assert (Gneutr: forall o x t (X:SAT),
isOrd o ->
x ∈ U o ->
~ x ∈ T o ->
inSAT t (RT o x) ->
inSAT (App G t) X).
intros.
specialize Gsat with (1:=H) (X:=X0).
specialize piSAT0_elim with (1:=Gsat)(2:=H0)(3:=H2).
clear Gsat; intros Gsat.
apply condSAT_neutral with (S:=X0) in Gsat; trivial.
assert (sn (Abs (App (lift 1 m) (App (lift 1 (GUARD G)) (Ref 0))))).
(* neutral case *)
eapply sat_sn.
apply prodSAT_intro with (A:=interSAT(fun S=>S)).
intros v vsat.
match goal with |- inSAT _ ?T =>
change (inSAT (App (subst v (lift 1 m)) (App (subst v (lift 1 (GUARD G))) (lift 0 v))) T)
end.
unfold subst; rewrite !simpl_subst; trivial.
rewrite !lift0.
apply piSAT0_elim' in msat; red in msat.
apply msat with (x:=o); auto with *.
apply lt_osucc; auto.
apply piSAT0_intro'; intros; [|apply Ubot; trivial].
apply GUARD_sat.
eapply prodSAT_elim;[|apply H0].
eapply prodSAT_elim;[|apply vsat].
specialize Gsat with (1:=oo)(X:=interSAT(fun S=>S)).
specialize piSAT0_elim with (1:=Gsat)(2:=H)(3:=H0).
clear Gsat; intros Gsat.
apply condSAT_smaller in Gsat.
specialize prodSAT_elim with (1:=Gsat)(2:=vsat).
intros.
apply interSAT_elim with (1:=H1).
elim oo using isOrd_ind; intros.
(*apply piSAT0_intro.
unfold FIXP.
eapply sat_sn.
eapply prodSAT_intro'.
intros.
apply GUARD_sat.
apply FIXP_sn.
intros.
eapply sat_sn.
eapply prodSAT_intro'.
intros.
apply GUARD_neutral; trivial.
*)
apply piSAT0_intro'; [|apply Ubot;trivial].
intros x u xty0 ureal.
unfold FIXP.
apply GUARD_sat.
assert (xty:=xty0).
apply Tcont in xty0; trivial.
destruct xty0 as [?|(y',?,?)].
apply prodSAT_elim with (2:=ureal).
apply prodSAT_elim with (2:=snSAT_intro H).
eapply prodSAT_elim;[|apply (snSAT_intro H)].
apply Gneutr with (1:=H0)(2:=xty)(3:=H3); trivial.
specialize H2 with (1:=H3).
assert (isOrd y') by eauto using isOrd_inv.
assert (zlt : osucc y' ⊆ y).
red; intros; apply le_lt_trans with y'; auto.
assert (ureal' : inSAT u (RT (osucc y') x)).
rewrite <- Rirrel with (3:=H4) in ureal; auto.
eapply inSAT_context.
apply inSAT_context.
intros.
apply prodSAT_elim with S.
eapply condSAT_smaller.
eapply piSAT0_elim with (1:=Gsat _ _ H0) (2:=xty) (3:=ureal).
exact H6.
eapply inSAT_context.
intros.
apply inSAT_exp.
left; simpl; rewrite !Bool.orb_true_r; trivial.
unfold subst; simpl.
rewrite simpl_subst; auto.
rewrite simpl_subst_rec; auto.
rewrite !lift0.
rewrite !lift_rec0.
change (inSAT (App m (FIXP G m)) S).
exact H6.
apply Xmono with (osucc y'); auto.
assert (y' ∈ osucc o).
apply isOrd_trans with o; auto.
apply H1; trivial.
apply piSAT0_elim' in msat; red in msat.
specialize msat with (1:=H6) (2:=H2).
apply piSAT0_elim' in msat; red in msat.
apply msat; trivial.
Qed.
*)
(* no osucc...
Lemma FIXP_sat0 G o T U RT m X :
let FIX_bot o := piSAT0 (fun n => n ∈ U o) (RT o) (X o) in
let FIX_strict o := piSAT0 (fun n => n ∈ T o) (RT o) (X o) in
isOrd o ->
(* strict domain values form a continuous sequence *)
(forall y n, isOrd y -> y ⊆ o -> n ∈ U y ->
eqSAT (RT y n) neuSAT \/ exists2 y', y' ∈ y & n ∈ T (osucc y')) ->
(* U is not empty *)
(forall o, isOrd o -> exists w, w ∈ U o) ->
(* monotonicity of RT and X *)
(forall y y' n, isOrd y -> isOrd y' -> n ∈ T y -> y ⊆ y' -> y' ⊆ o ->
eqSAT (RT y n) (RT y' n)) ->
(forall y y' n, isOrd y -> isOrd y' -> y ⊆ y' -> y' ⊆ o -> n ∈ T y ->
inclSAT (X y n) (X y' n)) ->
(* Saturation property of guard G *)
(forall t,
inSAT t neuSAT ->
inSAT (App G t) (prodSAT snSAT (prodSAT snSAT (prodSAT snSAT neuSAT)))) ->
(forall o x t m (X:SAT),
isOrd o -> x ∈ T o ->
inSAT t (RT o x) ->
inSAT m X ->
inSAT (App2 G t m) X) ->
inSAT m (piSAT0 (fun o' => o' ∈ o)
(fun o' => FIX_bot o') (fun o' => FIX_strict (osucc o'))) ->
inSAT (FIXP G m) (FIX_bot o).
intros FIX_bot FIX_strict oo Tcont Ubot Rirrel Xmono Gneutr Gsat msat.
elim oo using isOrd_ind; intros.
apply piSAT0_intro'; [|apply Ubot;trivial].
intros x u xty0 ureal.
unfold FIXP.
assert (sn (Abs (App (lift 1 m) (App (lift 1 (GUARD G)) (Ref 0))))).
(* neutral case *)
eapply sat_sn.
apply prodSAT_intro with (A:=neuSAT).
intros v vsat.
match goal with |- inSAT _ ?T =>
change (inSAT (App (subst v (lift 1 m)) (App (subst v (lift 1 (GUARD G))) (lift 0 v))) T)
end.
unfold subst; rewrite !simpl_subst; trivial.
rewrite !lift0.
assert (aux : inSAT m (prodSAT (prodSAT neuSAT neuSAT) snSAT)).
admit.
apply prodSAT_elim with (1:=aux).
apply prodSAT_intro'; intros.
apply GUARD_neutral.
apply sat_sn in vsat; trivial.
apply Gneutr; trivial.
(* apply piSAT0_elim' in msat; red in msat.
apply msat with (x:=y); auto with *.
apply ole_lts; auto.
apply piSAT0_intro'; intros; [|apply Ubot; trivial].
apply GUARD_sat.
eapply prodSAT_elim;[|apply H3].
eapply prodSAT_elim;[|apply vsat].
apply Tcont in H2; trivial.
destruct H2 as [?|(y',?,?)].
eapply prodSAT_elim;[|apply vsat].
rewrite H2 in H3.
specialize Gneutr with (1:=H3).
revert Gneutr; apply prodSAT_mono; auto with *.
apply neuSAT_inf.
apply prodSAT_mono; auto with *.
apply neuSAT_inf.
apply prodSAT_mono; auto with *.
red; red; intros.
apply sat_sn in H4; trivial.
apply neuSAT_inf.
assert (isOrd y') by eauto using isOrd_inv.
apply Gsat with (2:=H4); auto.
rewrite Rirrel with (y':=y); auto.
red; intros; apply le_lt_trans with y'; trivial.
apply neuSAT_def; trivial.*)
apply GUARD_sat.
apply Tcont in xty0; trivial.
destruct xty0 as [?|(y',?,?)].
apply prodSAT_elim with (2:=ureal).
apply prodSAT_elim with (2:=snSAT_intro H2).
eapply prodSAT_elim;[|apply (snSAT_intro H2)].
rewrite H3 in ureal.
specialize Gneutr with (1:=ureal); revert Gneutr.
apply prodSAT_mono; auto with *.
apply prodSAT_mono; auto with *.
apply prodSAT_mono; auto with *.
red; red; intros.
apply sat_sn in H4; trivial.
apply neuSAT_inf.
specialize H1 with (1:=H3).
assert (isOrd y') by eauto using isOrd_inv.
assert (zlt : osucc y' ⊆ y).
red; intros; apply le_lt_trans with y'; auto.
assert (ureal' : inSAT u (RT (osucc y') x)).
rewrite <- Rirrel with (3:=H4) in ureal; auto.
eapply inSAT_context.
apply inSAT_context.
intros.
apply Gsat with (2:=H4); auto.
exact H6.
eapply inSAT_context.
intros.
apply inSAT_exp.
left; simpl; rewrite !Bool.orb_true_r; trivial.
unfold subst; simpl.
rewrite simpl_subst; auto.
rewrite simpl_subst_rec; auto.
rewrite !lift0.