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
|
(in-package "ACL2")
;;;***************************************************************
;;;An ACL2 Library of Floating Point Arithmetic
;;;David M. Russinoff
;;;Advanced Micro Devices, Inc.
;;;February, 1998
;;;***************************************************************
(local (include-book "oddr-proofs"))
;; Necessary functions:
(defund fl (x)
(declare (xargs :guard (real/rationalp x)))
(floor x 1))
(defund cg (x)
(declare (xargs :guard (real/rationalp x)))
(- (fl (- x))))
(defun expo-measure (x)
; (declare (xargs :guard (and (real/rationalp x) (not (equal x 0)))))
(cond ((not (rationalp x)) 0)
((< x 0) '(2 . 0))
((< x 1) (cons 1 (fl (/ x))))
(t (fl x))))
(defund expo (x)
(declare (xargs :guard t
:measure (expo-measure x)))
(cond ((or (not (rationalp x)) (equal x 0)) 0)
((< x 0) (expo (- x)))
((< x 1) (1- (expo (* 2 x))))
((< x 2) 0)
(t (1+ (expo (/ x 2))))))
;could redefine to divide by the power of 2 (instead of making it a negative power of 2)...
(defund sig (x)
(declare (xargs :guard t))
(if (rationalp x)
(if (< x 0)
(- (* x (expt 2 (- (expo x)))))
(* x (expt 2 (- (expo x)))))
0))
;make defund?
(defun sgn (x)
(declare (xargs :guard t))
(if (or (not (rationalp x)) (equal x 0))
0
(if (< x 0)
-1
1)))
(defund exactp (x n)
; (declare (xargs :guard (and (real/rationalp x) (integerp n))))
(integerp (* (sig x) (expt 2 (1- n)))))
(defund trunc (x n)
(declare (xargs :guard (integerp n)))
(* (sgn x) (fl (* (expt 2 (1- n)) (sig x))) (expt 2 (- (1+ (expo x)) n))))
(defund away (x n)
(* (sgn x) (cg (* (expt 2 (1- n)) (sig x))) (expt 2 (- (1+ (expo x)) n))))
(defund re (x)
(- x (fl x)))
(defund near (x n)
(let ((z (fl (* (expt 2 (1- n)) (sig x))))
(f (re (* (expt 2 (1- n)) (sig x)))))
(if (< f 1/2)
(trunc x n)
(if (> f 1/2)
(away x n)
(if (evenp z)
(trunc x n)
(away x n))))))
;;
;; New stuff:
;;
(defund oddr (x n)
(let ((z (fl (* (expt 2 (1- n)) (sig x)))))
(if (evenp z)
(* (sgn x) (1+ z) (expt 2 (- (1+ (expo x)) n)))
(* (sgn x) z (expt 2 (- (1+ (expo x)) n))))))
(defthm oddr-pos
(implies (and (< 0 x)
(rationalp x)
(integerp n)
(> n 0))
(< 0 (oddr x n)))
:rule-classes ())
(defthm oddr>=trunc
(implies (and (rationalp x)
(> x 0)
(integerp n)
(> n 0))
(>= (oddr x n) (trunc x n)))
:rule-classes ())
;BOZO just opens up ODDR when x is positive
;leave disabled!
(defthmd oddr-rewrite
(implies (and (< 0 x) ;note this hyp
(rationalp x)
(integerp n)
(< 0 n))
(equal (oddr x n)
(let ((z (fl (* (expt 2 (- (1- n) (expo x))) x))))
(if (evenp z)
(* (1+ z) (expt 2 (- (1+ (expo x)) n)))
(* z (expt 2 (- (1+ (expo x)) n))))))))
;move!
(defthm fl/2
(implies (integerp z)
(= (fl (/ z 2))
(if (evenp z)
(/ z 2)
(/ (1- z) 2))))
:rule-classes ())
(defthm oddr-other
(implies (and (rationalp x)
(> x 0)
(integerp n)
(> n 1))
(= (oddr x n)
(+ (trunc x (1- n))
(expt 2 (- (1+ (expo x)) n)))))
:rule-classes ())
(defthm expo-oddr
(implies (and (rationalp x)
(integerp n)
(> x 0)
(> n 1))
(equal (expo (oddr x n)) (expo x))))
(defthm exactp-oddr
(implies (and (rationalp x)
(integerp n)
(> x 0)
(> n 1))
(exactp (oddr x n) n))
:rule-classes ())
(defthm not-exactp-oddr
(implies (and (rationalp x)
(integerp n)
(> x 0)
(> n 1))
(not (exactp (oddr x n) (1- n))))
:rule-classes ())
(defthm trunc-oddr
(implies (and (rationalp x)
(> x 0)
(integerp n)
(integerp m)
(> m 0)
(> n m))
(= (trunc (oddr x n) m)
(trunc x m)))
:rule-classes ())
;disable?
(defun kp (k x y)
(+ k (- (expo (+ x y)) (expo y))))
(defthm oddr-plus
(implies (and (rationalp x)
(rationalp y)
(integerp k)
(> x 0)
(> y 0)
(> k 1)
(> (+ (1- k) (- (expo x) (expo y))) 0)
(exactp x (+ (1- k) (- (expo x) (expo y)))))
(= (+ x (oddr y k))
(oddr (+ x y) (kp k x y))))
:rule-classes ())
(defthm trunc-trunc-oddr
(implies (and (rationalp x)
(rationalp y)
(integerp m)
(integerp k)
(> x y)
(> y 0)
(> k 0)
(>= (- m 2) k))
(>= (trunc x k) (trunc (oddr y m) k)))
:rule-classes ())
(defthm away-away-oddr
(implies (and (rationalp x)
(rationalp y)
(integerp m)
(integerp k)
(> x y)
(> y 0)
(> k 0)
(>= (- m 2) k))
(>= (away x k) (away (oddr y m) k)))
:rule-classes ())
(defthm near-near-oddr
(implies (and (rationalp x)
(rationalp y)
(integerp m)
(integerp k)
(> x y)
(> y 0)
(> k 0)
(>= (- m 2) k))
(>= (near x k) (near (oddr y m) k)))
:rule-classes ())
|