-
Notifications
You must be signed in to change notification settings - Fork 0
/
InvertA.v
1264 lines (1074 loc) · 31.8 KB
/
InvertA.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 Export Basics.
Require Export EnvLibA.
Require Export RelLibA.
Require Export Coq.Program.Equality.
Require Import Coq.Init.Specif.
Require Import Coq.Arith.PeanoNat.
Require Import Omega.
Require Import Coq.Lists.List.
Require Import IdModTypeA.
Require Import StaticSemA.
Require Import TRInductA.
Require Import WeakenA.
Require Import TSoundnessA.
Require Import IdModTypeA.
Require Import DetermA.
Require Import WeakenA.
Require Import AbbrevA.
Import ListNotations.
Module Invert (IdT: IdModType) <: IdModType.
Definition Id := IdT.Id.
Definition IdEqDec := IdT.IdEqDec.
Definition IdEq := IdT.IdEq.
Definition W := IdT.W.
Definition Loc_PI := IdT.Loc_PI.
Definition BInit := IdT.BInit.
Definition WP := IdT.WP.
Module AbbrevI := Abbrev IdT.
Export AbbrevI.
(** inverse big-step lemmas (using modules up to Weaken) *)
Lemma BindN_BStep1 (fenv: funEnv) (env: valEnv)
(e1 e2: Exp) (v: Value) (s s': W) :
(forall (e:Exp) (s: W), sigT (fun v: Value =>
sigT (fun s': W =>
EClosure fenv env (Conf Exp s e) (Conf Exp s' (Val v))))) ->
(forall (e:Exp) (s s1 s2: W) (v1 v2: Value),
EClosure fenv env (Conf Exp s e) (Conf Exp s1 (Val v1)) ->
EClosure fenv env (Conf Exp s e) (Conf Exp s2 (Val v2)) ->
(s1 = s2) /\ (v1 = v2)) ->
EClosure fenv env (Conf Exp s (BindN e1 e2)) (Conf Exp s' (Val v)) ->
(sigT2 (fun s1 : W =>
(sigT (fun v1: Value =>
EClosure fenv env (Conf Exp s e1) (Conf Exp s1 (Val v1)))))
(fun s1 : W =>
EClosure fenv env (Conf Exp s1 e2) (Conf Exp s' (Val v)))).
intros X K.
intros.
generalize X.
intro X1.
specialize (X e1 s).
destruct X as [v1 X].
destruct X as [s1 X].
specialize (X1 e2 s1).
destruct X1 as [v2 X1].
destruct X1 as [s2 X1].
generalize X.
intro K1.
eapply BindN_extended_congruence in X.
instantiate (1:=e2) in X.
assert (EStep fenv env (Conf Exp s1 (BindN (Val v1) e2)) (Conf Exp s1 e2)).
constructor.
eapply StepIsEClos in X2.
assert (EClosure fenv env (Conf Exp s (BindN e1 e2)) (Conf Exp s1 e2)).
eapply EClosConcat.
exact X.
assumption.
assert (EClosure fenv env (Conf Exp s (BindN e1 e2)) (Conf Exp s2 (Val v2))).
eapply EClosConcat.
exact X3.
assumption.
assert (s' = s2 /\ v = v2).
eapply K.
eauto.
assumption.
destruct H.
subst.
econstructor.
econstructor.
eauto.
auto.
Defined.
Lemma BindN_BStep2 (fenv: funEnv) (env: valEnv)
(e1 e2: Exp) (v: Value) (s s': W) :
(forall (e:Exp) (s: W), sigT (fun v: Value =>
sigT (fun s': W =>
EClosure fenv env (Conf Exp s e) (Conf Exp s' (Val v))))) ->
(forall (e:Exp) (s s1 s2: W) (v1 v2: Value),
EClosure fenv env (Conf Exp s e) (Conf Exp s1 (Val v1)) ->
EClosure fenv env (Conf Exp s e) (Conf Exp s2 (Val v2)) ->
(s1 = s2) /\ (v1 = v2)) ->
EClosure fenv env (Conf Exp s (BindN e1 e2)) (Conf Exp s' (Val v)) ->
forall (s1 : W) (v1: Value),
EClosure fenv env (Conf Exp s e1) (Conf Exp s1 (Val v1)) ->
EClosure fenv env (Conf Exp s1 e2) (Conf Exp s' (Val v)).
intros.
generalize X1.
intro X2.
eapply BindN_extended_congruence in X1.
instantiate (1:= e2) in X1.
assert (EStep fenv env (Conf Exp s1 (BindN (Val v1) e2)) (Conf Exp s1 e2)).
constructor.
eapply StepIsEClos in X3.
assert (EClosure fenv env (Conf Exp s (BindN e1 e2)) (Conf Exp s1 e2)).
eapply EClosConcat.
exact X1.
auto.
specialize (X e2 s1).
destruct X as [v2 X].
destruct X as [s2 X].
assert (EClosure fenv env (Conf Exp s (BindN e1 e2)) (Conf Exp s2 (Val v2))).
eapply EClosConcat.
exact X4.
auto.
assert (s' = s2 /\ v = v2).
eapply H.
exact X0.
auto.
destruct H0.
subst.
auto.
Defined.
Lemma BindS_BStep1 (fenv: funEnv) (env: valEnv)
(e1 e2: Exp) (x: Id) (v: Value) (s s': W) :
(forall (fenv: funEnv) (env: valEnv) (e:Exp) (s: W), sigT (fun v: Value =>
sigT (fun s': W =>
EClosure fenv env (Conf Exp s e) (Conf Exp s' (Val v))))) ->
(forall (e:Exp) (s s1 s2: W) (v1 v2: Value),
EClosure fenv env (Conf Exp s e) (Conf Exp s1 (Val v1)) ->
EClosure fenv env (Conf Exp s e) (Conf Exp s2 (Val v2)) ->
(s1 = s2) /\ (v1 = v2)) ->
EClosure fenv env (Conf Exp s (BindS x e1 e2)) (Conf Exp s' (Val v)) ->
sigT (fun s1 : W =>
(sigT2 (fun v1: Value =>
EClosure fenv env (Conf Exp s e1) (Conf Exp s1 (Val v1)))
(fun v1 : Value =>
EClosure fenv ((x,v1)::env) (Conf Exp s1 e2) (Conf Exp s' (Val v))))).
intros X K.
intros.
generalize X.
intro X1.
specialize (X fenv env e1 s).
destruct X as [v1 X].
destruct X as [s1 X].
generalize X.
intro K1.
eapply BindS_extended_congruence in X.
instantiate (1:=e2) in X.
instantiate (1:=x) in X.
assert (EStep fenv env (Conf Exp s1 (BindS x (Val v1) e2))
(Conf Exp s1 (BindMS emptyE [(x,v1)] e2))).
constructor.
eapply StepIsEClos in X2.
assert (EClosure fenv env (Conf Exp s (BindS x e1 e2))
(Conf Exp s1 (BindMS emptyE [(x,v1)] e2))).
eapply EClosConcat.
exact X.
assumption.
specialize (X1 fenv ((x,v1)::env) e2 s1).
destruct X1 as [v2 X1].
destruct X1 as [s2 X1].
assert (EClosure fenv env (Conf Exp s (BindS x e1 e2))
(Conf Exp s2 (Val v2))).
eapply EClosConcat.
exact X3.
assert (EClosure fenv env (Conf Exp s1 (BindMS emptyE [(x, v1)] e2))
(Conf Exp s2 (BindMS emptyE [(x, v1)] (Val v2)))).
eapply BindMS_extended_congruence.
reflexivity.
reflexivity.
assumption.
eapply EClosConcat.
exact X4.
eapply StepIsEClos.
constructor.
assert (s' = s2 /\ v = v2).
eapply K.
eauto.
assumption.
destruct H.
subst.
econstructor.
econstructor.
eauto.
auto.
Defined.
Lemma Apply_BStep1 (fenv: funEnv) (env: valEnv)
(f: Fun) (es: list Exp) (v: Value) (s s': W) :
(forall (fenv: funEnv) (env: valEnv) (e:Exp) (s: W), sigT (fun v: Value =>
sigT (fun s': W =>
EClosure fenv env (Conf Exp s e) (Conf Exp s' (Val v))))) ->
(forall (fenv: funEnv) (env: valEnv) (es:list Exp) (s: W),
sigT (fun vs: list Value =>
sigT (fun s': W =>
PrmsClosure fenv env (Conf Prms s (PS es))
(Conf Prms s' (PS (map Val vs)))))) ->
(forall (e:Exp) (s s1 s2: W) (v1 v2: Value),
EClosure fenv env (Conf Exp s e) (Conf Exp s1 (Val v1)) ->
EClosure fenv env (Conf Exp s e) (Conf Exp s2 (Val v2)) ->
(s1 = s2) /\ (v1 = v2)) ->
match f as f with
| FC fenv' tenv' e0 e1 x n =>
length tenv' = length es ->
EClosure fenv env (Conf Exp s (Apply (QF f) (PS es)))
(Conf Exp s' (Val v)) ->
sigT (fun s1 : W =>
(sigT2 (fun vs: list Value =>
PrmsClosure fenv env (Conf Prms s (PS es))
(Conf Prms s1 (PS (map Val vs))))
(fun vs : list Value =>
match n with
| 0 =>
EClosure fenv' (mkVEnv tenv' vs) (Conf Exp s1 e0)
(Conf Exp s' (Val v))
| S n' =>
EClosure ((x, FC fenv' tenv' e0 e1 x n') :: fenv')
(mkVEnv tenv' vs) (Conf Exp s1 e1) (Conf Exp s' (Val v))
end)))
end.
Proof.
intros P1 P2 P3.
destruct f.
intros.
generalize P2.
intro P0.
specialize (P0 fenv env es s).
destruct P0 as [vs P0].
destruct P0 as [s1 P0].
generalize P0.
intro X0.
eapply Apply1_extended_congruence with (f:=(FC fenv0 tenv e0 e1 x n)) in X0.
econstructor.
instantiate (1:=s1).
generalize P0.
intro P6.
eapply PrmsClos_aux0 in P6.
rewrite map_length with (f:=Val) in P6.
rewrite P6 in H.
clear P6.
econstructor.
instantiate (1:=vs).
exact P0.
destruct n.
(**)
generalize P1.
intro P5.
specialize (P5 fenv0 (mkVEnv tenv vs) e0 s1).
destruct P5 as [v2 P5].
destruct P5 as [s2 P5].
assert (EClosure fenv env (Conf Exp s1
(Apply (QF (FC fenv0 tenv e0 e1 x 0)) (PS (map Val vs))))
(Conf Exp s1 (BindMS fenv0 (mkVEnv tenv vs) e0))). eapply StepIsEClos.
econstructor.
econstructor.
reflexivity.
exact H.
reflexivity.
assert (EClosure fenv env (Conf Exp s1 (BindMS fenv0 (mkVEnv tenv vs) e0))
(Conf Exp s2 (BindMS fenv0 (mkVEnv tenv vs) (Val v2)))).
eapply BindMS_extended_congruence.
reflexivity.
reflexivity.
eapply weaken.
exact P5.
assert (EClosure fenv env
(Conf Exp s2 (BindMS fenv0 (mkVEnv tenv vs) (Val v2)))
(Conf Exp s2 (Val v2))).
eapply StepIsEClos.
econstructor.
assert (EClosure fenv env
(Conf Exp s (Apply (QF (FC fenv0 tenv e0 e1 x 0)) (PS es)))
(Conf Exp s2 (Val v2))).
eapply EClosConcat.
exact X0.
eapply EClosConcat.
exact X1.
eapply EClosConcat.
exact X2.
exact X3.
assert (s' = s2 /\ v = v2).
eapply P3.
exact X.
exact X4.
destruct H0.
subst.
exact P5.
(**)
generalize P1.
intro P5.
set ((x, FC fenv0 tenv e0 e1 x n) :: fenv0) as fenv'.
specialize (P5 fenv' (mkVEnv tenv vs) e1 s1).
destruct P5 as [v2 P5].
destruct P5 as [s2 P5].
assert (EClosure fenv env (Conf Exp s1
(Apply (QF (FC fenv0 tenv e0 e1 x (S n))) (PS (map Val vs))))
(Conf Exp s1
(BindMS fenv' (mkVEnv tenv vs) e1))).
eapply StepIsEClos.
econstructor.
econstructor.
reflexivity.
exact H.
reflexivity.
assert (EClosure fenv env (Conf Exp s1 (BindMS fenv' (mkVEnv tenv vs) e1))
(Conf Exp s2 (BindMS fenv' (mkVEnv tenv vs) (Val v2)))).
eapply BindMS_extended_congruence.
reflexivity.
reflexivity.
eapply weaken.
exact P5.
assert (EClosure fenv env
(Conf Exp s2 (BindMS fenv' (mkVEnv tenv vs) (Val v2)))
(Conf Exp s2 (Val v2))).
eapply StepIsEClos.
econstructor.
assert (EClosure fenv env
(Conf Exp s (Apply (QF (FC fenv0 tenv e0 e1 x (S n))) (PS es)))
(Conf Exp s2 (Val v2))).
eapply EClosConcat.
exact X0.
eapply EClosConcat.
exact X1.
eapply EClosConcat.
exact X2.
exact X3.
assert (s' = s2 /\ v = v2).
eapply P3.
exact X.
exact X4.
destruct H0.
subst.
exact P5.
Defined.
(*********************************************************************)
(** further inverse big-step lemmas *)
Lemma BindN_BStepT1 (ftenv: funTC) (tenv: valTC)
(fenv: funEnv) (env: valEnv)
(e1 e2: Exp) (v: Value) (s s': W)
(k1: FEnvTyping fenv ftenv)
(k2: EnvTyping env tenv) (t: VTyp)
(k3: ExpTyping ftenv tenv fenv (BindN e1 e2) t) :
EClosure fenv env (Conf Exp s (BindN e1 e2)) (Conf Exp s' (Val v)) ->
(sigT2 (fun s1 : W =>
(sigT (fun v1: Value =>
EClosure fenv env (Conf Exp s e1) (Conf Exp s1 (Val v1)))))
(fun s1 : W =>
EClosure fenv env (Conf Exp s1 e2) (Conf Exp s' (Val v)))).
intros.
inversion k3; subst.
rename X0 into Y1.
rename X1 into Y2.
rename t into t2.
assert (ExpSoundness ftenv tenv fenv e1 t1 Y1) as X1.
eapply (ExpEval ftenv tenv fenv e1 t1 Y1).
unfold ExpSoundness in X1.
unfold SoundExp in X1.
specialize (X1 k1 env k2 s).
destruct X1 as [v1 k4 X1].
destruct X1 as [s1 X1].
generalize X1.
intro.
assert (ExpSoundness ftenv tenv fenv e2 t2 Y2) as X2.
eapply (ExpEval ftenv tenv fenv e2 t2 Y2).
unfold ExpSoundness in X2.
unfold SoundExp in X2.
specialize (X2 k1 env k2 s1).
destruct X2 as [v2 k5 X2].
destruct X2 as [s2 X2].
eapply BindN_extended_congruence in X1.
instantiate (1:=e2) in X1.
assert (EStep fenv env (Conf Exp s1 (BindN (Val v1) e2)) (Conf Exp s1 e2)).
constructor.
eapply StepIsEClos in X3.
assert (EClosure fenv env (Conf Exp s (BindN e1 e2)) (Conf Exp s1 e2)).
eapply EClosConcat.
exact X1.
assumption.
assert (EClosure fenv env (Conf Exp s (BindN e1 e2)) (Conf Exp s2 (Val v2))).
eapply EClosConcat.
exact X4.
assumption.
assert (s' = s2 /\ v = v2).
eapply ExpConfluence.
exact k3.
auto.
eauto.
eauto.
auto.
destruct H.
subst.
econstructor.
econstructor.
eauto.
auto.
Defined.
Lemma BindS_BStepT1 (ftenv: funTC) (tenv: valTC)
(fenv: funEnv) (env: valEnv)
(e1 e2: Exp) (x: Id) (v: Value) (s s': W)
(k1: FEnvTyping fenv ftenv)
(k2: EnvTyping env tenv) (t: VTyp)
(k3: ExpTyping ftenv tenv fenv (BindS x e1 e2) t) :
EClosure fenv env (Conf Exp s (BindS x e1 e2)) (Conf Exp s' (Val v)) ->
sigT (fun s1 : W =>
(sigT2 (fun v1: Value =>
EClosure fenv env (Conf Exp s e1) (Conf Exp s1 (Val v1)))
(fun v1 : Value =>
EClosure fenv ((x,v1)::env) (Conf Exp s1 e2) (Conf Exp s' (Val v))))).
intros.
inversion k3; subst.
rename X0 into Y1.
rename X1 into Y2.
rename t into t2.
assert (ExpSoundness ftenv tenv fenv e1 t1 Y1) as X1.
eapply (ExpEval ftenv tenv fenv e1 t1 Y1).
unfold ExpSoundness in X1.
unfold SoundExp in X1.
specialize (X1 k1 env k2 s).
destruct X1 as [v1 k4 X1].
destruct X1 as [s1 X1].
generalize X1.
intro.
eapply BindS_extended_congruence in X1.
instantiate (1:=e2) in X1.
instantiate (1:=x) in X1.
assert (EStep fenv env (Conf Exp s1 (BindS x (Val v1) e2))
(Conf Exp s1 (BindMS emptyE [(x,v1)] e2))).
constructor.
eapply StepIsEClos in X2.
assert (EClosure fenv env (Conf Exp s (BindS x e1 e2))
(Conf Exp s1 (BindMS emptyE [(x,v1)] e2))).
eapply EClosConcat.
exact X1.
assumption.
assert (ExpSoundness ftenv tenv' fenv e2 t2 Y2) as X4.
eapply (ExpEval ftenv tenv' fenv e2 t2 Y2).
unfold ExpSoundness in X4.
unfold SoundExp in X4.
assert (MatchEnvsT ValueTyping ((x, v1) :: env) tenv').
econstructor.
auto.
auto.
specialize (X4 k1 ((x,v1)::env) X5 s1).
destruct X4 as [v2 k5 X4].
destruct X4 as [s2 X4].
assert (EClosure fenv env (Conf Exp s (BindS x e1 e2))
(Conf Exp s2 (Val v2))).
eapply EClosConcat.
exact X3.
assert (EClosure fenv env (Conf Exp s1 (BindMS emptyE [(x, v1)] e2))
(Conf Exp s2 (BindMS emptyE [(x, v1)] (Val v2)))).
eapply BindMS_extended_congruence.
reflexivity.
reflexivity.
assumption.
eapply EClosConcat.
exact X6.
eapply StepIsEClos.
constructor.
assert (s' = s2 /\ v = v2).
eapply ExpConfluence.
exact k3.
auto.
eauto.
eauto.
auto.
destruct H.
subst.
econstructor.
econstructor.
eauto.
auto.
Defined.
Lemma Apply_BStepT1 (ftenv: funTC) (tenv: valTC)
(fenv: funEnv) (env: valEnv)
(f: Fun) (es: list Exp) (v: Value) (s s': W)
(k1: FEnvTyping fenv ftenv)
(k2: EnvTyping env tenv) (t: VTyp)
(k3: ExpTyping ftenv tenv fenv (Apply (QF f) (PS es)) t) :
match f as f with
| FC fenv' tenv' e0 e1 x n =>
length tenv' = length es ->
EClosure fenv env (Conf Exp s (Apply (QF f) (PS es)))
(Conf Exp s' (Val v)) ->
sigT (fun s1 : W =>
(sigT2 (fun vs: list Value =>
PrmsClosure fenv env (Conf Prms s (PS es))
(Conf Prms s1 (PS (map Val vs))))
(fun vs : list Value =>
match n with
| 0 =>
EClosure fenv' (mkVEnv tenv' vs) (Conf Exp s1 e0)
(Conf Exp s' (Val v))
| S n' =>
EClosure ((x, FC fenv' tenv' e0 e1 x n') :: fenv')
(mkVEnv tenv' vs) (Conf Exp s1 e1) (Conf Exp s' (Val v))
end)))
end.
Proof.
destruct f.
intros.
inversion k3; subst.
rename X1 into Y2.
rename X2 into Y1.
assert (PrmsSoundness ftenv tenv fenv (PS es) (PT (map snd fps)) Y1) as X1.
eapply (PrmsEval ftenv tenv fenv (PS es) (PT (map snd fps)) Y1).
unfold PrmsSoundness in X1.
unfold SoundPrms in X1.
specialize (X1 k1 env k2 s).
destruct X1 as [es1 X1].
destruct X1 as [vs k4 X1].
destruct X1 as [k5 X1].
destruct X1 as [s1 X1].
generalize X1.
intro.
eapply Apply1_extended_congruence with (f:=(FC fenv0 tenv0 e0 e1 x n)) in X1.
econstructor.
instantiate (1:=s1).
generalize X2.
intro P6.
eapply PrmsClos_aux0 in P6.
inversion k4; subst.
rewrite map_length with (f:=Val) in P6.
rewrite P6 in H.
clear P6.
econstructor.
instantiate (1:=vs).
auto.
destruct n.
(**)
inversion Y2; subst.
inversion X3; subst.
assert (ExpSoundness ftenv0 fps fenv0 e0 t X5) as X6.
eapply (ExpEval ftenv0 fps fenv0 e0 t X5).
unfold ExpSoundness in X6.
unfold SoundExp in X6.
assert (MatchEnvsT ValueTyping (mkVEnv fps vs) fps).
eapply prmsTypingAux_T.
auto.
eapply matchListsAux02_T.
eauto.
eauto.
specialize (X6 X4 (mkVEnv fps vs) X7 s1).
destruct X6 as [v2 k7 P5].
destruct P5 as [s2 P5].
assert (EClosure fenv env (Conf Exp s1
(Apply (QF (FC fenv0 fps e0 e1 x 0)) (PS (map Val vs))))
(Conf Exp s1 (BindMS fenv0 (mkVEnv fps vs) e0))) as A1. eapply StepIsEClos.
econstructor.
econstructor.
reflexivity.
exact H.
reflexivity.
assert (EClosure fenv env (Conf Exp s1 (BindMS fenv0 (mkVEnv fps vs) e0))
(Conf Exp s2 (BindMS fenv0 (mkVEnv fps vs) (Val v2)))) as A2.
eapply BindMS_extended_congruence.
reflexivity.
reflexivity.
eapply weaken.
exact P5.
assert (EClosure fenv env
(Conf Exp s2 (BindMS fenv0 (mkVEnv fps vs) (Val v2)))
(Conf Exp s2 (Val v2))) as A3.
eapply StepIsEClos.
econstructor.
assert (EClosure fenv env
(Conf Exp s (Apply (QF (FC fenv0 fps e0 e1 x 0)) (PS es)))
(Conf Exp s2 (Val v2))) as A4.
eapply EClosConcat.
exact X1.
eapply EClosConcat.
exact A1.
eapply EClosConcat.
exact A2.
exact A3.
assert (s' = s2 /\ v = v2).
eapply ExpConfluence.
exact k3.
auto.
eauto.
eauto.
auto.
destruct H0.
subst.
exact P5.
(**)
inversion Y2; subst.
inversion X3; subst.
assert (ExpSoundness ftenv' fps fenv' e1 t X5) as X06.
eapply (ExpEval ftenv' fps fenv' e1 t X5).
unfold ExpSoundness in X06.
unfold SoundExp in X06.
assert (MatchEnvsT ValueTyping (mkVEnv fps vs) fps).
eapply prmsTypingAux_T.
auto.
eapply matchListsAux02_T.
eauto.
eauto.
assert (MatchEnvsT FunTyping fenv' ftenv').
econstructor.
auto.
auto.
specialize (X06 X8 (mkVEnv fps vs) X7 s1).
destruct X06 as [v2 k7 P5].
destruct P5 as [s2 P5].
assert (EClosure fenv env (Conf Exp s1
(Apply (QF (FC fenv0 fps e0 e1 x (S n))) (PS (map Val vs))))
(Conf Exp s1 (BindMS fenv' (mkVEnv fps vs) e1))) as A1. eapply StepIsEClos.
econstructor.
econstructor.
reflexivity.
exact H.
reflexivity.
assert (EClosure fenv env (Conf Exp s1 (BindMS fenv' (mkVEnv fps vs) e1))
(Conf Exp s2 (BindMS fenv' (mkVEnv fps vs) (Val v2)))) as A2.
eapply BindMS_extended_congruence.
reflexivity.
reflexivity.
eapply weaken.
exact P5.
assert (EClosure fenv env
(Conf Exp s2 (BindMS fenv' (mkVEnv fps vs) (Val v2)))
(Conf Exp s2 (Val v2))) as A3.
eapply StepIsEClos.
econstructor.
assert (EClosure fenv env
(Conf Exp s (Apply (QF (FC fenv0 fps e0 e1 x (S n))) (PS es)))
(Conf Exp s2 (Val v2))) as A4.
eapply EClosConcat.
exact X1.
eapply EClosConcat.
exact A1.
eapply EClosConcat.
exact A2.
exact A3.
assert (s' = s2 /\ v = v2).
eapply ExpConfluence.
exact k3.
auto.
eauto.
eauto.
auto.
destruct H0.
subst.
exact P5.
Defined.
Lemma Prms_BStepT1 (ftenv: funTC) (tenv: valTC)
(fenv: funEnv) (env: valEnv)
(e: Exp) (es: list Exp) (v: Value) (vs: list Value) (s s': W)
(k1: FEnvTyping fenv ftenv)
(k2: EnvTyping env tenv) (pt: PTyp)
(k3: PrmsTyping ftenv tenv fenv (PS (e::es)) pt) :
PrmsClosure fenv env (Conf Prms s (PS (e::es)))
(Conf Prms s' (PS (map Val (v::vs)))) ->
(sigT2 (fun s1 : W =>
(sigT (fun v1: Value =>
EClosure fenv env (Conf Exp s e) (Conf Exp s1 (Val v1)))))
(fun s1 : W =>
PrmsClosure fenv env (Conf Prms s1 (PS es))
(Conf Prms s' (PS (map Val vs))))).
intros.
inversion k3; subst.
inversion X0; subst.
rename X1 into Y1.
rename X2 into Y3.
rename y into t.
rename l' into ts.
assert (ExpSoundness ftenv tenv fenv e t Y1) as X1.
eapply (ExpEval ftenv tenv fenv e t Y1).
unfold ExpSoundness in X1.
unfold SoundExp in X1.
specialize (X1 k1 env k2 s).
destruct X1 as [v1 k4 X1].
destruct X1 as [s1 X1].
generalize X1.
intro Y4.
assert (PrmsTyping ftenv tenv fenv (PS es) (PT ts)) as Y2.
constructor.
auto.
assert (PrmsSoundness ftenv tenv fenv (PS es) (PT ts) Y2) as X2.
eapply (PrmsEval ftenv tenv fenv (PS es) (PT ts) Y2).
unfold PrmsSoundness in X2.
unfold SoundPrms in X2.
specialize (X2 k1 env k2 s1).
destruct X2 as [es1 X2].
destruct X2 as [vs1 Y5 X2].
destruct X2 as [Y6 X2].
destruct X2 as [s2 X2].
inversion Y5; subst.
(**)
assert (PrmsClosure fenv env (Conf Prms s (PS (e :: es)))
(Conf Prms s2 (PS (map Val (v1 :: vs1))))).
eapply Pars_extended_congruence4.
eauto.
exact X2.
constructor 1 with (x:=s1).
constructor 1 with (x:=v1).
exact X1.
assert (s' = s2 /\ vs = vs1).
eapply PrmsConfluence in X.
specialize (X X3).
destruct X.
split.
exact H.
inversion H0; subst.
auto.
eauto.
auto.
auto.
destruct H.
rewrite H.
rewrite H0.
auto.
Defined.
Lemma Prms_BStepT2 (ftenv: funTC) (tenv: valTC)
(fenv: funEnv) (env: valEnv)
(e: Exp) (es: list Exp) (v: Value) (vs: list Value) (s s': W)
(k1: FEnvTyping fenv ftenv)
(k2: EnvTyping env tenv) (pt: PTyp)
(k3: PrmsTyping ftenv tenv fenv (PS (e::es)) pt) :
PrmsClosure fenv env (Conf Prms s (PS (e::es)))
(Conf Prms s' (PS (map Val (v::vs)))) ->
(sigT2 (fun s1 : W =>
(EClosure fenv env (Conf Exp s e) (Conf Exp s1 (Val v))))
(fun s1 : W =>
PrmsClosure fenv env (Conf Prms s1 (PS es))
(Conf Prms s' (PS (map Val vs))))).
intros.
inversion k3; subst.
inversion X0; subst.
rename X1 into Y1.
rename X2 into Y3.
rename y into t.
rename l' into ts.
assert (ExpSoundness ftenv tenv fenv e t Y1) as X1.
eapply (ExpEval ftenv tenv fenv e t Y1).
unfold ExpSoundness in X1.
unfold SoundExp in X1.
specialize (X1 k1 env k2 s).
destruct X1 as [v1 k4 X1].
destruct X1 as [s1 X1].
(*
generalize X1.
intro Y4.
*)
assert (PrmsTyping ftenv tenv fenv (PS es) (PT ts)) as Y2.
constructor.
auto.
assert (PrmsSoundness ftenv tenv fenv (PS es) (PT ts) Y2) as X2.
eapply (PrmsEval ftenv tenv fenv (PS es) (PT ts) Y2).
unfold PrmsSoundness in X2.
unfold SoundPrms in X2.
specialize (X2 k1 env k2 s1).
destruct X2 as [es1 X2].
destruct X2 as [vs1 Y5 X2].
destruct X2 as [Y6 X2].
destruct X2 as [s2 X2].
inversion Y5; subst.
assert (PrmsClosure fenv env (Conf Prms s (PS (e :: es)))
(Conf Prms s2 (PS (map Val (v1 :: vs1))))).
eapply Pars_extended_congruence4.
eauto.
exact X2.
(**)
assert (s' = s2 /\ (v::vs) = (v1::vs1)).
eapply PrmsConfluence in X.
specialize (X X3).
exact X.
eauto.
auto.
auto.
destruct H.
injection H0.
intros.
constructor 1 with (x:=s1).
rewrite H2.
auto.
rewrite H.
rewrite H1.
auto.
Defined.
Lemma IfThenElse_BStepT1 (ftenv: funTC) (tenv: valTC)
(fenv: funEnv) (env: valEnv)
(e1 e2 e3: Exp) (v: Value) (s s': W)
(k1: FEnvTyping fenv ftenv)
(k2: EnvTyping env tenv) (t: VTyp)
(k3: ExpTyping ftenv tenv fenv (IfThenElse e1 e2 e3) t) :
EClosure fenv env (Conf Exp s (IfThenElse e1 e2 e3)) (Conf Exp s' (Val v)) ->
sum (sigT2 (fun s1 : W =>
EClosure fenv env (Conf Exp s e1) (Conf Exp s1 (Val (cst bool true)))) (fun s1 : W =>
(EClosure fenv env (Conf Exp s1 e2) (Conf Exp s' (Val v)))))
(sigT2 (fun s1 : W =>
EClosure fenv env (Conf Exp s e1) (Conf Exp s1 (Val (cst bool false)))) (fun s1 : W =>
(EClosure fenv env (Conf Exp s1 e3) (Conf Exp s' (Val v))))).
Proof.
intros.
inversion k3; subst.
assert (ExpSoundness ftenv tenv fenv e1 Bool X0) as Y1.
eapply (ExpEval ftenv tenv fenv e1 Bool X0).
unfold ExpSoundness in Y1.
unfold SoundExp in Y1.
specialize (Y1 k1 env k2 s).
assert (ExpSoundness ftenv tenv fenv e2 t X1) as Y2.
eapply (ExpEval ftenv tenv fenv e2 t X1).
unfold ExpSoundness in Y2.
unfold SoundExp in Y2.
specialize (Y2 k1 env k2).
assert (ExpSoundness ftenv tenv fenv e3 t X2) as Y3.
eapply (ExpEval ftenv tenv fenv e3 t X2).
unfold ExpSoundness in Y3.
unfold SoundExp in Y3.
specialize (Y3 k1 env k2).
destruct Y1 as [v1 H1 Y1].
destruct Y1 as [s1 Y1].
specialize (Y2 s1).
specialize (Y3 s1).
destruct v1.
destruct v0.
inversion H1; subst.
simpl in *.
subst T.
inversion H; subst.
clear H2.
destruct v0.
(**)
destruct Y2 as [v2 H2 Y2].
destruct Y2 as [s2 Y2].
assert (EClosure fenv env (Conf Exp s (IfThenElse e1 e2 e3))
(Conf Exp s2 (Val v2))).
eapply EClosConcat.
eapply IfThenElse_extended_congruence.
exact Y1.
econstructor.
econstructor.
exact Y2.
assert (s' = s2 /\ v = v2).
eapply (ExpConfluence ftenv tenv fenv (IfThenElse e1 e2 e3) t k3).
auto.
eauto.
exact X.
auto.
destruct H.
constructor.
econstructor 1 with (x:=s1).
auto.
rewrite H.
rewrite H3.
exact Y2.
(**)
clear Y2.
rename Y3 into Y2.
destruct Y2 as [v2 H2 Y2].
destruct Y2 as [s2 Y2].