-
Notifications
You must be signed in to change notification settings - Fork 0
/
LR.v
3004 lines (2350 loc) · 67.5 KB
/
LR.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 Infrastructure.
Require Import SourceProperty.
Require Import Omega.
Require Import Assumed.
Require Import Disjoint.
Require Import TargetProperty.
From Equations Require Import Equations.
(* ********************************************************************** *)
(** * Auxiliary definitions *)
Module terminating.
Definition t (P : exp_relation) (e1 e2 : exp) :=
exists v1 v2, e1 ->* v1 /\ e2 ->* v2 /\ value v1 /\ value v2 /\ P v1 v2.
Lemma impl :
forall (P Q : exp_relation),
(forall e1 e2, P e1 e2 -> Q e1 e2) ->
(forall e1 e2, terminating.t P e1 e2 -> terminating.t Q e1 e2).
Proof with eauto.
introv H EH.
destruct EH as (v1 & v2 & ? & ? & ? & ? & EH).
specializes H EH.
exists v1 v2...
Qed.
Lemma iff :
forall (P Q : exp_relation),
(forall e1 e2, P e1 e2 <-> Q e1 e2) ->
(forall e1 e2, terminating.t P e1 e2 <-> terminating.t Q e1 e2).
Proof.
intros P Q HPQ e1 e2.
split; apply impl; firstorder.
Qed.
End terminating.
Module num_of_all.
Fixpoint num_of_all (t: sty) : nat :=
match t with
| sty_nat => 0
| sty_top => 0
| sty_bot => 0
| sty_var_b n => 0
| sty_var_f x => 0
| sty_arrow A B => (num_of_all A) + (num_of_all B)
| sty_and A B => (num_of_all A) + (num_of_all B)
| sty_all A B => 1 + (num_of_all B)
| sty_rcd l A => num_of_all A
end.
Lemma num_of_all_mono : forall t,
mono t ->
num_of_all t = 0.
Proof with auto.
introv mn. inductions mn; simpl;
try(rewrite IHmn1, IHmn2)...
Qed.
Lemma num_of_all_open_mono : forall B t,
mono t ->
num_of_all (open_sty_wrt_sty B t) = num_of_all B.
Proof with eauto using num_of_all_mono.
intro B. unfold open_sty_wrt_sty.
generalize 0; inductions B; introv mn; simpl...
destruct (lt_eq_lt_dec n n0); simpl...
destruct s...
Qed.
End num_of_all.
Inductive rel_nat : exp -> exp -> Prop :=
| RelInt : forall n, rel_nat (exp_lit n) (exp_lit n).
Hint Constructors rel_nat.
Definition size_sum (ty : sty * sty) := size_sty (fst ty) + size_sty (snd ty).
Definition size_all (ty : sty * sty) := num_of_all.num_of_all (fst ty) + num_of_all.num_of_all (snd ty).
Definition sizeOrder (ty1 ty2 : sty * sty) := size_sum ty1 < size_sum ty2.
(* ****************************************************************************** *)
(** * Value relation (well-foundedness proof (Lemma 5) can be found in the paper) *)
Equations V (A B : sty) (v1 v2 : exp ) : Prop :=
V A B v1 v2 by rec (A, B) sizeOrder :=
V sty_nat sty_nat v1 v2 := rel_nat v1 v2;
V (sty_arrow A1 B1) (sty_arrow A2 B2) v1 v2 := value v1 /\ value v2 /\
forall v1' v2', V A2 A1 v2' v1' ->
typ nil nil v1' (|A1|) ->
typ nil nil v2' (|A2|) ->
exists vv1 vv2,
exp_app v1 v1' ->* vv1 /\
exp_app v2 v2' ->* vv2 /\
value vv1 /\
value vv2 /\
V B1 B2 vv1 vv2;
V (sty_rcd l1 A) (sty_rcd l2 B) v1 v2 := value v1 /\ value v2 /\ if l1 == l2 then V A B v1 v2 else True ;
V (sty_all A1 B1) (sty_all A2 B2) v1 v2 := value v1 /\ value v2 /\
forall t,
disjoint nil t (sty_and A1 A2) ->
swft nil t ->
mono t ->
exists vv1 vv2,
exp_tapp v1 (| t |) ->* vv1 /\
exp_tapp v2 (| t |) ->* vv2 /\
value vv1 /\
value vv2 /\
V (open_sty_wrt_sty B1 t)
(open_sty_wrt_sty B2 t)
vv1 vv2;
V (sty_and A B) ty2 v1 v2 := value v1 /\ value v2 /\
exists v11 v12,
v1 = exp_pair v11 v12 /\
V A ty2 v11 v2 /\
V B ty2 v12 v2;
V ty1 (sty_and A B) v1 v2 := value v1 /\ value v2 /\
exists v21 v22,
v2 = exp_pair v21 v22 /\
V ty1 A v1 v21 /\
V ty1 B v1 v22;
V _ _ v1 v2 := value v1 /\ value v2.
Admit Obligations.
(* ********************************************************************** *)
(** * Expression relation *)
Definition E A B e1 e2 :=
swft nil A /\
swft nil B /\
typ nil nil e1 (|A|) /\
typ nil nil e2 (|B|) /\
terminating.t (V A B) e1 e2.
(* ********************************************************************** *)
(** * Logical interpretation of term contexts *)
Inductive rel_g : sctx -> sctx -> list (atom * exp) -> list (atom * exp) -> Prop :=
| rel_g_empty : forall p, rel_g nil p nil nil
| rel_g_cons : forall x G g1 g2 A v1 v2 p,
x `notin` dom G ->
rel_g G p g1 g2 ->
fv_sty_in_sty A [<=] dom p ->
typ nil nil v1 (| mtsubst_in_sty p A |) ->
typ nil nil v2 (| mtsubst_in_sty p A |) ->
V (mtsubst_in_sty p A) (mtsubst_in_sty p A) v1 v2 ->
rel_g ([(x, A)] ++ G) p ([(x , v1)] ++ g1) ([(x , v2)] ++ g2).
Hint Constructors rel_g.
(* ********************************************************************** *)
(** * Logical equivalence *)
Definition E_open Δ Γ e1 e2 A B :=
swft Δ A /\
swft Δ B /\
typ (map (const tt) Δ) (∥ Γ ∥) e1 (| A |) /\
typ (map (const tt) Δ) (∥ Γ ∥) e2 (| B |) /\
forall p g1 g2,
rel_d Δ p ->
rel_g Γ p g1 g2 ->
E (mtsubst_in_sty p A) (mtsubst_in_sty p B)
(msubst_in_exp g1 (mtsubst_in_exp p e1))
(msubst_in_exp g2 (mtsubst_in_exp p e2)).
Lemma rel_g_same : forall Γ p g1 g2,
rel_g Γ p g1 g2 -> same_stctx Γ g1 /\ same_stctx Γ g2.
Proof with simpl_env; eauto.
induction 1; simpls...
destructs IHrel_g.
splits...
Qed.
Lemma rel_g_notin : forall Γ p g1 g2 x,
rel_g Γ p g1 g2 ->
x `notin` dom Γ ->
x `notin` dom g1 /\ x `notin` dom g2.
Proof with eauto.
introv RelG.
induction RelG; simpls...
Qed.
Lemma rel_g_uniq : forall Γ p g1 g2,
rel_g Γ p g1 g2 ->
uniq Γ /\ uniq g1 /\ uniq g2.
Proof with eauto using rel_g_notin.
introv RelG.
induction RelG; simpls...
forwards (? & ?) : rel_g_notin RelG...
splits; try solve_uniq...
Qed.
(* ********************************************************************** *)
(** * Properties of logical exp_relation *)
Lemma V_value :
forall A B v1 v2,
V A B v1 v2 ->
value v1 /\ value v2.
Proof with eauto.
introv HVrel.
destruct A; destruct B; try simp V in HVrel; try destructs HVrel...
inverts HVrel...
Qed.
Lemma E_type : forall A B e1 e2,
E A B e1 e2 ->
typ nil nil e1 (|A|) /\
typ nil nil e2 (|B|).
Proof.
introv H.
destructs H; auto.
Qed.
Lemma E_conv1 : forall A B e1 e1' e2,
E A B e1' e2 ->
step e1 e1' ->
typ nil nil e1 (|A|) ->
E A B e1 e2.
Proof with eauto.
introv HE ? ?.
destruct HE as (? & ? & ? & ? & v1 & v2 & ? & ? & ? & ? & ?).
splits...
exists v1 v2.
splits...
Qed.
Lemma E_conv2 : forall A B e1 e2 e2',
E A B e1 e2' ->
step e2 e2' ->
typ nil nil e2 (|B|) ->
E A B e1 e2.
Proof with eauto.
introv HE ? ?.
destruct HE as (? & ? & ? & ? & v1 & v2 & ? & ? & ? & ? & ?).
splits...
exists v1 v2.
splits...
Qed.
Lemma E_star1 : forall A B e1 e1' e2,
e1 ->* e1' ->
E A B e1' e2 ->
typ nil nil e1 (|A|) ->
E A B e1 e2.
Proof with eauto using preservation, E_conv1.
introv Star E12 Ty.
revert A B e2 E12 Ty.
induction Star...
Qed.
Lemma E_star2 : forall A B e1 e2 e2',
e2 ->* e2' ->
E A B e1 e2' ->
typ nil nil e2 (|B|) ->
E A B e1 e2.
Proof with eauto using preservation, E_conv2.
introv Star E12 Ty.
revert A B e1 E12 Ty.
induction Star...
Qed.
Ltac simplifier :=
repeat match goal with
| H : ?v ->* ?v', V1 : value ?v, V2 : value ?v' |- _ =>
apply value_no_step in H; autos; substs
| H1 : ?t ->* ?v1, H2 : ?t ->* ?v2, V1 : value ?v1, V2 : value ?v2 |- _ =>
forwards : finseq_unique step_unique H2 H1; eauto using value_irred; substs; clear H2
end.
Lemma E_starr1 : forall A B e1 e1' e2,
e1 ->* e1' ->
E A B e1 e2 ->
E A B e1' e2.
Proof with eauto.
introv Red EH.
destruct EH as (? & ? & ? & ? & v1 & v2 & ? & ? & ? & ? & ?).
lets Ty : preservation_multi_step H1 Red.
lets (v1' & ? & ?) : normalization Ty.
assert (e1 ->* v1').
apply star_trans with (b := e1')...
simplifier.
splits...
exists v1 v2.
splits...
Qed.
Lemma E_starr2 : forall A B e1 e2 e2',
e2 ->* e2' ->
E A B e1 e2 ->
E A B e1 e2'.
Proof with eauto.
introv Red EH.
destruct EH as (? & ? & ? & ? & v1 & v2 & ? & ? & ? & ? & ?).
lets Ty : preservation_multi_step H2 Red.
lets (v2' & ? & ?) : normalization Ty.
assert (e2 ->* v2').
apply star_trans with (b := e2')...
simplifier.
splits...
exists v1 v2.
splits...
Qed.
Lemma V_topl : forall A v1 v2,
value v1 ->
value v2 ->
typ nil nil v2 (| A |) ->
V sty_top A v1 v2.
Proof with eauto.
intros A.
induction A; introv V1 V2 Typ; simp V; simpls...
splits...
forwards (v21 & v22 & ? & ? & ?): prod_canonical Typ...
substs.
inverts V2.
inverts Typ.
exists v21 v22.
splits...
Qed.
Lemma V_topr : forall A v1 v2,
value v1 ->
value v2 ->
typ nil nil v1 (| A |) ->
V A sty_top v1 v2.
Proof with eauto.
intros A.
induction A; introv V1 V2 Typ; simp V; simpls...
splits...
forwards (v21 & v22 & ? & ? & ?): prod_canonical Typ...
substs.
inverts V1.
inverts Typ.
exists v21 v22.
splits...
Qed.
Lemma V_andl : forall C v11 v12 v2 A B,
value v11 ->
value v12 ->
value v2 ->
typ nil nil v11 (|A|) ->
typ nil nil v12 (|B|) ->
V (sty_and A B) C (exp_pair v11 v12) v2 <->
V A C v11 v2 /\ V B C v12 v2.
Proof with eauto.
intros C.
induction C; introv V11 V12 V2 Typ1 Typ2.
splits.
introv RelV.
simp V in RelV.
destruct RelV as (ValP & ? & v11' & v12' & Eq & RelV1 & RelV2).
inverts Eq.
splits~.
introv (RelV1 & RelV2).
lets (? & ?): V_value RelV1.
lets (? & ?): V_value RelV2.
simp V.
splits~.
exists v11 v12.
splits~.
splits.
introv RelV.
splits; apply V_topr...
introv (RelV1 & RelV2).
lets (? & ?): V_value RelV1.
lets (? & ?): V_value RelV2.
simp V.
splits~.
exists v11 v12.
splits...
splits.
introv RelV.
simp V in RelV.
destruct RelV as (ValP & ? & v11' & v12' & Eq & RelV1 & RelV2).
inverts Eq.
splits~.
introv (RelV1 & RelV2).
lets (? & ?): V_value RelV1.
lets (? & ?): V_value RelV2.
simp V.
splits~.
exists v11 v12.
splits~.
splits.
introv RelV.
simp V in RelV.
destruct RelV as (ValP & ? & v11' & v12' & Eq & RelV1 & RelV2).
inverts Eq.
splits~.
introv (RelV1 & RelV2).
lets (? & ?): V_value RelV1.
lets (? & ?): V_value RelV2.
simp V.
splits~.
exists v11 v12.
splits~.
splits.
introv RelV.
simp V in RelV.
destruct RelV as (ValP & ? & v11' & v12' & Eq & RelV1 & RelV2).
inverts Eq.
splits~.
introv (RelV1 & RelV2).
lets (? & ?): V_value RelV1.
lets (? & ?): V_value RelV2.
simp V.
splits~.
exists v11 v12.
splits~.
splits.
introv RelV.
simp V in RelV.
destruct RelV as (ValP & ? & v11' & v12' & Eq & RelV1 & RelV2).
inverts Eq.
splits~.
introv (RelV1 & RelV2).
lets (? & ?): V_value RelV1.
lets (? & ?): V_value RelV2.
simp V.
splits~.
exists v11 v12.
splits~.
splits.
introv RelV.
simp V in RelV.
destruct RelV as (ValP & ? & v11' & v12' & Eq & RelV1 & RelV2).
inverts Eq.
splits~.
introv (RelV1 & RelV2).
lets (? & ?): V_value RelV1.
lets (? & ?): V_value RelV2.
simp V.
splits~.
exists v11 v12.
splits~.
splits.
introv RelV.
simp V in RelV.
destruct RelV as (ValP & ? & v11' & v12' & Eq & RelV1 & RelV2).
inverts Eq.
splits~.
introv (RelV1 & RelV2).
lets (? & ?): V_value RelV1.
lets (? & ?): V_value RelV2.
simp V.
splits~.
exists v11 v12.
splits~.
splits.
introv RelV.
simp V in RelV.
destruct RelV as (ValP & ? & v11' & v12' & Eq & RelV1 & RelV2).
inverts Eq.
splits~.
introv (RelV1 & RelV2).
lets (? & ?): V_value RelV1.
lets (? & ?): V_value RelV2.
simp V.
splits~.
exists v11 v12.
splits~.
Qed.
Lemma V_andr : forall C v11 v12 v2 A B,
value v11 ->
value v12 ->
value v2 ->
typ nil nil v2 (|C|) ->
typ nil nil v11 (|A|) ->
typ nil nil v12 (|B|) ->
V C (sty_and A B) v2 (exp_pair v11 v12) <->
V C A v2 v11 /\ V C B v2 v12.
Proof with eauto.
intros C.
induction C; introv V11 V12 V2 Typ1 Typ2 Typ3.
split.
introv RelV.
simp V in RelV.
destruct RelV as (ValP & ? & v11' & v12' & Eq & RelV1 & RelV2).
inverts Eq.
splits~.
introv (RelV1 & RelV2).
lets (? & ?): V_value RelV1.
lets (? & ?): V_value RelV2.
simp V.
splits~.
exists v11 v12.
splits~.
split.
introv RelV.
splits; apply V_topl...
introv (RelV1 & RelV2).
lets (? & ?): V_value RelV1.
lets (? & ?): V_value RelV2.
simp V.
splits~.
exists v11 v12.
splits...
split.
introv RelV.
simp V in RelV.
destruct RelV as (ValP & ? & v11' & v12' & Eq & RelV1 & RelV2).
inverts Eq.
splits~.
introv (RelV1 & RelV2).
lets (? & ?): V_value RelV1.
lets (? & ?): V_value RelV2.
simp V.
splits~.
exists v11 v12.
splits~.
split.
introv RelV.
simp V in RelV.
destruct RelV as (ValP & ? & v11' & v12' & Eq & RelV1 & RelV2).
inverts Eq.
splits~.
introv (RelV1 & RelV2).
lets (? & ?): V_value RelV1.
lets (? & ?): V_value RelV2.
simp V.
splits~.
exists v11 v12.
splits~.
split.
introv RelV.
simp V in RelV.
destruct RelV as (ValP & ? & v11' & v12' & Eq & RelV1 & RelV2).
inverts Eq.
splits~.
introv (RelV1 & RelV2).
lets (? & ?): V_value RelV1.
lets (? & ?): V_value RelV2.
simp V.
splits~.
exists v11 v12.
splits~.
split.
introv RelV.
simp V in RelV.
destruct RelV as (ValP & ? & v11' & v12' & Eq & RelV1 & RelV2).
inverts Eq.
splits~.
introv (RelV1 & RelV2).
lets (? & ?): V_value RelV1.
lets (? & ?): V_value RelV2.
simp V.
splits~.
exists v11 v12.
splits~.
simpls.
split.
introv RelV.
simp V in RelV.
destruct RelV as (ValP & ? & v11' & v12' & Eq & RelV1 & RelV2).
substs.
lets (? & ?) : V_value RelV1.
lets (? & ?) : V_value RelV2.
inverts Typ1.
assert (Temp : V C1 A v11' v11 /\ V C1 B v11' v12).
apply IHC1...
destructs Temp.
assert (Temp: V C2 A v12' v11 /\ V C2 B v12' v12).
apply IHC2...
destructs Temp.
splits; apply V_andl...
introv (RelV1 & RelV2).
simp V.
splits~.
lets~ (v21 & v22 & ? & ? & ?): prod_canonical Typ1.
substs.
inverts Typ1.
apply V_andl in RelV1...
apply V_andl in RelV2...
destructs RelV1.
destructs RelV2.
exists v21 v22.
splits~.
apply IHC1...
apply IHC2...
split.
introv RelV.
simp V in RelV.
destruct RelV as (ValP & ? & v11' & v12' & Eq & RelV1 & RelV2).
inverts Eq.
splits~.
introv (RelV1 & RelV2).
lets (? & ?): V_value RelV1.
lets (? & ?): V_value RelV2.
simp V.
splits~.
exists v11 v12.
splits~.
split.
introv RelV.
simp V in RelV.
destruct RelV as (ValP & ? & v11' & v12' & Eq & RelV1 & RelV2).
inverts Eq.
splits~.
introv (RelV1 & RelV2).
lets (? & ?): V_value RelV1.
lets (? & ?): V_value RelV2.
simp V.
splits~.
exists v11 v12.
splits~.
Qed.
Lemma var_empty : forall v X,
typ nil nil v (ty_var_f X) ->
False.
Proof with eauto.
introv H.
lets (? & ? & Bad): typing_regular H.
apply ftv_in_dom in Bad.
simpls.
assert (X `in` empty).
fsetdec.
eapply empty_iff...
Qed.
Lemma V_sym_helper : forall m A B v1 v2,
num_of_all.num_of_all A < m ->
lc_sty A ->
lc_sty B ->
typ nil nil v1 (|A|) ->
typ nil nil v2 (|B|) ->
V A B v1 v2 ->
V B A v2 v1.
Proof with eauto; try omega.
intro m. induction m; introv lem.
inversion lem.
introv TA.
gen B v1 v2.
induction TA; simpl in lem.
- Case "A = nat".
introv TB.
gen v1 v2.
induction TB; introv TyA TyB VH; simp V in *; try solve [inverts~ VH | destructs~ VH].
destruct VH as (? & ? & v21 & v22 & ? & ? & ?).
substs.
simpls.
inverts TyB.
splits...
exists v21 v22.
splits...
- Case "A = top".
introv TB TyA TyB VH.
lets (? & ?): V_value VH.
apply V_topr...
- Case "A = bot".
introv TB TyA TyB VH.
lets (? & ?): V_value VH.
simpls.
eapply ty_absurd in TyA; simpls...
- Case "A = var".
intros.
simpls.
false var_empty...
- Case "A = arrow".
introv TB.
gen v1 v2.
induction TB; introv TyA TyB VH; simp V in *; try solve [inverts~ VH | destructs~ VH].
+ SCase "B = arrow ".
destruct VH as (? & ? & VH).
splits...
introv VH1 TV1 TV2.
apply IHTA1 in VH1...
forwards (vv1 & vv2 & ? & ? & ? & ? & VH2) : VH VH1...
exists vv2 vv1.
splits...
apply IHTA2...
eapply preservation_multi_step...
eapply preservation_multi_step...
+ SCase "B = and".
destruct VH as (? & ? & v21 & v22 & ? & ? & VH).
substs.
inverts TyB.
splits...
exists v21 v22.
splits...
- Case "A = and".
introv TB TyA TyB VH.
lets (? & ?) : V_value VH.
simpls.
lets Prod : prod_canonical TyA...
destruct Prod as (vv1 & vv2 & ? & ? & ?).
substs.
inverts TyA.
eapply V_andr...
eapply V_andl in VH...
destruct VH as (VH1 & VH2).
splits...
apply IHTA1...
apply IHTA2...
- Case "A = forall".
introv TB.
gen v1 v2.
induction TB; introv TyA TyB VH; simp V in *; try solve [inverts~ VH | destructs~ VH].
+ SCase "B = and".
destruct VH as (? & ? & v21 & v22 & ? & ? & VH).
substs.
inverts TyB.
splits...
exists v21 v22.
splits...
+ SCase "B = forall".
destruct VH as (? & ? & VH).
splits...
introv Dis WFT Mono.
assert (Dis' : disjoint [] t (sty_and A A0)).
apply disjoint_and in Dis...
destruct Dis.
eapply disjoint_and...
forwards (vv1 & vv2 & ? & ? & ? & ? & VH') : VH Dis'...
exists vv2 vv1.
splits...
apply IHm...
rewrite num_of_all.num_of_all_open_mono...
apply lc_body_sty_wrt_sty...
apply lc_body_sty_wrt_sty...
eapply preservation_multi_step with (exp_tapp v1 (| t |))...
autorewrite with lr_rewrite...
apply preservation_multi_step with (exp_tapp v2 (| t |))...
autorewrite with lr_rewrite...
- Case "A = record".
introv TB.
gen v1 v2.
induction TB; introv TyA TyB VH; simp V in *; try solve [inverts~ VH | destructs~ VH].
+ SCase "B = and".
destruct VH as (? & ? & v21 & v22 & ? & ? & VH).
substs.
inverts TyB.
splits...
exists v21 v22.
splits...
+ SCase "B = record".
destruct VH as (? & ? & VH).
splits...
case_if in VH; case_if...
Qed.
Lemma V_sym : forall A B v1 v2,
lc_sty A ->
lc_sty B ->
typ nil nil v1 (|A|) ->
typ nil nil v2 (|B|) ->
V A B v1 v2 ->
V B A v2 v1.
Proof with eauto.
intros.
eapply V_sym_helper...
Qed.
Lemma E_sym : forall e1 e2 A B,
E A B e1 e2 ->
E B A e2 e1.
Proof with eauto.
introv EH.
destruct EH as (? & ? & ? & ? & v1 & v2 & ? & ? & ? & ? & VH).
splits...
exists v2 v1.
splits...
apply V_sym; try eapply preservation_multi_step...
Qed.
Lemma V_toplike_helper : forall m A B v1 v2,
num_of_all.num_of_all A < m ->
TopLike A ->
lc_sty B ->
lc_sty A ->
value v1 ->
value v2 ->
typ nil nil v1 (| A |) ->
typ nil nil v2 (| B |) ->
V A B v1 v2.
Proof with eauto; try omega.
intro m. induction m; introv lem.
inversion lem.
introv TA.
gen B v1 v2.
induction TA; simpl in lem.
- Case "top".
intros.
eapply V_topl...
- Case "and".
introv LC1 LC2 ? ? TyA TyB.
simpls.
inverts LC2.
lets (vv1 & vv2 & ? & ? & ?) : prod_canonical TyA...
substs.
inverts TyA.
eapply V_andl...
splits...
apply IHTA1...
apply IHTA2...
- Case "arrow".
introv TB.
gen v1 v2.
induction TB; introv LC1 ? ? TyA TyB; simp V; splits; simpls...
+ SCase "arrow".
introv VH Ty11 Ty22.
inverts LC1.
lets Ty3 : typ_app TyA Ty11.
lets Ty4 : typ_app TyB Ty22.
lets (vv1 & ? & Tvv1) : normalization Ty3.
lets (vv2 & ? & Tvv2) : normalization Ty4.
forwards : preservation_multi_step Tvv1...
forwards : preservation_multi_step Tvv2...
exists vv1 vv2.
splits...
eapply IHTA...
+ SCase "and".
inverts LC1.
lets~ (v21 & v22 & ? & ? & ?): prod_canonical TyB.
substs.
inverts TyB...
exists v21 v22.
splits...
- Case "forall".
introv TB.
gen v1 v2.
induction TB; introv LC1 ? ? TyA TyB; simp V; splits; simpls...
+ SCase "and".
lets~ (v21 & v22 & ? & ? & ?): prod_canonical TyB.
substs.
inverts TyB...
exists v21 v22.
splits...
+ SCase "forall".
introv Dis SWF Mono.
forwards Ty3 : typ_tapp (|t|) TyA...
forwards Ty4 : typ_tapp (|t|) TyB...
forwards (vv1 & ? & ?) : normalization Ty3...
forwards (vv2 & ? & ?) : normalization Ty4...
inverts LC1.
exists vv1 vv2.
splits...
eapply IHm...
rewrite num_of_all.num_of_all_open_mono...
pick fresh X.
rewrite (subst_sty_in_sty_intro X)...
eapply subst_toplike...
apply lc_body_sty_wrt_sty...
apply lc_body_sty_wrt_sty...
eapply preservation_multi_step with (exp_tapp v1 (| t |))...
autorewrite with lr_rewrite...
eapply preservation_multi_step with (exp_tapp v2 (| t |))...
autorewrite with lr_rewrite...
- Case "rcd".
introv TB.
gen v1 v2.
induction TB; introv LC1 ? ? TyA TyB; simp V; splits; simpls...
+ SCase "and".
lets~ (v21 & v22 & ? & ? & ?): prod_canonical TyB.
substs.
inverts TyB...
exists v21 v22.
splits...
+ SCase "rcd".
case_if~.
inverts LC1.
eapply IHTA...
Qed.
Lemma V_toplike : forall A B v1 v2,
TopLike A ->
lc_sty B ->
lc_sty A ->
value v1 ->
value v2 ->
typ nil nil v1 (| A |) ->
typ nil nil v2 (| B |) ->