Floating-Point Decomposition
Function:
(defun sgn (x) (declare (xargs :guard t)) (if (or (not (rationalp x)) (equal x 0)) 0 (if (< x 0) -1 1)))
Function:
(defun expo (x) (declare (xargs :guard t)) (mbe :logic (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))))) :exec (if (rationalp x) (let* ((n (abs (numerator x))) (d (denominator x)) (ln (integer-length n)) (ld (integer-length d)) (l (- ln ld))) (if (>= ln ld) (if (>= (ash n (- l)) d) l (1- l)) (if (> ln 1) (if (> n (ash d l)) l (1- l)) (- (integer-length (1- d)))))) 0)))
Function:
(defun sig (x) (declare (xargs :guard t)) (if (rationalp x) (if (< x 0) (- (* x (expt 2 (- (expo x))))) (* x (expt 2 (- (expo x))))) 0))
Theorem:
(defthm expo-minus (implies (rationalp x) (equal (expo (- x)) (expo x))))
Theorem:
(defthm sig-minus (implies (rationalp x) (equal (sig (- x)) (sig x))))
Theorem:
(defthm expo-lower-bound (implies (and (rationalp x) (not (equal x 0))) (<= (expt 2 (expo x)) (abs x))) :rule-classes :linear)
Theorem:
(defthm expo-upper-bound (implies (and (rationalp x)) (< (abs x) (expt 2 (1+ (expo x))))) :rule-classes :linear)
Theorem:
(defthm expo-unique (implies (and (<= (expt 2 n) (abs x)) (< (abs x) (expt 2 (1+ n))) (rationalp x) (integerp n)) (equal n (expo x))) :rule-classes nil)
Theorem:
(defthm fp-rep (implies (rationalp x) (equal x (* (sgn x) (sig x) (expt 2 (expo x))))) :rule-classes nil)
Theorem:
(defthm fp-abs (implies (rationalp x) (equal (abs x) (* (sig x) (expt 2 (expo x))))) :rule-classes nil)
Theorem:
(defthm expo>= (implies (and (<= (expt 2 n) x) (rationalp x) (integerp n)) (<= n (expo x))) :rule-classes :linear)
Theorem:
(defthm expo<= (implies (and (< x (* 2 (expt 2 n))) (< 0 x) (rationalp x) (integerp n)) (<= (expo x) n)) :rule-classes :linear)
Theorem:
(defthm expo-2**n (implies (integerp n) (equal (expo (expt 2 n)) n)))
Theorem:
(defthm bitn-expo (implies (not (zp x)) (equal (bitn x (expo x)) 1)))
Theorem:
(defthm expo-monotone (implies (and (<= (abs x) (abs y)) (case-split (rationalp x)) (case-split (not (equal x 0))) (case-split (rationalp y))) (<= (expo x) (expo y))) :rule-classes :linear)
Theorem:
(defthm bvecp-expo (implies (case-split (natp x)) (bvecp x (1+ (expo x)))))
Theorem:
(defthm mod-expo (implies (and (< 0 x) (rationalp x)) (equal (mod x (expt 2 (expo x))) (- x (expt 2 (expo x))))))
Theorem:
(defthm sig-lower-bound (implies (and (rationalp x) (not (equal x 0))) (<= 1 (sig x))) :rule-classes (:rewrite :linear))
Theorem:
(defthm sig-upper-bound (< (sig x) 2) :rule-classes (:rewrite :linear))
Theorem:
(defthm expo-sig (implies (rationalp x) (equal (expo (sig x)) 0)))
Theorem:
(defthm sig-self (implies (and (rationalp x) (<= 1 x) (< x 2)) (equal (sig x) x)))
Theorem:
(defthm sig-sig (equal (sig (sig x)) (sig x)))
Theorem:
(defthm fp-rep-unique (implies (and (rationalp x) (rationalp m) (<= 1 m) (< m 2) (integerp e) (= (abs x) (* m (expt 2 e)))) (and (= m (sig x)) (= e (expo x)))) :rule-classes nil)
Theorem:
(defthm sgn-shift (equal (sgn (* x (expt 2 k))) (sgn x)))
Theorem:
(defthm expo-shift (implies (and (rationalp x) (not (equal x 0)) (integerp n)) (equal (expo (* (expt 2 n) x)) (+ n (expo x)))))
Theorem:
(defthm sig-shift (equal (sig (* (expt 2 n) x)) (sig x)))
Theorem:
(defthm sgn-prod (implies (and (case-split (rationalp x)) (case-split (rationalp y))) (equal (sgn (* x y)) (* (sgn x) (sgn y)))))
Theorem:
(defthm expo-prod (implies (and (rationalp x) (not (= x 0)) (rationalp y) (not (= y 0))) (equal (expo (* x y)) (if (< (* (sig x) (sig y)) 2) (+ (expo x) (expo y)) (+ 1 (expo x) (expo y))))))
Theorem:
(defthm expo-prod-lower (implies (and (rationalp x) (not (= x 0)) (rationalp y) (not (= y 0))) (<= (+ (expo x) (expo y)) (expo (* x y)))) :rule-classes :linear)
Theorem:
(defthm expo-prod-upper (implies (and (rationalp x) (not (= x 0)) (rationalp y) (not (= y 0))) (>= (+ (expo x) (expo y) 1) (expo (* x y)))) :rule-classes :linear)
Theorem:
(defthm sig-prod (implies (and (rationalp x) (not (= x 0)) (rationalp y) (not (= y 0))) (equal (sig (* x y)) (if (< (* (sig x) (sig y)) 2) (* (sig x) (sig y)) (* 1/2 (sig x) (sig y))))))
Theorem:
(defthm expo-fl (implies (and (rationalp x) (>= x 1)) (equal (expo (fl x)) (expo x))))
Theorem:
(defthm expo-logior (implies (and (natp x) (natp y) (<= (expo x) (expo y))) (equal (expo (logior x y)) (expo y))))