3
; Eric Smith, David Russinoff, with contributions and suggestions by Matt Kaufmann
5
;this file was previously called repsproofs.lisp
8
(include-book "float") ;to get the defns...
10
(local (include-book "ereps-proofs"))
12
(set-inhibit-warnings "theory") ; avoid warning in the next event
13
(local (in-theory nil))
14
;(set-inhibit-warnings) ; restore theory warnings (optional)
17
; bias of a q bit exponent field is 2^(q-1)-1
18
(defund bias (q) (- (expt 2 (- q 1)) 1) )
20
;;Encoding of floating-point numbers with explicit leading one:
21
;;bit vectors of length p+q+1, consisting of 1-bit sign field,
22
;;q-bit exponent field (bias = 2**(q-1)-1), and p-bit significand field.
24
(defund esgnf (x p q) (bitn x (+ p q)))
25
(defund eexpof (x p q) (bits x (1- (+ p q)) p))
26
(defund esigf (x p) (bits x (1- p) 0))
28
;;;**********************************************************************
29
;;; REPRESENTABLE NUMBERS
30
;;;**********************************************************************
35
(bvecp (+ (expo x) (bias q)) q)
39
;;;**********************************************************************
41
;;;**********************************************************************
43
(defund eencodingp (x p q)
44
(and (bvecp x (+ p q 1))
45
(= (bitn x (- p 1)) 1)))
48
;;;**********************************************************************
50
;;;**********************************************************************
54
; sig, expo, and sgn are defined in float.lisp
58
(defund eencode (x p q)
59
(cat (cat (if (= (sgn x) 1) 0 1)
64
(* (sig x) (expt 2 (- p 1)))
70
;;;**********************************************************************
72
;;;**********************************************************************
75
(defund edecode (x p q)
76
(* (if (= (esgnf x p q) 0) 1 -1)
78
(expt 2 (+ 1 (- p) (eexpof x p q) (- (bias q))))))
82
;;;**********************************************************************
83
;;; Encoding and Decoding are Inverses
84
;;;**********************************************************************
87
(implies (and (eencodingp x p q)
92
(erepp (edecode x p q) p q)))
95
(defthm eencodingp-eencode
96
(implies (and (erepp x p q)
101
(eencodingp (eencode x p q) p q) ))
103
(defthm edecode-eencode
104
(implies (and (erepp x p q)
110
(equal (edecode (eencode x p q) p q)
113
(defthm eencode-edecode
114
(implies (and (eencodingp x p q)
119
(equal (eencode (edecode x p q) p q)
123
(implies (and (eencodingp x p q)
128
(equal (expo (edecode x p q))
129
(- (eexpof x p q) (bias q))
133
(implies (and (eencodingp x p q)
138
(equal (sgn (edecode x p q))
139
(if (= (esgnf x p q) 0) 1 -1))))
142
(implies (and (eencodingp x p q)
147
(equal (sig (edecode x p q))
148
(/ (esigf x p) (expt 2 (- p 1))))))
150
(defthm eencodingp-not-zero
151
(implies (and (eencodingp x p q)
156
(not (equal (edecode x p q) 0))))
158
(defund rebias-expo (expo old new)
159
(+ expo (- (bias new) (bias old))))
161
;;I actually needed all four of the following lemmas, although I would have thought
162
;;that the two bvecp lemmas would be enough.
164
(defthm natp-rebias-up
165
(implies (and (natp n)
170
(natp (rebias-expo x m n)))
171
:hints (("goal" :in-theory (e/d ( expt-split rebias-expo bvecp natp bias
173
:use (:instance expt-weak-monotone (n m) (m n)))))
175
(defthm natp-rebias-down
176
(implies (and (natp n)
181
(< x (+ (expt 2 (1- n)) (expt 2 (1- m))))
182
(>= x (- (expt 2 (1- n)) (expt 2 (1- m)))))
183
(natp (rebias-expo x n m)))
184
:hints (("goal" :in-theory (enable rebias-expo bvecp natp bias))))
186
(defthm bvecp-rebias-up
187
(implies (and (natp n)
192
(bvecp (rebias-expo x m n) n)))
194
(defthm bvecp-rebias-down
195
(implies (and (natp n)
200
(< x (+ (expt 2 (1- n)) (expt 2 (1- m))))
201
(>= x (- (expt 2 (1- n)) (expt 2 (1- m)))))
202
(bvecp (rebias-expo x n m) m)))
205
(implies (and (natp n)
210
(equal (rebias-expo x m n)
211
(cat (cat (bitn x (1- m))
213
(mulcat 1 (- n m) (lnot (bitn x (1- m)) 1))
221
(implies (and (natp n)
226
(< x (+ (expt 2 (1- n)) (expt 2 (1- m))))
227
(>= x (- (expt 2 (1- n)) (expt 2 (1- m)))))
228
(equal (rebias-expo x n m)