-
Notifications
You must be signed in to change notification settings - Fork 79
/
float_thms.hl
5621 lines (4954 loc) · 257 KB
/
float_thms.hl
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
(* ========================================================================== *)
(* FLOATING POINT THEOREMS *)
(* ========================================================================== *)
(* needs "IEEE/common.hl";; *)
(* needs "IEEE/fixed_thms.hl";; *)
(* needs "IEEE/fixed.hl";; *)
(* needs "IEEE/float.hl";; *)
(* -------------------------------------------------------------------------- *)
(* Valid flformat properties *)
(* -------------------------------------------------------------------------- *)
let FLFORMAT_SPLIT = TAUT `!(fmt:flformat).
(dest_flformat fmt) = (FST (dest_flformat fmt),
SND (dest_flformat fmt))`;;
let FLFORMAT_VALID_IMP_RADIX_LT_1 =
prove(`!(r:num) (p:num). ((is_valid_flformat (r,p)) ==>
1 < (FST (r,p)))`,
REPEAT GEN_TAC THEN REWRITE_TAC[is_valid_flformat] THEN ARITH_TAC);;
let FLFORMAT_VALID_IMP_RADIX_EVEN =
prove(`!(r:num) (p:num). ((is_valid_flformat (r,p)) ==>
EVEN (FST (r,p)))`,
REPEAT GEN_TAC THEN REWRITE_TAC[is_valid_flformat] THEN MESON_TAC[]);;
let FLFORMAT_VALID_IMP_PREC_LT_1 =
prove(`!(r:num) (p:num). ((is_valid_flformat (r,p)) ==>
1 < (SND (r,p)))`,
REPEAT GEN_TAC THEN REWRITE_TAC[is_valid_flformat] THEN MESON_TAC[]);;
let FLFORMAT_VALID =
prove(`!(fmt:flformat). is_valid_flformat (dest_flformat fmt)`,
REWRITE_TAC[flformat_typbij]);;
let FLFORMAT_RADIX_LT_1 =
prove(`!(fmt:flformat). 1 < (flr fmt)`,
GEN_TAC THEN REWRITE_TAC[flr] THEN ONCE_REWRITE_TAC[FLFORMAT_SPLIT] THEN
MATCH_MP_TAC FLFORMAT_VALID_IMP_RADIX_LT_1 THEN
REWRITE_TAC[FLFORMAT_VALID]);;
let FLFORMAT_RADIX_LT_0 =
prove(`!(fmt:flformat). 0 < (flr fmt)`,
GEN_TAC THEN MATCH_MP_TAC (ARITH_RULE `1 < x ==> 0 < x`) THEN
REWRITE_TAC[FLFORMAT_RADIX_LT_1]);;
let FLFORMAT_RADIX_NE_0 =
prove(`!(fmt:flformat). ~(&(flr fmt) = &0)`,
GEN_TAC THEN REWRITE_TAC[REAL_OF_NUM_EQ] THEN MATCH_MP_TAC
(ARITH_RULE `0 < x ==> ~(x = 0)`) THEN
REWRITE_TAC[FLFORMAT_RADIX_LT_0]);;
let FLFORMAT_RADIX_EVEN =
prove(`!(fmt:flformat). EVEN (flr fmt)`,
GEN_TAC THEN REWRITE_TAC[flr] THEN ONCE_REWRITE_TAC[FLFORMAT_SPLIT] THEN
MATCH_MP_TAC FLFORMAT_VALID_IMP_RADIX_EVEN THEN
REWRITE_TAC[FLFORMAT_VALID]);;
let FLFORMAT_RADIX_LE_2 =
prove(`!(fmt:flformat). 2 <= (flr fmt)`,
GEN_TAC THEN
SUBGOAL_THEN `!x. ~(x = 0) /\ EVEN x ==> 2 <= x` MATCH_MP_TAC THENL [
GEN_TAC THEN
DISCH_THEN (LABEL_CONJUNCTS_TAC ["xneq0"; "evenx"]) THEN
ASM_CASES_TAC `x = 0` THENL [
ASM_ARITH_TAC; ALL_TAC] THEN
ASM_CASES_TAC `x = 1` THENL [
USE_THEN "evenx" (fun evenx ->
ASSUME_TAC (REWRITE_RULE[ASSUME `x = 1`] evenx)) THEN
ASSUME_TAC (REWRITE_RULE[GSYM NOT_EVEN] (ARITH_RULE `ODD 1`)) THEN
ASM_ARITH_TAC; ASM_ARITH_TAC]; ALL_TAC] THEN
REWRITE_TAC[REWRITE_RULE[REAL_OF_NUM_EQ] FLFORMAT_RADIX_NE_0] THEN
REWRITE_TAC[FLFORMAT_RADIX_EVEN]);;
let FLFORMAT_PREC_LT_1 =
prove(`!(fmt:flformat). 1 < (flp fmt)`,
GEN_TAC THEN REWRITE_TAC[flp] THEN ONCE_REWRITE_TAC[FLFORMAT_SPLIT] THEN
MATCH_MP_TAC FLFORMAT_VALID_IMP_PREC_LT_1 THEN
REWRITE_TAC[FLFORMAT_VALID]);;
let FLFORMAT_PREC_LT_0 =
prove(`!(fmt:flformat). 0 < (flp fmt)`,
GEN_TAC THEN MATCH_MP_TAC (ARITH_RULE `1 < x ==> 0 < x`) THEN
REWRITE_TAC[FLFORMAT_PREC_LT_1]);;
let FLFORMAT_PREC_MINUS_1 =
prove(`!(fmt:flformat). &0 <= (&(flp fmt):int) - (&1:int)`,
REWRITE_TAC[ARITH_RULE `&0 <= x:int - &1:int <=> &1 <= x`] THEN
REWRITE_TAC[INT_OF_NUM_LE] THEN
REWRITE_TAC[ARITH_RULE `1 <= n <=> 0 < n`] THEN
REWRITE_TAC[FLFORMAT_PREC_LT_0]);;
let FLFORMAT_PREC_IPOW_EQ_EXP =
prove(`!(fmt:flformat). &(flr fmt) ipow (&(flp fmt) - &1) =
&((flr fmt) EXP ((flp fmt) - 1))`,
REPEAT GEN_TAC THEN MATCH_MP_TAC IPOW_EQ_EXP_P THEN
REWRITE_TAC[FLFORMAT_PREC_LT_0]);;
let FLFORMAT_PREC_EXP_EQ_IPOW =
prove(`!(fmt:flformat) (n:num). &((flr fmt) EXP n) = &(flr fmt) ipow (&n)`,
REPEAT GEN_TAC THEN REWRITE_TAC[GSYM REAL_OF_NUM_POW] THEN
REWRITE_TAC[ipow] THEN
SUBGOAL_THEN `(&0:int) <= (&n)` (fun thm -> REWRITE_TAC[thm]) THENL [
REWRITE_TAC[REAL_OF_NUM_LE] THEN ARITH_TAC; ALL_TAC] THEN
REWRITE_TAC[NUM_OF_INT_OF_NUM]);;
let FLFORMAT_RADIX_IPOW_LE_0 =
prove(`!(fmt:flformat) (e:int). &0 <= &(flr fmt) ipow e`,
REPEAT GEN_TAC THEN
MATCH_MP_TAC (ARITH_RULE `&0 < (x:real) ==> &0 <= x`) THEN
MATCH_MP_TAC IPOW_LT_0 THEN
REWRITE_TAC[REAL_OF_NUM_LT] THEN
REWRITE_TAC[FLFORMAT_RADIX_LT_0]);;
let FLFORMAT_RADIX_IPOW_LT_0 =
prove(`!(fmt:flformat) (e:int). &0 < &(flr fmt) ipow e`,
REPEAT GEN_TAC THEN
MATCH_MP_TAC IPOW_LT_0 THEN
REWRITE_TAC[REAL_OF_NUM_LT] THEN
REWRITE_TAC[FLFORMAT_RADIX_LT_0]);;
let FLFORMAT_RADIX_IPOW_NEQ_0 =
prove(`!(fmt:flformat) (e:int). ~(&(flr fmt) ipow e = &0)`,
REPEAT GEN_TAC THEN
MATCH_MP_TAC (ARITH_RULE `&0 < (x:real) ==> ~(x = &0)`) THEN
MATCH_MP_TAC IPOW_LT_0 THEN
REWRITE_TAC[REAL_OF_NUM_LT] THEN
REWRITE_TAC[FLFORMAT_RADIX_LT_0]);;
let FLFORMAT_RADIX_IPOW_ADD_EXP =
prove(`!(fmt:flformat) (u:int) (v:int).
&(flr fmt) ipow u * &(flr fmt) ipow v = &(flr fmt) ipow (u + v)`,
REPEAT GEN_TAC THEN MATCH_MP_TAC IPOW_ADD_EXP THEN
REWRITE_TAC[FLFORMAT_RADIX_NE_0]);;
let FLFORMAT_TO_FFORMAT =
prove(`!(fmt:flformat) (e:int). ?(fmt':fformat).
(to_fformat fmt e) = fmt' /\
(fr fmt') = (flr fmt) /\
(fp fmt') = (flp fmt) /\
(fe fmt') = e`,
REPEAT GEN_TAC THEN
EXISTS_TAC `mk_fformat ((flr fmt), (flp fmt), e)` THEN
REWRITE_TAC[to_fformat] THEN REWRITE_TAC[fr;fp;fe] THEN
SUBGOAL_THEN `is_valid_fformat ((flr fmt), (flp fmt), e)`
(LABEL_TAC "valid") THENL [
REWRITE_TAC[is_valid_fformat] THEN
REWRITE_TAC[FLFORMAT_RADIX_LT_1] THEN
REWRITE_TAC[FLFORMAT_RADIX_EVEN] THEN
REWRITE_TAC[FLFORMAT_PREC_LT_0]; ALL_TAC] THEN
USE_THEN "valid" (fun valid ->
REWRITE_TAC[REWRITE_RULE[fformat_typbij] valid]));;
(* a saner version *)
let FLFORMAT_TO_FFORMAT_2 =
prove(`!(fmt:flformat) (e:int).
(fr (to_fformat fmt e)) = (flr fmt) /\
(fp (to_fformat fmt e)) = (flp fmt) /\
(fe (to_fformat fmt e)) = e`,
REPEAT GEN_TAC THEN REWRITE_TAC[to_fformat] THEN
SUBGOAL_THEN `is_valid_fformat (flr fmt, flp fmt, (e:int))`
(fun thm -> ASSUME_TAC (REWRITE_RULE[fformat_typbij] thm)) THENL [
REWRITE_TAC[is_valid_fformat] THEN
REWRITE_TAC[FLFORMAT_RADIX_LT_1] THEN
REWRITE_TAC[FLFORMAT_RADIX_EVEN] THEN
REWRITE_TAC[FLFORMAT_PREC_LT_0]; ALL_TAC] THEN
REWRITE_TAC[fr; fp; fe] THEN
ASM_REWRITE_TAC[]);;
(* -------------------------------------------------------------------------- *)
(* Useful ipow/exp properties, translated over to floating point *)
(* -------------------------------------------------------------------------- *)
let FLOAT_IPOW_LE_REAL =
prove(`!(fmt:flformat) (z:real). ?(e:int). z <= &(flr fmt) ipow e`,
GEN_TAC THEN
REWRITE_TAC[MATCH_MP IPOW_LE_REAL
(SPEC `fmt:flformat`FLFORMAT_RADIX_LE_2)]);;
let FLOAT_IPOW_LE_REAL_2 =
prove(`!(fmt:flformat) (z:real). &0 < z ==> ?(e:int). &(flr fmt) ipow e <= z`,
REPEAT GEN_TAC THEN DISCH_THEN (fun thm ->
REWRITE_TAC[MATCH_MP IPOW_LE_REAL_2 (CONJ thm
(SPEC `fmt:flformat`FLFORMAT_RADIX_LE_2))]));;
(* -------------------------------------------------------------------------- *)
(* Various float props *)
(* -------------------------------------------------------------------------- *)
let dump_float_defn isfloat =
LABEL_TAC "isfloat" isfloat THEN
CHOOSE_THEN
(CHOOSE_THEN (LABEL_TAC "isfracexp"))
(REWRITE_RULE[is_float] isfloat) THEN
USE_THEN "isfracexp" (fun isfracexp -> LABEL_CONJUNCTS_TAC
["fgt0"; "fltrp"; "absxeq"] (REWRITE_RULE[is_frac_and_exp] isfracexp));;
let FLOAT_NEG =
prove(`!(fmt:flformat) (x:real). is_float(fmt) x <=> is_float(fmt) (-- x)`,
REPEAT GEN_TAC THEN REWRITE_TAC[is_float] THEN
REWRITE_TAC[is_frac_and_exp] THEN
REWRITE_TAC[ARITH_RULE `abs(-- x) = abs(x)`] );;
let FLOAT_NOT_ZERO =
prove(`!(fmt:flformat) (x:real). is_float(fmt) x ==> ~(x = &0)`,
REPEAT GEN_TAC THEN DISCH_THEN dump_float_defn THEN
ONCE_REWRITE_TAC[GSYM REAL_ABS_ZERO] THEN
MATCH_MP_TAC (ARITH_RULE
`!y. (x:real) = y /\ ~(y = &0) ==> ~(x = &0)`) THEN
EXISTS_TAC `&f * &(flr fmt) ipow (e - &(flp fmt) + &1)` THEN
ASM_REWRITE_TAC[] THEN
REWRITE_TAC[REAL_ENTIRE] THEN REWRITE_TAC[DE_MORGAN_THM] THEN
CONJ_TAC THENL [
REWRITE_TAC[REAL_OF_NUM_EQ] THEN ASM_ARITH_TAC;
MATCH_MP_TAC (ARITH_RULE `&0 < x ==> ~(x = &0)`) THEN
REWRITE_TAC[FLFORMAT_RADIX_IPOW_LT_0]]);;
(* -------------------------------------------------------------------------- *)
(* greatest_e, greatest_m, greatest_r *)
(* -------------------------------------------------------------------------- *)
let is_greatest_e = define
`is_greatest_e (fmt:flformat) (x:real) (e:int) =
(&(flr fmt) ipow e <= abs(x) /\ !(e':int). &(flr fmt) ipow e' <= abs(x)
==> e' <= e)`;;
let FLOAT_GREATEST_E_EXISTS =
prove(`!(fmt:flformat) (x:real). ~(x = &0) ==>
?(e:int). greatest_e(fmt) x = e /\ is_greatest_e(fmt) x e`,
REPEAT GEN_TAC THEN DISCH_THEN (LABEL_TAC "xneq0") THEN
SUBGOAL_THEN `~({ e:int | &(flr fmt) ipow e <= abs(x) } = {})`
(LABEL_TAC "neqempty") THENL [
REWRITE_TAC[GSYM MEMBER_NOT_EMPTY] THEN
REWRITE_TAC[IN_ELIM_THM] THEN
USE_THEN "xneq0" (fun xneq0 ->
REWRITE_TAC[MATCH_MP FLOAT_IPOW_LE_REAL_2
(MATCH_MP
(ARITH_RULE `~((x:real) = &0) ==> &0 < abs(x)`) xneq0)]);
ALL_TAC] THEN
SUBGOAL_THEN `?(b:int). !(e:int). e IN
{ e:int | &(flr fmt) ipow e <= abs(x) } ==> e <= b`
(CHOOSE_THEN (LABEL_TAC "bound")) THENL [
CHOOSE_TAC (SPECL [`fmt:flformat`; `abs((x:real))`]
FLOAT_IPOW_LE_REAL) THEN
EXISTS_TAC `e:int` THEN
GEN_TAC THEN REWRITE_TAC[IN_ELIM_THM] THEN
DISCH_TAC THEN MATCH_MP_TAC IPOW_MONOTONE THEN
EXISTS_TAC `(flr fmt)` THEN REWRITE_TAC[FLFORMAT_RADIX_LE_2] THEN
ASM_ARITH_TAC; ALL_TAC] THEN
USE_THEN "neqempty" (fun neqempty -> USE_THEN "bound" (fun bound ->
CHOOSE_THEN (LABEL_CONJUNCTS_TAC ["supint"; "issupint"])
(MATCH_MP SUP_INT_BOUNDED (CONJ neqempty bound)))) THEN
EXISTS_TAC `e':int` THEN REWRITE_TAC[greatest_e; is_greatest_e] THEN
ASM_REWRITE_TAC[] THEN USE_THEN "issupint" (fun issupint ->
(LABEL_CONJUNCTS_TAC ["inset"; "biggest"]) (REWRITE_RULE[is_sup_int]
issupint)) THEN
CONJ_TAC THENL [
USE_THEN "inset" (fun inset -> REWRITE_TAC[REWRITE_RULE[IN_ELIM_THM]
inset]);
USE_THEN "biggest" (fun biggest ->
REWRITE_TAC[REWRITE_RULE[IN_ELIM_THM] biggest])]);;
let dump_ge_info xneq0 lbl =
let concat s = String.concat "" [lbl; s] in
CHOOSE_THEN
(LABEL_CONJUNCTS_TAC [concat "geeq"; concat "gebig"])
(MATCH_MP (SPEC `fmt:flformat` FLOAT_GREATEST_E_EXISTS) xneq0) THEN
USE_THEN (concat "gebig") (fun gebig ->
LABEL_CONJUNCTS_TAC [concat "gebig1"; concat "gebig2"]
(REWRITE_RULE[is_greatest_e] gebig));;
let dump_fl_ge_info isfloat lbl =
dump_ge_info (MATCH_MP (SPEC `fmt:flformat` FLOAT_NOT_ZERO) isfloat) lbl;;
let FLOAT_GREATEST_E_UNIQUE =
prove(`!(fmt:flformat) (x:real) (e1:int) (e2:int).
is_greatest_e(fmt) x e1 /\ is_greatest_e(fmt) x e2 ==>
e1 = e2`,
REPEAT GEN_TAC THEN DISCH_THEN
(LABEL_CONJUNCTS_TAC ["e1ge"; "e2ge"]) THEN
USE_THEN "e1ge" (fun e1ge -> LABEL_CONJUNCTS_TAC ["e1leqx"; "e1big"]
(REWRITE_RULE[is_greatest_e] e1ge)) THEN
USE_THEN "e2ge" (fun e2ge -> LABEL_CONJUNCTS_TAC ["e2leqx"; "e2big"]
(REWRITE_RULE[is_greatest_e] e2ge)) THEN
SUBGOAL_THEN `(e1:int) <= e2` ASSUME_TAC THENL [
USE_THEN "e2big" (fun e2big -> MATCH_MP_TAC e2big) THEN
ASM_REWRITE_TAC[]; ALL_TAC] THEN
SUBGOAL_THEN `(e2:int) <= e1` ASSUME_TAC THENL [
USE_THEN "e1big" (fun e1big -> MATCH_MP_TAC e1big) THEN
ASM_REWRITE_TAC[]; ALL_TAC] THEN
ASM_ARITH_TAC);;
let FLOAT_GREATEST_E_NEG =
prove(`!(fmt:flformat) (x:real). ~(x = &0) ==>
greatest_e(fmt) (-- x) = greatest_e(fmt) x`,
REPEAT GEN_TAC THEN DISCH_THEN (LABEL_TAC "xneq0") THEN
MATCH_MP_TAC FLOAT_GREATEST_E_UNIQUE THEN
EXISTS_TAC `fmt:flformat` THEN EXISTS_TAC `-- x` THEN
SUBGOAL_THEN `~(-- x = &0)` (LABEL_TAC "negxneq0") THENL [
ASM_ARITH_TAC; ALL_TAC] THEN
USE_THEN "negxneq0" (fun negxneq0 -> dump_ge_info negxneq0 "negx") THEN
ASM_REWRITE_TAC[] THEN REWRITE_TAC[is_greatest_e] THEN
USE_THEN "xneq0" (fun xneq0 -> dump_ge_info xneq0 "x") THEN
ASM_REWRITE_TAC[] THEN
REWRITE_TAC[ARITH_RULE `abs(-- x) = abs(x)`] THEN
ASM_REWRITE_TAC[]);;
let is_greatest_m = define
`is_greatest_m (fmt:flformat) (x:real) (m:num) =
(&m * &(flr fmt) ipow (greatest_e(fmt) x) <= abs(x) /\
!(m':num). &m' * &(flr fmt) ipow (greatest_e(fmt) x) <= abs(x) ==>
m' <= m)`;;
let FLOAT_GREATEST_M_EXISTS =
prove(`!(fmt:flformat) (x:real). ~(x = &0) ==>
?(m:num). greatest_m(fmt) x = m /\
is_greatest_m(fmt) x m /\
1 <= m /\
m < (flr fmt)`,
REPEAT GEN_TAC THEN DISCH_THEN (LABEL_TAC "xneq0") THEN
SUBGOAL_THEN `1 IN { (m:num) |
&m * &(flr fmt) ipow (greatest_e(fmt) x) <= abs(x) }`
(LABEL_TAC "oneins") THENL [
REWRITE_TAC[IN_ELIM_THM] THEN
REWRITE_TAC[ARITH_RULE `&1 * (x:real) = x`] THEN
USE_THEN "xneq0" (fun xneq0 -> CHOOSE_THEN
(LABEL_CONJUNCTS_TAC ["geeq"; "isge"])
(SPEC `fmt:flformat` (MATCH_MP FLOAT_GREATEST_E_EXISTS xneq0))) THEN
ASM_REWRITE_TAC[] THEN USE_THEN "isge" (fun isge ->
REWRITE_TAC[REWRITE_RULE[IN_ELIM_THM] (REWRITE_RULE[is_greatest_e]
isge)]); ALL_TAC] THEN
SUBGOAL_THEN `~({ (m:num) | &m * &(flr fmt) ipow (greatest_e(fmt) x) <=
abs(x) } = {})`
(LABEL_TAC "neqempty") THENL [
REWRITE_TAC[GSYM MEMBER_NOT_EMPTY] THEN
EXISTS_TAC `1:num` THEN ASM_REWRITE_TAC[]; ALL_TAC] THEN
SUBGOAL_THEN `!(m:num). m IN
{ (m:num) | &m * &(flr fmt) ipow (greatest_e(fmt) x) <=
abs(x) } ==> m < (flr fmt)`
(LABEL_TAC "bound") THENL [
GEN_TAC THEN REWRITE_TAC[IN_ELIM_THM] THEN
USE_THEN "xneq0" (fun xneq0 -> CHOOSE_THEN
(LABEL_CONJUNCTS_TAC ["geeq"; "isge"])
(SPEC `fmt:flformat` (MATCH_MP FLOAT_GREATEST_E_EXISTS xneq0))) THEN
ASM_REWRITE_TAC[] THEN
ASM_CASES_TAC `m < (flr fmt)` THENL [
ASM_ARITH_TAC;
SUBGOAL_THEN `?k. m = (flr fmt) + k` CHOOSE_TAC THENL [
EXISTS_TAC `m - (flr fmt)` THEN
ASM_ARITH_TAC; ALL_TAC] THEN
ASM_REWRITE_TAC[] THEN DISCH_TAC THEN
SUBGOAL_THEN `&(flr fmt) ipow (e + &1) <= abs(x)`
(LABEL_TAC "eplus1") THENL [
REWRITE_TAC[GSYM(MATCH_MP IPOW_ADD_EXP
(SPEC `fmt:flformat`FLFORMAT_RADIX_NE_0))] THEN
REWRITE_TAC[IPOW_TO_1] THEN
ONCE_REWRITE_TAC[ARITH_RULE `(a:real) * b = b * a`] THEN
ASSUME_TAC (REWRITE_RULE[ARITH_RULE `((a:real) + b) * c =
a * c + b * c`] (REWRITE_RULE[GSYM REAL_OF_NUM_ADD]
(ASSUME `&(flr fmt + k) * &(flr fmt) ipow e <= abs x`))) THEN
MATCH_MP_TAC (ARITH_RULE
`!z. &0 <= z /\ (a:real) + z <= b ==> a <= b`) THEN
EXISTS_TAC `&k * &(flr fmt) ipow e` THEN ASM_REWRITE_TAC[] THEN
MATCH_MP_TAC REAL_LE_MUL THEN
REWRITE_TAC[FLFORMAT_RADIX_IPOW_LE_0] THEN ARITH_TAC;
ALL_TAC] THEN
USE_THEN "eplus1" (fun eplus1 -> USE_THEN "isge" (fun isge ->
LABEL_TAC "eplus1leqe" (MATCH_MP (CONJUNCT2 (
REWRITE_RULE[is_greatest_e] isge)) eplus1))) THEN
ASM_ARITH_TAC]; ALL_TAC] THEN
SUBGOAL_THEN `!(m:num). m IN
{ (m:num) | &m * &(flr fmt) ipow (greatest_e(fmt) x) <=
abs(x) } ==> m <= (flr fmt)`
(LABEL_TAC "bound2") THENL [
GEN_TAC THEN
DISCH_THEN (fun thm -> USE_THEN "bound" (fun bound ->
ASSUME_TAC (MATCH_MP bound thm))) THEN ASM_ARITH_TAC; ALL_TAC] THEN
USE_THEN "neqempty" (fun neqempty -> USE_THEN "bound2" (fun bound2 ->
CHOOSE_THEN (LABEL_CONJUNCTS_TAC ["supnum"; "issupnum"])
(MATCH_MP SUP_NUM_BOUNDED (CONJ neqempty bound2)))) THEN
EXISTS_TAC `n':num` THEN REWRITE_TAC[greatest_m; is_greatest_m] THEN
ASM_REWRITE_TAC[] THEN USE_THEN "issupnum" (fun issupnum ->
(LABEL_CONJUNCTS_TAC ["inset"; "biggest"]) (REWRITE_RULE[is_sup_num]
issupnum)) THEN
CONJ_TAC THENL [
CONJ_TAC THENL [
USE_THEN "inset" (fun inset -> REWRITE_TAC[REWRITE_RULE[IN_ELIM_THM]
inset]);
USE_THEN "biggest" (fun biggest ->
REWRITE_TAC[REWRITE_RULE[IN_ELIM_THM] biggest])];
CONJ_TAC THENL [
USE_THEN "oneins" (fun oneins -> USE_THEN "biggest" (fun biggest ->
REWRITE_TAC[MATCH_MP biggest oneins]));
USE_THEN "bound" (fun bound -> USE_THEN "inset" (fun inset ->
REWRITE_TAC[MATCH_MP bound inset]))]]);;
let dump_gm_info xneq0 lbl =
let concat s = String.concat "" [lbl; s] in
CHOOSE_THEN
(LABEL_CONJUNCTS_TAC [concat "gmeq"; concat "gmbig"; concat "gmgeq1";
concat "gmltr"])
(MATCH_MP (SPEC `fmt:flformat` FLOAT_GREATEST_M_EXISTS) xneq0) THEN
USE_THEN (concat "gmbig") (fun gmbig ->
LABEL_CONJUNCTS_TAC [concat "gmbig1"; concat "gmbig2"]
(REWRITE_RULE[is_greatest_m] gmbig));;
let dump_fl_gm_info isfloat lbl =
dump_gm_info (MATCH_MP (SPEC `fmt:flformat` FLOAT_NOT_ZERO) isfloat) lbl;;
let FLOAT_GREATEST_M_UNIQUE =
prove(`!(fmt:flformat) (x:real) (m1:num) (m2:num).
is_greatest_m(fmt) x m1 /\ is_greatest_m(fmt) x m2 ==>
m1 = m2`,
REPEAT GEN_TAC THEN DISCH_THEN
(LABEL_CONJUNCTS_TAC ["m1ge"; "m2ge"]) THEN
USE_THEN "m1ge" (fun m1ge -> LABEL_CONJUNCTS_TAC ["m1leqx"; "m1big"]
(REWRITE_RULE[is_greatest_m] m1ge)) THEN
USE_THEN "m2ge" (fun m2ge -> LABEL_CONJUNCTS_TAC ["m2leqx"; "m2big"]
(REWRITE_RULE[is_greatest_m] m2ge)) THEN
SUBGOAL_THEN `(m1:num) <= m2` ASSUME_TAC THENL [
USE_THEN "m2big" (fun m2big -> MATCH_MP_TAC m2big) THEN
ASM_REWRITE_TAC[]; ALL_TAC] THEN
SUBGOAL_THEN `(m2:num) <= m1` ASSUME_TAC THENL [
USE_THEN "m1big" (fun m1big -> MATCH_MP_TAC m1big) THEN
ASM_REWRITE_TAC[]; ALL_TAC] THEN
ASM_ARITH_TAC);;
let FLOAT_GREATEST_M_NEG =
prove(`!(fmt:flformat) (x:real). ~(x = &0) ==>
greatest_m(fmt) (-- x) = greatest_m(fmt) x`,
REPEAT GEN_TAC THEN DISCH_THEN (LABEL_TAC "xneq0") THEN
MATCH_MP_TAC FLOAT_GREATEST_M_UNIQUE THEN
EXISTS_TAC `fmt:flformat` THEN EXISTS_TAC `-- x` THEN
SUBGOAL_THEN `~(-- x = &0)` (LABEL_TAC "negxneq0") THENL [
ASM_ARITH_TAC; ALL_TAC] THEN
USE_THEN "negxneq0" (fun negxneq0 -> dump_gm_info negxneq0 "negx") THEN
ASM_REWRITE_TAC[] THEN REWRITE_TAC[is_greatest_m] THEN
USE_THEN "xneq0" (fun xneq0 -> REWRITE_TAC[MATCH_MP
FLOAT_GREATEST_E_NEG xneq0]) THEN
USE_THEN "xneq0" (fun xneq0 -> dump_gm_info xneq0 "x") THEN
ASM_REWRITE_TAC[] THEN
REWRITE_TAC[ARITH_RULE `abs(-- x) = abs(x)`] THEN
ASM_REWRITE_TAC[]);;
let old_dump_ge_gm_info xneq0 =
CHOOSE_THEN
(LABEL_CONJUNCTS_TAC ["geeq"; "isge"])
(SPEC `fmt:flformat` (MATCH_MP FLOAT_GREATEST_E_EXISTS xneq0)) THEN
REMOVE_THEN "isge" (fun isge -> LABEL_CONJUNCTS_TAC ["geleqx"; "gebig"]
(REWRITE_RULE[is_greatest_e] isge)) THEN
CHOOSE_THEN
(LABEL_CONJUNCTS_TAC ["gmeq"; "isgm"; "gmgeq1"; "gmltr"])
(SPEC `fmt:flformat` (MATCH_MP FLOAT_GREATEST_M_EXISTS xneq0)) THEN
REMOVE_THEN "isgm" (fun isgm -> LABEL_CONJUNCTS_TAC ["gmleqx2"; "gmbig2"]
(REWRITE_RULE[is_greatest_m] isgm)) THEN
REMOVE_THEN "gmleqx2" (fun gmleqx2 -> USE_THEN "geeq" (fun geeq ->
LABEL_TAC "gmleqx" (REWRITE_RULE[geeq] gmleqx2))) THEN
REMOVE_THEN "gmbig2" (fun gmbig2 -> USE_THEN "geeq" (fun geeq ->
LABEL_TAC "gmbig" (REWRITE_RULE[geeq] gmbig2)));;
let dump_flformat_conv expterm =
CHOOSE_THEN
(LABEL_CONJUNCTS_TAC ["fmteq"; "fmteqr"; "fmteqp"; "fmteqe"])
(SPECL [`fmt:flformat`; expterm] FLFORMAT_TO_FFORMAT);;
let FLOAT_GREATEST_R_EXISTS =
prove(`!(fmt:flformat) (x:real). ~(x = &0) ==>
?(y:real). greatest_r(fmt) x = y /\
abs(y) < (finf (to_fformat fmt (greatest_e(fmt) x)))`,
REPEAT GEN_TAC THEN DISCH_THEN (LABEL_TAC "xneq0") THEN
USE_THEN "xneq0" (fun xneq0 -> old_dump_ge_gm_info xneq0) THEN
ASM_REWRITE_TAC[] THEN dump_flformat_conv `e:int` THEN
ASM_REWRITE_TAC[] THEN REWRITE_TAC[greatest_r] THEN
ASM_CASES_TAC `&0 <= (x:real)` THENL [
(* 0 <= x *)
ASM_REWRITE_TAC[] THEN
EXISTS_TAC `x - &m * &(flr fmt) ipow e` THEN REWRITE_TAC[] THEN
SUBGOAL_THEN `abs(x - &m * &(flr fmt) ipow e) =
x - &m * &(flr fmt) ipow e`
(fun thm -> REWRITE_TAC[thm]) THENL [
ASM_ARITH_TAC; ALL_TAC] THEN
REWRITE_TAC[finf] THEN ASM_REWRITE_TAC[] THEN
REWRITE_TAC[ARITH_RULE `(x:real) - y < z <=> x < y + z`] THEN
USE_THEN "gmbig" (fun gmbig -> LABEL_TAC "mplus1"
(MATCH_MP (ONCE_REWRITE_RULE[GSYM CONTRAPOS_THM] gmbig)
(ARITH_RULE `~(m + 1 <= m)`))) THEN
REWRITE_TAC[ARITH_RULE `(a:real) * b + b = (a + &1) * b`] THEN
REWRITE_TAC[REAL_OF_NUM_ADD] THEN ASM_ARITH_TAC;
(* x < 0 *)
ASM_REWRITE_TAC[] THEN
EXISTS_TAC `x + &m * &(flr fmt) ipow e` THEN REWRITE_TAC[] THEN
SUBGOAL_THEN `abs(x + &m * &(flr fmt) ipow e) =
-- x - &m * &(flr fmt) ipow e`
(fun thm -> REWRITE_TAC[thm]) THENL [
ASM_ARITH_TAC; ALL_TAC] THEN
REWRITE_TAC[finf] THEN ASM_REWRITE_TAC[] THEN
REWRITE_TAC[ARITH_RULE `(x:real) - y < z <=> x < y + z`] THEN
USE_THEN "gmbig" (fun gmbig -> LABEL_TAC "mplus1"
(MATCH_MP (ONCE_REWRITE_RULE[GSYM CONTRAPOS_THM] gmbig)
(ARITH_RULE `~(m + 1 <= m)`))) THEN
REWRITE_TAC[ARITH_RULE `(a:real) * b + b = (a + &1) * b`] THEN
REWRITE_TAC[REAL_OF_NUM_ADD] THEN ASM_ARITH_TAC]);;
let FLOAT_GREATEST_R_NEG =
prove(`!(fmt:flformat) (x:real). ~(x = &0) ==>
greatest_r(fmt) (-- x) = -- greatest_r(fmt) x`,
REPEAT GEN_TAC THEN DISCH_THEN (LABEL_TAC "xneq0") THEN
REWRITE_TAC[greatest_r] THEN
USE_THEN "xneq0" (fun xneq0 -> REWRITE_TAC[MATCH_MP
FLOAT_GREATEST_E_NEG xneq0] THEN REWRITE_TAC[MATCH_MP
FLOAT_GREATEST_M_NEG xneq0]) THEN
COND_CASES_TAC THENL [
ASM_ARITH_TAC;
ASM_ARITH_TAC]);;
let dump_gr_info xneq0 lbl =
let concat s = String.concat "" [lbl; s] in
CHOOSE_THEN
(LABEL_CONJUNCTS_TAC [concat "greq"; concat "grleq"])
(SPEC `fmt:flformat` (MATCH_MP FLOAT_GREATEST_R_EXISTS xneq0));;
let dump_fl_gr_info isfloat lbl =
dump_gr_info (MATCH_MP (SPEC `fmt:flformat` FLOAT_NOT_ZERO) isfloat) lbl;;
let FLOAT_GREATEST_R_LE_0 =
prove(`!(fmt:flformat) (x:real). ~(x = &0) /\ &0 <= x ==>
&0 <= greatest_r(fmt) x`,
REPEAT GEN_TAC THEN DISCH_THEN (LABEL_CONJUNCTS_TAC
["xneq0"; "xgeq0"]) THEN
REWRITE_TAC[greatest_r] THEN ASM_REWRITE_TAC[] THEN
REWRITE_TAC[ARITH_RULE `&0 <= (z:real) - w <=> w <= z`] THEN
USE_THEN "xgeq0" (fun xgeq0 -> GEN_REWRITE_TAC (RAND_CONV o
ONCE_DEPTH_CONV) [MATCH_MP
(ARITH_RULE `&0 <= (x:real) ==> x = abs(x)`) xgeq0]) THEN
USE_THEN "xneq0" (fun xneq0 -> dump_gm_info xneq0 "x") THEN
ASM_REWRITE_TAC[]);;
let FLOAT_GREATEST_R_LE_0_2 =
prove(`!(fmt:flformat) (x:real). ~(x = &0) /\ ~(&0 <= x) ==>
greatest_r(fmt) x <= &0`,
REPEAT GEN_TAC THEN DISCH_THEN (LABEL_CONJUNCTS_TAC
["xneq0"; "xgeq0"]) THEN
REWRITE_TAC[greatest_r] THEN ASM_REWRITE_TAC[] THEN
REWRITE_TAC[ARITH_RULE `((z:real) + w <= &0) <=> (w <= -- z)`] THEN
USE_THEN "xgeq0" (fun xgeq0 -> GEN_REWRITE_TAC (RAND_CONV o
ONCE_DEPTH_CONV) [MATCH_MP
(ARITH_RULE `~(&0 <= (x:real)) ==> -- x = abs(x)`) xgeq0]) THEN
USE_THEN "xneq0" (fun xneq0 -> dump_gm_info xneq0 "x") THEN
ASM_REWRITE_TAC[]);;
let old_dump_ge_gm_gr_info xneq0 =
old_dump_ge_gm_info xneq0 THEN
CHOOSE_THEN
(LABEL_CONJUNCTS_TAC ["greq"; "grleq2"])
(SPEC `fmt:flformat` (MATCH_MP FLOAT_GREATEST_R_EXISTS xneq0)) THEN
USE_THEN "geeq" (fun geeq -> dump_flformat_conv (rand (concl geeq))) THEN
REMOVE_THEN "grleq2" (fun grleq2 -> USE_THEN "fmteq" (fun fmteq ->
USE_THEN "geeq" (fun geeq ->
LABEL_TAC "grleq" (REWRITE_RULE[fmteq] (REWRITE_RULE[geeq] grleq2)))));;
let FLOAT_NORMALIZE_REAL =
prove(`!(fmt:flformat) (x:real). ~(x = &0) ==>
(if (&0 <= x)
then
x = &(greatest_m(fmt) x) * &(flr fmt) ipow (greatest_e(fmt) x) +
(greatest_r(fmt) x)
else
x = -- (&(greatest_m(fmt) x) *
&(flr fmt) ipow (greatest_e(fmt) x)) +
(greatest_r(fmt) x))`,
REPEAT GEN_TAC THEN DISCH_THEN (LABEL_TAC "xneq0") THEN
USE_THEN "xneq0" (fun xneq0 -> old_dump_ge_gm_gr_info xneq0) THEN
REWRITE_TAC[greatest_r] THEN ASM_REWRITE_TAC[] THEN
ARITH_TAC);;
let FLOAT_NORM_FRAC =
prove(`!(fmt:flformat) (x:real). is_float(fmt) x ==>
?(f:num) (e:int). (flr fmt) EXP ((flp fmt) - 1) <= f /\
is_frac_and_exp(fmt) x f e`,
REPEAT GEN_TAC THEN DISCH_THEN dump_float_defn THEN
SUBGOAL_THEN `?n. (flr fmt) EXP ((flp fmt) - 1) <=
f * (flr fmt) EXP n`
(LABEL_TAC "nexist") THENL [
EXISTS_TAC `(flp fmt) - 1` THEN REWRITE_TAC[IN_ELIM_THM] THEN
GEN_REWRITE_TAC (RATOR_CONV o RAND_CONV o ONCE_DEPTH_CONV)
[ARITH_RULE `n:num = n * 1`] THEN
GEN_REWRITE_TAC (RAND_CONV o ONCE_DEPTH_CONV)
[ARITH_RULE `(n:num) * m = m * n`] THEN
REWRITE_TAC[LE_MULT_LCANCEL] THEN DISJ2_TAC THEN ASM_ARITH_TAC;
ALL_TAC] THEN
REMOVE_THEN "nexist" (fun nexist -> CHOOSE_THEN
(LABEL_CONJUNCTS_TAC ["expn"; "nsmall"])
(MATCH_MP (REWRITE_RULE[WF] WF_num) nexist)) THEN
EXISTS_TAC `f * (flr fmt) EXP n` THEN EXISTS_TAC `(e:int) - &n` THEN
ASM_REWRITE_TAC[] THEN REWRITE_TAC[is_frac_and_exp] THEN
CONJ_TAC THENL [
REWRITE_TAC[LT_MULT] THEN ASM_REWRITE_TAC[] THEN
REWRITE_TAC[EXP_LT_0] THEN DISJ1_TAC THEN
REWRITE_TAC[GSYM REAL_OF_NUM_EQ] THEN
REWRITE_TAC[FLFORMAT_RADIX_NE_0];
CONJ_TAC THENL [
DISJ_CASES_TAC (SPEC `n:num` num_CASES) THENL [
ASM_REWRITE_TAC[] THEN REWRITE_TAC[EXP] THEN
ASM_ARITH_TAC;
CHOOSE_THEN (LABEL_TAC "neqnp")
(ASSUME `?n'. n = SUC n'`) THEN
CHOOSE_THEN (LABEL_TAC "peqpp")
(MATCH_MP (REWRITE_RULE[TAUT `a \/ b <=> ~a ==> b`] num_CASES)
(MATCH_MP (ARITH_RULE `0 < a ==> ~(a = 0)`)
(SPEC `fmt:flformat` FLFORMAT_PREC_LT_0))) THEN
ASM_REWRITE_TAC[] THEN REWRITE_TAC[EXP] THEN
ONCE_REWRITE_TAC[ARITH_RULE
`(a:num) * b * c = b * (a * c)`] THEN
REWRITE_TAC[LT_MULT_LCANCEL] THEN CONJ_TAC THENL [
REWRITE_TAC[GSYM REAL_OF_NUM_EQ] THEN
REWRITE_TAC[FLFORMAT_RADIX_NE_0];
SUBGOAL_THEN `n'' = (flp fmt) - 1` (fun thm ->
REWRITE_TAC[thm]) THENL [
ASM_ARITH_TAC; ALL_TAC] THEN
SUBGOAL_THEN `(n':num) < n` (LABEL_TAC "npltn") THENL [
ASM_ARITH_TAC; ALL_TAC] THEN
REWRITE_TAC[ARITH_RULE `(a:num) < b <=> ~(b <= a)`] THEN
USE_THEN "npltn" (fun npltn -> USE_THEN "nsmall" (fun nsmall ->
REWRITE_TAC[MATCH_MP nsmall npltn]))]];
(* cancel the common factor ... *)
REWRITE_TAC[ARITH_RULE `(e:int) - &n - &(flp fmt) + &1 =
(-- &n) + (e - &(flp fmt) + &1)`] THEN
ONCE_REWRITE_TAC[GSYM(MATCH_MP (SPEC `&(flr fmt)` IPOW_ADD_EXP)
(SPEC `fmt:flformat` FLFORMAT_RADIX_NE_0))] THEN
GEN_REWRITE_TAC (RAND_CONV o RAND_CONV o RATOR_CONV o RAND_CONV o
ONCE_DEPTH_CONV)
[MATCH_MP (SPEC `&(flr fmt)` IPOW_INV_NEG)
(SPEC `fmt:flformat` FLFORMAT_RADIX_NE_0)] THEN
REWRITE_TAC[ARITH_RULE `-- -- (&n:int) = &n`] THEN
SUBGOAL_THEN `&(flr fmt) ipow &n = &((flr fmt) EXP n)` (fun thm ->
REWRITE_TAC[thm]) THENL [
SUBGOAL_THEN `&0 <= (&n:int)` (fun thm ->
CHOOSE_THEN ASSUME_TAC (MATCH_MP (SPEC `(flr fmt)` IPOW_EQ_EXP)
thm)) THENL [ ARITH_TAC; ALL_TAC ] THEN
ASM_REWRITE_TAC[] THEN REWRITE_TAC[NUM_OF_INT_OF_NUM];
ALL_TAC] THEN
REWRITE_TAC[GSYM REAL_OF_NUM_MUL] THEN
SUBGOAL_THEN `(&((flr fmt) EXP n)) * inv (&((flr fmt) EXP n)) = &1`
ASSUME_TAC THENL [
MATCH_MP_TAC REAL_MUL_RINV THEN REWRITE_TAC[REAL_OF_NUM_EQ] THEN
REWRITE_TAC[EXP_EQ_0] THEN REWRITE_TAC[DE_MORGAN_THM] THEN
DISJ1_TAC THEN REWRITE_TAC[GSYM REAL_OF_NUM_EQ] THEN
REWRITE_TAC[FLFORMAT_RADIX_NE_0]; ALL_TAC] THEN
REWRITE_TAC[ARITH_RULE `((x:real) * y) * inv y * z =
(y * inv y) * x * z`] THEN
ASM_REWRITE_TAC[] THEN ARITH_TAC]]);;
let FLOAT_NORM_M =
prove(`!(fmt:flformat) (x:real). is_float(fmt) x ==>
(?(m:num) (e:int) (f':num).
f' < (flr fmt) EXP ((flp fmt) - 1) /\
1 <= m /\
m < (flr fmt) /\
abs(x) = &(m * (flr fmt) EXP ((flp fmt) - 1) + f') *
&(flr fmt) ipow (e - &(flp fmt) + &1))`,
REPEAT GEN_TAC THEN DISCH_THEN (fun thm -> CHOOSE_THEN
(CHOOSE_THEN (LABEL_CONJUNCTS_TAC ["flow"; "isfracexp"]))
(MATCH_MP FLOAT_NORM_FRAC thm)) THEN
REMOVE_THEN "isfracexp" (fun isfracexp -> LABEL_CONJUNCTS_TAC
["fpos"; "fleqrp"; "absxeq"] (REWRITE_RULE[is_frac_and_exp]
isfracexp)) THEN
SUBGOAL_THEN `?(m:num) (f':num).
f = m * ((flr fmt) EXP ((flp fmt) - 1)) + f' /\
f' < (flr fmt) EXP ((flp fmt) - 1)`
(CHOOSE_THEN (CHOOSE_THEN (LABEL_CONJUNCTS_TAC
["feqmfp"; "fpleq"]))) THENL [
MATCH_MP_TAC DIVMOD_EXIST THEN REWRITE_TAC[EXP_EQ_0] THEN
REWRITE_TAC[DE_MORGAN_THM] THEN DISJ1_TAC THEN
REWRITE_TAC[GSYM REAL_OF_NUM_EQ] THEN
REWRITE_TAC[FLFORMAT_RADIX_NE_0]; ALL_TAC] THEN
EXISTS_TAC `m:num` THEN EXISTS_TAC `e:int` THEN EXISTS_TAC `f':num` THEN
ASM_REWRITE_TAC[] THEN CONJ_TAC THENL [
MATCH_MP_TAC NUM_LE_MUL_1 THEN
EXISTS_TAC `(flr fmt) EXP ((flp fmt) - 1)` THEN
REWRITE_TAC[ARITH_RULE `1 <= b <=> 0 < b`] THEN
MATCH_MP_TAC (ARITH_RULE `!b. (a:num) < b /\ b <= c ==> a < c`) THEN
EXISTS_TAC `(flr fmt) EXP ((flp fmt) - 1) - f'` THEN
ASM_ARITH_TAC;
MATCH_MP_TAC (ARITH_RULE `!(a:num). x < (y:num) /\ ~(a = 0) ==>
x < y`) THEN
EXISTS_TAC `(flr fmt) EXP ((flp fmt) - 1)` THEN
REWRITE_TAC[GSYM LT_MULT_RCANCEL] THEN
GEN_REWRITE_TAC (RAND_CONV o ONCE_DEPTH_CONV)
[GSYM EXP] THEN
REWRITE_TAC[MATCH_MP (ARITH_RULE `0 < n ==> SUC (n - 1) = n`)
(SPEC `fmt:flformat` FLFORMAT_PREC_LT_0)] THEN
ASM_ARITH_TAC]);;
let FLOAT_NORM_GREATEST =
prove(`!(fmt:flformat) (x:real). is_float(fmt) x ==>
(?(f':num).
f' < (flr fmt) EXP ((flp fmt) - 1) /\
abs(x) = &((greatest_m(fmt) x) * ((flr fmt) EXP ((flp fmt) - 1))
+ f') *
&(flr fmt) ipow ((greatest_e(fmt) x) - &(flp fmt) + &1))`,
REPEAT GEN_TAC THEN DISCH_THEN (LABEL_TAC "isfloat") THEN
USE_THEN "isfloat" (fun isfloat -> CHOOSE_THEN
(CHOOSE_THEN (CHOOSE_THEN (LABEL_CONJUNCTS_TAC
["fpleqrp"; "mgeq1"; "mltr"; "absxeq"])))
(MATCH_MP FLOAT_NORM_M isfloat)) THEN
EXISTS_TAC `f':num` THEN ASM_REWRITE_TAC[] THEN
USE_THEN "isfloat" (fun isfloat -> LABEL_TAC "xneq0" (MATCH_MP
FLOAT_NOT_ZERO isfloat)) THEN
USE_THEN "xneq0" (fun xneq0 -> old_dump_ge_gm_info xneq0) THEN
SUBGOAL_THEN `&(flr fmt) ipow e <= abs(x)` (LABEL_TAC "eleqabs") THENL [
MATCH_MP_TAC REAL_LE_TRANS THEN
EXISTS_TAC `&m * &(flr fmt) ipow e` THEN CONJ_TAC THENL [
GEN_REWRITE_TAC (RATOR_CONV o RAND_CONV o ONCE_DEPTH_CONV)
[ARITH_RULE `(x:real) = &1 * x`] THEN
MATCH_MP_TAC REAL_LE_RMUL THEN CONJ_TAC THENL [
REWRITE_TAC[REAL_OF_NUM_LE] THEN ASM_REWRITE_TAC[];
REWRITE_TAC[FLFORMAT_RADIX_IPOW_LE_0]];
MATCH_MP_TAC REAL_LE_TRANS THEN
EXISTS_TAC `&(m * flr fmt EXP (flp fmt - 1) + f') *
&(flr fmt) ipow (e - &(flp fmt) + &1)` THEN
CONJ_TAC THENL [
REWRITE_TAC[GSYM REAL_OF_NUM_ADD] THEN
REWRITE_TAC[REAL_ADD_RDISTRIB] THEN
MATCH_MP_TAC (ARITH_RULE `(a:real) = b /\ &0 <= (c:real) ==>
a <= b + c`) THEN
CONJ_TAC THENL [
REWRITE_TAC[GSYM REAL_OF_NUM_MUL] THEN
REWRITE_TAC[GSYM (MATCH_MP (SPEC `(flr fmt)` IPOW_EQ_EXP_P)
(SPEC `fmt:flformat` FLFORMAT_PREC_LT_0))] THEN
REWRITE_TAC[ARITH_RULE `((a:real) * b) * c = a * (b * c)`] THEN
REWRITE_TAC[MATCH_MP IPOW_ADD_EXP
(SPEC `fmt:flformat` FLFORMAT_RADIX_NE_0)] THEN
REWRITE_TAC[ARITH_RULE `(x:int) - &1 + e - x + &1 = e`];
MATCH_MP_TAC REAL_LE_MUL THEN CONJ_TAC THENL [
REWRITE_TAC[REAL_OF_NUM_LE] THEN ARITH_TAC;
REWRITE_TAC[FLFORMAT_RADIX_IPOW_LE_0]]];
ASM_ARITH_TAC]]; ALL_TAC] THEN
USE_THEN "eleqabs" (fun eleqabs -> USE_THEN "gebig" (fun gebig ->
DISJ_CASES_TAC (MATCH_MP (ARITH_RULE `(e:int) <= b ==>
e = b \/ e < b`) (MATCH_MP gebig eleqabs)))) THENL [
(* e = e' *)
SUBGOAL_THEN `&m * &(flr fmt) ipow e' <= abs(x)`
(LABEL_TAC "mleqabs") THENL [
MATCH_MP_TAC REAL_LE_TRANS THEN
EXISTS_TAC `&(m * flr fmt EXP (flp fmt - 1) + f') *
&(flr fmt) ipow (e - &(flp fmt) + &1)` THEN
CONJ_TAC THENL [
REWRITE_TAC[GSYM REAL_OF_NUM_ADD] THEN
REWRITE_TAC[REAL_ADD_RDISTRIB] THEN
MATCH_MP_TAC (ARITH_RULE `(a:real) = b /\ &0 <= (c:real) ==>
a <= b + c`) THEN
CONJ_TAC THENL [
REWRITE_TAC[GSYM REAL_OF_NUM_MUL] THEN
REWRITE_TAC[GSYM (MATCH_MP (SPEC `(flr fmt)` IPOW_EQ_EXP_P)
(SPEC `fmt:flformat` FLFORMAT_PREC_LT_0))] THEN
REWRITE_TAC[ARITH_RULE
`((a:real) * b) * c = a * (b * c)`] THEN
REWRITE_TAC[MATCH_MP IPOW_ADD_EXP
(SPEC `fmt:flformat` FLFORMAT_RADIX_NE_0)] THEN
REWRITE_TAC[ARITH_RULE `(x:int) - &1 + e - x + &1 = e`] THEN
ASM_REWRITE_TAC[];
MATCH_MP_TAC REAL_LE_MUL THEN CONJ_TAC THENL [
REWRITE_TAC[REAL_OF_NUM_LE] THEN ARITH_TAC;
REWRITE_TAC[FLFORMAT_RADIX_IPOW_LE_0]]];
ASM_ARITH_TAC]; ALL_TAC] THEN
USE_THEN "mleqabs" (fun mleqabs -> USE_THEN "gmbig" (fun gmbig ->
DISJ_CASES_TAC (MATCH_MP (ARITH_RULE `(e:num) <= b ==>
e = b \/ e < b`) (MATCH_MP gmbig mleqabs)))) THENL [
(* m = m' *)
ASM_REWRITE_TAC[];
(* m < m' *)
SUBGOAL_THEN `&(m + 1) * &(flr fmt) ipow e' <= abs(x)`
ASSUME_TAC THENL [
MATCH_MP_TAC REAL_LE_TRANS THEN
EXISTS_TAC `&m' * &(flr fmt) ipow e'` THEN
ASM_REWRITE_TAC[] THEN MATCH_MP_TAC REAL_LE_RMUL THEN
REWRITE_TAC[FLFORMAT_RADIX_IPOW_LE_0] THEN
REWRITE_TAC[REAL_OF_NUM_LE] THEN ASM_ARITH_TAC; ALL_TAC] THEN
SUBGOAL_THEN `abs(x) < &(m + 1) * &(flr fmt) ipow e'`
ASSUME_TAC THENL [
ASM_REWRITE_TAC[] THEN REWRITE_TAC[GSYM REAL_OF_NUM_ADD] THEN
REWRITE_TAC[REAL_ADD_RDISTRIB] THEN
MATCH_MP_TAC (ARITH_RULE
`(a:real) < b /\ c = d ==> c + a < d + b`) THEN
CONJ_TAC THENL [
MATCH_MP_TAC (ARITH_RULE
`!b. (a:real) < b /\ b = c ==> a < c`) THEN
EXISTS_TAC `&((flr fmt) EXP ((flp fmt) - 1)) *
&(flr fmt) ipow (e' - &(flp fmt) + &1)` THEN
CONJ_TAC THENL [
MATCH_MP_TAC REAL_LT_RMUL THEN
REWRITE_TAC[FLFORMAT_RADIX_IPOW_LT_0] THEN
REWRITE_TAC[REAL_OF_NUM_LT] THEN ASM_REWRITE_TAC[];
REWRITE_TAC[GSYM (MATCH_MP (SPEC `(flr fmt)` IPOW_EQ_EXP_P)
(SPEC `fmt:flformat` FLFORMAT_PREC_LT_0))] THEN
REWRITE_TAC[MATCH_MP (SPEC `&(flr fmt)` IPOW_ADD_EXP)
(SPEC `fmt:flformat` FLFORMAT_RADIX_NE_0)] THEN
REWRITE_TAC[ARITH_RULE
`(e:int) - &1 + e' - e + &1 = e'`] THEN
ARITH_TAC];
REWRITE_TAC[GSYM REAL_OF_NUM_MUL] THEN
REWRITE_TAC[GSYM (MATCH_MP (SPEC `(flr fmt)` IPOW_EQ_EXP_P)
(SPEC `fmt:flformat` FLFORMAT_PREC_LT_0))] THEN
REWRITE_TAC[ARITH_RULE `((a:real) * b) * c = a * (b * c)`] THEN
REWRITE_TAC[MATCH_MP (SPEC `&(flr fmt)` IPOW_ADD_EXP)
(SPEC `fmt:flformat` FLFORMAT_RADIX_NE_0)] THEN
REWRITE_TAC[ARITH_RULE
`(e:int) - &1 + e' - e + &1 = e'`]];
ALL_TAC] THEN
ASM_ARITH_TAC];
(* e < e' *)
SUBGOAL_THEN `&(flr fmt) ipow (e + &1) <= abs(x)`
ASSUME_TAC THENL [
MATCH_MP_TAC REAL_LE_TRANS THEN
EXISTS_TAC `&(flr fmt) ipow e'` THEN CONJ_TAC THENL [
MATCH_MP_TAC IPOW_MONOTONE_2 THEN CONJ_TAC THENL [
REWRITE_TAC[REAL_OF_NUM_LE] THEN MATCH_MP_TAC
(ARITH_RULE `1 < x ==> 1 <= x`) THEN
REWRITE_TAC[FLFORMAT_RADIX_LT_1];
ASM_ARITH_TAC];
ASM_REWRITE_TAC[]]; ALL_TAC] THEN
SUBGOAL_THEN `abs(x) < &(flr fmt) ipow (e + &1)`
ASSUME_TAC THENL [
MATCH_MP_TAC (ARITH_RULE
`!b. (a:real) < b /\ b <= d ==> a < d`) THEN
EXISTS_TAC `&(m + 1) * &(flr fmt) ipow e` THEN CONJ_TAC THENL [
ASM_REWRITE_TAC[] THEN REWRITE_TAC[GSYM REAL_OF_NUM_ADD] THEN
REWRITE_TAC[REAL_ADD_RDISTRIB] THEN
MATCH_MP_TAC (ARITH_RULE
`(a:real) < b /\ c = d ==> c + a < d + b`) THEN
CONJ_TAC THENL [
MATCH_MP_TAC (ARITH_RULE
`!b. (a:real) < b /\ b = c ==> a < c`) THEN
EXISTS_TAC `&((flr fmt) EXP ((flp fmt) - 1)) *
&(flr fmt) ipow (e - &(flp fmt) + &1)` THEN
CONJ_TAC THENL [
MATCH_MP_TAC REAL_LT_RMUL THEN
REWRITE_TAC[FLFORMAT_RADIX_IPOW_LT_0] THEN
REWRITE_TAC[REAL_OF_NUM_LT] THEN ASM_REWRITE_TAC[];
REWRITE_TAC[GSYM (MATCH_MP (SPEC `(flr fmt)` IPOW_EQ_EXP_P)
(SPEC `fmt:flformat` FLFORMAT_PREC_LT_0))] THEN
REWRITE_TAC[MATCH_MP (SPEC `&(flr fmt)` IPOW_ADD_EXP)
(SPEC `fmt:flformat` FLFORMAT_RADIX_NE_0)] THEN
REWRITE_TAC[ARITH_RULE
`(e:int) - &1 + e' - e + &1 = e'`] THEN
ARITH_TAC];
REWRITE_TAC[GSYM REAL_OF_NUM_MUL] THEN
REWRITE_TAC[GSYM (MATCH_MP (SPEC `(flr fmt)` IPOW_EQ_EXP_P)
(SPEC `fmt:flformat` FLFORMAT_PREC_LT_0))] THEN
REWRITE_TAC[ARITH_RULE `((a:real) * b) * c = a * (b * c)`] THEN
REWRITE_TAC[MATCH_MP (SPEC `&(flr fmt)` IPOW_ADD_EXP)
(SPEC `fmt:flformat` FLFORMAT_RADIX_NE_0)] THEN
REWRITE_TAC[ARITH_RULE
`(e:int) - &1 + e' - e + &1 = e'`]];
REWRITE_TAC[GSYM (MATCH_MP (SPEC `&(flr fmt)` IPOW_ADD_EXP)
(SPEC `fmt:flformat` FLFORMAT_RADIX_NE_0))] THEN
GEN_REWRITE_TAC (RAND_CONV o ONCE_DEPTH_CONV)
[ARITH_RULE `(a:real) * b = b * a`] THEN
MATCH_MP_TAC REAL_LE_RMUL THEN
REWRITE_TAC[FLFORMAT_RADIX_IPOW_LE_0] THEN
REWRITE_TAC[IPOW_TO_1] THEN REWRITE_TAC[REAL_OF_NUM_LE] THEN
ASM_ARITH_TAC]; ALL_TAC] THEN
ASM_ARITH_TAC]);;
let FLOAT_NORMALIZE_FLOAT =
prove(`!(fmt:flformat) (x:real). is_float(fmt) x ==>
is_fixed(to_fformat fmt (greatest_e(fmt) x)) (greatest_r(fmt) x) /\
(if (&0 <= x)
then
x = &(greatest_m(fmt) x) * &(flr fmt) ipow (greatest_e(fmt) x) +
(greatest_r(fmt) x)
else
x = -- (&(greatest_m(fmt) x) *
&(flr fmt) ipow (greatest_e(fmt) x)) +
(greatest_r(fmt) x))`,
REPEAT GEN_TAC THEN DISCH_THEN (LABEL_TAC "isfloat") THEN
CONJ_TAC THENL [
USE_THEN "isfloat" (fun isfloat -> CHOOSE_THEN
(LABEL_CONJUNCTS_TAC ["fltrp"; "absxeq"]) (MATCH_MP
FLOAT_NORM_GREATEST isfloat)) THEN
dump_flformat_conv `greatest_e(fmt) x` THEN ASM_REWRITE_TAC[] THEN
ASM_CASES_TAC `&0 <= (x:real)` THENL [
REWRITE_TAC[greatest_r] THEN ASM_REWRITE_TAC[] THEN
SUBGOAL_THEN
`x - &(greatest_m fmt x) * &(flr fmt) ipow greatest_e fmt x =
&f' * &(flr fmt) ipow (greatest_e fmt x - &(flp fmt) + &1)`
(fun thm -> REWRITE_TAC[thm]) THENL [
SUBGOAL_THEN `x = abs(x)`
(fun thm -> GEN_REWRITE_TAC (RATOR_CONV o RAND_CONV o
RATOR_CONV o RAND_CONV o ONCE_DEPTH_CONV) [thm]) THENL [
ASM_ARITH_TAC; ALL_TAC] THEN
REWRITE_TAC[ARITH_RULE `((a:real) - b = c) <=> (a = b + c)`] THEN
ASM_REWRITE_TAC[] THEN REWRITE_TAC[GSYM REAL_OF_NUM_ADD] THEN
REWRITE_TAC[REAL_ADD_RDISTRIB] THEN
REWRITE_TAC[ARITH_RULE `((a:real) + b = c + b) <=> a = c`] THEN
REWRITE_TAC[GSYM REAL_OF_NUM_MUL] THEN
REWRITE_TAC[GSYM (MATCH_MP (SPEC `(flr fmt)` IPOW_EQ_EXP_P)
(SPEC `fmt:flformat` FLFORMAT_PREC_LT_0))] THEN
REWRITE_TAC[ARITH_RULE `((a:real) * b) * c = a * (b * c)`] THEN
REWRITE_TAC[MATCH_MP (SPEC `&(flr fmt)` IPOW_ADD_EXP)
(SPEC `fmt:flformat` FLFORMAT_RADIX_NE_0)] THEN
REWRITE_TAC[ARITH_RULE `(e:int) - &1 + e2 - e + &1 = e2`];
ALL_TAC] THEN
REWRITE_TAC[is_fixed] THEN EXISTS_TAC `f':num` THEN
REWRITE_TAC[is_frac] THEN CONJ_TAC THENL [
ASM_REWRITE_TAC[] THEN ASM_ARITH_TAC;
ASM_REWRITE_TAC[] THEN MATCH_MP_TAC (ARITH_RULE
`&0 <= (x:real) ==> abs(x) = x`) THEN
MATCH_MP_TAC REAL_LE_MUL THEN CONJ_TAC THENL [
ARITH_TAC;
REWRITE_TAC[FLFORMAT_RADIX_IPOW_LE_0]]];
(* x < 0 *)
REWRITE_TAC[greatest_r] THEN ASM_REWRITE_TAC[] THEN
SUBGOAL_THEN
`x + &(greatest_m fmt x) * &(flr fmt) ipow greatest_e fmt x =
-- (&f' * &(flr fmt) ipow (greatest_e fmt x - &(flp fmt) + &1))`
(fun thm -> REWRITE_TAC[thm]) THENL [
SUBGOAL_THEN `x = -- abs(x)`
(fun thm -> GEN_REWRITE_TAC (RATOR_CONV o RAND_CONV o
RATOR_CONV o RAND_CONV o ONCE_DEPTH_CONV) [thm]) THENL [
ASM_ARITH_TAC; ALL_TAC] THEN
REWRITE_TAC[ARITH_RULE
`(-- (a:real) + b = -- c) <=> (a = b + c)`] THEN
ASM_REWRITE_TAC[] THEN REWRITE_TAC[GSYM REAL_OF_NUM_ADD] THEN
REWRITE_TAC[REAL_ADD_RDISTRIB] THEN
REWRITE_TAC[ARITH_RULE `((a:real) + b = c + b) <=> a = c`] THEN
REWRITE_TAC[GSYM REAL_OF_NUM_MUL] THEN
REWRITE_TAC[GSYM (MATCH_MP (SPEC `(flr fmt)` IPOW_EQ_EXP_P)
(SPEC `fmt:flformat` FLFORMAT_PREC_LT_0))] THEN
REWRITE_TAC[ARITH_RULE `((a:real) * b) * c = a * (b * c)`] THEN
REWRITE_TAC[MATCH_MP (SPEC `&(flr fmt)` IPOW_ADD_EXP)
(SPEC `fmt:flformat` FLFORMAT_RADIX_NE_0)] THEN
REWRITE_TAC[ARITH_RULE `(e:int) - &1 + e2 - e + &1 = e2`];
ALL_TAC] THEN
REWRITE_TAC[is_fixed] THEN EXISTS_TAC `f':num` THEN
REWRITE_TAC[is_frac] THEN CONJ_TAC THENL [
ASM_REWRITE_TAC[] THEN ASM_ARITH_TAC;
ASM_REWRITE_TAC[] THEN MATCH_MP_TAC (ARITH_RULE
`&0 <= (x:real) ==> abs(-- x) = x`) THEN
MATCH_MP_TAC REAL_LE_MUL THEN CONJ_TAC THENL [
ARITH_TAC;
REWRITE_TAC[FLFORMAT_RADIX_IPOW_LE_0]]]];
USE_THEN "isfloat" (fun isfloat -> REWRITE_TAC[MATCH_MP
FLOAT_NORMALIZE_REAL (MATCH_MP FLOAT_NOT_ZERO isfloat)])]);;
(* -------------------------------------------------------------------------- *)
(* Discreteness and rounding lemmas *)
(* -------------------------------------------------------------------------- *)
let real_normalize xneq0 signthm lbl =
let concat s = String.concat "" [lbl; s] in
LABEL_TAC (concat "normed2")
(MATCH_MP (SPEC `fmt:flformat` FLOAT_NORMALIZE_REAL) xneq0) THEN
REMOVE_THEN (concat "normed2") (fun normed2 ->
LABEL_TAC (concat "normed") (REWRITE_RULE[signthm] normed2));;
let float_normalize isfloat signthm lbl =
let concat s = String.concat "" [lbl; s] in
LABEL_CONJUNCTS_TAC [concat "grfixed"; concat "normed2"]
(MATCH_MP (SPEC `fmt:flformat` FLOAT_NORMALIZE_FLOAT) isfloat) THEN
REMOVE_THEN (concat "normed2") (fun normed2 ->
LABEL_TAC (concat "normed") (REWRITE_RULE[signthm] normed2));;
let FLOAT_EQ_IPOW =
prove(`!(fmt:flformat) (x:real) (e:int) (m:num).
~(x = &0) /\
1 <= m /\
m < (flr fmt) /\
abs(x) = &m * &(flr fmt) ipow e ==>
greatest_e(fmt) x = e /\
greatest_m(fmt) x = m`,
REPEAT GEN_TAC THEN DISCH_THEN (LABEL_CONJUNCTS_TAC
["xneq0"; "mgeq1"; "mltr"; "mrleq"; "absxeq"]) THEN
SUBGOAL_THEN `greatest_e(fmt) x = e`
(LABEL_TAC "xgeeqe") THENL [
MATCH_MP_TAC FLOAT_GREATEST_E_UNIQUE THEN
EXISTS_TAC `fmt:flformat` THEN EXISTS_TAC `x:real` THEN
USE_THEN "xneq0" (fun xneq0 -> dump_ge_info xneq0 "x") THEN
ASM_REWRITE_TAC[] THEN
REWRITE_TAC[is_greatest_e] THEN
CONJ_TAC THENL [
(* show e is a lower bound *)
MATCH_MP_TAC REAL_LE_TRANS THEN
EXISTS_TAC `&m * &(flr fmt) ipow e` THEN ASM_REWRITE_TAC[] THEN
CONJ_TAC THENL [
GEN_REWRITE_TAC (RATOR_CONV o RAND_CONV o ONCE_DEPTH_CONV)
[ARITH_RULE `(x:real) = &1 * x`] THEN
MATCH_MP_TAC REAL_LE_RMUL THEN
REWRITE_TAC[REAL_OF_NUM_LE] THEN ASM_REWRITE_TAC[] THEN
REWRITE_TAC[FLFORMAT_RADIX_IPOW_LE_0];
ARITH_TAC]; ALL_TAC] THEN