-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpure_inferencePropsScript.sml
1442 lines (1319 loc) · 50.6 KB
/
pure_inferencePropsScript.sml
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
open HolKernel Parse boolLib bossLib BasicProvers dep_rewrite;
open pairTheory arithmeticTheory stringTheory optionTheory pred_setTheory
listTheory rich_listTheory alistTheory finite_mapTheory sptreeTheory;
open mlmapTheory;
open pure_miscTheory pure_typingTheory pure_typingPropsTheory
pure_inference_commonTheory pure_unificationTheory pure_inferenceTheory;
val _ = new_theory "pure_inferenceProps";
(******************* General results ********************)
(********** type_of/itype_of **********)
Theorem type_of_itype_of:
∀t. type_of (itype_of t) = SOME t
Proof
recInduct type_ind >> rw[itype_of_def, type_of_def] >>
Induct_on `l` >> rw[]
QED
Theorem type_of_SOME:
∀it t. type_of it = SOME t ⇒ itype_of t = it
Proof
recInduct itype_ind >> rw[] >> gvs[type_of_def, itype_of_def] >>
rpt $ pop_assum mp_tac >> qid_spec_tac `z` >> Induct_on `ts` >> rw[] >> gvs[]
QED
Theorem type_of_SOME_MAP:
∀its ts. MAP type_of its = MAP SOME ts ⇒ MAP itype_of ts = its
Proof
Induct >> rw[] >> Cases_on `ts` >> gvs[] >> imp_res_tac type_of_SOME
QED
Theorem type_of_SOME_lemma:
(∀its t. type_of (Tuple its) = SOME t ⇒
∃ts. t = Tuple ts ∧ MAP type_of its = MAP SOME ts) ∧
(∀its id t. type_of (TypeCons id its) = SOME t
⇒ ∃ts. t = TypeCons id ts ∧ MAP type_of its = MAP SOME ts) ∧
(∀its it ft. type_of (iFunctions its it) = SOME ft
⇒ ∃ts t. ft = Functions ts t ∧ MAP type_of its = MAP SOME ts ∧ type_of it = SOME t)
Proof
rpt conj_tac >> Induct >> rw[] >> gvs[type_of_def, iFunctions_def, Functions_def] >>
first_x_assum drule >> strip_tac >> simp[] >>
qexists_tac `it1::ts` >> simp[Functions_def]
QED
Theorem type_of_lemma:
(∀its ts. MAP type_of its = MAP SOME ts ⇒
type_of (Tuple its) = SOME (Tuple ts)) ∧
(∀its ts id. MAP type_of its = MAP SOME ts ⇒
type_of (TypeCons id its) = SOME (TypeCons id ts)) ∧
(∀its ts it t.
MAP type_of its = MAP SOME ts ∧ type_of it = SOME t ⇒
type_of (iFunctions its it) = SOME (Functions ts t))
Proof
rpt conj_tac >> Induct >> rw[] >> gvs[type_of_def, iFunctions_def, Functions_def] >>
Cases_on `ts` >> gvs[Functions_def]
QED
Theorem itype_of_11:
∀t1 t2. itype_of t1 = itype_of t2 ⇔ t1 = t2
Proof
Induct using type_ind >> rw[] >>
Cases_on `t2` >> rw[itype_of_def] >>
eq_tac >> rw[] >>
drule_at Any miscTheory.INJ_MAP_EQ_2 >> disch_then irule >> rw[] >> gvs[]
QED
Theorem type_of_ishift:
∀t vs. type_of (ishift vs t) = OPTION_MAP (tshift vs) (type_of t)
Proof
Induct using itype_ind >> rw[ishift_def, type_of_def, shift_db_def]
>- (
simp[OPTION_MAP_COMPOSE, combinTheory.o_DEF, shift_db_def, SF ETA_ss] >>
simp[FOLDR_MAP] >>
simp[GSYM combinTheory.o_DEF, GSYM OPTION_MAP_COMPOSE] >> AP_TERM_TAC >>
simp[combinTheory.o_DEF] >>
qsuff_tac `∀l.
FOLDR (λx y. OPTION_MAP2 CONS (type_of (ishift vs x)) y)
(SOME (MAP (tshift vs) l)) ts =
OPTION_MAP (MAP (tshift vs))
(FOLDR (λx. OPTION_MAP2 CONS (type_of x)) (SOME l) ts)`
>- (rw[] >> pop_assum $ qspec_then `[]` mp_tac >> simp[SF ETA_ss]) >>
Induct_on `ts` >> rw[shift_db_def] >> gvs[SF ETA_ss] >>
Cases_on `type_of h` >- simp[OPTION_MAP2_DEF] >>
simp[OPTION_MAP2_OPTION_MAP, OPTION_MAP_COMPOSE, combinTheory.o_DEF]
)
>- (
simp[OPTION_MAP_COMPOSE, combinTheory.o_DEF, shift_db_def, SF ETA_ss] >>
simp[FOLDR_MAP] >>
simp[GSYM combinTheory.o_DEF, GSYM OPTION_MAP_COMPOSE] >> AP_TERM_TAC >>
simp[combinTheory.o_DEF] >>
qsuff_tac `∀l.
FOLDR (λx y. OPTION_MAP2 CONS (type_of (ishift vs x)) y)
(SOME (MAP (tshift vs) l)) ts =
OPTION_MAP (MAP (tshift vs))
(FOLDR (λx. OPTION_MAP2 CONS (type_of x)) (SOME l) ts)`
>- (rw[] >> pop_assum $ qspec_then `[]` mp_tac >> simp[SF ETA_ss]) >>
Induct_on `ts` >> rw[shift_db_def] >> gvs[SF ETA_ss] >>
Cases_on `type_of h` >- simp[OPTION_MAP2_DEF] >>
simp[OPTION_MAP2_OPTION_MAP, OPTION_MAP_COMPOSE, combinTheory.o_DEF]
)
>- (
Cases_on `type_of t` >> gvs[] >>
Cases_on `type_of t'` >> gvs[shift_db_def]
)
>- (Cases_on `type_of t` >> gvs[shift_db_def])
>- (Cases_on `type_of t` >> gvs[shift_db_def])
QED
(********** pure_vars **********)
Theorem pure_vars_empty_eq_type_of:
∀it. pure_vars it = {} ⇔ (∃t. type_of it = SOME t)
Proof
recInduct itype_ind >> reverse $ rw[pure_vars, type_of_def]
>- (eq_tac >> rw[] >> rpt $ goal_assum drule >> simp[]) >>
(
Induct_on `ts` >> rw[] >> gvs[INSERT_EQ_SING] >> eq_tac >> rw[]
>- (
goal_assum drule >>
first_x_assum $ irule o iffLR >>
rw[DISJ_EQ_IMP, Once EXTENSION, MEM_MAP] >>
gvs[LIST_TO_SET_MAP, SUBSET_DEF] >> eq_tac >> rw[] >>
Cases_on `ts` >> gvs[] >> metis_tac[]
)
>- (goal_assum drule)
>- gvs[LIST_TO_SET_MAP, SUBSET_DEF]
)
QED
Theorem pure_vars_empty_eq_type_of_MAP:
∀its. (EVERY (λit. pure_vars it = {}) its) ⇔ ∃ts. MAP type_of its = MAP SOME ts
Proof
Induct >> rw[] >> eq_tac >> rw[]
>- (gvs[pure_vars_empty_eq_type_of] >> qexists_tac `t::ts` >> simp[])
>- (
Cases_on `ts` >> gvs[] >>
irule $ iffRL pure_vars_empty_eq_type_of >> goal_assum drule
)
>- ( Cases_on `ts` >> gvs[] >> irule_at Any EQ_REFL)
QED
Theorem pure_vars_itype_of[simp]:
∀t. pure_vars (itype_of t) = {}
Proof
recInduct type_ind >> rw[itype_of_def, pure_vars] >>
Induct_on `l` >> gvs[] >> rw[] >> gvs[]
QED
Theorem FINITE_pure_vars[simp]:
∀it. FINITE (pure_vars it)
Proof
recInduct itype_ind >> rw[pure_vars_def]
QED
Theorem pure_vars_iFunctions:
pure_vars (iFunctions tys ty) = BIGUNION (set (MAP pure_vars tys)) ∪ pure_vars ty
Proof
Induct_on `tys` >> rw[iFunctions_def, pure_vars] >> simp[UNION_ASSOC]
QED
Theorem pure_vars_ishift[simp]:
∀n t. pure_vars (ishift n t) = pure_vars t
Proof
gen_tac >> recInduct itype_ind >> rw[ishift_def, pure_vars] >>
simp[MAP_MAP_o, combinTheory.o_DEF] >>
rpt AP_TERM_TAC >> simp[MAP_EQ_f]
QED
Theorem pure_vars_isubst_SUBSET:
∀s t. pure_vars (isubst s t) ⊆ pure_vars t ∪ BIGUNION (set (MAP pure_vars s))
Proof
recInduct isubst_ind >> rw[isubst_def, pure_vars] >>
gvs[BIGUNION_SUBSET, LIST_TO_SET_MAP, IMAGE_IMAGE, combinTheory.o_DEF, PULL_EXISTS] >>
rw[] >> gvs[SUBSET_DEF, PULL_EXISTS] >> metis_tac[EL_MEM]
QED
Theorem pure_vars_isubst_SUPERSET:
∀s t. pure_vars t ⊆ pure_vars (isubst s t)
Proof
recInduct isubst_ind >> rw[isubst_def, pure_vars] >>
gvs[BIGUNION_SUBSET, LIST_TO_SET_MAP, IMAGE_IMAGE, combinTheory.o_DEF, PULL_EXISTS] >>
rw[] >> gvs[SUBSET_DEF] >> metis_tac[]
QED
Theorem pure_vars_pure_apply_subst_SUBSET:
∀t s. pure_vars (pure_apply_subst s t) ⊆
(pure_vars t DIFF FDOM s) ∪ BIGUNION (IMAGE pure_vars (FRANGE s))
Proof
recInduct itype_ind >> reverse $ rw[pure_apply_subst, pure_vars] >>
simp[LIST_TO_SET_MAP, IMAGE_IMAGE, combinTheory.o_DEF, BIGUNION_SUBSET,
FLOOKUP_DEF, pure_vars] >>
gvs[SUBSET_DEF] >> rw[PULL_EXISTS]
>- (goal_assum drule >> simp[FRANGE_DEF] >> metis_tac[]) >>
metis_tac[]
QED
Theorem pure_vars_pure_apply_subst_SUPERSET:
∀t s. pure_vars t DIFF FDOM s ∪
BIGUNION (IMAGE (pure_vars o pure_apply_subst s o CVar) (pure_vars t)) ⊆
pure_vars (pure_apply_subst s t)
Proof
recInduct itype_ind >> reverse $ rw[pure_apply_subst, pure_vars]
>- simp[BIGUNION_SUBSET, FLOOKUP_DEF, PULL_EXISTS, pure_vars] >>
gvs[DIFF_SUBSET, BIGUNION_SUBSET,
LIST_TO_SET_MAP, IMAGE_IMAGE, combinTheory.o_DEF, PULL_EXISTS] >>
rw[] >> gvs[SUBSET_DEF] >> metis_tac[]
QED
Theorem pure_vars_pure_walkstar_SUBSET:
∀s t. pure_wfs s ⇒
pure_vars (pure_walkstar s t) ⊆
(pure_vars t ∪ BIGUNION (FRANGE (pure_vars o_f s))) DIFF FDOM s
Proof
assume_tac pure_walkstar_vars_in >>
assume_tac pure_walkstar_vars_notin >>
gvs[SUBSET_DEF] >> rw[] >> res_tac
QED
Theorem pure_vars_pure_walkstar_SUPERSET:
∀s t. pure_wfs s ⇒
pure_vars t DIFF FDOM s ∪
BIGUNION (IMAGE (pure_vars o pure_walkstar s o CVar) (pure_vars t)) ⊆
pure_vars (pure_walkstar s t)
Proof
gen_tac >> simp[GSYM PULL_FORALL] >> strip_tac >>
qspec_then `s` mp_tac pure_walkstar_alt_ind >> simp[] >>
disch_then ho_match_mp_tac >> reverse $ rw[] >>
simp[pure_vars, pure_walkstar_alt]
>- (gvs[FLOOKUP_DEF] >> IF_CASES_TAC >> gvs[pure_vars]) >>
gvs[DIFF_SUBSET, BIGUNION_SUBSET, PULL_EXISTS,
LIST_TO_SET_MAP, IMAGE_IMAGE, combinTheory.o_DEF] >>
rw[] >> gvs[SUBSET_DEF] >> metis_tac[]
QED
Theorem pure_vars_pure_walkstar:
∀sub. pure_wfs sub ⇒
∀it n.
n ∈ pure_vars (pure_walkstar sub it) ⇒
∃cv. cv ∈ pure_vars it ∧ n ∈ pure_vars (pure_walkstar sub (CVar cv))
Proof
gen_tac >> strip_tac >>
qspec_then `sub` mp_tac pure_walkstar_alt_ind >> simp[] >>
disch_then ho_match_mp_tac >> rw[pure_vars, pure_walkstar_alt] >>
gvs[MAP_MAP_o, combinTheory.o_DEF, MEM_MAP, PULL_EXISTS]
>- (
goal_assum $ drule_at Any >>
first_x_assum drule_all >> strip_tac >> gvs[] >> rpt $ goal_assum drule
)
>- (
goal_assum $ drule_at Any >>
first_x_assum drule_all >> strip_tac >> gvs[] >> rpt $ goal_assum drule
)
>- (
first_x_assum drule >> strip_tac >> simp[] >>
irule_at Any OR_INTRO_THM1 >> rpt $ goal_assum drule
)
>- (
first_x_assum drule >> strip_tac >> simp[] >>
irule_at Any OR_INTRO_THM2 >> rpt $ goal_assum drule
)
QED
(********** freedbvars/itype_wf/itype_ok **********)
Theorem freetyvars_ok_freedbvars:
∀t db. freetyvars_ok db t ⇔ ∀n. n ∈ freedbvars (itype_of t) ⇒ n < db
Proof
recInduct type_ind >> rw[freetyvars_ok_def, itype_of_def, freedbvars_def] >>
rw[EVERY_MEM, MEM_MAP, PULL_EXISTS] >> eq_tac >> rw[] >> gvs[] >> metis_tac[]
QED
Theorem freetyvars_ok_freedbvars_alt:
∀t db. freetyvars_ok db t ⇔ freedbvars (itype_of t) ⊆ count db
Proof
rw[freetyvars_ok_freedbvars, SUBSET_DEF]
QED
Theorem type_wf_itype_wf:
∀t tdefs. type_wf tdefs t ⇔ itype_wf tdefs (itype_of t)
Proof
recInduct type_ind >> rw[type_wf_def, itype_wf_def, itype_of_def] >>
rw[EVERY_MEM, MEM_MAP, PULL_EXISTS]
QED
Theorem freedbvars_iFunctions:
∀ts t. freedbvars (iFunctions ts t) =
freedbvars t ∪ BIGUNION (set (MAP freedbvars ts))
Proof
Induct >> rw[iFunctions_def, freedbvars_def] >> rw[AC UNION_ASSOC UNION_COMM]
QED
Theorem freedbvars_pure_apply_subst_SUBSET:
∀it sub. freedbvars (pure_apply_subst sub it) ⊆
freedbvars it ∪ BIGUNION (IMAGE freedbvars (FRANGE sub))
Proof
recInduct itype_ind >> reverse $ rw[freedbvars_def, pure_apply_subst] >>
gvs[LIST_TO_SET_MAP, IMAGE_IMAGE, combinTheory.o_DEF] >>
gvs[BIGUNION_SUBSET, PULL_EXISTS, SUBSET_DEF] >> rw[]
>- (
every_case_tac >> gvs[freedbvars_def] >>
gvs[IN_FRANGE_FLOOKUP] >> rpt $ goal_assum drule
) >>
metis_tac[]
QED
Theorem freedbvars_pure_apply_subst_SUPERSET:
∀it sub.
freedbvars it ∪
BIGUNION (IMAGE (freedbvars o pure_apply_subst sub o CVar) (pure_vars it)) ⊆
freedbvars (pure_apply_subst sub it)
Proof
recInduct itype_ind >> reverse $ rw[freedbvars_def, pure_apply_subst, pure_vars] >>
gvs[LIST_TO_SET_MAP, IMAGE_IMAGE, combinTheory.o_DEF] >>
gvs[BIGUNION_SUBSET, PULL_EXISTS, SUBSET_DEF] >> rw[] >>
metis_tac[]
QED
Theorem freedbvars_pure_vwalk_SUBSET:
∀sub n. pure_wfs sub ⇒
freedbvars (pure_vwalk sub n) ⊆
BIGUNION (IMAGE freedbvars (FRANGE sub))
Proof
gen_tac >> simp[GSYM PULL_FORALL] >> strip_tac >>
qspec_then `sub` mp_tac pure_vwalk_ind >> simp[] >>
disch_then ho_match_mp_tac >> rw[] >>
simp[Once pure_vwalk] >> every_case_tac >> gvs[freedbvars_def] >>
gvs[BIGUNION_SUBSET, IN_FRANGE_FLOOKUP, PULL_EXISTS] >> rw[]
>- (goal_assum $ drule_at Any >> simp[freedbvars_def]) >>
simp[SUBSET_DEF, IN_FRANGE_FLOOKUP, PULL_EXISTS] >> rw[] >>
goal_assum $ drule_at $ Pos last >>
simp[freedbvars_def] >> goal_assum drule >> simp[]
QED
Theorem freedbvars_pure_walk_SUBSET:
∀sub it. pure_wfs sub ⇒
freedbvars (pure_walk sub it) ⊆
freedbvars it ∪ BIGUNION (IMAGE freedbvars (FRANGE sub))
Proof
rw[pure_walk] >> CASE_TAC >> gvs[freedbvars_def] >>
simp[freedbvars_pure_vwalk_SUBSET]
QED
Theorem freedbvars_pure_walkstar_SUBSET:
∀sub it. pure_wfs sub ⇒
freedbvars (pure_walkstar sub it) ⊆
freedbvars it ∪ BIGUNION (IMAGE freedbvars (FRANGE sub))
Proof
gen_tac >> simp[GSYM PULL_FORALL] >> strip_tac >>
qspec_then `sub` mp_tac pure_walkstar_ind >> simp[] >>
disch_then ho_match_mp_tac >> rw[] >>
DEP_ONCE_REWRITE_TAC[pure_walkstar] >> simp[] >>
drule freedbvars_pure_walk_SUBSET >>
disch_then $ qspec_then `it` assume_tac >>
CASE_TAC >> gvs[freedbvars_def]
>- (
gvs[Once pure_walk] >> every_case_tac >> gvs[freedbvars_def, PULL_EXISTS] >>
drule freedbvars_pure_vwalk_SUBSET >>
disch_then $ qspec_then `n'` mp_tac >> simp[freedbvars_def, PULL_EXISTS]
) >>
gvs[LIST_TO_SET_MAP, IMAGE_IMAGE, combinTheory.o_DEF,
BIGUNION_SUBSET, PULL_EXISTS] >>
rw[] >> gvs[SUBSET_DEF] >> metis_tac[]
QED
Theorem freedbvars_pure_walk_SUPERSET:
∀sub it. pure_wfs sub ⇒
freedbvars it ⊆ freedbvars (pure_walk sub it)
Proof
rw[pure_walk] >> CASE_TAC >> gvs[freedbvars_def]
QED
Theorem freedbvars_pure_walkstar_SUPERSET:
∀sub it. pure_wfs sub ⇒
freedbvars it ⊆ freedbvars (pure_walkstar sub it)
Proof
gen_tac >> simp[GSYM PULL_FORALL] >> strip_tac >>
qspec_then `sub` mp_tac pure_walkstar_ind >> simp[] >>
disch_then ho_match_mp_tac >> rw[] >>
DEP_ONCE_REWRITE_TAC[pure_walkstar] >> simp[] >>
drule freedbvars_pure_walk_SUPERSET >>
disch_then $ qspec_then `it` assume_tac >>
CASE_TAC >> gvs[freedbvars_def] >>
gvs[LIST_TO_SET_MAP, IMAGE_IMAGE, combinTheory.o_DEF, SUBSET_DEF] >>
metis_tac[]
QED
Theorem itype_wf_pure_apply_subst:
∀it tdefs sub.
(∀it. it ∈ FRANGE sub ⇒ itype_wf tdefs it) ∧
itype_wf tdefs it ⇒
itype_wf tdefs (pure_apply_subst sub it)
Proof
recInduct itype_ind >> rw[pure_apply_subst, itype_wf_def] >>
gvs[EVERY_MAP, EVERY_MEM] >>
CASE_TAC >> gvs[itype_wf_def, IN_FRANGE_FLOOKUP, PULL_EXISTS] >> res_tac
QED
Theorem itype_wf_pure_vwalk:
∀sub n tdefs. pure_wfs sub ⇒
(∀it. it ∈ FRANGE sub ⇒ itype_wf tdefs it)
⇒ itype_wf tdefs (pure_vwalk sub n)
Proof
gen_tac >> simp[GSYM PULL_FORALL] >> strip_tac >>
qspec_then `sub` mp_tac pure_vwalk_ind >> simp[] >>
disch_then ho_match_mp_tac >> rw[] >>
DEP_ONCE_REWRITE_TAC[pure_vwalk] >> simp[] >>
every_case_tac >> gvs[itype_wf_def, IN_FRANGE_FLOOKUP, PULL_EXISTS] >>
res_tac >> gvs[itype_wf_def]
QED
Theorem itype_wf_pure_walk:
∀sub it tdefs. pure_wfs sub ⇒
(∀it. it ∈ FRANGE sub ⇒ itype_wf tdefs it) ∧
itype_wf tdefs it
⇒ itype_wf tdefs (pure_walk sub it)
Proof
rw[pure_walk] >> every_case_tac >> gvs[itype_wf_pure_vwalk]
QED
Theorem itype_wf_pure_walkstar:
∀sub it tdefs. pure_wfs sub ⇒
(∀it. it ∈ FRANGE sub ⇒ itype_wf tdefs it) ∧
itype_wf tdefs it
⇒ itype_wf tdefs (pure_walkstar sub it)
Proof
gen_tac >> simp[GSYM PULL_FORALL] >> strip_tac >>
qspec_then `sub` mp_tac pure_walkstar_ind >> impl_tac >- simp[] >>
disch_then ho_match_mp_tac >> rw[] >>
DEP_ONCE_REWRITE_TAC[pure_walkstar] >> simp[] >>
drule_all itype_wf_pure_walk >> strip_tac >>
CASE_TAC >> gvs[itype_wf_def, EVERY_MAP, EVERY_MEM]
QED
Theorem pure_apply_subst_itype_wf:
∀it sub tdefs.
itype_wf tdefs (pure_apply_subst sub it)
⇒ ∀k v. k ∈ pure_vars it ∧ FLOOKUP sub k = SOME v ⇒ itype_wf tdefs v
Proof
recInduct itype_ind >> rw[itype_wf_def, pure_apply_subst, pure_vars] >>
gvs[MEM_MAP, EVERY_MAP, EVERY_MEM]
>- (first_x_assum drule >> rw[] >> last_x_assum $ drule_all >> rw[])
>- (first_x_assum drule >> rw[] >> last_x_assum $ drule_all >> rw[])
>- (first_x_assum drule_all >> rw[])
>- (first_x_assum drule_all >> rw[])
QED
Theorem pure_apply_subst_itype_of[simp]:
∀t s. pure_apply_subst s (itype_of t) = itype_of t
Proof
recInduct type_ind >> rw[itype_of_def, pure_apply_subst] >>
rw[MAP_MAP_o, combinTheory.o_DEF, MAP_EQ_f]
QED
Theorem itype_ok:
(∀tds v n. itype_ok tds n (CVar v) ⇔ T) ∧
(∀tds v n. itype_ok tds n (DBVar v) ⇔ v < n) ∧
(∀tds p n. itype_ok tds n (PrimTy p) ⇔ T) ∧
(∀tds n. itype_ok tds n Exception ⇔ T) ∧
(∀tds ts n c.
itype_ok tds n (TypeCons c ts) ⇔
EVERY (λa. itype_ok tds n a) ts ∧
∃ctors. LLOOKUP tds c = SOME (LENGTH ts,ctors)) ∧
(∀tds ts n. itype_ok tds n (Tuple ts) ⇔ EVERY (λa. itype_ok tds n a) ts) ∧
(∀tds tf t n.
itype_ok tds n (Function tf t) ⇔ itype_ok tds n tf ∧ itype_ok tds n t) ∧
(∀tds t n. itype_ok tds n (Array t) ⇔ itype_ok tds n t) ∧
(∀tds t n. itype_ok tds n (M t) ⇔ itype_ok tds n t)
Proof
rw[itype_ok_def, itype_wf_def, freedbvars_def] >>
gvs[EVERY_CONJ] >> eq_tac >> gvs[] >>
gvs[BIGUNION_SUBSET, MEM_MAP, PULL_EXISTS, EVERY_MEM] >> rw[]
QED
Theorem itype_ok_iFunctions:
∀ts t tds db. itype_ok tds db (iFunctions ts t) ⇔
EVERY (itype_ok tds db) ts ∧ itype_ok tds db t
Proof
Induct >> rw[iFunctions_def] >>
simp[itype_ok] >> eq_tac >> rw[]
QED
Theorem itype_ok_type_ok:
∀t tdefs db. itype_ok tdefs db (itype_of t) ⇔ type_ok tdefs db t
Proof
rw[itype_ok_def, type_ok_def] >>
simp[freetyvars_ok_freedbvars_alt, GSYM type_wf_itype_wf]
QED
Theorem itype_ok_pure_apply_subst:
∀it sub tdefs db.
itype_ok tdefs db it ∧
(∀it. it ∈ FRANGE sub ⇒ itype_ok tdefs db it)
⇒ itype_ok tdefs db (pure_apply_subst sub it)
Proof
Induct using itype_ind >> rw[pure_apply_subst, itype_ok] >>
gvs[EVERY_MAP, EVERY_MEM] >>
CASE_TAC >> simp[itype_ok] >>
gvs[IN_FRANGE_FLOOKUP, PULL_EXISTS] >> res_tac
QED
Theorem itype_ok_pure_walkstar:
∀sub. pure_wfs sub ⇒
∀it tdefs db.
(∀it. it ∈ FRANGE sub ⇒ itype_ok tdefs db it) ∧
itype_ok tdefs db it
⇒ itype_ok tdefs db (pure_walkstar sub it)
Proof
gen_tac >> strip_tac >>
qspec_then `sub` mp_tac pure_walkstar_alt_ind >> simp[] >>
disch_then ho_match_mp_tac >> rw[] >>
gvs[pure_walkstar_alt, itype_ok, EVERY_MAP, EVERY_MEM] >>
CASE_TAC >> gvs[itype_ok] >>
first_x_assum irule >> simp[] >>
gvs[IN_FRANGE_FLOOKUP, PULL_EXISTS] >> res_tac
QED
Theorem itype_ok_ishift:
∀shift tdefs n t.
itype_ok tdefs n t ⇒ itype_ok tdefs (n + shift) (ishift shift t)
Proof
rw[] >> Induct_on `t` using itype_ind >> rw[itype_ok, ishift_def] >>
gvs[EVERY_MAP, EVERY_MEM]
QED
Theorem itype_ok_isubst:
∀t ts n tdefs.
itype_ok tdefs (n + LENGTH ts) t ∧
EVERY (itype_ok tdefs n) ts
⇒ itype_ok tdefs n (isubst ts t)
Proof
Induct using itype_ind >> rw[itype_ok, isubst_def] >>
gvs[EVERY_EL, EVERY_MAP, MEM_EL, PULL_EXISTS]
QED
Theorem pure_vwalk_itype_ok:
∀s. pure_wfs s ⇒
∀n tds db.
(∀it. it ∈ FRANGE s ⇒ itype_ok tds db it)
⇒ itype_ok tds db (pure_vwalk s n)
Proof
gen_tac >> strip_tac >>
imp_res_tac pure_vwalk_ind >> pop_assum ho_match_mp_tac >> rw[] >>
DEP_ONCE_REWRITE_TAC[pure_vwalk] >> simp[] >>
CASE_TAC >> gvs[itype_ok] >>
gvs[IN_FRANGE_FLOOKUP, PULL_EXISTS] >>
CASE_TAC >> gvs[] >> res_tac
QED
Theorem pure_walk_itype_ok:
∀s t tds db.
pure_wfs s ∧
itype_ok tds db t ∧
(∀it. it ∈ FRANGE s ⇒ itype_ok tds db it)
⇒ itype_ok tds db (pure_walk s t)
Proof
rw[pure_walk] >> CASE_TAC >> gvs[] >>
drule_all pure_vwalk_itype_ok >> simp[]
QED
Theorem pure_unify_itype_ok_lemma:
(∀s t1 t2. pure_wfs s ⇒
∀sub it.
itype_ok tds db t1 ∧ itype_ok tds db t2 ∧
(∀it. it ∈ FRANGE s ⇒ itype_ok tds db it) ∧
pure_unify s t1 t2 = SOME sub ∧
it ∈ FRANGE sub
⇒ itype_ok tds db it) ∧
(∀s ts1 ts2. pure_wfs s ⇒
∀sub it.
EVERY (itype_ok tds db) ts1 ∧ EVERY (itype_ok tds db) ts2 ∧
(∀it. it ∈ FRANGE s ⇒ itype_ok tds db it) ∧
pure_unifyl s ts1 ts2 = SOME sub ∧
it ∈ FRANGE sub
⇒ itype_ok tds db it)
Proof
ho_match_mp_tac pure_unify_strongind >>
conj_tac >> rpt gen_tac >> strip_tac >> rpt gen_tac >> strip_tac
>- (
qpat_x_assum `pure_unify _ _ _ = _` mp_tac >>
DEP_ONCE_REWRITE_TAC[pure_unify] >> conj_tac >- simp[] >>
Cases_on `pure_walk s t1` >> fs[] >>
Cases_on `pure_walk s t2` >> fs[] >>
simp[pure_ext_s_check] >> rw[] >>
imp_res_tac pure_walk_itype_ok >>
gvs[IN_FRANGE_FLOOKUP, PULL_EXISTS, FLOOKUP_UPDATE] >>
every_case_tac >> gvs[] >> res_tac >> gvs[itype_ok, SF ETA_ss]
)
>- (
qpat_x_assum `pure_unifyl _ _ _ = _` mp_tac >>
Cases_on `ts1` >> Cases_on `ts2` >>
once_rewrite_tac[pure_unifyl_def] >> strip_tac >> fs[] >>
FULL_CASE_TAC >> fs[]
)
QED
Theorem pure_unify_itype_ok:
∀s t1 t2 sub tds db.
pure_wfs s ∧ (∀it. it ∈ FRANGE s ⇒ itype_ok tds db it) ∧
itype_ok tds db t1 ∧ itype_ok tds db t2 ∧
pure_unify s t1 t2 = SOME sub
⇒ (∀it. it ∈ FRANGE sub ⇒ itype_ok tds db it)
Proof
rw[] >> irule $ cj 1 pure_unify_itype_ok_lemma >> rpt $ goal_assum drule
QED
(********** isubst/ishift **********)
Theorem ishift_0[simp]:
∀it. ishift 0 = (λx. x)
Proof
simp[FUN_EQ_THM] >> recInduct itype_ind >> rw[ishift_def] >> gvs[MAP_ID_ON]
QED
Theorem isubst_NIL[simp]:
∀it. isubst [] it = it
Proof
recInduct itype_ind >> rw[isubst_def] >> simp[MAP_ID_ON]
QED
Theorem isubst_ishift_1:
∀it shift its m.
LENGTH its ≤ shift ⇒
isubst its (ishift shift it) = ishift (shift - LENGTH its) it
Proof
recInduct itype_ind >> rw[isubst_def, ishift_def] >>
simp[MAP_MAP_o, combinTheory.o_DEF, MAP_EQ_f]
QED
Theorem isubst_ishift_2:
∀it shift its m.
shift ≤ LENGTH its ⇒
isubst its (ishift shift it) = isubst (DROP shift its) it
Proof
recInduct itype_ind >> rw[isubst_def, ishift_def] >>
gvs[MAP_MAP_o, combinTheory.o_DEF, MAP_EQ_f, EL_DROP]
QED
Theorem isubst_itype_of:
∀ts t. isubst (MAP itype_of ts) (itype_of t) = itype_of (subst_db 0 ts t)
Proof
qsuff_tac
`∀n:num ts t. isubst (MAP itype_of ts) (itype_of t) = itype_of (subst_db 0 ts t)`
>- rw[] >>
ho_match_mp_tac subst_db_ind >>
rw[subst_db_def, isubst_def, itype_of_def] >>
rw[EL_MAP, MAP_MAP_o, combinTheory.o_DEF, MAP_EQ_f]
QED
Theorem ishift_itype_of:
∀n t. ishift n (itype_of t) = itype_of (shift_db 0 n t)
Proof
gen_tac >> recInduct type_ind >> rw[ishift_def, shift_db_def, itype_of_def] >>
simp[MAP_MAP_o, combinTheory.o_DEF, MAP_EQ_f]
QED
Theorem isubst_unchanged:
∀its it. freedbvars it = ∅ ⇒ isubst its it = it
Proof
recInduct isubst_ind >> rw[isubst_def, freedbvars_def] >> gvs[] >>
rw[miscTheory.MAP_EQ_ID] >> first_x_assum irule >> simp[] >>
gvs[LIST_TO_SET_EQ_SING, EVERY_MAP, EVERY_MEM]
QED
Theorem ishift_unchanged:
∀shift it. freedbvars it = ∅ ⇒ ishift shift it = it
Proof
recInduct ishift_ind >> rw[ishift_def, freedbvars_def] >> gvs[] >>
rw[miscTheory.MAP_EQ_ID] >> first_x_assum irule >> simp[] >>
gvs[LIST_TO_SET_EQ_SING, EVERY_MAP, EVERY_MEM]
QED
Theorem ishift_ishift:
∀t n m. ishift n (ishift m t) = ishift (n + m) t
Proof
Induct using itype_ind >> rw[ishift_def] >>
simp[MAP_MAP_o, combinTheory.o_DEF, MAP_EQ_f]
QED
Theorem ishift_ishift_comm:
∀t n m. ishift n (ishift m t) = ishift m (ishift n t)
Proof
simp[ishift_ishift]
QED
(********** pure_apply_subst **********)
Theorem pure_apply_subst_unchanged:
∀it sub.
DISJOINT (pure_vars it) (FDOM sub)
⇒ pure_apply_subst sub it = it
Proof
recInduct itype_ind >> reverse $ rw[pure_apply_subst, pure_vars, FLOOKUP_DEF] >>
gvs[MEM_MAP, PULL_EXISTS] >> irule MAP_ID_ON >> rw[] >> gvs[]
QED
Theorem pure_apply_subst_same:
∀sub sub' it.
(∀n. n ∈ pure_vars it ⇒ FLOOKUP sub n = FLOOKUP sub' n)
⇒ pure_apply_subst sub it = pure_apply_subst sub' it
Proof
ntac 2 gen_tac >> recInduct itype_ind >> rw[pure_vars, pure_apply_subst] >>
gvs[MAP_EQ_f, PULL_EXISTS, MEM_MAP] >> rw[] >> metis_tac[]
QED
Theorem pure_apply_subst_min:
∀sub it.
pure_apply_subst sub it = pure_apply_subst (DRESTRICT sub (pure_vars it)) it
Proof
rw[] >> irule pure_apply_subst_same >> simp[FLOOKUP_DRESTRICT]
QED
Theorem pure_apply_subst_iFunctions:
∀s ts t. pure_apply_subst s (iFunctions ts t) =
iFunctions (MAP (pure_apply_subst s) ts) (pure_apply_subst s t)
Proof
gen_tac >> Induct >> rw[iFunctions_def, pure_apply_subst]
QED
Theorem pure_apply_subst_FUNION:
∀it m1 m2.
(∀v. v ∈ FRANGE m2 ⇒ pure_vars v = {})
⇒ pure_apply_subst m1 (pure_apply_subst m2 it) =
pure_apply_subst (m2 ⊌ m1) it
Proof
recInduct itype_ind >> rw[pure_apply_subst] >>
simp[MAP_MAP_o, combinTheory.o_DEF, MAP_EQ_f] >>
simp[FLOOKUP_FUNION] >> CASE_TAC >> simp[pure_apply_subst] >>
irule pure_apply_subst_unchanged >>
gvs[IN_FRANGE_FLOOKUP, PULL_EXISTS] >> first_x_assum drule >> simp[]
QED
Theorem pure_apply_subst_FUNION_strong:
∀it m1 m2.
pure_apply_subst m1 (pure_apply_subst m2 it) =
pure_apply_subst (pure_apply_subst m1 o_f m2 ⊌ m1) it
Proof
recInduct itype_ind >> rw[pure_apply_subst] >>
simp[MAP_MAP_o, combinTheory.o_DEF, MAP_EQ_f] >>
simp[FLOOKUP_FUNION, FLOOKUP_o_f] >> CASE_TAC >> simp[pure_apply_subst]
QED
Theorem pure_apply_subst_isubst:
∀sub it its.
(∀it. it ∈ FRANGE sub ⇒ freedbvars it = {}) ⇒
pure_apply_subst sub (isubst its it) =
isubst (MAP (pure_apply_subst sub) its) (pure_apply_subst sub it)
Proof
gen_tac >> recInduct itype_ind >> rw[pure_apply_subst, isubst_def] >>
simp[EL_MAP, MAP_MAP_o, combinTheory.o_DEF, MAP_EQ_f] >>
CASE_TAC >> simp[isubst_def] >>
irule $ GSYM isubst_unchanged >> first_x_assum $ irule o GSYM >>
simp[IN_FRANGE_FLOOKUP] >> goal_assum drule >> simp[]
QED
Theorem pure_apply_subst_isubst_itype_of:
∀t sub its.
pure_apply_subst sub (isubst its (itype_of t)) =
isubst (MAP (pure_apply_subst sub) its) (itype_of t)
Proof
recInduct type_ind >>
rw[itype_of_def, isubst_def, pure_apply_subst, EL_MAP] >>
gvs[MAP_MAP_o, combinTheory.o_DEF, MAP_EQ_f]
QED
Theorem isubst_pure_apply_subst:
∀sub its it. (∀it. MEM it its ⇒ pure_vars it = {}) ⇒
isubst its (pure_apply_subst sub it) =
pure_apply_subst ((isubst its) o_f sub) (isubst its it)
Proof
ntac 2 gen_tac >> recInduct itype_ind >>
reverse $ rw[pure_apply_subst, isubst_def] >>
simp[MAP_MAP_o, combinTheory.o_DEF, MAP_EQ_f, FLOOKUP_o_f]
>- (CASE_TAC >> simp[isubst_def]) >>
gvs[pure_vars_empty_eq_type_of, MEM_EL, PULL_EXISTS] >>
first_x_assum drule >> strip_tac >>
drule type_of_SOME >> disch_then $ assume_tac o GSYM >> gvs[]
QED
Theorem isubst_pure_apply_subst_alt:
∀t s subs. freedbvars t = {} ⇒
isubst subs (pure_apply_subst s t) = pure_apply_subst (isubst subs o_f s) t
Proof
Induct using itype_ind >>
rw[freedbvars_def, pure_apply_subst, isubst_def] >>
simp[MAP_MAP_o, combinTheory.o_DEF, MAP_EQ_f] >>
gvs[LIST_TO_SET_MAP, IMAGE_EQ_SING] >>
simp[FLOOKUP_o_f] >> CASE_TAC >> gvs[isubst_def]
QED
Theorem pure_apply_subst_FEMPTY[simp]:
∀t. pure_apply_subst FEMPTY t = t
Proof
Induct using itype_ind >> rw[pure_apply_subst] >> gvs[MAP_ID_ON]
QED
Theorem pure_apply_subst_FUNION_alt:
∀it m1 m2. (∀v. v ∈ FRANGE m2 ⇒ DISJOINT (pure_vars v) (FDOM m1)) ⇒
pure_apply_subst m1 (pure_apply_subst m2 it) = pure_apply_subst (FUNION m2 m1) it
Proof
Induct using itype_ind >> rw[pure_apply_subst] >>
simp[MAP_MAP_o, combinTheory.o_DEF, MAP_EQ_f] >>
simp[FLOOKUP_FUNION] >> CASE_TAC >> simp[pure_apply_subst] >>
irule pure_apply_subst_unchanged >>
first_x_assum irule >> simp[IN_FRANGE_FLOOKUP] >> goal_assum drule
QED
Theorem pure_apply_subst_idempotent:
∀it m. (∀v. v ∈ FRANGE m ⇒ DISJOINT (pure_vars v) (FDOM m)) ⇒
pure_apply_subst m (pure_apply_subst m it) = pure_apply_subst m it
Proof
rw[pure_apply_subst_FUNION_alt]
QED
Theorem pure_vars_pure_apply_subst:
∀t s.
pure_vars (pure_apply_subst s t) =
BIGUNION $ IMAGE (pure_vars o pure_apply_subst s o CVar) (pure_vars t)
Proof
Induct using itype_ind >> rw[pure_apply_subst, pure_vars] >>
simp[LIST_TO_SET_MAP, IMAGE_IMAGE] >> simp[Once EXTENSION, PULL_EXISTS] >>
rw[] >> eq_tac >> rw[] >>
first_x_assum drule >> rw[] >> gvs[] >>
goal_assum $ drule_at $ Pos last >> gvs[PULL_EXISTS] >>
rpt $ goal_assum drule
QED
Theorem pure_apply_subst_isubst_strong:
∀it its sub.
pure_apply_subst sub (isubst its it) =
isubst (MAP (pure_apply_subst sub) its)
(pure_apply_subst (ishift (LENGTH its) o_f sub) it)
Proof
Induct using itype_ind >> rw[pure_apply_subst, isubst_def, ishift_def] >>
gvs[EL_MAP, MAP_MAP_o, combinTheory.o_DEF, MAP_EQ_f] >>
simp[FLOOKUP_o_f] >> CASE_TAC >> simp[isubst_def] >>
DEP_REWRITE_TAC[isubst_ishift_2] >> simp[] >>
simp[GSYM MAP_DROP, DROP_LENGTH_NIL]
QED
(********** pure_walkstar etc. **********)
Theorem pure_walkstar_iFunctions:
∀s ts t. pure_wfs s ⇒
pure_walkstar s (iFunctions ts t) =
iFunctions (MAP (pure_walkstar s) ts) (pure_walkstar s t)
Proof
simp[GSYM PULL_FORALL] >> gen_tac >> strip_tac >>
Induct >> rw[iFunctions_def, pure_walkstar_alt]
QED
Theorem pure_walkstar_itype_of[simp]:
∀t sub. pure_wfs sub ⇒
pure_walkstar sub (itype_of t) = itype_of t
Proof
recInduct type_ind >> rw[itype_of_def, pure_walkstar_alt] >>
gvs[MAP_MAP_o, combinTheory.o_DEF, MAP_EQ_f]
QED
Theorem pure_vwalk_isubst:
∀sub n its. pure_wfs sub ⇒
(∀it. it ∈ FRANGE sub ⇒ freedbvars it = {})
⇒ isubst its (pure_vwalk sub n) = pure_vwalk sub n
Proof
gen_tac >> simp[GSYM PULL_FORALL] >> ntac 2 strip_tac >>
qspec_then `sub` mp_tac pure_vwalk_ind >> simp[] >>
disch_then ho_match_mp_tac >> rw[] >>
DEP_ONCE_REWRITE_TAC[pure_vwalk] >> simp[] >>
CASE_TAC >> gvs[isubst_def] >>
CASE_TAC >> gvs[isubst_def] >>
gvs[IN_FRANGE_FLOOKUP, PULL_EXISTS] >>
first_x_assum drule >> gvs[freedbvars_def] >> rw[] >> gvs[] >>
rw[miscTheory.MAP_EQ_ID] >> gvs[LIST_TO_SET_EQ_SING, EVERY_MAP, EVERY_MEM] >>
metis_tac[isubst_unchanged]
QED
Theorem pure_walk_isubst:
∀its it sub.
pure_wfs sub ∧
(∀it. it ∈ FRANGE sub ⇒ freedbvars it = {})
⇒ pure_walk sub (isubst its it) =
case it of
| DBVar n => isubst (MAP (pure_walk sub) its) (DBVar n)
| _ => isubst its (pure_walk sub it)
Proof
rw[] >> CASE_TAC >> gvs[isubst_def]
>- (IF_CASES_TAC >> gvs[EL_MAP] >> simp[pure_walk]) >>
simp[pure_walk, MAP_MAP_o, combinTheory.o_DEF, isubst_def, pure_vwalk_isubst]
QED
Theorem pure_walkstar_isubst:
∀sub it its. pure_wfs sub ∧
(∀it. it ∈ FRANGE sub ⇒ freedbvars it = {}) ⇒
pure_walkstar sub (isubst its it) =
isubst (MAP (pure_walkstar sub) its) (pure_walkstar sub it)
Proof
gen_tac >> simp[GSYM PULL_FORALL] >> strip_tac >>
qspec_then `sub` mp_tac pure_walkstar_ind >> impl_tac >- simp[] >>
disch_then ho_match_mp_tac >> rw[] >>
Cases_on `it` >> gvs[pure_walk, isubst_def, pure_walkstar_alt] >>
gvs[MAP_MAP_o, combinTheory.o_DEF, MAP_EQ_f]
>- (simp[EL_MAP] >> IF_CASES_TAC >> gvs[pure_walkstar_alt]) >>
CASE_TAC >> gvs[isubst_def] >>
DEP_REWRITE_TAC[isubst_unchanged] >> once_rewrite_tac[GSYM SUBSET_EMPTY] >>
irule SUBSET_TRANS >> irule_at Any freedbvars_pure_walkstar_SUBSET >> simp[] >>
gvs[IMAGE_EQ_SING, IN_FRANGE_FLOOKUP, PULL_EXISTS] >>
first_x_assum drule >> simp[]
QED
Theorem pure_walkstar_to_pure_apply_subst:
∀w. pure_wfs w ⇒
∃s. pure_walkstar w = pure_apply_subst s ∧
FDOM s = FDOM w ∧
pure_apply_subst s o pure_apply_subst s = pure_apply_subst s
Proof
rw[] >> qexists_tac `FUN_FMAP (λn. pure_walkstar w (CVar n)) (FDOM w)` >> simp[] >>
reverse $ conj_asm1_tac
>- (
pop_assum $ assume_tac o GSYM >> gvs[] >>
simp[FUN_EQ_THM, pure_walkstar_idempotent]
) >>
simp[FUN_EQ_THM] >>
qspec_then `w` mp_tac pure_walkstar_alt_ind >> impl_tac >- simp[] >>
disch_then ho_match_mp_tac >> rw[pure_walkstar_alt, pure_apply_subst, MAP_EQ_f] >>
simp[FLOOKUP_FUN_FMAP] >> gvs[FLOOKUP_DEF] >>
IF_CASES_TAC >> gvs[]
QED
Theorem pure_walkstar_unchanged:
∀s. pure_wfs s ⇒
∀t. DISJOINT (FDOM s) (pure_vars t) ⇒
pure_walkstar s t = t
Proof
gen_tac >> strip_tac >>
qspec_then `s` mp_tac pure_walkstar_alt_ind >> simp[] >>
disch_then ho_match_mp_tac >> rw[pure_walkstar_alt] >>
gvs[pure_vars, MEM_MAP, PULL_EXISTS]
>- (irule MAP_ID_ON >> rw[])
>- (irule MAP_ID_ON >> rw[])
>- (first_x_assum irule >> once_rewrite_tac[DISJOINT_SYM] >> simp[])
>- (first_x_assum irule >> once_rewrite_tac[DISJOINT_SYM] >> simp[])
>- simp[FLOOKUP_DEF]
QED
Theorem pure_vars_pure_walkstar_alt:
∀sub it. pure_wfs sub ⇒
pure_vars (pure_walkstar sub it) =
BIGUNION $ IMAGE (pure_vars o pure_walkstar sub o CVar) (pure_vars it)
Proof
rw[Once EXTENSION, PULL_EXISTS] >> eq_tac >> rw[]
>- (
drule_all pure_vars_pure_walkstar >> rw[] >>
goal_assum drule >> simp[]
)
>- (
drule pure_vars_pure_walkstar_SUPERSET >>
disch_then $ qspec_then `it` mp_tac >>
rewrite_tac[SUBSET_DEF] >> disch_then irule >> simp[PULL_EXISTS] >>
drule pure_vars_pure_walkstar_SUBSET >>
disch_then $ qspec_then `CVar x'` mp_tac >>
simp[SUBSET_DEF, pure_vars, PULL_EXISTS] >>
disch_then drule >> rw[] >> simp[] >>
disj2_tac >> goal_assum drule >> simp[]
)
QED
Theorem pure_walkstar_pure_apply_subst:
DISJOINT (FDOM s) (pure_substvars w) ∧ pure_wfs w ⇒
pure_walkstar w (pure_apply_subst s t) =
pure_apply_subst (pure_walkstar w o_f s) (pure_walkstar w t)
Proof
Induct_on `t` using itype_ind >>
rw[pure_walkstar_alt, pure_apply_subst] >>
simp[MAP_MAP_o, combinTheory.o_DEF, MAP_EQ_f] >>
Cases_on `FLOOKUP w n` >> gvs[]
>- (simp[pure_apply_subst, FLOOKUP_o_f] >> CASE_TAC >> simp[pure_walkstar_alt]) >>
`FLOOKUP s n = NONE` by (
CCONTR_TAC >> gvs[FLOOKUP_DEF, DISJOINT_ALT, pure_substvars]) >>
simp[pure_walkstar_alt] >> irule $ GSYM pure_apply_subst_unchanged >> simp[] >>
simp[pure_vars_pure_walkstar_alt] >> rw[PULL_EXISTS, pure_vars, DISJOINT_ALT] >>
drule_all $ SRULE [SUBSET_DEF] pure_vars_pure_walkstar_SUBSET >>
simp[pure_vars, GSYM IMAGE_FRANGE, PULL_EXISTS] >> rw[] >>
gvs[IN_FRANGE_FLOOKUP, PULL_EXISTS, DISJOINT_ALT, pure_substvars, pure_rangevars] >>
metis_tac[]
QED
Theorem pure_walkstar_FUNION:
∀t s.
pure_wfs s ∧ pure_wfs t ∧
DISJOINT (FDOM t) (pure_substvars s)
⇒ pure_walkstar (FUNION t s) = pure_walkstar s o pure_walkstar t
Proof
rw[] >> drule_all pure_wfs_FUNION >> rw[] >> simp[FUN_EQ_THM] >>
qspec_then `FUNION t s` mp_tac pure_walkstar_alt_ind >> simp[] >>