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
|
;; Cuong Chau <ckc8687@gmail.com>
;; June 2021
(in-package "RTL")
(local (include-book "rtl/rel11/lib/top-alt" :dir :system))
;; ======================================================================
(defmacro arith-5-for-rtl ()
`(progn
(include-book "arithmetic-5/top" :dir :system)
(in-theory
#!acl2(disable |(mod (+ x y) z) where (<= 0 z)|
|(mod (+ x (- (mod a b))) y)|
|(mod (mod x y) z)|
|(mod (+ x (mod a b)) y)|
mod-cancel-*-const
cancel-mod-+
reduce-additive-constant-<
ash-to-floor
|(floor x 2)|
|(equal x (if a b c))|
|(equal (if a b c) x)|
|(logior 1 x)|
mod-theorem-one-b
|(mod (- x) y)|))))
(defmacro bitthm (&rest thm)
(declare (xargs :guard (and (true-listp thm)
(symbolp (car thm)))))
(b* ((body (cadr thm))
(term (cadr body)))
`(defthm ,@thm
:rule-classes ((:type-prescription :corollary (natp ,term))
(:linear :corollary (<= ,term 1))))))
(defmacro bvecthm (&rest thm)
(declare (xargs :guard (and (true-listp thm)
(symbolp (car thm)))))
(b* ((body (cadr thm))
(implies-form? (equal (car body) 'implies))
(term (if implies-form?
(cadr (caddr body))
(cadr body)))
(width (if implies-form?
(caddr (caddr body))
(caddr body))))
(if implies-form?
`(defthm ,@thm
:rule-classes ((:rewrite :corollary ,body)
(:type-prescription
:corollary
(implies ,(cadr body)
(natp ,term)))
(:linear
:corollary
(implies ,(cadr body)
(< ,term (expt 2 ,width))))))
`(defthm ,@thm
:rule-classes ((:rewrite :corollary ,body)
(:type-prescription :corollary (natp ,term))
(:linear :corollary (< ,term (expt 2 ,width))))))))
(defmacro bvecthm-nl (&rest thm)
(declare (xargs :guard (and (true-listp thm)
(symbolp (car thm)))))
(b* ((body (cadr thm))
(implies-form? (equal (car body) 'implies))
(term (if implies-form?
(cadr (caddr body))
(cadr body)))
(width (if implies-form?
(caddr (caddr body))
(caddr body))))
(if implies-form?
`(defthm-nl ,@thm
:rule-classes ((:rewrite :corollary ,body)
(:type-prescription
:corollary
(implies ,(cadr body)
(natp ,term)))
(:linear
:corollary
(implies ,(cadr body)
(< ,term (expt 2 ,width))))))
`(defthm-nl ,@thm
:rule-classes ((:rewrite :corollary ,body)
(:type-prescription :corollary (natp ,term))
(:linear :corollary (< ,term (expt 2 ,width))))))))
(defmacro bvecthm-nl++ (&rest thm)
(declare (xargs :guard (and (true-listp thm)
(symbolp (car thm)))))
(b* ((body (cadr thm))
(implies-form? (equal (car body) 'implies))
(term (if implies-form?
(cadr (caddr body))
(cadr body)))
(width (if implies-form?
(caddr (caddr body))
(caddr body))))
(if implies-form?
`(defthm-nl++ ,@thm
:rule-classes ((:rewrite :corollary ,body)
(:type-prescription
:corollary
(implies ,(cadr body)
(natp ,term)))
(:linear
:corollary
(implies ,(cadr body)
(< ,term (expt 2 ,width))))))
`(defthm-nl++ ,@thm
:rule-classes ((:rewrite :corollary ,body)
(:type-prescription :corollary (natp ,term))
(:linear :corollary (< ,term (expt 2 ,width))))))))
(defund strcat-for-expand-hints-nofree (l param newline)
(declare (xargs :guard (and (symbol-listp l)
(stringp param)
(stringp newline))))
(if (atom l)
newline
(concatenate 'string
newline "(" (symbol-name (car l)) " " param ")"
(strcat-for-expand-hints-nofree (cdr l) param newline))))
(defund strcat-for-expand-hints-free (l param free-str newline)
(declare (xargs :guard (and (symbol-listp l)
(stringp param)
(stringp free-str)
(stringp newline))))
(if (atom l)
newline
(concatenate
'string
newline "(:free " free-str
" (" (symbol-name (car l)) " " param "))"
(strcat-for-expand-hints-free (cdr l) param free-str newline))))
(defund strcat-for-expand-hints (l param free-str)
(declare (xargs :guard (and (symbol-listp l)
(stringp param)
(stringp free-str))))
(if (equal free-str "")
(strcat-for-expand-hints-nofree l param (string '#\Newline))
(strcat-for-expand-hints-free l param free-str (string '#\Newline))))
|