File: defprod.lsp

package info (click to toggle)
acl2 8.6%2Bdfsg-2
  • links: PTS
  • area: main
  • in suites: trixie
  • size: 1,111,420 kB
  • sloc: lisp: 17,818,294; java: 125,359; python: 28,122; javascript: 23,458; cpp: 18,851; ansic: 11,569; perl: 7,678; xml: 5,591; sh: 3,976; makefile: 3,833; ruby: 2,633; yacc: 1,126; ml: 763; awk: 295; csh: 233; lex: 197; php: 178; tcl: 49; asm: 23; haskell: 17
file content (237 lines) | stat: -rw-r--r-- 9,553 bytes parent folder | download | duplicates (6)
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
; FTY::defprod Example
; Copyright (C) 2014, Oracle and/or its affiliates. All rights reserved.
;
; License: (An MIT/X11-style license)
;
;   Permission is hereby granted, free of charge, to any person obtaining a
;   copy of this software and associated documentation files (the "Software"),
;   to deal in the Software without restriction, including without limitation
;   the rights to use, copy, modify, merge, publish, distribute, sublicense,
;   and/or sell copies of the Software, and to permit persons to whom the
;   Software is furnished to do so, subject to the following conditions:
;
;   The above copyright notice and this permission notice shall be included in
;   all copies or substantial portions of the Software.
;
;   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
;   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;   DEALINGS IN THE SOFTWARE.
;
; Original author: David L. Rager <david.rager@oracle.com>

(in-package "ACL2")

; WARNING: This file is a work in progress.  Hopefully at some point it will
; suffice as a nice working example for defprod's dependent types feature, but
; as of December 2015, it's broken.  It is currently intended to be "ld"'d into
; a system, not certified or included as a book.

(include-book "std/util/bstar" :dir :system)
(include-book "centaur/fty/deftypes" :dir :system)
(include-book "ihs/basic-definitions" :dir :system)
(include-book "centaur/fty/basetypes" :dir :system)
(include-book "std/top" :dir :system)

(defxdoc shifting-fifo-model
  :short "The start of a FIFO model that looks like a shifting-fifo in its
          implementation")

(local (set-default-parents shifting-fifo-model))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Here begins the "defprod" part of this modeling example
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define unsigned4b-p (x)
  (declare (xargs :guard t))
  (unsigned-byte-p 4 x))

(defun unsigned4b-p-fix (x)
  (if (unsigned4b-p x)
      x
    0))

(fty::deffixtype unsigned4b-p
  :pred unsigned4b-p
  :fix unsigned4b-p-fix
  :equiv equal)

(define unsigned8b-p (x)
  (declare (xargs :guard t))
  (unsigned-byte-p 8 x))

(defun unsigned8b-p-fix (x)
  (if (unsigned8b-p x)
      x
    0))

(fty::deffixtype unsigned8b-p
  :pred unsigned8b-p
  :fix unsigned8b-p-fix
  :equiv equal)

(fty::deffixtype bitp
  :pred bitp
  :fix bfix
  :equiv equal)

(define boolean-fix (x)
  (if (booleanp x) x nil))

(fty::deffixtype boolean
                 :fix boolean-fix
                 :pred booleanp
                 :equiv equal)
(in-theory (enable boolean-fix))

(fty::defprod data-address-valid
  ((data unsigned8b-p)
   (address unsigned4b-p)
   (valid booleanp :reqfix (if (booleanp valid) valid nil))))

(defval *default-invalid-data-address*
  :short "Default values for invalid address and associated data"
  (data-address-valid 0 0 nil))

(define match-address
  ((buffer data-address-valid-p)
   (in data-address-valid-p))
  :returns (retval booleanp :rule-classes :type-prescription)
  (b* (((data-address-valid buffer))
       ((data-address-valid in)))
    (and buffer.valid in.valid
         (equal buffer.address in.address))))

(defrule match-commute
  (equal (match-address x y)
         (match-address y x))
  :enable match-address)

(define buffers-req
  ((b1 data-address-valid-p)
   (b2 data-address-valid-p)
   (b3 data-address-valid-p)
   (b4 data-address-valid-p))
  (and (not (match-address b1 b2))
       (not (match-address b1 b3))
       (not (match-address b1 b4))
       (not (match-address b2 b3))
       (not (match-address b2 b4))
       (not (match-address b3 b4))))

(define data-address-valid-fix-for-buffers
  ((x data-address-valid-p)
   (b2 data-address-valid-p)
   (b3 data-address-valid-p)
   (b4 data-address-valid-p))
  :returns (retval data-address-valid-p :hyp :fguard)
  (if (or (match-address x b2)
          (match-address x b3)
          (match-address x b4))
        *default-invalid-data-address*
      x))

