forked from CakeML/cakeml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cfDivScript.sml
4809 lines (4662 loc) · 180 KB
/
cfDivScript.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
(*
Defines the repeat function and the corresponding lemma used to prove
non-termination of programs in cf.
*)
open preamble
open set_sepTheory helperLib ml_translatorTheory
open ml_translatorTheory semanticPrimitivesTheory
open cfHeapsBaseTheory cfHeapsTheory cfHeapsBaseLib cfStoreTheory
open cfNormaliseTheory cfAppTheory evaluateTheory
open cfTacticsBaseLib cfTacticsLib cfTheory
open std_preludeTheory;
val _ = new_theory "cfDiv";
val _ = temp_delsimps ["NORMEQ_CONV"]
val _ = diminish_srw_ss ["ABBREV"]
val _ = set_trace "BasicProvers.var_eq_old" 1
val _ = ml_translatorLib.translation_extends "std_prelude";
(* -- general set up -- *)
val st = ``st:'ffi semanticPrimitives$state``
Theorem POSTd_eq:
$POSTd Q r h <=> ?io1. r = Div io1 /\ Q io1 /\ emp h
Proof
Cases_on `r` \\ fs [POSTd_def,POST_def,cond_def,emp_def]
\\ eq_tac \\ rw []
QED
fun append_prog tm = let
val tm = QCONV EVAL tm |> concl |> rand
in ml_translatorLib.ml_prog_update (ml_progLib.add_prog tm I) end
Theorem dest_opapp_exp_size:
!tm f arg. dest_opapp tm = SOME(f,arg)
==> list_size exp_size arg < exp_size tm
Proof
ho_match_mp_tac cfNormaliseTheory.dest_opapp_ind
>> rw[cfNormaliseTheory.dest_opapp_def]
>> every_case_tac >> fs[]
>> gvs [astTheory.exp_size_eq,listTheory.list_size_def,astTheory.exp_size_def,
list_size_append]
QED
Theorem dest_opapp_eq_nil_IMP:
dest_opapp(exp) = SOME(f,[])
==> F
Proof
Cases_on `exp` >>
fs[cfNormaliseTheory.dest_opapp_def] >>
rename1 `App op exps` >>
Cases_on `op` >> Cases_on `exps` >>
fs[cfNormaliseTheory.dest_opapp_def] >>
every_case_tac >> fs[] >> strip_tac
QED
Theorem dest_opapp_eq_single_IMP:
dest_opapp(App op exps) = SOME(f,[arg])
==> op = Opapp /\ exps = [f;arg]
Proof
Cases_on `op` >> Cases_on `exps` >>
fs[cfNormaliseTheory.dest_opapp_def] >>
every_case_tac >> fs[] >> strip_tac >>
rveq >> rename1 `dest_opapp exp` >>
Cases_on `exp` >> fs[cfNormaliseTheory.dest_opapp_def] >>
rename1 `App op exps` >>
Cases_on `op` >> Cases_on `exps` >>
fs[cfNormaliseTheory.dest_opapp_def] >>
every_case_tac >> fs[]
QED
Theorem nsLookup_build_rec_env_fresh:
!funs env env' fname.
EVERY (λx. fname ≠ x) (MAP FST funs)
==>
nsLookup(build_rec_env funs env' env.v) (Short fname) =
nsLookup env.v (Short fname)
Proof
`∀(funs:(string # string # exp) list) funs' env env' fname.
EVERY (λx. fname ≠ x) (MAP FST funs) ⇒
nsLookup
(FOLDR (λ(f,x,e) env''. nsBind f (Recclosure env' (funs':(string # string # exp) list) f) env'')
env.v funs) (Short fname) = nsLookup env.v (Short fname)`
suffices_by rw[semanticPrimitivesTheory.build_rec_env_def] >>
Induct >> rw[semanticPrimitivesTheory.build_rec_env_def] >>
fs[ELIM_UNCURRY]
QED
Theorem nsLookup_alist_to_ns_fresh:
!l fname.
EVERY (λx. fname ≠ x) (MAP FST l)
==>
nsLookup(alist_to_ns l) (Short fname) = NONE
Proof
fs[namespaceTheory.alist_to_ns_def,namespaceTheory.nsLookup_def,
ALOOKUP_NONE,EVERY_MEM]
QED
(* -- tailrec -- *)
val tailrec_clos = cfTacticsLib.process_topdecs `
fun tailrec f x =
case f x of
Inl x => tailrec f x
| Inr y => y;
` |> rator |> rand |> rand
val tailrec_body = tailrec_clos |> rator |> rand |> rand |> rand |> rand
val mk_inl_def = Define `mk_inl e =
Let (SOME "x") e (Con(SOME(Short "Inl")) [Var(Short "x")])`
val mk_inr_def = Define `mk_inr e =
Let (SOME "x") e (Con(SOME(Short "Inr")) [Var(Short "x")])`
Definition mk_single_app_def:
(mk_single_app fname allow_fname (Raise e) =
do
e <- mk_single_app fname F e;
SOME(Raise e)
od) /\
(mk_single_app fname allow_fname (Handle e pes) =
do
e <- mk_single_app fname F e;
pes <- mk_single_appps fname allow_fname pes;
if allow_fname then
SOME(Handle (mk_inr e) pes)
else
SOME(Handle e pes)
od) /\
(mk_single_app fname allow_fname (Lit l) =
if allow_fname then
SOME(mk_inr(Lit l))
else
SOME(Lit l)) /\
(mk_single_app fname allow_fname (Con c es) =
do
es <- mk_single_apps fname F es;
if allow_fname then
SOME(mk_inr(Con c es))
else
SOME(Con c es)
od
) /\
(mk_single_app fname allow_fname (Var(Short v)) =
if SOME v = fname then
NONE
else if allow_fname then
SOME(mk_inr(Var(Short v)))
else
SOME(Var(Short v))
) /\
(mk_single_app fname allow_fname (Var v) =
if allow_fname then
SOME(mk_inr(Var v))
else
SOME(Var v)
) /\
(mk_single_app fname allow_fname (Fun x e) =
let fname' = if SOME x = fname then
NONE
else
fname
in
do
e <- mk_single_app fname' F e;
if allow_fname then
SOME(mk_inr(Fun x e))
else
SOME(Fun x e)
od
) /\
(mk_single_app fname allow_fname (Log lop e1 e2) =
do
e1 <- mk_single_app fname F e1;
e2 <- mk_single_app fname F e2;
if allow_fname then
SOME(mk_inr(Log lop e1 e2))
else
SOME(Log lop e1 e2)
od
) /\
(mk_single_app fname allow_fname (If e1 e2 e3) =
do
e1 <- mk_single_app fname F e1;
e2 <- mk_single_app fname allow_fname e2;
e3 <- mk_single_app fname allow_fname e3;
SOME(If e1 e2 e3)
od
) /\
(mk_single_app fname allow_fname (Mat e pes) =
do
e <- mk_single_app fname F e;
pes <- mk_single_appps fname allow_fname pes;
SOME(Mat e pes)
od
) /\
(mk_single_app fname allow_fname (Tannot e ty) =
do
e <- mk_single_app fname allow_fname e;
SOME(Tannot e ty)
od
) /\
(mk_single_app fname allow_fname (Lannot e l) =
do
e <- mk_single_app fname allow_fname e;
SOME(Lannot e l)
od
) /\
(mk_single_app fname allow_fname (Let NONE e1 e2) =
do
e1 <- mk_single_app fname F e1;
e2 <- mk_single_app fname allow_fname e2;
SOME(Let NONE e1 e2)
od) /\
(mk_single_app fname allow_fname (Let (SOME x) e1 e2) =
let fname' =
if SOME x = fname then
NONE
else fname
in
do
e1 <- mk_single_app fname F e1;
e2 <- mk_single_app fname' allow_fname e2;
SOME(Let (SOME x) e1 e2)
od) /\
(mk_single_app fname allow_fname (Letrec recfuns e) =
let fname' = if EXISTS ($= fname o SOME) (MAP FST recfuns)
then NONE else fname
in
do
recfuns <- mk_single_appr fname' F recfuns;
e <- mk_single_app fname' allow_fname e;
SOME(Letrec recfuns e)
od) /\
(mk_single_app fname allow_fname (App op es) =
(case dest_opapp (App op es) of
SOME(Var(Short f),[arg]) =>
if SOME f = fname then
if allow_fname then
do
arg <- mk_single_app fname F arg;
SOME(mk_inl arg)
od
else NONE
else
do
arg <- mk_single_app fname F arg;
if allow_fname then
SOME(mk_inr(App op [Var(Short f); arg]))
else
SOME(App op [Var(Short f); arg])
od
| _ =>
do
es <- mk_single_apps fname F es;
if allow_fname then
SOME(mk_inr(App op es))
else
SOME(App op es)
od
)
) /\
(mk_single_app fname allow_fname (FpOptimise sc e) =
do
e <- mk_single_app fname F e;
if allow_fname then
SOME(mk_inr(FpOptimise sc e))
else
SOME(FpOptimise sc e)
od) /\
(mk_single_apps fname allow_fname (e::es) =
do
e <- mk_single_app fname allow_fname e;
es <- mk_single_apps fname allow_fname es;
SOME(e::es)
od) /\
(mk_single_apps fname allow_fname [] =
SOME []) /\
(mk_single_appps fname allow_fname ((p,e)::pes) =
let fname' = if EXISTS ($= fname o SOME) (pat_bindings p [])
then NONE
else fname
in
do
e <- mk_single_app fname' allow_fname e;
pes <- mk_single_appps fname allow_fname pes;
SOME((p,e)::pes)
od) /\
(mk_single_appps fname allow_fname [] =
SOME []) /\
(mk_single_appr fname allow_fname ((f,x,e)::recfuns) =
let fname' = if SOME x = fname then NONE else fname
in
do
e <- mk_single_app fname allow_fname e;
recfun <- mk_single_appr fname allow_fname recfuns;
SOME((f,x,e)::recfuns)
od) /\
(mk_single_appr fname allow_fname [] =
SOME [])
Termination
WF_REL_TAC `inv_image $< (\x. case x of INL (t,x,e) => exp_size e
| INR (INL (t,x,es)) => list_size exp_size es
| INR (INR (INL (t,x,pes))) =>
list_size (pair_size pat_size exp_size) pes
| INR (INR (INR (t,x,funs))) =>
list_size (pair_size (list_size char_size)
(pair_size (list_size char_size) exp_size)) funs)`
\\ gvs [astTheory.exp_size_eq] \\ rw []
\\ gvs [Once (dest_opapp_def |> DefnBase.one_line_ify NONE)]
\\ gvs [AllCaseEqs()]
\\ fs [list_size_def,astTheory.exp_size_def]
End
val mk_single_app_ind = fetch "-" "mk_single_app_ind"
val mk_stepfun_closure_def = Define
`(mk_stepfun_closure env fname farg fbody =
do
gbody <- mk_single_app (SOME fname) T fbody;
SOME(let benv = build_rec_env [(fname,farg,fbody)] env env.v
in Closure (env with v := benv) farg gbody)
od) /\ mk_stepfun_closure _ _ _ _ = NONE`
val mk_tailrec_closure_def = Define
`(mk_tailrec_closure (Recclosure env [(fname,farg,fbody)] name2) =
do
gclosure <- mk_stepfun_closure env fname farg fbody;
SOME(Closure (env with <| v :=
(nsBind fname gclosure env.v) |>) farg
(App Opapp
[App Opapp
[Letrec ^tailrec_clos (Var(Short "tailrec"));
Var(Short fname)];
Var(Short farg)]
)
)
od) /\ mk_tailrec_closure _ = NONE`
val mk_single_app_F_unchanged_gen = Q.prove(
`(!fname allow_fname e e'. mk_single_app fname allow_fname e = SOME e'
/\ allow_fname = F ==> e = e') /\
(!fname allow_fname es es'. mk_single_apps fname allow_fname es = SOME es'
/\ allow_fname = F ==> es = es') /\
(!fname allow_fname pes pes'. mk_single_appps fname allow_fname pes = SOME pes'
/\ allow_fname = F ==> pes = pes') /\
(!fname allow_fname recfuns recfuns'. mk_single_appr fname allow_fname recfuns = SOME recfuns'
/\ allow_fname = F ==> recfuns = recfuns')
`,
ho_match_mp_tac mk_single_app_ind >>
rw[mk_single_app_def] >> fs[] >>
every_case_tac >> fs[] >> rfs[] >>
first_x_assum drule >> simp[] >>
imp_res_tac dest_opapp_eq_single_IMP >>
fs[]);
val mk_single_app_F_unchanged = save_thm("mk_single_app_F_unchanged",
SIMP_RULE std_ss [] mk_single_app_F_unchanged_gen);
val mk_inr_res_def = Define `
(mk_inr_res(Rval vs) =
Rval(MAP (λv. Conv (SOME (TypeStamp "Inr" 4)) [v]) vs)
) /\
(mk_inr_res res = res)`
val mk_inl_res_def = Define `
(mk_inl_res(Rval vs) =
Rval(MAP (λv. Conv (SOME (TypeStamp "Inl" 4)) [v]) vs)
) /\
(mk_inl_res res = res)`
val dest_inr_v_def = Define `
(dest_inr_v (Conv (SOME (TypeStamp txt n)) [v]) =
if txt = "Inr" /\ n = 4 then
SOME v
else
NONE) /\
(dest_inr_v _ = NONE)`
val dest_inl_v_def = Define `
(dest_inl_v (Conv (SOME (TypeStamp txt n)) [v]) =
if txt = "Inl" /\ n = 4 then
SOME v
else
NONE) /\
(dest_inl_v _ = NONE)`
Theorem dest_inr_v_IMP:
!e1 v. dest_inr_v e1 = SOME v ==> e1 = Conv (SOME (TypeStamp "Inr" 4)) [v]
Proof
ho_match_mp_tac (fetch "-" "dest_inr_v_ind") >>
rw[dest_inr_v_def]
QED
Theorem dest_inl_v_IMP:
!e1 v. dest_inl_v e1 = SOME v ==> e1 = Conv (SOME (TypeStamp "Inl" 4)) [v]
Proof
ho_match_mp_tac (fetch "-" "dest_inl_v_ind") >>
rw[dest_inl_v_def]
QED
Theorem evaluate_inl:
do_con_check env.c (SOME (Short "Inl")) 1 = T /\
(!v. build_conv env.c (SOME (Short "Inl")) [v] =
SOME(Conv (SOME (TypeStamp "Inl" 4)) [v]))
==> evaluate st env [mk_inl e] =
case evaluate st env [e] of
(st,Rval v) => (st,mk_inl_res(Rval v))
| (st,rerr) => (st,rerr)
Proof
rw[evaluate_def,mk_inl_def,namespaceTheory.nsOptBind_def,
ml_progTheory.nsLookup_nsBind_compute,mk_inl_res_def] >>
ntac 2(PURE_TOP_CASE_TAC >> fs[] >> rveq) >>
imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1]
QED
val build_conv_check_IMP_nsLookup = Q.prove(
`!env const v consname stamp n.
(∀v. build_conv env (SOME const) [v] =
SOME (Conv (SOME stamp) [v])) /\
do_con_check env (SOME const) n
==> nsLookup env const = SOME(n,stamp)
`,
rw[semanticPrimitivesTheory.build_conv_def,semanticPrimitivesTheory.do_con_check_def,
namespaceTheory.nsLookup_def] >>
every_case_tac >> fs[]);
Theorem evaluate_IMP_inl:
do_con_check env.c (SOME (Short "Inl")) 1 = T /\
(!v. build_conv env.c (SOME (Short "Inl")) [v] =
SOME(Conv (SOME (TypeStamp "Inl" 4)) [v])) /\
evaluate st env [e] = (st',res)
==> evaluate st env [mk_inl e] = (st',mk_inl_res res)
Proof
rw[evaluate_def,mk_inl_def,namespaceTheory.nsOptBind_def,
ml_progTheory.nsLookup_nsBind_compute] >>
PURE_TOP_CASE_TAC >> fs[mk_inl_res_def] >>
imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1]
QED
Theorem evaluate_inr:
do_con_check env.c (SOME (Short "Inr")) 1 = T /\
(!v. build_conv env.c (SOME (Short "Inr")) [v] =
SOME(Conv (SOME (TypeStamp "Inr" 4)) [v]))
==> evaluate st env [mk_inr e] =
case evaluate st env [e] of
(st,Rval v) => (st,mk_inr_res(Rval v))
| (st,rerr) => (st,rerr)
Proof
rw[evaluate_def,mk_inr_def,namespaceTheory.nsOptBind_def,
ml_progTheory.nsLookup_nsBind_compute,mk_inr_res_def] >>
ntac 2(PURE_TOP_CASE_TAC >> fs[] >> rveq) >>
imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1]
QED
Theorem evaluate_IMP_inr:
do_con_check env.c (SOME (Short "Inr")) 1 = T /\
(!v. build_conv env.c (SOME (Short "Inr")) [v] =
SOME(Conv (SOME (TypeStamp "Inr" 4)) [v])) /\
evaluate ^st env [e] = (st',res)
==> evaluate st env [mk_inr e] = (st',mk_inr_res res)
Proof
rw[evaluate_def,mk_inr_def,namespaceTheory.nsOptBind_def,
ml_progTheory.nsLookup_nsBind_compute] >>
PURE_TOP_CASE_TAC >> fs[mk_inr_res_def] >>
imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1]
QED
Theorem mk_single_appps_MAP_FST:
!pes x b pes'.
mk_single_appps x b pes = SOME pes' ==>
MAP FST pes = MAP FST pes'
Proof
Induct \\ fs [mk_single_app_def,FORALL_PROD]
\\ rw [] \\ fs [] \\ res_tac \\ fs []
QED
val mk_single_app_NONE_evaluate = Q.prove(
`(!^st env es es'. mk_single_apps NONE T es = SOME es'
/\ do_con_check env.c (SOME (Short "Inr")) 1 = T
/\ (!v. build_conv env.c (SOME (Short "Inr")) [v] =
SOME(Conv (SOME (TypeStamp "Inr" 4)) [v]))
==> evaluate st env es'
= case evaluate st env es of
(st',res) => (st', mk_inr_res res)
) /\
(!^st env v pes err_v pes'. mk_single_appps NONE T pes = SOME pes'
/\ do_con_check env.c (SOME (Short "Inr")) 1 = T
/\ (!v. build_conv env.c (SOME (Short "Inr")) [v] =
SOME(Conv (SOME (TypeStamp "Inr" 4)) [v]))
==> evaluate_match st env v pes' err_v
= case evaluate_match st env v pes err_v of
(st',res) => (st', mk_inr_res res)
)
`,
ho_match_mp_tac evaluate_ind >> rpt strip_tac >> PURE_TOP_CASE_TAC
(* Nil *)
>- (fs[mk_single_app_def] >> rveq >> fs[evaluate_def,mk_inr_res_def])
(* Sequence *)
>- (fs[Once evaluate_def,mk_single_app_def] >>
rveq >> every_case_tac >>
fs[] >> rveq >> fs[PULL_EXISTS] >>
rpt(first_x_assum drule) >> rpt(disch_then drule) >> rpt strip_tac >>
simp[Once evaluate_def] >>
fs[mk_inr_res_def] >>
imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1])
(* Lit *)
>- (fs[mk_single_app_def] >> rveq >> fs[evaluate_IMP_inr])
(* Raise *)
>- (fs[mk_single_app_def] >> rveq >> fs[evaluate_IMP_inr] >> fs[evaluate_def] >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
every_case_tac >> fs[] >> rveq >> fs[mk_inr_res_def])
(* Handle *)
>- (fs[mk_single_app_def] >> rveq >> fs[Once evaluate_def] >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
every_case_tac >> fs[] >> rveq >>
rfs[evaluate_inr] >> fs[mk_inr_res_def] >>
rveq >> fs[] >> imp_res_tac mk_single_appps_MAP_FST >> fs [])
(* Con *)
>- (fs[mk_single_app_def] >> rveq >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
fs[evaluate_IMP_inr])
(* Var*)
>- (rename1 `Var n` >> Cases_on `n` >>
fs[mk_single_app_def] >> rveq >>
fs[evaluate_IMP_inr])
(* Fun *)
>- (fs[mk_single_app_def] >> rveq >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
fs[evaluate_IMP_inr])
(* App *)
>- (fs[mk_single_app_def] >>
reverse(Cases_on `op = Opapp`)
>- (Cases_on `op` >>
rveq >> fs[cfNormaliseTheory.dest_opapp_def] >>
rveq >> simp[evaluate_IMP_inr] >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
simp[] >> every_case_tac >> fs[mk_inr_res_def] >>
rfs[] >> imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1] >> rveq >>
rfs[] >> fs[evaluate_IMP_inr]
) >>
rveq >>
Cases_on `es`
>- (fs[cfNormaliseTheory.dest_opapp_def] >>
rveq >> simp[evaluate_IMP_inr] >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
simp[] >> every_case_tac >> fs[mk_inr_res_def] >>
rfs[] >> imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1] >> rveq >>
rfs[] >> fs[evaluate_IMP_inr]) >>
rename1 `dest_opapp (App Opapp (exp::exps))` >>
reverse(Cases_on `exps`)
>- (fs[cfNormaliseTheory.dest_opapp_def] >>
simp[] >> rpt(PURE_FULL_CASE_TAC >> fs[] >> rveq) >>
fs[mk_single_app_def] >> rveq >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
fs[evaluate_IMP_inr] >>
fs[mk_inr_def] >>
simp[] >> simp[evaluate_def] >>
PURE_TOP_CASE_TAC >> fs[mk_inr_res_def] >>
rfs[] >> imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1] >> rveq >>
rfs[] >>
imp_res_tac dest_opapp_eq_nil_IMP) >>
fs[cfNormaliseTheory.dest_opapp_def] >>
rveq >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
simp[evaluate_IMP_inr])
(* Log *)
>- (fs[mk_single_app_def] >> rveq >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
simp[evaluate_IMP_inr])
(* If *)
>- (fs[mk_single_app_def] >> rveq >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
fs[Once evaluate_def] >>
TOP_CASE_TAC >> reverse TOP_CASE_TAC >-
(fs[] >> rveq >> fs[mk_inr_res_def]) >>
fs[semanticPrimitivesTheory.do_if_def] >>
rw[] >> fs[] >>
rveq >> fs[mk_inr_res_def])
(* Mat *)
>- (fs[mk_single_app_def] >> rveq >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
fs[Once evaluate_def] >>
TOP_CASE_TAC >> reverse TOP_CASE_TAC >-
(fs[] >> rveq >> fs[mk_inr_res_def]) >>
fs [pair_case_eq, CaseEq"result",CaseEq"bool"] >>
imp_res_tac mk_single_appps_MAP_FST >> fs [] >>
rveq >> fs[mk_inr_res_def])
(* Let *)
>- (rename1 `Let xo` >> Cases_on `xo` >>
fs[mk_single_app_def] >> rveq >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
fs[Once evaluate_def] >>
TOP_CASE_TAC >> reverse TOP_CASE_TAC >-
(fs[] >> rveq >> fs[mk_inr_res_def]) >>
fs[] >> rveq >> fs[mk_inr_res_def])
(* Letrec *)
>- (fs[mk_single_app_def] >> rveq >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
fs[Once evaluate_def] >>
rw[] >> fs[] >> rveq >> fs[mk_inr_res_def])
(* Tannot *)
>- (fs[mk_single_app_def] >> rveq >>
fs[Once evaluate_def])
(* Lannot *)
>- (fs[mk_single_app_def] >> rveq >>
fs[Once evaluate_def])
(* FpOptimise *)
>- (fs[mk_single_app_def] >> rveq >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
irule evaluate_IMP_inr >> fs[])
(* Pmatch empty row *)
>- (fs[mk_single_app_def] >> rveq >>
fs[evaluate_def] >> rveq >>
fs[mk_inr_res_def])
(* Pmatch cons *)
>- (fs[mk_single_app_def] >> rveq >>
fs[Once evaluate_def] >> rveq >>
reverse IF_CASES_TAC >-
(fs[] >> rveq >> fs[mk_inr_res_def]) >>
fs[] >> rveq >> fs[mk_inr_res_def, fp_translate_def] >>
TOP_CASE_TAC >> gs[] >> rveq >> fs[mk_inr_res_def])
);
val mk_single_app_NONE_evaluate_single = Q.prove(
`(!^st env e e'. mk_single_app NONE T e = SOME e'
/\ do_con_check env.c (SOME (Short "Inr")) 1
/\ (!v. build_conv env.c (SOME (Short "Inr")) [v] =
SOME(Conv (SOME (TypeStamp "Inr" 4)) [v]))
==> evaluate st env [e']
= case evaluate st env [e] of
(st',res) => (st', mk_inr_res res)
)`,
rpt strip_tac >>
match_mp_tac(CONJUNCT1 mk_single_app_NONE_evaluate) >>
simp[mk_single_app_def]);
val partially_evaluates_to_def = Define `
partially_evaluates_to fv env st [] = T /\
partially_evaluates_to fv env st ((e1,e2)::r) =
case evaluate st env [e1] of
(st',Rval v1) =>
(?v. dest_inr_v(HD v1) = SOME v /\ evaluate st env [e2] = (st',Rval [v]) /\
partially_evaluates_to fv env st' r)
\/
(?v st'' res. dest_inl_v(HD v1) = SOME v /\ evaluate st env [e2] = (st'',res) /\
case do_opapp [fv;v] of
SOME(env',e3) =>
if st'.clock = 0 then st'' = st' /\ res = Rerr(Rabort(Rtimeout_error))
else
evaluate (dec_clock st') env' [e3] = (st'',res) /\
(case res of Rval _ =>
partially_evaluates_to fv env st'' r
| _ => T)
| NONE => res = Rerr (Rabort Rtype_error))
| (st',rerr) => evaluate st env [e2] = (st',rerr)
`;
val partially_evaluates_to_match_def = Define `
partially_evaluates_to_match fv mv err_v env st (pr1,pr2) =
case evaluate_match st env mv pr1 err_v of
(st',Rval v1) =>
(?v. dest_inr_v(HD v1) = SOME v /\ evaluate_match st env mv pr2 err_v = (st',Rval [v]))
\/
(?v st'' res. dest_inl_v(HD v1) = SOME v /\ evaluate_match st env mv pr2 err_v = (st'',res) /\
case do_opapp [fv;v] of
SOME(env',e3) =>
if st'.clock = 0 then (st'' = st' /\ res = Rerr(Rabort(Rtimeout_error)))
else
evaluate (dec_clock st') env' [e3] = (st'',res)
| NONE => res = Rerr (Rabort Rtype_error))
| (st',rerr) => evaluate_match st env mv pr2 err_v = (st',rerr)
`;
val mk_single_app_evaluate = Q.prove(
`(!^st env es es' fname fv. mk_single_apps (SOME fname) T es = SOME es'
/\ do_con_check env.c (SOME (Short "Inr")) 1 = T
/\ (!v. build_conv env.c (SOME (Short "Inr")) [v] =
SOME(Conv (SOME (TypeStamp "Inr" 4)) [v]))
/\ do_con_check env.c (SOME (Short "Inl")) 1 = T
/\ (!v. build_conv env.c (SOME (Short "Inl")) [v] =
SOME(Conv (SOME (TypeStamp "Inl" 4)) [v]))
/\ nsLookup env.v (Short fname) = SOME fv
==> partially_evaluates_to fv env st (ZIP(es',es))
) /\
(!^st env v pes err_v pes' fname fv. mk_single_appps (SOME fname) T pes = SOME pes'
/\ do_con_check env.c (SOME (Short "Inr")) 1 = T
/\ (!v. build_conv env.c (SOME (Short "Inr")) [v] =
SOME(Conv (SOME (TypeStamp "Inr" 4)) [v]))
/\ do_con_check env.c (SOME (Short "Inl")) 1 = T
/\ (!v. build_conv env.c (SOME (Short "Inl")) [v] =
SOME(Conv (SOME (TypeStamp "Inl" 4)) [v]))
/\ nsLookup env.v (Short fname) = SOME fv
==> partially_evaluates_to_match fv v err_v env st (pes',pes)
)
`,
ho_match_mp_tac evaluate_ind >> rpt strip_tac
(* Nil *)
>- (fs[mk_single_app_def] >> rveq >> fs[partially_evaluates_to_def])
(* Sequence *)
>- (fs[mk_single_app_def] >>
rveq >> fs[partially_evaluates_to_def,ZIP] >>
TOP_CASE_TAC >> TOP_CASE_TAC >>
fs[PULL_EXISTS] >>
rpt(first_x_assum drule >> rpt(disch_then drule) >> rpt strip_tac) >>
rfs[partially_evaluates_to_def]
>- (first_x_assum drule >> rpt(disch_then drule) >> fs[]) >>
disj2_tac >>
ntac 4 (TOP_CASE_TAC >> fs[]) >> metis_tac[])
(* Lit *)
>- (fs[mk_single_app_def] >> rveq >>
fs[partially_evaluates_to_def,evaluate_inr] >>
fs[evaluate_def,mk_inr_res_def,dest_inr_v_def])
(* Raise *)
>- (fs[mk_single_app_def] >> rveq >>
fs[partially_evaluates_to_def,evaluate_def] >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
every_case_tac >> fs[])
(* Handle *)
>- (fs[mk_single_app_def] >> rveq >>
fs[partially_evaluates_to_def] >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
fs[Once evaluate_def] >>
fs[evaluate_inr] >>
every_case_tac >> fs[PULL_EXISTS] >> rveq >>
imp_res_tac mk_single_appps_MAP_FST >>
fs[mk_inr_res_def] >> rveq >>
imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1] >>
fs[dest_inr_v_def] >>
fs[evaluate_def] >>
rpt(first_x_assum drule >> rpt(disch_then drule) >> rpt strip_tac) >>
rfs[partially_evaluates_to_match_def] >>
every_case_tac >> fs[])
(* Con *)
>- (fs[mk_single_app_def] >> rveq >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
fs[partially_evaluates_to_def] >>
fs[evaluate_inr] >>
every_case_tac >> fs[] >>
imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1] >>
fs[mk_inr_res_def] >> rveq >> fs[dest_inr_v_def])
(* Var*)
>- (rename1 `Var n` >> Cases_on `n` >>
fs[mk_single_app_def] >> rveq >>
fs[partially_evaluates_to_def] >>
fs[evaluate_inr] >>
every_case_tac >> fs[] >>
imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1] >>
fs[mk_inr_res_def] >> rveq >> fs[dest_inr_v_def])
(* Fun *)
>- (fs[mk_single_app_def] >> rveq >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
simp[partially_evaluates_to_def,evaluate_inr] >>
simp[evaluate_def,mk_inr_res_def,dest_inr_v_def])
(* App *)
>- (fs[mk_single_app_def] >>
reverse(Cases_on `op = Opapp`)
>- (Cases_on `op` >>
rveq >> fs[cfNormaliseTheory.dest_opapp_def] >>
rveq >> simp[evaluate_inr,partially_evaluates_to_def] >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
simp[] >> every_case_tac >> fs[mk_inr_res_def] >>
rfs[] >> imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1] >> rveq >>
rfs[] >> fs[dest_inr_v_def]) >>
rveq >>
Cases_on `es`
>- (fs[cfNormaliseTheory.dest_opapp_def] >>
rveq >> simp[partially_evaluates_to_def,evaluate_inr] >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
simp[] >> every_case_tac >> fs[mk_inr_res_def] >>
rfs[] >> imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1] >> rveq >>
rfs[] >> fs[dest_inr_v_def]) >>
rename1 `dest_opapp (App Opapp (exp::exps))` >>
reverse(Cases_on `exps`)
>- (fs[cfNormaliseTheory.dest_opapp_def] >>
simp[] >> rpt(PURE_FULL_CASE_TAC >> fs[] >> rveq) >>
fs[mk_single_app_def] >> rveq >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
TRY(qmatch_goalsub_abbrev_tac `Letrec l e` >>
Cases_on `EXISTS ($= (SOME fname) ∘ SOME) (MAP FST l)` >>
FULL_SIMP_TAC std_ss [] >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
fs[partially_evaluates_to_def,evaluate_inr,evaluate_inl] >>
rpt(PURE_FULL_CASE_TAC >> rveq >> fs[]) >>
imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1] >> rveq >>
fs[mk_inr_res_def] >> rveq >> fs[dest_inr_v_def]) >>
TRY(qmatch_goalsub_abbrev_tac `mk_inr` >>
fs[partially_evaluates_to_def,evaluate_inr,evaluate_inl] >>
rpt(PURE_FULL_CASE_TAC >> rveq >> fs[]) >>
imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1] >> rveq >>
fs[mk_inr_res_def] >> rveq >> fs[dest_inr_v_def] >>
imp_res_tac dest_opapp_eq_nil_IMP) >>
imp_res_tac dest_opapp_eq_nil_IMP >>
fs[partially_evaluates_to_def,evaluate_inl] >>
fs[evaluate_def] >>
rpt(PURE_FULL_CASE_TAC >> rveq >> fs[]) >>
imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1] >> rveq >>
fs[mk_inl_res_def] >> rveq >>
fs[dest_inl_v_def,dest_inr_v_def] >>
fs[astTheory.getOpClass_def] >>
qmatch_goalsub_abbrev_tac `a1 = _` >>
MAP_EVERY qexists_tac [`FST a1`,`SND a1`] >>
simp[] >> PURE_TOP_CASE_TAC >> simp[]) >>
fs[cfNormaliseTheory.dest_opapp_def] >>
rveq >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
simp[partially_evaluates_to_def,evaluate_inr] >>
simp[evaluate_def] >>
every_case_tac >> fs[mk_inr_res_def] >>
rveq >>
imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1] >> rveq >>
fs[dest_inr_v_def])
(* Log *)
>- (fs[mk_single_app_def] >> rveq >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
simp[partially_evaluates_to_def,evaluate_inr] >>
every_case_tac >> fs[mk_inr_res_def] >> rfs[] >>
imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1] >> rveq >>
rfs[dest_inr_v_def])
(* If *)
>- (fs[mk_single_app_def] >> rveq >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
simp[partially_evaluates_to_def] >>
fs[evaluate_def,semanticPrimitivesTheory.do_if_def] >>
Cases_on `evaluate st env [e1]` >> rename1 `(_,result)` >>
reverse(Cases_on `result`) >- fs[] >>
rw[] >> fs[] >> rfs[] >>
rfs[partially_evaluates_to_def,PULL_EXISTS] >>
rpt(first_x_assum drule >> rpt(disch_then drule) >> rpt strip_tac))
(* Mat *)
>- (fs[mk_single_app_def] >> rveq >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
simp[partially_evaluates_to_def] >>
Cases_on `evaluate st env [e]` >> rename1 `(_,result)` >>
reverse(Cases_on `result`) >- fs[evaluate_def] >>
fs[evaluate_def,partially_evaluates_to_match_def,PULL_EXISTS] >>
imp_res_tac mk_single_appps_MAP_FST >>
IF_CASES_TAC >> fs [] >>
rpt(first_x_assum drule >> rpt(disch_then drule) >> rpt strip_tac) >>
rpt(TOP_CASE_TAC >> fs[] >> rveq))
(* Let *)
>- (rename1 `Let xo` >> Cases_on `xo` >>
fs[mk_single_app_def] >> rveq >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
fs[partially_evaluates_to_def,PULL_EXISTS] >>
fs[evaluate_def,namespaceTheory.nsOptBind_def] >>
Cases_on `evaluate st env [e1]` >> rename1 `(_,result)` >>
reverse(Cases_on `result`) >- fs[evaluate_def] >>
rpt(first_x_assum drule >> rpt(disch_then drule) >> rpt strip_tac) >>
fs[] >>
rpt(first_x_assum drule >> rpt(disch_then drule) >> rpt strip_tac) >>
Cases_on `x = fname` >> fs[] >> rveq >> fs[ml_progTheory.nsLookup_nsBind_compute] >>
rpt(first_x_assum drule >> rpt(disch_then drule) >> rpt strip_tac) >>
fs[] >>
drule mk_single_app_NONE_evaluate_single >>
qmatch_goalsub_abbrev_tac `evaluate a1 a2` >>
disch_then(qspecl_then [`a1`,`a2`] mp_tac) >>
unabbrev_all_tac >>
simp[] >> disch_then kall_tac >>
every_case_tac >> fs[mk_inr_res_def] >>
rveq >>
imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1] >>
rveq >> fs[dest_inr_v_def])
(* Letrec *)
>- (fs[mk_single_app_def] >> rveq >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
PURE_FULL_CASE_TAC >> FULL_SIMP_TAC std_ss [] >>
fs[partially_evaluates_to_def,evaluate_def] >>
rw[] >> fs[PULL_EXISTS] >>
rpt(first_x_assum drule >> rpt(disch_then drule) >> rpt strip_tac) >>
rfs[o_DEF,nsLookup_build_rec_env_fresh,partially_evaluates_to_def] >>
drule mk_single_app_NONE_evaluate_single >>
qmatch_goalsub_abbrev_tac `evaluate a1 a2` >>
disch_then(qspecl_then [`a1`,`a2`] mp_tac) >>
unabbrev_all_tac >>
simp[] >> disch_then kall_tac >>
every_case_tac >> fs[mk_inr_res_def] >>
rveq >>
imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1] >>
rveq >> fs[dest_inr_v_def])
(* Tannot *)
>- (fs[mk_single_app_def] >> rveq >>
fs[PULL_EXISTS] >> first_x_assum drule >>
rpt(disch_then drule) >>
simp[partially_evaluates_to_def,evaluate_def])
(* Lannot *)
>- (fs[mk_single_app_def] >> rveq >>
fs[PULL_EXISTS] >> first_x_assum drule >>
rpt(disch_then drule) >>
simp[partially_evaluates_to_def,evaluate_def])
(* FpOptimise *)
>- (fs[mk_single_app_def] >> rveq >>
imp_res_tac mk_single_app_F_unchanged >> rveq >>
rw[] >> fs[PULL_EXISTS] >>
fs[partially_evaluates_to_def] >>
fs [evaluate_inr] >>
Cases_on `evaluate st env [FpOptimise annot e]` >> fs[] >>
rename1 `_ = (_, result)` >> Cases_on `result` >> fs[mk_inr_res_def] >>
imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1] >>
rveq >> fs[dest_inr_v_def])
(* Pmatch empty row *)
>- (fs[mk_single_app_def] >> rveq >>
simp[partially_evaluates_to_match_def,evaluate_def])
(* Pmatch cons *)
>- (fs[mk_single_app_def] >> rveq >>
PURE_FULL_CASE_TAC >> FULL_SIMP_TAC std_ss [] >>
fs[partially_evaluates_to_match_def,evaluate_def] >>
rw[] >>
fs[PULL_EXISTS] >>
Cases_on `pmatch env.c st.refs p v []` >> fs[] >>
rpt(first_x_assum drule >> rpt(disch_then drule) >> strip_tac) >>
rfs[o_DEF,partially_evaluates_to_def] >>
fs[ml_progTheory.nsLookup_nsAppend_Short] >>
imp_res_tac semanticPrimitivesPropsTheory.pmatch_extend >> rveq >>
rfs[] >>
qpat_x_assum `MAP _ _ = pat_bindings _ _` (assume_tac o GSYM) >>
fs[] >> rfs[nsLookup_alist_to_ns_fresh] >>
TRY(qmatch_asmsub_abbrev_tac `mk_single_app (SOME _) T e = SOME ea`
>> every_case_tac >> fs[] >> every_case_tac >> fs[]) >>
drule mk_single_app_NONE_evaluate_single >>
qmatch_goalsub_abbrev_tac `evaluate a1 a2` >>
disch_then(qspecl_then [`a1`,`a2`] mp_tac) >>
unabbrev_all_tac >>
simp[] >> disch_then kall_tac >>
every_case_tac >> fs[mk_inr_res_def] >>
rveq >>
imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1] >>
qmatch_asmsub_abbrev_tac `evaluate _ _ _ = (_,result)` >>
Cases_on `result` >> fs[mk_inr_res_def] >> rveq >> fs[dest_inr_v_def] >>
imp_res_tac evaluatePropsTheory.evaluate_length >>
fs[quantHeuristicsTheory.LIST_LENGTH_1] >> fs[dest_inr_v_def])
);
Theorem mk_single_app_evaluate_single:
!^st env e e' fname fv. mk_single_app (SOME fname) T e = SOME e'
/\ do_con_check env.c (SOME (Short "Inr")) 1 = T
/\ (!v. build_conv env.c (SOME (Short "Inr")) [v] =
SOME(Conv (SOME (TypeStamp "Inr" 4)) [v]))
/\ do_con_check env.c (SOME (Short "Inl")) 1 = T
/\ (!v. build_conv env.c (SOME (Short "Inl")) [v] =
SOME(Conv (SOME (TypeStamp "Inl" 4)) [v]))
/\ nsLookup env.v (Short fname) = SOME fv
==> partially_evaluates_to fv env st [(e',e)]
Proof
rpt strip_tac >>
`mk_single_apps (SOME fname) T [e] = SOME [e']` by simp[mk_single_app_def] >>
drule(CONJUNCT1 mk_single_app_evaluate) >>
rpt(disch_then drule) >> simp[]
QED
val evaluate_tailrec_ind_lemma = Q.prove(
`!ck fbody gbody env env' ^st farg x v fname st' res.
mk_single_app (SOME fname) T fbody = SOME gbody /\
do_con_check env.c (SOME (Short "Inr")) 1 /\
(∀v.
build_conv env.c (SOME (Short "Inr")) [v] =
SOME (Conv (SOME (TypeStamp "Inr" 4)) [v])) /\
do_con_check env.c (SOME (Short "Inl")) 1 /\
res <> Rerr(Rabort(Rtimeout_error)) /\
(∀v.
build_conv env.c (SOME (Short "Inl")) [v] =
SOME (Conv (SOME (TypeStamp "Inl" 4)) [v])) /\
fname <> farg /\
evaluate_ck ck ^st
(env with
v :=
nsBind "x" v
(nsBind "f"
(Closure
(env with
v :=
nsBind fname (Recclosure env [(fname,farg,fbody)] fname)