-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlcaProofScript.sml
3441 lines (3359 loc) · 134 KB
/
lcaProofScript.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 preamble
open lcaTheory reflectionTheory reflectionLib
open holSyntaxTheory holSyntaxExtraTheory holSyntaxLib
open holSemanticsTheory holSemanticsExtraTheory
open lcaCtxtTheory
val _ = new_theory"lcaProof"
val _ = Globals.max_print_depth := 15
open holSyntaxLibTheory holBoolSyntaxTheory holBoolTheory setSpecTheory
val lca_ctxt = unpack_ctxt lca_ctxt_thm
val lca_inner_ctxt = lca_extends_init |> concl |> rator |> rand
val lca_ctxt_def = Define`
lca_ctxt = ^lca_inner_ctxt`
val theory_ok_lca = store_thm("theory_ok_lca",
``theory_ok (thyof lca_ctxt)``,
metis_tac[lca_extends_init |> REWRITE_RULE[GSYM lca_ctxt_def],
init_theory_ok,extends_theory_ok])
val FLOOKUP_LCA = (
``ALOOKUP (const_list lca_ctxt) (strlit"LCA")``
|> (PURE_ONCE_REWRITE_CONV[lca_ctxt_def] THENC EVAL))
val FLOOKUP_UNIV = (
``ALOOKUP (const_list lca_ctxt) (strlit"UNIV")``
|> (PURE_ONCE_REWRITE_CONV[lca_ctxt_def] THENC EVAL))
val FLOOKUP_cardleq = (
``ALOOKUP (const_list lca_ctxt) (strlit"cardleq")``
|> (PURE_ONCE_REWRITE_CONV[lca_ctxt_def] THENC EVAL))
val FLOOKUP_countable = (
``ALOOKUP (const_list lca_ctxt) (strlit"countable")``
|> (PURE_ONCE_REWRITE_CONV[lca_ctxt_def] THENC EVAL))
val FLOOKUP_INJ = (
``ALOOKUP (const_list lca_ctxt) (strlit"INJ")``
|> (PURE_ONCE_REWRITE_CONV[lca_ctxt_def] THENC EVAL))
val FLOOKUP_IN = (
``ALOOKUP (const_list lca_ctxt) (strlit"IN")``
|> (PURE_ONCE_REWRITE_CONV[lca_ctxt_def] THENC EVAL))
val FLOOKUP_SUBSET = (
``ALOOKUP (const_list lca_ctxt) (strlit"SUBSET")``
|> (PURE_ONCE_REWRITE_CONV[lca_ctxt_def] THENC EVAL))
val FLOOKUP_POW = (
``ALOOKUP (const_list lca_ctxt) (strlit"POW")``
|> (PURE_ONCE_REWRITE_CONV[lca_ctxt_def] THENC EVAL))
val FLOOKUP_LESS = (
``ALOOKUP (const_list lca_ctxt) (strlit"<")``
|> (PURE_ONCE_REWRITE_CONV[lca_ctxt_def] THENC EVAL))
val FLOOKUP_regular_cardinal = (
``ALOOKUP (const_list lca_ctxt) (strlit"regular_cardinal")``
|> (PURE_ONCE_REWRITE_CONV[lca_ctxt_def] THENC EVAL))
val FLOOKUP_strong_limit_cardinal = (
``ALOOKUP (const_list lca_ctxt) (strlit"strong_limit_cardinal")``
|> (PURE_ONCE_REWRITE_CONV[lca_ctxt_def] THENC EVAL))
val FLOOKUP_strongly_inaccessible = (
``ALOOKUP (const_list lca_ctxt) (strlit"strongly_inaccessible")``
|> (PURE_ONCE_REWRITE_CONV[lca_ctxt_def] THENC EVAL))
val lca_is_bool_sig = store_thm("lca_is_bool_sig",
``is_bool_sig (sigof lca_ctxt)``,
EVAL_TAC)
val _ = Parse.overload_on("Num", ``Tyapp(strlit"num")[]``)
val quote_def = Define`
(quote 0 = Const (strlit"0") Num) ∧
(quote (SUC n) = Comb (Const(strlit"SUC")(Fun Num Num))
(quote n))`
val type_ok_Num = store_thm("type_ok_Num",
``type_ok (tysof lca_ctxt) Num``,
rw[type_ok_def] >>
ONCE_REWRITE_TAC[lca_ctxt_def] >>
EVAL_TAC)
val LCA_l_UNIV = term_to_deep ``LCA l (UNIV:'U set)``
fun replace_term from to = Term.subst[from |-> to]
val EVAL_STRING_SORT = basicReflectionLib.EVAL_STRING_SORT
val (EVAL_type_ok0,EVAL_term_ok0) =
EVAL_type_ok_term_ok
EVAL (MATCH_MP theory_ok_sig theory_ok_lca |> SIMP_RULE std_ss[])
val th = prove(``tysof lca_ctxt = tysof(sigof lca_ctxt)``,rw[])
val EVAL_type_ok =
(RATOR_CONV(RAND_CONV(REWR_CONV th))) THENC EVAL_type_ok0
val EVAL_term_ok =
EVAL_term_ok0 THENC
SIMP_CONV (srw_ss()) [
holSyntaxLibTheory.tyvar_inst_exists,
reflectionTheory.tyvar_inst_exists2,
reflectionTheory.tyvar_inst_exists2_diff]
fun process n =
ONCE_REWRITE_TAC[relationTheory.RTC_CASES1] >> disj2_tac >>
CONV_TAC(QUANT_CONV(LAND_CONV(RATOR_CONV BETA_CONV THENC BETA_CONV))) >>
CONV_TAC(QUANT_CONV(LAND_CONV(QUANT_CONV(LAND_CONV(REWR_CONV listTheory.CONS_11))))) >>
CONV_TAC(QUANT_CONV(LAND_CONV((QUANT_CONV(REWR_CONV (GSYM CONJ_ASSOC)))THENC HO_REWR_CONV UNWIND_THM1))) >>
CONV_TAC((QUANT_CONV(REWR_CONV (GSYM CONJ_ASSOC))) THENC HO_REWR_CONV UNWIND_THM1) >>
conj_tac >- ACCEPT_TAC (#updates_thm (el n lca_ctxt))
val models_lca_ctxt_has_bool_interpretation = store_thm("models_lca_ctxt_has_bool_interpretation",
``is_set_theory ^mem ∧ i models thyof lca_ctxt ⇒ is_bool_interpretation i``,
rw[] >>
match_mp_tac (GEN_ALL extends_is_bool_interpretation) >>
qexists_tac`lca_ctxt` >>
qexists_tac`init_ctxt` >>
simp[] >>
conj_tac >- (
simp[extends_def] >>
ONCE_REWRITE_TAC[lca_ctxt_def] >>
map_every process (List.tabulate(18,curry op+1)) >>
simp[GSYM extends_def] >>
simp[holConsistencyTheory.hol_extends_bool] ) >>
metis_tac[extends_theory_ok,bool_extends_init,init_theory_ok])
fun EVAL_INST tm =
assert (same_const``INST`` o fst o strip_comb) tm |> (
REWR_CONV(MATCH_MP holDerivationTheory.inst_eval_thm
(EQT_ELIM(EVAL_welltyped ``welltyped^(rand tm)``))) THENC
EVAL_subst)
fun Abbrev_intro_tac th = assume_tac(EQ_MP(SPEC(concl th)(GSYM markerTheory.Abbrev_def))th)
val lca_of_sigof = prove(``tmsof (sigof lca_ctxt) = tmsof lca_ctxt``,rw[])
val quote_has_type = store_thm("quote_has_type",
``∀n. quote n has_type Num``,
Induct >> simp[quote_def] >>
simp[Once has_type_cases] >>
simp[Once has_type_cases])
val term_ok_quote = store_thm("term_ok_quote",
``∀n. term_ok (sigof lca_ctxt) (quote n)``,
Induct >> simp[quote_def] >-
(CONV_TAC EVAL_term_ok) >>
simp[Once term_ok_def] >>
conj_tac >- (CONV_TAC EVAL_term_ok) >>
metis_tac[quote_has_type,WELLTYPED_LEMMA,WELLTYPED])
val termsem_quote = store_thm("termsem_quote",
``is_set_theory ^mem ⇒
∀tmsig i v n.
FLOOKUP tmsig (strlit"0") = SOME Num ⇒
FLOOKUP tmsig (strlit"SUC") = SOME (Fun Num Num) ⇒
wf_to_inner ((to_inner Num):num -> 'U) ⇒
tmaof i (strlit"0") [] = to_inner Num (0:num) ⇒
tmaof i (strlit"SUC") [] =
Abstract (range ((to_inner Num):num->'U)) (range ((to_inner Num):num->'U))
(λm. to_inner Num (SUC (finv (to_inner Num) m))) ⇒
termsem tmsig i v (quote n) = to_inner Num n``,
strip_tac >> rpt gen_tac >>
Induct_on`n` >> rw[quote_def] >- (
rw[termsem_def] >>
rw[identity_instance] >>
EVAL_STRING_SORT >>
simp[] ) >>
rw[termsem_def] >>
rw[identity_instance] >>
EVAL_STRING_SORT >>
simp[] >>
match_mp_tac(apply_abstract_matchable) >>
imp_res_tac wf_to_inner_range_thm >> simp[] >>
metis_tac[wf_to_inner_finv_left])
fun use_apply_abstract (g as (asl,w)) =
let
val sel = lhs o snd o dest_imp
val tm = find_term(can(match_term(sel(concl(SPEC_ALL apply_abstract_matchable))))) w
in
mp_tac(Q.GEN`u`(PART_MATCH sel apply_abstract_matchable tm))
end g
fun use_termsem_implies (g as (asl,w)) =
let
val tm = find_term(can(match_term``termsem s i v (Implies a b)``)) w
val (_,args) = strip_comb tm
val imp = el 5 args
val p1 = imp |> rator |> rand |> rand
val p2 = imp |> rand
val s = el 2 args |> REWR_CONV(SYM lca_of_sigof) |> concl |> rhs |> rand
val th =
UNDISCH termsem_implies
|> SPECL[s, el 3 args, el 4 args, p1, p2]
|> CONV_RULE(DEPTH_CONV(REWR_CONV lca_of_sigof))
in
mp_tac th >>
impl_tac >- (
assume_tac lca_is_bool_sig >>
imp_res_tac models_lca_ctxt_has_bool_interpretation >>
conj_tac >- simp[] >>
conj_tac >- fs[models_def] >>
conj_tac >- fs[models_def,is_std_interpretation_def] >>
conj_tac >- (CONV_TAC EVAL_term_ok) >>
conj_tac >- (CONV_TAC EVAL_term_ok) >>
conj_tac >- (CONV_TAC (LAND_CONV EVAL_typeof) >> REFL_TAC) >>
conj_tac >- (CONV_TAC (LAND_CONV EVAL_typeof) >> REFL_TAC) >>
fs[is_bool_interpretation_def,is_bool_sig_def] ) >>
disch_then (CHANGED_TAC o SUBST1_TAC)
end g
fun use_termsem_and (g as (asl,w)) =
let
val tm = find_term(can(match_term``termsem s i v (And a b)``)) w
val (_,args) = strip_comb tm
val imp = el 5 args
val p1 = imp |> rator |> rand |> rand
val p2 = imp |> rand
val s = el 2 args |> REWR_CONV(SYM lca_of_sigof) |> concl |> rhs |> rand
val th =
UNDISCH termsem_and
|> SPECL[s, el 3 args, el 4 args, p1, p2]
|> CONV_RULE(DEPTH_CONV(REWR_CONV lca_of_sigof))
in
mp_tac th >>
impl_tac >- (
assume_tac lca_is_bool_sig >>
imp_res_tac models_lca_ctxt_has_bool_interpretation >>
conj_tac >- simp[] >>
conj_tac >- fs[models_def] >>
conj_tac >- fs[models_def,is_std_interpretation_def] >>
conj_tac >- (CONV_TAC EVAL_term_ok) >>
conj_tac >- (CONV_TAC EVAL_term_ok) >>
conj_tac >- (CONV_TAC (LAND_CONV EVAL_typeof) >> REFL_TAC) >>
conj_tac >- (CONV_TAC (LAND_CONV EVAL_typeof) >> REFL_TAC) >>
fs[is_bool_interpretation_def,is_bool_sig_def] ) >>
disch_then (CHANGED_TAC o SUBST1_TAC)
end g
fun use_termsem_not (g as (asl,w)) =
let
val tm = find_term(can(match_term``termsem s i v (Not a)``)) w
val (_,args) = strip_comb tm
val imp = el 5 args
val p1 = imp |> rand
val s = el 2 args |> REWR_CONV(SYM lca_of_sigof) |> concl |> rhs |> rand
val th =
UNDISCH termsem_not
|> SPECL[s, el 3 args, el 4 args, p1]
|> CONV_RULE(DEPTH_CONV(REWR_CONV lca_of_sigof))
in
mp_tac th >>
impl_tac >- (
assume_tac lca_is_bool_sig >>
imp_res_tac models_lca_ctxt_has_bool_interpretation >>
conj_tac >- simp[] >>
conj_tac >- fs[models_def] >>
conj_tac >- fs[models_def,is_std_interpretation_def] >>
conj_tac >- (CONV_TAC EVAL_term_ok) >>
conj_tac >- (CONV_TAC (LAND_CONV EVAL_typeof) >> REFL_TAC) >>
fs[is_bool_interpretation_def,is_bool_sig_def] ) >>
disch_then (CHANGED_TAC o SUBST1_TAC)
end g
fun use_termsem_equation (g as (asl,w)) =
let
val tm = find_term(can(match_term``termsem s i v (a === b)``)) w
val (_,args) = strip_comb tm
val eq = el 5 args
val p1 = eq |> rator |> rand
val p2 = eq |> rand
val s = el 2 args |> REWR_CONV(SYM lca_of_sigof) |> concl |> rhs |> rand
val th =
UNDISCH termsem_equation
|> SPECL[s, el 3 args, el 4 args, p1, p2, el 2 args]
|> CONV_RULE(DEPTH_CONV(REWR_CONV lca_of_sigof))
in
mp_tac th >>
impl_tac >- (
conj_tac >- (
simp[is_structure_def] >>
fs[models_def] >>
assume_tac theory_ok_lca >>
imp_res_tac theory_ok_sig >>
fs[] ) >>
conj_tac >- (
simp[equation_def] >>
CONV_TAC EVAL_term_ok ) >>
REFL_TAC ) >>
disch_then(CHANGED_TAC o SUBST1_TAC)
end g
fun use_termsem_forall (g as (asl,w)) =
let
val tm = find_term(can(match_term``termsem s i v (Forall x y z)``)) w
val (_,args) = strip_comb tm
val eq = el 5 args
val p1 = eq |> rand |> rator |> rand |> rator |> rand
val p2 = eq |> rand |> rator |> rand |> rand
val p3 = eq |> rand |> rand
val s = el 2 args |> REWR_CONV(SYM lca_of_sigof) |> concl |> rhs |> rand
val th =
UNDISCH termsem_forall
|> SPECL[s, el 3 args, el 4 args, p1, p2, p3]
|> CONV_RULE(DEPTH_CONV(REWR_CONV lca_of_sigof))
in
mp_tac th >>
impl_tac >- (
conj_tac >- simp[] >>
conj_tac >- fs[models_def] >>
conj_tac >- fs[models_def] >>
conj_tac >- (CONV_TAC EVAL_type_ok0) >>
conj_tac >- (CONV_TAC EVAL_term_ok) >>
conj_tac >- (CONV_TAC(LAND_CONV EVAL_typeof) >> REFL_TAC) >>
assume_tac lca_is_bool_sig >>
imp_res_tac models_lca_ctxt_has_bool_interpretation >>
fs[is_bool_interpretation_def,is_bool_sig_def]) >>
disch_then(CHANGED_TAC o SUBST1_TAC)
end g
fun use_termsem_exists (g as (asl,w)) =
let
val tm = find_term(can(match_term``termsem s i v (Exists x y z)``)) w
val (_,args) = strip_comb tm
val eq = el 5 args
val p1 = eq |> rand |> rator |> rand |> rator |> rand
val p2 = eq |> rand |> rator |> rand |> rand
val p3 = eq |> rand |> rand
val s = el 2 args |> REWR_CONV(SYM lca_of_sigof) |> concl |> rhs |> rand
val th =
UNDISCH termsem_exists
|> SPECL[s, el 3 args, el 4 args, p1, p2, p3]
|> CONV_RULE(DEPTH_CONV(REWR_CONV lca_of_sigof))
in
mp_tac th >>
impl_tac >- (
conj_tac >- simp[] >>
conj_tac >- fs[models_def] >>
conj_tac >- fs[models_def] >>
conj_tac >- (CONV_TAC EVAL_type_ok0) >>
conj_tac >- (CONV_TAC EVAL_term_ok) >>
conj_tac >- (CONV_TAC(LAND_CONV EVAL_typeof) >> REFL_TAC) >>
assume_tac lca_is_bool_sig >>
imp_res_tac models_lca_ctxt_has_bool_interpretation >>
fs[is_bool_interpretation_def,is_bool_sig_def]) >>
disch_then(CHANGED_TAC o SUBST1_TAC)
end g
val termsem_IN = store_thm("termsem_IN",
``is_set_theory ^mem ⇒
∀i v ty1 a b ty a0 b0 tyin.
i models thyof lca_ctxt ∧
is_valuation (tysof lca_ctxt) (tyaof i) v ∧
a = INST tyin a0 ∧
b = INST tyin b0 ∧
ty1 = Fun ty (Fun (Fun ty Bool) Bool) ∧
ty = REV_ASSOCD (Tyvar(strlit"A")) tyin (Tyvar(strlit"A")) ∧
EVERY (type_ok (tysof lca_ctxt)) (MAP FST tyin) ∧
term_ok (sigof lca_ctxt) a0 ∧
term_ok (sigof lca_ctxt) b0 ∧
typeof a0 = Tyvar(strlit"A") ∧
typeof b0 = (Fun (Tyvar(strlit"A")) Bool) ⇒
termsem (tmsof lca_ctxt) i v
(Comb (Comb (Const (strlit "IN") ty1) a) b)
= Boolean(Holds (termsem (tmsof lca_ctxt) i v b) (termsem (tmsof lca_ctxt) i v a))``,
rpt strip_tac >>
qmatch_abbrev_tac`termsem (tmsof lca_ctxt) i v (Comb (Comb (Const g gy) a) b) = R` >>
qspecl_then[`lca_ctxt`,`i`,`v`,`g`,`gy`,`tyin`,`a`,`b`]mp_tac (UNDISCH termsem_comb2_ax) >>
qunabbrev_tac`g` >>
CONV_TAC(LAND_CONV(STRIP_QUANT_CONV(LAND_CONV(LAND_CONV EVAL)))) >>
simp[FLOOKUP_IN,Abbr`gy`,REV_ASSOCD] >>
disch_then(qspecl_then[`a0`,`b0`]mp_tac) >>
simp[theory_ok_lca] >>
impl_tac >- metis_tac[WELLTYPED,term_ok_welltyped] >>
disch_then SUBST1_TAC >>
CONV_TAC(LAND_CONV(RAND_CONV(RAND_CONV(EVAL_subst)))) >>
qpat_x_assum`ty = X`Abbrev_intro_tac >>
qpat_x_assum`a = X`Abbrev_intro_tac >>
qpat_x_assum`b = X`Abbrev_intro_tac >>
imp_res_tac term_ok_welltyped >>
simp[INST_def,INST_CORE_def,INST_CORE_NIL_IS_RESULT,NOT_IS_CLASH_IS_RESULT] >>
simp[GSYM INST_def] >>
simp[termsem_def,Abbr`R`,holds_def,boolean_def] >> rw[] >>
qmatch_abbrev_tac`r:'U = False` >>
`r <: boolset` suffices_by metis_tac[mem_boolset] >>
qunabbrev_tac`r` >>
match_mp_tac(UNDISCH apply_in_rng) >>
qexists_tac`typesem (tyaof i) (tyvof v) ty` >>
`term_ok (sigof lca_ctxt) a` by (
qunabbrev_tac`a` >>
match_mp_tac term_ok_INST >>
simp[] ) >>
`term_ok (sigof lca_ctxt) b` by (
qunabbrev_tac`b` >>
match_mp_tac term_ok_INST >>
simp[] ) >>
qspecl_then[`a0`,`typeof a0`,`tyin`]mp_tac INST_HAS_TYPE >>
simp_tac bool_ss [] >> impl_tac >- metis_tac[WELLTYPED] >>
qspecl_then[`b0`,`typeof b0`,`tyin`]mp_tac INST_HAS_TYPE >>
simp_tac bool_ss [] >> impl_tac >- metis_tac[WELLTYPED] >>
simp[] >> ntac 2 strip_tac >>
imp_res_tac WELLTYPED_LEMMA >>
conj_tac >- (
qpat_x_assum`typeof a = ty`(SUBST1_TAC o SYM) >>
match_mp_tac (UNDISCH termsem_typesem_matchable) >>
qexists_tac`sigof lca_ctxt` >> simp[] >>
fs[models_def,is_std_interpretation_def] ) >>
match_mp_tac (UNDISCH termsem_typesem_matchable) >>
qexists_tac`sigof lca_ctxt` >> simp[] >>
fs[models_def,is_std_interpretation_def] >>
imp_res_tac typesem_Fun >>
imp_res_tac typesem_Bool >> simp[])
(*
val (g as (_,w)) = top_goal()
*)
fun use_termsem_IN_simple (g as (asl,w)) =
let
val tm = find_term(can(match_term``termsem s i v (Comb (Comb (Const (strlit"IN") ty) a) b)``)) w
val (_,args) = strip_comb tm
val app = el 5 args
val ty = app |> rator |> rand |> rator |> rand |> rand
val a = app |> rator |> rand |> rand
val b = app |> rand
val th =
UNDISCH termsem_IN
|> SPECL[el 3 args, el 4 args, ty, a, b]
in
mp_tac th >> simp[] >>
disch_then(qspec_then`[]`mp_tac o SPECL[a,b]) >>
impl_keep_tac >- (
conj_tac >- (CONV_TAC(RAND_CONV(EVAL_INST)) >> REFL_TAC) >>
conj_tac >- (CONV_TAC(RAND_CONV(EVAL_INST)) >> REFL_TAC) >>
conj_tac >- (simp[REV_ASSOCD]) >>
conj_tac >- (simp[]) >>
conj_tac >- (CONV_TAC(EVAL_term_ok)) >>
conj_tac >- (CONV_TAC(EVAL_term_ok)) >>
conj_tac >- (CONV_TAC(LAND_CONV(EVAL_typeof))>>REFL_TAC) >>
(CONV_TAC(LAND_CONV(EVAL_typeof))>>REFL_TAC)) >>
pop_assum(fn th =>
map_every (SUBST1_TAC o SYM) (List.take((CONJUNCTS th),2))) >>
disch_then(CHANGED_TAC o SUBST1_TAC)
end g
val termsem_UNIV = store_thm("termsem_UNIV",
``is_set_theory ^mem ⇒
∀i v ty.
i models thyof lca_ctxt ∧
is_valuation (tysof lca_ctxt) (tyaof i) v ∧
type_ok (tysof lca_ctxt) ty ⇒
termsem (tmsof lca_ctxt) i v (Const (strlit "UNIV") (Fun ty Bool))
= Abstract (typesem (tyaof i) (tyvof v) ty) boolset (K True)``,
rpt strip_tac >>
`∃ty0 r. (Const(strlit"UNIV")ty0 === r) ∈ (axsof lca_ctxt)` by
(EVAL_TAC >> simp[] ) >>
pop_assum (fn th=> assume_tac th >> mp_tac th) >>
CONV_TAC(LAND_CONV EVAL) >> strip_tac >>
qmatch_assum_abbrev_tac`MEM eq aqs` >>
qpat_x_assum`ty0 = _`Abbrev_intro_tac >>
`i satisfies (sigof lca_ctxt,[],eq)` by fs[models_def] >>
qspecl_then[`sigof lca_ctxt`,`eq`,`[(ty,Tyvar(strlit"A"))]`]mp_tac termsem_INST >>
simp[] >>
impl_tac >- (
unabbrev_all_tac >>
assume_tac theory_ok_lca >>
imp_res_tac theory_ok_sig >>
fs[term_ok_equation] >>
conj_tac >> CONV_TAC(EVAL_term_ok) ) >>
disch_then(qspecl_then[`i`,`v`]mp_tac) >>
simp[Abbr`eq`,equation_def,Abbr`ty0`] >>
CONV_TAC(LAND_CONV(LAND_CONV(RAND_CONV EVAL_INST))) >>
Q.PAT_ABBREV_TAC`vv:'U valuation = X Y` >>
`is_valuation (tysof lca_ctxt) (tyaof i) vv` by (
fs[Abbr`vv`,is_valuation_def,is_type_valuation_def,is_term_valuation_def] >>
conj_tac >- (
gen_tac >>
match_mp_tac(UNDISCH typesem_inhabited) >>
qexists_tac`tysof lca_ctxt` >>
simp[is_type_valuation_def] >>
fs[models_def,is_interpretation_def] >>
simp[holSyntaxLibTheory.REV_ASSOCD] >>
BasicProvers.CASE_TAC >> simp[type_ok_def]) >>
qx_genl_tac[`z`,`zy`] >> strip_tac >>
first_x_assum(qspecl_then[`z`,`TYPE_SUBST [(ty,Tyvar(strlit"A"))] zy`]mp_tac) >>
simp[type_ok_TYPE_SUBST,Once typesem_TYPE_SUBST] ) >>
simp[equation_intro] >>
fs[satisfies_def] >>
first_x_assum(qspec_then`vv`mp_tac) >> simp[] >>
disch_then kall_tac >>
qmatch_abbrev_tac`termsem (tmsof lca_ctxt) i v (ll === rr) = True ==> R` >>
qspecl_then[`sigof lca_ctxt`,`i`,`v`,`ll`,`rr`]mp_tac(UNDISCH termsem_equation) >>
simp[] >> impl_tac >- (
simp[is_structure_def] >>
fs[models_def] >>
conj_tac >- (
assume_tac theory_ok_lca >>
imp_res_tac theory_ok_sig >> fs[]) >>
simp[Abbr`ll`,Abbr`rr`,equation_def] >>
CONV_TAC EVAL_term_ok >>
simp[] ) >>
simp[boolean_eq_true] >>
disch_then kall_tac >>
simp[Abbr`R`] >> disch_then kall_tac >>
simp[Abbr`rr`,termsem_def] >>
qunabbrev_tac`aqs` >>
imp_res_tac models_lca_ctxt_has_bool_interpretation >>
fs[models_def,is_std_interpretation_def] >>
imp_res_tac typesem_Bool >> simp[] >>
match_mp_tac (UNDISCH abstract_eq) >>
simp[] >>
assume_tac(EVAL``FLOOKUP (tmsof lca_ctxt) (strlit "T")``) >>
simp[identity_instance] >>
EVAL_STRING_SORT >> simp[] >>
fs[is_bool_interpretation_def,is_true_interpretation_def,interprets_nil] >>
simp[mem_boolset])
val termsem_INJ = store_thm("termsem_INJ",
``is_set_theory ^mem ⇒
∀i v ty1 a b c tya tyb a0 b0 c0 tyin.
i models thyof lca_ctxt ∧
is_valuation (tysof lca_ctxt) (tyaof i) v ∧
a = INST tyin a0 ∧
b = INST tyin b0 ∧
c = INST tyin c0 ∧
ty1 = Fun (Fun tya tyb) (Fun (Fun tya Bool) (Fun (Fun tyb Bool) Bool)) ∧
tya = REV_ASSOCD(Tyvar(strlit"A"))tyin(Tyvar(strlit"A")) ∧
tyb = REV_ASSOCD(Tyvar(strlit"B"))tyin(Tyvar(strlit"B")) ∧
EVERY (type_ok (tysof lca_ctxt)) (MAP FST tyin) ∧
term_ok (sigof lca_ctxt) a0 ∧
term_ok (sigof lca_ctxt) b0 ∧
term_ok (sigof lca_ctxt) c0 ∧
typeof a0 = (Fun (Tyvar(strlit"A")) (Tyvar(strlit"B"))) ∧
typeof b0 = (Fun (Tyvar(strlit"A")) Bool) ∧
typeof c0 = (Fun (Tyvar(strlit"B")) Bool)
⇒
termsem (tmsof lca_ctxt) i v
(Comb (Comb (Comb
(Const (strlit "INJ") ty1)
a) b) c) =
Boolean (INJ ($' (termsem (tmsof lca_ctxt) i v a))
(ext(typesem (tyaof i) (tyvof v) tya) ∩ Holds (termsem (tmsof lca_ctxt) i v b))
(ext(typesem (tyaof i) (tyvof v) tyb) ∩ Holds (termsem (tmsof lca_ctxt) i v c)))``,
rpt strip_tac >>
qmatch_abbrev_tac`termsem (tmsof lca_ctxt) i v (Comb (Comb (Comb (Const g ty) a) b) c) = R` >>
qspecl_then[`lca_ctxt`,`i`,`v`,`g`,`ty`,`tyin`,`a`,`b`,`c`]mp_tac (UNDISCH termsem_comb3_ax) >>
qunabbrev_tac`g` >>
CONV_TAC(LAND_CONV(STRIP_QUANT_CONV(LAND_CONV(LAND_CONV EVAL)))) >>
simp[FLOOKUP_INJ,Abbr`ty`,REV_ASSOCD] >>
disch_then(qspecl_then[`a0`,`b0`,`c0`]mp_tac) >>
simp[theory_ok_lca] >>
impl_tac >- metis_tac[WELLTYPED,term_ok_welltyped] >>
disch_then SUBST1_TAC >>
qpat_x_assum`tya = _`Abbrev_intro_tac >>
qpat_x_assum`tyb = _`Abbrev_intro_tac >>
qpat_x_assum`a = _`Abbrev_intro_tac >>
qpat_x_assum`b = _`Abbrev_intro_tac >>
qpat_x_assum`c = _`Abbrev_intro_tac >>
simp[] >>
Q.PAT_ABBREV_TAC`s = (a0,Var X Y)::Z` >>
Q.PAT_ABBREV_TAC`tm = And X Y` >>
`term_ok (sigof lca_ctxt) tm` by (
qunabbrev_tac`tm` >>
CONV_TAC(EVAL_term_ok) ) >>
`term_ok (sigof lca_ctxt) (VSUBST s tm)` by (
match_mp_tac term_ok_VSUBST >>
simp[Abbr`s`] >> ntac 2 (pop_assum kall_tac) >> rw[] >>
metis_tac[WELLTYPED,term_ok_welltyped]) >>
qspecl_then[`sigof lca_ctxt`,`VSUBST s tm`,`tyin`]mp_tac termsem_INST >> simp[] >>
disch_then kall_tac >>
Q.PAT_ABBREV_TAC`vvv:'U valuation = X Y` >>
`is_valuation (tysof lca_ctxt) (tyaof i) vvv` by (
qpat_x_assum`term_ok X tm`kall_tac >>
qpat_x_assum`term_ok X (VSUBST A Y)`kall_tac >>
qunabbrev_tac`tm` >>
simp[Abbr`vvv`] >>
fs[is_valuation_def,is_type_valuation_def,is_term_valuation_def] >>
conj_tac >- (
gen_tac >>
match_mp_tac(UNDISCH typesem_inhabited) >>
qexists_tac`tysof lca_ctxt` >>
simp[is_type_valuation_def] >>
fs[models_def,is_interpretation_def] >>
simp[holSyntaxLibTheory.REV_ASSOCD_ALOOKUP] >>
BasicProvers.CASE_TAC >> simp[type_ok_def] >>
imp_res_tac ALOOKUP_MEM >>
fs[EVERY_MEM,MEM_MAP,EXISTS_PROD,PULL_EXISTS] >>
metis_tac[]) >>
qx_genl_tac[`z`,`ty`] >> strip_tac >>
first_x_assum(qspecl_then[`z`,`TYPE_SUBST tyin ty`]mp_tac) >>
simp[type_ok_TYPE_SUBST,Once typesem_TYPE_SUBST] ) >>
qspecl_then[`tm`,`s`]mp_tac termsem_VSUBST >>
impl_tac >- (
imp_res_tac term_ok_welltyped >>
simp[Abbr`s`] >> ntac 9 (pop_assum kall_tac) >> rw[] >>
metis_tac[WELLTYPED,term_ok_welltyped]) >>
simp[] >> disch_then kall_tac >>
Q.PAT_ABBREV_TAC`vv:'U valuation = X Y` >>
simp[Abbr`tm`] >>
qmatch_abbrev_tac`termsem (tmsof lca_ctxt) i vv (And tm1 tm2) = R` >>
qspecl_then[`sigof lca_ctxt`,`i`,`vv`,`tm1`,`tm2`]mp_tac (UNDISCH termsem_and) >>
`is_valuation (tysof lca_ctxt) (tyaof i) vv` by (
qpat_x_assum`term_ok X (And tm1 tm2)`kall_tac >>
qpat_x_assum`term_ok X (VSUBST A Y)`kall_tac >>
map_every qunabbrev_tac[`tm1`,`tm2`] >>
simp[Abbr`vv`,Abbr`s`,UPDATE_LIST_THM] >>
match_mp_tac is_valuation_extend >>
reverse conj_tac >- (
match_mp_tac (UNDISCH termsem_typesem_matchable) >>
qexists_tac`sigof lca_ctxt`>>simp[] >>
fs[models_def,is_std_interpretation_def] ) >>
match_mp_tac is_valuation_extend >>
reverse conj_tac >- (
match_mp_tac (UNDISCH termsem_typesem_matchable) >>
qexists_tac`sigof lca_ctxt`>>simp[] >>
fs[models_def,is_std_interpretation_def] ) >>
match_mp_tac is_valuation_extend >>
reverse conj_tac >- (
match_mp_tac (UNDISCH termsem_typesem_matchable) >>
qexists_tac`sigof lca_ctxt`>>simp[] >>
fs[models_def,is_std_interpretation_def] ) >>
simp[] ) >>
impl_tac >- (
imp_res_tac models_lca_ctxt_has_bool_interpretation >>
assume_tac lca_is_bool_sig >>
fs[models_def,is_std_interpretation_def,is_bool_interpretation_def,is_bool_sig_def] >>
unabbrev_all_tac >>
conj_tac >- (CONV_TAC EVAL_term_ok) >>
conj_tac >- (CONV_TAC EVAL_term_ok) >>
conj_tac >- (CONV_TAC (LAND_CONV EVAL_typeof) >> REFL_TAC) >>
(CONV_TAC (LAND_CONV EVAL_typeof) >> REFL_TAC)) >>
simp[] >> disch_then kall_tac >>
simp[Abbr`R`] >>
AP_TERM_TAC >>
simp[pred_setTheory.INJ_DEF] >>
qmatch_abbrev_tac`A ∧ B ⇔ A' ∧ B'` >>
`(A ⇔ A') ∧ (B ⇔ B')` suffices_by rw[] >>
map_every qunabbrev_tac[`A`,`A'`,`B`,`B'`] >>
conj_tac >- (
qpat_x_assum`term_ok X (And tm1 tm2)`kall_tac >>
qpat_x_assum`term_ok X (VSUBST A Y)`kall_tac >>
map_every qunabbrev_tac[`tm1`,`tm2`] >>
qmatch_abbrev_tac`termsem (tmsof lca_ctxt) i vv (Forall f ty t) = True ⇔ R` >>
qspecl_then[`sigof lca_ctxt`,`i`,`vv`,`f`,`ty`,`t`]mp_tac (UNDISCH termsem_forall) >>
impl_tac >- (
imp_res_tac models_lca_ctxt_has_bool_interpretation >>
assume_tac lca_is_bool_sig >>
fs[models_def,is_std_interpretation_def,is_bool_interpretation_def,is_bool_sig_def] >>
unabbrev_all_tac >>
conj_tac >- (CONV_TAC EVAL_type_ok) >>
conj_tac >- (CONV_TAC EVAL_term_ok) >>
(CONV_TAC (LAND_CONV EVAL_typeof) >> REFL_TAC)) >>
simp[] >> disch_then kall_tac >>
simp[boolean_eq_true,Abbr`R`] >>
simp[IN_DEF,ext_def,GSYM AND_IMP_INTRO] >>
`typesem (tyaof i) (tyvof vv) ty = typesem (tyaof i) (tyvof v) tya` by (
simp[Abbr`ty`,typesem_def,Abbr`vv`,Abbr`vvv`] ) >>
simp[] >>
qho_match_abbrev_tac`(∀x. P x ⇒ Q x) ⇔ (∀x. P x ⇒ R x)` >>
`∀x. P x ⇒ (Q x ⇔ R x)` suffices_by rw[] >>
map_every qunabbrev_tac[`P`,`Q`,`R`] >> simp[] >>
gen_tac >> strip_tac >>
qunabbrev_tac`t` >>
qmatch_abbrev_tac`termsem (tmsof lca_ctxt) i vvx (Implies tm1 tm2) = True ⇔ R` >>
`is_valuation (tysof lca_ctxt) (tyaof i) vvx` by (
simp[Abbr`vvx`] >>
match_mp_tac is_valuation_extend >>
simp[] ) >>
qspecl_then[`sigof lca_ctxt`,`i`,`vvx`,`tm1`,`tm2`]mp_tac (UNDISCH termsem_implies) >>
impl_tac >- (
imp_res_tac models_lca_ctxt_has_bool_interpretation >>
assume_tac lca_is_bool_sig >>
fs[models_def,is_std_interpretation_def,is_bool_interpretation_def,is_bool_sig_def] >>
unabbrev_all_tac >>
conj_tac >- (CONV_TAC EVAL_term_ok) >>
conj_tac >- (CONV_TAC EVAL_term_ok) >>
conj_tac >- (CONV_TAC (LAND_CONV EVAL_typeof) >> REFL_TAC) >>
(CONV_TAC (LAND_CONV EVAL_typeof) >> REFL_TAC)) >>
simp[] >> disch_then kall_tac >>
simp[boolean_eq_true,Abbr`R`] >>
qmatch_abbrev_tac`A ⇒ B ⇔ A' ⇒ B'` >>
`(A ⇔ A') ∧ (B ⇔ B')` suffices_by rw[] >>
map_every qunabbrev_tac[`A`,`A'`,`B`,`B'`] >>
conj_tac >- (
simp[Abbr`tm1`,Abbr`tm2`] >>
qmatch_abbrev_tac`termsem (tmsof lca_ctxt) i vvx (Comb (Comb (Const (strlit"IN") ty0) tm1) tm2) = True ⇔ R` >>
qspecl_then[`i`,`vvx`,`ty0`,`tm1`,`tm2`,`ty`,`tm1`,`tm2`,`[]`]mp_tac(UNDISCH termsem_IN) >>
simp[] >>
impl_tac >- (
unabbrev_all_tac >>
conj_tac >- ( CONV_TAC(RAND_CONV EVAL_INST) >> REFL_TAC) >>
conj_tac >- ( CONV_TAC(RAND_CONV EVAL_INST) >> REFL_TAC) >>
conj_tac >- (simp[REV_ASSOCD]) >>
conj_tac >- ( CONV_TAC(EVAL_term_ok)) >>
conj_tac >- ( CONV_TAC(EVAL_term_ok)) >>
conj_tac >- ( CONV_TAC(LAND_CONV EVAL_typeof) >> REFL_TAC) >>
( CONV_TAC(LAND_CONV EVAL_typeof) >> REFL_TAC) ) >>
simp[] >> disch_then kall_tac >>
simp[boolean_eq_true,Abbr`R`] >>
simp[Abbr`tm1`,Abbr`tm2`,termsem_def] >>
simp[Abbr`vvx`,APPLY_UPDATE_THM,Abbr`f`] >>
simp[Abbr`vv`,Abbr`s`,UPDATE_LIST_THM,APPLY_UPDATE_THM] >>
qspecl_then[`sigof lca_ctxt`,`b0`,`tyin`]mp_tac termsem_INST >>
simp[] ) >>
simp[Abbr`tm1`,Abbr`tm2`] >>
qmatch_abbrev_tac`termsem (tmsof lca_ctxt) i vvx (Comb (Comb (Const (strlit"IN") ty0) tm1) tm2) = True ⇔ R` >>
qspecl_then[`i`,`vvx`,`ty0`,`tm1`,`tm2`,`Tyvar(strlit"B")`]mp_tac(UNDISCH termsem_IN) >>
simp[] >>
disch_then(qspecl_then[
`Comb(Var(strlit"f")(Fun(Tyvar(strlit"C"))ty))(Var f (Tyvar(strlit"C")))`,
`Var(strlit"t")(Fun ty Bool)`,
`[(ty,Tyvar(strlit"C"));(Tyvar(strlit"B"),ty)]`]mp_tac) >>
impl_keep_tac >- (
unabbrev_all_tac >>
conj_tac >- ( CONV_TAC(RAND_CONV EVAL_INST) >> REFL_TAC) >>
conj_tac >- ( CONV_TAC(RAND_CONV EVAL_INST) >> REFL_TAC) >>
conj_tac >- (simp[REV_ASSOCD]) >>
conj_tac >- (simp[type_ok_def]) >>
conj_tac >- ( CONV_TAC EVAL_term_ok) >>
conj_tac >- ( CONV_TAC EVAL_term_ok) >>
conj_tac >- ( CONV_TAC(LAND_CONV EVAL_typeof) >> REFL_TAC) >>
( CONV_TAC(LAND_CONV EVAL_typeof) >> REFL_TAC) ) >>
pop_assum(fn th =>
map_every (SUBST1_TAC o SYM) (List.take(CONJUNCTS th,2))) >>
simp[] >> disch_then kall_tac >>
simp[boolean_eq_true,Abbr`R`] >>
simp[Abbr`tm1`,Abbr`tm2`,termsem_def] >>
simp[Abbr`vvx`,APPLY_UPDATE_THM,Abbr`f`] >>
simp[Abbr`vv`,Abbr`s`,UPDATE_LIST_THM,APPLY_UPDATE_THM] >>
qspecl_then[`sigof lca_ctxt`,`c0`,`tyin`]mp_tac termsem_INST >>
simp[] >> disch_then kall_tac >>
qspecl_then[`sigof lca_ctxt`,`a0`,`tyin`]mp_tac termsem_INST >>
simp[] >> disch_then kall_tac >>
EQ_TAC >> simp[] >> strip_tac >>
match_mp_tac (UNDISCH apply_in_rng) >>
first_assum(match_exists_tac o concl) >> simp[] >>
match_mp_tac(UNDISCH termsem_typesem_matchable) >>
simp[] >>
qexists_tac`sigof lca_ctxt` >>
simp[] >>
fs[models_def,is_std_interpretation_def] >>
imp_res_tac typesem_Fun >> simp[] >>
simp[typesem_def,Abbr`vvv`] ) >>
simp[Abbr`tm1`,Abbr`tm2`,IN_DEF,ext_def] >>
qmatch_abbrev_tac`termsem (tmsof lca_ctxt) i vv (Forall x y z) = True ⇔ R` >>
qspecl_then[`sigof lca_ctxt`,`i`,`vv`,`x`,`y`,`z`]mp_tac (UNDISCH termsem_forall) >>
impl_tac >- (
imp_res_tac models_lca_ctxt_has_bool_interpretation >>
assume_tac lca_is_bool_sig >>
fs[models_def,is_std_interpretation_def,is_bool_interpretation_def,is_bool_sig_def] >>
unabbrev_all_tac >>
conj_tac >- (CONV_TAC EVAL_type_ok) >>
conj_tac >- (CONV_TAC EVAL_term_ok) >>
(CONV_TAC (LAND_CONV EVAL_typeof) >> REFL_TAC)) >>
simp[] >> disch_then kall_tac >>
simp[boolean_eq_true,Abbr`R`] >>
simp[Abbr`x`,Abbr`y`,typesem_def] >>
simp[GSYM AND_IMP_INTRO,Once RIGHT_FORALL_IMP_THM] >>
AP_TERM_TAC >> simp[FUN_EQ_THM] >> gen_tac >>
qmatch_abbrev_tac`A ⇒ B ⇔ A' ⇒ B'` >>
`A = A' ∧ (A ⇒ (B = B'))` suffices_by metis_tac[] >>
map_every qunabbrev_tac[`A`,`A'`,`B`,`B'`] >>
conj_tac >- ( simp[Abbr`vv`,Abbr`vvv`] ) >>
strip_tac >>
simp[Abbr`z`] >>
qmatch_abbrev_tac`termsem (tmsof lca_ctxt) i vvx (Forall q y z) = True ⇔ R` >>
qspecl_then[`sigof lca_ctxt`,`i`,`vvx`,`q`,`y`,`z`]mp_tac (UNDISCH termsem_forall) >>
impl_tac >- (
conj_tac >- (
simp[Abbr`vvx`] >>
match_mp_tac is_valuation_extend >>
simp[Abbr`y`,typesem_def,APPLY_UPDATE_THM] ) >>
imp_res_tac models_lca_ctxt_has_bool_interpretation >>
assume_tac lca_is_bool_sig >>
fs[models_def,is_std_interpretation_def,is_bool_interpretation_def,is_bool_sig_def] >>
unabbrev_all_tac >>
conj_tac >- (CONV_TAC EVAL_type_ok) >>
conj_tac >- (CONV_TAC EVAL_term_ok) >>
(CONV_TAC (LAND_CONV EVAL_typeof) >> REFL_TAC)) >>
simp[] >> disch_then kall_tac >>
simp[boolean_eq_true,Abbr`R`] >>
simp[Abbr`q`,Abbr`y`,typesem_def] >>
CONV_TAC(RAND_CONV(QUANT_CONV(REWR_CONV(PROVE[]``(a ==> b ==> c) <=> (b ==> a ==> c)``)))) >>
simp[Abbr`vvx`] >>
AP_TERM_TAC >> simp[FUN_EQ_THM] >> gen_tac >>
qmatch_abbrev_tac`A ⇒ B ⇔ A' ⇒ B'` >>
`A = A' ∧ (A ⇒ (B = B'))` suffices_by metis_tac[] >>
map_every qunabbrev_tac[`A`,`A'`,`B`,`B'`] >>
conj_tac >- ( simp[Abbr`vv`,Abbr`vvv`] ) >>
strip_tac >>
simp[Abbr`z`] >>
Q.PAT_ABBREV_TAC`vu:'U valuation = X Y` >>
`is_valuation (tysof lca_ctxt) (tyaof i) vu` by (
simp[Abbr`vu`] >>
match_mp_tac is_valuation_extend >>
simp[typesem_def] >>
match_mp_tac is_valuation_extend >>
simp[typesem_def] ) >>
use_termsem_implies >>
simp[boolean_eq_true] >>
simp[Once AND_IMP_INTRO] >>
qmatch_abbrev_tac`(A ⇒ B) ⇔ (A' ⇒ B')` >>
`A = A' ∧ (A' ⇒ (B = B'))` suffices_by metis_tac[] >>
map_every qunabbrev_tac[`A`,`A'`,`B`,`B'`] >>
conj_tac >- (
use_termsem_and >>
simp[boolean_eq_true] >>
qmatch_abbrev_tac`A ∧ B ⇔ A' ∧ B'` >>
`(A ⇔ A') ∧ (B ⇔ B')` suffices_by rw[] >>
map_every qunabbrev_tac[`A`,`A'`,`B`,`B'`] >>
conj_tac >- (
use_termsem_IN_simple >>
simp[boolean_eq_true,termsem_def] >>
simp[Abbr`vu`,APPLY_UPDATE_THM] >>
simp[Abbr`vv`,Abbr`s`,UPDATE_LIST_THM,APPLY_UPDATE_THM] >>
qspecl_then[`sigof lca_ctxt`,`b0`,`tyin`]mp_tac termsem_INST >>
simp[] ) >>
use_termsem_IN_simple >>
simp[boolean_eq_true,termsem_def] >>
simp[Abbr`vu`,APPLY_UPDATE_THM] >>
simp[Abbr`vv`,Abbr`s`,UPDATE_LIST_THM,APPLY_UPDATE_THM] >>
qspecl_then[`sigof lca_ctxt`,`b0`,`tyin`]mp_tac termsem_INST >>
simp[] ) >>
strip_tac >>
use_termsem_implies >>
simp[boolean_eq_true] >>
simp[equation_intro] >>
qmatch_abbrev_tac`(A ⇒ B) ⇔ (A' ⇒ B')` >>
`A = A' ∧ (B = B')` suffices_by metis_tac[] >>
map_every qunabbrev_tac[`A`,`A'`,`B`,`B'`] >>
conj_tac >- (
use_termsem_equation >>
simp[boolean_eq_true,termsem_def] >>
simp[Abbr`vu`,APPLY_UPDATE_THM] >>
simp[Abbr`vv`,Abbr`s`,UPDATE_LIST_THM,APPLY_UPDATE_THM] >>
qspecl_then[`sigof lca_ctxt`,`a0`,`tyin`]mp_tac termsem_INST >> simp[]) >>
use_termsem_equation >>
simp[boolean_eq_true,termsem_def,Abbr`vu`,APPLY_UPDATE_THM])
fun use_termsem_INJ f tyinq (g as (asl,w)) =
let
val tm = find_term(can(match_term``termsem s i v (Comb (Comb (Comb (Const (strlit"INJ") ty) a) b) c)``)) w
val (_,args) = strip_comb tm
val app = el 5 args
val ty = app |> rator |> rand |> rator |> rand |> rator |> rand |> rand
val a = app |> rator |> rand |> rator |> rand |> rand
val b = app |> rator |> rand |> rand
val c = app |> rand
val th =
UNDISCH termsem_INJ
|> SPECL[el 3 args, el 4 args, ty, a, b, c]
in
mp_tac th >> simp[] >>
disch_then(qspec_then tyinq mp_tac o SPECL(map f [a, b, c])) >>
impl_keep_tac >- (
conj_tac >- (CONV_TAC(RAND_CONV(EVAL_INST)) >> REFL_TAC) >>
conj_tac >- (CONV_TAC(RAND_CONV(EVAL_INST)) >> REFL_TAC) >>
conj_tac >- (CONV_TAC(RAND_CONV EVAL_INST) >> REFL_TAC) >>
conj_tac >- (simp[REV_ASSOCD]) >>
conj_tac >- (simp[] >> rpt conj_tac >> CONV_TAC(EVAL_type_ok)) >>
conj_tac >- (CONV_TAC(EVAL_term_ok)) >>
conj_tac >- (CONV_TAC(EVAL_term_ok)) >>
conj_tac >- (CONV_TAC(EVAL_term_ok)) >>
conj_tac >- (CONV_TAC(LAND_CONV(EVAL_typeof))>>REFL_TAC) >>
conj_tac >- (CONV_TAC(LAND_CONV(EVAL_typeof))>>REFL_TAC) >>
(CONV_TAC(LAND_CONV(EVAL_typeof))>>REFL_TAC)) >>
pop_assum(fn th =>
map_every (SUBST1_TAC o SYM) (List.take((CONJUNCTS th),5))) >>
disch_then(CHANGED_TAC o SUBST1_TAC)
end g
val termsem_SUBSET = store_thm("termsem_SUBSET",
``is_set_theory ^mem ⇒
∀i v ty1 a b ty a0 b0 tyin.
i models thyof lca_ctxt ∧
is_valuation (tysof lca_ctxt) (tyaof i) v ∧
a = INST tyin a0 ∧
b = INST tyin b0 ∧
ty1 = Fun (Fun ty Bool) (Fun (Fun ty Bool) Bool) ∧
ty = REV_ASSOCD (Tyvar(strlit"A")) tyin (Tyvar(strlit"A")) ∧
EVERY (type_ok (tysof lca_ctxt)) (MAP FST tyin) ∧
term_ok (sigof lca_ctxt) a0 ∧
term_ok (sigof lca_ctxt) b0 ∧
typeof a0 = (Fun (Tyvar(strlit"A")) Bool) ∧
typeof b0 = (Fun (Tyvar(strlit"A")) Bool) ⇒
termsem (tmsof lca_ctxt) i v
(Comb (Comb (Const (strlit "SUBSET") ty1) a) b)
= Boolean(
ext (typesem (tyaof i) (tyvof v) ty) ∩ Holds (termsem (tmsof lca_ctxt) i v a) ⊆
ext (typesem (tyaof i) (tyvof v) ty) ∩ Holds (termsem (tmsof lca_ctxt) i v b))``,
rpt strip_tac >>
qmatch_abbrev_tac`termsem (tmsof lca_ctxt) i v (Comb (Comb (Const g gy) a) b) = R` >>
qspecl_then[`lca_ctxt`,`i`,`v`,`g`,`gy`,`tyin`,`a`,`b`]mp_tac (UNDISCH termsem_comb2_ax) >>
qunabbrev_tac`g` >>
CONV_TAC(LAND_CONV(STRIP_QUANT_CONV(LAND_CONV(LAND_CONV EVAL)))) >>
simp[FLOOKUP_SUBSET,Abbr`gy`,REV_ASSOCD] >>
disch_then(qspecl_then[`a0`,`b0`]mp_tac) >>
simp[theory_ok_lca] >>
impl_tac >- metis_tac[WELLTYPED,term_ok_welltyped] >>
disch_then SUBST1_TAC >>
qpat_x_assum`a = X`Abbrev_intro_tac >>
qpat_x_assum`b = X`Abbrev_intro_tac >>
qpat_x_assum`ty = X`Abbrev_intro_tac >>
Q.PAT_ABBREV_TAC`s = (a0,Var X Y)::Z` >>
Q.PAT_ABBREV_TAC`tm = Forall X Z Y` >>
`term_ok (sigof lca_ctxt) tm` by (
qunabbrev_tac`tm` >>
CONV_TAC(EVAL_term_ok) ) >>
`term_ok (sigof lca_ctxt) (VSUBST s tm)` by (
match_mp_tac term_ok_VSUBST >>
simp[Abbr`s`] >> ntac 2 (pop_assum kall_tac) >> rw[] >>
metis_tac[WELLTYPED,term_ok_welltyped]) >>
qspecl_then[`sigof lca_ctxt`,`VSUBST s tm`,`tyin`]mp_tac termsem_INST >> simp[] >>
disch_then kall_tac >>
Q.PAT_ABBREV_TAC`vvv:'U valuation = X Y` >>
`is_valuation (tysof lca_ctxt) (tyaof i) vvv` by (
qpat_x_assum`term_ok X tm`kall_tac >>
qpat_x_assum`term_ok X (VSUBST A Y)`kall_tac >>
qunabbrev_tac`tm` >>
simp[Abbr`vvv`] >>
fs[is_valuation_def,is_type_valuation_def,is_term_valuation_def] >>
conj_tac >- (
gen_tac >>
match_mp_tac(UNDISCH typesem_inhabited) >>
qexists_tac`tysof lca_ctxt` >>
simp[is_type_valuation_def] >>
fs[models_def,is_interpretation_def] >>
simp[holSyntaxLibTheory.REV_ASSOCD_ALOOKUP] >>
BasicProvers.CASE_TAC >> simp[type_ok_def] >>
imp_res_tac ALOOKUP_MEM >>
fs[EVERY_MEM,MEM_MAP,EXISTS_PROD,PULL_EXISTS] >>
metis_tac[]) >>
qx_genl_tac[`z`,`zy`] >> strip_tac >>
first_x_assum(qspecl_then[`z`,`TYPE_SUBST tyin zy`]mp_tac) >>
simp[type_ok_TYPE_SUBST,Once typesem_TYPE_SUBST] ) >>
qspecl_then[`tm`,`s`]mp_tac termsem_VSUBST >>
impl_tac >- (
imp_res_tac term_ok_welltyped >>
simp[Abbr`s`] >> ntac 9 (pop_assum kall_tac) >> rw[] >>
metis_tac[WELLTYPED,term_ok_welltyped]) >>
simp[] >> disch_then kall_tac >>
Q.PAT_ABBREV_TAC`vv:'U valuation = X Y` >>
simp[Abbr`tm`] >>
`is_valuation (tysof lca_ctxt) (tyaof i) vv` by (
qpat_x_assum`term_ok X (Forall Y tm1 tm2)`kall_tac >>
qpat_x_assum`term_ok X (VSUBST A Y)`kall_tac >>
simp[Abbr`vv`,Abbr`s`,UPDATE_LIST_THM] >>
match_mp_tac is_valuation_extend >>
reverse conj_tac >- (
match_mp_tac (UNDISCH termsem_typesem_matchable) >>
qexists_tac`sigof lca_ctxt`>>simp[] >>
fs[models_def,is_std_interpretation_def] ) >>
match_mp_tac is_valuation_extend >>
reverse conj_tac >- (
match_mp_tac (UNDISCH termsem_typesem_matchable) >>
qexists_tac`sigof lca_ctxt`>>simp[] >>
fs[models_def,is_std_interpretation_def] ) >>
simp[] ) >>
use_termsem_forall >>
simp[boolean_eq_true,Abbr`R`] >>
AP_TERM_TAC >>
simp[SUBSET_DEF,ext_def] >>
simp[Once typesem_def] >>
`tyvof vv (strlit "A") = typesem (tyaof i) (tyvof v) ty` by (
simp[Abbr`vv`,Abbr`vvv`] ) >>
simp[GSYM AND_IMP_INTRO] >>
qho_match_abbrev_tac`(∀x. P x ⇒ Q x) ⇔ (∀x. P x ⇒ Q' x)` >>
`∀x. P x ⇒ (Q x ⇔ Q' x)` suffices_by metis_tac[] >>
simp[Abbr`P`,Abbr`Q`,Abbr`Q'`] >>
gen_tac >> strip_tac >>
Q.PAT_ABBREV_TAC`vvx:'U valuation = X Y` >>
`is_valuation (tysof lca_ctxt) (tyaof i) vvx` by (
simp[Abbr`vvx`] >>
match_mp_tac is_valuation_extend >>
simp[typesem_def]) >>
use_termsem_implies >>
simp[boolean_eq_true] >>
qmatch_abbrev_tac`(A ⇒ B) ⇔ (A' ⇒ B')` >>
`A = A' ∧ B = B'` suffices_by metis_tac[] >>
map_every qunabbrev_tac[`A`,`A'`,`B`,`B'`] >>
conj_tac >- (
use_termsem_IN_simple >>
simp[boolean_eq_true] >>
simp[termsem_def] >>
simp[Abbr`vvx`,APPLY_UPDATE_THM] >>
simp[Abbr`vv`,APPLY_UPDATE_THM,Abbr`s`,UPDATE_LIST_THM] >>
qspecl_then[`sigof lca_ctxt`,`a0`,`tyin`]mp_tac termsem_INST >>
simp[IN_DEF] ) >>
use_termsem_IN_simple >>
simp[boolean_eq_true] >>
simp[termsem_def] >>
simp[Abbr`vvx`,APPLY_UPDATE_THM] >>
simp[Abbr`vv`,APPLY_UPDATE_THM,Abbr`s`,UPDATE_LIST_THM] >>
qspecl_then[`sigof lca_ctxt`,`b0`,`tyin`]mp_tac termsem_INST >>
simp[IN_DEF] )
fun use_termsem_SUBSET f tyinq (g as (asl,w)) =
let
val tm = find_term(can(match_term``termsem s i v (Comb (Comb (Const (strlit"SUBSET") ty) a) b)``)) w