-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFm_NormalForms.v
1268 lines (1114 loc) · 45.3 KB
/
Fm_NormalForms.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
(** Additional administrative lemmas concering normal forms for Fsub.
Authors: Edward Lee, Ondrej Lhotak
Authors: Brian Aydemir and Arthur Chargu\'eraud, with help from
Aaron Bohannon, Jeffrey Vaughan, and Dimitrios Vytiniotis.
This file contains a number of administrative lemmas that we
require for proving type-safety. These lemmas mainly concern
the predicates [in_normal_form] as well as the normalization functions
[merge_mutability] and [normal_form_typing]. These lemmas
are necessary for relating syntactically inequivalent but semantically
equivalent types: types like:
readonly (readonly X) and (readonly X)
Table of contents:
- #<a href="##normal_forms">Lemmas concering normal forms</a>#
- #<a href="##lemma_4.2">Lemma 4.2 (normalizing is idempotent) </a>#
*)
Require Export Fsub.Fm_Lemmas.
(* ********************************************************************** *)
(** * #<a name="normal_forms"></a># Lemmas concerning normal forms *)
Lemma merge_mutability_type : forall T,
type T ->
type (merge_mutability T mut_readonly).
Proof with simpl in *; auto; repeat fold merge_mutability in *.
intros * Typ.
dependent induction Typ...
+ apply type_all with (L := L)...
Qed.
#[export] Hint Resolve merge_mutability_type : core.
Lemma normal_form_type : forall T,
type T ->
type (normal_form_typing T).
Proof with simpl in *; auto; repeat fold merge_mutability in *; repeat fold normal_form_typing in *.
intros * Typ.
dependent induction Typ...
+ apply type_all with (L := L)... intros. rewrite <- normal_form_open_tt...
Qed.
#[export] Hint Resolve normal_form_type : core.
Lemma normal_forms_merge : forall T m,
in_normal_form T ->
in_normal_form (merge_mutability T m).
Proof with eauto; try fold merge_mutability in *; simpl.
intros.
destruct m...
dependent induction H; try unfold merge_mutability in *...
econstructor...
econstructor...
econstructor...
Qed.
#[export] Hint Resolve normal_forms_merge : core.
Lemma normal_forms : forall T,
type T ->
in_normal_form (normal_form_typing T).
Proof with eauto;
try fold normal_form_typing in *;
try fold merge_mutability in *; try congruence;
simpl in *.
intros.
dependent induction H; try unfold normal_form_typing in *;
try unfold merge_mutability in *; subst...
pick fresh Y and apply all_in_normal_form...
rewrite <- normal_form_open_tt...
Qed.
#[export] Hint Resolve normal_forms : core.
Lemma normal_form_multiple_mut : forall T,
normal_form_typing (typ_mut mut_readonly (typ_mut mut_readonly T)) =
normal_form_typing (typ_mut mut_readonly T).
Proof with eauto; try repeat fold merge_mutability; try repeat fold normal_form_typing.
intros; simpl...
induction T; subst...
- unfold normal_form_typing...
destruct m...
rewrite IHT...
- unfold normal_form_typing...
unfold merge_mutability...
rewrite IHT1...
rewrite IHT2...
Qed.
#[export] Hint Rewrite normal_form_multiple_mut : core.
Lemma normal_form_unique : forall T,
type T ->
in_normal_form T ->
T = (normal_form_typing T).
Proof with eauto;
try repeat fold merge_mutability; try repeat fold normal_form_typing.
intros * Typ Norm.
dependent induction Norm; inversion Typ; subst; simpl; try solve [eauto; f_equal; eauto]...
- f_equal...
apply open_tt_normal_equal_rec with (L := (L `union` L0)) (k := 0)...
- f_equal...
inversion H0; subst...
f_equal...
- f_equal...
inversion H0; subst...
f_equal...
Qed.
Lemma atom_in_intersection_normal: forall (X : atom) T,
in_intersection X T ->
in_intersection X (normal_form_typing T) \/
in_intersection (typ_mut mut_readonly X) (normal_form_typing T).
Proof with eauto; simpl.
intros * Int.
dependent induction Int; subst...
- destruct (IHInt X)...
- destruct (IHInt X)...
Qed.
Lemma atom_in_intersection_readonly_normal : forall (X : atom) T,
in_intersection X T ->
in_intersection X (normal_form_typing (typ_mut mut_readonly T))
\/
in_intersection (typ_mut mut_readonly X) (normal_form_typing (typ_mut mut_readonly T)).
Proof with eauto; simpl.
intros * Int.
dependent induction Int; subst...
- destruct (IHInt X)...
- destruct (IHInt X)...
Qed.
Lemma atom_equal_normal_form : forall (X : atom) T,
typ_fvar X = normal_form_typing T ->
typ_fvar X = T.
Proof with eauto; simpl.
intros.
destruct T; subst; simpl in *; try discriminate...
fold merge_mutability in *.
fold normal_form_typing in *.
destruct (normal_form_typing T); simpl in *; try discriminate; subst...
Qed.
#[export] Hint Resolve atom_equal_normal_form : core.
#[export] Hint Resolve
atom_in_intersection_normal atom_in_intersection_readonly_normal : core.
Lemma multiple_merge_mutability_in_normal_form : forall T,
in_normal_form T ->
merge_mutability (merge_mutability T mut_readonly) mut_readonly =
merge_mutability T mut_readonly.
Proof with eauto.
intros.
dependent induction H; simpl;
fold merge_mutability...
f_equal...
Qed.
Lemma multiple_merge_mutability_normalized : forall T,
type T ->
merge_mutability (merge_mutability (normal_form_typing T) mut_readonly) mut_readonly
= merge_mutability (normal_form_typing T) mut_readonly.
Proof with eauto using multiple_merge_mutability_in_normal_form.
intros...
Qed.
#[export] Hint Resolve multiple_merge_mutability_in_normal_form
multiple_merge_mutability_normalized : core.
#[export] Hint Rewrite multiple_merge_mutability_in_normal_form
multiple_merge_mutability_normalized : core.
Lemma merge_mutability_multiple : forall T m,
(merge_mutability (merge_mutability T m) m) = merge_mutability T m.
Proof with simpl in *; eauto;
try repeat fold merge_mutability in *; try repeat fold normal_form_typing in *.
intros *...
induction T...
f_equal...
Qed.
#[export] Hint Rewrite merge_mutability_multiple : core.
Lemma normal_form_merge_mutability_exchange : forall T m,
(normal_form_typing (merge_mutability T m)) =
(merge_mutability (normal_form_typing T) m).
Proof with simpl in *; eauto;
try repeat fold merge_mutability in *; try repeat fold normal_form_typing in *.
intros *...
induction T...
+ destruct m; destruct m0; autorewrite with core...
+ f_equal...
Qed.
(** #<a name="lemma_4.2"></a># Lemma 4.2: Normalizing is idempotent. *)
Lemma normal_form_in_normal_form : forall T,
(normal_form_typing (normal_form_typing T)) = (normal_form_typing T).
Proof with simpl in *; eauto;
try repeat fold merge_mutability in *; try repeat fold normal_form_typing in *.
intros T.
induction T; try solve [simpl in *; f_equal; eauto]...
+ rewrite normal_form_merge_mutability_exchange...
rewrite IHT...
Qed.
#[export] Hint Rewrite normal_form_in_normal_form : core.
Lemma readonly_atom_in_normal_to_normal : forall (X : atom) T,
in_intersection (typ_mut mut_readonly X)
(normal_form_typing T) ->
type T ->
in_intersection (typ_mut mut_readonly X)
(normal_form_typing (typ_mut mut_readonly T)).
Proof with eauto; simpl in *;
repeat (fold merge_mutability in *; fold normal_form_typing in *).
intros * Int Typ...
dependent induction T; subst;
try solve [ inversion Int; try discriminate ]...
- destruct m...
rewrite multiple_merge_mutability_normalized...
- inversion Typ; subst...
inversion Int; subst... discriminate.
Qed.
#[export] Hint Resolve readonly_atom_in_normal_to_normal : core.
Lemma readonly_atom_in_normal_readonly_to_normal : forall (X : atom) T,
in_intersection (typ_mut mut_readonly X)
(normal_form_typing (typ_mut mut_readonly T)) ->
type T ->
in_intersection (typ_mut mut_readonly X) (normal_form_typing T)
\/
in_intersection X (normal_form_typing T).
Proof with eauto; simpl in *;
repeat (fold merge_mutability in *; fold normal_form_typing in *);
try discriminate.
intros * Int Typ.
dependent induction T;
try solve [ inversion Int; try discriminate ]...
- inversion Int; subst...
inversion H...
- destruct m; rewrite multiple_merge_mutability_normalized in Int...
- inversion Int; subst...
destruct IHT1...
destruct IHT2...
Qed.
#[export] Hint Resolve readonly_atom_in_normal_readonly_to_normal : core.
Lemma intersection_of_normal_is_normal : forall S T,
in_intersection S T ->
in_normal_form T ->
in_normal_form S.
Proof with eauto.
intros * Int Normal.
induction Int; subst;
try solve [inversion Normal; eauto]...
Qed.
Lemma readonly_arrow_is_not_normal : forall T1 T2 T,
in_normal_form T ->
~ in_intersection (typ_mut mut_readonly (typ_arrow T1 T2)) T.
Proof with eauto; try discriminate.
intros.
induction H; intro Int; inversion Int; subst...
Qed.
Lemma readonly_all_is_not_normal : forall T1 T2 T,
in_normal_form T ->
~ in_intersection (typ_mut mut_readonly (typ_all T1 T2)) T.
Proof with eauto; try discriminate.
intros.
induction H; intro Int; inversion Int; subst...
Qed.
#[export] Hint Resolve readonly_arrow_is_not_normal readonly_all_is_not_normal : core.
Lemma in_intersection_arrow_normal_in_merge : forall T1 T2 T,
in_intersection (typ_arrow T1 T2) T ->
in_normal_form T ->
in_intersection (typ_arrow T1 T2)
(merge_mutability T mut_readonly).
Proof with eauto; try repeat fold merge_mutability in *; try discriminate.
intros * Int Norm.
dependent induction Norm; try solve [inversion Int; subst; eauto; discriminate].
- simpl; inversion Int; subst...
Qed.
Lemma in_intersection_arrow_merge_in_normal : forall T1 T2 T,
in_intersection (typ_arrow T1 T2) (merge_mutability T mut_readonly) ->
in_normal_form T ->
in_intersection (typ_arrow T1 T2) T.
Proof with eauto; try repeat fold merge_mutability in *;
try discriminate.
intros * Int Norm.
dependent induction Norm; try solve [inversion Int; eauto; discriminate].
Qed.
#[export] Hint Resolve in_intersection_arrow_normal_in_merge : core.
#[export] Hint Resolve in_intersection_arrow_merge_in_normal : core.
Lemma in_intersection_readonly_arrow_normal_in_merge : forall T1 T2 T,
in_intersection (typ_mut mut_readonly (typ_arrow T1 T2)) T ->
in_normal_form T ->
in_intersection (typ_mut mut_readonly (typ_arrow T1 T2))
(merge_mutability T mut_readonly).
Proof with eauto; try repeat fold merge_mutability in *;
try discriminate.
intros * Int Norm.
dependent induction Norm; try solve [inversion Int; eauto; discriminate].
- simpl; inversion Int...
Qed.
Lemma in_intersection_readonly_arrow_merge_in_normal : forall T1 T2 T,
in_intersection (typ_mut mut_readonly (typ_arrow T1 T2))
(merge_mutability T mut_readonly) ->
in_normal_form T ->
in_intersection (typ_arrow T1 T2) T.
Proof with eauto; try repeat fold merge_mutability in *;
try discriminate.
intros * Int Norm.
dependent induction Norm; try solve [inversion Int; eauto; discriminate].
Qed.
#[export] Hint Resolve in_intersection_readonly_arrow_merge_in_normal : core.
#[export] Hint Resolve in_intersection_readonly_arrow_normal_in_merge : core.
Lemma arrow_argument_in_normal_form : forall T1 T2,
in_normal_form (typ_arrow T1 T2) ->
in_normal_form T1.
Proof with eauto.
intros * Norm.
inversion Norm...
Qed.
Lemma arrow_return_in_normal_form : forall T1 T2 ,
in_normal_form (typ_arrow T1 T2) ->
in_normal_form T2.
Proof with eauto.
intros * Norm.
inversion Norm...
Qed.
Lemma mut_arrow_in_normal_form : forall T1 T2,
in_normal_form (typ_mut mut_readonly (typ_arrow T1 T2)) ->
in_normal_form (typ_arrow T1 T2).
Proof with eauto.
intros * Norm.
inversion Norm...
Qed.
#[export] Hint Immediate arrow_argument_in_normal_form arrow_return_in_normal_form
mut_arrow_in_normal_form : core.
Lemma in_intersection_all_normal_in_merge : forall T1 T2 T,
in_intersection (typ_all T1 T2) T ->
in_normal_form T ->
in_intersection (typ_all T1 T2)
(merge_mutability T mut_readonly).
Proof with eauto; try repeat fold merge_mutability in *; try discriminate.
intros * Int Norm.
dependent induction Norm; try solve
[inversion Int; simpl in *; eauto; discriminate]...
Qed.
Lemma in_intersection_all_merge_in_normal : forall T1 T2 T,
in_intersection (typ_all T1 T2) (merge_mutability T mut_readonly) ->
in_normal_form T ->
in_intersection (typ_all T1 T2) T.
Proof with eauto; try repeat fold merge_mutability in *;
try discriminate.
intros * Int Norm.
dependent induction Norm;
try solve [inversion Int; eauto; discriminate].
Qed.
#[export] Hint Resolve in_intersection_all_normal_in_merge : core.
#[export] Hint Resolve in_intersection_all_merge_in_normal : core.
Lemma in_intersection_readonly_all_normal_in_merge : forall T1 T2 T,
in_intersection (typ_mut mut_readonly (typ_all T1 T2)) T ->
in_normal_form T ->
in_intersection (typ_mut mut_readonly (typ_all T1 T2))
(merge_mutability T mut_readonly).
Proof with eauto; try repeat fold merge_mutability in *;
try discriminate.
intros * Int Norm.
dependent induction Norm; try solve [inversion Int; eauto; discriminate].
- simpl; inversion Int...
Qed.
Lemma in_intersection_readonly_all_merge_in_normal : forall T1 T2 T,
in_intersection (typ_mut mut_readonly (typ_all T1 T2))
(merge_mutability T mut_readonly) ->
in_normal_form T ->
in_intersection (typ_all T1 T2) T.
Proof with eauto; try repeat fold merge_mutability in *;
try discriminate.
intros * Int Norm.
dependent induction Norm; try solve [inversion Int; eauto; discriminate].
Qed.
#[export] Hint Resolve in_intersection_readonly_all_normal_in_merge : core.
#[export] Hint Resolve in_intersection_readonly_all_merge_in_normal : core.
(** Additional lemmas about wellformedness and normal forms
TODO: check how these proofs actually work. *)
Lemma wf_typ_merge_mutability : forall E T,
wf_typ E T ->
wf_typ E (merge_mutability T mut_readonly).
Proof with eauto.
intros * WfT.
dependent induction WfT...
Qed.
Lemma wf_typ_normal_form : forall E T,
wf_typ E T ->
wf_typ E (normal_form_typing T).
Proof with eauto.
intros * WfT.
dependent induction WfT...
Qed.
#[export] Hint Resolve wf_typ_normal_form wf_typ_merge_mutability : core.
Lemma wf_typ_all_arg_from_all : forall E T1 T2,
wf_typ E (typ_all T1 T2) ->
wf_typ E T1.
Proof with eauto.
intros * WfT.
inversion WfT...
Qed.
Lemma wf_typ_from_in_intersection : forall E S T,
in_intersection S T ->
wf_typ E T ->
wf_typ E S.
Proof with eauto.
intros * WfT IntST.
dependent induction IntST...
Qed.
#[export] Hint Resolve wf_typ_all_arg_from_all
wf_typ_from_in_intersection : core.
Lemma box_in_intersection_merge_inversion : forall S T,
~ in_intersection (typ_box S) (merge_mutability T mut_readonly).
Proof with simpl in *; eauto; repeat fold merge_mutability in *.
intros * Int.
induction T; inversion Int; try discriminate...
Qed.
#[export] Hint Resolve box_in_intersection_merge_inversion : core.
Lemma in_intersection_box_normal_in_merge : forall T1 T,
in_intersection (typ_box T1) T ->
in_normal_form T ->
in_intersection (typ_mut mut_readonly (typ_box T1))
(merge_mutability T mut_readonly).
Proof with simpl in *; eauto; try repeat fold merge_mutability in *; try discriminate.
intros * Int Norm.
dependent induction Norm;
try solve [simpl in *; inversion Int; subst; try discriminate]...
- inversion Int; subst...
inversion H...
- inversion Int; subst...
Qed.
Lemma in_intersection_box_merge_in_normal : forall T1 T,
in_intersection (typ_box T1) (merge_mutability T mut_readonly) ->
in_normal_form T ->
in_intersection (typ_box T1) T.
Proof with eauto; try repeat fold merge_mutability in *;
try discriminate.
intros * Int Norm.
dependent induction Norm; try solve [inversion Int; eauto; discriminate]...
Qed.
#[export] Hint Resolve in_intersection_box_normal_in_merge : core.
#[export] Hint Resolve in_intersection_box_merge_in_normal : core.
Lemma in_intersection_readonly_box_normal_in_merge : forall T1 T,
in_intersection (typ_mut mut_readonly (typ_box T1)) T ->
in_normal_form T ->
in_intersection (typ_mut mut_readonly (typ_box T1))
(merge_mutability T mut_readonly).
Proof with eauto; try repeat fold merge_mutability in *;
try discriminate.
intros * Int Norm.
dependent induction Norm; try solve [inversion Int; eauto; discriminate]...
- simpl; inversion Int...
Qed.
Lemma in_intersection_readonly_box_merge_in_normal : forall T1 T,
in_intersection (typ_mut mut_readonly (typ_box T1))
(merge_mutability T mut_readonly) ->
in_normal_form T ->
in_intersection (typ_box T1) T \/
in_intersection (typ_mut mut_readonly (typ_box T1)) T.
Proof with simpl in *; eauto; try repeat fold merge_mutability in *;
try discriminate.
intros * Int Norm.
dependent induction Norm; try solve [inversion Int; eauto; discriminate]...
- inversion Int; subst...
inversion H...
- simpl in *; inversion Int; subst...
+ destruct (IHNorm1 H1)...
+ destruct (IHNorm2 H1)...
Qed.
#[export] Hint Resolve in_intersection_readonly_box_normal_in_merge : core.
#[export] Hint Resolve in_intersection_readonly_box_merge_in_normal : core.
Lemma in_intersection_atom_normal_in_merge : forall (X : atom) T,
in_intersection X T ->
in_normal_form T ->
in_intersection (typ_mut mut_readonly X) (merge_mutability T mut_readonly).
Proof with simpl in *; eauto; repeat fold merge_mutability.
intros * Int Norm.
induction Norm; inversion Int; subst; try discriminate...
rewrite H...
Qed.
Lemma in_intersection_readonly_atom_normal_in_merge : forall (X :atom) T,
in_intersection (typ_mut mut_readonly X) T ->
in_normal_form T ->
in_intersection (typ_mut mut_readonly X) (merge_mutability T mut_readonly).
Proof with simpl in *; eauto; repeat fold merge_mutability.
intros * Int Norm.
induction Norm; inversion Int; subst; try discriminate...
Qed.
#[export] Hint Resolve in_intersection_atom_normal_in_merge
in_intersection_readonly_atom_normal_in_merge : core.
Lemma atom_in_intersection_merge_inversion : forall (X : atom) T,
~ in_intersection X (merge_mutability T mut_readonly).
Proof with simpl in *; eauto; repeat fold merge_mutability in *.
intros * Int.
induction T; inversion Int; try discriminate...
Qed.
#[export] Hint Resolve atom_in_intersection_merge_inversion : core.
Lemma merge_mutability_inversion_top : forall T,
merge_mutability T mut_readonly = typ_top ->
T = typ_top.
Proof with simpl in *; eauto; try discriminate; repeat fold merge_mutability in *.
intros * Merge.
induction T...
Qed.
#[export] Hint Resolve merge_mutability_inversion_top : core.
Lemma merge_mutability_inversion_arrow : forall T,
(exists T1 T2, merge_mutability T mut_readonly = typ_arrow T1 T2) ->
exists T1 T2, T = typ_arrow T1 T2.
Proof with simpl in *; eauto; try discriminate; repeat fold merge_mutability in *.
intros * Merge.
destruct Merge as [T1 [T2 Eq]].
induction T...
Qed.
#[export] Hint Resolve merge_mutability_inversion_arrow : core.
Lemma merge_mutability_inversion_box : forall T,
~ (exists T', merge_mutability T mut_readonly = typ_box T').
Proof with simpl in *; eauto; try discriminate; repeat fold merge_mutability in *.
intros * Merge.
destruct Merge as [T1 Eq].
induction T...
Qed.
#[export] Hint Resolve merge_mutability_inversion_box : core.
Lemma merge_mutability_inversion_readonly_box : forall T,
(exists T', merge_mutability T mut_readonly = typ_mut mut_readonly (typ_box T')) ->
(exists T', T = typ_box T') \/ (exists T', T = typ_mut mut_readonly (typ_box T')).
Proof with simpl in *; eauto; try discriminate; repeat fold merge_mutability in *.
intros * Merge.
destruct Merge as [T1 Eq].
induction T...
Qed.
#[export] Hint Resolve merge_mutability_inversion_readonly_box : core.
Lemma merge_mutability_inversion_record : forall T,
~ (exists a T', merge_mutability T mut_readonly = typ_record a T').
Proof with simpl in *; eauto; try discriminate; repeat fold merge_mutability in *.
intros * Merge.
destruct Merge as [T1 [a Eq]].
induction T...
Qed.
#[export] Hint Resolve merge_mutability_inversion_record : core.
Lemma merge_mutability_inversion_readonly_record : forall T,
(exists a T', merge_mutability T mut_readonly = typ_mut mut_readonly (typ_record a T')) ->
(exists a T', T = typ_record a T') \/ (exists a T', T = typ_mut mut_readonly (typ_record a T')).
Proof with simpl in *; eauto; try discriminate; repeat fold merge_mutability in *.
intros * Merge.
destruct Merge as [T1 [a Eq]].
induction T...
Qed.
#[export] Hint Resolve merge_mutability_inversion_readonly_record : core.
Lemma in_intersection_merge : forall T1 T,
in_normal_form T ->
~ (exists U1 U2, T1 = typ_int U1 U2) ->
in_intersection T1 (merge_mutability T mut_readonly) ->
in_intersection T1 T \/
exists T1', T1 = typ_mut mut_readonly T1' /\ in_intersection T1' T.
Proof with simpl in *; eauto 4; try repeat fold merge_mutability in *.
intros * NormT Form Int.
dependent induction NormT; try solve [inversion Int; subst; eauto]...
- inversion Int; subst...
right...
- inversion Int; subst...
right...
- inversion Int; subst...
+ exfalso. apply Form...
+ destruct IHNormT1 as [IntT1 | [T1' [EqT1' IntT1'T0]]]...
right...
+ destruct IHNormT2 as [IntT1 | [T1' [EqT1' IntT1'T2]]]...
right...
- inversion Int; subst...
right...
Qed.
#[export] Hint Resolve in_intersection_merge : core.
Lemma in_intersection_of_normal_is_normal : forall S T,
in_normal_form T ->
in_intersection S T ->
in_normal_form S.
Proof with debug eauto.
intros * NormT Int.
dependent induction NormT; try solve [inversion Int; subst; eauto];
inversion Int; subst; econstructor...
Qed.
#[export] Hint Resolve in_intersection_of_normal_is_normal : core.
Lemma merge_mutability_inversion_int : forall T L R,
merge_mutability T mut_readonly = typ_int L R ->
(exists L' R', T = typ_int L' R').
Proof with eauto; simpl in *; repeat fold merge_mutability in *.
intros * MergeEq.
induction T; try discriminate...
Qed.
#[export] Hint Resolve merge_mutability_inversion_int : core.
Lemma in_intersection_to_merge : forall S T,
in_normal_form T ->
in_intersection S T ->
in_intersection S (merge_mutability T mut_readonly) \/
in_intersection (merge_mutability S mut_readonly) (merge_mutability T mut_readonly).
Proof with eauto; simpl in *; repeat fold merge_mutability in *.
intros * NormT IntT.
induction IntT; subst; inversion NormT; subst...
- destruct IHIntT...
- destruct IHIntT...
Qed.
#[export] Hint Resolve in_intersection_to_merge : core.
#[export] Hint Extern 1 (~ exists L R, ?T = typ_int L R) =>
let Bad := fresh "Bad" in intro Bad; destruct Bad as [? [? ?]]; discriminate : core.
#[export] Hint Extern 6 False =>
match goal with
| H : forall S', in_intersection_component S' ?T1 -> S' = typ_top |- _ =>
eenough (T1 = typ_top) by discriminate; apply H; split; eauto
end : core.
#[export] Hint Extern 1 (in_intersection_component ?S ?T) =>
match goal with
| H1 : in_intersection S T |- _ =>
match goal with
| H2 : ~ (exists L R, S = typ_int L R) |- _ =>
split; assumption
end
end : core.
Lemma in_intersection_component_to_merge : forall S T,
in_normal_form T ->
in_intersection_component S T ->
in_intersection_component S (merge_mutability T mut_readonly) \/
in_intersection_component (merge_mutability S mut_readonly)
(merge_mutability T mut_readonly).
Proof with eauto; simpl in *; repeat fold merge_mutability in *.
intros * Norm IntComp.
destruct IntComp as [Primitive IntST]...
dependent induction IntST; subst; try solve [left; split; eauto];
try solve [right; split; eauto]...
- right... split...
intro Bad; destruct Bad as [L [R Eq]]...
- destruct IHIntST; eauto; destruct H...
- destruct IHIntST; eauto; destruct H...
Qed.
#[export] Hint Extern 1 False =>
match goal with
| H : forall S, in_intersection_component S (typ_mut ?m ?T) -> S = typ_top |- _ =>
eenough (typ_mut m T = typ_top) by discriminate; eapply H; split; eauto
end : core.
Lemma in_intersection_component_top_merged : forall T,
in_normal_form T ->
(forall S, in_intersection_component S (merge_mutability T mut_readonly) -> S = typ_top) ->
(forall S, in_intersection_component S T -> S = typ_top).
Proof with eauto 4; simpl in *; repeat fold merge_mutability in *.
intros * NormT SMut * IntS.
destruct IntS as [Primitive IntS]; dependent induction IntS; subst...
* induction NormT; apply SMut; split...
- exfalso...
- exfalso...
- exfalso. apply Primitive...
- exfalso...
* apply IHIntS... intros S' IntS'.
destruct IntS' as [PrimitiveS' IntS']... eapply SMut...
* apply IHIntS... intros S' IntS'.
destruct IntS' as [PrimitiveS' IntS']... eapply SMut...
Qed.
#[export] Hint Extern 1 False =>
let T1 := fresh "T1" in let T2 := fresh "T2" in let BadEq := fresh "BadEq" in
match goal with
| H : forall S, in_intersection_component S (typ_mut ?m ?T) ->
exists S1 S2, S = typ_arrow S1 S2 |- _ =>
eenough (exists T1 T2, typ_mut m T = typ_arrow T1 T2) as [T1 [T2 BadEq]] by discriminate; eapply H; split; eauto
end : core.
Lemma in_intersection_component_arrow_merged : forall T,
in_normal_form T ->
(forall S, in_intersection_component S (merge_mutability T mut_readonly) -> exists S1 S2, S = typ_arrow S1 S2) ->
(forall S, in_intersection_component S T -> exists S1 S2, S = typ_arrow S1 S2).
Proof with eauto; simpl in *; repeat fold merge_mutability in *.
intros * NormT SMut * IntS.
destruct IntS as [Primitive IntS]; dependent induction IntS; subst...
* induction NormT; apply SMut; split...
- exfalso...
- exfalso...
- exfalso. apply Primitive...
- exfalso...
* apply IHIntS... intros S' IntS'.
destruct IntS' as [PrimitiveS' IntS']...
* apply IHIntS... intros S' IntS'.
destruct IntS' as [PrimitiveS' IntS']...
Qed.
#[export] Hint Extern 1 False =>
let T1 := fresh "T1" in let T2 := fresh "T2" in let BadEq := fresh "BadEq" in
match goal with
| H : forall S, in_intersection_component S (typ_mut ?m ?T) ->
S = typ_top \/ exists S1 S2, S = typ_arrow S1 S2 |- _ =>
eenough (typ_mut m T = typ_top \/ exists T1 T2, typ_mut m T = typ_arrow T1 T2) as [Eq | [T1 [T2 BadEq]]] by discriminate; eapply H; split; eauto
end : core.
Lemma in_intersection_component_top_or_arrow_merged : forall T,
in_normal_form T ->
(forall S, in_intersection_component S (merge_mutability T mut_readonly) -> S = typ_top \/ exists S1 S2, S = typ_arrow S1 S2) ->
(forall S, in_intersection_component S T -> S = typ_top \/ exists S1 S2, S = typ_arrow S1 S2).
Proof with eauto; simpl in *; repeat fold merge_mutability in *.
intros * NormT SMut * IntS.
destruct IntS as [Primitive IntS]; dependent induction IntS; subst...
* induction NormT; apply SMut; split...
- exfalso...
- exfalso...
- exfalso. apply Primitive...
- exfalso...
* apply IHIntS... intros S' IntS'.
destruct IntS' as [PrimitiveS' IntS']...
* apply IHIntS... intros S' IntS'.
destruct IntS' as [PrimitiveS' IntS']...
Qed.
Lemma in_intersection_all_component_left : forall P T1 T2,
(forall T, in_intersection_component T (typ_int T1 T2) -> P T) ->
(forall T, in_intersection_component T T1 -> P T).
Proof with eauto.
intros * PropT T IntCompT1.
apply PropT... destruct IntCompT1 as [Prim IntT]; split...
Qed.
Lemma in_intersection_all_component_right : forall P T1 T2,
(forall T, in_intersection_component T (typ_int T1 T2) -> P T) ->
(forall T, in_intersection_component T T2 -> P T).
Proof with eauto.
intros * PropT T IntCompT1.
apply PropT... destruct IntCompT1 as [Prim IntT]; split...
Qed.
Lemma in_intersection_component_merged_top : forall T,
in_normal_form T ->
(forall S, in_intersection_component S T -> S = typ_top) ->
(forall S, in_intersection_component S (merge_mutability T mut_readonly) -> S = typ_top).
Proof with eauto 4; simpl in *; repeat fold merge_mutability in *.
intros * NormT IntCompS S IntCompSMut.
dependent induction NormT...
* exfalso...
* exfalso...
* destruct IntCompSMut as [Primitive IntS]...
unshelve epose proof
(in_intersection_all_component_left _ _ _ IntCompS).
unshelve epose proof
(in_intersection_all_component_right _ _ _ IntCompS).
inversion IntS; subst...
- exfalso. apply Primitive...
* exfalso...
Qed.
#[export] Hint Extern 6 False => let Eq := fresh "Eq" in let _S1 := fresh "S1" in let _S2 := fresh "S2" in
match goal with
| H : forall S', in_intersection_component S' ?T1 -> exists S1 S2, S' = typ_arrow S1 S2 |- _ =>
eenough (exists S1 S2, T1 = typ_arrow S1 S2) as [_S1 [_S2 Eq]] by discriminate; apply H; split; eauto
end : core.
Lemma in_intersection_component_merged_arrow : forall T,
in_normal_form T ->
(forall S, in_intersection_component S T -> exists S1 S2, S = typ_arrow S1 S2) ->
(forall S, in_intersection_component S (merge_mutability T mut_readonly) -> exists S1 S2, S = typ_arrow S1 S2).
Proof with eauto 4; simpl in *; repeat fold merge_mutability in *.
intros * NormT IntCompS S IntCompSMut.
dependent induction NormT...
* exfalso...
* exfalso...
* destruct IntCompSMut as [Primitive IntS]...
unshelve epose proof
(in_intersection_all_component_left _ _ _ IntCompS).
unshelve epose proof
(in_intersection_all_component_right _ _ _ IntCompS).
inversion IntS; subst...
- exfalso. apply Primitive...
* exfalso...
Qed.
#[export] Hint Extern 6 False =>
let Eq := fresh "Eq" in let _S1 := fresh "S1" in let _S2 := fresh "S2" in
match goal with
| H : forall S', in_intersection_component S' ?T1 -> S' = typ_top \/ exists S1 S2, S' = typ_arrow S1 S2 |- _ =>
eenough (T1 = typ_top \/ exists S1 S2, T1 = typ_arrow S1 S2) as [Eq | [_S1 [_S2 Eq]]] by discriminate; apply H; split; eauto
end : core.
Lemma in_intersection_component_merged_top_or_arrow : forall T,
in_normal_form T ->
(forall S, in_intersection_component S T -> S = typ_top \/ exists S1 S2, S = typ_arrow S1 S2) ->
(forall S, in_intersection_component S (merge_mutability T mut_readonly) -> S = typ_top \/ exists S1 S2, S = typ_arrow S1 S2).
Proof with eauto 4; simpl in *; repeat fold merge_mutability in *.
intros * NormT IntCompS S IntCompSMut.
dependent induction NormT...
* exfalso...
* exfalso...
* destruct IntCompSMut as [Primitive IntS]...
unshelve epose proof
(in_intersection_all_component_left _ _ _ IntCompS).
unshelve epose proof
(in_intersection_all_component_right _ _ _ IntCompS).
inversion IntS; subst...
- exfalso. apply Primitive...
* exfalso...
Qed.
Lemma mut_in_intersection_is_component : forall S S' T,
S = typ_mut mut_readonly S' ->
in_normal_form T ->
in_intersection S T ->
in_intersection_component S T.
Proof with eauto.
intros * Eq NormT IntS.
split...
induction NormT; inversion IntS; subst; try discriminate...
Qed.
#[export] Hint Extern 6 False => let Bad := fresh "Bad" in
match goal with
| H : forall S', in_intersection_component S' ?T1 -> exists S1, S' = typ_box S1 |- _ =>
eenough (exists S1, T1 = typ_box S1) as
Bad by (destruct Bad as [? ?]; discriminate); apply H; split; eauto
end : core.
#[export] Hint Extern 6 False =>
let Eq := fresh "Eq" in let _S1 := fresh "S1" in
match goal with
| H : forall S', in_intersection_component S' ?T1 -> S' = typ_top \/ exists S1, S' = typ_box S1 |- _ =>
eenough (T1 = typ_top \/ exists S1, T1 = typ_box S1) as [Eq | [_S1 Eq]] by discriminate; apply H; split; eauto
end : core.
Lemma in_intersection_component_top_or_box_merged : forall T,
in_normal_form T ->
(forall S, in_intersection_component S (merge_mutability T mut_readonly) -> S = typ_top \/ exists S1, S = typ_box S1) ->
(forall S, in_intersection_component S T -> S = typ_top \/ exists S1, S = typ_box S1).
Proof with eauto 4; simpl in *; repeat fold merge_mutability in *.
intros * NormT SMut * IntS.
destruct IntS as [Primitive IntS]; dependent induction IntS; subst...
* induction NormT; apply SMut; split...
- exfalso...
- exfalso...
- exfalso. apply Primitive...
- exfalso...
* apply IHIntS... intros S' IntS'.
destruct IntS' as [PrimitiveS' IntS']... eapply SMut...
* apply IHIntS... intros S' IntS'.
destruct IntS' as [PrimitiveS' IntS']... eapply SMut...
Qed.
Lemma in_intersection_component_merged_top_or_box : forall T,
in_normal_form T ->
(forall S, in_intersection_component S T -> S = typ_top \/ exists S1, S = typ_box S1) ->
(forall S, in_intersection_component S (merge_mutability T mut_readonly) -> S = typ_top \/ exists S1, S = typ_mut mut_readonly (typ_box S1)).
Proof with eauto 4; simpl in *; repeat fold merge_mutability in *.
intros * NormT IntCompS S IntCompSMut.
dependent induction NormT;
try solve [inversion IntCompSMut as [Prim Eq]; inversion Eq; eauto]...
* exfalso...
* exfalso...
* exfalso...
* exfalso...
* exfalso...
* destruct IntCompSMut as [Primitive IntS]...
unshelve epose proof
(in_intersection_all_component_left _ _ _ IntCompS).
unshelve epose proof
(in_intersection_all_component_right _ _ _ IntCompS).
inversion IntS; subst...
- exfalso. apply Primitive...
* exfalso...
* exfalso...
Qed.
#[export] Hint Extern 6 False => let Bad := fresh "Bad" in
match goal with
| H : forall S', in_intersection_component S' ?T1 ->
exists S1, S' = typ_box S1 |- _ =>
eenough (exists S1, T1 = typ_box S1) as
Bad by (destruct Bad as [? ?]; discriminate); apply H; split; eauto
end : core.
#[export] Hint Extern 6 False =>
let Eq := fresh "Eq" in let _S1 := fresh "S1" in
match goal with
| H : forall S', in_intersection_component S' ?T1 ->
S' = typ_top \/ (exists S1, S' = typ_box S1) \/ (exists S2, S' = typ_mut mut_readonly (typ_box S2)) |- _ =>
eenough (T1 = typ_top \/
(exists S1, T1 = typ_box S1) \/
(exists S2, T1 = typ_mut mut_readonly (typ_box S2)))
as [Eq | [[_S1 Eq] | [_S1 Eq]]] by discriminate; apply H; split; eauto
end : core.
Lemma in_intersection_component_top_or_box_or_readonly_box_merged : forall T,
in_normal_form T ->
(forall S, in_intersection_component S (merge_mutability T mut_readonly) ->
S = typ_top \/ (exists S1, S = typ_box S1) \/ (exists S1, S = typ_mut mut_readonly (typ_box S1))) ->
(forall S,
in_intersection_component S T ->
S = typ_top \/ (exists S1, S = typ_box S1) \/ (exists S1, S = typ_mut mut_readonly (typ_box S1))).
Proof with eauto 4; simpl in *; repeat fold merge_mutability in *.
intros * NormT SMut * IntS.
destruct IntS as [Primitive IntS]; dependent induction IntS; subst...
* induction NormT...
- exfalso...
- exfalso...
- exfalso...
- exfalso...
- right... right... destruct m...
- exfalso. apply Primitive...
- exfalso...
- exfalso...
* apply IHIntS... intros S' IntS'.
destruct IntS' as [PrimitiveS' IntS']... eapply SMut...
* apply IHIntS... intros S' IntS'.
destruct IntS' as [PrimitiveS' IntS']... eapply SMut...
Qed.
Lemma in_intersection_component_merged_top_or_box_or_readonly_box : forall T,
in_normal_form T ->
(forall S, in_intersection_component S T ->
S = typ_top \/ (exists S1, S = typ_box S1) \/ (exists S1, (S = typ_mut mut_readonly (typ_box S1)))) ->
(forall S, in_intersection_component S (merge_mutability T mut_readonly) ->
S = typ_top \/ (exists S1, S = typ_mut mut_readonly (typ_box S1))).
Proof with eauto 4; simpl in *; repeat fold merge_mutability in *.
intros * NormT IntCompS S IntCompSMut.
dependent induction NormT;
try solve [inversion IntCompSMut as [Prim Eq]; inversion Eq; eauto]...
* exfalso...
* exfalso...
* exfalso...
* exfalso...
* right... destruct m... destruct IntCompSMut as [Prim Eq]...