(defrule data-address-valid-fix-for-buffers-identities
  (and (IMPLIES (AND (BUFFERS-REQ B1 B2 B3 B4)
                     (DATA-ADDRESS-VALID-P B4)
                     (DATA-ADDRESS-VALID-P B3)
                     (DATA-ADDRESS-VALID-P B2)
                     (DATA-ADDRESS-VALID-P B1))
                (EQUAL (DATA-ADDRESS-VALID-FIX-FOR-BUFFERS B2 B1 B3 B4)
                       B2))
       (IMPLIES (AND (BUFFERS-REQ B1 B2 B3 B4)
                     (DATA-ADDRESS-VALID-P B4)
                     (DATA-ADDRESS-VALID-P B3)
                     (DATA-ADDRESS-VALID-P B2)
                     (DATA-ADDRESS-VALID-P B1))
                (EQUAL (DATA-ADDRESS-VALID-FIX-FOR-BUFFERS B4 B1 B2 B3)
                       B4))
       (IMPLIES (AND (BUFFERS-REQ B1 B2 B3 B4)
                     (DATA-ADDRESS-VALID-P B4)
                     (DATA-ADDRESS-VALID-P B3)
                     (DATA-ADDRESS-VALID-P B2)
                     (DATA-ADDRESS-VALID-P B1))
                (EQUAL (DATA-ADDRESS-VALID-FIX-FOR-BUFFERS B1 B2 B3 B4)
                       B1))
       (IMPLIES (AND (BUFFERS-REQ B1 B2 B3 B4)
                     (DATA-ADDRESS-VALID-P B4)
                     (DATA-ADDRESS-VALID-P B3)
                     (DATA-ADDRESS-VALID-P B2)
                     (DATA-ADDRESS-VALID-P B1))
                (EQUAL (DATA-ADDRESS-VALID-FIX-FOR-BUFFERS B3 B1 B2 B4)
                       B3)))
  :enable (buffers-req data-address-valid-fix-for-buffers))

(defrulel match-of-default-is-always-nil
; For subgoal 23.9 in buffers-fix-works and buffers-req-of-fixes, but it's not
; a horrible lemma to have in general.  Still, we make it local.
  (equal (MATCH-ADDRESS *default-invalid-data-address* xxx)
         nil)
  :enable match-address)

;; (defrule match-of-default-is-always-nil-2
;;    (equal (MATCH-ADDRESS xxx *default-invalid-data-address* )
;;           nil)
;;    :enable match-address)

(defrule buffers-fix-works
  (implies (and (data-address-valid-p b1)
                (data-address-valid-p b2)
                (data-address-valid-p b3)
                (data-address-valid-p b4))
           (buffers-req (data-address-valid-fix-for-buffers b1 b2 b3 b4)
                        (data-address-valid-fix-for-buffers b2 b1 b3 b4)
                        (data-address-valid-fix-for-buffers b3 b1 b2 b4)
                        (data-address-valid-fix-for-buffers b4 b1 b1 b2)))
  :enable (data-address-valid-fix-for-buffers  buffers-req))

(defrule buffers-req-of-fixes
; I don't quite understand why this is necessary, but it is.  At least it's
; clear how to duplicate this to one's own work.
  (BUFFERS-REQ
     (DATA-ADDRESS-VALID-FIX-FOR-BUFFERS (DATA-ADDRESS-VALID-FIX B1)
                                         (DATA-ADDRESS-VALID-FIX B2)
                                         (DATA-ADDRESS-VALID-FIX B3)
                                         (DATA-ADDRESS-VALID-FIX B4))
     (DATA-ADDRESS-VALID-FIX-FOR-BUFFERS (DATA-ADDRESS-VALID-FIX B2)
                                         (DATA-ADDRESS-VALID-FIX B1)
                                         (DATA-ADDRESS-VALID-FIX B3)
                                         (DATA-ADDRESS-VALID-FIX B4))
     (DATA-ADDRESS-VALID-FIX-FOR-BUFFERS (DATA-ADDRESS-VALID-FIX B3)
                                         (DATA-ADDRESS-VALID-FIX B1)
                                         (DATA-ADDRESS-VALID-FIX B2)
                                         (DATA-ADDRESS-VALID-FIX B4))
     (DATA-ADDRESS-VALID-FIX-FOR-BUFFERS (DATA-ADDRESS-VALID-FIX B4)
                                         (DATA-ADDRESS-VALID-FIX B1)
                                         (DATA-ADDRESS-VALID-FIX B2)
                                         (DATA-ADDRESS-VALID-FIX B3)))
    :enable (buffers-req DATA-ADDRESS-VALID-FIX-FOR-BUFFERS))

(defrulel obscure-fact
; The rewrite rule has to be structured to rewrite an equality to t, because if
; it's used to rewrite the lhs of the inner equality to the rhs of the inner
; equality, it generates bad checkpoints for other proof obligations (during
; the buffers defprod).

; That being said, why this rule is necessary (and corresponding rules for b2,
; b3, and b4 aren't necessary) is still a mystery.
  (equal (EQUAL (DATA-ADDRESS-VALID-FIX-FOR-BUFFERS (DATA-ADDRESS-VALID-FIX B1)
                                                    (DATA-ADDRESS-VALID-FIX B2)
                                                    (DATA-ADDRESS-VALID-FIX B3)
                                                    (DATA-ADDRESS-VALID-FIX B4))
                (DATA-ADDRESS-VALID-FIX-FOR-BUFFERS (DATA-ADDRESS-VALID-FIX B1)
                                                    B2 B3 B4))
         t)
  :enable (data-address-valid-fix-for-buffers match-address))

(fty::defprod buffers
  ((b1 data-address-valid :reqfix (data-address-valid-fix-for-buffers b1 b2 b3 b4))
   (b2 data-address-valid :reqfix (data-address-valid-fix-for-buffers b2 b1 b3 b4))
   (b3 data-address-valid :reqfix (data-address-valid-fix-for-buffers b3 b1 b2 b4))
   (b4 data-address-valid :reqfix (data-address-valid-fix-for-buffers b4 b1 b2 b3))
   (out data-address-valid))
  :require (buffers-req b1 b2 b3 b4))