summaryrefslogtreecommitdiff
path: root/books/workshops/2000/manolios/pipeline/pipeline/non-deterministic-systems/top/non-det-macros.lisp
blob: 4586a91f3d107031caec2d4caf1d1d03f2431590 (plain)
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
;  Copyright (C) 2000 Panagiotis Manolios

;  This program is free software; you can redistribute it and/or modify
;  it under the terms of the GNU General Public License as published by
;  the Free Software Foundation; either version 2 of the License, or
;  (at your option) any later version.

;  This program is distributed in the hope that it will be useful,
;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;  GNU General Public License for more details.

;  You should have received a copy of the GNU General Public License
;  along with this program; if not, write to the Free Software
;  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

;  Written by Panagiotis Manolios who can be reached as follows.

;  Email: pete@cs.utexas.edu

;  Postal Mail:
;  Department of Computer Science
;  The University of Texas at Austin
;  Austin, TX 78701 USA

(in-package "ACL2")
#|

This is a set of macros for relating an abstract system and a concrete
system with a WEB.  The systems are non-deterministic.

|#

(defun bor-macro (lst)
  (declare (xargs :guard t))
  (if (consp lst)
      (if (consp (cdr lst))
	  (list 'if
		(car lst)
		t
		(bor-macro (cdr lst)))
	(car lst))
    nil))

(defmacro bor (&rest args)
  (bor-macro args))

; The reason for the bor macro is that (or a b) gets expanded to (if a
; a b).  This results in extra rewriting in many situations.  bor is
; equivalent to or if all the arguments are booleans.


; Generate-Full-System is given abs-step, the function that steps the
; abstract system for one step, abs-p, the predicate that recognizes
; abstract states, con-step, the function that steps the concrete
; system for one step, con-p, the predicate that recognizes concrete
; states, and con-rank, the rank of a concrete state.  Note that I am
; assuming that the step of abstract and concrete states depends only
; on the state.  There may be situations in which this is not the
; case.  If so, these macros will have to be altered somewhat.  Also,
; I am assuming that the rank of abstract states is 0.  This may also
; not be the case in general.  R, B, and rank should be undefined.

(defmacro generate-full-system (abs-step abs-p con-step con-p
				con-to-abs good-con con-rank)
  `(progn

     (defun WF-rel (x y)
       (declare (xargs :normalize nil))
       (and (,abs-p x)
	    (,con-p y)
	    (,good-con y)
	    (equal x (,con-to-abs y))))

     (defun B (x y)
       (declare (xargs :normalize nil))
       (bor (WF-rel x y)
	    (WF-rel y x)
	    (equal x y)
	    (and (,con-p x)
		 (,con-p y)
		 (,good-con x)
		 (,good-con y)
		 (equal (,con-to-abs x)
			(,con-to-abs y)))))

     (defun rank (x)
       (declare (xargs :normalize nil))
       (if (,con-p x)
	   (,con-rank x)
	 0))

     (defun R-int (x y int)
       (declare (xargs :normalize nil))
       (cond ((,abs-p x)
	      (equal y (,abs-step x int)))
	     (t (equal y (,con-step x int)))))

     (defun-sk R (x y)
       (exists (int)
	 (r-int x y int)))

     (encapsulate
      ()
      (local (in-theory nil))

      (defthm WF-rel-fc
	(equal (Wf-rel x y)
	       (and (,abs-p x)
		    (,con-p y)
		    (,good-con y)
		    (equal x (,con-to-abs y))))
	:hints (("goal" :by Wf-rel))
	:rule-classes ((:forward-chaining :trigger-terms ((Wf-rel x y)))))

      (defthm B-fc
	(equal (B x y)
	       (bor (WF-rel x y)
		    (WF-rel y x)
		    (equal x y)
		    (and (,con-p x)
			 (,con-p y)
			 (,good-con x)
			 (,good-con y)
			 (equal (,con-to-abs x)
				(,con-to-abs y)))))
	:hints (("goal" :by B))
	:rule-classes ((:forward-chaining :trigger-terms ((B x y)))))

      (defthm rank-fc
	(equal (rank x)
	       (if (,con-p x)
		   (,con-rank x)
		 0))
	:hints (("goal" :by rank))
	:rule-classes ((:forward-chaining :trigger-terms ((rank x)))))

      (defthm R-int-fc
	(equal (R-int x y int)
	       (cond ((,abs-p x)
		      (equal y (,abs-step x int)))
		     (t (equal y (,con-step x int)))))
	:hints (("goal" :by R-int))
	:rule-classes ((:forward-chaining :trigger-terms ((R-int x y int)))))

      (defthm R-fc
	(equal (R x y)
	       (R-int x y (R-witness x y)))
	:hints (("goal" :use R))
	:rule-classes
	((:forward-chaining :trigger-terms ((R x y)))))

      )
     )
  )

(defmacro prove-web (abs-step abs-p con-step con-p con-to-abs con-rank)
  `(progn
     (defthm B-is-a-WF-bisim-core
       (let ((u (,abs-step s int))
	     (v (,con-step w int)))
	 (implies (and (WF-rel s w)
		       (not (WF-rel u v)))
		  (and (WF-rel s v)
		       (e0-ord-< (,con-rank v)
				 (,con-rank w))))))

     (in-theory (disable b-is-a-wf-bisim-core))

     (defthm con-to-abs-type
       (,abs-p (,con-to-abs x)))

     (defthm abs-step-type
       (,abs-p (,abs-step x int)))

     (defthm con-step-type
       (,con-p (,con-step x int)))

     (defthm con-not-abs
       (implies (,con-p x)
		(not (,abs-p x))))

     (defthm abs-not-con
       (implies (,abs-p x)
		(not (,con-p x))))))

