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 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
|
; RTL - A Formal Theory of Register-Transfer Logic and Computer Arithmetic
; Copyright (C) 1995-2013 Advanced Mirco Devices, Inc.
;
; Contact:
; David Russinoff
; 1106 W 9th St., Austin, TX 78703
; http://www.russsinoff.com/
;
; See license file books/rtl/rel9/license.txt.
;
; Author: David M. Russinoff (david@russinoff.com)
(in-package "ACL2")
(set-enforce-redundancy t)
;Contains bvecp lemmas about the RTL primitives.
;Also contains type lemmas (non-negative integer, natp, etc.)
(include-book "rtl")
(include-book "rtlarr")
(include-book "bits")
(include-book "float")
(local (include-book "base"))
(set-inhibit-warnings "theory")
(local (in-theory nil))
(set-match-free-default :all)
(defun fl (x)
(declare (xargs :guard (real/rationalp x)))
(floor x 1))
(defun expo-measure (x)
; (declare (xargs :guard (and (real/rationalp x) (not (equal x 0)))))
(cond ((not (rationalp x)) 0)
((< x 0) '(2 . 0))
((< x 1) (cons 1 (fl (/ x))))
(t (fl x))))
(defun expo (x)
(declare (xargs :guard t
:measure (:? x)))
(cond ((or (not (rationalp x)) (equal x 0)) 0)
((< x 0) (expo (- x)))
((< x 1) (1- (expo (* 2 x))))
((< x 2) 0)
(t (1+ (expo (/ x 2))))))
;; bits
(defthm bits-nonnegative-integerp-type
(and (<= 0 (bits x i j))
(integerp (bits x i j)))
:rule-classes (:type-prescription))
;this rule is no better than bits-nonnegative-integer and might be worse
(in-theory (disable (:type-prescription bits)))
(defthm bits-bvecp
(implies (and (<= (+ 1 i (- j)) k)
(case-split (integerp k))
)
(bvecp (bits x i j) k)))
;; setbits
(defthm setbits-nonnegative-integer-type
(and (integerp (setbits x w i j y))
(<= 0 (setbits x w i j y)))
:rule-classes (:type-prescription)
)
;this rule is no better than setbits-nonnegative-integer-type and might be worse:
(in-theory (disable (:type-prescription setbits)))
(defthm setbits-bvecp
(implies (and (<= w k)
(case-split (integerp k))
)
(bvecp (setbits x w i j y) k)))
;; setbitn
(defthm setbitn-nonnegative-integer-type
(and (integerp (setbitn x w n y))
(<= 0 (setbitn x w n y)))
:rule-classes (:type-prescription)
)
;this rule is no better than setbits-nonnegative-integer-type and might be worse:
(in-theory (disable (:type-prescription setbitn)))
(defthm setbitn-bvecp
(implies (and (<= w k)
(case-split (integerp k)))
(bvecp (setbitn x w n y) k)))
;; log<
(defthm log<-nonnegative-integer-type
(and (integerp (log< x y))
(<= 0 (log< x y)))
:rule-classes (:type-prescription))
;this rule is no better than log<-nonnegative-integer-type and might be worse
(in-theory (disable (:type-prescription log<)))
(defthm log<-bvecp
(bvecp (log< x y) 1))
;; log<=
(defthm log<=-nonnegative-integer-type
(and (integerp (log<= x y))
(<= 0 (log<= x y)))
:rule-classes (:type-prescription))
;this rule is no better than log<=-nonnegative-integer-type and might be worse
(in-theory (disable (:type-prescription log<=)))
(defthm log<=-bvecp
(bvecp (log<= x y) 1))
;; log>
(defthm log>-nonnegative-integer-type
(and (integerp (log> x y))
(<= 0 (log> x y)))
:rule-classes (:type-prescription))
;this rule is no better than log>-nonnegative-integer-type and might be worse
(in-theory (disable (:type-prescription log>)))
(defthm log>-bvecp
(bvecp (log> x y) 1))
;; log>=
(defthm log>=-nonnegative-integer-type
(and (integerp (log>= x y))
(<= 0 (log>= x y)))
:rule-classes (:type-prescription))
;this rule is no better than log>=-nonnegative-integer-type and might be worse
(in-theory (disable (:type-prescription log>=)))
(defthm log>=-bvecp
(bvecp (log>= x y) 1))
;; log=
(defthm log=-nonnegative-integer-type
(and (integerp (log= x y))
(<= 0 (log= x y)))
:rule-classes (:type-prescription))
;this rule is no better than log=-nonnegative-integer-type and might be worse
(in-theory (disable (:type-prescription log=)))
(defthm log=-bvecp
(bvecp (log= x y) 1))
;; log<>
(defthm log<>-nonnegative-integer-type
(and (integerp (log<> x y))
(<= 0 (log<> x y)))
:rule-classes (:type-prescription))
;this rule is no better than log<>-nonnegative-integer-type and might be worse
(in-theory (disable (:type-prescription log<>)))
(defthm log<>-bvecp
(bvecp (log<> x y) 1))
;; logand1
(defthm logand1-nonnegative-integer-type
(and (integerp (logand1 x y))
(<= 0 (logand1 x y)))
:rule-classes (:type-prescription))
;this rule is no better than logand1-nonnegative-integer-type and might be worse
(in-theory (disable (:type-prescription logand1)))
(defthm logand1-bvecp
(bvecp (logand1 x y) 1))
;; logior1
(defthm logior1-nonnegative-integer-type
(and (integerp (logior1 x))
(<= 0 (logior1 x)))
:rule-classes (:type-prescription))
;this rule is no better than logior1-nonnegative-integer-type and might be worse
(in-theory (disable (:type-prescription logior1)))
(defthm logior1-bvecp
(bvecp (logior1 x) 1))
;; logxor1
(defthm logxor1-nonnegative-integer-type
(and (integerp (logxor1 x))
(<= 0 (logxor1 x)))
:rule-classes (:type-prescription))
;this rule is no better than logxor1-nonnegative-integer-type and might be worse
(in-theory (disable (:type-prescription logxor1)))
(defthm logxor1-bvecp
(bvecp (logxor1 x) 1))
;; lnot
(defthm lnot-nonnegative-integer-type
(and (integerp (lnot x n))
(<= 0 (lnot x n)))
:rule-classes ((:type-prescription :typed-term (lnot x n))))
;lnot-nonnegative-integer-type is strictly better, and we don't need both
(in-theory (disable (:type-prescription lnot)))
(defthm lnot-bvecp
(implies (and (<= n k)
(case-split (integerp k)))
(bvecp (lnot x n) k)))
;; bitn
(defthm bitn-nonnegative-integer
(and (integerp (bitn x n))
(<= 0 (bitn x n)))
:rule-classes ( :type-prescription))
;this rule is no better than bitn-nonnegative-integer-type and might be worse
(in-theory (disable (:type-prescription bitn)))
(defthm bitn-bvecp
(implies (and (<= 1 k)
(case-split (integerp k)))
(bvecp (bitn x n) k)))
;; shft
(defthm shft-nonnegative-integer-type
(and (integerp (shft x s l))
(<= 0 (shft x s l)))
:rule-classes (:type-prescription))
;(:type-prescription shft) is no better than shft-nonnegative-integer-type and might be worse:
(in-theory (disable (:type-prescription shft)))
(defthm shft-bvecp
(implies (and (<= n k)
(case-split (integerp k)))
(bvecp (shft x s n) k)))
;; cat
(defthm cat-nonnegative-integer-type
(and (integerp (CAT X m Y N))
(<= 0 (CAT X m Y N)))
:rule-classes (:type-prescription))
(in-theory (disable (:type-prescription cat-nonnegative-integer-type)))
(defthm cat-bvecp
(implies (and (<= (+ m n) k)
(case-split (integerp k)))
(bvecp (cat x m y n) k)))
;; logand
(defthm logand-integer-type-prescription
(integerp (logand i j))
:rule-classes (:type-prescription))
(defthm logand-non-negative-integer-type-prescription
(implies (or (<= 0 i)
(<= 0 j))
(and (<= 0 (logand i j))
(integerp (logand i j))))
:rule-classes (:type-prescription))
(defthm logand-non-negative
(implies (or (<= 0 x)
(<= 0 y)
)
(<= 0 (logand x y))))
(defthm bvecp-logand-alternate
(implies (and (integerp n)
(<= 0 n)
(bvecp x n)
(bvecp y n))
(bvecp (logand x y) n)))
;; logior
(defthm logior-integer-type-prescription
(integerp (logior i j))
:rule-classes (:type-prescription))
(defthm logior-non-negative-integer-type-prescription
(implies (and (<= 0 i)
(<= 0 j))
(and (<= 0 (logior i j))
(integerp (logior i j))))
:rule-classes (:type-prescription))
(defthm logior-non-negative
(implies (and (<= 0 i)
(<= 0 j)
)
(<= 0 (logior i j))))
(defthm bvecp-logior-alternate
(implies (and (integerp n)
(<= 0 n)
(bvecp x n)
(bvecp y n))
(bvecp (logior x y) n)))
;; logxor
;!!fix this to have lemmas like logand,logior above
(defthm natp-logxor-alternate-2
(implies (and (integerp x) (<= 0 x)
(integerp y) (<= 0 y))
(and (integerp (logxor x y))
(<= 0 (logxor x y))))
:rule-classes (:rewrite :type-prescription))
(defthm bvecp-logxor-alternate
(implies (and (integerp n)
(<= 0 n)
(bvecp x n)
(bvecp y n))
(bvecp (logxor x y) n)))
;; mulcat
(defund mulcat (l n x)
; We introduce mbe not because we want particularly fast execution, but because
; the existing logic definition does not satisfy the guard of cat, which can't
; be changed because of the guard of bits.
(declare (xargs :guard (and (integerp l)
(< 0 l)
(acl2-numberp n)
(natp x))))
(mbe :logic (if (and (integerp n) (> n 0))
(cat (mulcat l (1- n) x)
(* l (1- n))
x
l)
0)
:exec (cond ((eql n 1)
(bits x (1- l) 0))
((and (integerp n) (> n 0))
(cat (mulcat l (1- n) x)
(* l (1- n))
x
l))
(t 0))))
(defthm mulcat-nonnegative-integer-type
(and (integerp (mulcat l n x))
(<= 0 (mulcat l n x)))
:rule-classes (:type-prescription))
;this rule is no better than mulcat-nonnegative-integer-type and might be worse
(in-theory (disable (:type-prescription mulcat-nonnegative-integer-type)))
(defthm mulcat-bvecp
(implies (and (>= p (* l n))
(case-split (integerp p))
(case-split (natp l)))
(bvecp (mulcat l n x) p)))
;; mod-
;finish this section (will have to change comp2-inv?)
#|
(defthm mod--nonnegative-integer-type
(and (integerp (mod- l n x))
(<= 0 (mod- l n x)))
:rule-classes (:type-prescription)
)
;this rule is no better than mod--nonnegative-integer-type and might be worse
(in-theory (disable (:type-prescription mod-)))
|#
#| mod- is now a macro!
(defthm mod--bvecp
(implies (and (bvecp x n)
(bvecp y n)
(integerp n)
(>= n 0))
(bvecp (mod- x y n) n)))
|#
;; encode
(defthm encode-nonnegative-integer-type
(and (integerp (encode x n))
(<= 0 (encode x n)))
:rule-classes (:type-prescription))
;this rule is no better than encode-nonnegative-integer-type and might be worse:
(in-theory (disable (:type-prescription encode)))
(defthm encode-bvecp-old
(implies (and (<= (+ 1 (expo n)) k)
(case-split (integerp k)))
(bvecp (encode x n) k)))
;; decode
(defthm decode-nonnegative-integer-type
(and (integerp (decode x n))
(<= 0 (decode x n)))
:rule-classes (:type-prescription))
;this rule is no better than decode-nonnegative-integer-type and might be worse:
(in-theory (disable (:type-prescription decode)))
(defthm decode-bvecp
(implies (and (<= n k)
(case-split (integerp k))
)
(bvecp (decode x n) k)))
(DEFTHM UNKNOWN-upper-bound
(< (UNKNOWN KEY SIZE N) (expt 2 size))
:RULE-CLASSES
(:REWRITE (:linear :trigger-terms ((UNKNOWN KEY SIZE N)))))
;BOZO dup?
(defthm bv-arrp-implies-nonnegative-integerp
(implies (bv-arrp obj size)
(and (INTEGERP (ag index obj))
(<= 0 (ag index obj))))
:rule-classes (:rewrite :type-prescription)
)
; land
(defthm land-nonnegative-integer-type
(and (integerp (land x y n))
(<= 0 (land x y n)))
:rule-classes (:type-prescription))
;(:type-prescription land) is no better than land-nonnegative-integer-type and might be worse:
(in-theory (disable (:type-prescription binary-land)))
;drop this if we plan to keep natp enabled?
(defthm land-natp
(natp (land x y n)))
(defthm land-bvecp
(implies (and (<= n k)
(case-split (integerp k)))
(bvecp (land x y n) k)))
;; lior
(defthm lior-nonnegative-integer-type
(and (integerp (lior x y n))
(<= 0 (lior x y n)))
:rule-classes (:type-prescription))
;(:type-prescription lior) is no better than lior-nonnegative-integer-type and might be worse:
(in-theory (disable (:type-prescription binary-lior)))
;drop this if we plan to keep natp enabled?
(defthm lior-natp
(natp (lior x y n)))
(defthm lior-bvecp
(implies (and (<= n k)
(case-split (integerp k)))
(bvecp (lior x y n) k)))
;; lxor
(defthm lxor-nonnegative-integer-type
(and (integerp (lxor x y n))
(<= 0 (lxor x y n)))
:rule-classes (:type-prescription))
;(:type-prescription lxor) is no better than lxor-nonnegative-integer-type and might be worse:
(in-theory (disable (:type-prescription binary-lxor)))
;drop this if we plan to keep natp enabled?
(defthm lxor-natp
(natp (lxor x y n)))
(defthm lxor-bvecp
(implies (and (<= n k)
(case-split (integerp k)))
(bvecp (lxor x y n) k)))
;; cat
(defthm cat-nonnegative-integer-type
(and (integerp (CAT X m Y N))
(<= 0 (CAT X m Y N)))
:rule-classes (:type-prescription)
)
;this rule is no better than cat-nonnegative-integer-type and might be worse
(in-theory (disable (:type-prescription binary-cat)))
;just a rewrite rule
(defthm cat-natp
(natp (cat x m y n)))
(defthm cat-bvecp
(implies (and (<= (+ m n) k)
(case-split (integerp k)))
(bvecp (cat x m y n) k)))
;would like to remove some of this stuff
;;;;;;;;;;;;;;;;;;; other helpful lemmas
(defthm nonneg-+
(implies (and (<= 0 x)
(<= 0 y))
(<= 0 (+ x y))))
(defthm integerp-+
(implies (and (integerp x)
(integerp y))
(integerp (+ x y))))
#|
;should be a forward-chaining rule?
(defthm bvecp-implies-natp
(implies (bvecp x k)
(and (integerp x)
(>= x 0))))
;free var
;should be a forward-chaining rule?
(defthm bvecp-implies-rationalp
(implies (bvecp x k)
(rationalp x)))
|#
;why do we have this?
(defthm unknown-upper-bound
(< (unknown key size n) (expt 2 size))
:rule-classes
(:rewrite (:linear :trigger-terms ((unknown key size n)))))
(defthm bv-arrp-implies-nonnegative-integerp
(implies (bv-arrp obj size)
(and (INTEGERP (ag index obj))
(<= 0 (ag index obj))))
:rule-classes (:rewrite :type-prescription))
;(local (in-theory (enable floor-fl)))
;These next two are for the bus unit bvecp lemmas:
;could use (local (in-theory (enable expt-compare-with-double)))
;remove?
(defthm bits-does-nothing-hack
(implies (and (< x (expt 2 i))
(integerp x)
(<= 0 x)
(integerp i)
(<= 0 i))
(equal (BITS (* 2 x) i 0)
(* 2 x))))
;remove?
(defthm bits-does-nothing-hack-2
(implies (and (< x (expt 2 i))
(integerp x)
(<= 0 x)
(integerp i)
(<= 0 i))
(equal (bits (+ 1 (* 2 x)) i 0)
(+ 1 (* 2 x)))))
;is this one too expensive?
(defthm bvecp-def
(implies (and (< x (expt 2 k))
(integerp x)
(<= 0 x)
)
(bvecp x k))
:rule-classes ((:rewrite :backchain-limit-lst (1 nil nil))))
; The two events following the next local include-book were added by Matt
; K. June 2004: Some proofs require calls of expt to be evaluated, but some
; calls are just too large (2^2^n for large n). So we use the following hack,
; which allows calls of 2^n for n<130 to be evaluated even when the
; executable-counterpart of expt is disabled. The use of 130 is somewhat
; arbitrary, chosen in the hope that it suffices for relieving of hyps related
; to widths of bit vectors
(defun expt-exec (r i)
(declare (xargs :guard
(and (acl2-numberp r)
(integerp i)
(not (and (eql r 0) (< i 0))))))
(mbe :logic (hide (expt r i)) ; hide may avoid potential loop
:exec (expt r i)))
(defthm expt-2-evaluator
(implies (syntaxp (and (quotep n)
(natp (cadr n))
(< (cadr n) 130)
))
(equal (expt 2 n)
(expt-exec 2 n))))
;remove these?
;;;;;;;;;;;;;;;;;;; We can probably eliminate the following if the translator
;;;;;;;;;;;;;;;;;;; would always use 0 instead of nil when case/casex
;;;;;;;;;;;;;;;;;;; statements have no default.
;maybe leave this one?
#|
(defthm bvecp-1-values
(implies (and (bvecp x 1)
(not (equal x 0)))
(equal (equal x 1) t)))
(defthm bvecp-2-values
(implies (and (bvecp x 2)
(not (equal x 2))
(not (equal x 1))
(not (equal x 0)))
(equal (equal x 3) t)))
(defthm bvecp-3-values
(implies (and (bvecp x 3)
(not (equal x 6))
(not (equal x 5))
(not (equal x 4))
(not (equal x 3))
(not (equal x 2))
(not (equal x 1))
(not (equal x 0)))
(equal (equal x 7) t)))
(defthm bvecp-4-values
(implies (and (bvecp x 4)
(not (equal x 14))
(not (equal x 13))
(not (equal x 12))
(not (equal x 11))
(not (equal x 10))
(not (equal x 9))
(not (equal x 8))
(not (equal x 7))
(not (equal x 6))
(not (equal x 5))
(not (equal x 4))
(not (equal x 3))
(not (equal x 2))
(not (equal x 1))
(not (equal x 0)))
(equal (equal x 15) t)))
(defthm bvecp-5-values
(implies (and (bvecp x 5)
(not (equal x 30))
(not (equal x 29))
(not (equal x 28))
(not (equal x 27))
(not (equal x 26))
(not (equal x 25))
(not (equal x 24))
(not (equal x 23))
(not (equal x 22))
(not (equal x 21))
(not (equal x 20))
(not (equal x 19))
(not (equal x 18))
(not (equal x 17))
(not (equal x 16))
(not (equal x 15))
(not (equal x 14))
(not (equal x 13))
(not (equal x 12))
(not (equal x 11))
(not (equal x 14))
(not (equal x 13))
(not (equal x 12))
(not (equal x 11))
(not (equal x 10))
(not (equal x 9))
(not (equal x 8))
(not (equal x 7))
(not (equal x 6))
(not (equal x 5))
(not (equal x 4))
(not (equal x 3))
(not (equal x 2))
(not (equal x 1))
(not (equal x 0)))
(equal (equal x 31) t)))
|#
#|
;can remove these two?
(defthm natp-*
(implies (and (integerp x)
(>= x 0)
(integerp y)
(>= y 0))
(and (integerp (* x y))
(>= (* x y) 0))))
(defthm natp-+
(implies (and (integerp x)
(>= x 0)
(integerp y)
(>= y 0))
(and (integerp (+ x y))
(>= (+ x y) 0))))
|#
#|
;drop?
(defthm bits-bvecp-fw
(implies (equal n (- (1+ i) j))
(bvecp (bits x i j) n))
:rule-classes
((:forward-chaining :trigger-terms ((bits x i j)))))
|#
|