Rebiasing Exponents
Function:
(defun rebias (expo old new) (declare (xargs :guard (and (integerp expo) (posp old) (posp new)))) (+ expo (- (expt 2 (1- new)) (expt 2 (1- old)))))
Theorem:
(defthm natp-rebias-up (implies (and (natp n) (natp m) (< 0 m) (<= m n) (bvecp x m)) (natp (rebias x m n))))
Theorem:
(defthm natp-rebias-down (implies (and (natp n) (natp m) (< 0 m) (<= m n) (bvecp x n) (< x (+ (expt 2 (1- n)) (expt 2 (1- m)))) (>= x (- (expt 2 (1- n)) (expt 2 (1- m))))) (natp (rebias x n m))))
Theorem:
(defthm bvecp-rebias-up (implies (and (natp n) (natp m) (< 0 m) (<= m n) (bvecp x m)) (bvecp (rebias x m n) n)))
Theorem:
(defthm bvecp-rebias-down (implies (and (natp n) (natp m) (< 0 m) (<= m n) (bvecp x n) (< x (+ (expt 2 (1- n)) (expt 2 (1- m)))) (>= x (- (expt 2 (1- n)) (expt 2 (1- m))))) (bvecp (rebias x n m) m)))
Theorem:
(defthm rebias-lower (implies (and (natp n) (natp m) (> n m) (> m 1) (bvecp x n) (< x (+ (expt 2 (1- n)) (expt 2 (1- m)))) (>= x (- (expt 2 (1- n)) (expt 2 (1- m))))) (equal (rebias x n m) (cat (bitn x (1- n)) 1 (bits x (- m 2) 0) (1- m)))))
Theorem:
(defthm rebias-higher (implies (and (natp n) (natp m) (> n m) (> m 1) (bvecp x m)) (equal (rebias x m n) (cat (cat (bitn x (1- m)) 1 (mulcat 1 (- n m) (bitn (lognot x) (1- m))) (- n m)) (1+ (- n m)) (bits x (- m 2) 0) (1- m)))))