Denormals and Zeroes
Function:
(defun zerp (x f) (declare (xargs :guard (encodingp x f))) (and (mbt (encodingp x f)) (= (expf x f) 0) (= (sigf x f) 0)))
Function:
(defun zencode (sgn f) (declare (xargs :guard (and (bvecp sgn 1) (formatp f)))) (cat sgn 1 0 (+ (sigw f) (expw f))))
Function:
(defun denormp (x f) (declare (xargs :guard (encodingp x f))) (and (mbt (encodingp x f)) (= (expf x f) 0) (not (= (sigf x f) 0)) (implies (explicitp f) (= (bitn x (1- (prec f))) 0))))
Function:
(defun pseudop (x f) (declare (xargs :guard (encodingp x f))) (and (mbt (encodingp x f)) (explicitp f) (= (expf x f) 0) (= (bitn x (1- (prec f))) 1)))
Function:
(defun ddecode (x f) (declare (xargs :guard (encodingp x f))) (* (if (= (sgnf x f) 0) 1 -1) (sigf x f) (expt 2 (+ 2 (- (bias f)) (- (prec f))))))
Function:
(defun decode (x f) (declare (xargs :guard (encodingp x f))) (if (= (expf x f) 0) (ddecode x f) (ndecode x f)))
Theorem:
(defthm sgn-ddecode (implies (or (denormp x f) (pseudop x f)) (equal (sgn (ddecode x f)) (if (= (sgnf x f) 0) 1 -1))))
Theorem:
(defthm expo-ddecode (implies (or (denormp x f) (pseudop x f)) (equal (expo (ddecode x f)) (+ 2 (- (prec f)) (- (bias f)) (expo (sigf x f))))))
Theorem:
(defthm sig-ddecode (implies (or (denormp x f) (pseudop x f)) (equal (sig (ddecode x f)) (sig (sigf x f)))))
Function:
(defun drepp (x f) (declare (xargs :guard t)) (and (rationalp x) (formatp f) (not (= x 0)) (<= (- 2 (prec f)) (+ (expo x) (bias f))) (<= (+ (expo x) (bias f)) 0) (exactp x (+ (1- (prec f)) (bias f) (expo x)))))
Theorem:
(defthm drepp-exactp (implies (drepp x f) (exactp x (prec f))))
Function:
(defun dencode (x f) (declare (xargs :guard (drepp x f))) (cat (if (= (sgn x) 1) 0 1) 1 0 (expw f) (* (sig x) (expt 2 (+ -2 (prec f) (expo x) (bias f)))) (sigw f)))
Theorem:
(defthm drepp-ddecode (implies (denormp x f) (drepp (ddecode x f) f)))
Theorem:
(defthm dencode-ddecode (implies (denormp x f) (equal (dencode (ddecode x f) f) x)))
Theorem:
(defthm denormp-dencode (implies (drepp x f) (denormp (dencode x f) f)))
Theorem:
(defthm ddecode-dencode (implies (drepp x f) (equal (ddecode (dencode x f) f) x)))
Theorem:
(defthm drepp<spn (implies (drepp x f) (< (abs x) (spn f))))
Function:
(defun spd (f) (declare (xargs :guard (formatp f))) (expt 2 (+ 2 (- (bias f)) (- (prec f)))))
Theorem:
(defthm positive-spd (implies (formatp f) (> (spd f) 0)) :rule-classes :linear)
Theorem:
(defthm drepp-spd (implies (formatp f) (drepp (spd f) f)))
Theorem:
(defthm smallest-spd (implies (drepp r f) (>= (abs r) (spd f))))
Theorem:
(defthm spd-mult (implies (and (formatp f) (> r 0) (= m (/ r (spd f)))) (iff (drepp r f) (and (natp m) (<= 1 m) (< m (expt 2 (1- (prec f))))))))