1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
|
; RTL - A Formal Theory of Register-Transfer Logic and Computer Arithmetic
;
; Contact:
; David M. Russinoff
; 1106 W 9th St., Austin, TX 78703
; david@russinoff.com
; http://www.russinoff.com/
;
; See license file books/rtl/rel11/license.txt.
;
(in-package "RTL")
(set-enforce-redundancy t) ; for some reason, acl2 4.3 complains about logand-natp
(local (include-book "../support/top"))
(set-inhibit-warnings "theory") ; avoid warning in the next event
(local (in-theory nil))
(include-book "defs")
;;;**********************************************************************
;;; LOGAND, LOGIOR, and LOGXOR
;;;**********************************************************************
(defsection-rtl |Binary Operations| |Logical Operations|
(in-theory (disable logand logior logxor))
(defthmd logand-def
(equal (logand x y)
(if (or (zip x) (zip y))
0
(if (= x y)
x
(+ (* 2 (logand (fl (/ x 2)) (fl (/ y 2))))
(logand (mod x 2) (mod y 2))))))
:rule-classes ((:definition :controller-alist ((binary-logand t t)))))
(defthmd logior-def
(implies (and (integerp x) (integerp y))
(equal (logior x y)
(if (or (zip x) (= x y))
y
(if (zip y)
x
(+ (* 2 (logior (fl (/ x 2)) (fl (/ y 2))))
(logior (mod x 2) (mod y 2)))))))
:rule-classes ((:definition :controller-alist ((binary-logior t t)))))
(defthmd logxor-def
(implies (and (integerp x) (integerp y))
(equal (logxor x y)
(if (zip x)
y
(if (zip y)
x
(if (= x y)
0
(+ (* 2 (logxor (fl (/ x 2)) (fl (/ y 2))))
(logxor (mod x 2) (mod y 2))))))))
:rule-classes ((:definition :controller-alist ((binary-logxor t t)))))
(defun log-induct (x y)
(declare (xargs :measure (abs (* (ifix x) (ifix y)))))
(if (or (not (integerp x)) (not (integerp y)) (= x 0) (= y 0) (= x y))
(+ x y)
(log-induct (fl (/ x 2)) (fl (/ y 2)))))
(defthm logand-bvecp
(implies (and (natp n)
(bvecp x n)
(integerp y))
(bvecp (logand x y) n)))
(defthm logior-bvecp
(implies (and (bvecp x n)
(bvecp y n))
(bvecp (logior x y) n)))
(defthm logxor-bvecp
(implies (and (bvecp x n)
(bvecp y n)
(natp n))
(bvecp (logxor x y) n)))
(defthmd logand-plus-logxor
(implies (and (integerp x)
(integerp y))
(equal (+ (logand x y) (logxor x y))
(logior x y))))
(defthmd logand-mod
(implies (and (integerp x)
(integerp y)
(integerp n))
(equal (mod (logand x y) (expt 2 n))
(logand (mod x (expt 2 n))
(mod y (expt 2 n))))))
(defthmd logior-mod
(implies (and (integerp x)
(integerp y)
(integerp n))
(equal (mod (logior x y) (expt 2 n))
(logior (mod x (expt 2 n))
(mod y (expt 2 n))))))
(defthmd logxor-mod
(implies (and (integerp x)
(integerp y)
(integerp n))
(equal (mod (logxor x y) (expt 2 n))
(logxor (mod x (expt 2 n))
(mod y (expt 2 n))))))
(defthmd fl-logand
(implies (and (integerp x)
(integerp y)
(natp n))
(equal (fl (* (expt 2 (- n)) (logand x y)))
(logand (fl (* (expt 2 (- n)) x)) (fl (* (expt 2 (- n)) y))))))
(defthmd fl-logior
(implies (and (integerp x)
(integerp y)
(natp n))
(equal (fl (* (expt 2 (- n)) (logior x y)))
(logior (fl (* (expt 2 (- n)) x)) (fl (* (expt 2 (- n)) y))))))
(defthmd fl-logxor
(implies (and (integerp x)
(integerp y)
(natp n))
(equal (fl (* (expt 2 (- n)) (logxor x y)))
(logxor (fl (* (expt 2 (- n)) x)) (fl (* (expt 2 (- n)) y))))))
(defthmd logand-cat
(implies (and (case-split (integerp x1))
(case-split (integerp y1))
(case-split (integerp x2))
(case-split (integerp y2))
(case-split (natp n))
(case-split (natp m)))
(equal (logand (cat x1 m y1 n) (cat x2 m y2 n))
(cat (logand x1 x2) m (logand y1 y2) n))))
(defthmd logior-cat
(implies (and (case-split (integerp x1))
(case-split (integerp y1))
(case-split (integerp x2))
(case-split (integerp y2))
(case-split (natp n))
(case-split (natp m)))
(equal (logior (cat x1 m y1 n) (cat x2 m y2 n))
(cat (logior x1 x2) m (logior y1 y2) n))))
(defthmd logxor-cat
(implies (and (case-split (integerp x1))
(case-split (integerp y1))
(case-split (integerp x2))
(case-split (integerp y2))
(case-split (natp n))
(case-split (natp m)))
(equal (logxor (cat x1 m y1 n) (cat x2 m y2 n))
(cat (logxor x1 x2) m (logxor y1 y2) n))))
(defthmd logand-shift
(implies (and (integerp x)
(integerp y)
(natp k))
(equal (logand (* (expt 2 k) x)
(* (expt 2 k) y))
(* (expt 2 k) (logand x y)))))
(defthmd logior-shift
(implies (and (integerp x)
(integerp y)
(natp k))
(equal (logior (* (expt 2 k) x)
(* (expt 2 k) y))
(* (expt 2 k) (logior x y)))))
(defthmd logxor-shift
(implies (and (integerp x)
(integerp y)
(natp k))
(equal (logxor (* (expt 2 k) x)
(* (expt 2 k) y))
(* (expt 2 k) (logxor x y)))))
(defthmd logand-expt
(implies (and (integerp x)
(integerp y)
(natp n))
(equal (logand (* (expt 2 n) x) y)
(* (expt 2 n) (logand x (fl (/ y (expt 2 n))))))))
(defthmd logior-expt
(implies (and (integerp x)
(integerp y)
(natp n))
(equal (logior (* (expt 2 n) x) y)
(+ (* (expt 2 n) (logior x (fl (/ y (expt 2 n)))))
(mod y (expt 2 n))))))
(defthmd logxor-expt
(implies (and (integerp x)
(integerp y)
(natp n))
(equal (logxor (* (expt 2 n) x) y)
(+ (* (expt 2 n) (logxor x (fl (/ y (expt 2 n)))))
(mod y (expt 2 n))))))
(defthmd logior-expt-cor
(implies (and (natp n)
(integerp x)
(bvecp y n))
(equal (logior (* (expt 2 n) x) y)
(+ (* (expt 2 n) x) y))))
(defthmd logior-2**n
(implies (and (natp n)
(integerp x))
(equal (logior (expt 2 n) x)
(if (= (bitn x n) 1)
x
(+ x (expt 2 n))))))
(defthmd logand-bits
(implies (and (integerp x)
(natp n)
(natp k)
(< k n))
(equal (logand x (- (expt 2 n) (expt 2 k)))
(* (expt 2 k) (bits x (1- n) k)))))
(defthmd logand-bit
(implies (and (integerp x)
(natp n))
(equal (logand x (expt 2 n))
(* (expt 2 n) (bitn x n)))))
(defthmd bits-logand
(implies (and (integerp x)
(integerp y)
(integerp i)
(integerp j))
(equal (bits (logand x y) i j)
(logand (bits x i j) (bits y i j)))))
(defthmd bits-logior
(implies (and (integerp x)
(integerp y)
(integerp i)
(integerp j))
(equal (bits (logior x y) i j)
(logior (bits x i j) (bits y i j)))))
(defthmd bits-logxor
(implies (and (integerp x)
(integerp y)
(integerp i)
(integerp j))
(equal (bits (logxor x y) i j)
(logxor (bits x i j) (bits y i j)))))
(defthmd bitn-logand
(implies (and (integerp x)
(integerp y)
(integerp n))
(equal (bitn (logand x y) n)
(logand (bitn x n) (bitn y n)))))
(defthmd bitn-logior
(implies (and (integerp x)
(integerp y)
(integerp n))
(equal (bitn (logior x y) n)
(logior (bitn x n) (bitn y n)))))
(defthmd bitn-logxor
(implies (and (case-split (integerp x))
(case-split (integerp y))
(case-split (integerp n)))
(equal (bitn (logxor x y) n)
(logxor (bitn x n) (bitn y n)))))
)
;;;**********************************************************************
;;; LOGNOT
;;;**********************************************************************
(defsection-rtl |Complementation| |Logical Operations|
(in-theory (disable lognot))
(defthmd lognot-def
(implies (integerp x)
(equal (lognot x)
(1- (- x)))))
(defthmd lognot-shift
(implies (and (integerp x)
(natp k))
(equal (lognot (* (expt 2 k) x))
(+ (* (expt 2 k) (lognot x))
(1- (expt 2 k))))))
(defthmd lognot-fl
(implies (and (integerp x)
(not (zp n)))
(equal (lognot (fl (/ x n)))
(fl (/ (lognot x) n)))))
(defthmd mod-lognot
(implies (and (integerp x)
(natp n))
(equal (mod (lognot x) (expt 2 n))
(1- (- (expt 2 n) (mod x (expt 2 n)))))))
(defthmd bits-lognot
(implies (and (natp i)
(natp j)
(<= j i)
(integerp x))
(equal (bits (lognot x) i j)
(- (1- (expt 2 (- (1+ i) j))) (bits x i j)))))
(defthm bitn-lognot
(implies (and (integerp x)
(natp n))
(not (equal (bitn (lognot x) n)
(bitn x n))))
:rule-classes ())
(defthmd bits-lognot-bits
(implies (and (integerp x)
(natp i)
(natp j)
(natp k)
(natp l)
(<= l k)
(<= k (- i j)))
(equal (bits (lognot (bits x i j)) k l)
(bits (lognot x) (+ k j) (+ l j)))))
(defthmd bits-lognot-bits-lognot
(implies (and (integerp x)
(natp i)
(natp j)
(natp k)
(natp l)
(<= l k)
(<= k (- i j)))
(equal (bits (lognot (bits (lognot x) i j)) k l)
(bits x (+ k j) (+ l j)))))
(defthmd logand-bits-lognot
(implies (and (integerp x)
(integerp n)
(bvecp y n))
(equal (logand y (bits (lognot x) (1- n) 0))
(logand y (lognot (bits x (1- n) 0))))))
)
;;;**********************************************************************
;;; Algebraic Properties
;;;**********************************************************************
(defsection-rtl |Algebraic Properties| |Logical Operations|
(defthm logand-x-0
(equal (logand x 0) 0))
(defthm logand-0-y
(equal (logand 0 y) 0))
(defthm logior-x-0
(implies (integerp x)
(equal (logior x 0) x)))
(defthm logior-0-y
(implies (integerp y)
(equal (logior 0 y) y)))
(defthm logxor-x-0
(implies (integerp x)
(equal (logxor x 0) x)))
(defthm logxor-0-y
(implies (integerp y)
(equal (logxor 0 y) y)))
(defthm logand-self
(implies (case-split (integerp x))
(equal (logand x x) x)))
(defthm logior-self
(implies (case-split (integerp x))
(equal (logior x x) x)))
(defthm logxor-self
(equal (logxor x x) 0))
(defthm lognot-lognot
(implies (case-split (integerp i))
(equal (lognot (lognot i))
i)))
(defthmd logior-not-0
(implies (and (integerp x)
(integerp y))
(iff (equal (logior x y) 0)
(and (= x 0) (= y 0)))))
(defthmd logxor-not-0
(implies (and (integerp x)
(integerp y))
(iff (equal (logxor x y) 0)
(= x y))))
(defthm logand-x-1
(implies (bvecp x 1)
(equal (logand x 1) x)))
(defthm logand-1-x
(implies (bvecp x 1)
(equal (logand 1 x) x)))
(defthm logior-1-x
(implies (bvecp x 1)
(equal (logior 1 x) 1)))
(defthm logior-x-1
(implies (bvecp x 1)
(equal (logior x 1) 1)))
(defthm logand-x-m1
(implies (integerp x)
(equal (logand x -1) x)))
(defthm logand-m1-y
(implies (integerp y)
(equal (logand -1 y) y)))
(defthm logior-x-m1
(implies (integerp x)
(equal (logior x -1) -1)))
(defthm logior-m1-y
(implies (integerp y)
(equal (logior -1 y) -1)))
(defthm logxor-x-m1
(implies (integerp x)
(equal (logxor x -1)
(lognot x))))
(defthm logxor-m1-x
(implies (integerp x)
(equal (logxor -1 x)
(lognot x))))
(defthm logand-commutative
(equal (logand y x) (logand x y)))
(defthm logior-commutative
(equal (logior y x) (logior x y)))
(defthm logxor-commutative
(equal (logxor y x) (logxor x y)))
(defthm logand-commutative-2
(equal (logand y x z)
(logand x y z)))
(defthm logior-commutative-2
(equal (logior y x z)
(logior x y z)))
(defthm logxor-commutative-2
(equal (logxor y x z)
(logxor x y z)))
(defthm logand-associative
(equal (logand (logand x y) z)
(logand x (logand y z))))
(defthm logior-associative
(equal (logior (logior x y) z)
(logior x (logior y z))))
(defthm logxor-associative
(equal (logxor (logxor x y) z)
(logxor x (logxor y z))))
(defthmd logior-logand
(implies (and (integerp x)
(integerp y)
(integerp z))
(equal (logior x (logand y z))
(logand (logior x y) (logior x z)))))
(defthmd logior-logand-1
(implies (and (integerp x)
(integerp y))
(equal (logior x (logand x y))
x)))
(defthmd logand-logior
(implies (and (integerp x)
(integerp y)
(integerp z))
(equal (logand x (logior y z))
(logior (logand x y) (logand x z)))))
(defthmd logior-logand-2
(implies (and (integerp x)
(integerp y)
(integerp z))
(equal (logand (logior y z) x)
(logior (logand y x) (logand z x)))))
(defthmd log3
(implies (and (integerp x)
(integerp y)
(integerp z))
(equal (logior (logand x y) (logior (logand x z) (logand y z)))
(logior (logand x y) (logand (logxor x y) z)))))
(defthmd logxor-rewrite
(implies (and (integerp x)
(integerp y))
(equal (logxor x y)
(logior (logand x (lognot y))
(logand y (lognot x))))))
(defthmd lognot-logxor
(and (equal (logxor (lognot x) y)
(lognot (logxor x y)))
(equal (logxor y (lognot x))
(lognot (logxor x y)))))
)
|