-
Notifications
You must be signed in to change notification settings - Fork 0
/
Infrastructure.v
2499 lines (1978 loc) · 54 KB
/
Infrastructure.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 Metalib.Metatheory.
Require Export LibTactics.
Require Export SystemF_inf.
Require Export Fii_inf.
Require Export TypeSystems.
Coercion ty_var_b : nat >-> ty.
Coercion ty_var_f : typvar >-> ty.
Coercion exp_var_b : nat >-> exp.
Coercion exp_var_f : expvar >-> exp.
Ltac gather_atoms ::=
let A := gather_atoms_with (fun x : vars => x) in
let B := gather_atoms_with (fun x : var => {{ x }}) in
let C1 := gather_atoms_with (fun x : ctx => dom x) in
let C2 := gather_atoms_with (fun x : tctx => dom x) in
let C3 := gather_atoms_with (fun x : stctx => dom x) in
let C4 := gather_atoms_with (fun x : sctx => dom x) in
let D1 := gather_atoms_with (fun x => fv_ty_in_ty x) in
let D2 := gather_atoms_with (fun x => fv_ty_in_exp x) in
let D3 := gather_atoms_with (fun x => fv_exp_in_exp x) in
let D4 := gather_atoms_with (fun x => fv_sty_in_sty x) in
let D5 := gather_atoms_with (fun x => fv_sty_in_sexp x) in
let D6 := gather_atoms_with (fun x => fv_sexp_in_sexp x) in
constr:(A \u B \u C1 \u C2 \u C3 \u C4 \u D1 \u D2 \u D3 \u D4 \u D5 \u D6).
(* ********************************************************************** *)
(** * Notations *)
Notation "'|' A '|'" := (sty2ty A) (at level 60).
Notation "'∥' Γ '∥'" := (map sty2ty Γ) (at level 60).
Lemma trans_open_sty_rec : forall A B n,
| open_sty_wrt_sty_rec n B A | = open_ty_wrt_ty_rec n (| B |) (| A |).
Proof with eauto.
intros A.
induction A; intros B m; simpls...
destruct (lt_eq_lt_dec n m)...
destruct s...
rewrite IHA2.
rewrite IHA1...
rewrite IHA2.
rewrite IHA1...
rewrite IHA2...
Qed.
Lemma trans_open_sty : forall A B,
| open_sty_wrt_sty B A | = open_ty_wrt_ty (| B |) (| A |).
Proof.
intros.
unfold open_sty_wrt_sty.
unfold open_ty_wrt_ty.
rewrite trans_open_sty_rec.
reflexivity.
Qed.
Lemma trans_subst_sty : forall B A X,
| subst_sty_in_sty A X B | = subst_ty_in_ty (| A |) X (| B |).
Proof with eauto.
intros B.
induction B; intros; simpls...
case_if...
rewrite IHB1...
rewrite IHB2...
rewrite IHB1...
rewrite IHB2...
rewrite IHB2...
Qed.
Lemma lc_sty_ty : forall A,
lc_sty A -> lc_ty (| A |).
Proof with eauto.
intros A H.
induction H; simpls...
pick fresh X.
apply (lc_ty_all_exists X).
unfold open_ty_wrt_ty.
simpls...
pick_fresh X.
apply (lc_ty_all_exists X).
asserts_rewrite (ty_var_f X = | sty_var_f X |)...
rewrite <- trans_open_sty...
Qed.
Lemma notin_sty_ty : forall X A,
X `notin` fv_sty_in_sty A -> X `notin` fv_ty_in_ty (| A |).
Proof with eauto.
intros.
induction A; simpls...
Qed.
(* ********************************************************************** *)
(** * Properties of monotype *)
Hint Constructors mono.
Lemma sty_mono_or_not : forall A,
lc_sty A ->
mono A \/ ~mono A.
Proof with eauto.
introv LC.
induction LC; try solve [left; constructor].
destruct IHLC1.
destruct IHLC2.
left; constructor...
right.
introv Bad.
inverts Bad.
tryfalse.
destruct IHLC2.
right.
introv Bad.
inverts Bad.
tryfalse.
right.
introv Bad.
inverts Bad.
tryfalse.
destruct IHLC1.
destruct IHLC2.
left; constructor...
right.
introv Bad.
inverts Bad.
tryfalse.
destruct IHLC2.
right.
introv Bad.
inverts Bad.
tryfalse.
right.
introv Bad.
inverts Bad.
tryfalse.
right.
introv Bad.
inverts Bad.
destruct IHLC.
left; constructor...
right.
introv Bad.
inverts Bad.
tryfalse.
Qed.
Lemma mono_lc : forall t,
mono t -> lc_sty t.
Proof with eauto.
induction 1...
Qed.
Lemma poly_lc : forall t,
poly t -> lc_sty t.
Proof with eauto using mono_lc.
induction 1...
Qed.
Lemma not_mono_arrow : forall A B,
lc_sty A ->
lc_sty B ->
~mono (sty_arrow A B) ->
~mono A \/ ~mono B.
Proof with eauto.
introv HA HB H.
apply sty_mono_or_not in HA.
apply sty_mono_or_not in HB.
destruct HA.
destruct HB.
false.
apply H...
right...
destruct HB.
left...
left...
Qed.
Lemma not_mono_and : forall A B,
lc_sty A ->
lc_sty B ->
~mono (sty_and A B) ->
~mono A \/ ~mono B.
Proof with eauto.
introv HA HB H.
apply sty_mono_or_not in HA.
apply sty_mono_or_not in HB.
destruct HA.
destruct HB.
false.
apply H...
right...
destruct HB.
left...
left...
Qed.
Lemma not_mono_is_poly : forall A,
lc_sty A -> ~mono A -> poly A.
Proof with eauto.
introv LC.
induction LC; introv Mono; try solve [false; apply Mono; eauto]...
- Case "arrow".
apply not_mono_arrow in Mono...
destruct Mono as [Mono1 | Mono2].
forwards HB : sty_mono_or_not B...
destruct HB as [HB1 | HB2].
apply IHLC1 in Mono1...
apply IHLC1 in Mono1...
forwards HA : sty_mono_or_not A...
destruct HA as [HA1 | HA2].
apply IHLC2 in Mono2...
apply IHLC1 in HA2...
- Case "and".
apply not_mono_and in Mono...
destruct Mono as [Mono1 | Mono2].
forwards HB : sty_mono_or_not B...
destruct HB as [HB1 | HB2].
apply IHLC1 in Mono1...
apply IHLC1 in Mono1...
forwards HA : sty_mono_or_not A...
destruct HA as [HA1 | HA2].
apply IHLC2 in Mono2...
apply IHLC1 in HA2...
- Case "record".
constructor...
Qed.
Lemma subst_mono: forall x t t',
mono t' ->
mono t ->
mono (subst_sty_in_sty t x t').
Proof with eauto.
introv Mono.
gen t x.
induction Mono; introv M; simpls; try constructor...
case_if...
Qed.
(* ********************************************************************** *)
(** * Properties of well-formedness of a type in an environment *)
Lemma fv_sty_dom : forall D A,
swft D A -> fv_sty_in_sty A [<=] dom D.
Proof.
introv H.
induction H; simpls; try fsetdec.
apply binds_In in H.
fsetdec.
pick fresh X.
assert (fv_sty_in_sty (open_sty_wrt_sty B (sty_var_f X)) [<=] add X (dom DD)) by eauto.
assert (fv_sty_in_sty B [<=] fv_sty_in_sty (open_sty_wrt_sty B (sty_var_f X))) by eapply fv_sty_in_sty_open_sty_wrt_sty_lower.
fsetdec.
Qed.
Lemma fv_sty_nil : forall A,
swft nil A ->
fv_sty_in_sty A [=] {}.
Proof.
introv H.
forwards~ : fv_sty_dom H.
fsetdec.
Qed.
Lemma uniq_from_swfe : forall D E,
swfe D E ->
uniq E.
Proof with eauto.
intros D E H; induction H...
Qed.
Lemma uniq_from_swfte : forall D,
swfte D ->
uniq D.
Proof with eauto.
intros D H; induction H...
Qed.
Lemma uniq_from_swfte_push : forall X A D,
swfte ([(X, A)] ++ D) ->
uniq D.
Proof with eauto.
introv WFTE; inversions WFTE. apply uniq_from_swfte...
Qed.
Lemma swft_type : forall E T,
swft E T -> lc_sty T.
Proof.
induction 1; eauto.
Qed.
Lemma swft_wft : forall Δ A,
swft Δ A -> wft (map (const tt) Δ) (| A |).
Proof with eauto.
introv H.
induction H; simpls...
pick fresh X and apply wft_all...
unfold open_ty_wrt_ty.
simpls...
constructor...
apply binds_map_2 with (f := const tt) (a := A)...
pick fresh X and apply wft_all...
asserts_rewrite (ty_var_f X = | sty_var_f X |)...
rewrite <- trans_open_sty...
apply (H1 X)...
Qed.
Lemma swft_wft_nil : forall A,
swft nil A -> wft nil (| A |).
Proof with eauto.
introv H.
apply swft_wft in H.
simpls...
Qed.
Lemma swfe_wfe : forall Δ Γ,
uniq Δ ->
swfe Δ Γ ->
wfe (map (const tt) Δ) (∥ Γ ∥).
Proof with eauto using swft_wft.
introv W H.
induction H; simpls...
constructor...
Qed.
Lemma swfe_notin : forall D G x A,
swfe D G ->
binds x A G ->
x `notin` dom D.
Proof with eauto.
induction 1; introv Bind; simpls...
analyze_binds Bind...
Qed.
Lemma wft_type : forall E T,
wft E T -> lc_ty T.
Proof.
induction 1; eauto.
Qed.
Lemma wft_weaken : forall T E F G,
wft (G ++ E) T ->
uniq (G ++ F ++ E) ->
wft (G ++ F ++ E) T.
Proof with simpl_env; eauto.
intros T E F G Hwf_typ Hk.
remember (G ++ E) as F'.
generalize dependent G.
induction Hwf_typ; intros G Hok Heq; subst...
Case "ty_all".
pick fresh Y and apply wft_all...
rewrite <- app_assoc.
apply H0...
Qed.
Lemma swft_weaken : forall T E F G,
swft (G ++ E) T ->
uniq (G ++ F ++ E) ->
swft (G ++ F ++ E) T.
Proof with simpl_env; eauto.
intros T E F G Hwf_typ Hk.
remember (G ++ E) as F'.
generalize dependent G.
induction Hwf_typ; intros G Hok Heq; subst...
Case "ty_all".
pick fresh Y and apply swft_all...
rewrite <- app_assoc.
apply H0...
Qed.
Lemma wft_weaken_head : forall T E F,
wft E T ->
uniq (F ++ E) ->
wft (F ++ E) T.
Proof.
intros.
rewrite_env (nil ++ F++ E).
auto using wft_weaken.
Qed.
Lemma swft_weaken_head : forall T E F,
swft E T ->
uniq (F ++ E) ->
swft (F ++ E) T.
Proof.
intros.
rewrite_env (nil ++ F++ E).
auto using swft_weaken.
Qed.
Lemma swft_from_swfte : forall Y A D,
swfte D ->
binds Y A D ->
swft D A.
Proof with eauto using uniq_from_swfte.
induction 1; intros J; analyze_binds J...
eapply swft_weaken_head...
apply IHswfte in BindsTac.
eapply swft_weaken_head...
Qed.
Lemma wft_subst_tb : forall F E Z P T,
wft (F ++ Z ~ tt ++ E) T ->
wft E P ->
uniq (F ++ E) ->
wft (F ++ E) (subst_ty_in_ty P Z T).
Proof with simpl_env; eauto using wft_weaken_head, wft_type.
intros F E Z P T WT WP.
remember (F ++ Z ~ tt ++ E) as G.
generalize dependent F.
induction WT; intros F EQ Ok; subst; simpl subst_ty_in_ty...
- Case "ty_var".
case_if...
- Case "ty_all".
pick fresh Y and apply wft_all...
rewrite subst_ty_in_ty_open_ty_wrt_ty_var...
rewrite_env (([(Y, tt)] ++ F) ++ E).
apply H0...
Qed.
Lemma swft_subst_tb : forall F E Z P T B,
swft (F ++ Z ~ B ++ E) T ->
swft E P ->
uniq (map (subst_sty_in_sty P Z) F ++ E) ->
swft (map (subst_sty_in_sty P Z) F ++ E) (subst_sty_in_sty P Z T).
Proof with simpl_env; eauto using swft_weaken_head, swft_type.
intros F E Z P T B WT WP.
remember (F ++ Z ~ B ++ E) as G.
generalize dependent F.
induction WT; intros F EQ Ok; subst; simpl subst_sty_in_sty...
- Case "swft_var".
case_if...
analyze_binds H...
- Case "swft_all".
pick fresh Y and apply swft_all...
rewrite subst_sty_in_sty_open_sty_wrt_sty_var...
rewrite_env (map (subst_sty_in_sty P Z) (Y ~ A ++ F) ++ E).
apply H0...
Qed.
Lemma swft_subst_sty : forall E Z P T B,
swft ([(Z, B)] ++ E) T ->
swft E P ->
uniq E ->
swft E (subst_sty_in_sty P Z T).
Proof.
introv HY WTF UNI.
rewrite_env (nil ++ Z ~ B ++ E) in HY.
forwards I : swft_subst_tb HY WTF UNI.
simpl_alist in I; auto.
Qed.
Lemma wft_open : forall E U T2,
uniq E ->
wft E (ty_all T2) ->
wft E U ->
wft E (open_ty_wrt_ty T2 U).
Proof with simpl_env; eauto.
intros E U T2 Ok WA WU.
inversion WA; subst.
pick fresh X.
rewrite (subst_ty_in_ty_intro X)...
rewrite_env (nil ++ E).
eapply wft_subst_tb...
Qed.
Lemma swft_open : forall E U T1 T2,
uniq E ->
swft E (sty_all T1 T2) ->
swft E U ->
swft E (open_sty_wrt_sty T2 U).
Proof with simpl_env; eauto.
intros E U T1 T2 Ok WA WU.
inversion WA; subst.
pick fresh X.
rewrite (subst_sty_in_sty_intro X)...
rewrite_env (map (subst_sty_in_sty U X) nil ++ E).
eapply swft_subst_tb...
Qed.
(* *********************************************************************************** *)
(** * Relations between well-formed environment and well-formed types in environments *)
Lemma swft_tvar : forall D X A,
swft D A ->
X `notin` dom D ->
X `notin` fv_sty_in_sty A.
Proof with eauto.
introv H.
gen X.
induction H; introv W; simpls...
lets : binds_In H.
fsetdec.
pick_fresh Y.
forwards~ : H1 Y X.
lets : IHswft W.
lets : fv_sty_in_sty_open_sty_wrt_sty_lower B (sty_var_f Y).
fsetdec.
Qed.
Lemma swfte_tvar : forall X A D,
swfte D ->
binds X A D ->
X `notin` fv_sty_in_sty A.
Proof with eauto.
introv H.
gen X A.
induction H; introv B.
analyze_binds B.
analyze_binds B.
eapply swft_tvar...
Qed.
Inductive same_stctx {a b} : list (atom * a) -> list (atom * b) -> Prop :=
| same_empty : same_stctx nil nil
| same_cons : forall X A B s1 s2,
same_stctx s1 s2 -> same_stctx ([(X , A)] ++ s1) ([(X , B)] ++ s2).
Hint Constructors same_stctx.
Lemma same_stctx_dom : forall a b (ctxa : list (atom * a)) (ctxb : list (atom * b)),
same_stctx ctxa ctxb ->
dom ctxa [=] dom ctxb.
Proof with eauto; try fsetdec.
induction 1; simpls...
Qed.
Lemma same_eq : forall a (s1 : list (atom * a)),
same_stctx s1 s1.
Proof with eauto.
alist induction s1...
Qed.
Lemma same_map : forall a b (s1 : list (atom * a)) (f : a -> b),
same_stctx s1 (map f s1).
Proof with eauto; simpl_env.
alist induction s1...
intros.
simpls...
intros.
simpls...
constructor...
Qed.
Lemma same_sym : forall a b (s1 : list (atom * a)) (s2 : list (atom * b)),
same_stctx s1 s2 -> same_stctx s2 s1.
Proof with eauto.
introv H.
induction H...
Qed.
Lemma same_var : forall a b (s1 : list (atom * a)) (s2 : list (atom * b)) X A,
same_stctx s1 s2 ->
binds X A s1 ->
exists B, binds X B s2.
Proof with eauto.
introv Eq.
gen X A.
induction Eq; introv H.
analyze_binds H.
analyze_binds H...
lets (B0 & ?) : IHEq BindsTac.
exists B0...
Qed.
Lemma swft_change : forall Δ Δ' A,
swft Δ A ->
same_stctx Δ Δ' ->
swft Δ' A.
Proof with eauto.
introv H.
gen Δ'.
induction H; introv Eq...
lets (B & ?): same_var Eq H...
Qed.
(* ******************************************************************************* *)
(** *Properties of [wfe] *)
Lemma uniq_from_wfe : forall D E,
wfe D E ->
uniq E /\ uniq D.
Proof with eauto.
intros D E H; induction H...
invert IHwfe...
Qed.
Lemma wft_from_wfe : forall x U E D,
wfe D E ->
binds x U E ->
wft D U.
Proof.
induction 1; intros J; analyze_binds J.
Qed.
Lemma swft_from_swfe : forall x U E D,
swfe D E ->
binds x U E ->
swft D U.
Proof.
induction 1; intros J; analyze_binds J.
Qed.
Lemma wfe_weaken : forall T E G X,
wfe (G ++ E) T ->
uniq (G ++ [(X, tt)] ++ E) ->
X `notin` dom T ->
wfe (G ++ [(X, tt)] ++ E) T.
Proof with simpl_env; eauto.
introv Hwf_typ Hk Notin.
remember (G ++ E) as F'.
generalize dependent G.
induction Hwf_typ; intros G Hok Heq; subst...
constructor...
apply wft_weaken...
Qed.
Lemma wfe_subst_tb : forall Z P E F D,
wfe (F ++ Z ~ tt ++ E) D ->
wft E P ->
uniq (F ++ E) ->
wfe (F ++ E) (map (subst_ty_in_ty P Z) D).
Proof with eauto using wft_subst_tb.
introv WFE WFT.
remember (F ++ Z ~ tt ++ E) as G.
generalize dependent F.
induction WFE; introv EQ Uniq; subst; simpl...
constructor...
Qed.
Lemma notin_fv_typ_in_typ_open : forall (Y X : typvar) T,
X `notin` fv_ty_in_ty (open_ty_wrt_ty T Y) ->
X `notin` fv_ty_in_ty T.
Proof.
intros Y X T. unfold open_ty_wrt_ty.
generalize 0.
induction T; simpl; intros k Fr; eauto.
Qed.
Lemma notin_fv_wf : forall E (X : typvar) T,
wft E T ->
X `notin` dom E ->
X `notin` fv_ty_in_ty T.
Proof with auto.
intros E X T Wf_typ.
induction Wf_typ; intros Fr; simpl...
Case "wf_typ_var".
assert (X0 `in` (dom dd))...
eapply binds_In; eauto. fsetdec.
Case "wft_all".
pick fresh Y.
apply (notin_fv_typ_in_typ_open Y)...
Qed.
Lemma map_subst_typ_in_binding_id : forall G Z P D,
wfe D G ->
Z `notin` dom D ->
G = map (subst_ty_in_ty P Z) G.
Proof with eauto.
introv H.
induction H; simpl; intros Fr; simpl_env...
rewrite <- IHwfe...
rewrite subst_ty_in_ty_fresh_eq...
eapply notin_fv_wf...
Qed.
Lemma wfe_strengthen : forall E F x U T,
wfe T (F ++ x ~ U ++ E) ->
wfe T (F ++ E).
Proof with eauto.
induction F;
introv Wfe; inversion Wfe; subst; simpl_env in *...
Qed.
(* ******************************************************************************* *)
(** *Regularity of relations *)
Lemma sub_regular : forall Δ A B c,
sub Δ A B c ->
swft Δ A /\ swft Δ B.
Proof with eauto using same_eq, same_sym.
introv Sub.
induction* Sub.
(* Case 1 *)
destruct IHSub.
splits.
pick fresh Y and apply swft_all...
forwards (? & ?) : H0...
apply swft_change with (Δ := ([(Y , A2)] ++ DD))...
pick fresh Y and apply swft_all...
forwards (? & ?) : H0...
(* Case 2 *)
splits...
pick fresh Y and apply swft_all...
unfold open_sty_wrt_sty.
simpls...
Unshelve.
exact (dom DD).
Qed.
Lemma disjoint_regular : forall Δ A B,
disjoint Δ A B ->
swft Δ A /\ swft Δ B.
Proof with eauto using same_eq.
introv Dis.
induction* Dis.
splits...
eapply sub_regular...
splits...
eapply sub_regular...
splits...
pick fresh X and apply swft_all...
apply swft_change with (Δ := ([(X , sty_and A1 A2)] ++ DD))...
eapply H0...
pick fresh X and apply swft_all...
apply swft_change with (Δ := ([(X , sty_and A1 A2)] ++ DD))...
eapply H0...
Qed.
Lemma styping_regular : forall D G E dir e A,
has_type D G E dir A e ->
lc_sexp E /\ swfe D G /\ swft D A /\ swfte D.
Proof with simpl_env; try solve [auto | intuition auto].
introv H.
induction H...
- Case "var".
splits...
eauto using swft_from_swfe.
- Case "app".
splits...
destruct IHhas_type1 as (_ & _ & K & _).
inverts K...
- Case "anno".
splits...
destructs IHhas_type...
lets : swft_type H2.
constructor~.
- Case "tabs".
pick_fresh Y.
destructs (H1 Y)...
inverts H6.
splits...
+ SCase "lc_sexp".
apply (lc_sexp_tabs_exists Y).
destructs (H1 Y)...
eauto using swft_type.
eauto using swft_type.
+ SCase "wft".
pick fresh Z and apply swft_all...
destructs (H1 Z)...
- Case "tapp".
splits...
+ SCase "lc_exp".
forwards (? & ?) : disjoint_regular H1.
apply lc_sexp_tapp...
eauto using swft_type.
+ SCase "wft".
forwards (? & ?) : disjoint_regular H1.
destructs IHhas_type.
eapply swft_open; eauto.
apply uniq_from_swfte...
- Case "proj".
destructs IHhas_type.
inverts H2.
splits...
- Case "abs".
pick_fresh y.
destructs (H1 y)...
inverts H3.
splits...
+ SCase "lc_exp".
apply (lc_sexp_abs_exists y).
destructs (H1 y)...
Qed.
Lemma typing_regular : forall D E e T,
typ D E e T ->
lc_exp e /\ wfe D E /\ wft D T.
Proof with simpl_env; try solve [auto | intuition auto].
introv H; induction H...
- Case "typ_var".
splits...
eauto using wft_from_wfe.
- Case "typ_abs".
pick_fresh y.
destructs (H0 y)...
inverts H3.
splits...
+ SCase "lc_exp".
apply (lc_exp_abs_exists y).
destructs (H0 y)...
- Case "typ_app".
splits...
destruct IHtyp1 as (_ & _ & K).
inverts K...
- Case "typ_tabs".
pick_fresh Y.
destructs (H0 Y)...
splits...
+ SCase "lc_exp".
apply (lc_exp_tabs_exists Y).
destructs (H0 Y)...
+ SCase "wft".
pick fresh Z and apply wft_all...
destructs (H0 Z)...
- Case "tapp".
splits...
+ SCase "lc_exp".
apply lc_exp_tapp...
eauto using wft_type.
+ SCase "wft".
destructs IHtyp.
eapply wft_open; eauto.
lets* : uniq_from_wfe H2.
Qed.
Lemma value_regular : forall v,
value v ->
lc_exp v.
Proof.
intros v H.
induction H; auto.
Qed.
Lemma step_regular : forall e e',
step e e' ->
lc_exp e /\ lc_exp e'.
Proof with eauto using value_regular, lc_body_exp_wrt_ty, lc_body_exp_wrt_exp, lc_body_exp_abs_1, lc_body_exp_tabs_1.
intros e e' H.
induction H; intuition eauto 6; try constructor...
Qed.
Lemma ctyp_wft : forall G c T1 T2,
ctyp G c T1 T2 ->
wft G T1 /\ wft G T2.
Proof with eauto.
introv Ctyp.
induction* Ctyp.
splits...
pick fresh X and apply wft_all.
unfold open_ty_wrt_ty.
simpls...
(* Case 1 *)
splits...
pick fresh X and apply wft_all.
forwards (? & ?): H0 X...
pick fresh X and apply wft_all.
forwards (? & ?): H0 X...
(* Case 2 *)
inverts H.
inverts H0.
splits; eauto.
pick fresh X and apply wft_all; auto.
unfold open_ty_wrt_ty.
simpls; eauto.
Unshelve.
exact (dom dd).
Qed.
(* Automations to the resue *)
Hint Extern 1 (wfe ?D ?E) =>
match goal with
| H: typ D E _ _ |- _ => apply (proj1 (proj2 (typing_regular _ _ _ _ H)))
end.
Hint Extern 1 (wft ?E ?T) =>
match goal with
| H: typ E _ _ T |- _ => apply (proj2 (proj2 (typing_regular _ _ _ _ H)))
| H: ctyp E _ T _ |- _ => apply (proj1 (ctyp_wft _ _ _ _ H))
| H: ctyp E _ _ T |- _ => apply (proj2 (ctyp_wft _ _ _ _ H))
end.