Normal Encodings
Function:
(defun normp (x f) (declare (xargs :guard (encodingp x f))) (and (mbt (encodingp x f)) (< 0 (expf x f)) (< (expf x f) (1- (expt 2 (expw f)))) (implies (explicitp f) (= (bitn x (1- (prec f))) 1))))
Function:
(defun unsupp (x f) (declare (xargs :guard (encodingp x f))) (and (mbt (encodingp x f)) (explicitp f) (< 0 (expf x f)) (= (bitn x (1- (prec f))) 0)))
Function:
(defun ndecode (x f) (declare (xargs :guard (encodingp x f))) (* (if (= (sgnf x f) 0) 1 -1) (expt 2 (- (expf x f) (bias f))) (1+ (* (manf x f) (expt 2 (- 1 (prec f)))))))
Theorem:
(defthm sgn-ndecode (implies (normp x f) (equal (sgn (ndecode x f)) (if (= (sgnf x f) 0) 1 -1))))
Theorem:
(defthm expo-ndecode (implies (normp x f) (equal (expo (ndecode x f)) (- (expf x f) (bias f)))))
Theorem:
(defthm sig-ndecode (implies (normp x f) (equal (sig (ndecode x f)) (+ 1 (/ (manf x f) (expt 2 (1- (prec f))))))))
Function:
(defun nrepp (x f) (declare (xargs :guard t)) (and (rationalp x) (formatp f) (not (= x 0)) (< 0 (+ (expo x) (bias f))) (< (+ (expo x) (bias f)) (1- (expt 2 (expw f)))) (exactp x (prec f))))
Function:
(defun nencode (x f) (declare (xargs :guard (and (rationalp x) (formatp f) (exactp x (prec f))))) (cat (if (= (sgn x) 1) 0 1) 1 (+ (expo x) (bias f)) (expw f) (* (sig x) (expt 2 (1- (prec f)))) (sigw f)))
Theorem:
(defthm nrepp-ndecode (implies (normp x f) (nrepp (ndecode x f) f)))
Theorem:
(defthm nencode-ndecode (implies (normp x f) (equal (nencode (ndecode x f) f) x)))
Theorem:
(defthm normp-nencode (implies (nrepp x f) (normp (nencode x f) f)))
Theorem:
(defthm ndecode-nencode (implies (nrepp x f) (equal (ndecode (nencode x f) f) x)))
Function:
(defun spn (f) (declare (xargs :guard (formatp f))) (expt 2 (- 1 (bias f))))
Theorem:
(defthm positive-spn (> (spn f) 0) :rule-classes (:linear))
Theorem:
(defthm expo-spn (implies (formatp f) (equal (expo (spn f)) (- 1 (bias f)))))
Theorem:
(defthm nrepp-spn (implies (formatp f) (nrepp (spn f) f)))
Theorem:
(defthm smallest-spn (implies (nrepp x f) (>= (abs x) (spn f))) :rule-classes ((:rewrite :match-free :once)))
Function:
(defun lpn (f) (declare (xargs :guard (formatp f))) (* (expt 2 (- (expt 2 (expw f)) (+ 2 (bias f)))) (- 2 (expt 2 (- 1 (prec f))))))
Theorem:
(defthm positive-lpn (implies (formatp f) (> (lpn f) 0)) :rule-classes (:linear))
Theorem:
(defthm expo-lpn (implies (formatp f) (equal (expo (lpn f)) (- (expt 2 (expw f)) (+ 2 (bias f))))))
Theorem:
(defthm sig-lpn (implies (formatp f) (equal (sig (lpn f)) (- 2 (expt 2 (- 1 (prec f)))))))
Theorem:
(defthm nrepp-lpn (implies (formatp f) (nrepp (lpn f) f)))
Theorem:
(defthm largest-lpn (implies (nrepp x f) (<= x (lpn f))) :rule-classes ((:rewrite :match-free :once)))