-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathpan_simpProofScript.sml
1247 lines (1173 loc) · 37.3 KB
/
pan_simpProofScript.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 proof for pan_simp
*)
open preamble
panSemTheory pan_simpTheory panPropsTheory
val _ = new_theory "pan_simpProof";
val _ = set_grammar_ancestry ["panSem", "pan_simp", "panProps"];
val s = ``s:('a,'ffi) panSem$state``
Theorem exp_ids_ret_to_tail_eq:
!p. exp_ids (ret_to_tail p) = exp_ids p
Proof
ho_match_mp_tac ret_to_tail_ind >> rw [] >>
fs [ret_to_tail_def, panLangTheory.exp_ids_def]
>- (
fs [seq_call_ret_def] >>
every_case_tac >> fs [panLangTheory.exp_ids_def]) >>
every_case_tac >> fs [panLangTheory.exp_ids_def]
QED
Theorem exp_ids_seq_assoc_eq:
!p q. exp_ids (seq_assoc p q) = exp_ids p ++ exp_ids q
Proof
ho_match_mp_tac seq_assoc_ind >> rw [] >>
fs [seq_assoc_def, panLangTheory.exp_ids_def] >>
every_case_tac >> fs [seq_assoc_def, panLangTheory.exp_ids_def]
QED
Theorem exp_ids_compile_eq:
!p. exp_ids (compile p) = exp_ids p
Proof
rw [] >>
fs [compile_def] >>
fs [exp_ids_ret_to_tail_eq, exp_ids_seq_assoc_eq,
panLangTheory.exp_ids_def]
QED
Theorem map_snd_f_eq:
!p f g. MAP (g ∘ SND ∘ SND ∘ (λ(name,params,body). (name,params,f body))) p =
MAP (g ∘ f) (MAP (SND ∘ SND) p)
Proof
Induct >> rw [] >>
cases_on ‘h’ >> fs [] >>
cases_on ‘r’ >> fs []
QED
Theorem size_of_eids_compile_eq:
!pan_code.
size_of_eids (compile_prog pan_code) =
size_of_eids pan_code
Proof
rw [] >>
fs [panLangTheory.size_of_eids_def] >>
fs [pan_simpTheory.compile_prog_def] >>
qmatch_goalsub_abbrev_tac ‘remove_dup (FLAT es)’ >>
qmatch_goalsub_abbrev_tac ‘_ = LENGTH
(remove_dup (FLAT ces))’ >>
qsuff_tac ‘es = ces’
>- fs [] >>
fs [Abbr ‘es’, Abbr ‘ces’, pan_simpTheory.compile_prog_def] >>
fs [MAP_MAP_o] >>
fs [map_snd_f_eq] >>
fs [MAP_EQ_EVERY2, LIST_REL_EL_EQN] >>
rw [] >>
‘EL n (MAP (SND ∘ SND) pan_code) =
(SND ∘ SND) (EL n pan_code)’ by (
match_mp_tac EL_MAP >>
fs []) >>
fs [] >>
fs [exp_ids_compile_eq]
QED
Theorem evaluate_SmartSeq:
evaluate (SmartSeq p q,s) = evaluate (Seq p q,^s)
Proof
rw [SmartSeq_def, evaluate_def]
QED
Theorem evaluate_seq_skip:
!p s. evaluate (Seq p Skip,s) = evaluate (p,^s)
Proof
Induct >> fs [Once evaluate_def] >> rw [] >>
rpt (pairarg_tac >> fs [] >> rw [evaluate_def] >> fs [])
QED
Theorem evaluate_skip_seq:
evaluate (Seq Skip p,s) = evaluate (p,^s)
Proof
fs [evaluate_def]
QED
Theorem evaluate_while_body_same:
(!(s:('a,'b)state). evaluate (body,s) = evaluate (body',s)) ==>
!(s:('a,'b)state). evaluate (While e body,s) = evaluate (While e body',s)
Proof
rw [] >> completeInduct_on ‘s.clock’ >>
rw [] >> fs [PULL_EXISTS,PULL_FORALL] >>
once_rewrite_tac [evaluate_def] >>
TOP_CASE_TAC >> fs [] >>
TOP_CASE_TAC >> fs [] >>
TOP_CASE_TAC >> fs [] >>
TOP_CASE_TAC >> fs [] >>
rpt (pairarg_tac >> fs [] >> rveq) >>
last_x_assum (qspec_then ‘s’ mp_tac) >>
fs [] >> rw [] >>
every_case_tac >>
imp_res_tac evaluate_clock >>
fs [dec_clock_def]
QED
Theorem evaluate_while_no_error_imp:
eval s e = SOME (ValWord w) /\
w <> 0w /\ s.clock <> 0 /\
FST (evaluate (While e c,s)) <> SOME Error ==>
FST (evaluate (c,dec_clock s)) <> SOME Error
Proof
rw [] >>
pop_assum mp_tac >>
once_rewrite_tac [evaluate_def] >>
TOP_CASE_TAC >> fs [] >>
pairarg_tac >> fs [] >> rveq >>
every_case_tac >> fs []
QED
Theorem evaluate_seq_assoc:
!p q s. evaluate (seq_assoc p q,s) = evaluate (Seq p q,^s)
Proof
ho_match_mp_tac seq_assoc_ind >> rw [] >>
fs [evaluate_seq_skip, seq_assoc_def] >>
TRY (
rename1 ‘While’ >>
TOP_CASE_TAC >> fs [] >> rveq >>
fs [evaluate_skip_seq]
>- metis_tac [evaluate_while_body_same] >>
once_rewrite_tac [evaluate_def] >> fs [] >>
rpt (pairarg_tac >> fs [] >> rveq) >>
TOP_CASE_TAC >> fs [] >>
metis_tac [evaluate_while_body_same]) >>
gvs [evaluate_def] >> rpt (pairarg_tac >> fs [] >> rw [] >> gvs[]) >>
every_case_tac >> gvs [evaluate_skip_seq, evaluate_def] >>
every_case_tac >> gvs [evaluate_skip_seq, evaluate_def]
QED
Theorem evaluate_seq_call_ret_eq:
!p s.
FST (evaluate (p,s)) <> SOME Error ==>
evaluate (seq_call_ret p,s) = evaluate (p,s)
Proof
rw [seq_call_ret_def] >>
every_case_tac >> fs [] >> rveq >>
fs [evaluate_def] >>
pairarg_tac >> fs [] >>
every_case_tac >> fs [] >> rveq >>
TRY (metis_tac [] >> NO_TAC) >>
fs [empty_locals_def, set_var_def] >>
fs [eval_def, FLOOKUP_UPDATE]
QED
Theorem evaluate_seq_no_error_fst:
FST (evaluate (Seq p p',s)) ≠ SOME Error ==>
FST (evaluate (p,s)) ≠ SOME Error
Proof
rw [evaluate_def] >>
rpt (pairarg_tac >> fs []) >>
every_case_tac >> fs[]
QED
Theorem eval_seq_assoc_eq_evaluate:
evaluate ((seq_assoc Skip p),s) = (res, t) ==>
evaluate (p,s) = (res, t)
Proof
rw [] >>
fs [evaluate_seq_assoc] >>
fs [evaluate_def]
QED
Theorem eval_seq_assoc_not_error:
FST (evaluate (p,s)) ≠ SOME Error ==>
FST (evaluate ((seq_assoc Skip p),s)) ≠ SOME Error
Proof
rw [evaluate_seq_assoc] >>
rw [evaluate_def]
QED
val goal =
``λ(prog, s).
FST (evaluate (prog,s)) <> SOME Error ==>
evaluate (ret_to_tail prog, s) = evaluate (prog,s)``
local
val ind_thm = panSemTheory.evaluate_ind
|> ISPEC goal
|> CONV_RULE (DEPTH_CONV PairRules.PBETA_CONV) |> REWRITE_RULE [];
fun list_dest_conj tm = if not (is_conj tm) then [tm] else let
val (c1,c2) = dest_conj tm in list_dest_conj c1 @ list_dest_conj c2 end
val ind_goals = ind_thm |> concl |> dest_imp |> fst |> list_dest_conj
in
fun get_goal s = first (can (find_term (can (match_term (Term [QUOTE s]))))) ind_goals
fun ret_to_tail_tm () = ind_thm |> concl |> rand
fun the_ind_thm () = ind_thm
end
Theorem ret_to_tail_Dec:
^(get_goal "panLang$Dec")
Proof
rw [ret_to_tail_def] >>
fs [evaluate_def] >>
TOP_CASE_TAC >> fs [] >>
rpt (pairarg_tac >> fs [] >> rveq)
QED
Theorem ret_to_tail_Seq:
^(get_goal "panLang$Seq")
Proof
rw [ret_to_tail_def] >>
qmatch_goalsub_abbrev_tac ‘seq_call_ret sprog’ >>
‘evaluate (seq_call_ret sprog,s) = evaluate (sprog,s)’ by (
ho_match_mp_tac evaluate_seq_call_ret_eq >>
unabbrev_all_tac >>
imp_res_tac evaluate_seq_no_error_fst >> fs [] >>
fs [evaluate_def] >>
pairarg_tac >> fs [] >>
TOP_CASE_TAC >> fs []) >>
fs [] >> pop_assum kall_tac >>
unabbrev_all_tac >>
rw [evaluate_def] >>
rpt (pairarg_tac >> fs []) >>
every_case_tac >> fs [] >> rveq >>
fs [evaluate_def]
QED
Theorem ret_to_tail_If:
^(get_goal "panLang$If")
Proof
rw [ret_to_tail_def] >>
fs [evaluate_def] >>
every_case_tac >> fs [] >>
rpt (pairarg_tac >> fs [] >> rveq)
QED
Theorem ret_to_tail_While:
^(get_goal "panLang$While")
Proof
rw [] >>
fs [ret_to_tail_def] >>
once_rewrite_tac [evaluate_def] >>
TOP_CASE_TAC >> fs [] >>
TOP_CASE_TAC >> fs [] >>
TOP_CASE_TAC >> fs [] >>
TOP_CASE_TAC >> fs [] >>
TOP_CASE_TAC >> fs [] >>
drule evaluate_while_no_error_imp >>
disch_then (qspec_then ‘c’ mp_tac) >>
rw [] >> fs [] >>
rpt (pairarg_tac >> fs [] >> rveq) >>
every_case_tac >> fs [] >>
‘FST (evaluate (While e c,s1)) ≠ SOME Error’ by
fs [Once evaluate_def] >>
fs []
QED
Theorem ret_to_tail_Call:
^(get_goal "panLang$Call")
Proof
rw [] >>
fs [ret_to_tail_def, evaluate_def] >>
every_case_tac >>
fs [evaluate_def, ret_to_tail_def]
QED
Theorem ret_to_tail_DecCall:
^(get_goal "panLang$DecCall")
Proof
rw [] >>
fs [ret_to_tail_def, evaluate_def] >>
every_case_tac >>
fs [evaluate_def, ret_to_tail_def,UNCURRY_eq_pair,PULL_EXISTS] >>
pairarg_tac >> gvs[]
QED
Theorem ret_to_tail_Others:
^(get_goal "panLang$Skip") /\
^(get_goal "panLang$Assign") /\
^(get_goal "panLang$Store") /\
^(get_goal "panLang$StoreByte") /\
^(get_goal "panLang$Break") /\
^(get_goal "panLang$Continue") /\
^(get_goal "panLang$ExtCall") /\
^(get_goal "panLang$Raise") /\
^(get_goal "panLang$ShMemLoad") /\
^(get_goal "panLang$ShMemStore") /\
^(get_goal "panLang$Return") /\
^(get_goal "panLang$Annot") /\
^(get_goal "panLang$Tick")
Proof
rw [ret_to_tail_def]
QED
Theorem ret_to_tail_correct:
^(ret_to_tail_tm())
Proof
match_mp_tac (the_ind_thm()) >>
EVERY (map strip_assume_tac
[ret_to_tail_Dec, ret_to_tail_Seq,
ret_to_tail_If, ret_to_tail_While, ret_to_tail_Call,
ret_to_tail_DecCall, ret_to_tail_Others]) >>
asm_rewrite_tac [] >> rw [] >> rpt (pop_assum kall_tac)
QED
Theorem compile_correct_same_state:
FST (evaluate (p,s)) <> SOME Error ==>
evaluate (compile p, s) = evaluate (p,s)
Proof
rw [compile_def] >>
dxrule eval_seq_assoc_not_error >> strip_tac >>
imp_res_tac ret_to_tail_correct >> fs [] >>
rw [evaluate_seq_assoc, evaluate_def]
QED
Theorem evaluate_seq_simp:
evaluate (p,s) = (res, t) /\ res <> SOME Error ==>
evaluate (compile p, s) = (res,t)
Proof
fs [compile_correct_same_state]
QED
Definition state_rel_def:
state_rel s t c <=>
(t = s with code := c) /\
(∀f.
FLOOKUP s.code f = NONE ==>
FLOOKUP c f = NONE) /\
(∀f vshs prog.
FLOOKUP s.code f = SOME (vshs, prog) ==>
FLOOKUP c f = SOME (vshs, pan_simp$compile prog))
End
Theorem state_rel_intro:
!s t c. state_rel s t c ==>
(t = s with code := c) /\
(∀f vshs prog.
FLOOKUP s.code f = SOME (vshs, prog) ==>
FLOOKUP c f = SOME (vshs, pan_simp$compile prog))
Proof
rw [state_rel_def]
QED
Theorem compile_eval_correct:
∀s e v t.
eval s e = SOME v /\
state_rel s t t.code ==>
eval t e = SOME v
Proof
ho_match_mp_tac panSemTheory.eval_ind >>
rpt conj_tac >> rpt gen_tac >> strip_tac
>- (
rename [‘Const w’] >>
fs [panSemTheory.eval_def])
>- (
rename [‘eval s (Var vname)’] >>
fs [panSemTheory.eval_def] >> rveq >>
fs [state_rel_def, state_component_equality])
>- (
rename [‘eval s (Label fname)’] >>
fs [panSemTheory.eval_def, option_case_eq] >> rveq >>
cases_on ‘v1’ >>
fs [state_rel_def, state_component_equality] >>
res_tac >> fs [])
>- (
rename [‘eval s (Struct es)’] >>
rpt gen_tac >> strip_tac >> fs [] >>
fs [panSemTheory.eval_def, option_case_eq] >> rveq >>
rpt (pop_assum mp_tac) >>
MAP_EVERY qid_spec_tac [‘vs’, ‘es’] >>
Induct >>
rpt gen_tac >> strip_tac >> fs [OPT_MMAP_def] >>
rewrite_tac [AND_IMP_INTRO] >> strip_tac >> rveq >>
rename [‘_ = SOME vs’] >>
fs [])
>- (
rename [‘eval s (Field index e)’] >>
rpt gen_tac >> strip_tac >> fs [] >>
fs [panSemTheory.eval_def, option_case_eq, v_case_eq] >> rveq >>
fs [])
>- (
rename [‘eval s (Load sh e)’] >>
rpt gen_tac >> strip_tac >>
fs [panSemTheory.eval_def, option_case_eq, v_case_eq,
CaseEq "word_lab"] >> rveq >> fs [] >>
fs [state_rel_def, state_component_equality])
>- (
rename [‘eval s (LoadByte e)’] >>
rpt gen_tac >> strip_tac >>
fs [panSemTheory.eval_def, option_case_eq, v_case_eq,
CaseEq "word_lab", option_case_eq] >> rveq >> fs [] >>
fs [state_rel_def, state_component_equality])
>- (
rename [‘eval s (Op op es)’] >>
rpt gen_tac >> strip_tac >>
fs [panSemTheory.eval_def, option_case_eq, v_case_eq,
CaseEq "word_lab", option_case_eq] >> rveq >> fs [] >>
qsuff_tac ‘OPT_MMAP (λa. eval t a) es = SOME ws’
>- fs [] >>
pop_assum mp_tac >>
pop_assum kall_tac >>
pop_assum kall_tac >>
pop_assum mp_tac >>
pop_assum mp_tac >>
MAP_EVERY qid_spec_tac [‘ws’, ‘es’] >>
Induct >> fs [] >>
rpt gen_tac >> strip_tac >> fs [OPT_MMAP_def] >>
rewrite_tac [AND_IMP_INTRO] >> strip_tac >> rveq >>
fs [])
>- (
rename [‘eval s (Panop op es)’] >>
rw[eval_def] \\
gvs[AllCaseEqs(),DefnBase.one_line_ify NONE pan_op_def,MAP_EQ_CONS,PULL_EXISTS,
pan_commonPropsTheory.opt_mmap_eq_some,SF DNF_ss] \\
metis_tac[])
>- (
rpt gen_tac >> strip_tac >>
fs [panSemTheory.eval_def] >>
fs [option_case_eq, v_case_eq, word_lab_case_eq] >> rveq >>
fs []) >>
rpt gen_tac >> rpt strip_tac >>
fs [panSemTheory.eval_def] >>
fs [option_case_eq, v_case_eq, word_lab_case_eq] >> rveq >>
fs [state_rel_def, state_component_equality]
QED
(* TODO: move *)
Theorem OPT_MMAP_NONE:
OPT_MMAP f xs = NONE ⇒
∃x. MEM x xs ∧ f x = NONE
Proof
Induct_on ‘xs’ \\ rw[PULL_EXISTS] \\
metis_tac[]
QED
(* TODO: move *)
Theorem OPT_MMAP_NONE':
MEM x xs ∧ f x = NONE ⇒ OPT_MMAP f xs = NONE
Proof
Induct_on ‘xs’ \\ rw[PULL_EXISTS]
THEN1 metis_tac[] \\
Cases_on ‘x = h’ \\ gvs[] \\
Cases_on ‘f h’ \\ gvs[]
QED
Theorem compile_eval_correct_none:
∀s e t.
eval s e = NONE /\
state_rel s t t.code ==>
eval t e = NONE
Proof
ho_match_mp_tac panSemTheory.eval_ind >>
rpt conj_tac >> rpt gen_tac >> strip_tac
>- (
rename [‘Const w’] >>
fs [panSemTheory.eval_def])
>- (
rename [‘eval s (Var vname)’] >>
fs [panSemTheory.eval_def] >> rveq >>
fs [state_rel_def, state_component_equality])
>- (
rename [‘eval s (Label fname)’] >>
fs [panSemTheory.eval_def, option_case_eq] >> rveq >>
fs [state_rel_def, state_component_equality] >>
res_tac >> fs [])
>- (
rename [‘eval s (Struct es)’] >>
rpt gen_tac >> strip_tac >> fs [] >>
fs [panSemTheory.eval_def, option_case_eq] >> rveq >>
rpt (pop_assum mp_tac) >>
MAP_EVERY qid_spec_tac [‘es’] >>
Induct >> fs [] >>
rpt gen_tac >> strip_tac >> fs [OPT_MMAP_def] >>
rewrite_tac [AND_IMP_INTRO] >> strip_tac >> rveq >>
fs [] >>
drule compile_eval_correct >>
fs [])
>- (
rename [‘eval s (Field index e)’] >>
rpt gen_tac >> strip_tac >> fs [] >>
fs [panSemTheory.eval_def, option_case_eq, v_case_eq] >> rveq >>
imp_res_tac compile_eval_correct >>
fs [])
>- (
rename [‘eval s (Load sh e)’] >>
rpt gen_tac >> strip_tac >>
fs [panSemTheory.eval_def, option_case_eq, v_case_eq,
CaseEq "word_lab"] >> rveq >> fs [] >>
imp_res_tac compile_eval_correct >>
fs [] >>
fs [state_rel_def, state_component_equality])
>- (
rename [‘eval s (LoadByte e)’] >>
rpt gen_tac >> strip_tac >>
fs [panSemTheory.eval_def, option_case_eq, v_case_eq,
CaseEq "word_lab", option_case_eq] >> rveq >> fs [] >>
imp_res_tac compile_eval_correct >>
fs [] >>
fs [state_rel_def, state_component_equality])
>- (
rename [‘eval s (Op op es)’] >>
rpt gen_tac >> strip_tac >>
fs [panSemTheory.eval_def, option_case_eq, v_case_eq,
CaseEq "word_lab", option_case_eq] >> rveq >> fs []
>- (
qsuff_tac ‘OPT_MMAP (λa. eval t a) es = NONE’
>- fs [] >>
pop_assum mp_tac >>
pop_assum mp_tac >>
pop_assum mp_tac >>
MAP_EVERY qid_spec_tac [‘es’] >>
Induct >> fs [] >>
rpt gen_tac >> strip_tac >> fs [OPT_MMAP_def] >>
rewrite_tac [AND_IMP_INTRO] >> strip_tac >> rveq >>
fs [] >>
imp_res_tac compile_eval_correct >>
fs []) >>
qsuff_tac ‘OPT_MMAP (λa. eval t a) es = SOME ws’
>- fs [] >>
pop_assum mp_tac >>
pop_assum kall_tac >>
pop_assum mp_tac >>
pop_assum mp_tac >>
MAP_EVERY qid_spec_tac [‘ws’, ‘es’] >>
Induct >> fs [] >>
rpt gen_tac >> strip_tac >> fs [OPT_MMAP_def] >>
rewrite_tac [AND_IMP_INTRO] >> strip_tac >> rveq >>
fs [] >>
imp_res_tac compile_eval_correct >>
fs [])
>- (
rename [‘eval s (Panop op es)’] >>
rw[eval_def] \\
PURE_TOP_CASE_TAC
THEN1 (gvs[AllCaseEqs(),DefnBase.one_line_ify NONE pan_op_def,MAP_EQ_CONS,PULL_EXISTS,
SF DNF_ss] \\
imp_res_tac OPT_MMAP_NONE \\
gvs[] \\
res_tac \\
disj1_tac \\
metis_tac[OPT_MMAP_NONE']) \\
gvs[] \\
strip_tac \\
gvs[eval_def,AllCaseEqs()]
THEN1 (imp_res_tac OPT_MMAP_NONE \\
fs[] \\
metis_tac[NOT_NONE_SOME,OPT_MMAP_NONE']) \\
qpat_x_assum ‘_ ⇒ _’ mp_tac \\ impl_keep_tac
THEN1 (gvs[EVERY_MEM] \\
rw[] \\
gvs[pan_commonPropsTheory.opt_mmap_eq_some,MAP_EQ_EVERY2,LIST_REL_EL_EQN,MEM_EL,PULL_EXISTS] \\
res_tac \\
drule_all_then strip_assume_tac compile_eval_correct \\
gvs[]) \\
imp_res_tac pan_commonPropsTheory.opt_mmap_length_eq \\
rw[DefnBase.one_line_ify NONE pan_op_def,AllCaseEqs(),MAP_EQ_CONS,PULL_EXISTS] \\
gvs[quantHeuristicsTheory.LIST_LENGTH_1,LENGTH_CONS] \\
every_case_tac \\ gvs[])
>- (
rpt gen_tac >> strip_tac >>
fs [panSemTheory.eval_def] >>
fs [option_case_eq, v_case_eq, word_lab_case_eq] >> rveq >>
fs [] >>
imp_res_tac compile_eval_correct >>
fs []) >>
rpt gen_tac >> rpt strip_tac >>
fs [panSemTheory.eval_def] >>
fs [option_case_eq, v_case_eq, word_lab_case_eq] >> rveq >>
fs [] >>
imp_res_tac compile_eval_correct >>
fs []
QED
val goal =
``λ comp (prog, s). ∀res s1 t ctxt.
evaluate (prog,s) = (res,s1) ∧ res ≠ SOME Error ∧
state_rel s t t.code ==>
∃t1. evaluate (comp prog,t) = (res,t1) /\
state_rel s1 t1 t1.code``
local
val goal = beta_conv ``^goal (pan_simp$seq_assoc Skip)``
val ind_thm = panSemTheory.evaluate_ind
|> ISPEC goal
|> CONV_RULE (DEPTH_CONV PairRules.PBETA_CONV) |> REWRITE_RULE [];
fun list_dest_conj tm = if not (is_conj tm) then [tm] else let
val (c1,c2) = dest_conj tm in list_dest_conj c1 @ list_dest_conj c2 end
val ind_goals = ind_thm |> concl |> dest_imp |> fst |> list_dest_conj
in
fun get_goal s = first (can (find_term (can (match_term (Term [QUOTE s]))))) ind_goals
fun compile_tm () = ind_thm |> concl |> rand
fun the_ind_thm () = ind_thm
end
Theorem compile_Seq:
^(get_goal "panLang$Seq")
Proof
rw [] >>
fs [evaluate_seq_assoc, evaluate_skip_seq] >>
fs [evaluate_def] >>
pairarg_tac >> fs [] >> rveq >> fs [] >>
pairarg_tac >> fs [] >> rveq >> fs [] >>
cases_on ‘res''’ >> fs [] >> rveq >> fs []
>- (
‘res' = NONE’ by (
res_tac >> fs []) >>
fs [] >>
first_x_assum drule >>
strip_tac >>
fs [] >> rveq >> fs []) >>
‘res' <> NONE’ by (
res_tac >> fs [] >> rveq >> fs []) >>
fs [] >>
res_tac >> fs [] >>
rveq >> fs []
QED
Theorem compile_Dec:
^(get_goal "panLang$Dec")
Proof
rw [] >>
fs [evaluate_seq_assoc, evaluate_skip_seq] >>
fs [evaluate_def] >>
cases_on ‘eval s e’ >> fs [] >> rveq >>
drule compile_eval_correct >>
disch_then drule >>
strip_tac >>
fs [] >>
pairarg_tac >> fs [] >> rveq >> fs [] >>
pairarg_tac >> fs [] >> rveq >> fs [] >>
first_x_assum (qspec_then ‘t with locals := t.locals |+ (v,x)’ mp_tac) >>
impl_tac
>- fs [state_rel_def, state_component_equality] >>
strip_tac >> fs [] >> rveq >>
rfs [state_rel_def] >>
fs [state_component_equality]
QED
Theorem compile_If:
^(get_goal "panLang$If")
Proof
rw [] >>
fs [evaluate_seq_assoc, evaluate_skip_seq] >>
fs [evaluate_def] >>
cases_on ‘eval s e’ >> fs [] >> rveq >>
drule compile_eval_correct >>
disch_then drule >>
strip_tac >>
fs [] >>
TOP_CASE_TAC >> fs [] >>
TOP_CASE_TAC >> fs []
QED
Theorem compile_Call:
^(get_goal "panLang$Call")
Proof
rw [] >>
fs [evaluate_seq_assoc, evaluate_skip_seq] >>
fs [evaluate_def] >>
cases_on ‘eval s trgt’ >> fs [] >> rveq >> fs [] >>
imp_res_tac compile_eval_correct >>
fs [] >>
TOP_CASE_TAC >> fs [] >> rveq >> fs [] >>
TOP_CASE_TAC >> fs [] >> rveq >> fs [] >>
cases_on ‘OPT_MMAP (eval s) argexps’ >>
fs [] >>
‘OPT_MMAP (eval t) argexps = OPT_MMAP (eval s) argexps’ by (
match_mp_tac IMP_OPT_MMAP_EQ >>
fs [pan_commonPropsTheory.opt_mmap_eq_some] >>
fs [MAP_EQ_EVERY2] >>
fs [LIST_REL_EL_EQN] >>
rw [] >>
metis_tac [compile_eval_correct]) >>
fs [] >>
cases_on ‘lookup_code s.code m x’ >> fs [] >>
fs [lookup_code_def] >>
cases_on ‘FLOOKUP s.code m’ >> fs [] >>
cases_on ‘ x''’ >> fs [] >> rveq >>
qpat_x_assum ‘state_rel s t t.code’ assume_tac >>
drule state_rel_intro >>
strip_tac >> rveq >> fs [] >>
pop_assum drule >>
strip_tac >> fs [] >>
‘t.clock = s.clock’ by
fs [state_rel_def, state_component_equality] >>
fs [] >>
cases_on ‘s.clock = 0’ >> fs []
>- (
fs [empty_locals_def] >> rveq >>
fs [state_rel_def, state_component_equality]) >>
cases_on ‘evaluate
(r,dec_clock s with locals := FEMPTY |++ ZIP (MAP FST q,x))’ >>
fs [] >>
cases_on ‘q'’ >> fs [] >>
cases_on ‘x'’ >> fs [] >> rveq >> fs []
>- (
last_x_assum (qspec_then ‘dec_clock t with
locals := FEMPTY |++ ZIP (MAP FST q,x)’ mp_tac) >>
impl_tac
>- fs [dec_clock_def, state_rel_def, state_component_equality] >>
strip_tac >> fs [] >>
drule evaluate_seq_simp >>
fs [] >>
strip_tac >>
fs [empty_locals_def] >> rveq >>
fs [state_rel_def, state_component_equality])
>- (
last_x_assum (qspec_then ‘dec_clock t with
locals := FEMPTY |++ ZIP (MAP FST q,x)’ mp_tac) >>
impl_tac
>- fs [dec_clock_def, state_rel_def, state_component_equality] >>
strip_tac >> fs [] >>
drule evaluate_seq_simp >>
fs [] >>
strip_tac >>
fs [] >> rveq >>
cases_on ‘caltyp’ >> rfs [] >>
fs [empty_locals_def] >> rveq >>
fs [state_rel_def, state_component_equality] >>
every_case_tac >> fs [set_var_def] >> rveq >> rfs [])
>- (
last_x_assum (qspec_then ‘dec_clock t with
locals := FEMPTY |++ ZIP (MAP FST q,x)’ mp_tac) >>
impl_tac
>- fs [dec_clock_def, state_rel_def, state_component_equality] >>
strip_tac >> fs [] >>
drule evaluate_seq_simp >>
fs [] >>
strip_tac >>
fs [] >> rveq >>
cases_on ‘caltyp’ >> rfs [] >>
fs [empty_locals_def] >> rveq >>
fs [state_rel_def, state_component_equality] >>
every_case_tac >> fs [set_var_def] >> rveq >> rfs []) >>
last_x_assum (qspec_then ‘dec_clock t with
locals := FEMPTY |++ ZIP (MAP FST q,x)’ mp_tac) >>
impl_tac
>- fs [dec_clock_def, state_rel_def, state_component_equality] >>
strip_tac >> fs [] >>
drule evaluate_seq_simp >>
fs [] >>
strip_tac >>
fs [empty_locals_def] >> rveq >>
fs [state_rel_def, state_component_equality]
QED
Theorem compile_DecCall:
^(get_goal "panLang$DecCall")
Proof
rw [] >>
fs [evaluate_seq_assoc, evaluate_skip_seq] >>
fs [evaluate_def] >>
gvs[AllCaseEqs(),PULL_EXISTS] >>
imp_res_tac compile_eval_correct >>
gvs[] >>
irule_at (Pos hd) EQ_TRANS >>
first_assum $ irule_at $ Pos $ hd o tl >>
irule_at (Pos hd) IMP_OPT_MMAP_EQ >>
simp[GSYM PULL_EXISTS] >>
(conj_asm1_tac
>- (fs [pan_commonPropsTheory.opt_mmap_eq_some] >>
fs [MAP_EQ_EVERY2] >>
fs [LIST_REL_EL_EQN] >>
rw [] >>
metis_tac [compile_eval_correct])) >>
gvs[state_rel_def,lookup_code_def,AllCaseEqs(),PULL_EXISTS] >>
first_assum drule >> strip_tac >> fs[] >>
‘t.clock = s.clock’ by (gvs[state_component_equality]) >>
gvs[] >>
gvs[empty_locals_def] >>
simp[]
>- gvs[state_component_equality] >>
qmatch_goalsub_abbrev_tac ‘compile _, tt’ >>
last_x_assum $ qspec_then ‘tt’ mp_tac >>
unabbrev_all_tac >>
(impl_tac >- gvs[dec_clock_def,state_component_equality]) >>
strip_tac >>
simp[] >>
gvs[evaluate_seq_assoc, evaluate_skip_seq,compile_def,ret_to_tail_correct] >>
gvs[state_component_equality,PULL_EXISTS,UNCURRY_eq_pair] >>
qmatch_goalsub_abbrev_tac ‘evaluate(_, tt)’ >>
last_x_assum $ qspec_then ‘tt’ mp_tac o CONV_RULE SWAP_FORALL_CONV >>
simp[Abbr ‘tt’,set_var_def] >>
disch_then(qspec_then ‘s1 with locals := st'.locals’ mp_tac) >>
simp[] >>
strip_tac >>
simp[] >>
qexists ‘s1 with code := t1'.code’ >>
simp[]
QED
Theorem compile_While:
^(get_goal "panLang$While")
Proof
rw [] >>
fs [evaluate_seq_assoc, evaluate_skip_seq] >>
qpat_x_assum ‘ evaluate (While e c,s) = (res,s1)’ mp_tac >>
once_rewrite_tac [evaluate_def] >>
TOP_CASE_TAC >> fs [] >>
TOP_CASE_TAC >> fs [] >>
TOP_CASE_TAC >> fs [] >>
TOP_CASE_TAC >> fs []
>- (
TOP_CASE_TAC >> fs [] >>
strip_tac >> rveq >> fs [] >>
imp_res_tac compile_eval_correct >>
fs []
>- (
‘t.clock = 0’ by
fs [state_rel_def, state_component_equality] >>
fs [] >>
fs [empty_locals_def, state_rel_def, state_component_equality]) >>
‘t.clock <> 0’ by
fs [state_rel_def, state_component_equality] >>
fs [] >>
cases_on ‘evaluate (c,dec_clock s)’ >>
fs [] >>
cases_on ‘q’ >> fs [] >> rveq >> fs [] >>
TRY (cases_on ‘x’ >> fs [] >> rveq >> fs []) >> (
last_x_assum (qspec_then ‘dec_clock t’ mp_tac) >>
impl_tac
>- fs [dec_clock_def, state_rel_def, state_component_equality] >>
strip_tac >> fs [])) >>
strip_tac >> rveq >> fs [] >>
imp_res_tac compile_eval_correct >>
fs []
QED
Theorem compile_ExtCall:
^(get_goal "panLang$ExtCall")
Proof
rw [] >>
fs [evaluate_seq_assoc, evaluate_skip_seq] >>
fs [evaluate_def] >> rveq >> fs [] >>
last_x_assum mp_tac >>
rpt (TOP_CASE_TAC >> fs []) >>
MAP_EVERY imp_res_tac [compile_eval_correct,compile_eval_correct_none] >> gvs[] >>
rfs [state_rel_def, state_component_equality,
empty_locals_def, dec_clock_def] >> rveq >> fs [] >>
rveq >> fs [] >> rveq >> rfs [] >>
strip_tac >> fs []
QED
Theorem compile_ShMemLoad:
^(get_goal "panLang$ShMemLoad")
Proof
rw [] >>
fs [evaluate_seq_assoc, evaluate_skip_seq] >>
Cases_on ‘op’>>
fs [evaluate_def] >> rveq >>
fs [nb_op_def,sh_mem_load_def,sh_mem_store_def,
set_var_def,empty_locals_def] >>
last_x_assum mp_tac >>
rpt (TOP_CASE_TAC >> fs []) >>
MAP_EVERY imp_res_tac [compile_eval_correct,compile_eval_correct_none] >> gvs[] >>
rfs [state_rel_def, state_component_equality,
empty_locals_def, dec_clock_def] >> rveq >> fs [] >>
rveq >> fs [] >> rveq >> rfs [] >>
strip_tac >> fs []
QED
Theorem compile_ShMemStore:
^(get_goal "panLang$ShMemStore")
Proof
rw [] >>
fs [evaluate_seq_assoc, evaluate_skip_seq] >>
Cases_on ‘op’>>
fs [evaluate_def] >> rveq >>
fs [nb_op_def,sh_mem_load_def,sh_mem_store_def,
set_var_def,empty_locals_def] >>
last_x_assum mp_tac >>
rpt (TOP_CASE_TAC >> fs []) >>
MAP_EVERY imp_res_tac [compile_eval_correct,compile_eval_correct_none] >> gvs[] >>
rfs [state_rel_def, state_component_equality,
empty_locals_def, dec_clock_def] >> rveq >> fs [] >>
rveq >> fs [] >> rveq >> rfs [] >>
strip_tac >> fs []
QED
Theorem compile_Others:
^(get_goal "panLang$Skip") /\
^(get_goal "panLang$Assign") /\
^(get_goal "panLang$Store") /\
^(get_goal "panLang$StoreByte") /\
^(get_goal "panLang$Break") /\
^(get_goal "panLang$Continue") /\
^(get_goal "panLang$Raise") /\
^(get_goal "panLang$Return") /\
^(get_goal "panLang$Annot") /\
^(get_goal "panLang$Tick")
Proof
rw [] >>
fs [evaluate_seq_assoc, evaluate_skip_seq] >>
fs [evaluate_def] >> rveq >> fs [] >>
(
every_case_tac >> gvs [] >>
imp_res_tac compile_eval_correct >>
gvs [state_rel_def, state_component_equality,
empty_locals_def, dec_clock_def])
QED
Theorem compile_correct:
^(compile_tm())
Proof
match_mp_tac (the_ind_thm()) >>
EVERY (map strip_assume_tac
[compile_Dec, compile_Seq, compile_ShMemLoad, compile_ShMemStore,
compile_If, compile_While, compile_Call, compile_DecCall,
compile_ExtCall, compile_Call,compile_Others]) >>
asm_rewrite_tac [] >> rw [] >> rpt (pop_assum kall_tac)
QED
Theorem first_compile_prog_all_distinct:
ALL_DISTINCT (MAP FST prog) ==>
ALL_DISTINCT (MAP FST (pan_simp$compile_prog prog))
Proof
rw [] >>
fs [pan_simpTheory.compile_prog_def] >>
fs [MAP_MAP_o] >>
qmatch_goalsub_abbrev_tac ‘MAP ls _’ >>
‘MAP ls prog = MAP FST prog’ suffices_by fs [] >>
fs [Abbr ‘ls’] >>
fs [MAP_EQ_EVERY2, LIST_REL_EL_EQN] >>
rw [] >>
cases_on ‘EL n prog’ >>
fs [] >>
cases_on ‘r’ >>
fs []
QED
Theorem el_compile_prog_el_prog_eq:
!prog n start pprog p.
EL n (compile_prog prog) = (start,[],pprog) /\
ALL_DISTINCT (MAP FST prog) /\ n < LENGTH prog /\
ALOOKUP prog start = SOME ([],p) ==>
EL n prog = (start,[],p)
Proof
Induct >> rw [] >>
fs [compile_prog_def] >>
cases_on ‘n’ >> fs [] >> rveq >> fs []
>- (
cases_on ‘h’ >> rfs [] >>
cases_on ‘r’ >> rfs [] >> rveq >> fs []) >>
last_x_assum match_mp_tac >>
qexists_tac ‘pprog’ >> fs [] >>
cases_on ‘h’ >> fs [] >>
cases_on ‘q = start’ >> fs [] >> rveq >> fs [] >>
fs [MEM_EL] >>
first_x_assum (qspec_then ‘n'’ mp_tac) >>
fs [] >>
strip_tac >>
qmatch_asmsub_abbrev_tac ‘EL _ (MAP ff _) = _’ >>
‘EL n' (MAP ff prog) = ff (EL n' prog)’ by (
match_mp_tac EL_MAP >> fs []) >>
fs [] >>
fs [Abbr ‘ff’] >>
cases_on ‘EL n' prog’ >> fs [] >>
cases_on ‘r’ >> fs [] >> rveq >> rfs [] >>
metis_tac [pan_commonPropsTheory.el_pair_map_fst_el]
QED
Theorem compile_prog_distinct_params:
∀prog.
EVERY (λ(name,params,body). ALL_DISTINCT params) prog ⇒
EVERY (λ(name,params,body). ALL_DISTINCT params) (compile_prog prog)
Proof
rw [] >>
fs [EVERY_MEM] >>
rw [] >>
PairCases_on ‘e’ >> fs [] >>
fs [compile_prog_def] >>
fs [MEM_EL] >>
qmatch_asmsub_abbrev_tac ‘MAP ff _’ >>
‘EL n (MAP ff prog) = ff (EL n prog)’ by (