-
Notifications
You must be signed in to change notification settings - Fork 4
/
pure_congruenceScript.sml
3010 lines (2885 loc) · 109 KB
/
pure_congruenceScript.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
(*
This file formalises Howe's method following the description of
Pitts 2011 chapter "Howe's method for higher-order languages".
*)
open HolKernel Parse boolLib bossLib term_tactic;
open fixedPointTheory arithmeticTheory listTheory stringTheory alistTheory
optionTheory pairTheory ltreeTheory llistTheory bagTheory
BasicProvers pred_setTheory relationTheory rich_listTheory finite_mapTheory
dep_rewrite;
open pure_expTheory pure_valueTheory pure_evalTheory pure_eval_lemmasTheory
pure_exp_lemmasTheory pure_limitTheory pure_exp_relTheory
pure_alpha_equivTheory pure_miscTheory;
val _ = temp_delsimps ["lift_disj_eq", "lift_imp_disj"]
val _ = new_theory "pure_congruence";
Definition Ref_def:
Ref R ⇔
∀vars e. e IN Exps vars ⇒ R vars e e
End
Definition Sym_def:
Sym R ⇔
∀vars e1 e2.
{e1; e2} SUBSET Exps vars ⇒
R vars e1 e2 ⇒ R vars e2 e1
End
Definition Tra_def:
Tra R ⇔
∀vars e1 e2 e3.
{e1; e2; e3} SUBSET Exps vars ⇒
R vars e1 e2 ∧ R vars e2 e3 ⇒ R vars e1 e3
End
Definition Com1_def:
Com1 R ⇔
∀vars x.
x IN vars ⇒
R vars (Var x) (Var x)
End
Definition Com2_def:
Com2 R ⇔
∀vars x e e'.
(* ~(x IN vars) ∧ *) {e; e'} SUBSET Exps (x INSERT vars) ⇒
R (x INSERT vars) e e' ⇒ R vars (Lam x e) (Lam x e')
End
Definition Com3_def:
Com3 R ⇔
∀vars e1 e1' e2 e2'.
{e1; e1'; e2; e2'} SUBSET Exps vars ⇒
R vars e1 e1' ∧ R vars e2 e2' ⇒ R vars (App e1 e2) (App e1' e2')
End
Definition Com4_def:
Com4 R ⇔
∀ vars es es' op.
set es ∪ set es' ⊆ Exps vars ⇒
LIST_REL (R vars) es es' ⇒ R vars (Prim op es) (Prim op es')
End
Definition Com5_def:
Com5 R ⇔
∀ vars ves ves' e e'.
{e; e'} ∪ set (MAP SND ves) ∪ set (MAP SND ves') ⊆
Exps (vars ∪ set (MAP FST ves)) ⇒
fmap_rel
(R (vars ∪ set (MAP FST ves))) (FEMPTY |++ ves) (FEMPTY |++ ves') ∧
R (vars ∪ set (MAP FST ves)) e e'
⇒ R vars (Letrec ves e) (Letrec ves' e')
End
Theorem Com_defs =
LIST_CONJ [Com1_def,Com2_def,Com3_def,Com4_def,Com5_def];
Definition Compatible_def:
Compatible R ⇔ Com1 R ∧ Com2 R ∧ Com3 R ∧ Com4 R ∧ Com5 R
End
Definition Precongruence_def:
Precongruence R ⇔ Tra R ∧ Compatible R
End
Definition Congruence_def:
Congruence R ⇔ Sym R ∧ Precongruence R
End
Theorem Ref_open_similarity:
∀b. Ref (open_similarity b)
Proof
fs[Ref_def, Exps_def]
\\ rw[open_similarity_def]
\\ irule reflexive_app_similarity'
\\ reverse (rw [bind_def])
\\ match_mp_tac IMP_closed_subst
\\ fs [FLOOKUP_DEF,FRANGE_DEF,PULL_EXISTS]
QED
Theorem Ref_open_bisimilarity:
∀b. Ref (open_bisimilarity b)
Proof
assume_tac Ref_open_similarity
\\ fs [Ref_def,open_bisimilarity_eq]
QED
Theorem Sym_open_bisimilarity:
∀b. Sym (open_bisimilarity b)
Proof
rw[Sym_def, open_bisimilarity_def]
\\ assume_tac symmetric_app_bisimilarity
\\ fs[symmetric_def]
QED
Theorem Tra_open_similarity:
∀b. Tra (open_similarity b)
Proof
rw[Tra_def]
\\ irule open_similarity_transitive
\\ goal_assum drule \\ fs[]
QED
Theorem Tra_open_bisimilarity:
∀b. Tra (open_bisimilarity b)
Proof
fs [Tra_def] \\ metis_tac [open_similarity_transitive,open_bisimilarity_eq]
QED
(* -- Howe's construction -- *)
Inductive Howe:
[Howe1:]
(∀vars x e2.
R vars (Var x) e2 ⇒
Howe R vars (Var x) e2)
[Howe2:]
(∀x e1 e1' e2 vars.
Howe R (x INSERT vars) e1 e1' ∧
R vars (Lam x e1') e2 ⇒
Howe R vars (Lam x e1) e2)
[Howe3:]
(∀e1 e1' e3 vars.
Howe R vars e1 e1' ∧
Howe R vars e2 e2' ∧
R vars (App e1' e2') e3 ⇒
Howe R vars (App e1 e2) e3)
[Howe4:]
(∀es es' e op vars.
LIST_REL (Howe R vars) es es' ∧
R vars (Prim op es') e ⇒
Howe R vars (Prim op es) e)
[Howe5:]
(∀ves ves' e e' e2.
Howe R (vars ∪ set (MAP FST ves)) e e' ∧
EVERY (λe. e ∈ Exps (vars ∪ set (MAP FST ves))) (MAP SND ves) ∧
fmap_rel
(Howe R (vars ∪ set (MAP FST ves))) (FEMPTY |++ ves) (FEMPTY |++ ves') ∧
R vars (Letrec ves' e') e2
⇒ Howe R vars (Letrec ves e) e2)
End
Theorem Howe_Ref: (* 5.5.1(i) *)
Ref R ⇒ Compatible (Howe R)
Proof
rw[Ref_def, Compatible_def]
>- (
rw[Com1_def] >>
irule Howe1 >>
first_x_assum irule >> fs[Exps_def]
)
>- (
rw[Com2_def] >>
irule Howe2 >> fs[] >>
goal_assum (drule_at Any) >>
first_x_assum irule >>
fs[Exps_def, LIST_TO_SET_FILTER, SUBSET_DEF] >>
metis_tac[]
)
>- (
rw[Com3_def] >>
irule Howe3 >>
rpt (goal_assum (drule_at Any)) >>
first_x_assum irule >> fs[Exps_def]
)
>- (
rw[Com4_def] >>
irule Howe4 >>
rpt (goal_assum (drule_at Any)) >>
first_x_assum irule >> fs[Exps_def] >>
gvs[SUBSET_DEF, MEM_FLAT, MEM_MAP] >> rw[] >>
first_x_assum irule >>
goal_assum drule >> fs[]
)
>- (
rw[Com5_def] >> imp_res_tac fmap_rel_fupdate_list_MAP_FST >> gvs[] >>
irule Howe5 >> gvs[] >>
conj_tac >- (simp[EVERY_MEM] >> gvs[SUBSET_DEF]) >>
rpt (goal_assum (drule_at Any)) >> fs[] >>
first_x_assum irule >> simp[Exps_simps] >>
gvs[SUBSET_DEF, EVERY_MEM]
)
QED
Definition term_rel_def:
term_rel R ⇔
(∀vars e1 e2. R vars e1 e2 ⇒ e1 ∈ Exps vars ∧ e2 ∈ Exps vars ∧
∀vars'. vars ⊆ vars' ⇒ R vars' e1 e2)
End
Theorem term_rel_open_similarity:
∀b. term_rel (open_similarity b)
Proof
fs [term_rel_def] >> rw[open_similarity_def,Exps_def] >> gvs[SUBSET_DEF]
QED
Theorem term_rel_Howe:
term_rel R ⇒ term_rel (Howe R)
Proof
fs[term_rel_def] >>
Induct_on `Howe` >> rw[]
>- metis_tac[]
>- metis_tac[]
>- (irule Howe1 >> metis_tac[])
>- (last_x_assum drule >> gvs[Exps_simps])
>- metis_tac[]
>- (
irule Howe2 >> qexists_tac `e2` >>
rw[] >- metis_tac[] >>
last_x_assum drule >>
strip_tac >>
pop_assum irule >> fs[SUBSET_DEF]
)
>- (
last_x_assum drule >>
last_x_assum drule >>
simp[Exps_simps]
)
>- metis_tac[]
>- (
irule Howe3 >> qexists_tac `e2'` >> qexists_tac `e2` >>
rw[] >- metis_tac[] >>
last_x_assum drule >>
last_x_assum drule >>
strip_tac >> strip_tac >>
first_x_assum irule >> fs[SUBSET_DEF]
)
>- (
simp[Exps_simps, EVERY_EL] >> rw[] >>
fs[LIST_REL_EL_EQN] >>
last_x_assum drule >> strip_tac >>
pop_assum drule >> simp[]
)
>- metis_tac[]
>- (
irule Howe4 >> qexists_tac `es'` >>
rw[] >- metis_tac[] >>
gvs[LIST_REL_EL_EQN] >> rw[] >>
last_x_assum drule >> strip_tac >>
pop_assum drule >> strip_tac >>
pop_assum irule >> fs[SUBSET_DEF]
)
>- (
simp[Exps_simps] >>
last_x_assum drule >> simp[]
)
>- metis_tac[]
>- (
irule Howe5 >>
conj_tac
>- (
gvs[EVERY_MEM] >> rw[] >>
irule Exps_SUBSET >>
qexists_tac `vars ∪ set (MAP FST ves)` >> simp[] >>
gvs[SUBSET_DEF]
) >>
qexistsl_tac [`e2`,`ves'`] >>
first_assum drule >> strip_tac >> pop_assum drule >> strip_tac >> simp[] >>
conj_tac
>- (
gvs[fmap_rel_def] >> rw[] >>
res_tac >>
first_x_assum irule >> simp[] >>
gvs[SUBSET_DEF]
)
>- (
last_x_assum drule >> strip_tac >> pop_assum irule >>
gvs[SUBSET_DEF]
)
)
QED
Theorem open_similarity_min_freevars:
∀e1 e2 vars b.
open_similarity b vars e1 e2
⇒ open_similarity b (freevars e1 ∪ freevars e2) e1 e2
Proof
rw[open_similarity_def]
QED
Theorem open_similarity_alt_def:
∀vars e1 e2 b.
open_similarity b vars e1 e2 ⇔
freevars e1 ∪ freevars e2 ⊆ vars ∧
∀f. freevars e1 ∪ freevars e2 = FDOM f ⇒ (bind f e1 ≲ bind f e2) b
Proof
rw[] >> eq_tac >> rw[] >> gvs[open_similarity_def] >> rw[]
>- (first_x_assum irule >> gvs[SUBSET_DEF, EXTENSION] >> metis_tac[]) >>
first_x_assum (qspec_then `DRESTRICT f (freevars e1 ∪ freevars e2)` mp_tac) >>
simp[FDOM_DRESTRICT] >> impl_tac
>- (gvs[EXTENSION, SUBSET_DEF] >> metis_tac[]) >>
gvs[bind_def, FLOOKUP_DRESTRICT] >>
reverse (rw[]) >> gvs[] >- res_tac >- res_tac >>
qmatch_asmsub_abbrev_tac `subst f' _` >>
qsuff_tac `subst f e1 = subst f' e1 ∧ subst f e2 = subst f' e2` >> simp[] >>
once_rewrite_tac[subst_FDIFF] >> unabbrev_all_tac >>
gvs[INTER_UNION]
QED
Theorem Howe_Tra: (* 5.5.1(ii) *)
Tra R ∧ term_rel R ⇒
∀vars e1 e2 e3.
e1 ∈ Exps vars ∧ e2 ∈ Exps vars ∧ e3 ∈ Exps vars ∧
Howe R vars e1 e2 ∧ R vars e2 e3 ⇒ Howe R vars e1 e3
Proof
rw[Tra_def] >>
qpat_x_assum `Howe _ _ _ _` mp_tac >>
simp[Once Howe_cases] >> rw[]
>- (
irule Howe1 >>
first_x_assum irule >> fs[Exps_def] >>
qexists_tac `e2` >> fs[]
)
>- (
irule Howe2 >> fs[] >>
goal_assum (drule_at Any) >>
first_x_assum irule >>
fs[term_rel_def] >> res_tac >> fs[] >>
qexists_tac `e2` >> fs[]
)
>- (
irule Howe3 >>
rpt (goal_assum (drule_at Any)) >>
first_x_assum irule >> fs[] >> rw[]
>- (imp_res_tac term_rel_def >> fs[Exps_def]) >>
qexists_tac `e2` >> fs[]
)
>- (
irule Howe4 >>
rpt (goal_assum (drule_at Any)) >>
first_x_assum irule >> fs[] >> rw[]
>- (imp_res_tac term_rel_def >> fs[Exps_def]) >>
qexists_tac `e2` >> fs[]
)
>- (
irule Howe5 >> gvs[] >>
rpt (goal_assum (drule_at Any)) >> gvs[] >>
first_x_assum irule >> gvs[] >> rw[]
>- (imp_res_tac term_rel_def >> fs[Exps_def]) >>
qexists_tac `e2` >> fs[]
)
QED
Theorem Howe_Ref_Tra: (* 5.5.1(iii) *)
Ref R ∧ term_rel R ⇒
∀vars e1 e2. R vars e1 e2 ⇒ Howe R vars e1 e2
Proof
strip_tac
\\ imp_res_tac Howe_Ref
\\ simp [Once SWAP_FORALL_THM]
\\ ho_match_mp_tac freevars_ind \\ rw []
THEN1 (simp [Once Howe_cases])
THEN1 (
simp [Once Howe_cases]
\\ goal_assum (first_assum o mp_then Any mp_tac)
\\ fs [term_rel_def] \\ last_x_assum drule
\\ pop_assum kall_tac
\\ strip_tac
\\ ‘∀e. MEM e es ⇒ e IN Exps vars’ by
(fs [Exps_def,SUBSET_DEF,MEM_MAP,PULL_EXISTS]
\\ rw [] \\ res_tac \\ fs [])
\\ rw[LIST_REL_EL_EQN]
\\ first_x_assum irule
\\ gvs[Ref_def, MEM_EL]
\\ metis_tac[])
THEN1 (
simp [Once Howe_cases]
\\ goal_assum (first_assum o mp_then Any mp_tac)
\\ fs [term_rel_def] \\ last_x_assum drule
\\ strip_tac \\ fs [] \\ rw []
\\ first_x_assum match_mp_tac
\\ fs [Ref_def] \\ first_assum (match_mp_tac o MP_CANON) \\ fs []
\\ fs [Exps_def,SUBSET_DEF]
)
THEN1
(simp [Once Howe_cases]
\\ goal_assum (first_assum o mp_then Any mp_tac)
\\ fs [term_rel_def] \\ last_x_assum drule
\\ strip_tac \\ fs [] \\ rw []
\\ first_x_assum match_mp_tac
\\ fs [Ref_def] \\ first_assum (match_mp_tac o MP_CANON) \\ fs []
\\ fs [Exps_def,SUBSET_DEF] \\ metis_tac [])
\\ simp [Once Howe_cases]
\\ goal_assum (first_assum o mp_then Any mp_tac)
\\ fs [term_rel_def] \\ last_x_assum drule
\\ strip_tac \\ fs [] \\ rw []
THEN1
(first_x_assum match_mp_tac
\\ fs [Ref_def] \\ first_assum (match_mp_tac o MP_CANON) \\ fs []
\\ fs [Exps_def,SUBSET_DEF] \\ metis_tac [])
THEN1 (fs[Exps_simps])
\\ ‘∀fn e1. MEM (fn,e1) lcs ⇒ e1 IN Exps (vars UNION set (MAP FST lcs))’ by
(fs [Exps_def,SUBSET_DEF,FORALL_PROD,EXISTS_PROD,MEM_MAP,PULL_EXISTS]
\\ rw [] \\ Cases_on ‘∃p_2. MEM (x,p_2) lcs’
THEN1 metis_tac [] \\ disj1_tac
\\ last_x_assum match_mp_tac \\ fs [] \\ metis_tac [])
\\ irule fmap_rel_FUPDATE_LIST_same \\ simp[]
\\ rw[LIST_REL_EL_EQN]
\\ last_x_assum irule \\ simp[EL_MAP] \\ conj_tac
>- (
qexists_tac `FST (EL n lcs)` \\ simp[EL_MEM]
)
\\ gvs[Ref_def] \\ last_x_assum irule \\ first_x_assum irule
\\ qexists_tac `FST (EL n lcs)` \\ simp[EL_MEM]
QED
Definition Sub_def: (* Sub = substitutive *)
Sub R ⇔
∀vars x e1 e1' e2 e2'.
(* x ∉ vars ∧ *)
{e1; e1'} ⊆ Exps (x INSERT vars) ∧ {e2; e2'} ⊆ Exps {} ⇒
R (x INSERT vars) e1 e1' ∧ R {} e2 e2' ⇒
R vars (subst1 x e2 e1) (subst1 x e2' e1')
(* This definition has been tweaked to only insert closed expressions e2, e2' *)
End
Definition Cus_def: (* closed under value-substitution *)
Cus R ⇔
∀vars x e1 e1' e2.
(* x ∉ vars ∧ *)
{e1; e1'} SUBSET Exps (x INSERT vars) ∧ e2 IN Exps {} ⇒
R (x INSERT vars) e1 e1' ⇒
R vars (subst1 x e2 e1) (subst1 x e2 e1')
(* This definition has been tweaked to only insert closed expressions e2 *)
End
Theorem Sub_Ref_IMP_Cus:
Sub R ∧ Ref R ⇒ Cus R
Proof
rw[Sub_def, Ref_def, Cus_def]
\\ fs [AND_IMP_INTRO]
\\ first_x_assum match_mp_tac \\ fs []
\\ first_x_assum match_mp_tac
\\ fs [Exps_def,closed_def]
QED
Theorem Cus_open_similarity:
∀b. Cus (open_similarity b)
Proof
fs [Cus_def] \\ rw []
\\ fs [open_similarity_def]
\\ fs [SUBSET_DEF,freevars_subst]
\\ conj_tac THEN1 (metis_tac [])
\\ rw [bind_def]
\\ ‘(∀v. v ∈ FRANGE (FEMPTY |+ (x,e2)) ⇒ closed v)’ by fs [FRANGE_DEF]
\\ drule subst_subst_FUNION \\ fs []
\\ disch_then kall_tac
\\ first_x_assum (qspec_then ‘FEMPTY |+ (x,e2) ⊌ f’ mp_tac)
\\ impl_tac THEN1 (fs [FUNION_DEF] \\ metis_tac [])
\\ simp [bind_def] \\ IF_CASES_TAC \\ fs []
\\ gvs [FLOOKUP_DEF,FUNION_DEF] \\ metis_tac []
QED
Theorem Cus_open_bisimilarity:
∀b. Cus (open_bisimilarity b)
Proof
assume_tac Cus_open_similarity
\\ fs [Cus_def,open_bisimilarity_eq]
QED
Theorem IMP_Howe_Sub: (* 5.5.3 *)
Ref R ∧ Tra R ∧ Cus R ∧ term_rel R ⇒ Sub (Howe R)
Proof
fs [Sub_def,PULL_FORALL] >>
qsuff_tac ‘
∀x_vars e1 e1'.
Howe R x_vars e1 e1' ⇒
∀vars x e2 e2'. x_vars = x INSERT vars ∧
Ref R ∧ Tra R ∧ Cus R ∧ term_rel R ∧
(e1 ∈ Exps (x INSERT vars) ∧ e1' ∈ Exps (x INSERT vars)) ∧
closed e2 ∧ closed e2' ∧ Howe R {} e2 e2' ⇒
Howe R vars (subst1 x e2 e1) (subst1 x e2' e1')’
>- fs [PULL_FORALL] >>
ho_match_mp_tac Howe_strongind >> rw[] >> fs[]
>- (
gvs[subst1_def] >> reverse (rw[])
>- (
irule Howe1 >>
gvs[Cus_def] >>
first_x_assum (drule_at (Pos last)) >>
simp[subst1_def]
) >>
irule Howe_Tra >> simp[PULL_EXISTS] >>
qexists_tac ‘e2'’ >>
gvs[Exps_def, freevars_subst1, closed_def] >> rw[SUBSET_DEF]
>- (gvs[IN_DEF, SUBSET_DEF] >> metis_tac[])
>- (
gvs[Cus_def] >>
first_x_assum (drule_at (Pos last)) >>
simp[subst1_def] >> disch_then irule >>
simp[closed_def, Exps_def]
)
>- (
imp_res_tac term_rel_Howe >>
gvs[term_rel_def] >> res_tac >>
first_x_assum irule >> fs[]
)
)
>- (
fs[subst1_def] >> rw[]
>- (
irule Howe2 >> fs[] >>
goal_assum (drule_at Any) >>
gvs[Cus_def] >>
first_x_assum (drule_at (Pos last)) >>
simp[subst1_def] >>
disch_then irule >> simp[] >>
drule term_rel_Howe >> simp[term_rel_def] >> disch_then imp_res_tac >>
gvs[Exps_def, SUBSET_INSERT_DELETE]
) >>
irule Howe2 >>
qexists_tac `subst1 x' e2' e1'` >>
conj_tac
>- (
gvs[Cus_def] >>
first_x_assum (drule_at (Pos last)) >> simp[subst1_def] >>
disch_then irule >> gvs[] >>
gvs[term_rel_def] >> res_tac
) >>
first_x_assum irule >> gvs[INSERT_COMM] >>
drule term_rel_Howe >> simp[term_rel_def] >> disch_then imp_res_tac >>
gvs[SUBSET_INSERT_DELETE]
)
>- (
gvs[subst1_def] >>
rename1 `Howe _ _ (App (subst1 x e ea) (subst1 x e eb)) (subst1 x e' ec)` >>
rename1 `R (_ INSERT _) (App ed ef) _` >>
irule Howe3 >>
qexists_tac `subst1 x e' ed` >> qexists_tac `subst1 x e' ef` >>
gvs[term_rel_def] >> first_x_assum drule >>
rw[] >- (gvs[Cus_def] >> simp[GSYM subst1_def]) >>
first_x_assum irule >> gvs[Exps_def]
)
>- (
gvs[subst1_def] >>
irule Howe4 >> qexists_tac `MAP (λe. subst1 x e2' e) es'` >>
gvs[term_rel_def] >> first_x_assum drule >> rw[]
>- (gvs[Cus_def] >> simp[GSYM subst1_def]) >>
gvs[LIST_REL_EL_EQN] >> rw[] >>
simp[EL_MAP] >>
last_x_assum drule >> strip_tac >>
pop_assum irule >> gvs[Exps_def] >>
gvs[SUBSET_DEF, PULL_EXISTS, MEM_MAP] >> rw[]
>- (last_x_assum irule >> qexists_tac `EL n es` >> gvs[EL_MEM])
>- (first_x_assum irule >> qexists_tac `EL n es'` >> gvs[EL_MEM])
)
>- (
gvs[subst1_def] >> rw[]
>- (
gvs[INSERT_UNION] >>
irule Howe5 >> simp[] >>
goal_assum (drule_at Any) >> qexists_tac `ves'` >>
imp_res_tac fmap_rel_fupdate_list_MAP_FST >>
gvs[fmap_rel_def, Cus_def] >>
first_x_assum (drule_at (Pos last)) >>
simp[subst1_def] >> disch_then irule >>
drule term_rel_Howe >> gvs[term_rel_def] >> disch_then imp_res_tac >>
gvs[Exps_simps, INSERT_UNION] >>
first_x_assum drule >> simp[Exps_simps, INSERT_UNION]
) >>
irule Howe5 >>
conj_tac
>- (
gvs[MAP_MAP_o, combinTheory.o_DEF, UNCURRY] >>
CONV_TAC (DEPTH_CONV ETA_CONV) >> fs[] >>
gvs[EVERY_EL, EL_MAP] >> rw[] >> last_x_assum drule >> simp[Exps_def] >>
imp_res_tac freevars_subst1 >> simp[] >>
simp[INSERT_UNION, GSYM SUBSET_INSERT_DELETE]
) >>
qexists_tac `subst1 x e2' e1'` >>
qexists_tac `MAP (λ(g,z). (g, subst1 x e2' z)) ves'` >>
gvs[MAP_MAP_o, combinTheory.o_DEF, UNCURRY] >>
CONV_TAC (DEPTH_CONV ETA_CONV) >> fs[] >>
imp_res_tac fmap_rel_fupdate_list_MAP_FST >> gvs[] >>
imp_res_tac term_rel_def >> rw[]
>- (
gvs[Cus_def] >>
first_x_assum (drule_at (Pos last)) >>
simp[subst1_def]
)
>- (
gvs[fmap_rel_OPTREL_FLOOKUP, flookup_fupdate_list, GSYM MAP_REVERSE] >>
simp[ALOOKUP_MAP_2] >> rw[] >>
first_x_assum (qspec_then `k` assume_tac) >>
Cases_on `ALOOKUP (REVERSE ves) k` >>
Cases_on `ALOOKUP (REVERSE ves') k` >> gvs[OPTREL_THM] >>
first_x_assum irule >> simp[INSERT_UNION] >>
gvs[Exps_simps, EVERY_MEM, INSERT_UNION] >>
gvs[MEM_MAP, PULL_EXISTS] >>
imp_res_tac ALOOKUP_MEM >> gvs[MEM_REVERSE, FORALL_PROD] >>
metis_tac[]
)
>- (
last_x_assum irule >> gvs[INSERT_UNION_EQ] >>
drule term_rel_Howe >> simp[term_rel_def] >> disch_then imp_res_tac >>
simp[]
)
)
QED
Theorem Ref_Howe:
Ref R ⇒ Ref (Howe R)
Proof
strip_tac
\\ gvs[Ref_def,PULL_FORALL]
\\ CONV_TAC SWAP_FORALL_CONV
\\ ho_match_mp_tac freevars_ind \\ rw []
THEN1 (rename [‘Var’] \\ rw[Once Howe_cases])
THEN1 (rename [‘Prim’] \\ rw[Once Howe_cases]
\\ qexists_tac ‘es’ \\ fs []
\\ Induct_on ‘es’ \\ fs [Exps_simps])
THEN1 (rename [‘App’] \\ rw[Once Howe_cases] \\ metis_tac[Exps_simps])
THEN1 (rename [‘Lam’] \\ rw[Once Howe_cases] \\ metis_tac[Exps_simps])
\\ rename [‘Letrec’] \\ rw[Once Howe_cases]
\\ qexists_tac ‘lcs’
\\ qexists_tac ‘e’ \\ fs [PULL_FORALL,AND_IMP_INTRO] \\ rw []
THEN1 (metis_tac[Exps_simps])
THEN1 (metis_tac[Exps_simps])
\\ irule fmap_rel_FUPDATE_LIST_same \\ simp[] \\ rw[LIST_REL_EL_EQN]
\\ first_x_assum irule \\ reverse conj_tac
>- (
qexists_tac `FST (EL n lcs)` >> simp[EL_MAP, EL_MEM]
)
\\ gvs[Exps_simps, EVERY_EL]
QED
Theorem Howe_shrink_vars_lemma:
∀vs.
FINITE vs ⇒
∀ R vars x e1 e2.
Ref R ∧ Tra R ∧ Cus R ∧ term_rel R ∧
Howe R (vs ∪ vars) e1 e2 ∧
(∀x. x ∈ vs ⇒ x ∉ freevars e1 ∧ x ∉ freevars e2)
⇒ Howe R vars e1 e2
Proof
pred_setLib.SET_INDUCT_TAC >> rw[] >>
first_x_assum irule >> simp[] >>
drule IMP_Howe_Sub >> rpt (disch_then drule) >>
simp[Sub_def] >>
disch_then (qspecl_then [`s ∪ vars`,`e`,`e1`,`e2`,`Fail`,`Fail`] mp_tac) >>
simp[] >> dep_rewrite.DEP_REWRITE_TAC[subst1_ignore] >> simp[] >>
disch_then irule >>
drule term_rel_Howe >> simp[term_rel_def] >> disch_then imp_res_tac >>
gvs[INSERT_UNION_EQ] >>
drule Ref_Howe >> rw[Ref_def] >>
last_x_assum irule >> gvs[GSYM INSERT_UNION_EQ]
QED
Theorem Howe_min_freevars:
∀R vars x e1 e2.
Ref R ∧ Tra R ∧ Cus R ∧ term_rel R ∧
Howe R vars e1 e2 ∧ FINITE vars
⇒ Howe R (freevars e1 ∪ freevars e2) e1 e2
Proof
rw[] >>
`∃ vars'.
vars = vars' ∪ (freevars e1 ∪ freevars e2) ∧
FINITE vars' ∧
DISJOINT vars' (freevars e1 ∪ freevars e2)` by (
drule term_rel_Howe >> simp[term_rel_def] >> disch_then imp_res_tac >>
gvs[Exps_def] >>
qexists_tac `vars DIFF freevars e1 DIFF freevars e2` >>
gvs[EXTENSION, SUBSET_DEF, DISJOINT_DEF] >> metis_tac[]) >>
gvs[] >>
drule Howe_shrink_vars_lemma >> rpt (disch_then drule) >> disch_then irule >>
gvs[DISJOINT_DEF, EXTENSION] >> metis_tac[]
QED
Theorem Sub_Howe_open_similarity:
∀b. Sub (Howe (open_similarity b))
Proof
metis_tac [Ref_Howe,Ref_open_similarity,IMP_Howe_Sub,
Cus_open_similarity,Tra_open_similarity,Ref_open_similarity,
term_rel_Howe, term_rel_open_similarity]
QED
Theorem Cus_Howe_open_similarity:
∀b. Cus (Howe (open_similarity b))
Proof
gen_tac
\\ match_mp_tac Sub_Ref_IMP_Cus
\\ rw [Sub_Howe_open_similarity]
\\ metis_tac[Ref_Howe, Ref_open_similarity]
QED
Theorem Howe_open_similarity_IMP_freevars:
Howe (open_similarity b) s x y ⇒ freevars x ⊆ s ∧ freevars y ⊆ s
Proof
rw [] \\ ‘term_rel (open_similarity b)’ by fs [term_rel_open_similarity]
\\ imp_res_tac term_rel_Howe
\\ fs [term_rel_def]
\\ res_tac \\ fs [] \\ rw []
\\ fs [Exps_def]
QED
Theorem Howe_open_similarity_IMP_closed:
Howe (open_similarity b) ∅ x y ⇒ closed x ∧ closed y
Proof
rw [] \\ imp_res_tac Howe_open_similarity_IMP_freevars
\\ fs [closed_def]
QED
Theorem LIST_REL_Howe_open_similarity_IMP_closed:
∀xs ys b.
LIST_REL (Howe (open_similarity b) ∅) xs ys ⇒
EVERY closed xs ∧ EVERY closed ys
Proof
Induct \\ fs [PULL_EXISTS] \\ rw [] \\ res_tac
\\ imp_res_tac Howe_open_similarity_IMP_closed
QED
Triviality perm_exp_IN_Exps:
freevars ce2 ⊆ {y} ⇒ perm_exp x y ce2 ∈ Exps {x}
Proof
fs [Exps_def]
\\ rewrite_tac [freevars_eqvt]
\\ fs [SUBSET_DEF,MEM_MAP,PULL_EXISTS,perm1_def,closed_def,
FILTER_EQ_NIL,EVERY_MEM]
\\ rw [] \\ res_tac \\ fs []
QED
Theorem exp_alpha_subst_lemma[local]:
closed (Lam y e5) ∧ closed e4 ⇒
exp_alpha (subst1 x e4 (perm_exp x y e5)) (subst1 y e4 e5)
Proof
rw [] \\ match_mp_tac exp_alpha_Trans
\\ qexists_tac ‘perm_exp x y (subst1 x e4 (perm_exp x y e5))’
\\ rw [] THEN1 (
match_mp_tac exp_alpha_perm_irrel
\\ fs [freevars_subst,freevars_eqvt,MEM_MAP,closed_def,FILTER_EQ_NIL,
EVERY_MEM,perm1_def, PULL_FORALL, SUBSET_DEF]
\\ CCONTR_TAC \\ gvs[])
\\ fs [subst1_eqvt,perm1_def]
\\ match_mp_tac exp_alpha_subst1_closed'
\\ fs [closed_perm]
\\ match_mp_tac exp_alpha_sym
\\ match_mp_tac exp_alpha_perm_irrel
\\ fs [closed_def]
QED
Theorem Sub_lift:
∀R. Sub R ⇒
∀f f' e1 e1' e2 e2' vars.
{e1; e1'} ⊆ Exps (FDOM f ∪ vars) ∧
R (FDOM f ∪ vars) e1 e1' ∧
FDOM f = FDOM f' ∧
(∀k. k ∈ FDOM f ⇒
f ' k ∈ Exps ∅ ∧ f' ' k ∈ Exps ∅ ∧
R {} (f ' k) (f' ' k))
⇒ R vars (subst f e1) (subst f' e1')
Proof
strip_tac >> strip_tac >>
Induct >> rw[]
>- (Cases_on `f'` >> gvs[]) >>
`∃g y'. f' = g |+ (x,y') ∧ x ∉ FDOM g ∧ R {} y y'` by (
qexists_tac `f' \\ x` >> qexists_tac `f' ' x` >> gvs[] >>
first_x_assum (qspec_then `x` assume_tac) >> gvs[] >>
irule (GSYM FUPDATE_ELIM)>> gvs[IN_DEF, EXTENSION] >> metis_tac[]) >>
gvs[] >>
once_rewrite_tac[FUPDATE_EQ_FUNION] >>
`∀v. v ∈ FRANGE (FEMPTY |+ (x,y)) ⇒ closed v` by (
gvs[] >> first_x_assum (qspec_then `x` assume_tac) >> gvs[]) >>
drule (GSYM subst_subst_FUNION) >> simp[] >> strip_tac >>
pop_assum kall_tac >>
drule_at Any subst_subst >>
disch_then (qspecl_then [`e1`,`f`] mp_tac) >> impl_tac
>- (
simp[DISJOINT_DEF, INTER_DEF, EXTENSION] >> rw[] >>
fs[IN_FRANGE] >>
first_x_assum (qspec_then `k` assume_tac) >> gvs[FAPPLY_FUPDATE_THM] >>
FULL_CASE_TAC >> gvs[]
) >>
disch_then (rw o single o GSYM) >> pop_assum kall_tac >>
`∀v. v ∈ FRANGE (FEMPTY |+ (x,y')) ⇒ closed v` by (
gvs[] >> first_x_assum (qspec_then `x` assume_tac) >> gvs[]) >>
drule (GSYM subst_subst_FUNION) >> simp[] >> strip_tac >>
pop_assum kall_tac >>
drule_at Any subst_subst >>
disch_then (qspecl_then [`e1'`,`g`] mp_tac) >> impl_tac
>- (
simp[DISJOINT_DEF, INTER_DEF, EXTENSION] >> rw[] >>
fs[IN_FRANGE] >>
first_x_assum (qspec_then `k` assume_tac) >> gvs[FAPPLY_FUPDATE_THM] >>
`k ∈ FDOM f` by (gvs[EXTENSION, INSERT_DEF] >> metis_tac[]) >> gvs[] >>
FULL_CASE_TAC >> gvs[]
) >>
disch_then (rw o single o GSYM) >> pop_assum kall_tac >>
gvs[Sub_def] >>
last_x_assum irule >> gvs[] >> rw[]
>- (first_x_assum (qspec_then `x` mp_tac) >> simp[])
>- (first_x_assum (qspec_then `x` mp_tac) >> simp[])
>- (
gvs[Exps_def] >>
`∀v. v ∈ FRANGE f ⇒ closed v` by (
rw[IN_FRANGE] >>
first_x_assum (qspec_then `k` assume_tac) >> gvs[FAPPLY_FUPDATE_THM] >>
FULL_CASE_TAC >> gvs[]) >>
drule freevars_subst >> rw[] >>
gvs[DIFF_DEF, SUBSET_DEF, INSERT_DEF, EXTENSION] >> rw[] >>
last_x_assum drule >> strip_tac >> gvs[] >>
qpat_x_assum `∀x. _ ⇔ _` (qspec_then `x'` assume_tac) >> gvs[]
)
>- (
gvs[Exps_def] >>
`∀v. v ∈ FRANGE g ⇒ closed v` by (
rw[IN_FRANGE] >>
first_x_assum (qspec_then `k` assume_tac) >> gvs[FAPPLY_FUPDATE_THM] >>
`k ∈ FDOM f` by (gvs[EXTENSION, INSERT_DEF] >> metis_tac[]) >> gvs[] >>
FULL_CASE_TAC >> gvs[]) >>
drule freevars_subst >> rw[] >>
gvs[DIFF_DEF, SUBSET_DEF, INSERT_DEF, EXTENSION] >> rw[] >>
last_x_assum drule >> strip_tac >> gvs[]
) >>
first_x_assum irule >> conj_tac
>- (
gen_tac >> strip_tac >>
first_x_assum (qspec_then `k` assume_tac) >> gvs[FAPPLY_FUPDATE_THM] >>
FULL_CASE_TAC >> gvs[] >>
first_x_assum drule >> disch_then (qspec_then `{x}` mp_tac) >>
once_rewrite_tac[UNION_COMM] >>
simp[GSYM INSERT_SING_UNION]
) >>
conj_asm1_tac
>- (gvs[INSERT_DEF, IN_DEF, EXTENSION] >> rw[] >> gvs[] >> metis_tac[])
>- (gvs[] >> metis_tac[UNION_COMM, UNION_ASSOC, INSERT_SING_UNION])
QED
Triviality closed_Letrec_funs:
∀ fs e f.
closed (Letrec fs e) ∧
MEM f fs
⇒ closed (Letrec fs (SND f))
Proof
rw[EVERY_MEM] >>
gvs[MEM_MAP, PULL_EXISTS]
QED
Theorem open_similarity_larger:
∀vars e1 e2 vars1 b.
open_similarity b vars e1 e2 ∧ vars SUBSET vars1 ⇒ open_similarity b vars1 e1 e2
Proof
fs [open_similarity_def]
\\ rw [] \\ imp_res_tac SUBSET_TRANS \\ fs []
QED
Theorem Howe_larger:
∀vars e2 e1 vars1 b.
Howe (open_similarity b) vars e1 e2 ∧ vars ⊆ vars1 ⇒
Howe (open_similarity b) vars1 e1 e2
Proof
rw[] >>
‘term_rel (open_similarity b)’ by fs [term_rel_open_similarity] >>
imp_res_tac term_rel_Howe >>
gvs[term_rel_def] >>
metis_tac[]
QED
Theorem LIST_REL_Howe_larger:
∀vs ws es ys b.
LIST_REL (Howe (open_similarity b) vs) es ys ∧ vs SUBSET ws ⇒
LIST_REL (Howe (open_similarity b) ws) es ys
Proof
rw [] \\ last_x_assum mp_tac
\\ match_mp_tac LIST_REL_mono \\ rw []
\\ match_mp_tac Howe_larger
\\ goal_assum (first_assum o mp_then Any mp_tac)
\\ fs [SUBSET_DEF]
QED
Theorem open_similarity_finite:
∀vars e1 e2 b.
open_similarity b vars e1 e2 ⇒ ∃vs. open_similarity b vs e1 e2 ∧ FINITE vs
Proof
fs [open_similarity_def] \\ rw []
\\ qexists_tac ‘freevars e1 UNION freevars e2’ \\ fs []
QED
Theorem Howe_finite_lemma[local]:
Howe R vars e1 e2 ⇒ R = open_similarity b ⇒
∃ws. Howe R ws e1 e2 ∧ FINITE ws
Proof
Induct_on ‘Howe’ \\ rw []
THEN1
(simp [Once Howe_cases]
\\ imp_res_tac open_similarity_finite
\\ qexists_tac ‘vs’ \\ fs [])
THEN1
(simp [Once Howe_cases,PULL_EXISTS]
\\ imp_res_tac open_similarity_finite
\\ qexists_tac ‘x INSERT (ws UNION vs)’ \\ fs []
\\ qexists_tac ‘e2’ \\ fs [] \\ rw []
THEN1
(match_mp_tac Howe_larger
\\ goal_assum (first_assum o mp_then Any mp_tac)
\\ fs [SUBSET_DEF])
\\ match_mp_tac open_similarity_larger
\\ goal_assum (first_assum o mp_then Any mp_tac)
\\ fs [SUBSET_DEF])
THEN1
(simp [Once Howe_cases,PULL_EXISTS]
\\ imp_res_tac open_similarity_finite
\\ qexists_tac ‘vs UNION ws UNION ws'’ \\ fs []
\\ qexists_tac ‘e2’ \\ fs [] \\ rw []
\\ qexists_tac ‘e2'’ \\ fs [] \\ rw []
\\ TRY (match_mp_tac Howe_larger)
\\ TRY (match_mp_tac open_similarity_larger)
\\ goal_assum (first_assum o mp_then Any mp_tac)
\\ fs [SUBSET_DEF])
THEN1
(simp [Once Howe_cases,PULL_EXISTS]
\\ imp_res_tac open_similarity_finite
\\ ‘∃ws1. LIST_REL (Howe (open_similarity b) ws1) es es' ∧ FINITE ws1 ∧ vs SUBSET ws1’ by
(qpat_x_assum ‘LIST_REL _ _ _’ mp_tac
\\ qid_spec_tac ‘es'’ \\ qid_spec_tac ‘es’
\\ Induct \\ fs []
THEN1 (goal_assum (first_assum o mp_then (Pos hd) mp_tac) \\ fs [])
\\ fs [PULL_EXISTS] \\ rw []
\\ first_x_assum drule \\ rw []
\\ qexists_tac ‘ws UNION ws1’ \\ fs [] \\ rw []
\\ TRY (match_mp_tac Howe_larger)
\\ TRY (match_mp_tac LIST_REL_Howe_larger)
\\ TRY (goal_assum (first_assum o mp_then Any mp_tac))
\\ fs [SUBSET_DEF])
\\ goal_assum (first_assum o mp_then (Pos hd) mp_tac) \\ fs []
\\ TRY (match_mp_tac open_similarity_larger)
\\ goal_assum (first_assum o mp_then Any mp_tac)
\\ fs [SUBSET_DEF])
\\ imp_res_tac open_similarity_finite
\\ imp_res_tac fmap_rel_fupdate_list_MAP_FST \\ gvs[]
\\ `fmap_rel (λe1 e2. ∃ws. Howe (open_similarity b) ws e1 e2 ∧ FINITE ws)
(FEMPTY |++ ves) (FEMPTY |++ ves')` by gvs[fmap_rel_def]
\\ `∃ws1. FINITE ws1 ∧
fmap_rel (Howe (open_similarity b) (ws1 ∪ set (MAP FST ves)))
(FEMPTY |++ ves) (FEMPTY |++ ves')` by (
rename1 `fmap_rel _ f1 f2` >>
pop_assum mp_tac >> qid_spec_tac `f2` >> qid_spec_tac `f1` >>
ho_match_mp_tac fmap_rel_ind >> rw[]
>- (qexists_tac `{}` >> simp[]) >>
simp[GSYM fmap_rel_FUPDATE_EQN] >>
rename1 `Howe _ ws2 _ _` >> qexists_tac `ws1 ∪ ws2` >> simp[] >>
irule_at Any Howe_larger >> goal_assum drule >> simp[SUBSET_DEF] >>
irule fmap_rel_mono >> goal_assum (drule_at Any) >> rw[] >>
irule Howe_larger >> goal_assum (drule_at Any) >> simp[SUBSET_DEF])
\\ `∃ws2. FINITE ws2 ∧
EVERY (λe. e ∈ Exps (ws2 ∪ set (MAP FST ves'))) (MAP SND ves)` by (
qpat_x_assum `EVERY _ _` mp_tac >> qid_spec_tac `ves` >>
Induct >> rw[] >- (qexists_tac `{}` >> simp[]) >> gvs[] >>
qexists_tac `freevars (SND h) ∪ ws2` >> gvs[Exps_def, SUBSET_DEF] >>
gvs[EVERY_MEM] >> rw[] >> metis_tac[])
\\ simp [Once Howe_cases,PULL_EXISTS]
\\ qexistsl_tac [`ws ∪ vs ∪ ws1 ∪ ws2 ∪ set (MAP FST ves)`,`ves'`,`e2`] >>
irule_at Any Howe_larger >> goal_assum drule >> simp[GSYM UNION_ASSOC] >>
irule_at Any open_similarity_larger >>
goal_assum drule >> simp[SUBSET_DEF] >>
irule_at Any fmap_rel_mono >> goal_assum (drule_at Any) >>
conj_tac
>- (
rw[] >> irule Howe_larger >> goal_assum (drule_at Any) >> simp[SUBSET_DEF]
) >>
gvs[EVERY_MEM] >> rw[] >> first_x_assum drule >> strip_tac >>
irule Exps_SUBSET >> goal_assum drule >> simp[SUBSET_DEF]
QED
Theorem Howe_finite = GEN_ALL Howe_finite_lemma |> SIMP_RULE std_ss [] |> MP_CANON;
Theorem Howe_open_similarity_min_freevars:
∀R vars x e1 e2 b.
Howe (open_similarity b) vars e1 e2
⇒ Howe (open_similarity b) (freevars e1 ∪ freevars e2) e1 e2
Proof
rw[] >>
drule Howe_finite >> strip_tac >>
irule Howe_min_freevars >>