summaryrefslogtreecommitdiff
path: root/books/workshops/2011/verbeek-schmaltz/sources/GeNoC-misc.lisp
blob: 7d5494651bcfcad17ce57fa6d2a94b56f5e6e7f2 (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
324
325
326
327
328
329
330
331
332
#|$ACL2s-Preamble$;
;; Amr HELMY
;; Miscelaneous definitions and lemmas

;;31st october 2007
;; File: GeNoC-misc.lisp
(begin-book);$ACL2s-Preamble$|#

(in-package "ACL2")

(include-book "GeNoC-types")
(include-book "make-event/defspec"  :dir :system)

;;|-------------------------------------------------|
;;|                                                    |
;;|                    Not-in                            |
;;|                                                    |
;;|-------------------------------------------------|

(defun not-in (x y)
  (if (or (endp x) (endp y))
      t
    (and (not (member-equal (car x) y))
         (not-in (cdr x) y))))


(defthm no-dups-append
  (equal (no-duplicatesp-equal (append x y))
         (and (no-duplicatesp-equal x)
              (no-duplicatesp-equal y)
              (not-in x y))))


;;|---------------------------------------|
;;|                                          |
;;|         Theoremes about Subsetp              |
;;|                                          |
;;|---------------------------------------|
;; we prove some useful lemmas about subsetp
(defthm subsetp-expand
  (implies (subsetp x y)
           (subsetp x (cons z y))))

(defthm subsetp-x-x
  (subsetp x x))

(defthm subsetp-append
  (equal (subsetp (append x y) z)
         (and (subsetp x z)
              (subsetp y z))))

(defthm subsetp-trans
  ;; transitivity of subsetp
  (implies (and (subsetp x y)
                (subsetp y z))
           (subsetp x z)))



(defthm len-v-ids
  (equal (len (v-ids x))
         (len x)))

;;|---------------------------------|
;;|                                    |
;;|             tomissives             |
;;|                                 |
;;|---------------------------------|
(defun ToMissives (TmLst)
  ;;  convert a Traveling missives List to a Missive List
  (if (endp TmLst)
      nil
    (let* ((tr (car TmLst))
           (id (IdTm tr))
           (org (OrgTm tr))
           (frm (FrmTm Tr))
           (dest (DestTm tr))
           (Flit (FlitTM tr))
           (time (timeTM tr)))
      (cons (list Id org frm dest Flit time)
            (ToMissives (cdr TmLst))))))

;; for the proof of the correctness of GeNOC
;; two important lemmas are needed

;; the first one rewrites (ToMissives (extract-sublst ..))
;; to (extract-sublst (tomissives) ... )
(defthm tomissives-append     ;; OK
  ;; we first link ToMissives and append
  (equal (ToMissives (append A B))
         (append (ToMissives A) (ToMissives B))))

(defthm m-ids-tomissives
  (equal (M-ids (ToMissives m)) (Tm-ids m)))

(defthm fwd-missivesp
  ;; as missivesp is disabled we prove this rule to add
  ;; the content of missivesp as hypotheses
  (implies (missivesp M NodeSet)
           (and (Validfields-M M )
                (subsetp (M-orgs M) NodeSet)
                (subsetp (M-dests M) NodeSet)
                (True-listp M)
                (No-duplicatesp-equal (M-ids M))))
  :rule-classes :forward-chaining)


(defthm tomissives-truelistp
  (implies (Tmissivesp M nodeset)
           (true-listp (tomissives m))))

(defthm to-missives-missivesp
  (implies (TMissivesp m nodeset)
           (Missivesp (ToMissives m) NodeSet)))

(defthm tomissives-len-equal
  (equal  (len (tomissives x))
          (len x)))

(defthm m-ids-append-invert
  ;; append out of the mids
  (equal (m-ids (append a b))
         (append (m-ids a) (m-ids b))))

(defthm rewrite-missivesp-append
  (implies (true-listp x)
           (equal (missivesp (append x y) nodeset)
                  (and (missivesp x nodeset)
                       (missivesp y nodeset)
                       (not-in (m-ids x) (m-ids y))))))



(defthm memberequal-implies-id-member-missives ;OK
  ;; member of a list then the id of the element is a member of the
  ;; ids of the list
  (implies (member-equal  x l)
           (member-equal (idm x) (m-ids l))))

(defthm missivesy-missives-cdry
  ;; missivesp y then missivesp cdr y
  (implies (missivesp y nodeset)
           (missivesp (cdr y) nodeset)))

;;|------------------------------|
;;|                              |
;;|            toTmissives                 |
;;|                                 |
;;|------------------------------|

(defun ToTMissives (TrLst)
  ;;  convert a Travel List to a Traveling Missive List
  (if (endp TrLst)
      nil
    (let* ((tr (car TrLst))
           (frm (FrmV tr))
           (org (OrgV tr))
           (curr (CurV tr))
           (dest (DestV tr))
           (id (IdV tr))
           (Flit (FlitV tr))
           (Time (TimeV tr))
           (Loc (LocV tr)))
      (cons (list id org curr frm dest Flit time loc)
            (ToTMissives (cdr TrLst))))))

(defun equal-locs (trlst TM)
  (if (endp TrLst)
      (if (endp TM)
          t
        nil)
      (and (equal (LocV (car trlst)) (LocTM (car TM)))
           (equal-locs (cdr trlst) (cdr TM)))))
(defthm TM-ids-ToMissives-V-ids    ;; OK
  (equal (TM-ids (ToTMissives x)) (V-ids x)))


;; for the proof of the correctness of GeNOC
;; two important lemmas are needed

;; the first one rewrites (ToMissives (extract-sublst ..))
;; to (extract-sublst (tomissives) ... )
(defthm ToTMissives-append    ;; OK
  ;; we first link ToTMissives and append
  (equal (ToTMissives (append A B))
         (append (ToTMissives A) (ToTMissives B))))

(defthm TMissivesp-ToMissives-bis
  (implies (trlstp trlst nodeset)
           (TMissivesp (ToTMissives TrLst) NodeSet)))

(defthm fwd-tmissivesp
  ;; as Tmissivesp is disabled we prove this rule to add
  ;; the content of Tmissivesp as hypotheses
  (implies (Tmissivesp M NodeSet)
           (and (Validfields-TM M nodeset)
                (subsetp (TM-orgs M) NodeSet)
                (subsetp (TM-curs M) NodeSet)
                (subsetp (TM-dests M) NodeSet)
                (True-listp M)
                (No-duplicatesp-equal (TM-ids M))))
  :rule-classes :forward-chaining)


(defthm tm-ids-append-invert
  (equal (tm-ids (append a b))
         (append (tm-ids a) (tm-ids b))))

(defthm memberequal-implies-id-member ;OK
  ;; the IDs of a member of a list are part of the ids of this list
  (implies (member-equal  x l)
           (member-equal (idtm x) (tm-ids l))))

(defthm tmissivesy-tmissives-cdry
  (implies (tmissivesp y nodeset)
           (tmissivesp (cdr y) nodeset)))


(defthm tm-ids-append-->append-tm-ids
  (equal (tm-ids (append x y))
         (append (tm-ids x) (tm-ids y))))
(defthm rewrite-nodups-tm-ids-append
  (equal (no-duplicatesp-equal (tm-ids (append x y)))
         (and (no-duplicatesp-equal (tm-ids x))
              (no-duplicatesp-equal (tm-ids y))
              (not-in (tm-ids x) (tm-ids y)))))
(in-theory (disable tm-ids-append-->append-tm-ids))
(defthm rewrite-validfields-tm-append
  (equal (validfields-tm (append x y) nodeset)
         (and (validfields-tm x nodeset)
              (validfields-tm y nodeset))))
(defthm tm-orgs-append
  (equal (tm-orgs (append x y))
         (append (tm-orgs x) (tm-orgs y))))
(defthm tm-curs-append
  (equal (tm-curs (append x y))
         (append (tm-curs x) (tm-curs y))))
(defthm tm-dests-append
  (equal (tm-dests (append x y))
         (append (tm-dests x) (tm-dests y))))
(in-theory (disable subsetp-append))
(defthm rewrite-subsetp-append-l
  (equal (subsetp (append x y) z)
         (and (subsetp x z)
              (subsetp y z))))
(defthm rewrite-tmissivesp-append
  (implies (true-listp tmissives1)
           (equal (tmissivesp (append tmissives1 tmissives2) nodeset)
                  (and (tmissivesp tmissives1 nodeset)
                       (tmissivesp tmissives2 nodeset)
                       (not-in (tm-ids tmissives1) (tm-ids tmissives2))))))
;;|------------------------------|
;;|                                 |
;;|              Travels            |
;;|                                 |
;;|------------------------------|

(defthm v-ids-append-->append-v-ids
  (equal (v-ids (append a b))
         (append (v-ids a) (v-ids b))))
(in-theory (disable v-ids-append-->append-v-ids))
(defthm append-v-ids-->v-ids-append
  (equal (append (v-ids trlst1) (v-ids trlst2))
         (v-ids (append trlst1 trlst2))))
(defthm rewrite-trlstp-append
  (implies (true-listp x)
           (equal (trlstp (append x y) nodeset)
                  (and (trlstp x nodeset)
                       (trlstp y nodeset)
                       (not-in (v-ids x) (v-ids y)))))
  :otf-flg t
  :hints (("Goal" :in-theory (e/d (locv v-ids-append-->append-v-ids) (append-v-ids-->v-ids-append)))))

(defthm fwd-trlstp
  ;; because we disable trlstp, this rule adds its content
  ;; as hypotheses
  (implies (TrLstp TrLst nodeset)
           (and (validfields-trlst trlst nodeset)
                (true-listp trlst)
                (no-duplicatesp-equal (v-ids trlst))))
  :rule-classes :forward-chaining)

;;|------------------------------|
;;|                                 |
;;|                 rev                 |
;;|------------------------------|
(defun rev (x)
  (declare (xargs :guard (true-listp x)))
  (if (endp x)
      nil
    (append (rev (cdr x)) (list (car x)))))

(defthm subsetp-rev-l
  (equal (subsetp (rev x) y)
         (subsetp x y)))
(defthm member-rev
  (iff (member-equal a (rev x))
       (member-equal a x)))
(defthm subsetp-rev-r
  (equal (subsetp x (rev y))
         (subsetp x y)))


;;|------------------------------|
;;|                                 |
;;|            Transactionsp                 |
;;|                                 |
;;|------------------------------|

(defthm fwd-chaining-transactionsp
  (implies (transactionsp trs nodeset)
           (and (validfields-t trs)
                (true-listp trs)
                (subsetp (t-orgs trs) nodeset)
                (subsetp (t-dests trs) nodeset)
                (no-duplicatesp-equal (t-ids trs))))
  :rule-classes :forward-chaining)


;;|------------------------------|
;;|                                 |
;;|            ntkstate                 |
;;|                                 |
;;|------------------------------|

;; valid ntkstate
(defthm validstate-entry-implies-coord-and-buffer
  (implies (and (validstate-entryp x)
                (consp x))
           (and (validcoord (car x))
                (validbuffer (cadr x)))))#|ACL2s-ToDo-Line|#