-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFsub_LetSum_Soundness.v
2752 lines (2612 loc) · 94.2 KB
/
Fsub_LetSum_Soundness.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
(** Type-safety proofs for Fsub.CaptureTrack.
Authors: Brian Aydemir and Arthur Chargu\'eraud, with help from
Aaron Bohannon, Jeffrey Vaughan, and Dimitrios Vytiniotis.
In parentheses are given the label of the corresponding lemma in
the appendix (informal proofs) of the POPLmark Challenge.
Table of contents:
- #<a href="##subtyping">Properties of subtyping</a>#
- #<a href="##typing">Properties of typing</a>#
- #<a href="##preservation">Preservation</a>#
- #<a href="##progress">Progress</a># *)
Require Import Fsub.CaptureTrack.Tactics.
Require Import Coq.Program.Equality.
Require Export Fsub.CaptureTrack.Fsub_LetSum_Lemmas.
(* ********************************************************************** *)
(** * #<a name="subtyping"></a># Properties of subtyping *)
(* ********************************************************************** *)
(** ** Reflexivity (1) *)
Lemma subqual_reflexivity : forall E T,
wf_env E ->
wf_qua E T ->
subqual E T T.
Proof with eauto 6.
intros E T Ok Wf.
induction Wf...
Qed.
Lemma sub_reflexivity : forall E T,
wf_env E ->
wf_typ E T ->
sub E T T
with subqtype_reflexivity : forall E T,
wf_env E ->
wf_qtyp E T ->
subqtype E T T.
Proof with eauto using subqual_reflexivity.
------
clear sub_reflexivity.
intros E T Ok Wf.
induction Wf...
pick fresh y and apply sub_arrow...
pick fresh Y and apply sub_all...
pick fresh Y and apply sub_qall...
------
clear subqtype_reflexivity.
intros E T Ok Wf.
induction Wf...
Qed.
(* ********************************************************************** *)
(** ** Weakening (2) *)
Lemma subqual_weakening : forall E F G S T,
subqual (G ++ E) S T ->
wf_env (G ++ F ++ E) ->
subqual (G ++ F ++ E) S T.
Proof with simpl_env; auto 6 using wf_qua_weakening.
intros E F G S T Sub Ok.
remember (G ++ E) as H.
generalize dependent G.
induction Sub; intros G Ok EQ; subst...
Case "subqual_trans_qvar".
apply (subqual_trans_qvar R)...
Case "subqual_trans_term_qvar".
apply (subqual_trans_term_qvar R) with (T := T)...
Qed.
Lemma sub_weakening : forall E F G S T,
sub (G ++ E) S T ->
wf_env (G ++ F ++ E) ->
sub (G ++ F ++ E) S T
with subqtype_weakening : forall E F G S T,
subqtype (G ++ E) S T ->
wf_env (G ++ F ++ E) ->
subqtype (G ++ F ++ E) S T.
Proof with simpl_env; auto using wf_typ_weakening, subqual_weakening,
wf_qtyp_weakening, wf_qua_weakening.
------
clear sub_weakening.
intros E F G S T Sub Ok.
remember (G ++ E) as H.
generalize dependent G.
induction Sub; intros G Ok EQ; subst...
Case "sub_trans_tvar".
apply (sub_trans_tvar U)...
Case "sub_arrow".
pick fresh y and apply sub_arrow...
rewrite <- app_assoc.
apply subqtype_weakening...
Case "sub_all".
pick fresh Y and apply sub_all...
rewrite <- app_assoc.
apply subqtype_weakening...
Case "sub_qall".
pick fresh Y and apply sub_qall...
rewrite <- app_assoc.
apply subqtype_weakening...
------
clear subqtype_weakening.
intros E F G S T Sub Ok.
remember (G ++ E) as H.
generalize dependent G.
induction Sub; intros G Ok EQ; subst...
Qed.
(* ********************************************************************** *)
(** ** Narrowing and transitivity (3) *)
Definition transitivity_on_sub Q := forall E S T,
sub E S Q -> sub E Q T -> sub E S T.
Definition transitivity_on_subqtype Q := forall E S T,
subqtype E S Q -> subqtype E Q T -> subqtype E S T.
Definition transitivity_on_subqual Q := forall E S T,
subqual E S Q -> subqual E Q T -> subqual E S T.
Lemma subqual_join_split : forall E R1 R2 T,
subqual E (qua_join R1 R2) T ->
subqual E R1 T /\ subqual E R2 T.
Proof with eauto.
intros * Sub.
dependent induction Sub; try solve [intuition eauto]...
- edestruct IHSub...
- edestruct IHSub...
- edestruct IHSub1...
edestruct IHSub2...
Qed.
Lemma subqual_transitivity : forall Q,
transitivity_on_subqual Q.
Proof with simpl_env; auto.
unfold transitivity_on_subqual.
intros Q E S T SsubQ QsubT.
generalize dependent T.
induction SsubQ; intros Tq QsubT...
* dependent induction QsubT...
* eapply subqual_trans_qvar with (R := R)...
* eapply subqual_trans_term_qvar with (R := R) (T := T)...
* eapply subqual_join_split in QsubT as [SubL SubR]...
* eapply subqual_join_split in QsubT as [SubL SubR]...
* remember (qua_meet R1 R2) as R.
induction QsubT; inversion HeqR; subst...
Qed.
Lemma subqual_narrowing_qua_aux : forall Q F E Z P S T,
transitivity_on_subqual Q ->
subqual (F ++ Z ~ bind_qua Q ++ E) S T ->
subqual E P Q ->
subqual (F ++ Z ~ bind_qua P ++ E) S T.
Proof with simpl_env; eauto using wf_qua_narrowing_qua,
wf_env_narrowing_qua.
intros Q F E Z P S T TransQ SsubT PsubQ.
remember (F ++ Z ~ bind_qua Q ++ E) as G. generalize dependent F.
induction SsubT; intros F EQ; subst...
Case "sub_trans_tvar".
destruct (X == Z); subst.
SCase "X = Z".
apply (subqual_trans_qvar P); [ eauto using fresh_mid_head | ].
apply TransQ.
SSCase "P <: Q".
rewrite_env (empty ++ (F ++ Z ~ bind_qua P) ++ E).
apply subqual_weakening...
SSCase "Q <: T".
analyze_binds_uniq H.
injection BindsTacVal; intros; subst...
SCase "X <> Z".
apply (subqual_trans_qvar R)...
Case "sub_trans_term_tvar".
destruct (X == Z); subst...
exfalso. analyze_binds_uniq H.
Qed.
Lemma subqual_narrowing_sub_aux : forall Q F E Z P S T,
transitivity_on_sub Q ->
subqual (F ++ Z ~ bind_sub Q ++ E) S T ->
sub E P Q ->
subqual (F ++ Z ~ bind_sub P ++ E) S T.
Proof with simpl_env; eauto using wf_qua_narrowing_sub,
wf_env_narrowing_sub.
intros Q F E Z P S T TransQ SsubT PsubQ.
remember (F ++ Z ~ bind_sub Q ++ E) as G. generalize dependent F.
induction SsubT; intros F EQ; subst...
Case "sub_trans_tvar".
destruct (X == Z); subst...
exfalso. analyze_binds_uniq H.
Case "sub_trans_term_tvar".
destruct (X == Z); subst...
exfalso. analyze_binds_uniq H.
Qed.
Lemma subqual_narrowing_typ_aux : forall Q F E Z P S T,
transitivity_on_subqtype Q ->
subqual (F ++ Z ~ bind_typ Q ++ E) S T ->
subqtype E P Q ->
subqual (F ++ Z ~ bind_typ P ++ E) S T.
Proof with simpl_env; eauto using wf_qua_narrowing_typ,
wf_env_narrowing_typ.
intros Q F E Z P S T TransQ SsubT PsubQ.
remember (F ++ Z ~ bind_typ Q ++ E) as G.
generalize dependent F.
induction SsubT; intros F EQ; subst...
Case "sub_trans_tvar".
destruct (X == Z); subst...
exfalso. analyze_binds_uniq H.
Case "sub_trans_term_tvar".
destruct (X == Z); subst...
destruct P as [R2 T2].
apply subqual_trans_term_qvar with (R := R2) (T := T2)...
inversion PsubQ; analyze_binds_uniq H; subst...
inversion BindsTacVal; subst...
eapply (subqual_transitivity Q2)...
rewrite_env (empty ++ (F ++ Z ~ bind_typ (qtyp_qtyp R2 T2)) ++ E).
apply subqual_weakening...
Qed.
Lemma sub_narrowing_sub_aux : forall Q F E Z P S T,
transitivity_on_sub Q ->
sub (F ++ Z ~ bind_sub Q ++ E) S T ->
sub E P Q ->
sub (F ++ Z ~ bind_sub P ++ E) S T
with subqtype_narrowing_sub_aux : forall Q F E Z P S T,
transitivity_on_sub Q ->
subqtype (F ++ Z ~ bind_sub Q ++ E) S T ->
sub E P Q ->
subqtype (F ++ Z ~ bind_sub P ++ E) S T.
Proof with simpl_env; eauto using wf_typ_narrowing_sub, wf_env_narrowing_sub,
subqual_narrowing_sub_aux.
------
clear sub_narrowing_sub_aux.
intros Q F E Z P S T TransQ SsubT PsubQ.
remember (F ++ Z ~ bind_sub Q ++ E) as G. generalize dependent F.
induction SsubT; intros F EQ; subst...
Case "sub_trans_tvar".
destruct (X == Z); subst.
SCase "X = Z".
apply (sub_trans_tvar P); [ eauto using fresh_mid_head | ].
apply TransQ.
SSCase "P <: Q".
rewrite_env (empty ++ (F ++ Z ~ bind_sub P) ++ E).
apply sub_weakening...
SSCase "Q <: T".
analyze_binds_uniq H.
injection BindsTacVal; intros; subst...
SCase "X <> Z".
apply (sub_trans_tvar U)...
Case "sub_arrow".
pick fresh Y and apply sub_arrow...
rewrite <- app_assoc.
eapply subqtype_narrowing_sub_aux...
Case "sub_all".
pick fresh Y and apply sub_all...
rewrite <- app_assoc.
eapply subqtype_narrowing_sub_aux...
Case "sub_qall".
pick fresh Y and apply sub_qall...
rewrite <- app_assoc.
eapply subqtype_narrowing_sub_aux...
------
clear subqtype_narrowing_sub_aux.
intros Q F E Z P S T TransQ SsubT PsubQ.
remember (F ++ Z ~ bind_sub Q ++ E) as G. generalize dependent F.
induction SsubT; intros F EQ; subst...
Qed.
Lemma sub_narrowing_qua_aux : forall Q F E Z P S T,
transitivity_on_subqual Q ->
sub (F ++ Z ~ bind_qua Q ++ E) S T ->
subqual E P Q ->
sub (F ++ Z ~ bind_qua P ++ E) S T
with subqtype_narrowing_qua_aux : forall Q F E Z P S T,
transitivity_on_subqual Q ->
subqtype (F ++ Z ~ bind_qua Q ++ E) S T ->
subqual E P Q ->
subqtype (F ++ Z ~ bind_qua P ++ E) S T.
Proof with simpl_env; eauto using wf_typ_narrowing_qua, wf_env_narrowing_qua,
subqual_narrowing_qua_aux.
------
clear sub_narrowing_qua_aux.
intros Q F E Z P S T TransQ SsubT PsubQ.
remember (F ++ Z ~ bind_qua Q ++ E) as G. generalize dependent F.
induction SsubT; intros F EQ; subst...
Case "sub_trans_tvar".
destruct (X == Z); subst.
SCase "X = Z".
exfalso. analyze_binds_uniq H...
SCase "X <> Z".
apply (sub_trans_tvar U)...
Case "sub_arrow".
pick fresh Y and apply sub_arrow...
rewrite <- app_assoc.
eapply subqtype_narrowing_qua_aux...
Case "sub_all".
pick fresh Y and apply sub_all...
rewrite <- app_assoc.
eapply subqtype_narrowing_qua_aux...
Case "sub_qall".
pick fresh Y and apply sub_qall...
rewrite <- app_assoc.
eapply subqtype_narrowing_qua_aux...
------
clear subqtype_narrowing_qua_aux.
intros Q F E Z P S T TransQ SsubT PsubQ.
remember (F ++ Z ~ bind_qua Q ++ E) as G. generalize dependent F.
induction SsubT; intros F EQ; subst...
Qed.
Lemma sub_narrowing_typ_aux : forall Q F E Z P S T,
transitivity_on_subqtype Q ->
sub (F ++ Z ~ bind_typ Q ++ E) S T ->
subqtype E P Q ->
sub (F ++ Z ~ bind_typ P ++ E) S T
with subqtype_narrowing_typ_aux : forall Q F E Z P S T,
transitivity_on_subqtype Q ->
subqtype (F ++ Z ~ bind_typ Q ++ E) S T ->
subqtype E P Q ->
subqtype (F ++ Z ~ bind_typ P ++ E) S T.
Proof with simpl_env; eauto using wf_typ_narrowing_typ, wf_env_narrowing_typ,
subqual_narrowing_typ_aux.
------
clear sub_narrowing_typ_aux.
intros Q F E Z P S T TransQ SsubT PsubQ.
remember (F ++ Z ~ bind_typ Q ++ E) as G.
generalize dependent F.
induction SsubT; intros F EQ; subst...
Case "sub_trans_tvar".
destruct (X == Z); subst.
SCase "X = Z".
analyze_binds_uniq H...
SCase "X <> Z".
apply (sub_trans_tvar U)...
Case "sub_arrow".
pick fresh Y and apply sub_arrow...
rewrite <- app_assoc.
eapply subqtype_narrowing_typ_aux...
Case "sub_all".
pick fresh Y and apply sub_all...
rewrite <- app_assoc.
eapply subqtype_narrowing_typ_aux...
Case "sub_qall".
pick fresh Y and apply sub_qall...
rewrite <- app_assoc.
eapply subqtype_narrowing_typ_aux...
------
clear subqtype_narrowing_typ_aux.
intros Q F E Z P S T TransQ SsubT PsubQ.
remember (F ++ Z ~ bind_typ Q ++ E) as G. generalize dependent F.
induction SsubT; intros F EQ; subst...
Qed.
Lemma sub_transitivity_rec : forall Q,
type Q -> transitivity_on_sub Q
with subqtype_transitivity_rec : forall Q,
qtype Q -> transitivity_on_subqtype Q.
Proof with simpl_env; auto.
------
clear sub_transitivity_rec.
unfold transitivity_on_sub.
intros Q W E S T SsubQ QsubT.
generalize dependent T.
generalize dependent S.
generalize dependent E.
remember Q as Q' in |- *.
generalize dependent Q'.
induction W;
intros Q' EQ E S SsubQ;
induction SsubQ; try discriminate; inversion EQ; subst;
intros T' QsubT;
inversion QsubT; subst; eauto 4 using sub_trans_tvar.
Case "sub_arrow / sub_top".
assert (sub E (typ_arrow S1 S2) (typ_arrow T1 T2)).
SCase "proof of assertion".
pick fresh y and apply sub_arrow...
auto.
Case "sub_arrow / sub_arrow".
pick fresh Y and apply sub_arrow...
SCase "bounds".
eapply subqtype_transitivity_rec with (Q := T1)...
SCase "bodies".
lapply (H2 Y); [ intros K | auto ].
lapply (H8 Y); [ intros K2 | auto ].
eapply subqtype_transitivity_rec...
rewrite_env (empty ++ Y ~ bind_typ T0 ++ E).
eapply (subqtype_narrowing_typ_aux T1)...
Case "sub_all / sub_top".
assert (sub E (typ_all S1 S2) (typ_all T1 T2)).
SCase "proof of assertion".
pick fresh y and apply sub_all...
auto.
Case "sub_all / sub_all".
pick fresh Y and apply sub_all.
SCase "bounds".
eauto.
SCase "bodies".
lapply (H0 Y); [ intros K | auto ].
lapply (H6 Y); [ intros K2 | auto ].
eapply subqtype_transitivity_rec with (Q := (open_tqt T2 Y))...
rewrite_env (empty ++ Y ~ bind_sub T0 ++ E).
eapply (subqtype_narrowing_sub_aux T1)...
unshelve epose proof (IHW T1 _) as TransT1...
unfold transitivity_on_sub; eauto using TransT1...
Case "sub_qall / sub_top".
assert (sub E (typ_qall S1 S2) (typ_qall Q T)).
SCase "proof of assertion".
pick fresh y and apply sub_qall...
auto.
Case "sub_qall / sub_qall".
pick fresh Y and apply sub_qall...
SCase "bounds".
eapply subqual_transitivity with (Q := Q)...
SCase "bodies".
lapply (H2 Y); [ intros K | auto ].
lapply (H8 Y); [ intros K2 | auto ].
eapply subqtype_transitivity_rec...
rewrite_env (empty ++ Y ~ bind_qua T1 ++ E).
eapply subqtype_narrowing_qua_aux ...
apply subqual_transitivity.
Case "sub_sum / sub_sum".
eapply sub_sum...
eapply subqtype_transitivity_rec with (Q := T1)...
eapply subqtype_transitivity_rec with (Q := T2)...
Case "sub_pair / sub_pair".
eapply sub_pair...
eapply subqtype_transitivity_rec with (Q := T1)...
eapply subqtype_transitivity_rec with (Q := T2)...
------
clear subqtype_transitivity_rec.
unfold transitivity_on_subqtype.
intros Q W E S T SsubQ QsubT.
generalize dependent T.
generalize dependent S.
generalize dependent E.
remember Q as Q' in |- *.
generalize dependent Q'.
induction W;
intros Q' EQ E S SsubQ;
induction SsubQ; try discriminate; inversion EQ; subst;
intros T' QsubT;
inversion QsubT; subst; eauto 4 using sub_trans_tvar.
eapply sub_qtyp_qtyp...
eapply subqual_transitivity with (Q := Q)...
eapply sub_transitivity_rec with (Q := T)...
Qed.
Lemma sub_transitivity : forall Q,
transitivity_on_sub Q.
Proof with simpl_env; auto.
unfold transitivity_on_sub.
intros.
eapply sub_transitivity_rec with (Q := Q)...
Qed.
Lemma subqtype_transitivity : forall Q,
transitivity_on_subqtype Q.
Proof with simpl_env; auto.
unfold transitivity_on_subqtype.
intros.
eapply subqtype_transitivity_rec with (Q := Q)...
Qed.
Lemma sub_narrowing_sub : forall Q E F Z P S T,
sub E P Q ->
sub (F ++ Z ~ bind_sub Q ++ E) S T ->
sub (F ++ Z ~ bind_sub P ++ E) S T.
Proof.
intros.
eapply sub_narrowing_sub_aux; eauto.
apply sub_transitivity.
Qed.
Lemma subqtype_narrowing_sub : forall Q E F Z P S T,
sub E P Q ->
subqtype (F ++ Z ~ bind_sub Q ++ E) S T ->
subqtype (F ++ Z ~ bind_sub P ++ E) S T.
Proof.
intros.
eapply subqtype_narrowing_sub_aux; eauto.
apply sub_transitivity.
Qed.
Lemma subqual_narrowing_sub : forall Q E F Z P S T,
sub E P Q ->
subqual (F ++ Z ~ bind_sub Q ++ E) S T ->
subqual (F ++ Z ~ bind_sub P ++ E) S T.
Proof.
intros.
eapply subqual_narrowing_sub_aux; eauto.
apply sub_transitivity.
Qed.
Lemma sub_narrowing_qua : forall Q E F Z P S T,
subqual E P Q ->
sub (F ++ Z ~ bind_qua Q ++ E) S T ->
sub (F ++ Z ~ bind_qua P ++ E) S T.
Proof.
intros.
eapply sub_narrowing_qua_aux; eauto.
apply subqual_transitivity.
Qed.
Lemma subqtype_narrowing_qua : forall Q E F Z P S T,
subqual E P Q ->
subqtype (F ++ Z ~ bind_qua Q ++ E) S T ->
subqtype (F ++ Z ~ bind_qua P ++ E) S T.
Proof.
intros.
eapply subqtype_narrowing_qua_aux; eauto.
apply subqual_transitivity.
Qed.
Lemma subqual_narrowing_qua : forall Q E F Z P S T,
subqual E P Q ->
subqual (F ++ Z ~ bind_qua Q ++ E) S T ->
subqual (F ++ Z ~ bind_qua P ++ E) S T.
Proof.
intros.
eapply subqual_narrowing_qua_aux; eauto.
apply subqual_transitivity.
Qed.
Lemma sub_narrowing_typ : forall Q E F Z P S T,
subqtype E P Q ->
sub (F ++ Z ~ bind_typ Q ++ E) S T ->
sub (F ++ Z ~ bind_typ P ++ E) S T.
Proof.
intros.
eapply sub_narrowing_typ_aux; eauto.
apply subqtype_transitivity.
Qed.
Lemma subqtype_narrowing_typ : forall Q E F Z P S T,
subqtype E P Q ->
subqtype (F ++ Z ~ bind_typ Q ++ E) S T ->
subqtype (F ++ Z ~ bind_typ P ++ E) S T.
Proof.
intros.
eapply subqtype_narrowing_typ_aux; eauto.
apply subqtype_transitivity.
Qed.
Lemma subqual_narrowing_typ : forall Q E F Z P S T,
subqtype E P Q ->
subqual (F ++ Z ~ bind_typ Q ++ E) S T ->
subqual (F ++ Z ~ bind_typ P ++ E) S T.
Proof.
intros.
eapply subqual_narrowing_typ_aux; eauto.
apply subqtype_transitivity.
Qed.
(* ********************************************************************** *)
(** ** Type substitution preserves subtyping (10) *)
Lemma subqual_through_subst_qq : forall Q E F Z S T P,
subqual (F ++ Z ~ bind_qua Q ++ E) S T ->
subqual E P Q ->
subqual (map (subst_qb Z P) F ++ E) (subst_qq Z P S) (subst_qq Z P T).
Proof with simpl_env;
eauto 4 using wf_qua_subst_qb, wf_env_subst_qb, wf_qua_weaken_head.
intros Q E F Z S T P SsubT PsubQ.
remember (F ++ Z ~ bind_qua Q ++ E) as G.
generalize dependent F.
induction SsubT; intros G EQ; subst; simpl subst_qq...
Case "subqual_top".
eapply subqual_top...
Case "subqual_bot".
eapply subqual_bot...
Case "subqual_refl_fvar".
destruct (X == Z); subst.
SCase "X = Z".
apply subqual_reflexivity...
SCase "X <> Z".
apply subqual_reflexivity...
inversion H0; subst; analyze_binds H3...
apply (wf_qua_fvar (subst_qq Z P R))...
apply (wf_qua_term_fvar (subst_qqt Z P T))...
Case "subqual_trans_qvar".
destruct (X == Z); subst.
SCase "X = Z".
apply (subqual_transitivity Q).
SSCase "left branch".
rewrite_env (empty ++ map (subst_qb Z P) G ++ E).
apply subqual_weakening...
SSCase "right branch".
rewrite (subst_qq_fresh Z P Q).
analyze_binds_uniq H.
inversion BindsTacVal; subst...
apply (notin_fv_qq_wf_qua E); eauto using fresh_mid_tail.
SCase "X <> Z".
apply (subqual_trans_qvar (subst_qq Z P R))...
rewrite (map_subst_qb_id E Z P);
[ | auto | eapply fresh_mid_tail; eauto ].
analyze_binds H...
Case "subqual_trans_term_qvar".
destruct (X == Z); subst.
SCase "X = Z".
apply (subqual_transitivity Q).
SSCase "left branch".
rewrite_env (empty ++ map (subst_qb Z P) G ++ E).
apply subqual_weakening...
SSCase "right branch".
rewrite (subst_qq_fresh Z P Q).
analyze_binds_uniq H.
apply (notin_fv_qq_wf_qua E); eauto using fresh_mid_tail.
SCase "X <> Z".
apply (subqual_trans_term_qvar (subst_qq Z P R) _ (subst_qt Z P T))...
rewrite (map_subst_qb_id E Z P);
[ | auto | eapply fresh_mid_tail; eauto ].
replace (bind_typ (qtyp_qtyp (subst_qq Z P R) (subst_qt Z P T)))
with (subst_qb Z P (bind_typ (qtyp_qtyp R T)))...
analyze_binds H...
Case "subqual_join_inl".
apply subqual_join_inl...
Case "subqual_join_inr".
apply subqual_join_inr...
Case "subqual_meet_eliml".
apply subqual_meet_eliml...
Case "subqual_meet_elimr".
apply subqual_meet_elimr...
Qed.
Lemma subqual_through_subst_tt : forall Q E F Z S T P,
subqual (F ++ Z ~ bind_sub Q ++ E) S T ->
sub E P Q ->
subqual (map (subst_tb Z P) F ++ E) S T.
Proof with simpl_env;
eauto 4 using wf_qua_subst_tb, wf_env_subst_tb, wf_qua_weaken_head.
intros Q E F Z S T P SsubT PsubQ.
remember (F ++ Z ~ bind_sub Q ++ E) as G.
generalize dependent F.
induction SsubT; intros G EQ; subst; simpl...
Case "subqual_top".
apply subqual_top...
Case "subqual_bot".
eapply subqual_bot...
Case "subqual_refl_fvar".
apply subqual_reflexivity...
Case "subqual_trans_qvar".
apply (subqual_trans_qvar R)...
analyze_binds H...
unsimpl (subst_tb Z P (bind_qua R))...
Case "subqual_trans_term_qvar".
apply (subqual_trans_term_qvar R _ (subst_tt Z P T))...
analyze_binds H;
unsimpl (subst_tb Z P (bind_typ (qtyp_qtyp R T)))...
rewrite (map_subst_tb_id E Z P);
[ | auto | eapply fresh_mid_tail; eauto ]...
Case "subqual_join_inl".
apply subqual_join_inl...
Case "subqual_join_inr".
apply subqual_join_inr...
Case "subqual_meet_eliml".
apply subqual_meet_eliml...
Case "subqual_meet_elimr".
apply subqual_meet_elimr...
Qed.
Lemma subqual_through_subst_qq_var : forall Q R E F Z S T P,
subqual (F ++ Z ~ bind_typ (qtyp_qtyp Q R) ++ E) S T ->
subqual E P Q ->
subqual (map (subst_qb Z P) F ++ E) (subst_qq Z P S) (subst_qq Z P T).
Proof with simpl_env;
eauto 4 using wf_qua_subst_qb_var, wf_env_subst_qb_var, wf_qua_weaken_head.
intros Q R E F Z S T P SsubT PsubQ.
remember (F ++ Z ~ bind_typ (qtyp_qtyp Q R) ++ E) as G.
generalize dependent F.
induction SsubT; intros G EQ; subst; simpl subst_qq...
Case "subqual_top".
eapply subqual_top...
Case "subqual_bot".
eapply subqual_bot...
Case "subqual_refl_fvar".
destruct (X == Z); subst.
SCase "X = Z".
apply subqual_reflexivity...
SCase "X <> Z".
apply subqual_reflexivity...
inversion H0; subst; analyze_binds H3...
apply (wf_qua_fvar (subst_qq Z P R0))...
apply (wf_qua_term_fvar (subst_qqt Z P T))...
Case "subqual_trans_qvar".
destruct (X == Z); subst.
SCase "X = Z".
exfalso.
analyze_binds_uniq H...
SCase "X <> Z".
apply (subqual_trans_qvar (subst_qq Z P R0))...
rewrite (map_subst_qb_id E Z P);
[ | auto | eapply fresh_mid_tail; eauto ].
analyze_binds H...
Case "subqual_trans_term_qvar".
destruct (X == Z); subst.
SCase "X = Z".
apply (subqual_transitivity Q).
SSCase "left branch".
rewrite_env (empty ++ map (subst_qb Z P) G ++ E).
apply subqual_weakening...
SSCase "right branch".
rewrite (subst_qq_fresh Z P Q).
analyze_binds_uniq H.
inversion BindsTacVal; subst...
apply (notin_fv_qq_wf_qua E); eauto using fresh_mid_tail.
SCase "X <> Z".
apply (subqual_trans_term_qvar (subst_qq Z P R0) _ (subst_qt Z P T))...
rewrite (map_subst_qb_id E Z P);
[ | auto | eapply fresh_mid_tail; eauto ].
unsimpl (subst_qqt Z P (qtyp_qtyp R0 T)).
replace (bind_typ (subst_qqt Z P (qtyp_qtyp R0 T)))
with (subst_qb Z P (bind_typ (qtyp_qtyp R0 T))); [ | auto].
analyze_binds_uniq H...
Case "subqual_join_inl".
apply subqual_join_inl...
Case "subqual_join_inr".
apply subqual_join_inr...
Case "subqual_meet_eliml".
apply subqual_meet_eliml...
Case "subqual_meet_elimr".
apply subqual_meet_elimr...
Qed.
Lemma sub_through_subst_tt : forall Q E F Z S T P,
sub (F ++ Z ~ bind_sub Q ++ E) S T ->
sub E P Q ->
sub (map (subst_tb Z P) F ++ E) (subst_tt Z P S) (subst_tt Z P T)
with subqtype_through_subst_tqt : forall Q E F Z S T P,
subqtype (F ++ Z ~ bind_sub Q ++ E) S T ->
sub E P Q ->
subqtype (map (subst_tb Z P) F ++ E) (subst_tqt Z P S) (subst_tqt Z P T).
Proof with
simpl_env;
eauto 4 using wf_typ_subst_tb, wf_env_subst_tb, wf_typ_weaken_head.
------
clear sub_through_subst_tt.
intros Q E F Z S T P SsubT PsubQ.
remember (F ++ Z ~ bind_sub Q ++ E) as G.
generalize dependent F.
induction SsubT; intros G EQ; subst; simpl subst_tt...
Case "sub_top".
apply sub_top...
Case "sub_refl_tvar".
destruct (X == Z); subst.
SCase "X = Z".
apply sub_reflexivity...
SCase "X <> Z".
apply sub_reflexivity...
inversion H0; subst.
analyze_binds H3...
apply (wf_typ_var (subst_tt Z P U))...
Case "sub_trans_tvar".
destruct (X == Z); subst.
SCase "X = Z".
apply (sub_transitivity Q).
SSCase "left branch".
rewrite_env (empty ++ map (subst_tb Z P) G ++ E).
apply sub_weakening...
SSCase "right branch".
rewrite (subst_tt_fresh Z P Q).
analyze_binds_uniq H.
inversion BindsTacVal; subst...
apply (notin_fv_tt_wf_typ E); eauto using fresh_mid_tail.
SCase "X <> Z".
apply (sub_trans_tvar (subst_tt Z P U))...
rewrite (map_subst_tb_id E Z P);
[ | auto | eapply fresh_mid_tail; eauto ].
analyze_binds H...
Case "sub_arrow".
pick fresh x and apply sub_arrow...
rewrite subst_tqt_open_qqt_var...
rewrite subst_tqt_open_qqt_var...
rewrite_env (map (subst_tb Z P) (x ~ bind_typ T1 ++ G) ++ E).
eapply subqtype_through_subst_tqt...
Case "sub_all".
pick fresh X and apply sub_all...
rewrite subst_tqt_open_tqt_var...
rewrite subst_tqt_open_tqt_var...
rewrite_env (map (subst_tb Z P) (X ~ bind_sub T1 ++ G) ++ E).
eapply subqtype_through_subst_tqt...
Case "sub_qall".
apply (sub_qall L)...
eapply subqual_through_subst_tt...
intros.
rewrite <- subst_tqt_open_qqt...
rewrite <- subst_tqt_open_qqt...
rewrite_env (map (subst_tb Z P) (X ~ bind_qua T1 ++ G) ++ E).
eapply subqtype_through_subst_tqt...
------
clear subqtype_through_subst_tqt.
intros Q E F Z S T P SsubT PsubQ.
remember (F ++ Z ~ bind_sub Q ++ E) as G.
generalize dependent F.
induction SsubT; intros G EQ; subst; simpl subst_tt...
econstructor; eauto using subqual_through_subst_tt...
Qed.
Lemma sub_through_subst_qt : forall Q E F Z S T P,
sub (F ++ Z ~ bind_qua Q ++ E) S T ->
subqual E P Q ->
sub (map (subst_qb Z P) F ++ E) (subst_qt Z P S) (subst_qt Z P T)
with subqtype_through_subst_qqt : forall Q E F Z S T P,
subqtype (F ++ Z ~ bind_qua Q ++ E) S T ->
subqual E P Q ->
subqtype (map (subst_qb Z P) F ++ E) (subst_qqt Z P S) (subst_qqt Z P T).
Proof with
simpl_env;
eauto 4 using wf_typ_subst_qb, wf_env_subst_qb, wf_typ_weaken_head,
subqual_through_subst_qq.
------
clear sub_through_subst_qt.
intros Q E F Z S T P SsubT PsubQ.
remember (F ++ Z ~ bind_qua Q ++ E) as G.
generalize dependent F.
induction SsubT; intros G EQ; subst; simpl subst_qt...
Case "sub_top".
apply sub_top...
Case "sub_refl_tvar".
apply sub_reflexivity...
unsimpl (subst_qt Z P X)...
Case "sub_trans_tvar".
destruct (X == Z); subst.
SCase "X = Z".
exfalso. analyze_binds_uniq H.
SCase "X <> Z".
apply (sub_trans_tvar (subst_qt Z P U))...
rewrite (map_subst_qb_id E Z P);
[ | auto | eapply fresh_mid_tail; eauto ].
analyze_binds H...
Case "sub_arrow".
pick fresh x and apply sub_arrow...
rewrite subst_qqt_open_qqt_var...
rewrite subst_qqt_open_qqt_var...
rewrite_env (map (subst_qb Z P) (x ~ bind_typ T1 ++ G) ++ E).
eapply subqtype_through_subst_qqt...
Case "sub_all".
pick fresh X and apply sub_all...
rewrite subst_qqt_open_tqt_var...
rewrite subst_qqt_open_tqt_var...
rewrite_env (map (subst_qb Z P) (X ~ bind_sub T1 ++ G) ++ E).
eapply subqtype_through_subst_qqt...
Case "sub_qall".
pick fresh X and apply sub_qall...
rewrite subst_qqt_open_qqt_var...
rewrite subst_qqt_open_qqt_var...
rewrite_env (map (subst_qb Z P) (X ~ bind_qua T1 ++ G) ++ E).
eapply subqtype_through_subst_qqt...
------
clear subqtype_through_subst_qqt.
intros Q E F Z S T P SsubT PsubQ.
remember (F ++ Z ~ bind_qua Q ++ E) as G.
generalize dependent F.
induction SsubT; intros G EQ; subst; simpl subst_qt...
econstructor; eauto using subqual_through_subst_qq...
Qed.
Lemma sub_through_subst_qt_var : forall Q R E F Z S T P,
sub (F ++ Z ~ bind_typ (qtyp_qtyp Q R) ++ E) S T ->
subqual E P Q ->
sub (map (subst_qb Z P) F ++ E) (subst_qt Z P S) (subst_qt Z P T)
with subqtype_through_subst_qqt_var : forall Q R E F Z S T P,
subqtype (F ++ Z ~ bind_typ (qtyp_qtyp Q R) ++ E) S T ->
subqual E P Q ->
subqtype (map (subst_qb Z P) F ++ E) (subst_qqt Z P S) (subst_qqt Z P T).
Proof with
simpl_env;
eauto 4 using wf_typ_subst_qb_var, wf_env_subst_qb_var, wf_typ_weaken_head,
subqual_through_subst_qq_var.
------
clear sub_through_subst_qt_var.
intros Q R E F Z S T P SsubT PsubQ.
remember (F ++ Z ~ bind_typ (qtyp_qtyp Q R) ++ E) as G.
generalize dependent F.
induction SsubT; intros G EQ; subst; simpl subst_qt...
Case "sub_top".
apply sub_top...
Case "sub_refl_tvar".
apply sub_reflexivity...
unsimpl (subst_qt Z P X)...
Case "sub_trans_tvar".
destruct (X == Z); subst.
SCase "X = Z".
exfalso. analyze_binds_uniq H.
SCase "X <> Z".
apply (sub_trans_tvar (subst_qt Z P U))...
rewrite (map_subst_qb_id E Z P);
[ | auto | eapply fresh_mid_tail; eauto ].
analyze_binds H...
Case "sub_arrow".
pick fresh x and apply sub_arrow...
rewrite subst_qqt_open_qqt_var...
rewrite subst_qqt_open_qqt_var...
rewrite_env (map (subst_qb Z P) (x ~ bind_typ T1 ++ G) ++ E).
eapply subqtype_through_subst_qqt_var...
Case "sub_all".
pick fresh X and apply sub_all...
rewrite subst_qqt_open_tqt_var...
rewrite subst_qqt_open_tqt_var...
rewrite_env (map (subst_qb Z P) (X ~ bind_sub T1 ++ G) ++ E).
eapply subqtype_through_subst_qqt_var...
Case "sub_qall".
pick fresh X and apply sub_qall...
rewrite subst_qqt_open_qqt_var...
rewrite subst_qqt_open_qqt_var...
rewrite_env (map (subst_qb Z P) (X ~ bind_qua T1 ++ G) ++ E).
eapply subqtype_through_subst_qqt_var...
------
clear subqtype_through_subst_qqt_var.
intros Q R E F Z S T P SsubT PsubQ.
remember (F ++ Z ~ bind_typ (qtyp_qtyp Q R) ++ E) as G.
generalize dependent F.
induction SsubT; intros G EQ; subst; simpl subst_qt...
econstructor; eauto using subqual_through_subst_qq_var...
Qed.
(* ********************************************************************** *)
(** * #<a name="typing"></a># Properties of typing *)
(* ********************************************************************** *)
(** ** Weakening (5) *)
Lemma typing_weakening : forall E F G e T,
typing (G ++ E) e T ->
wf_env (G ++ F ++ E) ->
typing (G ++ F ++ E) e T.
Proof with simpl_env;
eauto using wf_typ_weakening,
wf_qtyp_weakening,
wf_qua_weakening,
wf_qtyp_from_wf_env_typ,
wf_typ_from_wf_env_sub,
wf_qua_from_wf_env_qua,
sub_weakening,
subqual_weakening,
subqtype_weakening.
intros E F G e T Typ.
remember (G ++ E) as H.
generalize dependent G.
induction Typ; intros G EQ Ok; subst...
Case "typing_abs".
pick fresh x and apply typing_abs...
lapply (H0 x); [intros K | auto].
rewrite <- app_assoc.
apply (H1 x)...
Case "typing_tabs".
pick fresh X and apply typing_tabs...
lapply (H0 X); [intros K | auto].
rewrite <- app_assoc.
apply (H1 X)...
Case "typing_qabs".
pick fresh X and apply typing_qabs...
lapply (H0 X); [intros K | auto].
rewrite <- app_assoc.
apply (H1 X)...
Case "typing_let".
pick fresh x and apply typing_let...
lapply (H0 x); [intros K | auto].
rewrite <- app_assoc.
eapply H1...
Case "typing_inl".
apply typing_inl...
Case "typing_inr".
apply typing_inr...
Case "typing_case".
pick fresh x and apply typing_case...
SCase "inl branch".
lapply (H0 x); [intros K | auto].
rewrite <- app_assoc.
apply H1...
eassert (M : wf_qtyp (G ++ F ++ E) (qtyp_qtyp _ (typ_sum (qtyp_qtyp Q1 S1) (qtyp_qtyp Q2 S2))))...
assert (J : wf_typ (G ++ F ++ E) (typ_sum (qtyp_qtyp Q1 S1) (qtyp_qtyp Q2 S2)))...
inversion J...
SCase "inr branch".
lapply (H2 x); [intros K | auto].
rewrite <- app_assoc.
apply H3...
Qed.
(* ********************************************************************** *)
(** ** Strengthening (6) *)
(************************************************************************ *)
(** ** Narrowing for typing (7) *)
Lemma typing_narrowing_sub : forall Q E F X P e T,
sub E P Q ->
typing (F ++ X ~ bind_sub Q ++ E) e T ->
typing (F ++ X ~ bind_sub P ++ E) e T.
Proof with eauto 6 using wf_env_narrowing_sub,
wf_typ_narrowing_sub, wf_qtyp_narrowing_sub, wf_qua_narrowing_sub,
sub_narrowing_sub, subqual_narrowing_sub, subqtype_narrowing_sub.
intros Q E F X P e T PsubQ Typ.
remember (F ++ X ~ bind_sub Q ++ E) as E'.
generalize dependent F.
induction Typ; intros F EQ; subst...