(defmacro wrap-it-up (abs-step abs-p con-step con-p
			       good-con con-to-abs con-rank)
  `(encapsulate
    ()

    (encapsulate
     ()
     (local (in-theory nil))

     (local (in-theory (enable abs-step-type con-step-type con-not-abs abs-not-con
			       con-to-abs-type
			       Wf-rel-fc B-fc
			       b-is-a-wf-bisim-core)))

     (defequiv b
       :hints (("goal"
		:by (:functional-instance
		     encap-B-is-an-equivalence

		     (encap-abs-step ,abs-step)
		     (encap-abs-p ,abs-p)
		     (encap-con-step ,con-step)
		     (encap-con-p ,con-p)
		     (encap-con-to-abs ,con-to-abs)
		     (encap-good-con ,good-con)
		     (encap-con-rank ,con-rank)

		     (encap-wf-rel wf-rel)
		     (encap-B B))))))

    (defthm rank-well-founded
      (e0-ordinalp (rank x)))

    (defun-weak-sk exists-w-succ-for-u-weak (w u)
      (exists (v)
	(and (R w v)
	     (B u v))))

    (defun-weak-sk exists-w-succ-for-s-weak (w s)
      (exists (v)
	(and (R w v)
	     (B s v)
	     (e0-ord-< (rank v) (rank w)))))

    (encapsulate
     ()
     (local (in-theory nil))

     (defthm exists-w-succ-for-u-weak-fc
       (implies (and (R w v)
		     (B u v))
		(exists-w-succ-for-u-weak w u))
       :hints (("goal" :by exists-w-succ-for-u-weak-suff))
       :rule-classes ((:forward-chaining
		       :trigger-terms ((r w v) (b u v)
				       (exists-w-succ-for-u-weak w u)))))

     (defthm exists-w-succ-for-s-weak-fc
       (implies (and (R w v)
		     (B s v)
		     (e0-ord-< (rank v) (rank w)))
		(exists-w-succ-for-s-weak w s))
       :hints (("goal" :by exists-w-succ-for-s-weak-suff))
       :rule-classes ((:forward-chaining
		       :trigger-terms ((r w v) (b s v)
				       (exists-w-succ-for-s-weak w s))))))


    (local (in-theory nil))

    (local (in-theory (enable abs-step-type con-step-type con-not-abs abs-not-con
			      con-to-abs-type
			      exists-w-succ-for-s-weak-fc exists-w-succ-for-u-weak-fc
			      R-fc R-int-fc Wf-rel-fc B-fc rank-fc
			      r-suff b-is-a-wf-bisim-core)))

    (defthm b-is-a-wf-bisim-weak
      (implies (and (b s w)
		    (r s u))
	       (or (exists-w-succ-for-u-weak w u)
		   (and (b u w)
			(e0-ord-< (rank u) (rank s)))
		   (exists-w-succ-for-s-weak w s)))
      :hints (("goal"
	       :by (:functional-instance
		    B-is-a-WF-bisim-sk

		    (encap-abs-step ,abs-step)
		    (encap-abs-p ,abs-p)
		    (encap-con-step ,con-step)
		    (encap-con-p ,con-p)
		    (encap-con-to-abs ,con-to-abs)
		    (encap-good-con ,good-con)
		    (encap-con-rank ,con-rank)

		    (encap-R-int R-int)
		    (encap-R-witness R-witness)
		    (encap-R R)
		    (encap-wf-rel wf-rel)
		    (encap-B B)
		    (encap-rank rank)

		    (encap-exists-w-succ-for-u exists-w-succ-for-u-weak)
		    (encap-exists-w-succ-for-s exists-w-succ-for-s-weak))))
      :rule-classes nil)

    (defun-sk exists-w-succ-for-u (w u)
      (exists (v)
	(and (R w v)
	     (B u v))))

    (defun-sk exists-w-succ-for-s (w s)
      (exists (v)
	(and (R w v)
	     (B s v)
	     (e0-ord-< (rank v) (rank w)))))

    (local (in-theory nil))
    (local (in-theory (enable exists-w-succ-for-s-suff exists-w-succ-for-u-suff)))

    (defthm b-is-a-wf-bisim
      (implies (and (b s w)
		    (r s u))
	       (or (exists-w-succ-for-u w u)
		   (and (b u w)
			(e0-ord-< (rank u) (rank s)))
		   (exists-w-succ-for-s w s)))
      :hints (("goal"
	       :by (:functional-instance
		    B-is-a-WF-bisim-weak

		    (exists-w-succ-for-u-weak exists-w-succ-for-u)
		    (exists-w-succ-for-s-weak exists-w-succ-for-s))))
      :rule-classes nil)
    )
  )