-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathIEEE_connectionScript.sml
2137 lines (2088 loc) · 96.1 KB
/
IEEE_connectionScript.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
(**
Connect FloVer's idealized machine semantics to 64-bit
IEEE-754 floating-point semantics
**)
open machine_ieeeTheory binary_ieeeTheory lift_ieeeTheory realTheory RealArith;
open MachineTypeTheory ExpressionsTheory RealSimpsTheory FloverTactics
CertificateCheckerTheory FPRangeValidatorTheory IntervalValidationTheory
ExpressionAbbrevsTheory
ExpressionSemanticsTheory FloverMapTheory RealRangeArithTheory
TypeValidatorTheory ErrorValidationTheory IntervalArithTheory AbbrevsTheory
CommandsTheory ssaPrgsTheory EnvironmentsTheory FloverMapTheory;
open preambleFloVer;
val _ = new_theory "IEEE_connection";
val _ = temp_delsimps ["fromAList_def", "domain_union",
"domain_inter", "domain_difference",
"domain_map", "sptree.map_def", "sptree.lookup_rwts",
"sptree.insert_notEmpty", "sptree.isEmpty_union"]
Overload abs[local] = “realax$abs”
(** FloVer assumes rounding with ties to even, thus we exprlicitly define
a rounding mode here **)
Definition dmode_def :
dmode = roundTiesToEven
End
Definition optionLift_def:
(optionLift (SOME v) some_cont none_cont = some_cont v) /\
(optionLift (NONE) some_cont none_cont = none_cont)
End
Definition updFlEnv_def:
updFlEnv x v E = \ y. if y = x then SOME v else E y
End
Definition eval_expr_float_def:
(eval_expr_float (Var n) E = E n) /\
(eval_expr_float (Const m v) E = SOME v) /\
(eval_expr_float (Unop Neg e) E =
case eval_expr_float e E of
| SOME v => SOME (fp64_negate v)
| _ => NONE) ∧
(eval_expr_float (Unop Inv e) E = NONE) ∧
(eval_expr_float (Unop Sqrt e) E =
case eval_expr_float e E of
| SOME v => SOME (fp64_sqrt dmode v)
| _ => NONE) ∧
(eval_expr_float (Binop b e1 e2) E =
(case (eval_expr_float e1 E), (eval_expr_float e2 E) of
| SOME v1, SOME v2 =>
(case b of
| Plus => SOME (fp64_add dmode v1 v2)
| Sub => SOME (fp64_sub dmode v1 v2)
| Mult => SOME (fp64_mul dmode v1 v2)
| Div => SOME (fp64_div dmode v1 v2))
| _, _ => NONE)) /\
(eval_expr_float (Fma e1 e2 e3) E =
(case (eval_expr_float e1 E), (eval_expr_float e2 E), (eval_expr_float e3 E) of
| SOME v1, SOME v2, SOME v3 => SOME (fp64_mul_add roundTiesToEven v1 v2 v3)
| _, _, _ => NONE)) /\
(eval_expr_float (Downcast m e) E = NONE)
End
Definition bstep_float_def:
(bstep_float (Let m x e g) E :word64 option=
optionLift (eval_expr_float e E)
(\ v. bstep_float g (updFlEnv x v E))
NONE) /\
(bstep_float (Ret e) E = eval_expr_float e E)
End
Definition toRExp_def:
(toRExp ((Var v):word64 expr) = Var v) /\
(toRExp (Const m c) = Const m (float_to_real (fp64_to_float c))) /\
(toRExp (Unop u e1) = Unop u (toRExp e1)) /\
(toRExp (Binop b e1 e2) = Binop b (toRExp e1) (toRExp e2)) /\
(toRExp (Fma e1 e2 e3) = Fma (toRExp e1) (toRExp e2) (toRExp e3)) /\
(toRExp (Downcast m e1) = Downcast m (toRExp e1))
End
Definition toRCmd_def:
(toRCmd (Let m x e g) = Let m x (toRExp e) (toRCmd g)) /\
(toRCmd (Ret e) = Ret (toRExp e))
End
Definition toREnv_def:
toREnv (E:num -> word64 option) (x:num):real option =
case E x of
| NONE => NONE
| SOME v => SOME (float_to_real (fp64_to_float v))
End
Definition toWordEnv_def:
toWordEnv E = \x. case E x of
| SOME v => SOME (float_to_fp64 (real_to_float dmode v))
| NONE => NONE
End
Definition Binop_to_Rop_def:
Binop_to_Rop (b:binop) :real->real->real =
case b of
| Plus => $+
| Sub => $-
| Mult => $*
| Div => $/
End
Theorem real_div_pow:
! a n m. a <> 0 /\ n >= m ==> a pow n / a pow m = a pow (n - m)
Proof
Induct_on `n` \\ rpt strip_tac
>- (Cases_on `m` \\ fs[pow])
\\ fs[pow]
\\ Cases_on `m` \\ fs[pow]
\\ `n >= n'` by (fs[])
\\ res_tac
\\ first_x_assum (qspec_then `a` (fn thm => rewrite_tac[(GSYM thm)]))
\\ qspecl_then [`a`, `a pow n'`] destruct REAL_INV_MUL
>- (conj_tac \\ fs[]
\\ Cases_on `n'` \\ fs[pow, POW_ZERO_EQ])
\\ fs[real_div, REAL_MUL_ASSOC]
\\ `a * a pow n * inv a * inv (a pow n') = a * inv a * a pow n * inv (a pow n')`
by (REAL_ASM_ARITH_TAC)
\\ pop_assum (fn thm => once_rewrite_tac [thm])
\\ fs[REAL_MUL_RINV]
QED
Theorem zero_lt_sign_zero:
0 < float_to_real fp ⇒
fp.Sign = 0w
Proof
rpt strip_tac \\ CCONTR_TAC
\\ ‘fp.Sign = 1w’ by (Cases_on ‘fp.Sign’ \\ gs[])
\\ gs[float_to_real_def]
\\ ‘0 < 0:real’ suffices_by gs[]
\\ irule REAL_LTE_TRANS
\\ asm_exists_tac \\ gs[REAL_MUL_LNEG]
\\ Cases_on ‘fp.Exponent = 0w’ \\ gs[real_div]
>- (
irule realTheory.REAL_LE_MUL \\ conj_tac
\\ irule realTheory.REAL_LE_MUL \\ gs[] )
\\ gs[real_div] \\ irule REAL_LE_MUL \\ conj_tac
\\ TRY (irule REAL_LE_MUL \\ gs[])
\\ irule REAL_LE_ADD \\ conj_tac \\ gs[]
\\ irule REAL_LE_MUL \\ conj_tac \\ gs[]
QED
Theorem pow_simp1[local] = Q.prove (`2 pow 2047 / 2 pow 1023 = 2 pow 1024`,
qspecl_then [`2`, `2047`,`1023`] destruct real_div_pow \\ fs[]);
Theorem pow_simp2[local] = Q.prove (`2 pow 2046 / 2 pow 1023 = 2 pow 1023`,
qspecl_then [`2`, `2046`,`1023`] destruct real_div_pow \\ fs[]);
Theorem threshold_64_bit_lt_maxValue:
maxValue M64 < threshold (:52 # 11)
Proof
rewrite_tac[threshold_def, maxValue_def, maxExponent_def, GSYM REAL_OF_NUM_POW]
\\ simp[pow_simp2]
\\ once_rewrite_tac [GSYM REAL_MUL_RID]
\\ once_rewrite_tac [GSYM REAL_MUL_ASSOC]
\\ irule REAL_LT_LMUL_IMP \\ fs[]
\\ once_rewrite_tac [real_sub]
\\ once_rewrite_tac [GSYM REAL_LT_ADDNEG2]
\\ once_rewrite_tac [REAL_NEGNEG]
\\ once_rewrite_tac [RealArith.REAL_ARITH ``2:real = 1+1``]
\\ irule REAL_LT_IADD \\ fs[]
\\ once_rewrite_tac [GSYM REAL_INV1]
\\ irule REAL_LT_INV \\ fs[]
\\ `1 = 2 pow 0` by (fs[pow])
\\ pop_assum (fn thm => once_rewrite_tac [thm])
\\ irule REAL_POW_MONO_LT \\ fs[]
QED
Theorem normalValue_implies_normalization:
!v.
normal v M64 ==>
normalizes (:52 #11) v
Proof
rewrite_tac[normal_def, minValue_pos_def, maxValue_def, GSYM REAL_OF_NUM_POW]
\\ rpt strip_tac
\\ fs[normalizes_def, wordsTheory.INT_MAX_def, minExponentPos_def,
wordsTheory.INT_MIN_def, wordsTheory.dimindex_11,
wordsTheory.UINT_MAX_def, wordsTheory.dimword_11]
\\ irule REAL_LET_TRANS
\\ qexists_tac `maxValue M64` \\ fs[threshold_64_bit_lt_maxValue, GSYM REAL_OF_NUM_POW, maxValue_def]
QED
Theorem normalValue_implies_finiteness:
!v.
normal v M64 ==>
float_is_finite ((real_to_float dmode v):(52 , 11) float)
Proof
rpt strip_tac
\\ fs [real_to_float_def, normal_def, dmode_def]
\\ irule float_round_finite
\\ irule REAL_LET_TRANS
\\ qexists_tac `maxValue M64` \\ fs[threshold_64_bit_lt_maxValue]
QED
Theorem denormalValue_implies_finiteness:
!v.
denormal v M64 ==>
float_is_finite ((real_to_float dmode v):(52 , 11) float)
Proof
rpt strip_tac
\\ fs [real_to_float_def, denormal_def, dmode_def]
\\ irule float_round_finite
\\ irule REAL_LT_TRANS
\\ qexists_tac `minValue_pos M64` \\ fs[]
\\ irule REAL_LET_TRANS \\ qexists_tac `maxValue M64`
\\ `minValue_pos M64 <= 1`
by (fs[minValue_pos_def, minExponentPos_def]
\\ once_rewrite_tac [GSYM REAL_INV1]
\\ irule REAL_INV_LE_ANTIMONO_IMPR \\ fs[])
\\ fs[threshold_64_bit_lt_maxValue]
\\ irule REAL_LE_TRANS \\ qexists_tac `1`
\\ fs[maxValue_def, maxExponent_def]
QED
Theorem normal_value_is_float_value:
∀ ff.
normal (float_to_real ((ff):(52,11) float)) M64 ⇒
float_value ff = Float (float_to_real ff)
Proof
rpt strip_tac
\\ rewrite_tac[float_value_def]
\\ rw_thm_asm `normal _ _` normal_def
\\ fs[float_to_real_def]
\\ every_case_tac
\\ fs [maxValue_def, maxExponent_def, minValue_pos_def, minExponentPos_def,
GSYM REAL_OF_NUM_POW, pow_simp1, REAL_DIV_LZERO]
>-(Cases_on `ff.Sign` \\ fs[]
\\ Cases_on `n` \\ fs[pow]
>- (fs[GSYM POW_ABS, abs, REAL_OF_NUM_POW])
\\ Cases_on `n'` \\ fs[pow,REAL_ABS_MUL, abs, REAL_OF_NUM_POW])
\\ qpat_x_assum `abs _ <= _` MP_TAC
\\ qmatch_abbrev_tac `abs (cst1 * cst2) <= cst3 ==> _`
\\ strip_tac
\\ Cases_on `ff.Sign` \\ fs[]
\\ Cases_on `n` \\ fs[pow]
>- (unabbrev_all_tac
\\ fs[ABS_MUL, GSYM POW_ABS]
\\ `abs 2 = 2` by (fs[abs]) \\ fs[]
\\ `abs (1 + &w2n ff.Significand / 2 pow 52) = 1 + &w2n ff.Significand / 2 pow 52`
by (rewrite_tac [ABS_REFL]
\\ irule REAL_LE_ADD \\ fs[])
\\ qpat_x_assum `abs (1 + _) = _` (fn thm => fs[thm])
\\ `2 pow 1024 <= 2 pow 1023`
by (irule REAL_LE_TRANS \\ find_exists_tac \\ fs[]
\\ rewrite_tac [REAL_LDISTRIB, REAL_MUL_RID]
\\ qabbrev_tac `res = 2 pow 1024 + 2 pow 1024 * (&w2n ff.Significand / 2 pow 52)`
\\ qspec_then `2 pow 1024` (fn thm => once_rewrite_tac [GSYM thm]) REAL_ADD_RID
\\ unabbrev_all_tac
\\ irule REAL_LE_LADD_IMP
\\ irule REAL_LE_MUL \\ fs[])
\\ fs[REAL_OF_NUM_POW])
\\ Cases_on `n'` \\ fs[]
\\ Cases_on `ff.Significand` \\ fs[]
\\ Cases_on `n` \\ fs[pow]
\\ `abs (cst1 * cst2) = -(cst1 * cst2)`
by (
fs[abs]
\\ ‘~ (0 ≤ cst1 * cst2)’ suffices_by (fs[])
\\ unabbrev_all_tac
\\ once_rewrite_tac [REAL_NOT_LE]
\\ simp [GSYM REAL_NEG_LT0]
\\ rewrite_tac [GSYM REAL_MUL_ASSOC, GSYM REAL_NEG_MINUS1]
\\ fs[REAL_NEG_LT0]
\\ once_rewrite_tac [REAL_MUL_LNEG] \\ fs[REAL_NEG_LT0]
\\ irule REAL_LT_MUL \\ fs[]
\\ irule REAL_LT_ADD \\ fs[]
\\ irule REAL_LT_DIV \\ fs[])
\\ rw_asm_star `abs _ = _`
\\ `- cst1 <= cst3`
suffices_by (unabbrev_all_tac \\ fs[REAL_NEG_LMUL, REAL_NEGNEG, REAL_OF_NUM_POW])
\\ irule REAL_LE_TRANS
\\ qexists_tac `- (cst1 * cst2)` \\ conj_tac \\ TRY (unabbrev_all_tac \\ fs[]\\ FAIL_TAC "")
\\ once_rewrite_tac [RealArith.REAL_ARITH ``-cst1:real = -cst1 * 1``]
\\ once_rewrite_tac [RealArith.REAL_ARITH ``- (cst1 * cst2) * 1 = - cst1 * cst2:real``]
\\ irule REAL_LE_LMUL_IMP
\\ unabbrev_all_tac \\ fs[]
\\ once_rewrite_tac [REAL_LE_ADDR]
\\ rewrite_tac [GSYM REAL_NEG_MINUS1]
\\ fs[REAL_NEG_LT0]
QED
Theorem denormal_value_is_float_value:
∀ ff:(52,11) float.
denormal (float_to_real ff) M64 ==>
float_value ff = Float (float_to_real ff)
Proof
rpt strip_tac
\\ rewrite_tac[float_value_def]
\\ rw_thm_asm `denormal _ _` denormal_def
\\ TOP_CASE_TAC \\ fs[]
\\ rw_thm_asm `abs _ < _` float_to_real_def
\\ fs[]
\\ `ff.Exponent <> 0w` by fs[] \\ fs[]
\\ Cases_on `ff` \\ fs[]
\\ `w2n (-1w:word11) = 2047` by EVAL_TAC
\\ `w2n c0 = 2047` by fs[] \\ fs[]
\\ TOP_CASE_TAC \\ fs[minValue_pos_def, minExponentPos_def]
\\ fs[REAL_ABS_MUL, POW_M1]
>- (
qpat_x_assum ‘_ < inv _’ mp_tac
\\ qmatch_goalsub_abbrev_tac ‘_ < inv cst1 ⇒ _’
\\ strip_tac
\\ `inv cst1 <= inv 1`
by (unabbrev_all_tac \\ irule REAL_INV_LE_ANTIMONO_IMPR \\ fs[])
\\ fs[pow_simp1, REAL_DIV_LZERO, ABS_1, REAL_OF_NUM_POW, abs]
\\ qpat_x_assum ‘_ < inv cst1’ mp_tac
\\ qmatch_goalsub_abbrev_tac ‘cst2 < inv cst1’ \\ strip_tac
\\ `cst2 < inv 1`
by (unabbrev_all_tac \\ irule REAL_LTE_TRANS \\ asm_exists_tac \\ fs[])
\\ unabbrev_all_tac \\ fs[REAL_INV1])
\\ Cases_on `c1` \\ fs[]
\\ `1 < abs (1 + &n / 4503599627370496)`
by (fs[abs]
\\ `0:real <= 1 + &n / 4503599627370496`
by (irule REAL_LE_TRANS
\\ qexists_tac `1` \\ fs[]
\\ irule REAL_LE_DIV \\ fs[])
\\ fs[]
\\ once_rewrite_tac [GSYM REAL_ADD_RID]
\\ once_rewrite_tac [GSYM REAL_ADD_ASSOC]
\\ fs[]
\\ irule REAL_LT_DIV \\ fs[])
\\ qpat_x_assum ‘_ < inv _’ mp_tac
\\ qmatch_goalsub_abbrev_tac ‘_ < inv cst1 ⇒ _’
\\ `inv cst1 <= inv 1`
by (unabbrev_all_tac \\ irule REAL_INV_LE_ANTIMONO_IMPR \\ fs[])
\\ strip_tac
\\ fs[pow_simp1, REAL_DIV_LZERO, ABS_1, REAL_OF_NUM_POW, abs]
\\ qpat_x_assum ‘_ < inv cst1’ mp_tac
\\ qmatch_goalsub_abbrev_tac ‘(cst2 * _) < inv cst1’
\\ strip_tac
\\ `cst2 < inv 1`
by (unabbrev_all_tac \\ irule REAL_LTE_TRANS \\ once_rewrite_tac[CONJ_COMM]
\\ rewrite_tac[REAL_INV1] \\ asm_exists_tac \\ fs[]
\\ qmatch_goalsub_abbrev_tac `cst1 < cst2`
\\ `0 <= (1:real) + &n / 4503599627370496`
by (irule REAL_LE_ADD \\ fs[real_div]
\\ irule REAL_LE_MUL \\ fs[]
\\ irule REAL_LE_INV \\ fs[])
\\ fs[]
\\ irule REAL_LT_TRANS \\ qexists_tac `cst1 * (1 + &n / 4503599627370496)`
\\ fs[]
\\ once_rewrite_tac [GSYM REAL_MUL_RID]
\\ once_rewrite_tac [GSYM REAL_MUL_ASSOC] \\ irule REAL_LT_LMUL_IMP
\\ fs[]
\\ unabbrev_all_tac \\ fs[])
\\ unabbrev_all_tac \\ fs[REAL_INV1]
QED
Theorem validValue_gives_float_value:
!ff:(52,11) float.
validFloatValue (float_to_real ff) M64 ==>
float_value ff = Float (float_to_real ff)
Proof
rpt strip_tac \\ fs[validFloatValue_def]
>- (irule normal_value_is_float_value \\ fs[])
>- (irule denormal_value_is_float_value \\ fs[])
\\ fs[GSYM float_is_zero_to_real, float_is_zero_def]
\\ every_case_tac \\ fs[]
QED
Theorem normalTranslatedValue_implies_finiteness:
!ff:double.
normal (float_to_real ff) M64 ==>
float_is_finite ff
Proof
rpt strip_tac
\\ fs[float_is_finite_def]
\\ qspec_then `ff` impl_subgoal_tac normal_value_is_float_value
\\ fs[]
QED
Theorem denormalTranslatedValue_implies_finiteness:
!ff:double.
denormal (float_to_real ff) M64 ==>
float_is_finite ff
Proof
rpt strip_tac
\\ fs[float_is_finite_def]
\\ qspec_then `ff` impl_subgoal_tac denormal_value_is_float_value
\\ fs[]
QED
Theorem zero_value_implies_finiteness:
!v. v= 0 ==> float_is_finite ((real_to_float dmode v))
Proof
rpt strip_tac \\ rveq
\\ fs[real_to_float_def, dmode_def]
\\ irule float_round_finite
\\ fs[threshold_is_positive]
QED
Theorem finite_float_implies_threshold:
!f:(α , β) float.
float_is_finite f ==>
~(float_to_real f ≤ -threshold (:α # β)) /\
~(float_to_real f ≥ threshold (:α # β))
Proof
rpt strip_tac
\\ drule lift_ieeeTheory.float_to_real_threshold
\\ simp[realTheory.abs]
\\ every_case_tac
\\ strip_tac \\ RealArith.REAL_ASM_ARITH_TAC
QED
Theorem round_float_to_real_id:
!f.
float_is_finite f /\
float_is_normal f /\
~ float_is_zero f ==>
round roundTiesToEven (float_to_real f) = f
Proof
rw[]
\\ qpat_assum `float_is_finite _` mp_tac
\\ qpat_assum `float_is_normal _` mp_tac
\\ rewrite_tac [float_is_finite_def, float_is_normal_def]
\\ rewrite_tac [float_value_def]
\\ simp[]
\\ strip_tac
\\ once_rewrite_tac [round_def]
\\ fs[finite_float_implies_threshold]
\\ once_rewrite_tac [closest_such_def]
\\ SELECT_ELIM_TAC
\\ rw[]
>- (qexists_tac `f`
\\ rw[is_closest_def, IN_DEF, realTheory.ABS_POS]
\\ Cases_on `f = b` \\ fs[]
\\ first_x_assum (qspec_then `f` mp_tac)
\\ fs[realTheory.REAL_SUB_REFL]
\\ strip_tac
\\ fs[float_to_real_eq]
\\ rfs[])
\\ CCONTR_TAC
\\ fs[is_closest_def, IN_DEF]
\\ qpat_x_assum `!x._ ` mp_tac
\\ first_x_assum (qspec_then `f` mp_tac)
\\ fs[realTheory.REAL_SUB_REFL]
\\ rpt strip_tac
\\ fs[float_to_real_eq]
\\ rfs[]
QED
Theorem real_to_float_id:
!f.
float_is_finite f /\
float_is_normal f /\
~ float_is_zero f ==>
real_to_float dmode (float_to_real f) = f
Proof
rpt strip_tac
\\ fs[dmode_def, real_to_float_def, float_round_def, round_float_to_real_id]
QED
Theorem real_to_float_float_id:
!f.
fp64_isFinite f /\
fp64_isNormal f /\
~ fp64_isZero f ==>
float_to_fp64 (real_to_float dmode (float_to_real (fp64_to_float f))) = f
Proof
rpt strip_tac
\\ fs[fp64_isFinite_def, fp64_isZero_def, fp64_isNormal_def]
\\ fs[real_to_float_id]
\\ fs[float_to_fp64_fp64_to_float]
QED
Theorem float_to_real_real_to_float_zero_id:
float_to_real (real_to_float roundTiesToEven 0) = 0
Proof
once_rewrite_tac[real_to_float_def]
\\ `float_round roundTiesToEven F 0 = (float_plus_zero(:α#β))`
by (irule round_roundTiesToEven_is_plus_zero
\\ fs[ulp_def, ULP_def, real_div]
\\ irule REAL_LE_MUL \\ fs[pow]
\\ irule REAL_LE_INV \\ irule POW_POS \\ fs[])
\\ fs[float_to_real_def, float_plus_zero_def]
QED
Theorem div_eq0_general:
!a b:real. b <> 0 ==> (a / b = 0 <=> a = 0)
Proof
rpt strip_tac \\ Cases_on `0 < b` \\ fs[div_eq0]
\\ `0 < -b` by RealArith.REAL_ASM_ARITH_TAC
\\ `a/ -b = 0 <=> a = 0` by fs[div_eq0]
\\ fs[real_div]
\\ Cases_on `a = 0` \\ fs[]
\\ Cases_on `inv b = 0` \\ fs[REAL_INV_NZ]
QED
Theorem float_to_real_round_zero_is_zero:
!ff P.
2 * abs ff <= ulp ((:α#β) :(α#β) itself) ==>
float_to_real ((float_round roundTiesToEven P ff):(α, β) float) = 0
Proof
rpt strip_tac \\ Cases_on `P`
\\ fs [round_roundTiesToEven_is_plus_zero,
round_roundTiesToEven_is_minus_zero, zero_to_real]
QED
Definition noDowncast_def:
(noDowncast (Var v) = T) /\
(noDowncast (Const _ _) = T) /\
(noDowncast (Unop _ e) = noDowncast e) /\
(noDowncast (Binop b e1 e2) = (noDowncast e1 /\ noDowncast e2)) /\
(noDowncast (Fma e1 e2 e3) = (noDowncast e1 /\ noDowncast e2 /\ noDowncast e3)) /\
(noDowncast (Downcast _ _) = F)
End
Definition noDowncastFun_def:
(noDowncastFun (Let m x e g) = (noDowncast e /\ noDowncastFun g)) /\
(noDowncastFun (Ret e) = noDowncast e)
End
Definition is64BitEval_def:
(is64BitEval ((Const m c):real expr) = (m = M64)) /\
(is64BitEval (Unop _ e) = is64BitEval e) /\
(is64BitEval (Binop b e1 e2) = (is64BitEval e1 /\ is64BitEval e2)) /\
(is64BitEval (Fma e1 e2 e3) = (is64BitEval e1 /\ is64BitEval e2 /\ is64BitEval e3)) /\
(is64BitEval (Downcast m e) = ((m = M64) /\ is64BitEval e)) /\
(is64BitEval ((Var v):real expr) = T)
End
Definition is64BitBstep_def:
(is64BitBstep (Let m x e g) = ((m = M64) /\ is64BitEval e /\ is64BitBstep g)) /\
(is64BitBstep (Ret e) = is64BitEval e)
End
Definition is64BitEnv_def:
is64BitEnv Gamma =
! e m. FloverMapTree_find e Gamma = SOME m ==> m = M64
End
Theorem typing_expr_64bit:
!e Gamma.
is64BitEnv Gamma /\
validTypes e Gamma ==>
FloverMapTree_find e Gamma = SOME M64
Proof
Cases_on `e` \\ fs[Once validTypes_def, is64BitEnv_def]
\\ rpt strip_tac \\ fs[]
\\ res_tac
QED
Theorem typing_cmd_64bit:
!f Gamma.
is64BitEnv Gamma /\
validTypesCmd f Gamma ==>
FloverMapTree_find (getRetExp f) Gamma = SOME M64
Proof
Cases_on `f` \\ fs[Once validTypes_def, Once validTypesCmd_def, is64BitEnv_def]
\\ rpt strip_tac \\ fs[]
\\ res_tac
QED
Theorem eval_expr_gives_IEEE:
!(e:word64 expr) E1 E2 E2_real Gamma vR A fVars dVars.
(!x. (toREnv E2) x = E2_real x) /\
validTypes (toRExp e) Gamma /\
approxEnv E1 (toRExpMap Gamma) A fVars dVars E2_real /\
validRanges (toRExp e) A E1 (toRTMap (toRExpMap Gamma)) /\
validErrorbound (toRExp e) Gamma A dVars /\
FPRangeValidator (toRExp e) A Gamma dVars /\
eval_expr (toREnv E2) (toRExpMap Gamma) (toRExp e) vR M64 /\
domain (usedVars (toRExp e)) DIFF domain dVars ⊆ domain fVars ∧
is64BitEval (toRExp e) /\
is64BitEnv Gamma /\
noDowncast (toRExp e) /\
(∀v.
v ∈ domain dVars ⇒
∃vF m.
(E2_real v = SOME vF ∧ FloverMapTree_find (Var v) Gamma = SOME m ∧
validFloatValue vF m)) ==>
?v.
eval_expr_float e E2 = SOME v /\
eval_expr (toREnv E2) (toRExpMap Gamma) (toRExp e)
(float_to_real (fp64_to_float v)) M64
Proof
Induct_on `e` \\ rewrite_tac[toRExp_def] \\ rpt strip_tac
\\ inversion `eval_expr _ _ _ _ _` eval_expr_cases
\\ once_rewrite_tac [eval_expr_float_def]
\\ fs[noDowncast_def]
>- (once_rewrite_tac [toREnv_def]
\\ fs[validFloatValue_def]
\\ rveq
\\ fs[eval_expr_cases, fp64_to_float_float_to_fp64, dmode_def,
float_to_real_real_to_float_zero_id]
\\ fs[toREnv_def]
\\ fs[eval_expr_float_def, optionLift_def]
\\ Cases_on `E2 n` \\ fs[optionLift_def])
>- (rveq \\ fs[eval_expr_cases]
\\ fs[optionLift_def, minValue_pos_def,
minExponentPos_def, REAL_LT_INV_EQ]
\\ qexists_tac `0:real`
\\ fs[mTypeToR_pos, perturb_def, fp64_to_float_float_to_fp64,
zero_to_real])
>- (fs[Once validTypes_def]
\\ ‘M64 = mG’
by (first_x_assum irule
\\ qexistsl_tac [‘toREnv E2’, ‘Gamma’, ‘vR’] \\ rveq \\ fs[eval_expr_cases]
\\ qexistsl_tac [‘m'’, ‘v1’] \\ fs[])
\\ ‘m' = M64’ by (Cases_on ‘m'’ \\ fs[isCompat_def])
\\ ‘me = M64’ by (Cases_on ‘me’ \\ fs[isCompat_def])
\\ rveq \\ fs[isCompat_def] \\ rpt (qpat_x_assum ‘T’ kall_tac)
\\ fs[eval_expr_float_def]
\\ first_x_assum
(qspecl_then
[`E1`, `E2`, `E2_real`, `Gamma`, `v1`, `A`, `fVars`, `dVars`]
destruct)
>- (
fs[] \\ rpt conj_tac
>- (fs[Once validTypes_def])
>- (rveq \\ rpt strip_tac
\\ drule validTypes_single \\ strip_tac \\ rfs[] \\ rveq
\\ first_x_assum irule
\\ find_exists_tac \\ fs[]
\\ asm_exists_tac \\ fs[])
>- (fs[Once validRanges_def])
>- (
qpat_x_assum ‘validErrorbound _ _ _ _’
(fn thm => assume_tac (ONCE_REWRITE_RULE [validErrorbound_def] thm))
\\ fs[option_case_eq]
\\ pop_assum mp_tac \\ rpt (TOP_CASE_TAC \\ fs[]))
>- (
rw_thm_asm `FPRangeValidator _ _ _ _` FPRangeValidator_def
\\ fs[]
\\ Cases_on `FloverMapTree_find (Unop Neg (toRExp e)) A` \\ fs[]
\\ PairCases_on `x` \\ fs[]
\\ rw_asm_star `FloverMapTree_find (Unop _ _) Gamma = _`)
>- (rw_thm_asm `domain (usedVars _) DIFF _ SUBSET _` usedVars_def \\ fs[])
\\ rw_thm_asm `is64BitEval _` is64BitEval_def
\\ fs[])
\\ fs[fp64_negate_def, fp64_to_float_float_to_fp64]
\\ once_rewrite_tac [float_to_real_negate]
\\ once_rewrite_tac [eval_expr_cases]
\\ fs[] \\ once_rewrite_tac [CONJ_COMM]
\\ qexists_tac ‘M64’ \\ fs[isCompat_def]
\\ asm_exists_tac \\ fs[evalUnop_def])
>- (
qpat_x_assum ‘validErrorbound _ _ _ _’
(fn thm => mp_tac (ONCE_REWRITE_RULE [validErrorbound_def] thm))
\\ fs[option_case_eq] \\ rpt (TOP_CASE_TAC \\ fs[]))
>- (
fs[Once validTypes_def] \\ rveq
\\ imp_res_tac validTypes_single
\\ ‘M64 = m1’
by (qpat_x_assum ‘isCompat m1 _’ mp_tac \\ Cases_on ‘m1’
\\ simp[isCompat_def])
\\ rveq
\\ ‘M64 = mG’
by (qpat_x_assum ‘toRExpMap _ _ = SOME _’ mp_tac
\\ qpat_x_assum ‘FloVerMapTree_find _ _ = SOME mG’ mp_tac
\\ simp[toRExpMap_def])
\\ ‘me = M64’
by (qpat_x_assum ‘isCompat me _’ mp_tac \\ rveq \\ Cases_on ‘me’
\\ simp[isCompat_def])
\\ rveq \\ fs[isCompat_def] \\ rpt (qpat_x_assum ‘T’ kall_tac)
\\ rveq
\\ fs[eval_expr_float_def]
\\ first_x_assum
(qspecl_then
[`E1`, `E2`, `E2_real`, `Gamma`, `v1`, `A`, `fVars`, `dVars`]
destruct)
>- (
fs[] \\ rpt conj_tac
>- (fs[Once validTypes_def])
>- (rveq \\ rpt strip_tac
\\ drule validTypes_single \\ strip_tac \\ rfs[] \\ rveq
\\ first_x_assum irule
\\ find_exists_tac \\ fs[]
\\ asm_exists_tac \\ fs[])
>- (fs[Once validRanges_def])
>- (
qpat_x_assum ‘validErrorbound _ _ _ _’
(fn thm => assume_tac (ONCE_REWRITE_RULE [validErrorbound_def] thm))
\\ fs[option_case_eq]
\\ pop_assum mp_tac \\ rpt (TOP_CASE_TAC \\ fs[]))
>- (
rw_thm_asm `FPRangeValidator _ _ _ _` FPRangeValidator_def
\\ fs[]
\\ Cases_on `FloverMapTree_find (Unop Sqrt (toRExp e)) A` \\ fs[]
\\ PairCases_on `x` \\ fs[]
\\ rw_asm_star `FloverMapTree_find (Unop _ _) Gamma = _`)
>- (rw_thm_asm `domain (usedVars _) DIFF _ SUBSET _` usedVars_def \\ fs[])
\\ rw_thm_asm `is64BitEval _` is64BitEval_def \\ fs[])
\\ fs[fp64_sqrt_def, fp64_to_float_float_to_fp64]
\\ qpat_x_assum `validRanges _ _ _ _` mp_tac
\\ simp[Once validRanges_def] \\ rpt strip_tac
\\ imp_res_tac validRanges_single
\\ rename1 ‘FloverMapTree_find (toRExp e) A = SOME (iv1, err1)’
\\ ‘0 < IVlo iv1’ by (res_tac \\ gs[IVlo_def])
\\ rename1 ‘IVlo iv1 ≤ vR1’
(* Obtain evaluation for E2_real*)
\\ ‘!vF1 m1. eval_expr E2_real (toRExpMap Gamma) (toRExp e) vF1 m1 ==>
abs (vR1 - vF1) <= err1’
by (qspecl_then [`toRExp e`, `E1`, `E2_real`, `A`,`vR1`,
`err1`, `IVlo iv1`, `IVhi iv1`, `fVars`,
`dVars`,`Gamma`] destruct validErrorbound_sound
\\ rpt conj_tac \\ fs[]
>- (fs [DIFF_DEF, SUBSET_DEF]
\\ rpt strip_tac \\ first_x_assum irule
\\ once_rewrite_tac [usedVars_def] \\ fs[domain_union])
\\ qpat_x_assum ‘validErrorbound _ _ _ _’
(fn thm => mp_tac (ONCE_REWRITE_RULE [validErrorbound_def] thm))
\\ fs[option_case_eq] \\ rpt (TOP_CASE_TAC \\ fs[]))
\\ ‘validFloatValue (float_to_real (fp64_to_float v)) M64’
by (drule FPRangeValidator_sound
\\ disch_then $ qspecl_then [‘toRExp e’, ‘fp64_to_real v’, ‘M64’] mp_tac
\\ gs[] \\ impl_tac
>- (rpt conj_tac
>- (drule eval_eq_env
\\ rpt $ disch_then drule \\ gs[fp64_to_real_def])
>- (
qpat_x_assum ‘validErrorbound _ _ _ _’
(fn thm => mp_tac (ONCE_REWRITE_RULE [validErrorbound_def] thm))
\\ fs[option_case_eq] \\ rpt (TOP_CASE_TAC \\ fs[]))
>- (
qpat_x_assum ‘FPRangeValidator _ _ _ _’
(fn thm => mp_tac (ONCE_REWRITE_RULE [FPRangeValidator_def] thm))
\\ fs[option_case_eq] \\ rpt (TOP_CASE_TAC \\ fs[]))
\\ fs [DIFF_DEF, SUBSET_DEF]
\\ rpt strip_tac \\ first_x_assum irule
\\ once_rewrite_tac [usedVars_def] \\ fs[domain_union])
\\ simp[fp64_to_real_def])
\\ ‘contained (float_to_real (fp64_to_float v))
(widenInterval (FST iv1, SND iv1) err1)’
by (
irule distance_gives_iv
\\ qexists_tac `vR1` \\ fs [contained_def]
\\ first_x_assum irule
\\ qexists_tac `M64`
\\ drule eval_eq_env
\\ rpt (disch_then drule) \\ fs[])
\\ ‘0 < FST (widenInterval (FST iv1, SND iv1) err1)’
by (
qpat_x_assum ‘validErrorbound _ _ _ _’
(fn thm => mp_tac (ONCE_REWRITE_RULE [validErrorbound_def] thm))
\\ fs[option_case_eq] \\ rpt (TOP_CASE_TAC \\ fs[]))
\\ ‘0 < float_to_real (fp64_to_float v)’
by (gs[contained_def, widenInterval_def] \\ irule REAL_LTE_TRANS
\\ asm_exists_tac \\ gs[])
\\ ‘(fp64_to_float v).Sign = 0w’
by imp_res_tac zero_lt_sign_zero
\\ ‘validFloatValue (evalUnop Sqrt (float_to_real (fp64_to_float v))) M64’
by (
drule FPRangeValidator_sound
\\ disch_then
(qspecl_then
[`Unop Sqrt (toRExp e)`,
`evalUnop Sqrt (float_to_real (fp64_to_float v))`, `M64`]
irule)
\\ fs[]
\\ qexists_tac ‘e’ \\ fs[]
\\ rpt conj_tac
>- (simp[Once validTypes_def, isCompat_def] \\ first_x_assum MATCH_ACCEPT_TAC)
>- (simp[Once validRanges_def] \\ asm_exists_tac \\ fs[]
\\ fs[] \\ rveq \\ fs[])
\\ irule eval_eq_env
\\ qexists_tac ‘toREnv E2’ \\ rpt conj_tac >- fs[]
\\ irule Unop_sqrt'
\\ qexistsl_tac [‘0’, `M64`, ‘M64’, `float_to_real (fp64_to_float v)`]
\\ fs[perturb_def, evalUnop_def, mTypeToR_pos, isCompat_def])
\\ qpat_x_assum `validFloatValue (evalUnop _ _) M64` (assume_tac o SIMP_RULE std_ss [validFloatValue_def])
\\ gs[]
(* normal sqrt *)
>- (
Q.ISPEC_THEN `(fp64_to_float v):(52,11) float`
impl_subgoal_tac
float_sqrt_relative
>- (rpt conj_tac
\\ fs[validFloatValue_def,
normalTranslatedValue_implies_finiteness,
denormalTranslatedValue_implies_finiteness,
normalValue_implies_normalization,
GSYM float_is_zero_to_real, float_is_finite, evalUnop_def,
sqrtable_def,
normalizes_def])
\\ fs[dmode_def] \\ simp[Once eval_expr_cases]
\\ qexistsl_tac [`M64`, `float_to_real (fp64_to_float v)`, ‘e'’]
\\ fs[perturb_def, evalUnop_def]
\\ imp_res_tac normal_not_denormal
\\ fs[REAL_INV_1OVER, mTypeToR_def, isCompat_def])
(* denormal sqrt *)
>- (
Q.ISPEC_THEN `(fp64_to_float v):(52,11) float`
impl_subgoal_tac
float_sqrt_relative_denorm
>- (rpt conj_tac
>- fs[validFloatValue_def,
normalTranslatedValue_implies_finiteness,
denormalTranslatedValue_implies_finiteness,
normalValue_implies_normalization, float_is_finite,
GSYM float_is_zero_to_real, evalUnop_def]
>- fs[sqrtable_def]
>- (
fs[normalTranslatedValue_implies_finiteness,
denormalTranslatedValue_implies_finiteness,
normalValue_implies_normalization, float_is_finite,
GSYM float_is_zero_to_real, evalUnop_def, denormal_def, minValue_pos_def]
\\ rewrite_tac [INT_MAX_def, INT_MIN_def, dimindex_11, EVAL “2 ** (11 - 1) - 1 - 1”]
\\ irule REAL_LT_TRANS
\\ asm_exists_tac \\ fs[GSYM REAL_OF_NUM_POW, minExponentPos_def]
\\ irule REAL_LET_TRANS \\ qexists_tac ‘1 * inv (2 pow 1022)’
\\ conj_tac
>- (rewrite_tac[real_div] \\ irule REAL_LT_RMUL_IMP \\ fs[])
\\ fs[])
>- (irule REAL_LT_TRANS \\ qexists_tac ‘maxValue M64’
\\ fs[threshold_64_bit_lt_maxValue, denormal_def]
\\ irule REAL_LTE_TRANS \\ qexists_tac ‘minValue_pos M64’
\\ fs[minValue_pos_def, maxValue_def, GSYM REAL_OF_NUM_POW, evalUnop_def]
\\ irule REAL_LE_TRANS \\ qexists_tac ‘1’ \\ conj_tac
>- (once_rewrite_tac[GSYM REAL_INV1] \\ irule REAL_INV_LE_ANTIMONO_IMPR
\\ fs[POW_2_LE1])
\\ fs[POW_2_LE1])
\\ fs[INT_MAX_def, INT_MIN_def, dimindex_11])
\\ gs[dmode_def] \\ simp[Once eval_expr_cases]
\\ qexistsl_tac [`M64`, `float_to_real (fp64_to_float v)`, ‘e'’]
\\ fs[perturb_def, evalUnop_def]
\\ fs[REAL_INV_1OVER, mTypeToR_def, isCompat_def, minExponentPos_def])
(* sqrt 0 *)
\\ ‘0 < sqrt (float_to_real (fp64_to_float v))’ by (irule SQRT_POS_LT \\ gs[])
\\ gs[evalUnop_def])
>- (
rename1 `Binop b (toRExp e1) (toRExp e2)` \\ rveq
\\ IMP_RES_TAC validRanges_single
\\ rw_thm_asm `validTypes _ _` validTypes_def
\\ rw_thm_asm `validRanges _ _ _ _` validRanges_def
\\ fs[eval_expr_float_def, optionLift_def]
\\ imp_res_tac validTypes_exec
\\ rveq
\\ `m1 = M64 /\ m2 = M64`
by (fs[is64BitEnv_def]
\\ conj_tac \\ first_x_assum irule \\ find_exists_tac \\ fs[])
\\ rveq
\\ rw_thm_asm `is64BitEval _` is64BitEval_def \\ fs[]
\\ ntac 2
(first_x_assum
(qspecl_then [`E1`, `E2`,`E2_real`, `Gamma`] assume_tac))
\\ first_x_assum (qspecl_then [`v1`, `A`, `fVars`, `dVars`] destruct)
>- (
rpt conj_tac \\ fs[]
>- (
qpat_x_assum ‘validErrorbound _ _ _ _’
(fn thm => mp_tac (ONCE_REWRITE_RULE [validErrorbound_def] thm))
\\ fs[option_case_eq] \\ rpt (TOP_CASE_TAC \\ fs[]))
>- (
rw_thm_asm `FPRangeValidator _ _ _ _` FPRangeValidator_def
\\ fs[] \\ rveq
\\ rw_asm_star `FloverMapTree_find (Binop _ _ _) A = _`
\\ rw_asm_star `FloverMapTree_find (Binop _ _ _) Gamma = _`)
\\ rw_thm_asm `domain (usedVars _) DIFF _ SUBSET _` usedVars_def
\\ fs[domain_union, DIFF_DEF, SUBSET_DEF, Once usedVars_def]
\\ rpt strip_tac \\ first_x_assum irule \\ simp[Once usedVars_def])
\\ first_x_assum (qspecl_then [`v2`, `A`, `fVars`, `dVars`] destruct)
>- (
rpt conj_tac \\ fs[]
>- (
qpat_x_assum ‘validErrorbound _ _ _ _’
(fn thm => mp_tac (ONCE_REWRITE_RULE [validErrorbound_def] thm))
\\ fs[option_case_eq] \\ rpt (TOP_CASE_TAC \\ fs[]))
>- (
rw_thm_asm `FPRangeValidator _ _ _ _` FPRangeValidator_def
\\ fs[] \\ rveq
\\ rw_asm_star `FloverMapTree_find (Binop _ _ _) A = _`
\\ rw_asm_star `FloverMapTree_find (Binop _ _ _) Gamma = _`)
\\ rw_thm_asm `domain (usedVars _) DIFF _ SUBSET _` usedVars_def
\\ fs[domain_union, DIFF_DEF, SUBSET_DEF])
\\ fs[]
\\ rename1 `eval_expr_float e1 _ = SOME vF1`
\\ rename1 `eval_expr_float e2 _ = SOME vF2`
\\ imp_res_tac validRanges_single
\\ rename1 `FloverMapTree_find (toRExp e2) A = SOME (iv2, err2)`
\\ rename1 `FloverMapTree_find (toRExp e1) A = SOME (iv1, err1)`
\\ rename1 `eval_expr E1 _ (toREval (toRExp e2)) nR2 REAL`
\\ rename1 `eval_expr E1 _ (toREval (toRExp e1)) nR1 REAL`
(* Obtain evaluation for E2_real*)
\\ ‘!vF2 m2. eval_expr E2_real (toRExpMap Gamma) (toRExp e2) vF2 m2 ==>
abs (nR2 - vF2) <= err2’
by (qspecl_then [`toRExp e2`, `E1`, `E2_real`, `A`,`nR2`,
`err2`, `FST iv2`, `SND iv2`, `fVars`,
`dVars`,`Gamma`] destruct validErrorbound_sound
\\ rpt conj_tac \\ fs[]
>- (fs [DIFF_DEF, SUBSET_DEF]
\\ rpt strip_tac \\ first_x_assum irule
\\ once_rewrite_tac [usedVars_def] \\ fs[domain_union])
\\ qpat_x_assum ‘validErrorbound _ _ _ _’
(fn thm => mp_tac (ONCE_REWRITE_RULE [validErrorbound_def] thm))
\\ fs[option_case_eq] \\ rpt (TOP_CASE_TAC \\ fs[]))
\\ `contained (float_to_real (fp64_to_float vF2))
(widenInterval (FST iv2, SND iv2) err2)`
by (irule distance_gives_iv
\\ qexists_tac `nR2` \\ fs [contained_def]
\\ first_x_assum irule
\\ qexists_tac `M64`
\\ drule eval_eq_env
\\ rpt (disch_then drule) \\ fs[])
\\ `b = Div ==> float_to_real (fp64_to_float vF2) <> 0`
by (strip_tac \\ rveq
\\ qpat_x_assum ‘validErrorbound _ _ _ _’
(fn thm => mp_tac (ONCE_REWRITE_RULE [validErrorbound_def] thm))
\\ fs[widenInterval_def, contained_def, noDivzero_def]
\\ rpt strip_tac
>- (CCONTR_TAC \\ fs[] \\ rveq
\\ `0 < 0:real`
by (irule REAL_LET_TRANS
\\ qexists_tac `SND iv2 + err2` \\ fs[])
\\ fs[])
>- (CCONTR_TAC \\ fs[] \\ rveq
\\ `0 < 0:real`
by (irule REAL_LTE_TRANS
\\ qexists_tac `FST iv2 - err2` \\ fs[])
\\ fs[])
>- (CCONTR_TAC \\ fs[] \\ rveq
\\ `0 < 0:real`
by (irule REAL_LET_TRANS
\\ qexists_tac `SND iv2 + err2` \\ fs[])
\\ fs[])
\\ CCONTR_TAC \\ fs[] \\ rveq
\\ `0 < 0:real`
by (irule REAL_LTE_TRANS
\\ qexists_tac `FST iv2 - err2` \\ fs[])
\\ fs[])
\\ `validFloatValue
(evalBinop b (float_to_real (fp64_to_float vF1))
(float_to_real (fp64_to_float vF2))) M64`
by (drule FPRangeValidator_sound
\\ disch_then
(qspecl_then
[`(Binop b (toRExp e1) (toRExp e2))`,
`evalBinop b (float_to_real (fp64_to_float vF1))
(float_to_real (fp64_to_float vF2))`,
`M64`] irule)
\\ fs[]
\\ qexistsl_tac [`e1`, `e2`] \\ fs[]
\\ rpt conj_tac
>- (simp[Once validTypes_def] \\ first_x_assum MATCH_ACCEPT_TAC)
>- (simp[Once validRanges_def] \\ asm_exists_tac \\ fs[]
\\ fs[] \\ rveq \\ fs[])
\\ irule eval_eq_env
\\ qexists_tac ‘toREnv E2’ \\ rpt conj_tac >- fs[]
\\ irule Binop_dist'
\\ qexistsl_tac [‘0’, `M64`, `M64`, ‘M64’, `float_to_real (fp64_to_float vF1)`,
`float_to_real (fp64_to_float vF2)`]
\\ Cases_on `b`
\\ fs[perturb_def, evalBinop_def, mTypeToR_pos])
\\ `validFloatValue (float_to_real (fp64_to_float vF1)) M64`
by (drule FPRangeValidator_sound
\\ disch_then
(qspecl_then
[`toRExp e1`, `float_to_real (fp64_to_float vF1)`,
`M64`] irule)
\\ fs[]
\\ qexistsl_tac [`e1`] \\ fs[]
\\ rpt conj_tac
>- (rw_thm_asm `domain (usedVars _) DIFF _ SUBSET _` usedVars_def
\\ fs[domain_union, DIFF_DEF, SUBSET_DEF, Once usedVars_def])
>- (rw_thm_asm `FPRangeValidator _ _ _ _` FPRangeValidator_def
\\ fs[] \\ rveq
\\ rw_asm_star `FloverMapTree_find (Binop _ _ _) A = _`
\\ rw_asm_star `FloverMapTree_find (Binop _ _ _) Gamma = _`)
>- (
qpat_x_assum ‘validErrorbound _ _ _ _’
(fn thm => mp_tac (ONCE_REWRITE_RULE [validErrorbound_def] thm))
\\ fs[option_case_eq] \\ rpt (TOP_CASE_TAC \\ fs[]))
\\ irule eval_eq_env
\\ find_exists_tac \\ fs[])
\\ `validFloatValue (float_to_real (fp64_to_float vF2)) M64`
by (drule FPRangeValidator_sound
\\ disch_then
(qspecl_then
[`toRExp e2`, `float_to_real (fp64_to_float vF2)`,
`M64`] irule)
\\ fs[]
\\ qexists_tac `e2` \\ fs[]
\\ rpt conj_tac
>- (rw_thm_asm `domain (usedVars _) DIFF _ SUBSET _` usedVars_def
\\ fs[domain_union, DIFF_DEF, SUBSET_DEF])
>- (rw_thm_asm `FPRangeValidator _ _ _ _` FPRangeValidator_def
\\ fs[] \\ rveq
\\ rw_asm_star `FloverMapTree_find (Binop _ _ _) A = _`
\\ rw_asm_star `FloverMapTree_find (Binop _ _ _) Gamma = _`)
>- (
qpat_x_assum ‘validErrorbound _ _ _ _’
(fn thm => mp_tac (ONCE_REWRITE_RULE [validErrorbound_def] thm))
\\ fs[option_case_eq] \\ rpt (TOP_CASE_TAC \\ fs[]))
\\ irule eval_eq_env
\\ find_exists_tac \\ fs[])
\\ qpat_x_assum `validFloatValue (evalBinop _ _ _) M64` (assume_tac o SIMP_RULE std_ss [validFloatValue_def])
(** Case distinction for operator **)
\\ Cases_on `b` \\ fs[optionLift_def, PULL_EXISTS]
\\ simp[Once eval_expr_cases]
(* Addition, result normal *)
>- (fs[fp64_add_def, fp64_to_float_float_to_fp64, evalBinop_def]
\\ Q.ISPECL_THEN [`(fp64_to_float vF1):(52,11) float`,