-
Notifications
You must be signed in to change notification settings - Fork 85
/
readerProofScript.sml
1804 lines (1672 loc) · 58.4 KB
/
readerProofScript.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
(*
Correctness proofs about the OpenTheory article checker's CakeML
implementation. In particular, anything the article checker proves
follows by logical inference in Candle's version of the HOL logic.
*)
open preamble ml_monadBaseTheory holKernelTheory holKernelProofTheory
holSyntaxTheory holSyntaxExtraTheory readerTheory reader_initTheory
TextIOProgTheory;
val _ = new_theory"readerProof";
Overload return[local] = “st_ex_return”;
Overload failwith[local] = “raise_Failure”;
val case_eq_thms =
CaseEqs ["prod", "exc", "hol_exn", "term", "thm",
"object", "option", "list", "update",
"mlstring", "state", "type", "sum",
"hol_refs", "command"]
(* -------------------------------------------------------------------------
* Reader does not raise Clash
* ------------------------------------------------------------------------- *)
Theorem find_axiom_not_clash[simp]:
find_axiom (a,b) c ≠ (M_failure (Clash tm),refs)
Proof
Cases_on `a`
\\ rw [find_axiom_def, st_ex_bind_def, raise_Failure_def, st_ex_return_def,
case_eq_thms, axioms_def, get_the_axioms_def, bool_case_eq]
\\ PURE_CASE_TAC \\ fs []
QED
Theorem pop_not_clash[simp]:
pop x y ≠ (M_failure (Clash tm),refs)
Proof
EVAL_TAC \\ rw[] \\ EVAL_TAC
QED
Theorem peek_not_clash[simp]:
peek x y ≠ (M_failure (Clash tm),refs)
Proof
EVAL_TAC \\ rw [] \\ EVAL_TAC
QED
Theorem getNum_not_clash[simp]:
getNum x y ≠ (M_failure (Clash tm),refs)
Proof
Cases_on`x` \\ EVAL_TAC
QED
Theorem getVar_not_clash[simp]:
getVar x y ≠ (M_failure (Clash tm),refs)
Proof
Cases_on`x` \\ EVAL_TAC
QED
Theorem getTerm_not_clash[simp]:
getTerm x y ≠ (M_failure (Clash tm),refs)
Proof
Cases_on`x` \\ EVAL_TAC
QED
Theorem getThm_not_clash[simp]:
getThm x y ≠ (M_failure (Clash tm),refs)
Proof
Cases_on`x` \\ EVAL_TAC
QED
Theorem getType_not_clash[simp]:
getType x y ≠ (M_failure (Clash tm),refs)
Proof
Cases_on`x` \\ EVAL_TAC
QED
Theorem getName_not_clash[simp]:
getName x y ≠ (M_failure (Clash tm),refs)
Proof
Cases_on`x` \\ EVAL_TAC
\\ fs [st_ex_return_def] \\ CASE_TAC \\ fs []
QED
Theorem getConst_not_clash[simp]:
getConst x y ≠ (M_failure (Clash tm),refs)
Proof
Cases_on`x` \\ EVAL_TAC
QED
Theorem getList_not_clash[simp]:
getList x y ≠ (M_failure (Clash tm),refs)
Proof
Cases_on `x` \\ EVAL_TAC
QED
Theorem getTypeOp_not_clash[simp]:
getTypeOp a b ≠ (M_failure (Clash tm),refs)
Proof
Cases_on`a` \\ EVAL_TAC
QED
Theorem getPair_not_clash[simp]:
getPair a b ≠ (M_failure (Clash tm),refs)
Proof
Cases_on `a` \\ EVAL_TAC \\ Cases_on `l` \\ EVAL_TAC
\\ Cases_on `t` \\ EVAL_TAC \\ Cases_on `t'` \\ EVAL_TAC
QED
Theorem getCns_not_clash[simp]:
getCns a b ≠ (M_failure (Clash tm),refs)
Proof
Cases_on `a` \\ EVAL_TAC \\ every_case_tac \\ fs []
QED
Theorem getNvs_not_clash[simp]:
getNvs a b ≠ (M_failure (Clash tm),refs)
Proof
Cases_on `a` \\ EVAL_TAC
\\ PURE_CASE_TAC \\ rw [case_eq_thms, UNCURRY]
\\ CCONTR_TAC \\ fs []
QED
Theorem getTms_not_clash[simp]:
getTms a b ≠ (M_failure (Clash tm),refs)
Proof
Cases_on `a` \\ EVAL_TAC
\\ PURE_CASE_TAC \\ rw [case_eq_thms, UNCURRY]
\\ CCONTR_TAC \\ fs []
QED
Theorem getTys_not_clash[simp]:
getTys a b ≠ (M_failure (Clash tm),refs)
Proof
Cases_on `a` \\ EVAL_TAC
\\ PURE_CASE_TAC \\ rw [case_eq_thms, UNCURRY]
\\ CCONTR_TAC \\ fs []
QED
Theorem BETA_CONV_not_clash[simp]:
BETA_CONV t s ≠ (M_failure (Clash tm),r)
Proof
rw [BETA_CONV_def, handle_Failure_def, st_ex_bind_def, raise_Failure_def]
\\ PURE_CASE_TAC \\ rw [case_eq_thms, UNCURRY]
\\ CCONTR_TAC \\ fs [] \\ rw [] \\ fs []
QED
Theorem readLine_not_clash[simp]:
∀c. readLine s c refs ≠ (M_failure (Clash tm),refs')
Proof
Cases
\\ simp [readLine_def, st_ex_bind_def, st_ex_return_def, raise_Failure_def,
handle_Clash_def, handle_Failure_def, ELIM_UNCURRY]
\\ strip_tac
\\ fs [case_eq_thms, map_not_clash_thm]
\\ rveq \\ fs []
\\ pop_assum mp_tac \\ fs []
\\ rpt (PURE_CASE_TAC \\ fs [])
QED
Theorem readLines_not_clash[simp]:
∀s ls refs tm refs'. readLines s ls refs ≠ (M_failure (Clash tm),refs')
Proof
recInduct readLines_ind
\\ strip_tac
\\ Cases \\ simp []
>- simp [readLines_def, st_ex_return_def]
\\ strip_tac
\\ simp [Once readLines_def]
\\ rw [handle_Failure_def, st_ex_bind_def, raise_Failure_def]
\\ fsrw_tac [SATISFY_ss, DNF_ss] [case_eq_thms]
QED
(* -------------------------------------------------------------------------
* reader_init does not raise Clash
* ------------------------------------------------------------------------- *)
Theorem mk_true_not_clash[simp]:
mk_true () refs ≠ (M_failure (Clash tm), refs')
Proof
rw [mk_true_def, st_ex_bind_def, st_ex_return_def, case_eq_thms]
QED
Theorem mk_univ_not_clash[simp]:
mk_univ ty refs ≠ (M_failure (Clash tm), refs')
Proof
rw [mk_univ_def, st_ex_bind_def, st_ex_return_def, case_eq_thms]
QED
Theorem mk_forall_not_clash[simp]:
mk_forall (v,p) refs ≠ (M_failure (Clash tm), refs')
Proof
rw [mk_forall_def, st_ex_bind_def, st_ex_return_def, case_eq_thms]
QED
Theorem mk_eta_ax_not_clash[simp]:
mk_eta_ax () refs ≠ (M_failure (Clash tm), refs')
Proof
rw [mk_eta_ax_def, st_ex_bind_def, st_ex_return_def, case_eq_thms]
QED
Theorem mk_conj_const_not_clash[simp]:
mk_conj_const () refs ≠ (M_failure (Clash tm), refs')
Proof
rw [mk_conj_const_def, st_ex_bind_def, st_ex_return_def, case_eq_thms]
QED
Theorem mk_conj_not_clash[simp]:
mk_conj (p,q) refs ≠ (M_failure (Clash tm), refs')
Proof
rw [mk_conj_def, st_ex_bind_def, st_ex_return_def, case_eq_thms]
QED
Theorem mk_imp_const_not_clash[simp]:
mk_imp_const () refs ≠ (M_failure (Clash tm), refs')
Proof
rw [mk_imp_const_def, st_ex_bind_def, st_ex_return_def, case_eq_thms]
QED
Theorem mk_imp_not_clash[simp]:
mk_imp (p,q) refs ≠ (M_failure (Clash tm), refs')
Proof
rw [mk_imp_def, st_ex_bind_def, st_ex_return_def, case_eq_thms]
QED
Theorem mk_select_ax_not_clash[simp]:
mk_select_ax () refs ≠ (M_failure (Clash tm), refs')
Proof
rw [mk_select_ax_def, st_ex_bind_def, st_ex_return_def, case_eq_thms]
QED
Theorem mk_ex_not_clash[simp]:
mk_ex ty refs ≠ (M_failure (Clash tm), refs')
Proof
rw [mk_ex_def, st_ex_bind_def, st_ex_return_def, case_eq_thms]
QED
Theorem mk_exists_not_clash[simp]:
mk_exists (v,p) refs ≠ (M_failure (Clash tm), refs')
Proof
rw [mk_exists_def, st_ex_bind_def, st_ex_return_def, case_eq_thms]
QED
Theorem mk_surj_not_clash[simp]:
mk_surj f a b refs ≠ (M_failure (Clash tm), refs')
Proof
rw [mk_surj_def, st_ex_bind_def, st_ex_return_def, case_eq_thms]
QED
Theorem mk_inj_not_clash[simp]:
mk_inj f a refs ≠ (M_failure (Clash tm), refs')
Proof
rw [mk_inj_def, st_ex_bind_def, st_ex_return_def, case_eq_thms]
QED
Theorem mk_false_not_clash[simp]:
mk_false () refs ≠ (M_failure (Clash tm), refs')
Proof
rw [mk_false_def, st_ex_bind_def, st_ex_return_def, case_eq_thms]
QED
Theorem mk_neg_const_not_clash[simp]:
mk_neg_const () refs ≠ (M_failure (Clash tm), refs')
Proof
rw [mk_neg_const_def, st_ex_bind_def, st_ex_return_def, case_eq_thms]
QED
Theorem mk_neg_not_clash[simp]:
mk_neg p refs ≠ (M_failure (Clash tm), refs')
Proof
rw [mk_neg_def, st_ex_bind_def, st_ex_return_def, case_eq_thms]
QED
Theorem mk_infinity_ax_not_clash[simp]:
mk_infinity_ax () refs ≠ (M_failure (Clash tm), refs')
Proof
rw [mk_infinity_ax_def, st_ex_bind_def, st_ex_return_def, case_eq_thms]
QED
Theorem init_reader_not_clash[simp]:
init_reader () refs ≠ (M_failure (Clash tm), refs')
Proof
rw [init_reader_def, st_ex_bind_def, st_ex_return_def, case_eq_thms,
select_sym_def, ind_type_def]
QED
(* -------------------------------------------------------------------------
* Refinement invariants
* ------------------------------------------------------------------------- *)
(* Refinement invariant for objects *)
Definition OBJ_def:
(OBJ defs (List xs) ⇔ EVERY (OBJ defs) xs) ∧
(OBJ defs (Type ty) ⇔ TYPE defs ty) ∧
(OBJ defs (Var (n, ty)) ⇔ TERM defs (Var n ty) ∧ TYPE defs ty) ∧
(OBJ defs (Term tm) ⇔ TERM defs tm) ∧
(OBJ defs (Thm th) ⇔ THM defs th) ∧
(OBJ defs _ ⇔ T)
Termination
WF_REL_TAC ‘measure (object_size o SND)’
\\ Induct \\ rw [object_size_def]
\\ res_tac \\ fs []
End
Theorem OBJ_APPEND_EXTEND:
∀defs obj d.
STATE (ds ++ defs) refs ∧
(∀th. THM defs th ⇒ THM (ds ++ defs) th) ∧
OBJ defs obj ⇒
OBJ (ds ++ defs) obj
Proof
recInduct OBJ_ind
\\ srw_tac [SATISFY_ss]
[OBJ_def, EVERY_MEM, TERM_APPEND_EXTEND, TYPE_APPEND_EXTEND]
QED
Definition READER_STATE_def:
READER_STATE defs st ⇔
EVERY (THM defs) st.thms ∧
EVERY (OBJ defs) st.stack ∧
(∀n obj.
lookup (Num n) st.dict = SOME obj ⇒
OBJ defs obj)
End
Theorem READER_STATE_EXTEND:
READER_STATE defs st ∧
THM defs th ⇒
READER_STATE defs (st with thms := th::st.thms)
Proof
rw [READER_STATE_def]
QED
Theorem READER_STATE_APPEND_EXTEND:
STATE (ds ++ defs) refs ∧
READER_STATE defs st ∧
(∀th. THM defs th ⇒ THM (ds ++ defs) th) ⇒
READER_STATE (ds ++ defs) st
Proof
srw_tac [SATISFY_ss]
[READER_STATE_def, OBJ_APPEND_EXTEND, EVERY_MEM]
QED
Theorem READER_STATE_CONS_EXTEND =
READER_STATE_APPEND_EXTEND
|> Q.INST [`ds`|->`[d]`]
|> SIMP_RULE list_ss [];
(* -------------------------------------------------------------------------
* Kernel function support theorems
* ------------------------------------------------------------------------- *)
Theorem first_EVERY:
∀Q xs x. EVERY P xs ∧ first Q xs = SOME x ⇒ P x
Proof
recInduct first_ind \\ rw [] \\ pop_assum mp_tac
\\ once_rewrite_tac [first_def]
\\ rw [case_eq_thms, PULL_EXISTS, bool_case_eq] \\ fs []
QED
Theorem axioms_thm:
axioms () refs = (res, refs') ∧
STATE defs refs ⇒
refs = refs' ∧
∀axs. res = M_success axs ⇒ EVERY (THM defs) axs
Proof
rw [axioms_def, get_the_axioms_def, STATE_def]
\\ fs [EVERY_MAP, lift_tm_def, CONTEXT_def, EVERY_MEM, MEM_MAP] \\ rw []
\\ fs [THM_def]
\\ (FIRST o map irule o rev o CONJUNCTS) proves_rules
\\ fsrw_tac [SATISFY_ss, DNF_ss]
[extends_theory_ok, init_theory_ok, MEM_FLAT, MEM_MAP]
QED
Theorem find_axiom_thm:
find_axiom (ls, tm) refs = (res, refs') ∧
STATE defs refs ∧
EVERY (TERM defs) ls ∧
TERM defs tm ⇒
refs = refs' ∧
∀thm. res = M_success thm ⇒ THM defs thm
Proof
rw [find_axiom_def, st_ex_bind_def, st_ex_return_def, raise_Failure_def,
case_eq_thms, PULL_EXISTS]
\\ dxrule_all axioms_thm \\ rw []
\\ FULL_CASE_TAC \\ fs [] \\ rveq
\\ dxrule_all first_EVERY \\ rw []
QED
Theorem assoc_ALOOKUP:
∀l s refs res refs'.
assoc s l refs = (res, refs') ⇒
refs = refs' ∧
∀t. res = M_success t ⇒ ALOOKUP l s = SOME t
Proof
Induct
\\ simp [Once assoc_def, FORALL_PROD, raise_Failure_def, st_ex_return_def]
\\ rw []
\\ fsrw_tac [SATISFY_ss] []
QED
Theorem type_of_thm:
∀tm refs res refs'.
type_of tm refs = (res, refs') ∧
STATE defs refs ∧
TERM defs tm ⇒
refs = refs' ∧
∀ty. res = M_success ty ⇒ TYPE defs ty ∧ welltyped tm
Proof
Induct
\\ rpt gen_tac
\\ strip_tac
\\ qhdtm_x_assum `type_of` mp_tac
\\ simp [Once type_of_def, st_ex_return_def, st_ex_bind_def, raise_Failure_def,
dest_type_def]
\\ fs [TERM_def, TYPE_def, type_ok_def, term_ok_def]
\\ rw [] \\ fs []
\\ fs [case_eq_thms, type_ok_def, mk_fun_ty_def, mk_type_def, st_ex_bind_def,
st_ex_return_def, raise_Failure_def, try_def, otherwise_def,
get_type_arity_def, get_the_type_constants_def]
\\ every_case_tac \\ fs [] \\ rveq
\\ first_x_assum drule_all \\ rw []
\\ fs [type_ok_def]
\\ drule_all assoc_ALOOKUP \\ rw []
\\ rfs [STATE_def, CONTEXT_def]
QED
Theorem get_const_type_thm:
get_const_type n refs = (res, refs') ∧
STATE defs refs ⇒
refs = refs' ∧
∀ty. res = M_success ty ⇒ TYPE defs ty
Proof
rw [get_const_type_def, st_ex_bind_def, st_ex_return_def,
get_the_term_constants_def]
\\ imp_res_tac the_term_constants_TYPE
\\ fs [ELIM_UNCURRY, GSYM o_DEF]
\\ drule_all assoc_thm \\ rw []
\\ fsrw_tac [SATISFY_ss] [EVERY_MEM, FORALL_PROD]
QED
Theorem tymatch_thm:
∀tys1 tys2 sids.
tymatch tys1 tys2 sids = SOME (tys, _) ∧
EVERY (TYPE defs) tys1 ∧
EVERY (TYPE defs) tys2 ∧
EVERY (λ(t1,t2). TYPE defs t1 ∧ TYPE defs t2) (FST sids) ⇒
EVERY (λ(t1,t2). TYPE defs t1 ∧ TYPE defs t2) tys
Proof
recInduct tymatch_ind
\\ simp [FORALL_PROD] \\ rw []
\\ qhdtm_x_assum `tymatch` mp_tac
\\ rw [Once tymatch_def] \\ fs []
\\ pop_assum irule
\\ fsrw_tac [SATISFY_ss] [TYPE_def, type_ok_def, EVERY_MEM]
QED
Theorem match_type_thm:
match_type ty1 ty2 = SOME tys ∧
TYPE defs ty1 ∧
TYPE defs ty2 ⇒
EVERY (λ(t1,t2). TYPE defs t1 ∧ TYPE defs t2) tys
Proof
rw [holSyntaxExtraTheory.match_type_def]
\\ PairCases_on ‘z’ \\ fs []
\\ imp_res_tac tymatch_thm \\ rfs []
QED
Theorem TERM_Comb:
TERM defs (Comb a b) ⇒
TERM defs a ∧
TERM defs b
Proof
rw [TERM_def, term_ok_def]
QED
Theorem TERM_Abs:
TERM defs (Abs v e) ⇒
TERM defs v ∧
TERM defs e
Proof
rw [TERM_def] \\ fs [term_ok_def]
QED
(* ------------------------------------------------------------------------- *)
(* Reader operations preserve invariants *)
(* ------------------------------------------------------------------------- *)
Theorem next_line_thm:
READER_STATE defs s ⇒
READER_STATE defs (next_line s)
Proof
rw [READER_STATE_def, next_line_def]
QED
Theorem getNum_thm:
getNum obj refs = (res, refs') ⇒
refs = refs'
Proof
Cases_on ‘obj’
\\ rw [getNum_def, raise_Failure_def, st_ex_return_def]
\\ fs []
QED
Theorem getName_thm:
getName obj refs = (res, refs') ⇒
refs = refs'
Proof
Cases_on ‘obj’
\\ rw [getName_def, raise_Failure_def, st_ex_return_def]
\\ fs []
QED
Theorem getList_thm:
getList obj refs = (res, refs') ∧
OBJ defs obj ⇒
refs = refs' ∧
∀ls. res = M_success ls ⇒ EVERY (OBJ defs) ls
Proof
Cases_on ‘obj’
\\ rw [getList_def, raise_Failure_def, st_ex_return_def, OBJ_def]
\\ fsrw_tac [ETA_ss] [OBJ_def]
QED
Theorem getTypeOp_thm:
getTypeOp obj refs = (res, refs') ⇒
refs = refs'
Proof
Cases_on ‘obj’
\\ rw [getTypeOp_def, raise_Failure_def, st_ex_return_def]
\\ fs []
QED
Theorem getType_thm:
getType obj refs = (res, refs') ∧
OBJ defs obj ⇒
refs = refs' ∧
∀ty. res = M_success ty ⇒ TYPE defs ty
Proof
Cases_on ‘obj’
\\ rw [getType_def, raise_Failure_def, st_ex_return_def]
\\ fs [OBJ_def]
QED
Theorem map_getType_thm:
∀xs refs res refs'.
map getType xs refs = (res, refs') ∧
EVERY (OBJ defs) xs ⇒
refs = refs' ∧
∀tys. res = M_success tys ⇒ EVERY (TYPE defs) tys
Proof
Induct
\\ rw [Once map_def, st_ex_return_def, st_ex_bind_def]
\\ fs [case_eq_thms] \\ rveq
\\ drule_all getType_thm \\ rw []
\\ first_x_assum drule_all \\ rw []
QED
Theorem getConst_thm:
getConst obj refs = (res, refs') ⇒
refs = refs'
Proof
Cases_on ‘obj’
\\ rw [getConst_def, raise_Failure_def, st_ex_return_def]
\\ fs []
QED
Theorem getVar_thm:
getVar obj refs = (res, refs') ∧
OBJ defs obj ⇒
refs = refs' ∧
∀n ty.
res = M_success (n, ty) ⇒
TERM defs (Var n ty) ∧
TYPE defs ty
Proof
Cases_on ‘obj’
\\ rw [getVar_def, raise_Failure_def, st_ex_return_def]
\\ fs [OBJ_def]
QED
Theorem getTerm_thm:
getTerm obj refs = (res, refs') ∧
OBJ defs obj ⇒
refs = refs' ∧
∀tm. res = M_success tm ⇒ TERM defs tm
Proof
Cases_on ‘obj’
\\ rw [getTerm_def, raise_Failure_def, st_ex_return_def] \\ fs []
\\ fs [OBJ_def]
QED
Theorem map_getTerm_thm:
∀xs refs res refs'.
map getTerm xs refs = (res, refs') ∧
EVERY (OBJ defs) xs ⇒
refs = refs' ∧
∀tms. res = M_success tms ⇒ EVERY (TERM defs) tms
Proof
Induct
\\ rw [Once map_def, st_ex_return_def, st_ex_bind_def, case_eq_thms]
\\ fs []
\\ drule_all getTerm_thm \\ rw []
\\ first_x_assum drule_all \\ rw []
QED
Theorem getThm_thm:
getThm obj refs = (res, refs') ∧
OBJ defs obj ⇒
refs = refs' ∧
∀thm. res = M_success thm ⇒ THM defs thm
Proof
Cases_on ‘obj’
\\ rw [getThm_def, raise_Failure_def, st_ex_return_def]
\\ fs [OBJ_def]
QED
Theorem pop_thm:
pop st refs = (res, refs') ∧
READER_STATE defs st ⇒
refs = refs' ∧
∀a st'.
res = M_success (a, st') ⇒
OBJ defs a ∧
READER_STATE defs st'
Proof
rw [pop_def, raise_Failure_def, st_ex_return_def]
\\ Cases_on `st.stack`
\\ fsrw_tac [SATISFY_ss] [READER_STATE_def, state_component_equality]
\\ rfs []
QED
Theorem peek_thm:
peek st refs = (res, refs') ∧
READER_STATE defs st ⇒
refs = refs' ∧
∀obj. res = M_success obj ⇒ OBJ defs obj
Proof
rw [peek_def, raise_Failure_def, st_ex_return_def]
\\ Cases_on `st.stack`
\\ fs [READER_STATE_def]
\\ rw []
QED
Theorem push_thm:
READER_STATE defs st ∧
OBJ defs obj ⇒
READER_STATE defs (push obj st)
Proof
rw [push_def, READER_STATE_def]
QED
Theorem insert_dict_thm:
READER_STATE defs st ∧
OBJ defs obj ⇒
READER_STATE defs (insert_dict (Num n) obj st)
Proof
rw [insert_dict_def, READER_STATE_def, lookup_insert]
\\ pop_assum mp_tac
\\ IF_CASES_TAC \\ rw []
\\ fsrw_tac [SATISFY_ss] []
QED
Theorem delete_dict_thm:
READER_STATE defs st ⇒
READER_STATE defs (delete_dict (Num n) st)
Proof
rw [delete_dict_def, READER_STATE_def, lookup_delete]
\\ fsrw_tac [SATISFY_ss] []
QED
Theorem getPair_thm:
∀obj refs res refs'.
getPair obj refs = (res, refs') ∧
OBJ defs obj ⇒
refs = refs' ∧
∀a b.
res = M_success (a, b) ⇒
OBJ defs a ∧
OBJ defs b
Proof
ho_match_mp_tac getPair_ind
\\ simp [getPair_def, raise_Failure_def, st_ex_return_def, OBJ_def]
QED
Theorem getTys_thm:
∀obj refs res refs'.
getTys obj refs = (res, refs') ∧
STATE defs refs ∧
OBJ defs obj ⇒
refs = refs' ∧
∀t ty.
res = M_success (t, ty) ⇒
TYPE defs t ∧
TYPE defs ty
Proof
ho_match_mp_tac getPair_ind
\\ simp [getPair_def, raise_Failure_def, st_ex_return_def, OBJ_def,
getTys_def, st_ex_bind_def, case_eq_thms]
\\ rw []
\\ drule_all getName_thm \\ rw []
\\ drule_all getType_thm \\ rw []
\\ irule mk_vartype_thm
\\ fsrw_tac [SATISFY_ss] []
QED
Theorem map_getTys_thm:
∀xs refs res refs'.
map getTys xs refs = (res, refs') ∧
STATE defs refs ∧
EVERY (OBJ defs) xs ⇒
refs = refs' ∧
∀tys.
res = M_success tys ⇒
EVERY (λ(ty1,ty2). TYPE defs ty1 ∧ TYPE defs ty2) tys
Proof
Induct \\ rw []
\\ qhdtm_x_assum `map` mp_tac
\\ rw [Once map_def, st_ex_bind_def, st_ex_return_def] \\ fs []
\\ fs [case_eq_thms] \\ rw []
\\ drule_all getTys_thm \\ rw []
\\ fs [quantHeuristicsTheory.PAIR_EQ_EXPAND, UNCURRY]
\\ first_x_assum drule_all \\ rw []
QED
Theorem getTms_thm:
∀obj refs res refs'.
getTms obj refs = (res, refs') ∧
STATE defs refs ∧
OBJ defs obj ⇒
refs = refs' ∧
∀tm var.
res = M_success (tm, var) ⇒
TERM defs tm ∧
TERM defs var
Proof
Cases
\\ simp [getTms_def, LAMBDA_PROD, st_ex_return_def, st_ex_bind_def,
raise_Failure_def, getPair_def, case_eq_thms, EXISTS_PROD]
\\ rw []
\\ drule_all getPair_thm \\ rw []
\\ drule_all getVar_thm \\ rw []
\\ drule_all getTerm_thm \\ rw []
\\ fsrw_tac [SATISFY_ss] [mk_var_thm]
QED
Theorem map_getTms_thm:
∀xs refs res refs'.
map getTms xs refs = (res, refs') ∧
STATE defs refs ∧
EVERY (OBJ defs) xs ⇒
refs = refs' ∧
∀tmvs.
res = M_success tmvs ⇒
EVERY (λ(tm1,tm2). TERM defs tm1 ∧ TERM defs tm2) tmvs
Proof
Induct \\ rw []
\\ qhdtm_x_assum `map` mp_tac
\\ simp [Once map_def, LAMBDA_PROD, st_ex_bind_def, st_ex_return_def,
case_eq_thms, EXISTS_PROD]
\\ rw []
\\ drule_all getTms_thm \\ rw []
\\ fsrw_tac [SATISFY_ss] []
QED
Theorem getNvs_thm:
getNvs obj refs = (res, refs') ∧
STATE defs refs ∧
OBJ defs obj ⇒
refs = refs' ∧
∀tm1 tm2.
res = M_success (tm1, tm2) ⇒
TERM defs tm1 ∧
TERM defs tm2
Proof
Cases_on ‘obj’
\\ simp [getNvs_def, LAMBDA_PROD, st_ex_bind_def, st_ex_return_def,
raise_Failure_def, getPair_def, case_eq_thms, EXISTS_PROD]
\\ rw []
\\ drule_all getPair_thm \\ rw []
\\ drule_all getName_thm \\ rw []
\\ drule_all getVar_thm \\ rw []
\\ fsrw_tac [SATISFY_ss] [mk_var_thm]
QED
Theorem map_getNvs_thm:
∀xs refs res refs'.
map getNvs xs refs = (res, refs') ∧
STATE defs refs ∧
EVERY (OBJ defs) xs ⇒
refs = refs' ∧
∀ts.
res = M_success ts ⇒
EVERY (λ(t1,t2). TERM defs t1 ∧ TERM defs t2) ts
Proof
Induct
\\ simp [Once map_def, LAMBDA_PROD, st_ex_return_def, st_ex_bind_def,
case_eq_thms, EXISTS_PROD]
\\ rw []
\\ drule_all getNvs_thm \\ rw []
\\ fsrw_tac [SATISFY_ss] []
QED
Theorem getCns_thm:
getCns (tm, _) refs = (res, refs') ∧
STATE defs refs ∧
TERM defs tm ⇒
refs = refs' ∧
∀a. res = M_success a ⇒ OBJ defs a
Proof
rw [getCns_def, st_ex_bind_def, st_ex_return_def, UNCURRY, case_eq_thms]
\\ fsrw_tac [SATISFY_ss] [dest_var_thm, OBJ_def]
QED
Theorem map_getCns_thm:
∀xs refs res refs'.
map getCns xs refs = (res, refs') ∧
STATE defs refs ∧
EVERY (TERM defs o FST) xs ⇒
refs = refs' ∧
∀xs. res = M_success xs ⇒ EVERY (OBJ defs) xs
Proof
Induct
\\ simp [Once map_def, LAMBDA_PROD, st_ex_return_def, st_ex_bind_def,
case_eq_thms, FORALL_PROD]
\\ rw []
\\ drule_all getCns_thm \\ rw []
\\ fsrw_tac [SATISFY_ss] []
QED
Theorem BETA_CONV_thm:
∀tm refs res refs'.
BETA_CONV tm refs = (res, refs') ∧
STATE defs refs ∧
TERM defs tm ⇒
refs = refs' ∧
∀thm. res = M_success thm ⇒ THM defs thm
Proof
Cases
\\ simp [BETA_CONV_def, LAMBDA_PROD, handle_Failure_def, raise_Failure_def,
st_ex_bind_def, st_ex_return_def, case_eq_thms, dest_comb_def,
dest_abs_def, EXISTS_PROD]
\\ rw []
\\ dxrule_then drule_all BETA_thm \\ rw []
\\ Cases_on `t` \\ fs [] \\ rveq
\\ drule TERM_Comb \\ rw []
\\ drule TERM_Abs \\ rw []
\\ drule_all mk_comb_thm \\ rw []
\\ drule_all BETA_thm \\ rw []
\\ drule INST_thm \\ simp []
\\ disch_then drule \\ rw []
QED
(* ------------------------------------------------------------------------- *)
(* Reader preserves invariants *)
(* ------------------------------------------------------------------------- *)
Theorem PROP_APPEND_EXISTS[local] =
METIS_PROVE [APPEND] “P x y ⇒ ∃z. P ((z: 'a list) ++ x) y”
Theorem PROP_APPEND_EXISTS2[local] =
METIS_PROVE [APPEND] “P x y ∧ Q x w ⇒
∃z. P ((z: 'a list) ++ x) y ∧ Q (z ++ x) w”
fun fsp ths =
fsrw_tac [SATISFY_ss]
(PROP_APPEND_EXISTS::
PROP_APPEND_EXISTS2::ths);
Theorem readLine_thm:
readLine st cmd refs = (res, refs') ∧
STATE defs refs ∧
READER_STATE defs st ⇒
∃ds.
STATE (ds ++ defs) refs' ∧
∀st'. res = M_success st' ⇒ READER_STATE (ds ++ defs) st'
Proof
simp [readLine_def, st_ex_bind_def, st_ex_return_def, raise_Failure_def,
LAMBDA_PROD, EXISTS_PROD, FORALL_PROD]
\\ Cases_on ‘cmd = version’ \\ simp []
>-
(rw [case_eq_thms, LAMBDA_PROD, EXISTS_PROD]
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_all getNum_thm \\ rw [] \\ fsp [])
\\ Cases_on ‘cmd = absTerm’ \\ simp []
>-
(rw [case_eq_thms, LAMBDA_PROD, EXISTS_PROD]
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all getTerm_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all getVar_thm \\ rw [] \\ fsp []
\\ dxrule_then (qspec_then `defs` mp_tac) mk_abs_thm
\\ imp_res_tac mk_var_thm \\ fsp [] \\ rw []
\\ fsp [push_thm, OBJ_def])
\\ Cases_on ‘cmd = absThm’ \\ simp []
>-
(rw [case_eq_thms, LAMBDA_PROD, EXISTS_PROD]
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all getThm_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all getVar_thm \\ rw [] \\ fsp []
\\ drule_then (qspec_then `defs` mp_tac) ABS_thm
\\ imp_res_tac mk_var_thm \\ fsp [] \\ rw []
\\ fsp [push_thm, OBJ_def])
\\ Cases_on ‘cmd = appTerm’ \\ simp []
>-
(rw [case_eq_thms, LAMBDA_PROD, EXISTS_PROD]
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all getTerm_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all getTerm_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all mk_comb_thm \\ rw [] \\ fsp []
\\ fsp [push_thm, OBJ_def])
\\ Cases_on ‘cmd = appThm’ \\ simp []
>-
(rw [case_eq_thms, LAMBDA_PROD, EXISTS_PROD]
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all getThm_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all getThm_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all MK_COMB_thm \\ rw [] \\ fsp []
\\ fsp [push_thm, OBJ_def])
\\ Cases_on ‘cmd = assume’ \\ simp []
>-
(rw [case_eq_thms, LAMBDA_PROD, EXISTS_PROD]
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all getTerm_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all ASSUME_thm \\ rw [] \\ fsp []
\\ fsp [push_thm, OBJ_def])
\\ Cases_on ‘cmd = axiom’ \\ simp []
>-
(rw [case_eq_thms, LAMBDA_PROD, EXISTS_PROD]
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all getTerm_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all getList_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all map_getTerm_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all find_axiom_thm \\ rw [] \\ fsp []
\\ fsp [OBJ_def, push_thm])
\\ Cases_on ‘cmd = betaConv’ \\ simp []
>-
(rw [case_eq_thms, LAMBDA_PROD, EXISTS_PROD]
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all getTerm_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all BETA_CONV_thm \\ rw [] \\ fsp []
\\ fsp [OBJ_def, push_thm])
\\ Cases_on `cmd = cons` \\ simp []
>-
(rw [case_eq_thms, LAMBDA_PROD, EXISTS_PROD]
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all getList_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ qexists_tac ‘[]’ \\ simp []
\\ irule push_thm
\\ fsrw_tac [ETA_ss] [OBJ_def])
\\ Cases_on ‘cmd = const’ \\ simp []
>-
(rw [case_eq_thms, LAMBDA_PROD, EXISTS_PROD]
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_all getName_thm \\ rw [] \\ fsp []
\\ fsp [push_thm, OBJ_def])
\\ Cases_on ‘cmd = constTerm’ \\ simp []
>-
(rw [case_eq_thms, LAMBDA_PROD, EXISTS_PROD]
\\ TRY FULL_CASE_TAC \\ fs []
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all getType_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_all getConst_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all get_const_type_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all match_type_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all mk_const_thm \\ rw [] \\ fsp []
\\ fsp [push_thm, OBJ_def])
\\ Cases_on ‘cmd = deductAntisym’ \\ simp []
>-
(rw [case_eq_thms, LAMBDA_PROD, EXISTS_PROD]
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all getThm_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all getThm_thm \\ rw [] \\ fsp []
\\ drule_then drule_all DEDUCT_ANTISYM_RULE_thm \\ rw [] \\ fsp []
\\ fsp [OBJ_def, push_thm])
\\ Cases_on ‘cmd = def’ \\ simp []
>-
(rw [case_eq_thms, LAMBDA_PROD, EXISTS_PROD]
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ Cases_on `n < 0` \\ fs []
\\ dxrule_all getNum_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all peek_thm \\ rw [] \\ fsp []
\\ fsp [insert_dict_thm, OBJ_def])
\\ Cases_on ‘cmd = defineConst’ \\ simp []
>-
(rw [case_eq_thms, LAMBDA_PROD, EXISTS_PROD]
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all getTerm_thm \\ rw [] \\ fsp []
\\ dxrule_then drule_all pop_thm \\ rw [] \\ fsp []
\\ dxrule_all getName_thm \\ rw [] \\ fsp []
\\ drule_all type_of_thm \\ rw [] \\ fsp []
\\ dxrule_then (qspec_then ‘defs’ mp_tac) mk_eq_thm \\ fsp [mk_var_thm]
\\ rw []
\\ drule_all new_basic_definition_thm \\ rw [] \\ fsp []
\\ qexists_tac ‘[d]’ \\ simp []