-
Notifications
You must be signed in to change notification settings - Fork 84
/
CakeMLtoFloVerProofsScript.sml
2066 lines (2014 loc) · 81.9 KB
/
CakeMLtoFloVerProofsScript.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
(*
Main connection theorem relating FloVer's roundoff error bound
to CakeML floating-point kernel executions
*)
(* HOL4 *)
open machine_ieeeTheory realTheory realLib RealArith;
(* CakeML *)
open semanticPrimitivesTheory evaluateTheory ml_translatorTheory;
(* FloVer *)
open ExpressionsTheory ExpressionSemanticsTheory CommandsTheory
EnvironmentsTheory IEEE_connectionTheory
FloverMapTheory TypeValidatorTheory;
(* Icing *)
open fpSemTheory source_to_source2Theory CakeMLtoFloVerTheory
CakeMLtoFloVerLemsTheory floatToRealTheory floatToRealProofsTheory;
open preamble;
val _ = new_theory "CakeMLtoFloVerProofs";
(* TODO: Move to HOL4 distrib *)
Theorem float_is_finite_sandwich:
∀ (w1:('a,'b) float) (w2:('a,'b) float) (w3:('a,'b) float).
float_less_equal w1 w2 ∧
float_less_equal w2 w3 ∧
float_is_finite w1 ∧
float_is_finite w3 ⇒
float_is_finite w2
Proof
rpt strip_tac
\\ fs[binary_ieeeTheory.float_is_finite_def,
binary_ieeeTheory.float_less_equal_def]
\\ Cases_on ‘float_value w1’ \\ fs[]
\\ Cases_on ‘float_value w3’ \\ fs[]
\\ Cases_on ‘float_compare w1 w2’ \\ fs[]
\\ Cases_on ‘float_compare w2 w3’ \\ rfs[binary_ieeeTheory.float_compare_def]
\\ Cases_on ‘float_value w2’ \\ fs[]
\\ Cases_on ‘w2.Sign = 1w’ \\ fs[]
QED
Theorem fp64_isFinite_sandwich:
∀ w1 w2 w3.
fp64_lessEqual w1 w2 ∧
fp64_lessEqual w2 w3 ∧
fp64_isFinite w1 ∧
fp64_isFinite w3 ⇒
fp64_isFinite w2
Proof
fs[fp64_lessEqual_def, fp64_isFinite_def]
\\ rpt strip_tac
\\ irule float_is_finite_sandwich
\\ fsrw_tac [SATISFY_ss] []
QED
Theorem closest_such_0:
∀ (f:('a, 'b) float).
closest_such (λ a. ~word_lsb a.Significand) float_is_finite 0 = f ⇒
f = float_plus_zero (:'a # 'b) ∨ f = float_minus_zero (:'a # 'b)
Proof
rpt strip_tac \\ rveq
\\ fs[binary_ieeeTheory.closest_such_def]
\\ SELECT_ELIM_TAC \\ rpt strip_tac
>- (
fs[binary_ieeeTheory.is_closest_def]
\\ qexists_tac ‘float_plus_zero (:'a # 'b)’
\\ fs[binary_ieeeTheory.float_is_finite, IN_DEF,
binary_ieeeTheory.zero_properties, binary_ieeeTheory.zero_to_real,
ABS_POS]
\\ rpt strip_tac
\\ fs[wordsTheory.word_lsb_def, binary_ieeeTheory.float_plus_zero_def]
\\ pop_assum (fn thm => assume_tac (EVAL_RULE thm)) \\ fs[])
\\ fs[binary_ieeeTheory.is_closest_def]
\\ last_x_assum (qspec_then ‘float_plus_zero (:'a # 'b)’ mp_tac)
\\ simp[binary_ieeeTheory.float_is_finite, IN_DEF,
binary_ieeeTheory.zero_properties, binary_ieeeTheory.zero_to_real,
ABS_POS]
\\ rpt strip_tac
\\ ‘float_is_zero x’ by (fs[binary_ieeeTheory.float_is_zero_to_real])
\\ fs[binary_ieeeTheory.float_is_zero, binary_ieeeTheory.float_plus_zero_def,
binary_ieeeTheory.float_minus_zero_def]
\\ Cases_on ‘x’ \\ Cases_on ‘c’ \\ Cases_on ‘n’ \\ fs[]
\\ TRY (rename1 ‘SUC n < 2’ \\ Cases_on ‘n’)
\\ fs[binary_ieeeTheory.float_negate_def, binary_ieeeTheory.float_component_equality]
QED
Definition v_word_eq_def:
v_word_eq (FP_WordTree fp) w = (compress_word fp = w) ∧
(* v_word_eq (Litv (Word64 w1)) w2 = (w1 = w2) ∧ *)
v_word_eq _ _ = F
End
(**
Relation: env_word_sim
Arguments:
The CakeML environment env, the FloVer environment E, and a set of pairs of
CakeML * FloVer variables, and a type environment Gamma
The environments env and E are in relation with each other for the set of
variables fVars under the type assignment Gamma,
if and only if for every pair of variables (cake_id, flover_id):
if the CakeML environment binds cake_id, the FloVer environment must bind
flover_id to a value r that is in relation with the CakeML value for the type
in Gamma, and
if the FloVer environment binds flover_id, and has a type in Gamma, the
the CakeML environment binds the variable cake_id to a value that is in
relation with the FloVer value under the type from Gamma **)
Definition env_word_sim_def:
env_word_sim env (E:num -> word64 option) fVars =
(∀ (cake_id:(string, string) id) (flover_id:num).
(cake_id, flover_id) IN fVars ⇒
(∀ v.
nsLookup env cake_id = SOME v ⇒
∃ r. E flover_id = SOME r ∧ v_word_eq v r) ∧
(∀ r.
E flover_id = SOME r ⇒
∃ v. nsLookup env cake_id = SOME v ∧ v_word_eq v r))
End
Theorem env_word_sim_inhabited:
(∀ x y. (x,y) IN fVars ⇒ lookupFloVerVar y ids = SOME (x,y)) ∧
(∀ x y. (x,y) IN fVars ⇒ ∃ fp. nsLookup env x = SOME (FP_WordTree fp))⇒
env_word_sim env
(λ x. case lookupFloVerVar x ids of
|NONE => NONE
|SOME (cakeId, _) =>
case nsLookup env cakeId of
|SOME (Litv (Word64 w)) => SOME w
|SOME (FP_WordTree fp) => SOME (compress_word fp)
| _ => NONE) fVars
Proof
rpt strip_tac \\ fs[env_word_sim_def]
\\ rpt strip_tac \\ res_tac \\ fs[] \\ rveq \\ fs[option_case_eq, v_word_eq_def]
QED
(**
Relation: v_eq
Arguments:
The CakeML value v, a real number r, and a FloVer type m.
The predicate returns true, iff either m is REAL, and v represents exactly the
real number r, or m is M64 for a 64-bit double number, v is a double value or
a value tree, and r is the translation to reals of v. **)
Definition v_eq_def:
v_eq (FP_WordTree fp) r M64 = (r = fp64_to_real (compress_word fp)) ∧
(* v_eq (Litv (Word64 w)) r M64 = (r = fp64_to_real w) ∧ *)
v_eq (Real r1) r2 REAL = (r1 = r2) ∧
v_eq _ _ _ = F
End
(**
Triviality v_eq_float:
v_eq (Litv (Word64 w)) r m ⇔ ((m = M64) ∧ r = fp64_to_real w)
Proof
Cases_on ‘m’ \\ fs[v_eq_def]
QED
**)
Triviality v_eq_valtree:
v_eq (FP_WordTree fp) r m ⇔ ((m = M64) ∧ r = fp64_to_real (compress_word fp))
Proof
Cases_on ‘m’ \\ fs[v_eq_def]
QED
Triviality v_eq_real:
v_eq v r REAL ⇔ v = Real r
Proof
Cases_on ‘v’ \\ fs[v_eq_def]
QED
(**
Relation: env_sim
Arguments:
The CakeML environment env, the FloVer environment E, and a set of pairs of
CakeML * FloVer variables, and a type environment Gamma
The environments env and E are in relation with each other for the set of
variables fVars under the type assignment Gamma,
if and only if for every pair of variables (cake_id, flover_id):
if the CakeML environment binds cake_id, the FloVer environment must bind
flover_id to a value r that is in relation with the CakeML value for the type
in Gamma, and
if the FloVer environment binds flover_id, and has a type in Gamma, the
the CakeML environment binds the variable cake_id to a value that is in
relation with the FloVer value under the type from Gamma **)
Definition env_sim_def:
env_sim env E fVars (Gamma:(real expr -> mType option)) =
(∀ (cake_id:(string, string) id) (flover_id:num).
(cake_id, flover_id) IN fVars ⇒
(∀ v.
nsLookup env cake_id = SOME v ⇒
∃ r m. E flover_id = SOME r ∧ Gamma (Var flover_id) = SOME m ∧ v_eq v r m) ∧
(∀ r m.
E flover_id = SOME r ∧
Gamma (Var flover_id) = SOME m ⇒
∃ v. nsLookup env cake_id = SOME v ∧ v_eq v r m))
End
Definition type_correct_def:
type_correct (Real r) REAL = T ∧
type_correct (FP_WordTree fp) M64 = T ∧
(* type_correct (Litv (Word64 w)) M64 = T ∧ *)
type_correct _ _ = F
End
(**
Relation: env_sim_real
Arguments:
The CakeML environment env, the FloVer environment E, and a set of pairs of
CakeML * FloVer variables, and a type environment Gamma
The environments env and E are in relation with each other for the set of
variables fVars under the type assignment Gamma,
if and only if for every pair of variables (cake_id, flover_id):
if the CakeML environment binds cake_id, the FloVer environment must bind
flover_id to a value r that is in relation with the CakeML value for the type
in Gamma, and
if the FloVer environment binds flover_id, and has a type in Gamma, the
the CakeML environment binds the variable cake_id to a value that is in
relation with the FloVer value under the type from Gamma **)
Definition env_sim_real_def:
env_sim_real env E fVars =
(∀ (cake_id:(string, string) id) (flover_id:num).
(cake_id, flover_id) IN fVars ⇒
(∀ v.
nsLookup env cake_id = SOME v ⇒
∃ r. E flover_id = SOME r ∧ v_eq v r REAL) ∧
(∀ r.
E flover_id = SOME r ⇒
∃ v. nsLookup env cake_id = SOME v ∧ v_eq v r REAL))
End
Definition toRspace_def:
toRspace env =
nsMap (λ (x:v). case x of
(* |Litv (Word64 w) => Real (fp64_to_real w) *)
| FP_WordTree fp => Real (fp64_to_real (compress_word fp))
| _ => x) env
End
Theorem env_sim_real_from_word_sim:
∀ env Ed fVars.
env_word_sim env Ed fVars ⇒
env_sim_real (toRspace env)
(λ x. case Ed x of SOME w => SOME (fp64_to_real w) | _ => NONE)
fVars
Proof
rpt strip_tac \\ fs[env_word_sim_def, env_sim_real_def, toRspace_def,
namespacePropsTheory.nsLookup_nsMap]
\\ rpt strip_tac \\ res_tac \\ fs[type_correct_def] \\ rveq
>- (
rename1 ‘v_word_eq v r’ \\ Cases_on ‘v’
\\ fs[v_word_eq_def, ExpressionAbbrevsTheory.toRTMap_def]
\\ TRY (rename1 ‘v_word_eq (Litv l) r’ \\ Cases_on ‘l’ \\ fs[v_word_eq_def])
\\ rveq \\ fs[type_correct_def, v_eq_def])
\\ fs[option_case_eq] \\ rveq \\ res_tac
\\ Cases_on ‘v’ \\ fs[v_word_eq_def]
\\ TRY (rename1 ‘v_word_eq (Litv l) r’ \\ Cases_on ‘l’ \\ fs[v_word_eq_def])
\\ rveq \\ fs[type_correct_def, v_eq_def]
QED
(*
Theorem approxEnv_construct:
∀ E1 Gamma A fVars.
(∀ x. ~ (x IN domain fVars) ⇒ E1 x = NONE) ∧
(∀ x. x IN domain fVars ⇒ Gamma (Var x) = SOME M64) ∧
(∀ x. x IN domain fVars ⇒ ∃ v. E1 x = SOME v) ∧
(∀ x v. E1 x = SOME v ⇒ (binary_ieeeTheory.float_is_finite (float_to_fp64 (round roundTiesToEven v)))) ==>
approxEnv E1
Gamma A fVars LN
(toREnv
(λ n. case E1 n of
|NONE => NONE
| SOME v => SOME (float_to_fp64 (round roundTiesToEven v))))
Proof
fs[approxEnv_def] \\ rpt strip_tac
\\ res_tac \\ fs[toREnv_def]
\\ simp[fp64_to_float_float_to_fp64]
\\ ‘normalizes (:52 # 11) v ∨ v = 0’
by (first_x_assum irule \\ fsrw_tac [SATISFY_ss] [])
>- (
imp_res_tac lift_ieeeTheory.relative_error
\\ simp[MachineTypeTheory.computeError_def, MachineTypeTheory.mTypeToR_def]
\\ rewrite_tac [REAL_LDISTRIB, REAL_MUL_RID, real_sub, REAL_NEG_ADD,
REAL_ADD_ASSOC]
\\ fs[ABS_NEG, ABS_MUL]
\\ irule REAL_LE_TRANS \\ qexists_tac ‘1 * realax$abs v’
\\ reverse conj_tac >- fs[]
\\ rewrite_tac [REAL_MUL_ASSOC]
\\ irule REAL_LE_RMUL_IMP \\ fs[ABS_POS])
\\ rveq \\ fs[binary_ieeeTheory.round_def, binary_ieeeTheory.threshold]
\\ Q.ISPEC_THEN ‘f:(52,11) float’
(assume_tac o SIMP_RULE std_ss [] o GEN_ALL) closest_such_0
\\ fs[binary_ieeeTheory.zero_to_real, MachineTypeTheory.computeError_def]
QED
*)
Theorem buildFloVerTypeMap_is_64Bit:
∀ floverVars. is64BitEnv (buildFloVerTypeMap floverVars)
Proof
Induct_on ‘floverVars’
\\ fs[buildFloVerTypeMap_def, is64BitEnv_def,
FloverMapTree_empty_def, FloverMapTree_find_def, map_find_add]
\\ rpt strip_tac \\ every_case_tac \\ rveq
\\ fs[ExpressionAbbrevsTheory.toRExpMap_def, FloverMapTheory.map_find_add]
\\ res_tac
QED
Theorem eval_expr_real:
∀ Gamma E e v m.
(∀ x m. Gamma x = SOME m ⇒ m = REAL) ∧
eval_expr E Gamma (toREval e) v m ⇒
m = REAL
Proof
Induct_on ‘e’ \\ rpt strip_tac
\\ fs[Once toREval_def, Once eval_expr_cases] \\ rveq
\\ res_tac
QED
Theorem CakeML_FloVer_real_sim_exp:
∀ varMap f theExp freshId E env fVars (st:'ffi semanticPrimitives$state) Gamma v.
toFloVerExp varMap f = SOME theExp ∧
ids_unique varMap freshId ∧
st.fp_state.real_sem ∧
env_sim_real env.v E fVars ∧
(∀ x. x IN freevars [f] ⇒ ∃ y. lookupCMLVar x varMap = SOME (x,y) ∧ (x,y) IN fVars) ∧
eval_expr E (toRTMap Gamma) (toREval (toRExp theExp)) v REAL ⇒
evaluate st env [realify f] = (st, Rval [Real v])
Proof
ho_match_mp_tac toFloVerExp_ind
\\ rpt strip_tac
\\ ((rename1 ‘App op exps’ \\ imp_res_tac toFloVerExp_App_cases)
ORELSE
(qpat_x_assum ‘toFloVerExp _ _ = SOME _’ mp_tac
\\ simp[Once toFloVerExp_def] \\ rpt strip_tac))
\\ rveq \\ fs[realify_def, freevars_def]
\\ rfs[] \\ rveq \\ fs [toRExp_def, toREval_def, eval_expr_cases]
>- (
fs[env_sim_real_def] \\ rveq
\\ fs[ExpressionAbbrevsTheory.toRExpMap_def,
ExpressionAbbrevsTheory.toRTMap_def, option_case_eq]
\\ simp[evaluate_def] \\ res_tac \\ fs[v_eq_real])
>- (
simp[realify_def, evaluate_def, astTheory.getOpClass_def]
\\ fs[MachineTypeTheory.mTypeToR_def, perturb_def] \\ rveq
\\ simp[do_app_def, fp64_to_real_def, state_component_equality])
>- (
rveq \\ rpt (qpat_x_assum ‘T’ kall_tac)
\\ fs[freevars_def]
\\ Cases_on ‘m'’ \\ fs[MachineTypeTheory.isCompat_def]
\\ ‘evaluate st env [realify e] = (st, Rval [Real v1])’
by (
last_x_assum drule \\ rpt (disch_then drule)
\\ fs[MachineTypeTheory.isCompat_def])
\\ simp[realify_def, evaluate_def, astTheory.getOpClass_def,
getRealUop_def]
\\ fs[do_app_def] \\ EVAL_TAC \\ fs[state_component_equality])
>- (
rveq \\ rpt (qpat_x_assum ‘T’ kall_tac)
\\ fs[freevars_def]
\\ Cases_on ‘m1’ \\ fs[MachineTypeTheory.isCompat_def]
\\ ‘evaluate st env [realify e] = (st, Rval [Real v1])’
by (
last_x_assum drule \\ rpt (disch_then drule)
\\ fs[MachineTypeTheory.isCompat_def])
\\ simp[realify_def, evaluate_def, astTheory.getOpClass_def,
getRealUop_def]
\\ fs[do_app_def] \\ EVAL_TAC \\ fs[state_component_equality])
>- (
rpt (qpat_x_assum ‘T’ kall_tac)
\\ fs[freevars_def]
\\ ‘m1 = REAL ∧ m2 = REAL’
by (
conj_tac \\ irule eval_expr_real
\\ once_rewrite_tac[CONJ_COMM] \\ asm_exists_tac \\ fs[]
\\ rpt strip_tac
\\ Cases_on ‘x’
\\ fs[ExpressionAbbrevsTheory.toRTMap_def, option_case_eq])
\\ rveq
\\ ‘evaluate st env [realify e2] = (st, Rval [Real v2])’
by (
last_x_assum drule \\ rpt (disch_then drule)
\\ disch_then (qspecl_then [‘Gamma’, ‘v2’] mp_tac) \\ impl_tac \\ fs[])
\\ ‘evaluate st env [realify e1] = (st, Rval [Real v1])’
by (
last_x_assum kall_tac
\\ last_x_assum drule \\ rpt (disch_then drule)
\\ disch_then (qspecl_then [‘Gamma’, ‘v1’] mp_tac) \\ impl_tac \\ fs[])
\\ simp[evaluate_def, astTheory.getOpClass_def, semanticPrimitivesTheory.do_app_def]
\\ fs[MachineTypeTheory.mTypeToR_def, perturb_def]
\\ Cases_on ‘bop’ \\ EVAL_TAC \\ fs[state_component_equality])
>- (
rpt (qpat_x_assum ‘T’ kall_tac)
\\ fs[freevars_def]
\\ ‘m1 = REAL ∧ m2 = REAL ∧ m3 = REAL’
by (
rpt conj_tac \\ irule eval_expr_real
\\ once_rewrite_tac[CONJ_COMM] \\ asm_exists_tac \\ fs[]
\\ rpt strip_tac
\\ Cases_on ‘x’
\\ fs[ExpressionAbbrevsTheory.toRTMap_def, option_case_eq])
\\ rveq
\\ ‘∀ (st:'ffi semanticPrimitives$state). st.fp_state.real_sem ⇒
evaluate st env [realify e3] = (st, Rval [Real v2])’
by (
rpt strip_tac
\\ last_x_assum drule \\ rpt (disch_then drule)
\\ disch_then (qspecl_then [‘Gamma’, ‘v2’] mp_tac)
\\ impl_tac \\ fs[])
\\ last_x_assum kall_tac
\\ ‘∀ (st:'ffi semanticPrimitives$state). st.fp_state.real_sem ⇒
evaluate st env [realify e2] = (st, Rval [Real v1])’
by (
rpt strip_tac
\\ last_x_assum drule \\ rpt (disch_then drule)
\\ disch_then (qspecl_then [‘Gamma’, ‘v1’] mp_tac) \\ impl_tac \\ fs[])
\\ last_x_assum kall_tac
\\ ‘∀ (st:'ffi semanticPrimitives$state). st.fp_state.real_sem ⇒
evaluate st env [realify e1] = (st, Rval [Real v3])’
by (
rpt strip_tac
\\ last_x_assum drule \\ rpt (disch_then drule)
\\ disch_then (qspecl_then [‘Gamma’, ‘v3’] mp_tac) \\ impl_tac \\ fs[])
\\ last_x_assum kall_tac
\\ first_x_assum (qspec_then ‘st’ mp_tac) \\ impl_tac \\ fs[]
\\ strip_tac \\ fs[]
\\ last_x_assum (qspec_then ‘st’ mp_tac) \\ impl_tac \\ fs[]
\\ strip_tac \\ fs[]
\\ last_x_assum (qspec_then ‘st’ mp_tac) \\ impl_tac \\ fs[]
\\ strip_tac \\ fs[]
\\ simp[evaluate_def, astTheory.getOpClass_def,
semanticPrimitivesTheory.do_app_def]
\\ simp[semanticPrimitivesTheory.shift_fp_opts_def]
\\ fs[MachineTypeTheory.mTypeToR_def, perturb_def]
\\ EVAL_TAC \\ fs[state_component_equality])
>- (
simp[evaluate_def]
\\ qmatch_goalsub_abbrev_tac ‘evaluate stUpd env [realify f]’
\\ ‘stUpd.fp_state.real_sem’
by (unabbrev_all_tac \\ TOP_CASE_TAC
\\ fs[state_component_equality, fpState_component_equality])
\\ first_x_assum drule
\\ rpt (disch_then drule)
\\ strip_tac \\ unabbrev_all_tac
\\ fs[do_fpoptimise_def, state_component_equality, fpState_component_equality]
\\ TOP_CASE_TAC \\ fs[])
QED
Theorem CakeML_FloVer_real_sim:
∀ varMap freshId f theIds freshId2 theCmd E env fVars (st:'ffi semanticPrimitives$state) Gamma r.
toFloVerCmd varMap freshId f = SOME (theIds, freshId2, theCmd) ∧
ids_unique varMap freshId ∧
st.fp_state.real_sem ∧
env_sim_real env.v E fVars ∧
(∀ x y. (x,y) IN fVars ⇒ lookupCMLVar x varMap = SOME (x,y)) ∧
(∀ x. x IN freevars [f] ⇒ ∃ y. lookupCMLVar x varMap = SOME (x,y) ∧ (x,y) IN fVars) ∧
bstep (toREvalCmd (toRCmd theCmd)) E (toRTMap Gamma) r REAL ⇒
evaluate st env [realify f] = (st, Rval [Real r])
Proof
ho_match_mp_tac toFloVerCmd_ind
\\ rpt strip_tac \\ fs[toFloVerCmd_def]
>- (
fs[option_case_eq, pair_case_eq] \\ rveq
\\ qpat_x_assum ‘bstep _ _ _ _ _’ mp_tac
\\ simp[Once toRCmd_def, Once toREvalCmd_def, bstep_cases, freevars_def]
\\ rpt strip_tac
\\ drule CakeML_FloVer_real_sim_exp \\ rpt (disch_then drule)
\\ disch_then (qspecl_then [‘Gamma’, ‘v’] mp_tac)
\\ impl_tac \\ fs[freevars_def]
\\ disch_then assume_tac \\ fs[]
\\ qpat_assum ‘bstep _ _ _ _ _’
(fn thm => first_x_assum (fn ithm => mp_then Any mp_tac ithm thm))
\\ disch_then
(qspecl_then [‘env with v := (nsOptBind (SOME x) (Real v) env.v)’,
‘fVars UNION { (Short x,freshId)}’,
‘st’] mp_tac)
\\ impl_tac
>- (
rpt conj_tac \\ fs[]
>- (
irule ids_unique_append \\ asm_exists_tac \\ fs[])
>- (
simp[env_sim_real_def] \\ rpt strip_tac \\ fs[namespaceTheory.nsOptBind_def]
>- (
‘cake_id ≠ Short x’
by (CCONTR_TAC
\\ fs[] \\ rveq \\ res_tac
\\ fs[])
\\ ‘flover_id ≠ freshId’
by (CCONTR_TAC
\\ fs[] \\ rveq \\ res_tac
\\ fs[ids_unique_def] \\ res_tac
\\ fs[])
\\ fs[env_sim_real_def] \\ res_tac
\\ fsrw_tac [SATISFY_ss] []
\\ res_tac \\ fs[])
>- (
‘cake_id ≠ Short x’
by (CCONTR_TAC
\\ fs[] \\ rveq \\ res_tac
\\ fs[])
\\ ‘flover_id ≠ freshId’
by (CCONTR_TAC
\\ fs[] \\ rveq \\ res_tac
\\ fs[ids_unique_def] \\ res_tac
\\ fs[])
\\ fs[ml_progTheory.nsLookup_nsBind_compute]
\\ fs[env_sim_real_def] \\ res_tac
\\ fsrw_tac [SATISFY_ss] []
\\ res_tac \\ rfs[])
>- (
rveq \\ fs[ml_progTheory.nsLookup_nsBind_compute]
\\ rveq \\ fs[v_eq_def])
\\ rveq \\ fs[] \\ rveq \\ fs[v_eq_def])
>- (
rpt strip_tac
>- (
fs[lookupCMLVar_appendCMLVar]
\\ ‘x' ≠ Short x’
by (CCONTR_TAC
\\ fs[] \\ rveq \\ res_tac
\\ fs[])
\\ ‘y ≠ freshId’
by (CCONTR_TAC
\\ fs[] \\ rveq \\ res_tac
\\ fs[ids_unique_def] \\ res_tac
\\ fs[])
\\ res_tac
\\ fs[lookupCMLVar_def, updateTheory.FIND_def])
\\ rveq \\ fs[lookupCMLVar_appendCMLVar, lookupCMLVar_def, updateTheory.FIND_def])
>- (
rpt strip_tac
\\ fs[lookupCMLVar_appendCMLVar, lookupCMLVar_def, updateTheory.FIND_def]
\\ TOP_CASE_TAC \\ fs[]
\\ first_x_assum (qspec_then ‘x'’ mp_tac) \\ fs[]
\\ disch_then assume_tac \\ fs[]
\\ fs[]))
\\ disch_then assume_tac \\ fs[]
\\ simp[realify_def, evaluate_def])
\\ TRY (
fs[option_case_eq, pair_case_eq] \\ rveq
\\ fs[Once toRCmd_def, Once toREvalCmd_def, bstep_cases] \\ rveq
\\ drule CakeML_FloVer_real_sim_exp \\ fs[]
\\ rpt (disch_then drule) \\ fs[])
\\ simp[realify_def, evaluate_def]
\\ qmatch_goalsub_abbrev_tac ‘evaluate stUpd env [realify f]’
\\ ‘stUpd.fp_state.real_sem’ by (unabbrev_all_tac \\ TOP_CASE_TAC \\ fs[])
\\ first_x_assum drule
\\ fs[freevars_def]
\\ rpt (disch_then drule)
\\ strip_tac \\ unabbrev_all_tac
\\ fs[do_fpoptimise_def, state_component_equality, fpState_component_equality]
\\ TOP_CASE_TAC \\ fs[]
QED
Theorem CakeML_FloVer_float_sim_exp:
∀ varMap f theExp freshId E env fVars (st:'ffi semanticPrimitives$state) vF.
toFloVerExp varMap f = SOME theExp ∧
st.fp_state.canOpt = FPScope NoOpt ∧
ids_unique varMap freshId ∧
(∀ x y. (x,y) IN fVars ⇒ lookupCMLVar x varMap = SOME (x,y)) ∧
env_word_sim env.v E fVars ∧
(∀ x. x IN freevars [f] ⇒ ∃ y. lookupCMLVar x varMap = SOME (x,y) ∧
(x,y) IN fVars) ∧
eval_expr_float theExp E = SOME vF ⇒
∃ fp. evaluate st env [f] = (st, Rval [FP_WordTree fp]) ∧
v_word_eq (FP_WordTree fp) vF
Proof
ho_match_mp_tac toFloVerExp_ind
\\ rpt strip_tac
\\ ((rename1 ‘App op exps’ \\ imp_res_tac toFloVerExp_App_cases)
ORELSE
(qpat_x_assum ‘toFloVerExp _ _ = SOME _’ mp_tac
\\ simp[Once toFloVerExp_def] \\ rpt strip_tac))
>- (
fs[option_case_eq, pair_case_eq] \\ rveq
\\ fs[eval_expr_float_def, option_case_eq, freevars_def]
\\ rveq \\ fs[env_word_sim_def]
\\ res_tac \\ rveq \\ fs[] \\ rveq
\\ simp[evaluate_def]
\\ Cases_on ‘v’ \\ fs[v_word_eq_def])
>- (
rveq \\ fs[]
\\ rpt (qpat_x_assum `T` kall_tac)
\\ fs[eval_expr_float_def] \\ rveq \\ fs[]
\\ simp[evaluate_def, astTheory.getOpClass_def,
semanticPrimitivesTheory.do_app_def, fpSemTheory.compress_word_def,
state_component_equality,
v_word_eq_def])
>- (
fs[option_case_eq, pair_case_eq] \\ rveq
\\ rpt (qpat_x_assum ‘T’ kall_tac)
\\ fs[eval_expr_float_def, option_case_eq, freevars_def]
\\ rveq \\ fs[]
\\ ‘∃ vFC. evaluate st env [e] = (st, Rval [vFC]) ∧
v_word_eq vFC v’
by (
last_x_assum drule \\ rpt (disch_then drule)
\\ disch_then assume_tac \\ fs[])
\\ simp[evaluate_def, v_eq_def, astTheory.getOpClass_def,
semanticPrimitivesTheory.do_app_def]
\\ Cases_on ‘vFC’
\\ TRY (rename1 ‘v_word_eq (Litv l) v’ \\ Cases_on ‘l’)
\\ fs[v_word_eq_def] \\ rveq
\\ fs[v_word_eq_def, semanticPrimitivesTheory.fp_translate_def,
astTheory.isFpBool_def, fpValTreeTheory.fp_uop_def,
state_component_equality,
fpSemTheory.compress_word_def]
\\ EVAL_TAC)
>- (
fs[option_case_eq, pair_case_eq] \\ rveq
\\ rpt (qpat_x_assum ‘T’ kall_tac)
\\ fs[eval_expr_float_def, option_case_eq, freevars_def]
\\ rveq \\ fs[]
\\ ‘∃ vFC. evaluate st env [e] = (st, Rval [vFC]) ∧
v_word_eq vFC v’
by (
last_x_assum drule \\ rpt (disch_then drule)
\\ disch_then assume_tac \\ fs[])
\\ simp[evaluate_def, v_eq_def, astTheory.getOpClass_def,
semanticPrimitivesTheory.do_app_def]
\\ Cases_on ‘vFC’
\\ TRY (rename1 ‘v_word_eq (Litv l) v’ \\ Cases_on ‘l’)
\\ fs[v_word_eq_def] \\ rveq
\\ fs[v_word_eq_def, semanticPrimitivesTheory.fp_translate_def,
astTheory.isFpBool_def, fpValTreeTheory.fp_uop_def,
state_component_equality,
fpSemTheory.compress_word_def]
\\ EVAL_TAC)
>- (
rveq \\ fs[]
\\ rpt (qpat_x_assum ‘T’ kall_tac)
\\ fs[eval_expr_float_def, option_case_eq, freevars_def]
\\ rveq \\ fs[]
\\ ‘∃ fp2. evaluate st env [e2] = (st, Rval [FP_WordTree fp2]) ∧
v_word_eq (FP_WordTree fp2) v2’
by (
last_x_assum drule \\ rpt (disch_then drule)
\\ disch_then (qspec_then ‘v2’ mp_tac) \\ impl_tac \\ fs[])
\\ last_x_assum kall_tac
\\ ‘∃ fp1. evaluate st env [e1] = (st, Rval [FP_WordTree fp1]) ∧
v_word_eq (FP_WordTree fp1) v1’
by (
last_x_assum drule \\ rpt (disch_then drule)
\\ disch_then (qspec_then ‘v1’ mp_tac) \\ impl_tac \\ fs[])
\\ simp[evaluate_def, v_eq_def, astTheory.getOpClass_def,
semanticPrimitivesTheory.do_app_def]
\\ Cases_on ‘fp1’ \\ Cases_on ‘fp2’
\\ fs[v_word_eq_def, semanticPrimitivesTheory.fp_translate_def,
astTheory.isFpBool_def, fpValTreeTheory.fp_uop_def,
state_component_equality,
fpSemTheory.compress_word_def]
\\ rveq \\ Cases_on ‘bop’ \\ fs[fpBopToFloVer_def, dmode_def] \\ rveq
\\ fs[fpValTreeTheory.fp_bop_def, fpSemTheory.compress_word_def]
\\ EVAL_TAC)
>- (
rveq \\ fs[]
\\ rpt (qpat_x_assum ‘T’ kall_tac)
\\ fs[eval_expr_float_def, option_case_eq, freevars_def]
\\ rveq \\ fs[]
\\ ‘∃ fp3. evaluate st env [e3] = (st, Rval [FP_WordTree fp3]) ∧
v_word_eq (FP_WordTree fp3) v2’
by (
last_x_assum drule \\ rpt (disch_then drule)
\\ disch_then (qspec_then ‘v2’ mp_tac) \\ impl_tac \\ fs[])
\\ last_x_assum kall_tac
\\ ‘∃ fp2. evaluate st env [e2] = (st, Rval [FP_WordTree fp2]) ∧
v_word_eq (FP_WordTree fp2) v1’
by (
last_x_assum drule \\ rpt (disch_then drule)
\\ disch_then (qspec_then ‘v1’ mp_tac) \\ impl_tac \\ fs[])
\\ last_x_assum kall_tac
\\ ‘∃ fp1. evaluate st env [e1] = (st, Rval [FP_WordTree fp1]) ∧
v_word_eq (FP_WordTree fp1) v3’
by (
last_x_assum drule \\ rpt (disch_then drule)
\\ disch_then (qspec_then ‘v3’ mp_tac) \\ impl_tac \\ fs[])
\\ simp[evaluate_def, v_eq_def, astTheory.getOpClass_def,
semanticPrimitivesTheory.do_app_def]
\\ Cases_on ‘fp1’ \\ Cases_on ‘fp2’ \\ Cases_on ‘fp3’
\\ fs[v_word_eq_def, semanticPrimitivesTheory.fp_translate_def,
astTheory.isFpBool_def, fpValTreeTheory.fp_uop_def,
state_component_equality,
fpSemTheory.compress_word_def]
\\ rveq
\\ fs[fpValTreeTheory.fp_top_def, fpSemTheory.compress_word_def]
\\ EVAL_TAC)
>- (
simp[evaluate_def]
\\ qmatch_goalsub_abbrev_tac ‘evaluate stUpd env [f]’
\\ ‘stUpd.fp_state.canOpt = FPScope NoOpt’
by (unabbrev_all_tac \\ fs[])
\\ first_x_assum drule
\\ rpt (disch_then drule)
\\ disch_then (qspec_then ‘vF’ mp_tac)
\\ impl_tac
>- (fs[freevars_def])
\\ strip_tac \\ fs[]
\\ Cases_on ‘fp’
\\ unabbrev_all_tac
\\ fs[v_word_eq_def, do_fpoptimise_def, state_component_equality,
fpState_component_equality, fpSemTheory.compress_word_def])
QED
Theorem CakeML_FloVer_float_sim:
∀ varMap freshId f theIds freshId2 theCmd E env fVars
(st:'ffi semanticPrimitives$state) vF.
toFloVerCmd varMap freshId f = SOME (theIds, freshId2, theCmd) ∧
st.fp_state.canOpt = FPScope NoOpt ∧
ids_unique varMap freshId ∧
(∀ x y. (x,y) IN fVars ⇒ lookupCMLVar x varMap = SOME (x,y)) ∧
env_word_sim env.v E fVars ∧
(∀ x. x IN freevars [f] ⇒ ∃ y. lookupCMLVar x varMap = SOME (x,y) ∧ (x,y) IN fVars) ∧
bstep_float theCmd E = SOME vF ⇒
∃ fp. evaluate st env [f] = (st, Rval [FP_WordTree fp]) ∧
v_word_eq (FP_WordTree fp) vF
Proof
ho_match_mp_tac toFloVerCmd_ind
\\ rpt strip_tac \\ fs[toFloVerCmd_def]
>- (
fs[option_case_eq, pair_case_eq, freevars_def] \\ rveq
\\ fs[bstep_float_def]
\\ Cases_on ‘eval_expr_float fexp1 E’ \\ fs[optionLift_def]
\\ rename1 ‘eval_expr_float fexp1 E = SOME w1’
\\ ‘∃fp1. evaluate st env [e1] = (st, Rval [FP_WordTree fp1]) ∧ v_word_eq (FP_WordTree fp1) w1’
by (drule CakeML_FloVer_float_sim_exp
\\ rpt (disch_then drule)
\\ disch_then (qspec_then ‘w1’ mp_tac) \\ impl_tac
\\ rpt strip_tac \\ fs[])
\\ simp[evaluate_def]
\\ first_x_assum drule \\ rpt (disch_then drule)
\\ disch_then (qspecl_then [‘updFlEnv freshId w1 E’,
‘env with v := nsOptBind (SOME x) (FP_WordTree fp1) env.v’,
‘fVars UNION { (Short x, freshId) }’,
‘vF’] mp_tac)
\\ reverse (impl_tac)
>- (strip_tac \\ fsrw_tac [SATISFY_ss] [])
\\ rpt conj_tac
>- (
irule ids_unique_append \\ fs[])
>- (
rpt strip_tac \\ fs[]
>- (
fs[lookupCMLVar_appendCMLVar]
\\ ‘x' ≠ Short x’
by (CCONTR_TAC
\\ fs[] \\ rveq \\ res_tac
\\ fs[])
\\ ‘y ≠ freshId’
by (CCONTR_TAC
\\ fs[] \\ rveq \\ res_tac
\\ fs[ids_unique_def] \\ res_tac
\\ fs[])
\\ res_tac
\\ fs[lookupCMLVar_def, updateTheory.FIND_def])
\\ rveq \\ fs[lookupCMLVar_appendCMLVar, lookupCMLVar_def, updateTheory.FIND_def])
>- (
simp[env_word_sim_def] \\ rpt strip_tac \\ fs[namespaceTheory.nsOptBind_def]
>- (
‘cake_id ≠ Short x’
by (CCONTR_TAC
\\ fs[] \\ rveq \\ res_tac
\\ fs[])
\\ ‘flover_id ≠ freshId’
by (CCONTR_TAC
\\ fs[] \\ rveq \\ res_tac
\\ fs[ids_unique_def] \\ res_tac
\\ fs[])
\\ fs[env_word_sim_def] \\ res_tac
\\ fsrw_tac [SATISFY_ss] []
\\ res_tac \\ fs[updFlEnv_def])
>- (
‘cake_id ≠ Short x’
by (CCONTR_TAC
\\ fs[] \\ rveq \\ res_tac
\\ fs[])
\\ ‘flover_id ≠ freshId’
by (CCONTR_TAC
\\ fs[] \\ rveq \\ res_tac
\\ fs[ids_unique_def] \\ res_tac
\\ fs[])
\\ fs[ml_progTheory.nsLookup_nsBind_compute]
\\ fs[env_word_sim_def] \\ res_tac
\\ fsrw_tac [SATISFY_ss] []
\\ res_tac \\ rfs[updFlEnv_def] \\ fs[])
>- (
rveq \\ fs[ml_progTheory.nsLookup_nsBind_compute]
\\ rveq \\ fs[v_word_eq_def, updFlEnv_def])
\\ rveq \\ fs[updFlEnv_def] \\ rveq \\ fs[v_word_eq_def])
>- (
rpt strip_tac
\\ fs[lookupCMLVar_appendCMLVar, lookupCMLVar_def, updateTheory.FIND_def]
\\ TOP_CASE_TAC \\ fs[]
\\ first_x_assum (qspec_then ‘x'’ mp_tac) \\ fs[]
\\ disch_then assume_tac \\ fs[])
\\ fs[])
\\ TRY (
fs[option_case_eq, pair_case_eq] \\ rveq
\\ fs[bstep_float_def]
\\ drule CakeML_FloVer_float_sim_exp \\ rpt (disch_then drule)
\\ strip_tac \\ fs[])
\\ simp[evaluate_def]
\\ qmatch_goalsub_abbrev_tac ‘evaluate stUpd env _’
\\ ‘stUpd.fp_state.canOpt = FPScope NoOpt’ by (unabbrev_all_tac \\ fs[])
\\ fs[freevars_def]
\\ first_x_assum drule
\\ rpt (disch_then drule)
\\ strip_tac \\ fs[]
\\ Cases_on ‘fp’ \\ fs[v_word_eq_def]
\\ rveq \\ EVAL_TAC
\\ unabbrev_all_tac
\\ fs[fpSemTheory.compress_word_def, v_word_eq_def, fp_uop_comp_def,
fp_bop_comp_def, fp_top_comp_def, fpfma_def,
state_component_equality, fpState_component_equality]
QED
Theorem CakeML_FloVer_float_sim_exp_strict:
∀ varMap f theExp freshId E env fVars (st:'ffi semanticPrimitives$state) vF.
toFloVerExp varMap f = SOME theExp ∧
st.fp_state.canOpt = Strict ∧
ids_unique varMap freshId ∧
(∀ x y. (x,y) IN fVars ⇒ lookupCMLVar x varMap = SOME (x,y)) ∧
env_word_sim env.v E fVars ∧
(∀ x. x IN freevars [f] ⇒ ∃ y. lookupCMLVar x varMap = SOME (x,y) ∧ (x,y) IN fVars) ∧
eval_expr_float theExp E = SOME vF ⇒
∃ fp. evaluate st env [f] = (st, Rval [FP_WordTree fp]) ∧
v_word_eq (FP_WordTree fp) vF
Proof
ho_match_mp_tac toFloVerExp_ind
\\ rpt strip_tac
\\ ((rename1 ‘App op exps’ \\ imp_res_tac toFloVerExp_App_cases)
ORELSE
(qpat_x_assum ‘toFloVerExp _ _ = SOME _’ mp_tac
\\ simp[Once toFloVerExp_def] \\ rpt strip_tac))
>- (
fs[option_case_eq, pair_case_eq] \\ rveq
\\ fs[eval_expr_float_def, option_case_eq, freevars_def]
\\ rveq \\ fs[env_word_sim_def]
\\ res_tac \\ rveq \\ fs[] \\ rveq
\\ simp[evaluate_def]
\\ Cases_on ‘v’ \\ fs[v_word_eq_def])
>- (
rveq \\ fs[]
\\ rpt (qpat_x_assum `T` kall_tac)
\\ fs[eval_expr_float_def] \\ rveq \\ fs[]
\\ simp[evaluate_def, astTheory.getOpClass_def,
semanticPrimitivesTheory.do_app_def, fpSemTheory.compress_word_def,
state_component_equality,
v_word_eq_def])
>- (
fs[option_case_eq, pair_case_eq] \\ rveq
\\ rpt (qpat_x_assum ‘T’ kall_tac)
\\ fs[eval_expr_float_def, option_case_eq, freevars_def]
\\ rveq \\ fs[]
\\ ‘∃ vFC. evaluate st env [e] = (st, Rval [vFC]) ∧
v_word_eq vFC v’
by (
last_x_assum drule \\ rpt (disch_then drule)
\\ disch_then assume_tac \\ fs[])
\\ simp[evaluate_def, v_eq_def, astTheory.getOpClass_def,
semanticPrimitivesTheory.do_app_def]
\\ Cases_on ‘vFC’
\\ TRY (rename1 ‘v_word_eq (Litv l) v’ \\ Cases_on ‘l’)
\\ fs[v_word_eq_def] \\ rveq
\\ fs[v_word_eq_def, semanticPrimitivesTheory.fp_translate_def,
astTheory.isFpBool_def, fpValTreeTheory.fp_uop_def,
state_component_equality,
fpSemTheory.compress_word_def]
\\ EVAL_TAC)
>- (
fs[option_case_eq, pair_case_eq] \\ rveq
\\ rpt (qpat_x_assum ‘T’ kall_tac)
\\ fs[eval_expr_float_def, option_case_eq, freevars_def]
\\ rveq \\ fs[]
\\ ‘∃ vFC. evaluate st env [e] = (st, Rval [vFC]) ∧
v_word_eq vFC v’
by (
last_x_assum drule \\ rpt (disch_then drule)
\\ disch_then assume_tac \\ fs[])
\\ simp[evaluate_def, v_eq_def, astTheory.getOpClass_def,
semanticPrimitivesTheory.do_app_def]
\\ Cases_on ‘vFC’
\\ TRY (rename1 ‘v_word_eq (Litv l) v’ \\ Cases_on ‘l’)
\\ fs[v_word_eq_def] \\ rveq
\\ fs[v_word_eq_def, semanticPrimitivesTheory.fp_translate_def,
astTheory.isFpBool_def, fpValTreeTheory.fp_uop_def,
state_component_equality,
fpSemTheory.compress_word_def]
\\ EVAL_TAC)
>- (
rveq \\ fs[]
\\ rpt (qpat_x_assum ‘T’ kall_tac)
\\ fs[eval_expr_float_def, option_case_eq, freevars_def]
\\ rveq \\ fs[]
\\ ‘∃ fp2. evaluate st env [e2] = (st, Rval [FP_WordTree fp2]) ∧
v_word_eq (FP_WordTree fp2) v2’
by (
last_x_assum drule \\ rpt (disch_then drule)
\\ disch_then (qspec_then ‘v2’ mp_tac) \\ impl_tac \\ fs[])
\\ last_x_assum kall_tac
\\ ‘∃ fp1. evaluate st env [e1] = (st, Rval [FP_WordTree fp1]) ∧
v_word_eq (FP_WordTree fp1) v1’
by (
last_x_assum drule \\ rpt (disch_then drule)
\\ disch_then (qspec_then ‘v1’ mp_tac) \\ impl_tac \\ fs[])
\\ simp[evaluate_def, v_eq_def, astTheory.getOpClass_def,
semanticPrimitivesTheory.do_app_def]
\\ Cases_on ‘fp1’ \\ Cases_on ‘fp2’
\\ fs[v_word_eq_def, semanticPrimitivesTheory.fp_translate_def,
astTheory.isFpBool_def, fpValTreeTheory.fp_uop_def,
state_component_equality,
fpSemTheory.compress_word_def]
\\ rveq \\ Cases_on ‘bop’ \\ fs[fpBopToFloVer_def, dmode_def] \\ rveq
\\ fs[fpValTreeTheory.fp_bop_def, fpSemTheory.compress_word_def]
\\ EVAL_TAC)
>- (
rveq \\ fs[]
\\ rpt (qpat_x_assum ‘T’ kall_tac)
\\ fs[eval_expr_float_def, option_case_eq, freevars_def]
\\ rveq \\ fs[]
\\ ‘∃ fp3. evaluate st env [e3] = (st, Rval [FP_WordTree fp3]) ∧
v_word_eq (FP_WordTree fp3) v2’
by (
last_x_assum drule \\ rpt (disch_then drule)
\\ disch_then (qspec_then ‘v2’ mp_tac) \\ impl_tac \\ fs[])
\\ last_x_assum kall_tac
\\ ‘∃ fp2. evaluate st env [e2] = (st, Rval [FP_WordTree fp2]) ∧
v_word_eq (FP_WordTree fp2) v1’
by (
last_x_assum drule \\ rpt (disch_then drule)
\\ disch_then (qspec_then ‘v1’ mp_tac) \\ impl_tac \\ fs[])
\\ last_x_assum kall_tac
\\ ‘∃ fp1. evaluate st env [e1] = (st, Rval [FP_WordTree fp1]) ∧
v_word_eq (FP_WordTree fp1) v3’
by (
last_x_assum drule \\ rpt (disch_then drule)
\\ disch_then (qspec_then ‘v3’ mp_tac) \\ impl_tac \\ fs[])
\\ simp[evaluate_def, v_eq_def, astTheory.getOpClass_def,
semanticPrimitivesTheory.do_app_def]
\\ Cases_on ‘fp1’ \\ Cases_on ‘fp2’ \\ Cases_on ‘fp3’
\\ fs[v_word_eq_def, semanticPrimitivesTheory.fp_translate_def,
astTheory.isFpBool_def, fpValTreeTheory.fp_uop_def,
state_component_equality,
fpSemTheory.compress_word_def]
\\ rveq
\\ fs[fpValTreeTheory.fp_top_def, fpSemTheory.compress_word_def]
\\ EVAL_TAC)
>- (
simp[evaluate_def]
\\ qmatch_goalsub_abbrev_tac ‘evaluate stUpd env [f]’
\\ ‘stUpd.fp_state.canOpt = Strict’
by (unabbrev_all_tac \\ fs[])
\\ first_x_assum drule
\\ rpt (disch_then drule)
\\ disch_then (qspec_then ‘vF’ mp_tac)
\\ impl_tac
>- (fs[freevars_def])
\\ strip_tac \\ fs[]
\\ Cases_on ‘fp’
\\ unabbrev_all_tac
\\ fs[v_word_eq_def, do_fpoptimise_def, state_component_equality,
fpState_component_equality, fpSemTheory.compress_word_def])
QED
Theorem CakeML_FloVer_float_sim_strict:
∀ varMap freshId f theIds freshId2 theCmd E env fVars
(st:'ffi semanticPrimitives$state) vF.
toFloVerCmd varMap freshId f = SOME (theIds, freshId2, theCmd) ∧
st.fp_state.canOpt = Strict ∧
ids_unique varMap freshId ∧
(∀ x y. (x,y) IN fVars ⇒ lookupCMLVar x varMap = SOME (x,y)) ∧
env_word_sim env.v E fVars ∧
(∀ x. x IN freevars [f] ⇒ ∃ y. lookupCMLVar x varMap = SOME (x,y) ∧ (x,y) IN fVars) ∧
bstep_float theCmd E = SOME vF ⇒
∃ fp. evaluate st env [f] = (st, Rval [FP_WordTree fp]) ∧
v_word_eq (FP_WordTree fp) vF
Proof
ho_match_mp_tac toFloVerCmd_ind
\\ rpt strip_tac \\ fs[toFloVerCmd_def]
>- (
fs[option_case_eq, pair_case_eq, freevars_def] \\ rveq
\\ fs[bstep_float_def]
\\ Cases_on ‘eval_expr_float fexp1 E’ \\ fs[optionLift_def]
\\ rename1 ‘eval_expr_float fexp1 E = SOME w1’
\\ ‘∃vF1. evaluate st env [e1] = (st, Rval [vF1]) ∧ v_word_eq vF1 w1’
by (drule CakeML_FloVer_float_sim_exp_strict
\\ rpt (disch_then drule)
\\ disch_then (qspec_then ‘w1’ mp_tac) \\ impl_tac
\\ rpt strip_tac \\ fs[])
\\ simp[evaluate_def]
\\ first_x_assum drule \\ rpt (disch_then drule)
\\ disch_then (qspecl_then [‘updFlEnv freshId w1 E’,
‘env with v := nsOptBind (SOME x) vF1 env.v’,
‘fVars UNION { (Short x, freshId) }’,
‘vF’] mp_tac)
\\ reverse (impl_tac)
>- (strip_tac \\ fsrw_tac [SATISFY_ss] [])
\\ rpt conj_tac
>- (
irule ids_unique_append \\ fs[])
>- (
rpt strip_tac \\ fs[]
>- (
fs[lookupCMLVar_appendCMLVar]
\\ ‘x' ≠ Short x’
by (CCONTR_TAC