summaryrefslogtreecommitdiff
path: root/books/workshops/2013/van-gastel-schmaltz/books/GeNoC-misc.lisp
blob: 51cec40b0c3500a844c6ad2580fe3c1a280a0896 (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
#|$ACL2s-Preamble$;
;; Amr HELMY
;; Miscelaneous definitions and lemmas

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

(in-package "ACL2")

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

;;
;;  nil_list
;;
(defun nil_list (n)
  (if (zp n)
    nil
    (cons nil (nil_list (1- n)))))

;;|-------------------------------------------------|
;;|                                                    |
;;|                    Not-in                            |
;;|                                                    |
;;|-------------------------------------------------|
(defun not-in-test (x y)
  (not (member-equal x y)))
(create-for-all not-in-test :name not-in :extra (y))
(defcong permp equal (not-in x y) 2)
(defthm not-in-append-alt
  (equal (not-in x (append y z))
         (and (not-in x y)
              (not-in x z))))
(defthm not-in-empty-list-always-true
  (implies (endp y)
           (not-in x y)))
(defthm subset-not-in
  (implies (and (subsetp x y)
                (not-in a y))
           (not-in a x)))
(defcong permp equal (not-in x y) 2)
(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 subsetp-cons-cdr-part
  (implies (subsetp (cons x xs) y)
           (subsetp xs y)))

(defthm subsetp-cons-car-part
  (implies (subsetp (cons x xs) y)
           (member-equal x y)))

;;|---------------------------------|
;;|                                    |
;;|             tomissives             |
;;|                                 |
;;|---------------------------------|
(defun ToMissive-TM (tr)
    (let* ((id (IdTm tr))
           (org (OrgTm tr))
           (frm (FrmTm Tr))
           ;(dest (DestTm tr))
           (Flit (FlitTM tr))
           (time (timeTM tr)))
     (M Id org frm Flit time)))
(create-map tomissive-TM :name tomissives)

;; 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 m-ids-tomissives
  (equal (M-ids (ToMissives m)) (Tm-ids m))
    :hints (("Goal" :in-theory (e/d (v-id 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 tmissives nodeset)
           (Missivesp (ToMissives tmissives) NodeSet))
      :hints (("Goal" :in-theory (e/d (v-id m-_id M M-p weak-M-p M-frame TM-frame M-flit M-time M-org)()) ))
)

(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 missivesy-missives-cdry
  ;; missivesp y then missivesp cdr y
  (implies (missivesp y nodeset)
           (missivesp (cdr y) nodeset)))

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

(defun ToTMissive-V (tr)
    (let ((frm (FrmV tr))
           (org (OrgV tr))
           (curr (CurV tr))
           ;(dest (DestV tr))
           (id (IdV tr))
           (Flit (FlitV tr))
           (Time (TimeV tr))
           (Loc (LocV tr)))
      (TM id org curr frm Flit time loc)))

(create-map ToTMissive-V :name ToTMissives)

(defun tomissive-V (v)
  (M (IdV v) (OrgV v) (FrmV v) (FlitV v) (TimeV v)))

(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))
      :hints (("Goal" :in-theory (e/d (v-id TM)()) ))
)


;; 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 TMissivesp-ToMissives-bis
  (implies (trlstp trlst nodeset)
           (TMissivesp (ToTMissives TrLst) NodeSet))
        :hints (("Goal" :in-theory (e/d (v-id TM TM-p weak-TM-p TM-frame TM-flit TM-time TM-org TM-cur TM-loc)()) ))
        )


(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 tmissivesy-tmissives-cdry
  (implies (tmissivesp y nodeset)
           (tmissivesp (cdr y) nodeset)))

(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)))))
(defthm rewrite-validfields-tm-append
  (equal (validfields-tm (append x y) nodeset)
         (and (validfields-tm x nodeset)
              (validfields-tm y nodeset))))
(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 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)

(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)))



;;|------------------------------|
;;|                                 |
;;|            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|#