-
Notifications
You must be signed in to change notification settings - Fork 0
/
PRelLibA.v
1052 lines (943 loc) · 26.7 KB
/
PRelLibA.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 Coq.Lists.List.
Require Import Omega.
Require Import Coq.Logic.ProofIrrelevance.
Require Export EnvLibA.
Import ListNotations.
Lemma valTyp_irrelevance : forall (T: Type) (p1 p2: ValTyp T), p1 = p2.
intros.
eapply proof_irrelevance.
Qed.
(*********************************************************************)
Inductive MatchEnvs {K V1 V2: Type} {h: DEq K} (rel: V1 -> V2 -> Prop) :
Envr K V1 -> Envr K V2 -> Prop :=
| MatchEnvs_Nil : MatchEnvs rel nil nil
| MatchEnvs_Cons : forall ls1 ls2 k v1 v2,
rel v1 v2 ->
MatchEnvs rel ls1 ls2 ->
MatchEnvs rel ((k,v1)::ls1) ((k,v2)::ls2).
(*********************************************************************)
(** lemmas on MatchEnvs *)
Lemma consEnvLemma {K V1 V2: Type} {h: DEq K} (rel: V1 -> V2 -> Prop)
(env1: Envr K V1) (env2: Envr K V2) (x: K)
(v1: V1) (v2: V2):
MatchEnvs rel env1 env2 ->
rel v1 v2 ->
MatchEnvs rel ((x, v1)::env1) ((x, v2)::env2).
Proof.
intros.
constructor.
assumption.
assumption.
Defined.
Lemma updateEnvLemma {K V1 V2: Type} {h: DEq K} (rel: V1 -> V2 -> Prop)
(env1: Envr K V1) (env2: Envr K V2) (x: K)
(v1: V1) (v2: V2):
MatchEnvs rel env1 env2 ->
rel v1 v2 ->
MatchEnvs rel (updateE env1 x v1) (updateE env2 x v2).
Proof.
unfold updateE.
eapply consEnvLemma.
Defined.
Lemma app_cons_assoc {A: Type} (x: A) (ls1 ls2: list A):
(x :: ls1) ++ ls2 = x :: (ls1 ++ ls2).
Proof.
simpl.
reflexivity.
Defined.
Lemma appEnvLemma {K V1 V2: Type} {h: DEq K} (rel: V1 -> V2 -> Prop):
forall (env1A env1B: Envr K V1) (env2A env2B: Envr K V2),
MatchEnvs rel env1A env2A ->
MatchEnvs rel env1B env2B ->
MatchEnvs rel (env1A ++ env1B) (env2A ++ env2B).
Proof.
induction env1A.
intros.
induction env2A.
simpl.
assumption.
inversion H.
induction env2A.
intros.
inversion H.
intros.
simpl.
destruct a.
destruct a0.
destruct (dEq k k0).
Focus 2.
inversion H; subst.
intuition n.
destruct e.
inversion H; subst.
constructor.
assumption.
apply IHenv1A.
assumption.
assumption.
Defined.
Lemma overrideEnvLemma {K V1 V2: Type} {h: DEq K} (rel: V1 -> V2 -> Prop):
forall (env1A env1B: Envr K V1) (env2A env2B: Envr K V2),
MatchEnvs rel env1A env2A ->
MatchEnvs rel env1B env2B ->
MatchEnvs rel (env1A ++ env1B) (env2A ++ env2B).
Proof.
eapply appEnvLemma.
Defined.
Lemma RelatedByEnvEP {K V1 V2: Type} {h: DEq K} (rel: V1 -> V2 -> Prop)
(env1: Envr K V1) (env2: Envr K V2) (x: K)
(v1: V1) (v2: V2)
: MatchEnvs rel env1 env2 -> findEP env1 x v1 ->
findEP env2 x v2 -> rel v1 v2.
Proof.
intros.
inversion H0; subst.
inversion H1; subst.
induction H.
inversion H2.
inversion H3; subst.
inversion H2; subst.
destruct (dEq x k).
inversion H6; subst.
inversion H7; subst.
assumption.
apply IHMatchEnvs.
constructor.
assumption.
constructor.
assumption.
assumption.
assumption.
Defined.
Lemma RelatedByEnvEP2 {K V1 V2: Type} {h: DEq K} (rel: V1 -> V2 -> Prop)
(env1: Envr K V1) (env2: Envr K V2) (x: K)
(v1: V1) (v2: V2)
: MatchEnvs rel env1 env2 -> findEP2 env1 x v1 ->
findEP2 env2 x v2 -> rel v1 v2.
intros.
apply findEP2toEP in H0.
apply findEP2toEP in H1.
eapply RelatedByEnvEP.
eassumption.
eassumption.
assumption.
Defined.
Lemma ExRelVal {K V1 V2: Type} {h: DEq K} (R: V1 -> V2 -> Prop)
(tenv: Envr K V2) (venv: Envr K V1) (x: K) (t: V2):
MatchEnvs R venv tenv ->
findEP tenv x t ->
exists v: V1, findEP venv x v /\ R v t.
Proof.
intros.
induction H; subst.
inversion H0.
inversion H.
inversion H0; subst.
inversion H2; subst.
rename v2 into t2.
destruct (dEq x k).
inversion H4; subst.
exists v1.
split.
constructor.
simpl.
destruct (dEq k k).
auto.
intuition n.
assumption.
assert (findEP ls2 x t).
constructor.
auto.
eapply IHMatchEnvs in H3.
destruct H3.
destruct H3.
exists x0.
split.
constructor.
simpl.
destruct (dEq x k).
rewrite e in n.
intuition n.
inversion H3; subst.
assumption.
assumption.
Defined.
Lemma ExRelValRev {K V1 V2: Type} {h: DEq K} (R: V1 -> V2 -> Prop)
(tenv: Envr K V2) (venv: Envr K V1) (x: K) (v: V1):
MatchEnvs R venv tenv ->
findEP venv x v ->
exists t: V2, findEP tenv x t /\ R v t.
Proof.
intros.
induction H; subst.
inversion H0.
inversion H.
inversion H0; subst.
inversion H2; subst.
rename v2 into t1.
destruct (dEq x k).
inversion H4; subst.
exists t1.
split.
constructor.
simpl.
destruct (dEq k k).
auto.
intuition n.
assumption.
assert (findEP ls1 x v).
constructor.
auto.
eapply IHMatchEnvs in H3.
destruct H3.
destruct H3.
exists x0.
split.
constructor.
simpl.
destruct (dEq x k).
rewrite e in n.
intuition n.
inversion H3; subst.
assumption.
assumption.
Defined.
Lemma ExRelValNone {K V1 V2: Type} {h: DEq K} (R: V1 -> V2 -> Prop)
(tenv: Envr K V2) (venv: Envr K V1) (x: K) (t: V2):
MatchEnvs R venv tenv ->
findE tenv x = None ->
findE venv x = None.
Proof.
intros.
induction H; subst.
simpl.
reflexivity.
inversion H0; subst.
simpl.
destruct (dEq x k).
inversion H3.
apply IHMatchEnvs.
assumption.
Defined.
Lemma ExRelValProj1 {K V1 V2: Type} {h: DEq K} (R: V1 -> V2 -> Prop)
(tenv: Envr K V2) (venv: Envr K V1) (x: K) (t: V2):
MatchEnvs R venv tenv ->
findEP tenv x t ->
exists v: V1, findEP venv x v.
Proof.
intros.
eapply ExRelVal in H.
destruct H.
destruct H.
eexists.
eauto.
eauto.
Defined.
(*******************************************************************)
Inductive MatchEnvs2 {K V1 V2: Type} {h: DEq K} (rel: V1 -> V2 -> Prop) :
Envr K V1 -> Envr K V2 -> Prop :=
| MatchEnvs2_Nil : MatchEnvs2 rel nil nil
| MatchEnvs2_Cons : forall ls5 ls6 ls1 ls2 ls3 ls4 k v1 v2,
rel v1 v2 ->
MatchEnvs rel ls1 ls2 ->
MatchEnvs rel ls3 ls4 ->
findE ls2 k = None ->
ls5 = ls1 ++ ((k,v1)::ls3) ->
ls6 = ls2 ++ ((k,v2)::ls4) ->
MatchEnvs2 rel ls5 ls6.
(********************************************************************)
(** lemmas on MatchEnvs2 *)
Lemma MatchEnvs1to2 {K V1 V2: Type} {h: DEq K} (R: V1 -> V2 -> Prop)
(env1: Envr K V1) (env2: Envr K V2) :
MatchEnvs R env1 env2 -> MatchEnvs2 R env1 env2.
intros.
inversion H; subst.
constructor.
eapply MatchEnvs2_Cons.
eassumption.
eapply MatchEnvs_Nil.
eapply H1.
simpl.
reflexivity.
simpl.
reflexivity.
simpl.
reflexivity.
Defined.
Lemma MatchEnvs2to1 {K V1 V2: Type} {h: DEq K} (R: V1 -> V2 -> Prop)
(env1: Envr K V1) (env2: Envr K V2) :
MatchEnvs2 R env1 env2 -> MatchEnvs R env1 env2.
intros.
inversion H; subst.
constructor.
destruct ls1.
destruct ls2.
simpl.
constructor.
assumption.
assumption.
inversion H1.
destruct ls2.
inversion H1.
rewrite <- app_comm_cons.
rewrite <- app_comm_cons.
destruct p.
destruct p0.
inversion H1; subst.
eapply MatchEnvs_Cons.
assumption.
eapply appEnvLemma.
assumption.
eapply consEnvLemma.
assumption.
assumption.
Defined.
(***********************************************************************)
Inductive MatchEnvs2B {K V1 V2: Type} {h: DEq K} (rel: V1 -> V2 -> Prop)
(k: K) (v1: V1) (v2: V2) : Envr K V1 -> Envr K V2 -> Prop :=
| MatchEnvs2B_split : forall ls5 ls6 ls1 ls2 ls3 ls4,
rel v1 v2 ->
MatchEnvs rel ls1 ls2 ->
MatchEnvs rel ls3 ls4 ->
findE ls2 k = None ->
ls5 = ls1 ++ ((k,v1)::ls3) ->
ls6 = ls2 ++ ((k,v2)::ls4) ->
MatchEnvs2B rel k v1 v2 ls5 ls6.
(**********************************************************************)
(** lemmas on MatchEnvs2B *)
Lemma MatchEnvsB2A {K V1 V2: Type} {h: DEq K} (R: V1 -> V2 -> Prop)
(env1: Envr K V1) (env2: Envr K V2)
(k: K) (v1: V1) (v2: V2):
MatchEnvs2B R k v1 v2 env1 env2 -> MatchEnvs2 R env1 env2.
intros.
inversion H; subst.
econstructor.
eassumption.
exact H1.
exact H2.
eassumption.
reflexivity.
reflexivity.
Defined.
(*********************************************************************)
Inductive EnvPos {K V: Type} {h: DEq K} :
Envr K V -> K -> option nat -> Prop :=
| EnvPos_Nil : forall k: K, EnvPos emptyE k None
| EnvPos_Same : forall (env: Envr K V) (k: K) (v: V),
EnvPos ((k,v)::env) k (Some 0)
| EnvPos_Diff : forall (env: Envr K V) (k1 k2: K)
(n: nat) (v: V),
k1 <> k2 ->
EnvPos env k1 (Some n) ->
EnvPos ((k2,v)::env) k1 (Some (n+1)).
Inductive EnvPrefix {K V: Type} {h: DEq K} :
Envr K V -> K -> Envr K V -> Prop :=
| EnvPrefix_Nil : forall k: K, EnvPrefix emptyE k emptyE
| EnvPrefix_Same : forall (env: Envr K V) (k: K) (v: V),
EnvPrefix ((k,v)::env) k emptyE
| EnvPrefix_Diff : forall (env1 env2: Envr K V) (k1 k2: K)
(v: V),
k1 <> k2 ->
EnvPrefix env1 k1 env2 ->
EnvPrefix ((k2,v)::env1) k1 ((k2,v)::env2).
Inductive EnvSuffix {K V: Type} {h: DEq K} :
Envr K V -> K -> Envr K V -> Prop :=
| EnvSuffix_Nil : forall k: K, EnvSuffix emptyE k emptyE
| EnvSuffix_Same : forall (env: Envr K V) (k: K) (v: V),
EnvSuffix ((k,v)::env) k env
| EnvSuffix_Diff : forall (env1 env2: Envr K V) (k1 k2: K)
(v: V),
k1 <> k2 ->
EnvSuffix env1 k1 env2 ->
EnvSuffix ((k2,v)::env1) k1 env2.
(********************************************************************)
(** lemmas for EnvPos, EnvPrefix and EnvSuffix *)
Lemma MatchEnvsPos {K V1 V2: Type} {h: DEq K} (R: V1 -> V2 -> Prop)
(env1: Envr K V1) (env2: Envr K V2) :
MatchEnvs R env1 env2 ->
forall (k: K) (n1 n2: option nat),
EnvPos env1 k n1 ->
EnvPos env2 k n2 ->
n1 = n2.
Proof.
intros.
dependent induction H.
inversion H0; subst.
inversion H1; subst.
reflexivity.
inversion H1; subst.
inversion H2; subst.
reflexivity.
intuition H8.
inversion H2; subst.
inversion H1; subst.
omega.
intuition H7.
specialize (IHMatchEnvs k0 (Some n) (Some n0) H9 H11).
inversion IHMatchEnvs; subst.
reflexivity.
Defined.
Lemma MatchEnvsPrefix {K V1 V2: Type} {h: DEq K} (R: V1 -> V2 -> Prop)
(env1: Envr K V1) (env2: Envr K V2) :
MatchEnvs R env1 env2 ->
forall k env3 env4,
EnvPrefix env1 k env3 ->
EnvPrefix env2 k env4 ->
MatchEnvs R env3 env4.
Proof.
intros.
dependent induction H.
inversion H0; subst.
inversion H1; subst.
constructor.
inversion H1; subst.
inversion H2; subst.
constructor.
intuition H8.
inversion H2; subst.
intuition H8.
constructor.
assumption.
apply (IHMatchEnvs k0).
assumption.
assumption.
Defined.
Lemma MatchEnvsSuffix {K V1 V2: Type} {h: DEq K} (R: V1 -> V2 -> Prop)
(env1: Envr K V1) (env2: Envr K V2) :
MatchEnvs R env1 env2 ->
forall k env3 env4,
EnvSuffix env1 k env3 ->
EnvSuffix env2 k env4 ->
MatchEnvs R env3 env4.
Proof.
intros.
dependent induction H.
inversion H0; subst.
inversion H1; subst.
constructor.
inversion H1; subst.
inversion H2; subst.
assumption.
intuition H8.
inversion H2; subst.
intuition H8.
apply (IHMatchEnvs k0).
assumption.
assumption.
Defined.
Lemma IsEnvPrefix {K V: Type} {h: DEq K}
(env: Envr K V) (k: K) :
forall ls1 ls2 v,
env = ls1 ++ ((k,v)::ls2) ->
findE ls1 k = None ->
EnvPrefix env k ls1.
Proof.
intros.
revert H H0.
revert k v ls2 env.
induction ls1.
intros.
simpl in H.
rewrite H.
constructor.
intros.
rewrite <- app_comm_cons in H.
induction env.
inversion H.
inversion H; subst.
destruct a.
constructor.
inversion H0; subst.
destruct (dEq k k0).
inversion H2.
assumption.
eapply find_simpl2 in H0.
eapply IHls1 in H0.
eassumption.
reflexivity.
Defined.
Lemma IsEnvSuffix {K V: Type} {h: DEq K}
(env: Envr K V) (k: K) :
forall ls1 ls2 v,
env = ls1 ++ ((k,v)::ls2) ->
findE ls1 k = None ->
EnvSuffix env k ls2.
Proof.
intros.
revert H H0.
revert k v ls2 env.
induction ls1.
intros.
simpl in H.
rewrite H.
constructor.
intros.
rewrite <- app_comm_cons in H.
induction env.
inversion H.
inversion H; subst.
destruct a.
constructor.
inversion H0; subst.
destruct (dEq k k0).
inversion H2.
assumption.
eapply find_simpl2 in H0.
eapply IHls1 in H0.
eassumption.
reflexivity.
Defined.
(***************************************************************)
(** more lemmas on MatchEnvs *)
Lemma MatchEnvsApp {K V1 V2: Type} {h: DEq K} (R: V1 -> V2 -> Prop)
(env1: Envr K V1) (env2: Envr K V2) :
MatchEnvs R env1 env2 ->
forall ls1 ls2 ls3 ls4 k v1 v2,
env1 = ls1 ++ ((k,v1)::ls3) ->
env2 = ls2 ++ ((k,v2)::ls4) ->
findE ls1 k = None ->
findE ls2 k = None ->
R v1 v2 /\ MatchEnvs R ls1 ls2 /\ MatchEnvs R ls3 ls4.
Proof.
intros.
assert (env1 = ls1 ++ (k, v1) :: ls3) as E1.
auto.
assert (env2 = ls2 ++ (k, v2) :: ls4) as E2.
auto.
eapply IsEnvPrefix in E1.
eapply IsEnvPrefix in E2.
intros.
assert (env1 = ls1 ++ (k, v1) :: ls3) as F1.
auto.
assert (env2 = ls2 ++ (k, v2) :: ls4) as F2.
auto.
eapply IsEnvSuffix in F1.
eapply IsEnvSuffix in F2.
intros.
assert (env1 = ls1 ++ (k, v1) :: ls3) as G1.
auto.
assert (env2 = ls2 ++ (k, v2) :: ls4) as G2.
auto.
eapply IsEnvEl in G1.
eapply IsEnvEl in G2.
split.
eapply RelatedByEnvEP.
eapply H.
eapply G1.
apply G2.
split.
eapply MatchEnvsPrefix.
eapply H.
eapply E1.
apply E2.
eapply MatchEnvsSuffix.
eapply H.
eapply F1.
apply F2.
assumption.
assumption.
assumption.
assumption.
assumption.
assumption.
Defined.
Lemma MatchEnvsApp1 {K V1 V2: Type} {h: DEq K} (R: V1 -> V2 -> Prop)
(env1: Envr K V1) (env2: Envr K V2) :
MatchEnvs R env1 env2 ->
forall ls1 ls2 ls3 ls4 k v1 v2,
env1 = ls1 ++ ((k,v1)::ls3) ->
env2 = ls2 ++ ((k,v2)::ls4) ->
findE ls1 k = None ->
findE ls2 k = None ->
R v1 v2.
Proof.
eapply MatchEnvsApp.
Defined.
Lemma MatchEnvsApp2 {K V1 V2: Type} {h: DEq K} (R: V1 -> V2 -> Prop)
(env1: Envr K V1) (env2: Envr K V2) :
MatchEnvs R env1 env2 ->
forall ls1 ls2 ls3 ls4 k v1 v2,
env1 = ls1 ++ ((k,v1)::ls3) ->
env2 = ls2 ++ ((k,v2)::ls4) ->
findE ls1 k = None ->
findE ls2 k = None ->
MatchEnvs R ls1 ls2.
Proof.
eapply MatchEnvsApp.
Defined.
Lemma MatchEnvsApp3 {K V1 V2: Type} {h: DEq K} (R: V1 -> V2 -> Prop)
(env1: Envr K V1) (env2: Envr K V2) :
MatchEnvs R env1 env2 ->
forall ls1 ls2 ls3 ls4 k v1 v2,
env1 = ls1 ++ ((k,v1)::ls3) ->
env2 = ls2 ++ ((k,v2)::ls4) ->
findE ls1 k = None ->
findE ls2 k = None ->
MatchEnvs R ls3 ls4.
Proof.
eapply MatchEnvsApp.
Defined.
Lemma MatchEnvsA2B {K V1 V2: Type} {h: DEq K} (R: V1 -> V2 -> Prop)
(env1: Envr K V1) (env2: Envr K V2) :
MatchEnvs2 R env1 env2 ->
forall (k: K) (v1: V1) (v2: V2), findEP env1 k v1 ->
findEP env2 k v2 ->
MatchEnvs2B R k v1 v2 env1 env2.
Proof.
intros.
assert (findEP env1 k v1) as K1.
auto.
assert (findEP env2 k v2) as K2.
auto.
apply findEPtoEP2 in K1.
apply findEPtoEP2 in K2.
inversion K1.
rename H3 into K3.
inversion K2.
rename H3 into K4.
dependent induction H.
eapply (MatchEnvs2B_split R k v1 v2 nil nil nil nil nil nil).
inversion H0; subst.
inversion H.
inversion H0; subst.
inversion H.
inversion H0; subst.
inversion H.
inversion H0; subst.
inversion H.
inversion H0; subst.
inversion H.
inversion H0; subst.
inversion H.
assert (MatchEnvs R (ls1 ++ (k, v1) :: ls3) (ls2 ++ (k, v2) :: ls4)).
eapply appEnvLemma.
assumption.
eapply consEnvLemma.
assumption.
assumption.
rewrite H3 in H7.
rewrite H4 in K4.
econstructor.
(*
inversion H5; subst.
inversion H6; subst.
*)
eapply RelatedByEnvEP.
exact H11.
rewrite <- H3.
exact H5.
rewrite <- H4.
exact H6.
(***)
instantiate (1:=m2).
instantiate (1:=m0).
(*rewrite H3 in H7.
rewrite H4 in K4.*)
eapply MatchEnvsApp2.
eapply H11.
eapply H7.
eapply K4.
assumption.
assumption.
instantiate (1:=m3).
instantiate (1:=m1).
eapply MatchEnvsApp3.
eapply H11.
eapply H7.
eapply K4.
assumption.
assumption.
assumption.
rewrite H3.
assumption.
rewrite H4.
assumption.
Defined.
(*********************************************************************)
Inductive LiftRel {A B: Type} (R: A -> B -> Prop) :
option A -> option B -> Prop :=
| SLift : forall (v: A) (t: B), R v t ->
LiftRel R (Some v) (Some t)
| NLift : LiftRel R None None.
(**********************************************************************)
(** lemmas on LiftRel *)
Lemma nthErrorAux3 {A B: Type} (R : A -> B -> Prop)
(ls1: list A) (ls2: list B) (a: A) (b: B): (forall n : nat,
LiftRel R (nth_error (a :: ls1) n) (nth_error (b :: ls2) n)) ->
(forall n : nat, LiftRel R (nth_error ls1 n) (nth_error ls2 n)).
Proof.
intros.
specialize (H (S n)).
simpl in H.
assumption.
Defined.
Lemma sameBehSameLengthB {A B: Type} (R : A -> B -> Prop)
(ls1: list A) (ls2: list B) : (forall n : nat,
LiftRel R (nth_error ls1 n) (nth_error ls2 n)) ->
length ls1 = length ls2.
Proof.
intros.
dependent induction ls1.
dependent induction ls2.
reflexivity.
specialize (H 0).
simpl in H.
inversion H; subst.
dependent induction ls2.
specialize (H 0).
simpl in H.
inversion H.
specialize (IHls1 ls2).
assert ((forall n : nat,
LiftRel R (nth_error (a :: ls1) n) (nth_error (a0 :: ls2) n)) ->
(forall n : nat, LiftRel R (nth_error ls1 n) (nth_error ls2 n))).
apply (nthErrorAux3 R ls1 ls2 a a0).
assert (forall n : nat, LiftRel R (nth_error ls1 n) (nth_error ls2 n)).
auto.
apply IHls1 in H1.
simpl.
auto.
Defined.
(************************************************************************)
Inductive Forall3A {A B :Type} (R: A -> B -> Prop)
(P: forall (a:A) (b:B), R a b -> Type) :
list A -> list B -> Prop :=
| Forall3A_nil : Forall3A R P nil nil
| Forall3A_cons : forall (aas: list A) (bbs: list B)
(a:A) (b:B) (p: R a b),
P a b p ->
Forall3A R P aas bbs ->
Forall3A R P (a::aas) (b::bbs).
Inductive Forall3 {K A B :Type} (R: A -> B -> Prop)
(P: forall (a:A) (b:B), R a b -> Prop) :
Envr K A -> Envr K B -> Prop :=
| Forall3_nil : Forall3 R P nil nil
| Forall3_cons : forall (aas: Envr K A) (bbs: Envr K B)
(x:K) (a:A) (b:B) (p: R a b),
P a b p ->
Forall3 R P aas bbs ->
Forall3 R P ((x,a)::aas) ((x,b)::bbs).
Inductive Forall2B {K A B :Type} {h: DEq K} (R: A -> B -> Prop)
(P: forall (a:A) (b:B), R a b -> Prop)
(Q: forall (ls1: Envr K A) (ls2: Envr K B),
MatchEnvs R ls1 ls2 -> Prop) :
K -> A -> B -> Envr K A -> Envr K B -> Prop :=
Forall2B_split : forall (aas as1 as2: Envr K A)
(bbs bs1 bs2: Envr K B)
(k:K) (a:A) (b:B)
(p1: MatchEnvs R as1 bs1)
(p2: MatchEnvs R as2 bs2)
(p0: R a b),
aas = as1 ++ ((k,a)::as2) ->
bbs = bs1 ++ ((k,b)::bs2) ->
Q as1 bs1 p1 ->
Q as2 bs2 p2 ->
P a b p0 ->
Forall2B R P Q k a b aas bbs.
Inductive Forall2BC {K A B :Type} {h: DEq K} (R: A -> B -> Prop)
(P: forall (ls1: Envr K A) (ls2: Envr K B),
MatchEnvs R ls1 ls2 -> Prop) :
K -> A -> B -> Envr K A -> Envr K B -> Prop :=
Forall2BC_split : forall (aas as1 as2: Envr K A)
(bbs bs1 bs2: Envr K B)
(k:K) (a:A) (b:B)
(p1: MatchEnvs R as1 bs1)
(p2: MatchEnvs R as2 bs2)
(p0: MatchEnvs R (singleE k a) (singleE k b)),
aas = as1 ++ ((k,a)::as2) ->
bbs = bs1 ++ ((k,b)::bs2) ->
P as1 bs1 p1 ->
P as2 bs2 p2 ->
P (singleE k a) (singleE k b) p0 ->
Forall2BC R P k a b aas bbs.
Inductive Forall2BB {K A B :Type} {h: DEq K} (R: A -> B -> Prop)
(P: forall (a0:A) (b0:B), R a0 b0 -> Prop) :
K -> A -> B -> Envr K A -> Envr K B -> Prop :=
| Forall2BB_one : forall (k:K) (a:A) (b:B) (p: R a b),
P a b p ->
Forall2BB R P k a b (singleE k a) (singleE k b)
| Forall2BB_cons : forall (aas as1 as2: Envr K A)
(bbs bs1 bs2: Envr K B)
(k:K) (a:A) (b:B) (p: R a b),
aas = as1 ++ ((k,a)::as2) ->
bbs = bs1 ++ ((k,b)::bs2) ->
findE as1 k = None ->
findE bs1 k = None ->
P a b p ->
Forall3 R P as1 bs1 ->
Forall3 R P as2 bs2 ->
Forall2BB R P k a b aas bbs.
(***********************************************************************)
(** lemmas for Forall *)
Lemma matchForallAux1 {K A B} {h: DEq K} (R: A -> B -> Prop)
(P: forall (a:A) (b:B), R a b -> Prop)
(env1: Envr K A) (env2: Envr K B) (x:K) (a:A) (b:B):
Forall3 R P env1 env2 ->
findEP env1 x a -> findEP env2 x b ->
(forall p: R a b, P a b p).
Proof.
intros.
generalize dependent p.
dependent induction H.
inversion H0.
inversion H.
intros.
inversion H1; subst.
inversion H3; subst.
destruct (dEq x x0) in H5.
inversion H5; subst.
inversion H2; subst.
inversion H4; subst.
destruct (dEq x0 x0) in H7.
inversion H7; subst.
assert (p = p0).
apply proof_irrelevance.
rewrite <- H6.
assumption.
intuition n.
inversion H2; subst.
inversion H4; subst.
destruct (dEq x x0) in H7.
inversion H7; subst.
intuition n.
eapply IHForall3.
constructor.
assumption.
constructor.
assumption.
Defined.
Lemma forall3ConsExt {K A B :Type} {h: DEq K} (R: A -> B -> Prop)
(P: forall (a:A) (b:B), R a b -> Prop)
(env1: Envr K A) (env2: Envr K B) (x:K) (a:A) (b:B) (p: R a b):
Forall3 R P env1 env2 ->
P a b p ->
Forall3 R P ((x,a)::env1) ((x,b)::env2).
Proof.
intros.
econstructor.
eassumption.
assumption.
Defined.
Lemma forall3AppExt {K A B :Type} {h: DEq K} (R: A -> B -> Prop)
(P: forall (a:A) (b:B), R a b -> Prop)
(env1 env3: Envr K A) (env2 env4: Envr K B) (x:K):
Forall3 R P env1 env2 ->
Forall3 R P env3 env4 ->
Forall3 R P (env1 ++ env3) (env2 ++ env4).
Proof.
intros.
dependent induction H.
simpl.
assumption.
rewrite <- app_comm_cons.
rewrite <- app_comm_cons.
econstructor.
eassumption.
auto.
Defined.
Lemma forall2Bto3 {K A B :Type} {h: DEq K} (R: A -> B -> Prop)
(P: forall (a:A) (b:B), R a b -> Prop)
(env1: Envr K A) (env2: Envr K B) (x:K) (a:A) (b:B):
@Forall2B K A B h R P (fun x y z => Forall3 R P x y) x a b env1 env2 ->
Forall3 R P env1 env2.
Proof.
intros.
inversion H; subst.
eapply (forall3ConsExt R P) in H3.
instantiate (1:=b) in H3.
instantiate (1:=x) in H3.
instantiate (1:=a) in H3.
eapply (forall3AppExt R P).
auto.
auto.
auto.
eauto.
Defined.
(* see OPEN PROBLEMS in EnvListAux8.v *)
(************************************************************************)
Inductive MatchLists {V1 V2: Type} (rel: V1 -> V2 -> Prop) :
list V1 -> list V2 -> Prop :=
| MatchLists_Nil : MatchLists rel nil nil
| MatchLists_Cons : forall ls1 ls2 v1 v2,
rel v1 v2 ->
MatchLists rel ls1 ls2 ->
MatchLists rel (v1::ls1) (v2::ls2).
(************************************************************************)
(** lemmas on MatchLists *)
Lemma prmsTypingAux1 {A T V: Type} (R: V -> T -> Prop)
(fps : list (A * T)) (vls : list V)
(h2: length fps = length vls):
MatchLists R vls (map snd fps) ->
MatchLists R (map snd (zip (map fst fps) vls (map_fst_length fps vls h2)))
(map snd fps).
Proof.
generalize h2; clear.
dependent induction fps.
dependent induction vls.
intros.
simpl.
constructor.
intros.
inversion h2.
dependent induction vls.
intros.
inversion h2.
intros.
simpl in h2.
simpl in H.
simpl.
inversion H; subst.
constructor.
assumption.
specialize (IHfps vls (cons_length fps vls a a0 h2) H5).
assert (cons_length (map fst fps) vls (fst a) a0
(map_fst_length (a :: fps) (a0 :: vls) h2) = (map_fst_length fps vls (cons_length fps vls a a0 h2))).
apply proof_irrelevance.
rewrite H0.