3
(set-enforce-redundancy t)
5
;; (local (include-book "../support/support/rtlarr"))
6
;; (local (include-book "../support/support/bvecp-helpers"))
7
;; (local (include-book "../support/support/guards"))
8
;; Fri Oct 27 15:38:29 2006
10
(local (include-book "../support/top/top"))
12
(set-inhibit-warnings "theory") ; avoid warning in the next event
13
(local (in-theory nil))
14
;(set-inhibit-warnings) ; restore theory warnings (optional)
16
;;We define generic record accessing and updating functions to be used
17
;;with RTL arrays. The basic functions are (ag a r) and (as a v r)
18
;;where a is an array index, v is a value, r is an "array" or record.
19
;;(ag a r) returns the value at index a in array r, and (as a v r) returns
20
;;a new array with index a set to value v in array r.
22
(include-book "misc/total-order" :dir :system)
26
(defmacro default-get-valu () 0)
29
(declare (xargs :guard t))
37
(<< (caar x) (caadr x))))))
39
(defthm rcdp-implies-alistp
40
(implies (rcdp x) (alistp x)))
43
''unlikely-to-ever-occur-in-an-executable-counterpart)
45
(defun ifrp (x) ;; ill-formed rcdp
46
(declare (xargs :guard t))
51
(equal (cdar x) (ifrp-tag))
54
(defun acl2->rcd (x) ;; function mapping acl2 objects to well-formed records.
55
(declare (xargs :guard t))
56
(if (ifrp x) (list (cons x (ifrp-tag))) x))
58
(defun rcd->acl2 (r) ;; inverse of acl2->rcd.
59
(declare (xargs :guard (rcdp r)))
60
(if (ifrp r) (caar r) r))
62
(defun ag-aux (a r) ;; record g(et) when r is a well-formed record.
63
(declare (xargs :guard (rcdp r)))
72
(defun ag (a x) ;; the generic record g(et) which works on any ACL2 object.
73
(declare (xargs :guard t))
74
(ag-aux a (acl2->rcd x)))
76
(defun acons-if (a v r)
77
(declare (xargs :guard (rcdp r)))
78
(if (equal v (default-get-valu)) r (acons a v r)))
80
(defun as-aux (a v r) ;; record s(et) when x is a well-formed record.
81
(declare (xargs :guard (rcdp r)))
86
(acons-if a v (cdr r)))
88
(cons (car r) (as-aux a v (cdr r))))))
90
(defun as (a v x) ;; the generic record s(et) which works on any ACL2 object.
91
(declare (xargs :guard t))
92
(rcd->acl2 (as-aux a v (acl2->rcd x))))
95
;;Basic properties of arrays:
98
(equal (ag a (as a v r))
102
(implies (not (equal a b))
103
(equal (ag a (as b v r))
106
;;;; NOTE: The following can be used instead of the above rules to force ACL2
107
;;;; to do a case-split. We disable this rule by default since it can lead to
108
;;;; an expensive case explosion, but in many cases, this rule may be more
109
;;;; effective than two rules above and should be enabled.
111
(defthm ag-of-as-redux
112
(equal (ag a (as b v r))
113
(if (equal a b) v (ag a r))))
115
(in-theory (disable ag-of-as-redux))
118
(equal (as a (ag a r) r)
122
(equal (as a y (as a x r))
126
(implies (not (equal a b))
127
(equal (as b y (as a x r))
128
(as a x (as b y r))))
129
:rule-classes ((:rewrite :loop-stopper ((b a as)))))
131
;; the following theorems are less relevant but have been useful in dealing
132
;; with a default record of NIL.
134
(defthm ag-of-nil-is-default
135
(equal (ag a nil) (default-get-valu)))
137
(defthm as-non-default-cannot-be-nil
138
(implies (not (equal v (default-get-valu)))
141
(defthm non-nil-if-ag-not-default
142
(implies (not (equal (ag a r)
145
:rule-classes :forward-chaining)
147
;; OK, we add here some properties for typing the records and the values which
148
;; are stored in the records. This "typing" is pretty generic, but we choose the
149
;; "bvecp" types for record values because it suits AMD's RTL modeling needs.
152
(declare (xargs :guard (integerp k)))
161
(<< (caar x) (caadr x))))))
163
(defthm as-maps-bv-arr-to-bv-arr
164
(implies (and (bv-arrp r k)
166
(bv-arrp (as a v r) k)))
168
(defthm ag-maps-bv-arr-to-bvecp
169
(implies (bv-arrp r k)
172
(defun mk-bvarr (r k)
173
(declare (xargs :guard (integerp k)))
174
(if (bv-arrp r k) r ()))
176
(defthm mk-bvarr-is-bv-arrp
177
(bv-arrp (mk-bvarr r k) k))
179
(defthm mk-bvarr-identity
180
(implies (bv-arrp r k)
181
(equal (mk-bvarr r k) r)))
183
(in-theory (disable bv-arrp mk-bvarr))
185
;;We also define as2 and ag2 for 2-dimensional arrays but these simply
186
;;macro-expand into appropriate as and ag calls.
188
(defmacro ag2 (a b r)
189
`(ag (cons ,a ,b) ,r))
191
(defmacro as2 (a b v r)
192
`(as (cons ,a ,b) ,v ,r))
195
;;We disable as and ag, assuming the rules proved in this book are
196
;;sufficient to manipulate any record terms that are encountered.
198
(in-theory (disable as ag))
200
(defun positive-integer-listp (l)
201
(declare (xargs :guard t))
204
(t (and (integerp (car l))
206
(positive-integer-listp (cdr l))))))
208
(defmacro arr0 (&rest dims)
209
(declare (ignore dims)
210
(xargs :guard (positive-integer-listp dims)))
213
;;Functions representing bit vectors of determined length but undetermined value:
216
((reset2 (key size) t))
217
(local (defun reset2 (key size) (declare (ignore key size)) nil))
218
(defthm bv-arrp-reset2
219
(bv-arrp (reset2 key size) size)
221
(("goal" :in-theory (enable bv-arrp)))))
224
((unknown2 (key size n) t))
225
(local (defun unknown2 (key size n) (declare (ignore key size n)) nil))
226
(defthm bv-arrp-unknown2
227
(bv-arrp (unknown2 key size n) size)
229
(("goal" :in-theory (enable bv-arrp)))))
231
;BOZO where in lib/ should this go?
233
(equal (bv-arrp (if1 x y z) n)
234
(if1 x (bv-arrp y n) (bv-arrp z n))))