1
;;;**************************************************************
2
;;;An ACL2 Library of Floating Point Arithmetic
5
;;;Advanced Micro Devices, Inc.
7
;;;***************************************************************
10
;This book includes theorems mixing the logical operators (logand, etc.) with bits and bitn.
12
(include-book "ground-zero")
14
(local (include-book "log-proofs"))
17
(declare (xargs :guard (real/rationalp x)))
21
(declare (xargs :guard (and (natp x)
25
(mbe :logic (if (or (not (integerp i))
28
(fl (/ (mod x (expt 2 (1+ i))) (expt 2 j))))
31
(logand (ash x (- j)) (1- (ash 1 (1+ (- i j))))))))
34
(declare (xargs :guard (and (natp x)
37
(mbe :logic (bits x n n)
38
:exec (if (evenp (ash x (- n))) 0 1)))
41
(declare (xargs :guard t))
46
(declare (xargs :guard (integerp k)))
52
(include-book "logand")
53
(include-book "logior")
54
(include-book "logxor")
57
;rename! mod-lognot-by-2
60
(iff (= (mod (lognot i) 2) 0)
61
(not (= (mod i 2) 0)))))
65
(implies (and (integerp i)
67
(iff (and (= (mod i 2) 0) (= (mod j 2) 0))
68
(= (mod (logior i j) 2) 0)))
70
:hints (("Goal" :use mod-logior-by-2
71
:in-theory (set-difference-theories
78
(implies (and (integerp x)
84
(equal (logior x (logand y z))
85
(logand (logior x y) (logior x z))))
89
(defthm logior-logand-alt
90
(implies (and (integerp x)
96
(equal (logior (logand y z) x)
97
(logand (logior x y) (logior x z))))
100
(defthm logand-logior
101
(implies (and (integerp x) (<= 0 x)
102
(integerp y) (<= 0 y)
103
(integerp z) (<= 0 z))
104
(equal (logand x (logior y z))
105
(logior (logand x y) (logand x z))))
108
(defthm logand-logior-alt
109
(implies (and (integerp x) (>= x 0)
110
(integerp y) (>= y 0)
111
(integerp z) (>= z 0))
112
(equal (logand (logior y z) x)
113
(logior (logand y x) (logand z x))))
116
(defthm mod-logand-aux
117
(implies (and (integerp x) (>= x 0)
118
(integerp y) (>= y 0)
119
(integerp n) (>= n 0))
120
(= (mod (logand x y) (expt 2 n))
121
(logand (mod x (expt 2 n)) y)))
124
;generalize (mod y (expt 2 n)) to anything < 2^n?
126
(implies (and (integerp x) (>= x 0)
127
(integerp y) (>= y 0)
128
(integerp n) (>= n 0)
131
(logand x (mod y (expt 2 n)))))
134
;compare to mod-logand-aux
135
;we can wrap the mod around x or y or both (same for bits of logand?)
137
(implies (and (integerp x) (>= x 0)
138
(integerp y) (>= y 0)
139
(integerp n) (>= n 0))
140
(equal (mod (logand x y) (expt 2 n))
141
(logand (mod x (expt 2 n)) (mod y (expt 2 n))))))
143
;prove that we can wrap the bits around either arg in the conclusion or both...
144
;will have to shift if we don't wrap bits??
146
(implies (and ;(<= i j)
147
(case-split (natp x)) ;drop?
148
(case-split (natp y)) ;drop?
149
(case-split (natp i))
150
(case-split (natp j))
152
(equal (bits (logand x y) i j)
153
(logand (bits x i j) (bits y i j)))))
156
(implies (and (integerp x) ; (>= x 0)
157
(integerp y) ; (>= y 0)
158
(integerp n) (>= n 0)
160
(equal (bitn (logand x y) n)
161
(logand (bitn x n) (bitn y n)))))
164
(implies (and ;(>= i j)
165
(case-split (natp x))
166
(case-split (natp y))
167
(case-split (natp i))
168
(case-split (natp j))
170
(equal (bits (logior x y) i j)
171
(logior (bits x i j) (bits y i j)))))
173
;someday prove from bits-logior (will have to generalize bits-logior?)?
175
(implies (and (integerp x)
179
(equal (bitn (logior x y) n)
180
(logior (bitn x n) (bitn y n)))))
182
;give better name, perhaps "logand-with-power2" ?
184
(implies (and (integerp x) (>= x 0)
185
(integerp k) (>= k 0))
186
(= (logand x (expt 2 k))
187
(* (expt 2 k) (bitn x k))))
191
(implies (and (integerp x) (>= x 0)
192
(integerp k) (>= k 0))
193
(= (logior x (expt 2 k))
200
(implies (and (integerp x) (>= x 0)
201
(integerp n) (>= n 0)
202
(integerp k) (>= k 0)
204
(= (logand x (- (expt 2 n) (expt 2 k)))
205
(* (expt 2 k) (bits x (1- n) k))))
208
;move to logxor.lisp?
209
(defthmd logxor-rewrite
210
(implies (and (< x (expt 2 n))
212
(integerp n) (>= n 1) ;gen?
213
(integerp x) (>= x 0)
214
(integerp y) (>= y 0))
216
(logior (logand x (lnot y n))
217
(logand y (lnot x n))))))
220
(defthmd logxor-rewrite-2
221
;; ! Do we really want to get rid of logxor?
222
(implies (and (bvecp x n)
227
(logior (logand x (lnot y n))
228
(logand y (lnot x n)))))
229
:rule-classes ((:rewrite :match-free :all)))
232
(implies (and (case-split (integerp x))
233
(case-split (integerp y))
234
(case-split (integerp n))
235
(case-split (>= n 0))
237
(equal (bitn (logxor x y) n)
238
(logxor (bitn x n) (bitn y n)))))
243
(implies (and (case-split (natp x))
244
(case-split (natp y))
245
(case-split (natp i))
246
(case-split (natp j))
249
(equal (bits (logxor x y) i j)
250
(logxor (bits x i j) (bits y i j))))
251
:hints (("Goal" :in-theory (set-difference-theories
252
(enable bvecp natp expt-split)
254
:use ((:instance hack1 (x (+ i x y)))
255
(:instance bits-logxor-aux (n (+ i x y)))))))