3
;;;; we will need a book on record ops and theorems
5
(include-book "records")
6
(include-book "../../../../ordinals/e0-ordinal")
8
#|----------------------------------------------------------------------------|#
10
;;;; BEGIN auxiliary definitions ;;;;
13
(if (member e x) x (cons e x)))
15
(defun add-in-range (lo hi x)
16
(declare (xargs :measure (nfix (1+ (- hi lo)))))
17
(if (and (integerp hi)
20
(add-in-range lo (1- hi) (add-set hi x))
23
(defun add-nums-in (case x)
24
(cond ((endp (cdr case)) x)
26
(add-in-range (caar case)
28
(add-nums-in (cdr case) x)))
29
(t (add-set (car case)
30
(add-nums-in (cdr case) x)))))
32
(defun locase-nums (cases)
34
(add-nums-in (car cases)
35
(locase-nums (cdr cases)))))
37
(defun loc-in-range (loc range)
39
(>= loc (first range))
40
(<= loc (second range))))
42
(defun loc-in-when (loc case)
43
(and (consp (rest case))
44
(or (equal loc (first case))
45
(loc-in-range loc (first case))
46
(loc-in-when loc (rest case)))))
48
(defun gen-locase (loc cases)
49
(cond ((endp cases) ())
50
((loc-in-when loc (first cases))
51
(cons (first (last (first cases)))
52
(gen-locase loc (rest cases))))
53
(t (gen-locase loc (rest cases)))))
55
(defun gen-locases (locs cases)
56
(if (endp locs) '((t t))
57
(cons (list (first locs)
58
(cons 'and (gen-locase (first locs) cases)))
59
(gen-locases (rest locs) cases))))
61
;;;; a useful macro for defining large case splits on program locations
62
;;;; in predicates. This is used extensively in the invariant definitions
64
(defmacro locase (loc &rest cases)
65
(list* 'case loc (gen-locases (locase-nums cases) cases)))
67
(defthm nil-update-absorbed
68
(implies (not (g a r))
69
(equal (s a nil r) r))
71
:use (:instance s-same-g)
72
:in-theory (disable s-same-g))))
75
;; some initial defintions
77
(defmacro in-range (x lo hi)
82
; The following was removed with the addition of natp-compound-recognizer to
84
;(defthm natp-compound-recognizer
86
; (and (integerp x) (>= x 0)))
87
; :rule-classes :compound-recognizer)
89
(in-theory (disable natp))
91
; The following was removed with the addition of natp-compound-recognizer to
93
;(defthm posp-compound-recognizer
95
; (and (integerp x) (> x 0)))
96
; :rule-classes :compound-recognizer)
98
(in-theory (disable posp))
103
(local (defun maxf () 1))
104
(defthm maxf-is-positive-natural
106
:rule-classes :type-prescription))
109
(if (and (posp ndx) (<= ndx (maxf))) ndx 1))
111
(defthm thf-is-<=-maxf (<= (thf ndx) (maxf)))
113
(in-theory (disable thf))
116
(and (posp i) (<= i N) (posp N)))
118
(defthm indexp-thf-ndx-maxf
119
(indexp (thf ndx) (maxf)))
121
(in-theory (disable indexp))
124
(defmacro top (a) `(car ,a))
125
(defmacro tag (a) `(cdr ,a))
128
`(cons (1+ (top ,a)) (tag ,a)))
134
`(cons (top ,a) (1+ (tag ,a))))
137
`(and (natp (top ,a)) (natp (tag ,a))))
140
(or (< (tag x) (tag y))
141
(and (equal (tag x) (tag y))
142
(< (top x) (top y)))))
145
(defun mend (bot top mem)
146
(declare (xargs :measure (nfix (- bot top))))
150
(cons (<- mem (1- bot))
151
(mend (1- bot) top mem))))
154
(defun val (x) (if (natp x) x 0))
156
(defthm val-type-prescription
158
:rule-classes :type-prescription)
160
(in-theory (disable val))
163
(and (consp x) (atom (rest x))))
167
(and (consp d) (val (first d)))
173
(cons (first d) (drop-top (rest d)))))
175
(defmacro get-bot (d) `(and (consp ,d) (val (first ,d))))
177
(defmacro drop-bot (d) `(rest ,d))
179
(defmacro push-bot (x d) `(cons ,x ,d))
182
;; various auxiliary theorems about mending and ages ;;
184
(defthm mend-bounded-to-bot-top
185
(implies (and (integerp bot)
188
(equal (mend bot top (-> mem x y))
189
(mend bot top mem))))
191
(defthm mend-atom-bot<=top
192
(implies (and (integerp top)
194
(equal (consp (mend bot top mem))
197
(defthm get-top-of-mend-is-top
198
(implies (and (integerp bot)
201
(equal (get-top (mend bot top mem))
202
(val (<- mem top)))))
204
(defthm drop-top-mend-is-mend-top1+
205
(implies (and (integerp bot)
207
(equal (drop-top (mend bot top mem))
208
(mend bot (1+ top) mem))))
210
(defthm one-eltp-mend-iff-bot=top+1
211
(implies (and (integerp bot)
213
(equal (one-eltp (mend bot top mem))
214
(equal bot (1+ top)))))
216
(in-theory (disable one-eltp))
218
(defthm mend-<=-bot-top-equals-nil
219
(implies (<= bot top)
220
(not (mend bot top mem))))
222
(defthm additive-factoid1
223
(implies (and (integerp x) (integerp y))
224
(equal (+ (- x) x y) y)))
226
(defthm mend-top+1-unwind-hack
227
(implies (and (equal x (1+ bot))
231
(equal (mend x top mem)
233
(mend bot top mem)))))
236
(defthm agep-age<<-top+1
238
(age<< a (top+1 a))))
240
(defthm agep-age<<-tag+1-top=0
242
(age<< a (tag+1 (top=0 a)))))
244
(defthm age<<-transitive-top+1
246
(age<< a (top+1 b))))
248
(defthm age<<-transitive-tag+1-top=0
250
(age<< a (tag+1 (top=0 b)))))
252
(defthm age<<-irreflexive
255
(defthm age<<-trichotomy
256
(implies (and (agep x) (agep y)
261
(defthm age<<-is-asymmetric
265
(in-theory (disable age<<))
267
(defthm agep-implies-top+1-not-equal
268
(implies (agep x) (not (equal x (top+1 x)))))
270
(defthm agep-implies-tag+1-top=0-not-equal
271
(implies (agep x) (not (equal x (cons 0 (1+ (cdr x)))))))
273
(defthm age<<-top+1-hack1
274
(implies (and (agep a)
278
(defthm age<<-top+1-hack2
279
(implies (and (age<< a b)
283
(defthm tag<-implies-age<<
284
(implies (< (tag x) (tag y))
286
:hints (("Goal" :in-theory (enable age<<))))
288
(defthm age<<-implies-tag<=
290
(<= (tag x) (tag y)))
291
:hints (("Goal" :in-theory (enable age<<)))
292
:rule-classes :forward-chaining)
294
(defthm forward-chain-unfortunate
295
(implies (and (<= x y)
298
:rule-classes :forward-chaining)
300
;;;; some macros for defining accessors from records
302
(defmacro new (x) `(<- ,x :new))
303
(defmacro old (x) `(<- ,x :old))
304
(defmacro itm (x) `(<- ,x :itm))
305
(defmacro loc (x) `(<- ,x :loc))
306
(defmacro emt (x) `(<- ,x :emt))
307
(defmacro dtm (x) `(<- ,x :dtm))
309
(defmacro bot (x) `(<- ,x :bot))
310
(defmacro mem (x) `(<- ,x :mem))
311
(defmacro age (x) `(<- ,x :age))
312
(defmacro ret (x) `(<- ,x :ret))
313
(defmacro deq (x) `(<- ,x :deq))
314
(defmacro ctr (x) `(<- ,x :ctr))
315
(defmacro one (x) `(<- ,x :one))
316
(defmacro clk (x) `(<- ,x :clk))
318
(defmacro xitm (x) `(<- ,x :xitm))
319
(defmacro xctr (x) `(<- ,x :xctr))
320
(defmacro xone (x) `(<- ,x :xone))
321
(defmacro xzero (x) `(<- ,x :xzero))
322
(defmacro xsafe (x) `(<- ,x :xsafe))
324
(defmacro shr (x) `(<- ,x :shr))
325
(defmacro tvs (x) `(<- ,x :tvs))
326
(defmacro onr (x) `(<- ,x :onr))
328
(defmacro ndx (x) `(<- ,x :ndx))
329
(defmacro dtm (x) `(<- ,x :dtm))
330
(defmacro psh (x) `(<- ,x :psh))
332
(defmacro st8 (x) `(<- ,x :st8))
333
(defmacro stl (x) `(<- ,x :stl))
334
(defmacro xgo (x) `(<- ,x :xgo))
336
(defmacro >s (&rest x) `(update s ,@x))
337
(defmacro >f (&rest x) `(update f ,@x))
338
(defmacro >o (&rest x) `(update o ,@x))
339
(defmacro >st (&rest x) `(update st ,@x))
340
(defmacro >in (&rest x) `(update in ,@x))
341
(defmacro >_ (&rest x) `(update () ,@x))
343
;;;; END auxiliary definitions ;;;;
345
#|----------------------------------------------------------------------------|#
347
;;;; BEGIN cdeq step functions ;;;;
351
(8 (if (equal (age s) (old f))
354
(10 (>s :ret (itm f) :clk (1+ (clk s))))
360
(1 (>f :loc 2 :old (age s)))
361
(2 (>f :loc 3 :bot (bot s)))
362
(3 (>f :loc (if (> (bot f) (top (old f))) 5 4)))
363
(4 (>f :loc 0 :ret nil))
364
(5 (>f :loc 6 :itm (val (<- (mem s) (top (old f))))))
365
(6 (>f :loc 7 :new (old f)))
366
(7 (>f :loc 8 :new (top+1 (new f))))
367
(8 (>f :loc 9 :new (if (equal (age s) (old f))
369
(9 (>f :loc (if (equal (old f) (new f)) 10 11)))
370
(10 (>f :loc 0 :ret (itm f)))
371
(11 (>f :loc 0 :ret nil))
376
(5 (>s :bot (bot o)))
377
(9 (>s :ret (itm o) :clk (1+ (clk s))))
379
(14 (if (equal (age s) (old o))
382
(16 (>s :ret (itm o) :clk (1+ (clk s))))
383
(17 (>s :age (new o)))
384
(20 (>s :mem (-> (mem s) (bot o) (dtm o))))
385
(22 (>s :bot (bot o)))
388
(defun c-onr-o (p d o s)
390
(0 (if p (>o :loc 19 :dtm d)
392
(1 (>o :loc 2 :bot (bot s)))
393
(2 (>o :loc (if (= (bot o) 0) 3 4)))
394
(3 (>o :loc 0 :ret nil))
395
(4 (>o :loc 5 :bot (1- (bot o))))
397
(6 (>o :loc 7 :itm (val (<- (mem s) (bot o)))))
398
(7 (>o :loc 8 :old (age s)))
399
(8 (>o :loc (if (> (bot o) (top (old o))) 9 10)))
400
(9 (>o :loc 0 :ret (itm o)))
402
(11 (>o :loc 12 :new (top=0 (old o))))
403
(12 (>o :loc 13 :new (tag+1 (new o))))
404
(13 (>o :loc (if (= (bot o) (top (old o))) 14 17)))
405
(14 (>o :loc 15 :new (if (equal (age s) (old o))
407
(15 (>o :loc (if (equal (old o) (new o)) 16 17)))
408
(16 (>o :loc 0 :ret (itm o)))
410
(18 (>o :loc 0 :ret nil))
411
(19 (>o :loc 20 :bot (bot s)))
413
(21 (>o :loc 22 :bot (1+ (bot o))))
417
(let* ((ndx (thf (ndx in)))
425
(>st :tvs (-> tvs ndx (c-thf-f thf shr))
426
:shr (c-thf-s thf shr))
427
(>st :onr (c-onr-o psh dtm onr shr)
428
:shr (c-onr-s onr shr)))))
430
;;;; END cdeq step functions ;;;;
432
#|----------------------------------------------------------------------------|#
434
;;;; BEGIN cdeq+ step functions ;;;;
438
(8 (if (equal (age s) (old f))
442
(10 (>s :ret (itm f) :clk (1+ (clk s))))
453
:xitm (and (> (bot s) (top (age s)))
454
(val (<- (mem s) (top (age s)))))))
455
(3 (>f :loc (if (> (bot f) (top (old f))) 5 4)))
456
(4 (>f :loc 0 :ret nil))
457
(5 (>f :loc 6 :itm (val (<- (mem s) (top (old f))))))
458
(6 (>f :loc 7 :new (old f)))
459
(7 (>f :loc 8 :new (top+1 (new f))))
460
(8 (>f :loc 9 :new (if (equal (age s) (old f))
462
(9 (>f :loc (if (equal (old f) (new f)) 10 11)))
463
(10 (>f :loc 0 :ret (itm f)))
464
(11 (>f :loc 0 :ret nil))
470
:xsafe (<= (bot o) (top (age s)))))
471
(7 (>s :xsafe (<= (bot s) (top (age s)))))
472
(9 (>s :ret (itm o) :clk (1+ (clk s))))
474
(14 (if (equal (age s) (old o))
479
(16 (>s :ret (itm o) :clk (1+ (clk s))))
483
(20 (>s :mem (-> (mem s) (bot o) (dtm o))))
484
(22 (>s :bot (bot o)))
487
(defun i-onr-o (p d o s)
489
(0 (if p (>o :loc 19 :dtm d)
491
(1 (let ((o (>o :loc 2 :bot (bot s))))
495
(2 (>o :loc (if (= (bot o) 0) 3 4)))
496
(3 (>o :loc 0 :ret nil :xzero t))
497
(4 (>o :loc 5 :bot (1- (bot o))))
499
:xitm (and (>= (bot o) (top (age s)))
500
(val (<- (mem s) (bot o))))
501
:xctr (and (= (bot o) (top (age s)))
503
(6 (>o :loc 7 :itm (val (<- (mem s) (bot o)))))
506
:xitm (and (>= (bot o) (top (age s)))
508
:xctr (if (and (not (xctr o))
509
(= (bot o) (top (age s))))
512
(8 (if (> (bot o) (top (old o)))
513
(>o :loc 9 :xctr nil :xzero nil)
515
(9 (>o :loc 0 :ret (itm o)))
517
(11 (>o :loc 12 :new (top=0 (old o))))
518
(12 (>o :loc 13 :new (tag+1 (new o))))
519
(13 (>o :loc (if (= (bot o) (top (old o))) 14 17)))
520
(14 (let ((o (>o :loc 15)))
521
(if (equal (age s) (old o))
526
(15 (>o :loc (if (equal (old o) (new o)) 16 17)))
527
(16 (>o :loc 0 :ret (itm o)))
528
(17 (>o :loc 18 :xctr nil :xzero t))
529
(18 (>o :loc 0 :ret nil))
530
(19 (>o :loc 20 :bot (bot s)))
532
(21 (>o :loc 22 :bot (1+ (bot o))))
533
(22 (>o :loc 0 :xzero nil))
537
(let* ((ndx (thf (ndx in)))
545
(>st :tvs (-> tvs ndx (i-thf-f thf shr))
546
:shr (i-thf-s thf shr))
547
(>st :onr (i-onr-o psh dtm onr shr)
548
:shr (i-onr-s onr shr)))))
550
;;;; END cdeq+ step functions ;;;;
552
#|----------------------------------------------------------------------------|#
554
;;;; BEGIN intr step functions ;;;;
560
(>s :deq (drop-top (deq s))
563
(3 (>s :ret (itm f) :clk (1+ (clk s))))
569
(0 (>f :loc 1 :ctr (ctr s)))
570
(1 (>f :loc 2 :itm (get-top (deq s))))
571
(2 (>f :loc (if (and (itm f)
578
(1 (>s :deq (drop-bot (deq s))))
579
(3 (if (or (= (ctr o) (ctr s))
581
(implies (itm o) (ctr o))
583
(>s :ctr (1+ (ctr s)))
585
(4 (>s :ret (itm o) :clk (1+ (clk s))))
586
(5 (>s :deq (push-bot (dtm o) (deq s))))
589
(defun m-onr-o (p d o s)
591
(0 (if p (>o :loc 5 :dtm d)
595
:itm (get-bot (deq s))
596
:ctr (and (one-eltp (deq s))
598
(2 (let ((o (>o :loc 3)))
599
(cond ((or (not (itm o))
603
((not (ctr o)) (>o :ctr (ctr s)))
605
(3 (>o :loc (if (and (itm o)
607
(= (ctr o) (ctr s))))
609
:xzero (implies (itm o) (ctr o))
611
(5 (>o :loc 0 :xzero nil))
616
(let* ((ndx (thf (ndx in)))
624
(>st :tvs (-> tvs ndx (m-thf-f thf shr))
625
:shr (m-thf-s thf shr))
626
(>st :onr (m-onr-o psh dtm onr shr)
627
:shr (m-onr-s onr shr)))))
629
;;;; END intr step functions ;;;;
631
#|----------------------------------------------------------------------------|#
633
;;;; BEGIN intr+ step functions ;;;;
639
(>s :deq (drop-top (deq s))
642
(3 (>s :ret (itm f) :clk (1+ (clk s))))
652
(0 (>f :loc 1 :ctr (ctr s)))
653
(1 (>f :loc 2 :itm (get-top (deq s))))
654
(2 (>f :loc (if (and (itm f)
661
(1 (>s :deq (drop-bot (deq s))))
662
(3 (if (or (= (ctr o) (ctr s))
664
(implies (itm o) (ctr o))
666
(>s :ctr (1+ (ctr s)))
668
(4 (>s :ret (itm o) :clk (1+ (clk s))))
669
(5 (>s :deq (push-bot (dtm o) (deq s))))
672
(defun r-onr-o (p d o s)
674
(0 (if p (>o :loc 5 :dtm d)
678
:itm (get-bot (deq s))
679
:ctr (and (one-eltp (deq s))
681
(2 (let ((o (>o :loc 3)))
682
(cond ((or (not (itm o))
686
((not (ctr o)) (>o :ctr (ctr s)))
688
(3 (>o :loc (if (and (itm o)
690
(= (ctr o) (ctr s))))
692
:xzero (implies (itm o) (ctr o))
694
(5 (>o :loc 0 :xzero nil))
699
(let* ((ndx (thf (ndx in)))
707
(>st :tvs (-> tvs ndx (r-thf-f thf shr))
708
:shr (r-thf-s thf shr))
709
(>st :onr (r-onr-o psh dtm onr shr)
710
:shr (r-onr-s onr shr)))))
712
;;;; END intr+ step functions ;;;;
714
#|----------------------------------------------------------------------------|#
716
;;;; BEGIN spec step function ;;;;
719
(let ((ndx (thf (ndx in)))
724
(deq (deq (shr st))))
727
(>st :tvs (-> tvs ndx nil)
728
:shr (>s :ret (<- tvs ndx)
730
((and (itm o) (equal (st8 o) 'pop)
732
(>st :tvs (-> tvs ndx (itm o))
735
(>st :tvs (-> tvs ndx (get-top deq))
736
:shr (>s :deq (drop-top deq)))))
738
(push (>st :onr (>o :st8 'idle)
739
:shr (>s :deq (push-bot (dtm o) deq))))
741
(>st :onr (>o :st8 'idle :itm nil)
742
:shr (>s :ret (itm o)
744
(>st :onr (>o :st8 'idle))))
746
(>st :onr (>o :st8 'push :dtm dtm))
747
(>st :onr (>o :st8 'pop :itm (get-bot deq))
748
:shr (>s :deq (drop-bot deq)))))))))
750
;;;; END spec step function ;;;;
752
#|----------------------------------------------------------------------------|#
754
;;;; BEGIN label function ;;;;
761
;;;; END label function ;;;;
763
#|----------------------------------------------------------------------------|#