3
;;;***************************************************************
4
;;;An ACL2 Library of Floating Point Arithmetic
7
;;;Advanced Micro Devices, Inc.
9
;;;***************************************************************
11
;(include-book "near")
12
(local (include-book "../../arithmetic/top"))
13
(local (include-book "float"))
14
(local (include-book "trunc"))
15
(local (include-book "away"))
16
(local (include-book "near"))
18
;; Necessary functions:
21
(declare (xargs :guard (real/rationalp x)))
25
(declare (xargs :guard (real/rationalp x)))
28
(defun expo-measure (x)
29
; (declare (xargs :guard (and (real/rationalp x) (not (equal x 0)))))
30
(cond ((not (rationalp x)) 0)
32
((< x 1) (cons 1 (fl (/ x))))
36
(declare (xargs :guard t
37
:measure (expo-measure x)))
38
(cond ((or (not (rationalp x)) (equal x 0)) 0)
39
((< x 0) (expo (- x)))
40
((< x 1) (1- (expo (* 2 x))))
42
(t (1+ (expo (/ x 2))))))
44
;could redefine to divide by the power of 2 (instead of making it a negative power of 2)...
46
(declare (xargs :guard t))
49
(- (* x (expt 2 (- (expo x)))))
50
(* x (expt 2 (- (expo x)))))
55
(declare (xargs :guard t))
56
(if (or (not (rationalp x)) (equal x 0))
63
; (declare (xargs :guard (and (real/rationalp x) (integerp n))))
64
(integerp (* (sig x) (expt 2 (1- n)))))
67
(declare (xargs :guard (integerp n)))
68
(* (sgn x) (fl (* (expt 2 (1- n)) (sig x))) (expt 2 (- (1+ (expo x)) n))))
71
(* (sgn x) (cg (* (expt 2 (1- n)) (sig x))) (expt 2 (- (1+ (expo x)) n))))
77
(let ((z (fl (* (expt 2 (1- n)) (sig x))))
78
(f (re (* (expt 2 (1- n)) (sig x)))))
92
(let ((z (fl (* (expt 2 (1- n)) (sig x)))))
94
(* (sgn x) (1+ z) (expt 2 (- (1+ (expo x)) n)))
95
(* (sgn x) z (expt 2 (- (1+ (expo x)) n))))))
105
:hints (("Goal" :in-theory (e/d (oddr) ( SIG-LESS-THAN-1-MEANS-X-0 sig-lower-bound))
106
:use ((:instance sig-lower-bound)))))
109
(implies (and (rationalp x)
113
(>= (oddr x n) (trunc x n)))
115
:hints (("Goal" :in-theory (enable oddr)
116
:use ((:instance trunc)
119
;BOZO just opens up ODDR when x is positive
121
(defthmd oddr-rewrite
122
(implies (and (< 0 x) ;note this hyp
127
(let ((z (fl (* (expt 2 (- (1- n) (expo x))) x))))
129
(* (1+ z) (expt 2 (- (1+ (expo x)) n)))
130
(* z (expt 2 (- (1+ (expo x)) n)))))))
131
:hints (("Goal" :in-theory (enable sig sgn oddr expt-split))))
135
(implies (and (integerp n)
137
(= (fl (* 1/2 x (expt 2 n)))
138
(fl (* x (expt 2 (1- n))))))
139
:hints (("Goal" :in-theory (enable expt)))
144
(implies (and (rationalp x)
149
(* (fl (/ (* (expt 2 (- (1- n) (expo x))) x) 2))
150
(expt 2 (- (+ 2 (expo x)) n)))))
152
:hints (("Goal" :in-theory (enable trunc-pos-rewrite)
153
:use ((:instance hack2 (n (- (1- n) (expo x)))))))))
157
(implies (and (rationalp x)
162
(* (fl (/ (fl (* (expt 2 (- (1- n) (expo x))) x)) 2))
163
(expt 2 (- (+ 2 (expo x)) n)))))
165
:hints (("Goal" :in-theory (disable fl/int-rewrite)
166
:use ((:instance oddr-other-1)
167
(:instance fl/int-rewrite (x (* (expt 2 (- (1- n) (expo x))) x)) (n 2)))))))
171
(implies (integerp z)
176
:hints (("Goal" :in-theory (enable evenp)))
181
(implies (and (rationalp x)
185
(= z (fl (* (expt 2 (- (1- n) (expo x))) x)))
188
(* z (expt 2 (- (1+ (expo x)) n)))))
190
:hints (("Goal" :use ((:instance fl/2)
191
(:instance expt-split (r 2) (j (- (1+ (expo x)) n)) (i 1))
192
(:instance oddr-other-2))))))
196
(implies (and (rationalp x)
200
(= z (fl (* (expt 2 (- (1- n) (expo x))) x)))
202
(= (* (fl (/ (fl (* (expt 2 (- (1- n) (expo x))) x)) 2))
203
(expt 2 (- (+ 2 (expo x)) n)))
204
(* (fl (/ z 2)) (expt 2 (- (+ 2 (expo x)) n)))))
209
(implies (and (rationalp x)
213
(= z (fl (* (expt 2 (- (1- n) (expo x))) x)))
216
(* (fl (/ z 2)) (expt 2 (- (+ 2 (expo x)) n)))))
218
:hints (("Goal" :use ((:instance oddr-other-2)
219
(:instance oddr-other-4))))))
223
(implies (and (rationalp x)
232
(implies (and (rationalp x)
236
(= z (fl (* (expt 2 (- (1- n) (expo x))) x)))
239
(* (/ (1- z) 2) (expt 2 (- (+ 2 (expo x)) n)))))
241
:hints (("Goal" :use ((:instance fl/2)
242
(:instance oddr-other-5)
246
(z (expt 2 (- (+ 2 (expo x)) n)))))))))
250
(implies (and (rationalp x)
254
(= z (fl (* (expt 2 (- (1- n) (expo x))) x)))
257
(* (1- z) (expt 2 (- (1+ (expo x)) n)))))
259
:hints (("Goal" :in-theory (enable expt-split)
260
:use ((:instance oddr-other-6)
261
(:instance expt-split (r 2) (j (- (1+ (expo x)) n)) (i 1)))))))
264
(implies (and (rationalp x)
270
(expt 2 (- (1+ (expo x)) n)))))
272
:hints (("Goal" :use ((:instance oddr-other-3 (z (fl (* (expt 2 (- (1- n) (expo x))) x))))
273
(:instance oddr-other-7 (z (fl (* (expt 2 (- (1- n) (expo x))) x))))
274
(:instance oddr-rewrite)))))
278
(implies (and (rationalp x)
282
(< (trunc x n) (expt 2 (1+ (expo x)))))
284
:hints (("Goal" :in-theory (e/d () ( expo-trunc abs-trunc))
285
:use ((:instance expo-trunc)
286
; (:instance trunc-pos)
287
(:instance expo-upper-bound (x (trunc x n))))))))
291
(implies (and (rationalp x)
295
(< (oddr x n) (expt 2 (1+ (expo x)))))
297
:hints (("Goal" :in-theory (e/d (expt-split) ( expo-trunc abs-trunc))
298
:use ((:instance expo-oddr-1 (n (1- n)))
299
(:instance oddr-other)
300
(:instance exactp-2**n (m (1- n)) (n (1+ (expo x))))
301
(:instance expo-trunc (n (1- n)))
302
(:instance expt-strong-monotone (n (- (1+ (expo x)) n)) (m (- (1+ (expo x)) (1- n))))
303
; (:instance trunc-pos (n (1- n)))
304
(:instance fp+2 (n (1- n)) (x (trunc x (1- n))) (y (expt 2 (1+ (expo x))))))))))
308
(implies (and (rationalp x)
312
(<= (expo (oddr x n)) (expo x)))
314
:hints (("Goal" :use ((:instance expo-oddr-2)
316
(:instance expo-upper-2 (x (oddr x n)) (n (1+ (expo x)))))))))
319
(implies (and (rationalp x)
323
(equal (expo (oddr x n)) (expo x)))
324
:hints (("Goal" :in-theory (e/d ( expt-split ) (EXPO-COMPARISON-REWRITE-TO-BOUND
325
EXPO-COMPARISON-REWRITE-TO-BOUND-2))
326
:use ((:instance expo-oddr-3)
327
(:instance oddr-other)
328
; (:instance expt-pos (x (- (1+ (expo x)) n)))
329
(:instance expo-monotone (y (oddr x n)) (x (trunc x (1- n))))
331
; (:instance trunc-pos (n (1- n)))
335
(defthm exactp-oddr-1
336
(implies (and (rationalp x)
340
(= (* (+ (trunc x (1- n))
341
(expt 2 (- (1+ (expo x)) n)))
342
(expt 2 (- (1- n) (expo x))))
343
(1+ (* (trunc x (1- n)) (expt 2 (- (1- n) (expo x)))))))
345
:hints (("Goal" :in-theory (disable ;expt-pos
347
:use ((:instance expt-split (r 2) (j (- (1- n) (expo x))) (i (- (1+ (expo x)) n))))))))
350
(defthm exactp-oddr-2
351
(implies (and (rationalp x)
355
(= (* (oddr x n) (expt 2 (- (1- n) (expo x))))
356
(1+ (* (trunc x (1- n)) (expt 2 (- (1- n) (expo x)))))))
358
:hints (("Goal" :in-theory (disable ;expt-pos
360
:use ((:instance oddr-other)
361
(:instance exactp-oddr-1))))))
364
(defthm exactp-oddr-3
365
(implies (and (rationalp x)
367
(= (expt 2 (- (1- n) (expo x)))
368
(* 2 (expt 2 (- (- n 2) (expo x))))))
370
:hints (("Goal" :use ((:instance expt-split (r 2) (j (- (- n 2) (expo x))) (i 1)))))))
373
(defthm exactp-oddr-4
374
(implies (and (rationalp x)
377
(= (* y 2 (expt 2 (- (- n 2) (expo x))))
378
(* 2 y (expt 2 (- (- n 2) (expo x))))))
382
(defthm exactp-oddr-5
383
(implies (and (rationalp x)
385
(= (* (trunc x (1- n)) (expt 2 (- (1- n) (expo x))))
386
(* 2 (trunc x (1- n)) (expt 2 (- (- n 2) (expo x))))))
388
:hints (("Goal" :use ((:instance exactp-oddr-3)
389
(:instance exactp-oddr-4 (y (trunc x (1- n)))))))))
392
(defthm exactp-oddr-6
393
(implies (and (rationalp x)
397
(= (* (oddr x n) (expt 2 (- (1- n) (expo x))))
398
(1+ (* 2 (* (trunc x (1- n)) (expt 2 (- (- n 2) (expo x))))))))
400
:hints (("Goal" :in-theory (disable ;expt-pos
402
:use ((:instance exactp-oddr-2)
403
(:instance exactp-oddr-5))))))
406
(implies (and (rationalp x)
410
(exactp (oddr x n) n))
412
:hints (("Goal" :in-theory (disable ;expt-pos
414
:use ((:instance exactp-oddr-6)
415
(:instance exactp2 (x (oddr x n)))
416
(:instance exactp2 (x (trunc x (1- n))) (n (1- n)))))))
418
(defthm not-exactp-oddr-1
419
(implies (and (rationalp x)
423
(= (* (+ (trunc x (1- n)) (expt 2 (- (1+ (expo x)) n)))
424
(expt 2 (- (- n 2) (expo x))))
425
(+ (* (trunc x (1- n)) (expt 2 (- (- n 2) (expo x)))) 1/2)))
427
:hints (("Goal" :use ((:instance expt-split (r 2) (i (- (- n 2) (expo x))) (j (- (1+ (expo x)) n))))))))
430
(defthm not-exactp-oddr-2
431
(implies (and (rationalp x)
436
(expt 2 (- (- n 2) (expo x))))
437
(+ (* (trunc x (1- n)) (expt 2 (- (- n 2) (expo x)))) 1/2)))
439
:hints (("Goal" :use ((:instance oddr-other)
440
(:instance not-exactp-oddr-1))))))
442
(defthm not-exactp-oddr
443
(implies (and (rationalp x)
447
(not (exactp (oddr x n) (1- n))))
449
:hints (("Goal" :in-theory (disable ;expt-pos
450
EQUAL-MULTIPLY-THROUGH-BY-inverted-factor-FROM-RIGHT-HAND-SIDE
452
:use ((:instance not-exactp-oddr-2)
453
(:instance exactp2 (x (oddr x n)) (n (1- n)))
454
(:instance exactp2 (x (trunc x (1- n))) (n (1- n)))))))
458
(implies (and (rationalp x)
462
(= (trunc (oddr x n) (1- n))
463
(* (fl (* (expt 2 (- (- n 2) (expo x)))
464
(+ (* (fl (* (expt 2 (- (- n 2) (expo x)))
466
(expt 2 (- (+ (expo x) 2) n)))
467
(expt 2 (- (1+ (expo x)) n)))))
468
(expt 2 (- (+ (expo x) 2) n)))))
470
:hints (("Goal" :in-theory (enable trunc-pos-rewrite)
471
:use ((:instance oddr-other)
472
(:instance oddr-pos))))))
476
(implies (and (rationalp x)
480
(= (trunc (oddr x n) (1- n))
481
(* (fl (+ (fl (* (expt 2 (- (- n 2) (expo x)))
484
(expt 2 (- (+ (expo x) 2) n)))))
486
:hints (("Goal" :in-theory (enable a15)
487
:use ((:instance trunc-oddr-1)
488
(:instance expt-split (r 2) (i (- (- n 2) (expo x))) (j (- (+ (expo x) 2) n)))
489
(:instance expt-split (r 2) (i (- (- n 2) (expo x))) (j (- (+ (expo x) 1) n))))))))
493
(implies (and (rationalp x)
497
(= (trunc (oddr x n) (1- n))
498
(* (fl (* (expt 2 (- (- n 2) (expo x)))
500
(expt 2 (- (+ (expo x) 2) n)))))
502
:hints (("Goal" :use ((:instance trunc-oddr-2))))))
506
(implies (and (rationalp x)
510
(= (trunc (oddr x n) (1- n))
513
:hints (("Goal" :in-theory (enable trunc-pos-rewrite)
514
:use ((:instance trunc-oddr-3))))))
517
(implies (and (rationalp x)
523
(= (trunc (oddr x n) m)
526
:hints (("Goal" :in-theory (disable trunc-trunc)
527
:use ((:instance trunc-oddr-4)
529
(:instance trunc-trunc (n (1- n)))
530
(:instance trunc-trunc (n (1- n)) (x (oddr x n)))
534
(+ k (- (expo (+ x y)) (expo y))))
537
(implies (and (rationalp x)
543
(> (+ (1- k) (- (expo x) (expo y))) 0)
544
(exactp x (+ (1- k) (- (expo x) (expo y)))))
546
(oddr (+ x y) (kp k x y))))
548
:hints (("Goal" :use ((:instance oddr-other (n k) (x y))
549
(:instance expo-monotone (x y) (y (+ x y)))
550
(:instance plus-trunc (k (1- k)))
551
(:instance oddr-other (x (+ x y)) (n (kp k x y)))))))
553
(defthm trunc-trunc-oddr
554
(implies (and (rationalp x)
562
(>= (trunc x k) (trunc (oddr y m) k)))
564
:hints (("Goal" :use ((:instance trunc-oddr (x y) (m k) (n m))
565
(:instance trunc-monotone (x y) (y x) (n k))))))
568
(defthm away-away-oddr-1
569
(implies (and (rationalp x)
577
(> (away x k) (trunc y (1- m))))
579
:hints (("Goal" :use ((:instance away-lower-pos (n k))
580
(:instance trunc-upper-pos (x y) (n (1- m))))))))
583
(defthm away-away-oddr-2
584
(implies (and (rationalp x)
592
(>= (away x k) (+ (trunc y (1- m)) (expt 2 (- (+ (expo y) 2) m)))))
594
:hints (("Goal" :use ((:instance away-away-oddr-1)
595
(:instance fp+2 (x (trunc y (1- m))) (y (away x k)) (n (1- m)))
596
(:instance expo-trunc (x y) (n (1- m)))
597
(:instance trunc-exactp-a (x y) (n (1- m)))
598
(:instance away-exactp-a (n k))
599
; (:instance trunc-pos (x y) (n (1- m)))
600
(:instance exactp-<= (x (away x k)) (m k) (n (1- m))))))))
603
(defthm away-away-oddr-3
604
(implies (and (rationalp x)
612
(> (away x k) (oddr y m)))
614
:hints (("Goal" :in-theory (disable EXPT-COMPARE)
615
:use ((:instance away-away-oddr-2)
616
(:instance oddr-other (x y) (n m))
617
(:instance expt-strong-monotone (n (- (1+ (expo y)) m)) (m (- (+ (expo y) 2) m))))))))
619
(defthm away-away-oddr
620
(implies (and (rationalp x)
628
(>= (away x k) (away (oddr y m) k)))
630
:hints (("Goal" :use ((:instance away-away-oddr-3)
631
(:instance oddr-pos (x y) (n m))
632
(:instance away-exactp-c (a (away x k)) (x (oddr y m)) (n k))
633
(:instance away-exactp-a (n k))))))
635
(defthm near-near-oddr
636
(implies (and (rationalp x)
644
(>= (near x k) (near (oddr y m) k)))
646
:hints (("Goal" :use ((:instance trunc-exactp-a (n (1- m)) (x y))
647
(:instance oddr-pos (x y) (n m))
648
; (:instance trunc-pos (x y) (n (1- m)))
649
(:instance trunc-upper-pos (x y) (n (1- m)))
650
(:instance expo-trunc (x y) (n (1- m)))
651
(:instance oddr-other (x y) (n m))
652
(:instance expt-strong-monotone
653
(n (- (1+ (expo y)) m))
654
(m (- (+ 2 (expo y)) m)))
b'\\ No newline at end of file'