~ubuntu-branches/ubuntu/wily/acl2/wily

« back to all changes in this revision

Viewing changes to books/workshops/1999/embedded/Proof-Of-Contribution/Proof-Of-Correctness-OneCycle.lisp

  • Committer: Package Import Robot
  • Author(s): Camm Maguire
  • Date: 2015-01-16 10:35:45 UTC
  • mfrom: (3.3.26 sid)
  • Revision ID: package-import@ubuntu.com-20150116103545-prehe9thgo79o8w8
Tags: 7.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
(in-package "ACL2")
 
3
 
 
4
(include-book "Disjoint-lists")
 
5
 
 
6
; The following is commented out starting with v2-7 because a more general
 
7
; macro e/d is now part of ACL2.
 
8
; (defmacro e/d (enable disable)
 
9
;  `(union-theories ',enable (disable ,@disable)))
 
10
 
 
11
(defun in-range (idx l)
 
12
  (and
 
13
   (integerp idx)
 
14
   (>= idx 0)
 
15
   (< idx (len l))))
 
16
 
 
17
(in-theory (enable in-range))
 
18
(in-theory (disable mod floor))
 
19
 
 
20
(defun mlambda-fn (args form)
 
21
  (declare (xargs :guard (symbol-listp args)))
 
22
  (cond ((atom form)
 
23
         (cond ((member form args) form)
 
24
               (t (list 'QUOTE form))))
 
25
        (t (list 'CONS (mlambda-fn args (car form))
 
26
                 (mlambda-fn args (cdr form))))))
 
27
 
 
28
(defmacro mlambda (args form)
 
29
  (declare (xargs :guard (symbol-listp args)))
 
30
  (mlambda-fn args form))
 
31
 
 
32
 
 
33
(defmacro qr-guard (x y)
 
34
  (mlambda (x y)
 
35
    (and (force (rationalp x))
 
36
         (force (rationalp y))
 
37
         (force (not (equal 0 y))))))
 
38
 
 
39
(defun type-expected (vars)
 
40
  (cond
 
41
   ( (and (true-listp vars)
 
42
          (equal (len vars) 1))
 
43
     'Bool)
 
44
   ( (and (true-listp vars)
 
45
          (equal (len vars) (len *rns*)))
 
46
     'Int)
 
47
   ( t
 
48
     'Wrong-Typing)))
 
49
 
 
50
 
 
51
(defthm IN-RANGE-I-ON-M-IMPLIES-IN-RANGE-I-1-ON-CDR-M
 
52
                     (IMPLIES (AND (IN-RANGE IDX M)
 
53
                                   (NOT (ENDP M))
 
54
                                   (NOT (ZP IDX)))
 
55
                              (IN-RANGE (1- IDX) (CDR M))))
 
56
 
 
57
(defun positivep (v)
 
58
  (and
 
59
   (integerp v)
 
60
   (> v 0)))
 
61
 
 
62
 
 
63
(defun positive-list (l)
 
64
  (if (endp l)
 
65
      (null l)
 
66
    (and (positivep (car l))
 
67
         (positive-list (cdr l)))))
 
68
 
 
69
 
 
70
(defun boolean-to-int (bool)
 
71
  (if bool 1 0))
 
72
 
 
73
(defun int-to-bool (int) 
 
74
  (equal int 1))
 
75
 
 
76
(defun make-n-list (el n)
 
77
  (if
 
78
      (zp n)
 
79
      nil
 
80
    (cons el (make-n-list el (1- n)))))
 
81
 
 
82
(defun eventually-make-list (l n)
 
83
  (if (equal (len l) 1)
 
84
      (make-n-list (car l) n)
 
85
    l))
 
86
 
 
87
(defun double-induct (idx n)
 
88
  (if (zp idx)  (+ idx n)
 
89
    (double-induct (1- idx) (1- n))))
 
90
 
 
91
(defthm el-of-makelist-is-el
 
92
 (implies
 
93
  (and
 
94
   (integerp n)
 
95
   (in-range idx (make-n-list el n)))
 
96
  (equal 
 
97
   (nth idx (make-n-list el n))
 
98
   el))
 
99
 :hints (("Goal" :induct (double-induct idx n))
 
100
         ("Subgoal *1/1" :use make-n-list)))
 
101
 
 
102
  
 
103
 
 
104
 
 
105
 
 
106
 
 
107
(in-theory (disable my-or-3 my-or-2))
 
108
 
 
109
 
 
110
 
 
111
 
 
112
 
 
113
(defun opcode (ins) (nth 0 ins))
 
114
(defun par1   (ins) (nth 1 ins))
 
115
(defun par2   (ins) (nth 2 ins))
 
116
(defun par3   (ins) (nth 3 ins))
 
117
(defun par4   (ins) (nth 4 ins))
 
118
 
 
119
 
 
120
(defun mem  (s) (car  s))
 
121
(defun pcc  (s) (cadr s))
 
122
(defun code (s) (cddr  s))
 
123
 
 
124
(defun make-state (mem pcc code)
 
125
  (cons mem (cons pcc code)))
 
126
 
 
127
 
 
128
(defun initial-state (prog)
 
129
  (make-state (car prog) 0 (cdr prog)))
 
130
 
 
131
 
 
132
 
 
133
 
 
134
 
 
135
 
 
136
(defun gem-instruction-p (instr mem)
 
137
  (and
 
138
   (true-listp instr)
 
139
   (or
 
140
    (and
 
141
     (equal (opcode instr) 'gem-add)
 
142
     (equal (len instr) 4)
 
143
     (is-mem-cell-p (get-cell (par1 instr) mem))
 
144
     (is-mem-cell-p (get-cell (par2 instr) mem))
 
145
     (is-mem-cell-p (get-cell (par3 instr) mem))
 
146
     (equal (var-type (get-cell (par1 instr) mem)) 'Int) )
 
147
    (and
 
148
     (equal (opcode instr) 'gem-sub)
 
149
     (equal (len instr) 4)
 
150
     (is-mem-cell-p (get-cell (par1 instr) mem))
 
151
     (is-mem-cell-p (get-cell (par2 instr) mem))
 
152
     (is-mem-cell-p (get-cell (par3 instr) mem))
 
153
     (equal (var-type (get-cell (par1 instr) mem)) 'Int)
 
154
     (equal (var-type (get-cell (par2 instr) mem)) 'Int) 
 
155
     (equal (var-type (get-cell (par3 instr) mem)) 'Int) )
 
156
    (and
 
157
     (equal (opcode instr) 'gem-equ)
 
158
     (equal (len instr) 4)
 
159
     (is-mem-cell-p (get-cell (par1 instr) mem))
 
160
     (is-mem-cell-p (get-cell (par2 instr) mem))
 
161
     (is-mem-cell-p (get-cell (par3 instr) mem))
 
162
     (equal (var-type (get-cell (par1 instr) mem)) 'Bool) )
 
163
     )))
 
164
 
 
165
 
 
166
(defun gem-instruction-list-p (instlist mem)
 
167
  (if
 
168
      (endp instlist)
 
169
      (null instlist)
 
170
    (and
 
171
     (gem-instruction-p (car instlist) mem)
 
172
     (gem-instruction-list-p (cdr instlist) mem))))
 
173
 
 
174
 
 
175
(defun gem-program-p (prog)
 
176
  (and
 
177
   (true-listp prog)
 
178
   (equal (len prog) 2)
 
179
   (is-typed-amem-p (car prog))
 
180
   (bounded-amem-p  (car prog))
 
181
   (gem-instruction-list-p (cdr prog) (car prog))))
 
182
 
 
183
 
 
184
(defun gem-statep (x)
 
185
  (and (consp x)
 
186
       (consp (cdr x))
 
187
       (integerp (pcc x))
 
188
       (is-typed-amem-p (mem x))
 
189
       (bounded-amem-p (mem x))     ;;; new
 
190
       (gem-instruction-list-p (code x) (mem x))))
 
191
 
 
192
 
 
193
(defthm nth-instruction-of-gem-list-is-gem-instruction
 
194
 (implies
 
195
  (gem-instruction-list-p gl mem)
 
196
  (or
 
197
   (null (nth idx gl))
 
198
   (gem-instruction-p (nth idx gl) mem)))
 
199
 :hints (("Goal" :in-theory (disable gem-instruction-p)))
 
200
 :rule-classes nil)
 
201
 
 
202
(defthm an-instruction-of-gem-program-is-null-or-gem-instruction
 
203
 (implies
 
204
  (gem-statep st)
 
205
  (or
 
206
   (null (nth (pcc st) (code st)))
 
207
   (gem-instruction-p (nth (pcc st) (code st)) (mem st))))
 
208
 :hints (("Goal" :in-theory (disable code mem pcc gem-instruction-list-p gem-instruction-p)
 
209
         :use (:instance nth-instruction-of-gem-list-is-gem-instruction
 
210
                         (gl (code st))
 
211
                         (idx (pcc st))
 
212
                         (mem (mem st)))))
 
213
 :rule-classes nil)
 
214
 
 
215
 
 
216
 
 
217
 
 
218
 
 
219
 
 
220
 
 
221
 
 
222
 
 
223
 
 
224
 
 
225
(defun rtm-instruction-p (instr mem)
 
226
  (and
 
227
   (true-listp instr)
 
228
   (or
 
229
    (and
 
230
     (equal (opcode instr) 'rtm-add)
 
231
     (equal (len instr) 4)
 
232
     (is-mem-cell-p (get-cell (par1 instr) mem))
 
233
     (is-mem-cell-p (get-cell (par2 instr) mem))
 
234
     (is-mem-cell-p (get-cell (par3 instr) mem))
 
235
     (equal (var-type (get-cell (par1 instr) mem)) 'Int) 
 
236
     (equal (var-type (get-cell (par2 instr) mem)) 'Int)
 
237
     (equal (var-type (get-cell (par3 instr) mem)) 'Int)
 
238
     (positivep (par4 instr)))
 
239
    (and
 
240
     (equal (opcode instr) 'rtm-sub)
 
241
     (equal (len instr) 4)
 
242
     (is-mem-cell-p (get-cell (par1 instr) mem))
 
243
     (is-mem-cell-p (get-cell (par2 instr) mem))
 
244
     (is-mem-cell-p (get-cell (par3 instr) mem))
 
245
     (equal (var-type (get-cell (par1 instr) mem)) 'Int) 
 
246
     (equal (var-type (get-cell (par2 instr) mem)) 'Int)
 
247
     (equal (var-type (get-cell (par3 instr) mem)) 'Int)
 
248
     (positivep (par4 instr)))
 
249
    (and
 
250
     (equal (opcode instr) 'rtm-equ)
 
251
     (equal (len instr) 4)
 
252
     (is-mem-cell-p (get-cell (par1 instr) mem))
 
253
     (is-mem-cell-p (get-cell (par2 instr) mem))
 
254
     (is-mem-cell-p (get-cell (par3 instr) mem))
 
255
     (equal (var-type (get-cell (par1 instr) mem)) 'Int)
 
256
     (equal (var-type (get-cell (par2 instr) mem)) 'Int)
 
257
     (equal (var-type (get-cell (par3 instr) mem)) 'Int))
 
258
    (and
 
259
     (equal (opcode instr) 'rtm-or)
 
260
     (equal (len instr) 4)
 
261
     (is-mem-cell-p (get-cell (par1 instr) mem))
 
262
     (is-mem-cell-p (get-cell (par2 instr) mem))
 
263
     (is-mem-cell-p (get-cell (par3 instr) mem))
 
264
     (equal (var-type (get-cell (par1 instr) mem)) 'Int)
 
265
     (equal (var-type (get-cell (par2 instr) mem)) 'Int)
 
266
     (equal (var-type (get-cell (par3 instr) mem)) 'Int))
 
267
    (and
 
268
     (equal (opcode instr) 'rtm-and)
 
269
     (equal (len instr) 4)
 
270
     (is-mem-cell-p (get-cell (par1 instr) mem))
 
271
     (is-mem-cell-p (get-cell (par2 instr) mem))
 
272
     (is-mem-cell-p (get-cell (par3 instr) mem))
 
273
     (equal (var-type (get-cell (par1 instr) mem)) 'Int)
 
274
     (equal (var-type (get-cell (par2 instr) mem)) 'Int)
 
275
     (equal (var-type (get-cell (par3 instr) mem)) 'Int)))))
 
276
 
 
277
(defun rtm-instruction-list-p (instlist mem)
 
278
  (if
 
279
      (endp instlist)
 
280
      (null instlist)
 
281
    (and
 
282
     (rtm-instruction-p (car instlist) mem)
 
283
     (rtm-instruction-list-p (cdr instlist) mem))))
 
284
 
 
285
 
 
286
(defun rtm-program-p (prog)
 
287
  (and
 
288
   (true-listp prog)
 
289
   (equal (len prog) 2)
 
290
   (is-typed-amem-p (car prog))
 
291
   (rtm-instruction-list-p (cdr prog) (car prog))))
 
292
 
 
293
 
 
294
 
 
295
 
 
296
(defun rtm-statep (x)
 
297
  (and (consp x)
 
298
       (consp (cdr x))
 
299
       (integerp (pcc x))
 
300
       (is-typed-amem-p (mem x))
 
301
       (rtm-instruction-list-p (code x) (mem x))))
 
302
 
 
303
 
 
304
 
 
305
 
 
306
 
 
307
 
 
308
 
 
309
(defthm nth-instruction-of-rtm-list-is-rtm-instruction
 
310
 (implies
 
311
  (rtm-instruction-list-p gl mem)
 
312
  (or
 
313
   (null (nth idx gl))
 
314
   (rtm-instruction-p (nth idx gl) mem)))
 
315
 :hints (("Goal" :in-theory (disable rtm-instruction-p)))
 
316
 :rule-classes nil)
 
317
 
 
318
(defthm an-instruction-of-rtm-program-is-null-or-rtm-instruction
 
319
 (implies
 
320
  (rtm-statep st)
 
321
  (or
 
322
   (null (nth (pcc st) (code st)))
 
323
   (rtm-instruction-p (nth (pcc st) (code st)) (mem st))))
 
324
 :hints (("Goal" :in-theory (disable code mem pcc rtm-instruction-list-p rtm-instruction-p)
 
325
         :use (:instance nth-instruction-of-rtm-list-is-rtm-instruction
 
326
                         (gl (code st))
 
327
                         (idx (pcc st))
 
328
                         (mem (mem st)))))
 
329
 :rule-classes nil)
 
330
 
 
331
 
 
332
 
 
333
 
 
334
 
 
335
 
 
336
(defun sum-and-update (c1 c2 c3 prime mem)
 
337
  (make-cell 
 
338
   (mod
 
339
    (+
 
340
     (var-value (get-cell c2 mem))
 
341
     (var-value (get-cell c3 mem)))
 
342
    prime)
 
343
   (var-attribute (get-cell c1 mem))
 
344
   (var-type (get-cell c1 mem))))
 
345
 
 
346
        
 
347
(DEFUN SUM-AND-UPDATE-NOREST  (C1 C2 C3 MEM)
 
348
  (MAKE-CELL (mod
 
349
              (+ (VAR-VALUE (GET-CELL C2 MEM))
 
350
                 (VAR-VALUE (GET-CELL C3 MEM)))
 
351
              (prod *rns*))
 
352
  (VAR-ATTRIBUTE (GET-CELL C1 MEM))
 
353
  (VAR-TYPE (GET-CELL C1 MEM))))
 
354
 
 
355
(defun sub-and-update (c1 c2 c3 prime mem)
 
356
  (make-cell 
 
357
   (mod
 
358
    (-
 
359
     (var-value (get-cell c2 mem))
 
360
     (var-value (get-cell c3 mem)))
 
361
    prime)
 
362
   (var-attribute (get-cell c1 mem))
 
363
   (var-type (get-cell c1 mem))))
 
364
 
 
365
        
 
366
(DEFUN SUB-AND-UPDATE-NOREST  (C1 C2 C3 MEM)
 
367
  (MAKE-CELL (mod 
 
368
              (- (VAR-VALUE (GET-CELL C2 MEM))
 
369
                 (VAR-VALUE (GET-CELL C3 MEM)))
 
370
              (prod *rns*))
 
371
  (VAR-ATTRIBUTE (GET-CELL C1 MEM))
 
372
  (VAR-TYPE (GET-CELL C1 MEM))))
 
373
 
 
374
 
 
375
 
 
376
(defun and-update (c1 c2 c3 mem)
 
377
  (make-cell 
 
378
   (boolean-to-int
 
379
    (and
 
380
     (int-to-bool (var-value (get-cell c2 mem)))
 
381
     (int-to-bool (var-value (get-cell c3 mem)))))
 
382
   (var-attribute (get-cell c1 mem))
 
383
   (var-type (get-cell c1 mem))))
 
384
 
 
385
(defun or-update (c1 c2 c3 mem)
 
386
  (make-cell 
 
387
   (boolean-to-int
 
388
    (or
 
389
     (int-to-bool (var-value (get-cell c2 mem)))
 
390
     (int-to-bool (var-value (get-cell c3 mem)))))
 
391
   (var-attribute (get-cell c1 mem))
 
392
   (var-type (get-cell c1 mem))))
 
393
 
 
394
(defun gen-eq-update (c1 c2 c3 mem)
 
395
  (make-cell 
 
396
   (boolean-to-int
 
397
    (equal
 
398
     (var-value (get-cell c2 mem))
 
399
     (var-value (get-cell c3 mem))))
 
400
   (var-attribute (get-cell c1 mem))
 
401
   (var-type (get-cell c1 mem))))
 
402
 
 
403
 
 
404
 
 
405
 
 
406
 
 
407
(defthm sum-and-update-returns-a-mem-cell
 
408
 (implies
 
409
  (and
 
410
   (equal (var-type (get-cell c1 mem)) 'Int) ; This is added to account for booleans
 
411
   (is-mem-cell-p (get-cell c1 mem)) 
 
412
   (is-mem-cell-p (get-cell c2 mem)) 
 
413
   (is-mem-cell-p (get-cell c3 mem)) 
 
414
   (positivep prime))
 
415
  (is-mem-cell-p (sum-and-update c1 c2 c3 prime mem)))
 
416
 :hints (("Goal" :in-theory (enable mod make-cell var-type var-attribute var-value)))
 
417
 :rule-classes :forward-chaining)
 
418
 
 
419
#|
 
420
(defthm gcd-unfold 
 
421
 (equal (g-c-d x y)
 
422
        (IF (ZP X)
 
423
            Y
 
424
            (IF (ZP Y)
 
425
                X
 
426
                (IF (<= X Y)
 
427
                    (G-C-D X (- Y X))
 
428
                    (G-C-D (- X Y) Y)))))
 
429
  :hints (("Goal" :in-theory (enable g-c-d nonneg-int-gcd 
 
430
                                     (:executable-counterpart nonneg-int-gcd)
 
431
                                     (:induction nonneg-int-gcd)))))
 
432
|#
 
433
  
 
434
 
 
435
(defthm posp-all-unfold 
 
436
  (equal (posp-all l)
 
437
         (IF (ENDP L)
 
438
             T
 
439
             (AND (POSP (CAR L))
 
440
                  (POSP-ALL (CDR L)))))
 
441
  :hints (("Goal" :in-theory (enable posp-all))))
 
442
 
 
443
(defun integer>1-listp (l)
 
444
  (if (endp l)
 
445
      (null l)
 
446
    (and (integerp (car l))
 
447
         (> (car l) 1)
 
448
         (integer>1-listp (cdr l)))))
 
449
 
 
450
 
 
451
(defthm int>1-unfold 
 
452
  (equal (integer>1-listp l)
 
453
         (IF (ENDP L)
 
454
             (NULL L)
 
455
             (AND (INTEGERP (CAR L))
 
456
                  (> (CAR L) 1)
 
457
                  (INTEGER>1-LISTP (CDR L))))))
 
458
 
 
459
 
 
460
(defthm fact-bout-rns
 
461
  (and
 
462
   (integer-listp *rns*)
 
463
   (rel-prime-moduli *rns*)
 
464
   (posp-all *rns*)
 
465
   (integer>1-listp *rns*)
 
466
   (not (null *rns*))
 
467
   (natp (prod *rns*))
 
468
   (> (prod *rns*) 1))
 
469
  :hints (("Goal" :in-theory (enable prod posp rel-prime-moduli rel-prime-all rel-prime g-c-d (:executable-counterpart nonneg-int-gcd))))
 
470
  :rule-classes nil)
 
471
 
 
472
(in-theory (disable 
 
473
            ;gcd-unfold 
 
474
            posp-all-unfold int>1-unfold))
 
475
 
 
476
(defthm greater-one-means-greater-zero
 
477
  (implies (integer>1-listp rns) (posp-all rns))
 
478
  :hints (("Goal" 
 
479
           :in-theory (enable posp-all posp)))
 
480
  :rule-classes nil)
 
481
 
 
482
(DEFTHM SILS1A
 
483
  (IMPLIES (AND (POSP M) (INTEGERP A))
 
484
           (NATP (MOD A M)))
 
485
  :HINTS
 
486
  (("Goal" :IN-THEORY
 
487
    '((:REWRITE INTEGERP-MOD-EXP)
 
488
      (:DEFINITION NATP)
 
489
      (:DEFINITION POSP))
 
490
    :USE
 
491
    ((:INSTANCE MOD-TYPE-EXP (X A) (Y M))
 
492
     (:INSTANCE MOD-=-0-EXP (X A) (Y M)))))
 
493
  :rule-classes nil)
 
494
 
 
495
(defthm sum-and-update-norest-returns-a-mem-cell
 
496
 (implies
 
497
  (and
 
498
   (equal (var-type (get-cell c1 mem)) 'Int)
 
499
   (is-mem-cell-p (get-cell c1 mem)) 
 
500
   (is-mem-cell-p (get-cell c2 mem)) 
 
501
   (is-mem-cell-p (get-cell c3 mem)))
 
502
  (and
 
503
   (is-mem-cell-p (sum-and-update-norest c1 c2 c3 mem))
 
504
   (bounded-value (sum-and-update-norest c1 c2 c3 mem))
 
505
   (equal (var-type (sum-and-update-norest c1 c2 c3 mem)) 'Int))   )
 
506
 :hints (("Goal"
 
507
          :use (fact-bout-rns
 
508
                (:instance sils1a
 
509
                           (a (+ (var-value (get-cell c2 mem)) (var-value (get-cell c3 mem))))
 
510
                           (m (prod *rns*)))
 
511
                (:instance mod-bounds-exp 
 
512
                          (x (+ (var-value (get-cell c2 mem)) (var-value (get-cell c3 mem))))
 
513
                          (y (prod *rns*))))
 
514
          :in-theory (enable posp make-cell var-type var-attribute var-value)))
 
515
 :rule-classes :forward-chaining)
 
516
 
 
517
 
 
518
(defthm sub-and-update-returns-a-mem-cell
 
519
 (implies
 
520
  (and
 
521
   (equal (var-type (get-cell c1 mem)) 'Int)
 
522
   (is-mem-cell-p (get-cell c1 mem)) 
 
523
   (is-mem-cell-p (get-cell c2 mem)) 
 
524
   (is-mem-cell-p (get-cell c3 mem)) 
 
525
   (positivep prime) )
 
526
  (is-mem-cell-p (sub-and-update c1 c2 c3 prime mem)))
 
527
 :hints (("Goal" :in-theory (enable mod make-cell var-type var-attribute var-value)))
 
528
 :rule-classes :forward-chaining)
 
529
 
 
530
 
 
531
(defthm sub-and-update-norest-returns-a-mem-cell
 
532
 (implies
 
533
  (and
 
534
   (equal (var-type (get-cell c1 mem)) 'Int)
 
535
   (is-mem-cell-p (get-cell c1 mem)) 
 
536
   (is-mem-cell-p (get-cell c2 mem)) 
 
537
   (is-mem-cell-p (get-cell c3 mem)))
 
538
  (and
 
539
   (is-mem-cell-p (sub-and-update-norest c1 c2 c3 mem))
 
540
   (bounded-value (sub-and-update-norest c1 c2 c3 mem))
 
541
   (equal (var-type (sub-and-update-norest c1 c2 c3 mem)) 'Int))   )
 
542
 :hints (("Goal"
 
543
          :use (fact-bout-rns
 
544
                (:instance sils1a
 
545
                           (a (- (var-value (get-cell c2 mem)) (var-value (get-cell c3 mem))))
 
546
                           (m (prod *rns*)))
 
547
                (:instance mod-bounds-exp 
 
548
                          (x (- (var-value (get-cell c2 mem)) (var-value (get-cell c3 mem))))
 
549
                          (y (prod *rns*))))
 
550
          :in-theory (enable posp make-cell var-type var-attribute var-value)))
 
551
 :rule-classes :forward-chaining)
 
552
 
 
553
 
 
554
(defthm and-update-returns-a-mem-cell
 
555
 (implies
 
556
  (and
 
557
   (is-mem-cell-p (get-cell c1 mem)) 
 
558
   (is-mem-cell-p (get-cell c2 mem)) 
 
559
   (is-mem-cell-p (get-cell c3 mem))) 
 
560
  (is-mem-cell-p (and-update c1 c2 c3 mem)))
 
561
 :hints (("Goal" :in-theory (enable my-or-2 make-cell var-type var-attribute var-value)))
 
562
 :rule-classes :forward-chaining)
 
563
 
 
564
(defthm or-update-returns-a-mem-cell
 
565
 (implies
 
566
  (and
 
567
   (is-mem-cell-p (get-cell c1 mem)) 
 
568
   (is-mem-cell-p (get-cell c2 mem)) 
 
569
   (is-mem-cell-p (get-cell c3 mem))) 
 
570
  (is-mem-cell-p (or-update c1 c2 c3 mem)))
 
571
 :hints (("Goal" :in-theory (enable my-or-2 make-cell var-type var-attribute var-value)))
 
572
 :rule-classes :forward-chaining)
 
573
 
 
574
(defthm gen-eq-update-returns-a-mem-cell
 
575
 (implies
 
576
  (and
 
577
   (is-mem-cell-p (get-cell c1 mem)) 
 
578
   (is-mem-cell-p (get-cell c2 mem)) 
 
579
   (is-mem-cell-p (get-cell c3 mem))) 
 
580
  (and
 
581
   (bounded-value (gen-eq-update c1 c2 c3 mem))
 
582
   (is-mem-cell-p (gen-eq-update c1 c2 c3 mem))))
 
583
 :hints (("Goal"
 
584
          :use (fact-bout-rns
 
585
                (:instance sils1a
 
586
                           (a (boolean-to-int (equal (var-value (get-cell c2 mem)) (var-value (get-cell c3 mem)))))
 
587
                           (m (prod *rns*)))
 
588
                (:instance mod-bounds-exp 
 
589
                          (x (boolean-to-int (equal (var-value (get-cell c2 mem)) (var-value (get-cell c3 mem)))))
 
590
                          (y (prod *rns*))))
 
591
          :in-theory (enable posp my-or-2 make-cell var-type var-attribute var-value)))
 
592
 :rule-classes :forward-chaining)
 
593
 
 
594
 
 
595
 
 
596
 
 
597
 
 
598
 
 
599
 
 
600
 
 
601
 
 
602
 
 
603
 
 
604
(defun gem-add (a b c s)
 
605
  (make-state
 
606
   (put-cell a
 
607
             (sum-and-update-norest a b c (mem s))
 
608
             (mem s))
 
609
   (1+ (pcc s))
 
610
   (code s)))
 
611
 
 
612
(defun gem-sub (a b c s)
 
613
  (make-state
 
614
   (put-cell a
 
615
             (sub-and-update-norest a b c (mem s))
 
616
             (mem s))
 
617
   (1+ (pcc s))
 
618
   (code s)))
 
619
 
 
620
(defun rtm-add (a b c d s)
 
621
  (make-state
 
622
   (put-cell a
 
623
             (sum-and-update a b c d (mem s))
 
624
             (mem s))
 
625
   (1+ (pcc s))
 
626
   (code s)))
 
627
 
 
628
(defun rtm-sub (a b c d s)
 
629
  (make-state
 
630
   (put-cell a
 
631
             (sub-and-update a b c d (mem s))
 
632
             (mem s))
 
633
   (1+ (pcc s))
 
634
   (code s)))
 
635
 
 
636
 
 
637
(defun rtm-and (a b c s)
 
638
  (make-state
 
639
   (put-cell a
 
640
             (and-update a b c (mem s))
 
641
             (mem s))
 
642
   (1+ (pcc s))
 
643
   (code s)))
 
644
 
 
645
(defun rtm-or (a b c s)
 
646
  (make-state
 
647
   (put-cell a
 
648
             (or-update a b c (mem s))
 
649
             (mem s))
 
650
   (1+ (pcc s))
 
651
   (code s)))
 
652
 
 
653
(defun generic-eql (a b c s)
 
654
  (make-state
 
655
   (put-cell a
 
656
             (gen-eq-update a b c (mem s))
 
657
             (mem s))
 
658
   (1+ (pcc s))
 
659
   (code s)))
 
660
 
 
661
 
 
662
 
 
663
(defun execute-instruction (st)
 
664
  (let
 
665
      ((op (opcode (nth (pcc st) (code st))))
 
666
       (ins (nth (pcc st) (code st))))
 
667
  (case op
 
668
        (gem-add  (gem-add     (par1 ins) (par2 ins) (par3 ins) st))
 
669
        (gem-sub  (gem-sub     (par1 ins) (par2 ins) (par3 ins) st))
 
670
        (gem-equ  (generic-eql (par1 ins) (par2 ins) (par3 ins) st))
 
671
        (rtm-add  (rtm-add     (par1 ins) (par2 ins) (par3 ins) (par4 ins) st))
 
672
        (rtm-sub  (rtm-sub     (par1 ins) (par2 ins) (par3 ins) (par4 ins) st))
 
673
        (rtm-and  (rtm-and     (par1 ins) (par2 ins) (par3 ins) st))
 
674
        (rtm-or   (rtm-or      (par1 ins) (par2 ins) (par3 ins) st))
 
675
        (rtm-equ  (generic-eql (par1 ins) (par2 ins) (par3 ins) st))    
 
676
        (otherwise st))))
 
677
 
 
678
 
 
679
(defun execute-n-instructions (st n)
 
680
 (if
 
681
      (zp n)
 
682
      st
 
683
    (execute-n-instructions 
 
684
     (execute-instruction st)
 
685
     (1- n))))
 
686
 
 
687
 
 
688
 
 
689
(defthm instruction-incrementing-pvv
 
690
 (implies
 
691
  (>= (pcc st) 0)
 
692
  (>= (pcc (execute-instruction st)) 0)))
 
693
 
 
694
 
 
695
 
 
696
 
 
697
(defthm in-range-instruction-is-gem-instruction
 
698
 (implies 
 
699
  (and
 
700
   (in-range pcc code)
 
701
   (gem-instruction-list-p code mem))
 
702
  (gem-instruction-p (nth pcc code) mem))
 
703
 :hints (("Goal" :in-theory (disable gem-instruction-p)))
 
704
 :rule-classes :forward-chaining)
 
705
 
 
706
 
 
707
 
 
708
(defthm in-range-instruction-is-rtmm-instruction
 
709
 (implies 
 
710
  (and
 
711
   (in-range pcc code)
 
712
   (rtm-instruction-list-p code mem))
 
713
  (rtm-instruction-p (nth pcc code) mem))
 
714
 :hints (("Goal" :in-theory (disable rtm-instruction-p)))
 
715
 :rule-classes :forward-chaining)
 
716
 
 
717
 
 
718
 
 
719
 
 
720
 
 
721
(defthm null-not-in-range 
 
722
 (implies
 
723
  (and
 
724
   (integerp idx)
 
725
   (>= idx 0)
 
726
   (not (in-range idx l)))
 
727
  (null (nth idx l)))
 
728
 :rule-classes :forward-chaining)
 
729
 
 
730
(defthm pcc-not-in-range-means-null-instruction
 
731
  (implies
 
732
   (and
 
733
    (or
 
734
     (gem-statep st)
 
735
     (rtm-statep st))
 
736
    (>= (pcc st) 0)
 
737
    (not (in-range (pcc st) (code st))))
 
738
   (null (nth (pcc st) (code st))))
 
739
  :hints (("Goal" :cases ( (gem-statep st) (rtm-statep st))))
 
740
  :rule-classes :forward-chaining)
 
741
 
 
742
(defthm null-opcode-implies-execution-does-not-touch-state
 
743
  (implies
 
744
   (null (nth (pcc st) (code st)))
 
745
   (equal (execute-instruction st) st)))
 
746
 
 
747
(defthm execute-not-in-range-instruction-retrieves-same-state
 
748
  (implies
 
749
   (and
 
750
    (or
 
751
     (gem-statep st)
 
752
     (rtm-statep st) )
 
753
    (>= (pcc st) 0)
 
754
    (not (in-range (pcc st) (code st))))
 
755
   (equal (execute-instruction st) st))
 
756
  :hints (("Goal" :cases ( (gem-statep st) (rtm-statep st) ))
 
757
          ("Subgoal 2" :use ((:instance gem-statep (x st)) 
 
758
                             null-opcode-implies-execution-does-not-touch-state 
 
759
                             pcc-not-in-range-means-null-instruction))
 
760
          ("Subgoal 1" :use ((:instance rtm-statep (x st)) 
 
761
                             null-opcode-implies-execution-does-not-touch-state 
 
762
                             pcc-not-in-range-means-null-instruction))))
 
763
 
 
764
(in-theory (disable null-opcode-implies-execution-does-not-touch-state
 
765
                    execute-not-in-range-instruction-retrieves-same-state))
 
766
 
 
767
 
 
768
(defthm execute-instruction-does-not-touch-code (equal (code (execute-instruction st)) (code st)))
 
769
 
 
770
(defthm execute-n-instruction-does-not-touch-code (equal (code (execute-n-instructions st n)) (code st)))
 
771
 
 
772
(defthm execute-n-instruction-decomposition
 
773
 (implies
 
774
  (and
 
775
   (integerp n1)
 
776
   (integerp n2)
 
777
   (>= n1 0)
 
778
   (>= n2 0))
 
779
 (equal
 
780
  (execute-n-instructions st (+ n1 n2))
 
781
  (execute-n-instructions (execute-n-instructions st n1) n2)))
 
782
 :hints (("Goal" :in-theory (disable execute-instruction member-equal))))
 
783
 
 
784
 
 
785
(defthm putting-a-new-cell-preserves-typed-amem
 
786
 (implies
 
787
  (and
 
788
   (is-typed-amem-p mem)
 
789
   (is-mem-cell-p new-cell))
 
790
  (is-typed-amem-p (put-cell c new-cell mem)))
 
791
:hints (("Goal" :in-theory (enable put-cell))))
 
792
 
 
793
(defthm no-influence-of-putting-mem-cells
 
794
 (implies
 
795
  (and
 
796
   (is-mem-cell-p cell)
 
797
   (is-mem-cell-p (get-cell c1 mem)))
 
798
  (is-mem-cell-p (get-cell c1 (put-cell pos cell mem))))
 
799
 :hints ( ("Goal" :in-theory (enable put-cell get-cell) )))
 
800
 
 
801
 
 
802
(defthm putting-a-new-bounded-cell-preserves-boundedness
 
803
 (implies
 
804
  (and
 
805
   (bounded-amem-p mem)
 
806
   (bounded-value new-cell))
 
807
  (bounded-amem-p (put-cell c new-cell mem)))
 
808
:hints (("Goal" :in-theory (enable put-cell))))
 
809
 
 
810
(defthm no-influence-of-putting-bounded-cells
 
811
 (implies
 
812
  (and
 
813
   (bounded-value cell)
 
814
   (bounded-value (get-cell c1 mem)))
 
815
  (bounded-value (get-cell c1 (put-cell pos cell mem))))
 
816
 :hints ( ("Goal" :in-theory (enable put-cell get-cell) )))
 
817
 
 
818
 
 
819
 
 
820
(defthm putting-an-existing-cell-does-not-change-var-inclusion-right
 
821
 (implies
 
822
  (is-mem-cell-p (get-cell v mem))
 
823
  (iff (vars-inclusion m mem) (vars-inclusion m (put-cell v anyvalue mem))))
 
824
 :hints (("Goal" :in-theory (enable put-cell get-cell is-mem-cell-p))))
 
825
 
 
826
(defthm  putting-an-existing-cell-does-not-change-var-inclusion-left
 
827
 (implies
 
828
  (is-mem-cell-p (get-cell v mem))
 
829
  (iff (vars-inclusion mem m) (vars-inclusion (put-cell v anyvalue mem) m)))
 
830
 :hints (("Goal" :in-theory (enable put-cell get-cell is-mem-cell-p))))
 
831
 
 
832
 
 
833
 
 
834
(defthm execute-instruction-is-type-and-attribute-invariant-on-any-var 
 
835
 (and
 
836
 (equal (var-attribute (get-cell cell (mem st))) 
 
837
        (var-attribute (get-cell cell (mem (execute-instruction st)))))
 
838
 (equal (var-type (get-cell cell (mem st))) 
 
839
        (var-type (get-cell cell (mem (execute-instruction st))))))
 
840
 :hints (("Goal" :in-theory (enable put-cell get-cell make-cell mem make-state var-attribute var-type))))
 
841
 
 
842
 
 
843
 
 
844
(in-theory (disable 
 
845
            putting-an-existing-cell-does-not-change-var-inclusion-left
 
846
            putting-an-existing-cell-does-not-change-var-inclusion-right
 
847
            ))
 
848
 
 
849
 
 
850
 
 
851
 
 
852
 
 
853
 
 
854
;;(ld "Properties-of-Execute-Gem-Instruction-New.lisp" :ld-error-action :error)
 
855
 
 
856
 
 
857
 
 
858
(defthm any-mem-cell-is-conserved-after-execute-instruction-on-gemstate
 
859
 (implies (and
 
860
           (gem-statep st)
 
861
           (is-mem-cell-p (get-cell anycell (mem st))))
 
862
          (is-mem-cell-p (get-cell anycell (mem (execute-instruction st)))))
 
863
:hints (("Goal" :cases ( (null (nth (pcc st) (code st))) (gem-instruction-p (nth (pcc st) (code st)) (mem st))))
 
864
        ("Subgoal 3" :use an-instruction-of-gem-program-is-null-or-gem-instruction)
 
865
        ("Subgoal 1" :use (execute-instruction
 
866
                           (:instance sum-and-update-norest-returns-a-mem-cell
 
867
                                      (c1 (par1 (nth (pcc st) (code st))))
 
868
                                      (c2 (par2 (nth (pcc st) (code st))))
 
869
                                      (c3 (par3 (nth (pcc st) (code st))))
 
870
                                      (mem (mem st)))
 
871
                           (:instance sub-and-update-norest-returns-a-mem-cell
 
872
                                      (c1 (par1 (nth (pcc st) (code st))))
 
873
                                      (c2 (par2 (nth (pcc st) (code st))))
 
874
                                      (c3 (par3 (nth (pcc st) (code st))))
 
875
                                      (mem (mem st)))
 
876
                           (:instance gen-eq-update-returns-a-mem-cell
 
877
                                      (c1 (par1 (nth (pcc st) (code st))))
 
878
                                      (c2 (par2 (nth (pcc st) (code st))))
 
879
                                      (c3 (par3 (nth (pcc st) (code st))))
 
880
                                      (mem (mem st))))
 
881
         :in-theory (disable bounded-value put-cell get-cell execute-instruction 
 
882
                             sum-and-update-norest sub-and-update-norest gen-eq-update
 
883
                             par1 par2 par3 par4 member-equal nth rtm-add rtm-sub is-mem-cell-p))))
 
884
 
 
885
(defthm any-bounded-cell-is-bounded-after-execute-instruction-on-gemstate
 
886
 (implies (and
 
887
           (gem-statep st)
 
888
           (bounded-value (get-cell anycell (mem st))))
 
889
          (bounded-value (get-cell anycell (mem (execute-instruction st)))))
 
890
:hints (("Goal" :cases ( (null (nth (pcc st) (code st))) (gem-instruction-p (nth (pcc st) (code st)) (mem st))))
 
891
        ("Subgoal 3" :use an-instruction-of-gem-program-is-null-or-gem-instruction)
 
892
        ("Subgoal 1" :use (execute-instruction
 
893
                           (:instance sum-and-update-norest-returns-a-mem-cell
 
894
                                      (c1 (par1 (nth (pcc st) (code st))))
 
895
                                      (c2 (par2 (nth (pcc st) (code st))))
 
896
                                      (c3 (par3 (nth (pcc st) (code st))))
 
897
                                      (mem (mem st)))
 
898
                           (:instance sub-and-update-norest-returns-a-mem-cell
 
899
                                      (c1 (par1 (nth (pcc st) (code st))))
 
900
                                      (c2 (par2 (nth (pcc st) (code st))))
 
901
                                      (c3 (par3 (nth (pcc st) (code st))))
 
902
                                      (mem (mem st)))
 
903
                           (:instance gen-eq-update-returns-a-mem-cell
 
904
                                      (c1 (par1 (nth (pcc st) (code st))))
 
905
                                      (c2 (par2 (nth (pcc st) (code st))))
 
906
                                      (c3 (par3 (nth (pcc st) (code st))))
 
907
                                      (mem (mem st))))
 
908
         :in-theory (disable bounded-value put-cell get-cell execute-instruction bounded-value
 
909
                             sum-and-update-norest sub-and-update-norest gen-eq-update
 
910
                             par1 par2 par3 par4 member-equal nth rtm-add rtm-sub is-mem-cell-p))))
 
911
 
 
912
#|
 
913
(defthm execute-instruction-is-type-and-attribute-invariant-on-any-var 
 
914
 (and
 
915
 (equal (var-attribute (get-cell cell (mem st))) 
 
916
        (var-attribute (get-cell cell (mem (execute-instruction st)))))
 
917
 (equal (var-type (get-cell cell (mem st))) 
 
918
        (var-type (get-cell cell (mem (execute-instruction st))))))
 
919
 :hints (("Goal" :in-theory (enable put-cell get-cell make-cell mem make-state var-attribute var-type))))
 
920
|#
 
921
 
 
922
(defthm any-gem-instruction-is-conserved-by-execution
 
923
 (implies 
 
924
  (and
 
925
   (gem-statep st)
 
926
   (gem-instruction-p  instr (mem st)))
 
927
 (gem-instruction-p instr (mem (execute-instruction st))))
 
928
  :hints (("Goal"
 
929
           :in-theory '((:definition gem-instruction-p))
 
930
           :use
 
931
           (
 
932
             (:instance any-mem-cell-is-conserved-after-execute-instruction-on-gemstate
 
933
                        (anycell  (par1 instr)))
 
934
             (:instance any-mem-cell-is-conserved-after-execute-instruction-on-gemstate
 
935
                        (anycell  (par2 instr)))
 
936
             (:instance any-mem-cell-is-conserved-after-execute-instruction-on-gemstate
 
937
                        (anycell  (par3 instr)))
 
938
             (:instance execute-instruction-is-type-and-attribute-invariant-on-any-var
 
939
                        (cell  (par1 instr)))
 
940
             (:instance execute-instruction-is-type-and-attribute-invariant-on-any-var
 
941
                        (cell  (par2 instr)))
 
942
             (:instance execute-instruction-is-type-and-attribute-invariant-on-any-var
 
943
                        (cell  (par3 instr)))))))
 
944
 
 
945
 
 
946
 
 
947
(defthm a-gem-instruction-list-is-such-after-execute-instruction
 
948
 (implies 
 
949
  (and
 
950
   (gem-statep st)
 
951
   (gem-instruction-list-p  instrlist (mem st)))
 
952
 (gem-instruction-list-p instrlist (mem (execute-instruction st))))
 
953
  :hints (("Goal" 
 
954
           :induct  (gem-instruction-list-p  instrlist (mem st)) ;(len instrlist) 
 
955
           :in-theory (disable execute-instruction))
 
956
          ("Subgoal *1/3" :use (:instance gem-instruction-list-p  (instlist instrlist) (mem (mem st))))
 
957
          ("Subgoal *1/2"
 
958
           :in-theory (union-theories (current-theory 'ground-zero) '((:definition gem-instruction-list-p)))
 
959
           :use (:instance any-gem-instruction-is-conserved-by-execution (instr (car instrlist))))))
 
960
 
 
961
 
 
962
 
 
963
 
 
964
(defthm execute-gem-retrieves-a-memory
 
965
  (implies
 
966
   (and
 
967
    (gem-statep st)
 
968
    (gem-instruction-p (nth (pcc st) (code st)) (mem st)))
 
969
   (and
 
970
    (bounded-amem-p (mem (execute-instruction st)))
 
971
    (is-typed-amem-p (mem (execute-instruction st)))))
 
972
  :hints (("Goal"
 
973
           :in-theory (disable is-mem-cell-p sum-and-update-norest sub-and-update-norest gen-eq-update)
 
974
           :use (
 
975
                 (:instance gen-eq-update-returns-a-mem-cell
 
976
                            (c1 (par1 (nth (pcc st) (code st))))
 
977
                            (c2 (par2 (nth (pcc st) (code st))))
 
978
                            (c3 (par3 (nth (pcc st) (code st))))
 
979
                            (mem (mem st)))
 
980
                 (:instance sum-and-update-norest-returns-a-mem-cell
 
981
                            (c1 (par1 (nth (pcc st) (code st))))
 
982
                            (c2 (par2 (nth (pcc st) (code st))))
 
983
                            (c3 (par3 (nth (pcc st) (code st))))
 
984
                            (mem (mem st)))
 
985
                 (:instance sub-and-update-norest-returns-a-mem-cell
 
986
                            (c1 (par1 (nth (pcc st) (code st))))
 
987
                            (c2 (par2 (nth (pcc st) (code st))))
 
988
                            (c3 (par3 (nth (pcc st) (code st))))
 
989
                            (mem (mem st)))))))
 
990
 
 
991
                       
 
992
 
 
993
(defthm executing-gem-instruction-retrieves-a-gem-state-from-gem-state
 
994
  (implies
 
995
   (gem-statep st)
 
996
   (gem-statep (execute-instruction st)))
 
997
  :hints (("Goal" :cases ( (null (nth (pcc st) (code st))) (gem-instruction-p (nth (pcc st) (code st)) (mem st))))
 
998
          ("Subgoal 3" :use an-instruction-of-gem-program-is-null-or-gem-instruction)
 
999
          ("Subgoal 1"
 
1000
          :use (
 
1001
                (:instance a-gem-instruction-list-is-such-after-execute-instruction (instrlist (code st)))
 
1002
                (:instance execute-gem-retrieves-a-memory))
 
1003
  :in-theory (disable sum-and-update-norest sub-and-update-norest gen-eq-update gem-instruction-p
 
1004
                              par1 par2 par3 par4 member-equal nth))))
 
1005
 
 
1006
 
 
1007
 
 
1008
 
 
1009
 
 
1010
(defthm executing-gem-instruction-preserves-correctness-wrt-arity
 
1011
 (implies
 
1012
  (and
 
1013
   (gem-statep st)
 
1014
   (correct-wrt-arity m (mem st)))
 
1015
  (correct-wrt-arity  m (mem (execute-instruction st))))
 
1016
 :hints (("Goal" :in-theory (disable correct-type  gemvar-0 var-type gem-statep pcc nth execute-instruction type-0))
 
1017
         ("Subgoal *1/3" :use (:instance execute-instruction-is-type-and-attribute-invariant-on-any-var (cell (gemvar-0 m))))))
 
1018
 
 
1019
 
 
1020
 
 
1021
 
 
1022
             
 
1023
(defthm executing-gem-instruction-keeps-vars-inclusion-right
 
1024
 (implies
 
1025
  (gem-statep st)
 
1026
  (iff (vars-inclusion m (mem st)) (vars-inclusion m (mem (execute-instruction st)))))
 
1027
  :hints (("Goal" :cases ( (null (nth (pcc st) (code st))) (gem-instruction-p (nth (pcc st) (code st)) (mem st))))
 
1028
          ("Subgoal 3" :use an-instruction-of-gem-program-is-null-or-gem-instruction)
 
1029
          ("Subgoal 1" :in-theory (disable par1 par2 par3 par4 sum-and-update-norest opcode code pcc member-equal nth)
 
1030
           :cases  ( (equal (opcode (nth (pcc st) (code st))) 'gem-equ)
 
1031
                     (equal (opcode (nth (pcc st) (code st))) 'gem-add)
 
1032
                     (equal (opcode (nth (pcc st) (code st))) 'gem-sub)))
 
1033
          ("Subgoal 1.3" :in-theory '((:rewrite car-cons)
 
1034
                                      (:definition make-state)
 
1035
                                      (:definition mem)
 
1036
                                      (:definition generic-eql)
 
1037
                                      (:definition execute-instruction)
 
1038
                                      (:definition gem-instruction-p))
 
1039
           :use                        (:instance putting-an-existing-cell-does-not-change-var-inclusion-right
 
1040
                                         (mem (mem st))
 
1041
                                         (v (par1 (nth (pcc st) (code st))))
 
1042
                                         (anyvalue (gen-eq-update 
 
1043
                                                    (par1 (nth (pcc st) (code st)))
 
1044
                                                    (par2 (nth (pcc st) (code st)))
 
1045
                                                    (par3 (nth (pcc st) (code st)))
 
1046
                                                    (mem st)))))
 
1047
          ("Subgoal 1.2" :in-theory '((:rewrite car-cons)
 
1048
                                      (:definition make-state)
 
1049
                                      (:definition mem)
 
1050
                                      (:definition gem-add)
 
1051
                                      (:definition execute-instruction)
 
1052
                                      (:definition gem-instruction-p))
 
1053
           :use                        (:instance putting-an-existing-cell-does-not-change-var-inclusion-right
 
1054
                                         (mem (mem st))
 
1055
                                         (v (par1 (nth (pcc st) (code st))))
 
1056
                                         (anyvalue (sum-and-update-norest 
 
1057
                                                    (par1 (nth (pcc st) (code st)))
 
1058
                                                    (par2 (nth (pcc st) (code st)))
 
1059
                                                    (par3 (nth (pcc st) (code st)))
 
1060
                                                    (mem st)))))
 
1061
          ("Subgoal 1.1" :in-theory '((:rewrite car-cons)
 
1062
                                      (:definition make-state)
 
1063
                                      (:definition mem)
 
1064
                                      (:definition gem-sub)
 
1065
                                      (:definition execute-instruction)
 
1066
                                      (:definition gem-instruction-p))
 
1067
           :use                        (:instance putting-an-existing-cell-does-not-change-var-inclusion-right
 
1068
                                         (mem (mem st))
 
1069
                                         (v (par1 (nth (pcc st) (code st))))
 
1070
                                         (anyvalue (sub-and-update-norest 
 
1071
                                                    (par1 (nth (pcc st) (code st)))
 
1072
                                                    (par2 (nth (pcc st) (code st)))
 
1073
                                                    (par3 (nth (pcc st) (code st)))
 
1074
                                                    (mem st)))))))
 
1075
 
 
1076
(defthm executing-gem-instruction-keeps-vars-inclusion-left
 
1077
 (implies
 
1078
  (gem-statep st)
 
1079
  (iff (vars-inclusion (mem st) m) (vars-inclusion (mem (execute-instruction st)) m)))
 
1080
  :hints (("Goal" :cases ( (null (nth (pcc st) (code st))) (gem-instruction-p (nth (pcc st) (code st)) (mem st))))
 
1081
          ("Subgoal 3" :use an-instruction-of-gem-program-is-null-or-gem-instruction)
 
1082
          ("Subgoal 1" :in-theory (disable par1 par2 par3 par4 sum-and-update-norest opcode code pcc member-equal nth)
 
1083
           :cases  ( (equal (opcode (nth (pcc st) (code st))) 'gem-equ)
 
1084
                     (equal (opcode (nth (pcc st) (code st))) 'gem-add)
 
1085
                     (equal (opcode (nth (pcc st) (code st))) 'gem-sub)))
 
1086
          ("Subgoal 1.3" :in-theory '((:rewrite car-cons)
 
1087
                                      (:definition make-state)
 
1088
                                      (:definition mem)
 
1089
                                      (:definition generic-eql)
 
1090
                                      (:definition execute-instruction)
 
1091
                                      (:definition gem-instruction-p))
 
1092
           :use                        (:instance putting-an-existing-cell-does-not-change-var-inclusion-left
 
1093
                                         (mem (mem st))
 
1094
                                         (v (par1 (nth (pcc st) (code st))))
 
1095
                                         (anyvalue (gen-eq-update 
 
1096
                                                    (par1 (nth (pcc st) (code st)))
 
1097
                                                    (par2 (nth (pcc st) (code st)))
 
1098
                                                    (par3 (nth (pcc st) (code st)))
 
1099
                                                    (mem st)))))
 
1100
          ("Subgoal 1.2" :in-theory '((:rewrite car-cons)
 
1101
                                      (:definition make-state)
 
1102
                                      (:definition mem)
 
1103
                                      (:definition gem-add)
 
1104
                                      (:definition execute-instruction)
 
1105
                                      (:definition gem-instruction-p))
 
1106
           :use                        (:instance putting-an-existing-cell-does-not-change-var-inclusion-left
 
1107
                                         (mem (mem st))
 
1108
                                         (v (par1 (nth (pcc st) (code st))))
 
1109
                                         (anyvalue (sum-and-update-norest 
 
1110
                                                    (par1 (nth (pcc st) (code st)))
 
1111
                                                    (par2 (nth (pcc st) (code st)))
 
1112
                                                    (par3 (nth (pcc st) (code st)))
 
1113
                                                    (mem st)))))
 
1114
          ("Subgoal 1.1" :in-theory '((:rewrite car-cons)
 
1115
                                      (:definition make-state)
 
1116
                                      (:definition mem)
 
1117
                                      (:definition gem-sub)
 
1118
                                      (:definition execute-instruction)
 
1119
                                      (:definition gem-instruction-p))
 
1120
           :use                        (:instance putting-an-existing-cell-does-not-change-var-inclusion-left
 
1121
                                         (mem (mem st))
 
1122
                                         (v (par1 (nth (pcc st) (code st))))
 
1123
                                         (anyvalue (sub-and-update-norest 
 
1124
                                                    (par1 (nth (pcc st) (code st)))
 
1125
                                                    (par2 (nth (pcc st) (code st)))
 
1126
                                                    (par3 (nth (pcc st) (code st)))
 
1127
                                                    (mem st)))))))
 
1128
 
 
1129
 
 
1130
;;(ld "Properties-of-Execute-n-Rtm-Instructions-New.lisp" :ld-error-action :error)
 
1131
 
 
1132
 
 
1133
 
 
1134
(defthm any-mem-cell-is-conserved-after-execute-instruction-on-rtmstate
 
1135
 (implies (and
 
1136
           (rtm-statep st)
 
1137
           (is-mem-cell-p (get-cell anycell (mem st))))
 
1138
          (is-mem-cell-p (get-cell anycell (mem (execute-instruction st)))))
 
1139
:hints (("Goal" :cases ( (null (nth (pcc st) (code st))) (rtm-instruction-p (nth (pcc st) (code st)) (mem st))))
 
1140
        ("Subgoal 3" :use an-instruction-of-rtm-program-is-null-or-rtm-instruction)
 
1141
        ("Subgoal 1" :use (execute-instruction
 
1142
                           (:instance gen-eq-update-returns-a-mem-cell
 
1143
                                      (c1 (par1 (nth (pcc st) (code st))))
 
1144
                                      (c2 (par2 (nth (pcc st) (code st))))
 
1145
                                      (c3 (par3 (nth (pcc st) (code st))))
 
1146
                                      (mem (mem st)))
 
1147
                           (:instance and-update-returns-a-mem-cell
 
1148
                                      (c1 (par1 (nth (pcc st) (code st))))
 
1149
                                      (c2 (par2 (nth (pcc st) (code st))))
 
1150
                                      (c3 (par3 (nth (pcc st) (code st))))
 
1151
                                      (mem (mem st)))
 
1152
                           (:instance or-update-returns-a-mem-cell
 
1153
                                      (c1 (par1 (nth (pcc st) (code st))))
 
1154
                                      (c2 (par2 (nth (pcc st) (code st))))
 
1155
                                      (c3 (par3 (nth (pcc st) (code st))))
 
1156
                                      (mem (mem st)))
 
1157
                           (:instance sum-and-update-returns-a-mem-cell
 
1158
                                      (c1 (par1 (nth (pcc st) (code st))))
 
1159
                                      (c2 (par2 (nth (pcc st) (code st))))
 
1160
                                      (c3 (par3 (nth (pcc st) (code st))))
 
1161
                                      (prime (par4 (nth (pcc st) (code st))))
 
1162
                                      (mem (mem st)))
 
1163
                           (:instance sub-and-update-returns-a-mem-cell
 
1164
                                      (c1 (par1 (nth (pcc st) (code st))))
 
1165
                                      (c2 (par2 (nth (pcc st) (code st))))
 
1166
                                      (c3 (par3 (nth (pcc st) (code st))))
 
1167
                                      (prime (par4 (nth (pcc st) (code st))))
 
1168
                                      (mem (mem st))))
 
1169
         :in-theory (disable put-cell get-cell execute-instruction 
 
1170
                             sum-and-update sub-and-update and-update or-update gen-eq-update
 
1171
                             par1 par2 par3 par4 member-equal nth gem-add gem-sub is-mem-cell-p))))
 
1172
 
 
1173
 
 
1174
(defthm any-rtm-instruction-is-conserved-by-execution
 
1175
 (implies 
 
1176
  (and
 
1177
   (rtm-statep st)
 
1178
   (rtm-instruction-p  instr (mem st)))
 
1179
 (rtm-instruction-p instr (mem (execute-instruction st))))
 
1180
  :hints (("Goal"
 
1181
           :in-theory '((:definition rtm-instruction-p))
 
1182
           :use
 
1183
           (
 
1184
             (:instance any-mem-cell-is-conserved-after-execute-instruction-on-rtmstate
 
1185
                        (anycell  (par1 instr)))
 
1186
             (:instance any-mem-cell-is-conserved-after-execute-instruction-on-rtmstate
 
1187
                        (anycell  (par2 instr)))
 
1188
             (:instance any-mem-cell-is-conserved-after-execute-instruction-on-rtmstate
 
1189
                        (anycell  (par3 instr)))
 
1190
             (:instance any-mem-cell-is-conserved-after-execute-instruction-on-rtmstate
 
1191
                        (anycell  (par4 instr)))
 
1192
             (:instance execute-instruction-is-type-and-attribute-invariant-on-any-var
 
1193
                        (cell  (par1 instr)))
 
1194
             (:instance execute-instruction-is-type-and-attribute-invariant-on-any-var
 
1195
                        (cell  (par2 instr)))
 
1196
             (:instance execute-instruction-is-type-and-attribute-invariant-on-any-var
 
1197
                        (cell  (par3 instr)))
 
1198
             (:instance execute-instruction-is-type-and-attribute-invariant-on-any-var
 
1199
                        (cell  (par4 instr)))))))
 
1200
 
 
1201
 
 
1202
 
 
1203
(defthm a-rtm-instruction-list-is-such-after-execute-instruction
 
1204
 (implies 
 
1205
  (and
 
1206
   (rtm-statep st)
 
1207
   (rtm-instruction-list-p  instrlist (mem st)))
 
1208
 (rtm-instruction-list-p instrlist (mem (execute-instruction st))))
 
1209
  :hints (("Goal" 
 
1210
           :induct  (rtm-instruction-list-p  instrlist (mem st))  
 
1211
           :in-theory (disable execute-instruction))
 
1212
          ("Subgoal *1/3" :use (:instance rtm-instruction-list-p  (instlist instrlist) (mem (mem st))))
 
1213
          ("Subgoal *1/2"
 
1214
           :in-theory (union-theories (current-theory 'ground-zero) '((:definition rtm-instruction-list-p)))
 
1215
           :use (:instance any-rtm-instruction-is-conserved-by-execution (instr (car instrlist))))))
 
1216
 
 
1217
 
 
1218
(defthm execute-rtm-retrieves-a-memory
 
1219
  (implies
 
1220
   (and
 
1221
    (rtm-statep st)
 
1222
    (rtm-instruction-p (nth (pcc st) (code st)) (mem st)))
 
1223
   (is-typed-amem-p (mem (execute-instruction st))))
 
1224
  :hints (("Goal"
 
1225
           :in-theory (disable is-mem-cell-p 
 
1226
                               and-update or-update gen-eq-update sum-and-update sub-and-update )
 
1227
           :use (
 
1228
                 (:instance gen-eq-update-returns-a-mem-cell
 
1229
                            (c1 (par1 (nth (pcc st) (code st))))
 
1230
                            (c2 (par2 (nth (pcc st) (code st))))
 
1231
                            (c3 (par3 (nth (pcc st) (code st))))
 
1232
                            (mem (mem st)))
 
1233
                 (:instance or-update-returns-a-mem-cell
 
1234
                            (c1 (par1 (nth (pcc st) (code st))))
 
1235
                            (c2 (par2 (nth (pcc st) (code st))))
 
1236
                            (c3 (par3 (nth (pcc st) (code st))))
 
1237
                            (mem (mem st)))
 
1238
                 (:instance and-update-returns-a-mem-cell
 
1239
                            (c1 (par1 (nth (pcc st) (code st))))
 
1240
                            (c2 (par2 (nth (pcc st) (code st))))
 
1241
                            (c3 (par3 (nth (pcc st) (code st))))
 
1242
                            (mem (mem st)))
 
1243
                 (:instance sum-and-update-returns-a-mem-cell
 
1244
                            (c1 (par1 (nth (pcc st) (code st))))
 
1245
                            (c2 (par2 (nth (pcc st) (code st))))
 
1246
                            (c3 (par3 (nth (pcc st) (code st))))
 
1247
                            (prime (par4 (nth (pcc st) (code st))))
 
1248
                            (mem (mem st)))
 
1249
                 (:instance sub-and-update-returns-a-mem-cell
 
1250
                            (c1 (par1 (nth (pcc st) (code st))))
 
1251
                            (c2 (par2 (nth (pcc st) (code st))))
 
1252
                            (c3 (par3 (nth (pcc st) (code st))))
 
1253
                            (prime (par4 (nth (pcc st) (code st))))
 
1254
                            (mem (mem st)))))))
 
1255
 
 
1256
                       
 
1257
 
 
1258
(defthm executing-rtm-instruction-retrieves-a-rtm-state-from-rtm-state
 
1259
  (implies
 
1260
   (rtm-statep st)
 
1261
   (rtm-statep (execute-instruction st)))
 
1262
  :hints (("Goal" :cases ( (null (nth (pcc st) (code st))) (rtm-instruction-p (nth (pcc st) (code st)) (mem st))))
 
1263
          ("Subgoal 3" :use an-instruction-of-rtm-program-is-null-or-rtm-instruction)
 
1264
          ("Subgoal 1"
 
1265
          :use (
 
1266
                (:instance a-rtm-instruction-list-is-such-after-execute-instruction (instrlist (code st)))
 
1267
                (:instance execute-rtm-retrieves-a-memory))
 
1268
  :in-theory (disable sum-and-update sub-and-update and-update or-update gen-eq-update
 
1269
                      rtm-instruction-p
 
1270
                      par1 par2 par3 par4 member-equal nth))))
 
1271
 
 
1272
 
 
1273
 
 
1274
 
 
1275
 
 
1276
(defthm executing-rtm-instruction-is-attributes-invariant
 
1277
  (implies
 
1278
   (rtm-statep st)
 
1279
   (equal 
 
1280
    (var-attributes vars (mem st))
 
1281
    (var-attributes  vars (mem (execute-instruction st)))))
 
1282
 :hints (("Goal" :in-theory (disable par1 par2 par3 par4 member-equal nth))
 
1283
         ("Subgoal *1/2" :use (:instance execute-instruction-is-type-and-attribute-invariant-on-any-var
 
1284
                                         (cell (car vars))))))
 
1285
 
 
1286
 
 
1287
 
 
1288
(defthm executing-rtm-instruction-keeps-m-pointing-to-rtm-var-sets
 
1289
 (implies
 
1290
  (and
 
1291
   (rtm-statep st)
 
1292
   (m-entries-point-to-good-rtm-var-sets m (mem st)))
 
1293
  (m-entries-point-to-good-rtm-var-sets m (mem (execute-instruction st))))
 
1294
 :hints (("Goal" :in-theory (disable par1 par2 par3 par4 member-equal nth))
 
1295
         ("Subgoal *1/3" :use (:instance executing-rtm-instruction-is-attributes-invariant
 
1296
                                         (vars (rtmintvars-0 m))))))
 
1297
 
 
1298
 
 
1299
 
 
1300
   
 
1301
 
 
1302
 
 
1303
 
 
1304
 
 
1305
 
 
1306
 
 
1307
 
 
1308
 
 
1309
 
 
1310
 
 
1311
 
 
1312
 
 
1313
 
 
1314
(defun listpars1 (st n)
 
1315
  (if (zp n)
 
1316
      nil
 
1317
    (cons (par1 (nth (pcc st) (code st)))
 
1318
          (listpars1 (execute-instruction st) (1- n)))))
 
1319
 
 
1320
(defun listpars2 (st n)
 
1321
  (if (zp n)
 
1322
      nil
 
1323
    (cons (par2 (nth (pcc st) (code st)))
 
1324
          (listpars2 (execute-instruction st) (1- n)))))
 
1325
 
 
1326
(defun listpars3 (st n)
 
1327
  (if (zp n)
 
1328
      nil
 
1329
    (cons (par3 (nth (pcc st) (code st)))
 
1330
          (listpars3 (execute-instruction st) (1- n)))))
 
1331
 
 
1332
(defun listpars4 (st n)
 
1333
  (if (zp n)
 
1334
      nil
 
1335
    (cons (par4 (nth (pcc st) (code st)))
 
1336
          (listpars4 (execute-instruction st) (1- n)))))
 
1337
 
 
1338
 
 
1339
 
 
1340
 
 
1341
(defthm lemma12-lp1r
 
1342
  (equal (cdr (listpars1 st n)) (listpars1 (execute-instruction st) (1- n)))
 
1343
:hints (("Goal" :in-theory (disable execute-instruction))))
 
1344
 
 
1345
 
 
1346
(defthm lemma12-lp2r
 
1347
  (equal (cdr (listpars2 st n)) (listpars2 (execute-instruction st) (1- n)))
 
1348
  :hints (("Goal" :in-theory (disable execute-instruction))))
 
1349
 
 
1350
 
 
1351
(defthm lemma12-lp3r
 
1352
  (equal (cdr (listpars3 st n)) (listpars3 (execute-instruction st) (1- n)))
 
1353
  :hints (("Goal" :in-theory (disable execute-instruction))))
 
1354
 
 
1355
 
 
1356
(defthm lemma12-lp4r
 
1357
  (equal (cdr (listpars4 st n)) (listpars4 (execute-instruction st) (1- n)))
 
1358
  :hints (("Goal" :in-theory (disable execute-instruction))))
 
1359
 
 
1360
(defthm length-of-listpars1-n-is-n
 
1361
 (implies
 
1362
  (and 
 
1363
   (integerp n)
 
1364
   (>= n 0))
 
1365
  (equal (len (listpars1 st n)) n))
 
1366
 :hints (("Goal" :in-theory (disable execute-instruction nth par1 pcc code member-equal))))
 
1367
 
 
1368
(defthm length-of-listpars2-n-is-n
 
1369
 (implies
 
1370
  (and 
 
1371
   (integerp n)
 
1372
   (>= n 0))
 
1373
  (equal (len (listpars2 st n)) n))
 
1374
 :hints (("Goal" :in-theory (disable execute-instruction nth par2 pcc code member-equal))))
 
1375
 
 
1376
(defthm length-of-listpars3-n-is-n
 
1377
 (implies
 
1378
  (and 
 
1379
   (integerp n)
 
1380
   (>= n 0))
 
1381
  (equal (len (listpars3 st n)) n))
 
1382
 :hints (("Goal" :in-theory (disable execute-instruction))))
 
1383
 
 
1384
(defthm length-of-listpars4-n-is-n
 
1385
 (implies
 
1386
  (and 
 
1387
   (integerp n)
 
1388
   (>= n 0))
 
1389
  (equal (len (listpars4 st n)) n))
 
1390
 :hints (("Goal" :in-theory (disable execute-instruction))))
 
1391
 
 
1392
 
 
1393
 
 
1394
 
 
1395
 
 
1396
 
 
1397
 
 
1398
 
 
1399
 
 
1400
 
 
1401
 
 
1402
 
 
1403
 
 
1404
 
 
1405
(defthm only-par1-is-involved
 
1406
 (implies
 
1407
  (and
 
1408
   (or
 
1409
    (null (nth (pcc gstate) (code gstate)))
 
1410
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-equ)   
 
1411
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-add)   
 
1412
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-sub))
 
1413
  (not (equal var (par1 (nth (pcc gstate) (code gstate))))) )
 
1414
  (equal (get-cell var (mem gstate)) (get-cell var (mem (execute-instruction gstate)))))
 
1415
 :hints (("Goal" :in-theory (disable sum-and-update sub-and-update gen-eq-update nth mod))))
 
1416
 
 
1417
(defthm only-par1-is-involved-rtm
 
1418
 (implies
 
1419
  (and
 
1420
   (or
 
1421
    (null (nth (pcc gstate) (code gstate)))
 
1422
    (equal (opcode (nth (pcc gstate) (code gstate))) 'rtm-and)   
 
1423
    (equal (opcode (nth (pcc gstate) (code gstate))) 'rtm-or)   
 
1424
    (equal (opcode (nth (pcc gstate) (code gstate))) 'rtm-equ)   
 
1425
    (equal (opcode (nth (pcc gstate) (code gstate))) 'rtm-add)   
 
1426
    (equal (opcode (nth (pcc gstate) (code gstate))) 'rtm-sub))
 
1427
  (not (equal var (par1 (nth (pcc gstate) (code gstate))))) )
 
1428
  (equal (get-cell var (mem gstate)) (get-cell var (mem (execute-instruction gstate)))))
 
1429
 :hints (("Goal" :in-theory (disable sum-and-update sub-and-update gen-eq-update nth mod))))
 
1430
 
 
1431
 
 
1432
 
 
1433
 
 
1434
 
 
1435
 
 
1436
 
 
1437
 
 
1438
 
 
1439
 
 
1440
 
 
1441
 
 
1442
 
 
1443
 
 
1444
 
 
1445
 
 
1446
 
 
1447
 
 
1448
 
 
1449
 
 
1450
(in-theory (enable build-values-by-rns))
 
1451
 
 
1452
 
 
1453
(in-theory (disable mod floor))
 
1454
 
 
1455
 
 
1456
 
 
1457
 
 
1458
 
 
1459
(defun rtmintvars-i (gvar m) (cdr (assoc-equal gvar m)))
 
1460
 
 
1461
(DEFUN TYPE-I (gvar M)
 
1462
  (COND ((AND (TRUE-LISTP (RTMINTVARS-I gvar M))
 
1463
              (EQUAL (LEN (RTMINTVARS-I gvar M)) 1))
 
1464
         'BOOL)
 
1465
        ((AND (TRUE-LISTP (RTMINTVARS-I gvar M))
 
1466
              (EQUAL (LEN (RTMINTVARS-I gvar M))
 
1467
                     (LEN *RNS*)))
 
1468
         'INT)
 
1469
        (T 'WRONG-TYPING)))
 
1470
 
 
1471
(defthm type-i-is-vartyper
 
1472
 (implies
 
1473
  (and
 
1474
   (assoc-equal gvar1 m)
 
1475
   (true-listp m)
 
1476
   (correct-wrt-arity m mem))
 
1477
  (equal (type-i gvar1 m) (var-type (get-cell gvar1 mem))))
 
1478
 :hints (("Goal" :in-theory (enable
 
1479
                             var-type gemvar-0 rtmintvars-0 var-type type-i type-0))))
 
1480
 
 
1481
(defthm type-i-is-type-expected
 
1482
 (implies
 
1483
  (and
 
1484
   (assoc-equal gvar m)
 
1485
   (true-listp m)
 
1486
   (correct-wrt-arity m mem))
 
1487
  (equal
 
1488
   (type-i gvar m) 
 
1489
   (type-expected (rtmintvars-i gvar m)))))
 
1490
 
 
1491
(defun pos-equal-0 (el l)
 
1492
  (cond
 
1493
   ( (endp l)           0 )
 
1494
   ( (equal el (caar l)) 0 )
 
1495
   (t                   (1+ (pos-equal-0 el (cdr l))))))
 
1496
 
 
1497
(defthm assoc-means-pos-in-range
 
1498
  (implies (assoc-equal el l) (in-range (pos-equal-0 el l) l))
 
1499
  :rule-classes :forward-chaining)
 
1500
 
 
1501
 
 
1502
 
 
1503
(defun retrieve-gemvars (m)
 
1504
  (if
 
1505
      (endp m)
 
1506
      nil
 
1507
    (cons (gemvar-0 m) (retrieve-gemvars (cdr m)))))
 
1508
 
 
1509
 
 
1510
(defthm retrieve-gemvars-same-len 
 
1511
 (implies
 
1512
  (true-listp m)
 
1513
  (equal (len (retrieve-gemvars m)) (len m))))
 
1514
 
 
1515
(defthm equal-nth-of-retrieve-car-of-nth
 
1516
  (equal (nth idx (retrieve-gemvars m)) (car (nth idx m)))
 
1517
 :hints (("Goal" :in-theory (enable gemvar-0))))
 
1518
 
 
1519
 
 
1520
(defthm no-duplicates-whose-caar-is-nth-idx-means-idx-is-0
 
1521
(IMPLIES (AND (NOT (ENDP L))
 
1522
              (EQUAL (CAR (NTH IDX L)) (CAAR L))
 
1523
              (TRUE-LISTP L)
 
1524
              (in-range idx l)
 
1525
              (NO-DUPLICATES-P (RETRIEVE-GEMVARS L)))
 
1526
         (EQUAL idx 0))
 
1527
:hints (("Goal" 
 
1528
         :in-theory (union-theories (current-theory 'ground-zero) 
 
1529
                                    '((:definition in-range) 
 
1530
                                      (:definition len) 
 
1531
                                      (:rewrite equal-nth-of-retrieve-car-of-nth)))
 
1532
         :use
 
1533
         ( 
 
1534
           (:instance retrieve-gemvars-same-len (m l))
 
1535
           (:instance no-dup-3 (l (retrieve-gemvars l)) (idx2 0)))))
 
1536
:rule-classes nil)
 
1537
 
 
1538
 
 
1539
(defthm subgoal12
 
1540
(IMPLIES (AND (NOT (ENDP L))
 
1541
              (EQUAL (CAR (NTH IDX L)) (CAAR L))
 
1542
              (TRUE-LISTP L)
 
1543
              (< (POS-EQUAL-0 (CAR (NTH IDX L)) L)
 
1544
                 (LEN L))
 
1545
              (INTEGERP IDX)
 
1546
              (<= 0 IDX)
 
1547
              (< IDX (LEN L))
 
1548
              (NO-DUPLICATES-P (RETRIEVE-GEMVARS L)))
 
1549
         (EQUAL (POS-EQUAL-0 (CAR (NTH IDX L)) L)
 
1550
                IDX))
 
1551
:hints (("Goal"
 
1552
         :use no-duplicates-whose-caar-is-nth-idx-means-idx-is-0)))
 
1553
 
 
1554
 
 
1555
(defthm no-duplicates-has-pos-equal-right-in-that-place
 
1556
 (implies
 
1557
  (and
 
1558
   (true-listp l)
 
1559
   (in-range idx l)
 
1560
   (no-duplicates-p (retrieve-gemvars l)))
 
1561
  (equal (pos-equal-0 (car (nth idx l)) l) idx))
 
1562
 :hints (("Goal" :in-theory (enable gemvar-0))
 
1563
         ("Subgoal *1/2" :use subgoal12)))
 
1564
 
 
1565
 
 
1566
 
 
1567
 
 
1568
 
 
1569
(defthm rtmintvars-i-is-cdr-of-nth-entry
 
1570
 (equal (rtmintvars-i gvar m)
 
1571
        (cdr (nth (pos-equal-0 gvar m) m))))
 
1572
 
 
1573
 
 
1574
 
 
1575
(defun type-i-idx (m idx)
 
1576
  (COND ((AND (TRUE-LISTP (cdr (nth idx m)))
 
1577
              (EQUAL (LEN (cdr (nth idx m))) 1))
 
1578
         'BOOL)
 
1579
        ((AND (TRUE-LISTP (cdr (nth idx m)))
 
1580
              (EQUAL (LEN (cdr (nth idx m)))
 
1581
                     (LEN *RNS*)))
 
1582
         'INT)
 
1583
        (T 'WRONG-TYPING)))
 
1584
 
 
1585
(defun listinstr (st n)
 
1586
  (if (zp n)
 
1587
      nil
 
1588
    (cons (nth (pcc st) (code st))
 
1589
          (listinstr (execute-instruction st) (1- n)))))
 
1590
 
 
1591
(defthm inclusion-trans
 
1592
  (implies
 
1593
   (and
 
1594
    (vars-inclusion m1 m2)
 
1595
    (assoc-equal v m1))
 
1596
   (assoc-equal v m2)))
 
1597
 
 
1598
(defthm correct-wrt-arity-has-rtmintvars-i-tl
 
1599
 (implies 
 
1600
  (correct-wrt-arity m mem)
 
1601
  (true-listp (rtmintvars-i gvar1 m)))
 
1602
 :hints (("Goal" :in-theory (enable correct-wrt-arity type-0 gemvar-0 rtmintvars-0 correct-type))))
 
1603
 
 
1604
(defun rtm-eq-and (v1 v2 tmp res)
 
1605
(list
 
1606
 (list 'rtm-equ tmp v1 v2)
 
1607
 (list 'rtm-and res tmp res)))
 
1608
 
 
1609
(defun rtm-eq-or (v1 v2 tmp res)
 
1610
(list
 
1611
 (list 'rtm-equ tmp v1 v2)
 
1612
 (list 'rtm-or  res tmp tmp)))
 
1613
 
 
1614
(defun equality-trans2 (listvars1 listvars2 tmp res)
 
1615
  (if (endp listvars1)
 
1616
      nil
 
1617
    (append
 
1618
     (rtm-eq-and (car listvars1) (car listvars2) tmp res)
 
1619
     (equality-trans2 (cdr listvars1) (cdr listvars2) tmp res))))
 
1620
 
 
1621
(defun equality-trans3 (listvars1 listvars2 tmp res)
 
1622
    (append
 
1623
     (rtm-eq-or (car listvars1) (car listvars2) tmp res)
 
1624
     (equality-trans2 (cdr listvars1) (cdr listvars2) tmp res)))
 
1625
 
 
1626
(defun all-rtm-adds-for-n-steps (st n)
 
1627
  (declare (xargs :measure (acl2-count n)))
 
1628
  (if (zp n)
 
1629
      t
 
1630
    (and 
 
1631
     (equal (opcode (nth (pcc st) (code st))) 'rtm-add)
 
1632
     (all-rtm-adds-for-n-steps (execute-instruction st) (1- n)))))
 
1633
 
 
1634
(defun all-rtm-subs-for-n-steps (st n)
 
1635
  (declare (xargs :measure (acl2-count n)))
 
1636
  (if (zp n)
 
1637
      t
 
1638
    (and 
 
1639
     (equal (opcode (nth (pcc st) (code st))) 'rtm-sub)
 
1640
     (all-rtm-subs-for-n-steps (execute-instruction st) (1- n)))))
 
1641
 
 
1642
 
 
1643
(defun good-translation-gem-rtm (gstate rstate m)
 
1644
 (declare (xargs :measure (acl2-count (- (len (code gstate)) (pcc gstate)))))
 
1645
  (if
 
1646
      (or (not (integerp (pcc gstate)))
 
1647
          (< (pcc gstate) 0)
 
1648
          (>= (pcc gstate) (len (code gstate))))
 
1649
      (>= (pcc rstate) (len (code rstate)))
 
1650
    (case (opcode (nth (pcc gstate) (code gstate)))
 
1651
      (gem-equ
 
1652
       (and 
 
1653
        (in-range (pcc rstate) (code rstate))
 
1654
        (equal (listinstr     rstate (* 2 (len *rns*)) ) 
 
1655
               (equality-trans3 
 
1656
                (eventually-make-list (rtmintvars-i (par2 (nth (pcc gstate) (code gstate))) m) (len *rns*))
 
1657
                (eventually-make-list (rtmintvars-i (par3 (nth (pcc gstate) (code gstate))) m) (len *rns*))
 
1658
                'tmp
 
1659
                (car (rtmintvars-i (par1 (nth (pcc gstate) (code gstate))) m))))
 
1660
        (not (equal 
 
1661
              (par1 (nth (pcc gstate) (code gstate)))
 
1662
              (par2 (nth (pcc gstate) (code gstate)))))
 
1663
        (not (equal 
 
1664
              (par1 (nth (pcc gstate) (code gstate)))
 
1665
              (par3 (nth (pcc gstate) (code gstate)))))
 
1666
        (good-translation-gem-rtm 
 
1667
         (execute-instruction    gstate                   ) 
 
1668
         (execute-n-instructions rstate (* 2 (len *rns*)) )
 
1669
         m)))
 
1670
      (gem-add 
 
1671
       (and 
 
1672
        (in-range (pcc rstate) (code rstate))
 
1673
        (all-rtm-adds-for-n-steps rstate (len *rns*) )
 
1674
        (equal (listpars1     rstate (len *rns*) ) 
 
1675
               (rtmintvars-i (par1 (nth (pcc gstate) (code gstate))) m))
 
1676
        (equal (listpars2     rstate (len *rns*) ) 
 
1677
               (eventually-make-list (rtmintvars-i (par2 (nth (pcc gstate) (code gstate))) m) (len *rns*))) ;new
 
1678
        (equal (listpars3     rstate (len *rns*) ) 
 
1679
               (eventually-make-list (rtmintvars-i (par3 (nth (pcc gstate) (code gstate))) m) (len *rns*))) ;new
 
1680
        (equal (listpars4     rstate (len *rns*) ) *rns*)
 
1681
        (good-translation-gem-rtm 
 
1682
         (execute-instruction    gstate             ) 
 
1683
         (execute-n-instructions rstate (len *rns*) )
 
1684
         m)))
 
1685
      (gem-sub ;;;gem-add
 
1686
       (and 
 
1687
        (in-range (pcc rstate) (code rstate))
 
1688
        (all-rtm-subs-for-n-steps rstate (len *rns*) )
 
1689
        (equal (listpars1     rstate (len *rns*) ) 
 
1690
               (rtmintvars-i (par1 (nth (pcc gstate) (code gstate))) m))
 
1691
        (equal (listpars2     rstate (len *rns*) ) 
 
1692
               (eventually-make-list (rtmintvars-i (par2 (nth (pcc gstate) (code gstate))) m) (len *rns*))) ;new
 
1693
        (equal (listpars3     rstate (len *rns*) ) 
 
1694
               (eventually-make-list (rtmintvars-i (par3 (nth (pcc gstate) (code gstate))) m) (len *rns*))) ;new
 
1695
        (equal (listpars4     rstate (len *rns*) ) *rns*)
 
1696
        (good-translation-gem-rtm 
 
1697
         (execute-instruction    gstate             ) 
 
1698
         (execute-n-instructions rstate (len *rns*) )
 
1699
         m)))
 
1700
      (otherwise nil))))
 
1701
 
 
1702
 
 
1703
 
 
1704
 
 
1705
 
 
1706
(defun equal-get-cells (lcell mem1 mem2)
 
1707
  (if (endp lcell)
 
1708
      (null lcell)
 
1709
    (and
 
1710
     (equal (get-cell (car lcell) mem1) (get-cell (car lcell) mem2))
 
1711
     (equal-get-cells (cdr lcell) mem1 mem2))))
 
1712
 
 
1713
(defthm equal-get-cells-implies-equal-parts-of-cells
 
1714
 (implies
 
1715
  (equal-get-cells lcell mem1 mem2)
 
1716
  (and
 
1717
   (equal
 
1718
    (var-attributes lcell mem1)
 
1719
    (var-attributes lcell mem2))
 
1720
   (equal
 
1721
    (var-values lcell mem1)
 
1722
    (var-values lcell mem2)))))
 
1723
 
 
1724
 
 
1725
(defthm equal-get-cells-implies-equal-values-and-attributes-still-works
 
1726
 (implies
 
1727
  (equal-get-cells lcell mem1 mem2)
 
1728
  (iff
 
1729
   (equal-values-and-attributes gemcell lcell mem1 type)
 
1730
   (equal-values-and-attributes gemcell lcell mem2 type))))
 
1731
 
 
1732
   
 
1733
(defun idx-different-cell (l mem1 mem2)
 
1734
  (cond
 
1735
   ( (endp l) 0)
 
1736
   ( (not (equal (get-cell (car l) mem1) (get-cell (car l) mem2))) 0 )
 
1737
   (t (1+ (idx-different-cell (cdr l) mem1 mem2)))))
 
1738
 
 
1739
 
 
1740
 
 
1741
(defthm if-bad-index-in-range-then-cells-must-be-different
 
1742
 (implies 
 
1743
  (in-range (idx-different-cell l mem1 mem2) l) 
 
1744
  (not (equal 
 
1745
        (get-cell (nth (idx-different-cell l mem1 mem2) l) mem1)
 
1746
        (get-cell (nth (idx-different-cell l mem1 mem2) l) mem2))))
 
1747
 :rule-classes :forward-chaining)
 
1748
 
 
1749
 
 
1750
(defthm if-bad-index-not-in-range-then-every-equal
 
1751
 (implies (and (true-listp l)
 
1752
               (not (in-range (idx-different-cell l mem1 mem2) l)))
 
1753
          (equal-get-cells l mem1 mem2)))
 
1754
 
 
1755
 
 
1756
 
 
1757
 
 
1758
 
 
1759
 
 
1760
(in-theory (enable gemvar-0 rtmintvars-0))
 
1761
 
 
1762
(defthm m-correspondent-values-implies-equal-values-and-attribus
 
1763
 (implies
 
1764
  (and
 
1765
   (true-listp m) 
 
1766
   (m-correspondent-values-p m memgstate memrstate)
 
1767
   (assoc-equal gvar1 m))
 
1768
  (equal-values-and-attributes
 
1769
   (get-cell gvar1 memgstate)
 
1770
   (rtmintvars-i gvar1 m)
 
1771
   memrstate
 
1772
   (type-i gvar1 m)))
 
1773
:hints (("Goal" :in-theory (disable equal-values-and-attributes))))
 
1774
 
 
1775
(in-theory (disable gemvar-0 rtmintvars-0))
 
1776
 
 
1777
 
 
1778
(defun retrieve-rtmvars (m)
 
1779
  (if (endp m)
 
1780
      nil
 
1781
    (cons (cdr (car m))
 
1782
          (retrieve-rtmvars (cdr m)))))
 
1783
 
 
1784
 
 
1785
(defthm rtmintvars-i-is-pos-equal-0-of-retrieve-vars
 
1786
  (equal (rtmintvars-i gvar m)
 
1787
         (nth (pos-equal-0 gvar m) (retrieve-rtmvars m))))
 
1788
 
 
1789
 
 
1790
(defthm lemma-help2 
 
1791
  (implies
 
1792
   (true-listp m)
 
1793
   (equal (len m) (len (retrieve-rtmvars m))))
 
1794
  :rule-classes nil)
 
1795
 
 
1796
(defthm lemma-help3 
 
1797
  (implies
 
1798
   (true-listp m)
 
1799
    (iff (in-range idx m) (in-range idx (retrieve-rtmvars m))))
 
1800
  :hints (("Goal" :use lemma-help2))
 
1801
  :rule-classes nil)
 
1802
 
 
1803
(defthm lemma-help4 
 
1804
  (implies
 
1805
   (and
 
1806
    (assoc-equal gvar1 m)
 
1807
    (not (equal gvar1 gvar2)))
 
1808
   (not (equal (pos-equal-0 gvar1 m) (pos-equal-0 gvar2 m)))))
 
1809
 
 
1810
(defthm lemma1-different-vars-do-not-belong
 
1811
  (implies
 
1812
   (and
 
1813
    (true-listp m)
 
1814
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
1815
    (assoc-equal gvar1 m)
 
1816
    (assoc-equal gvar2 m)
 
1817
    (not (equal gvar1 gvar2))
 
1818
    (in-range idx1 (rtmintvars-i gvar1 m)))
 
1819
  (not (member-equal-bool (nth idx1 (rtmintvars-i gvar1 m))
 
1820
                     (rtmintvars-i gvar2 m))))
 
1821
  :hints (("Goal"
 
1822
           :in-theory '((:type-prescription retrieve-rtmvars)
 
1823
                        (:definition in-range)
 
1824
                        (:rewrite in-range-is-member-eq-bool))
 
1825
           :use (
 
1826
                 lemma-help4
 
1827
                 (:instance lemma-help3 (idx (pos-equal-0 gvar1 m)))
 
1828
                 (:instance lemma-help3 (idx (pos-equal-0 gvar2 m)))
 
1829
                 (:instance generalized-disjunctivity-unordered-2
 
1830
                            (el1 (nth idx1 (nth (pos-equal-0 gvar1 m) (retrieve-rtmvars m))))
 
1831
                            (ll (retrieve-rtmvars m))
 
1832
                            (idx1 (pos-equal-0 gvar1 m))
 
1833
                            (idx2 (pos-equal-0 gvar2 m)))
 
1834
                 (:instance assoc-means-pos-in-range (el gvar1) (l m))
 
1835
                 (:instance assoc-means-pos-in-range (el gvar2) (l m))
 
1836
                 (:instance rtmintvars-i-is-pos-equal-0-of-retrieve-vars (gvar gvar1))
 
1837
                 (:instance rtmintvars-i-is-pos-equal-0-of-retrieve-vars (gvar gvar2))))))
 
1838
 
 
1839
 
 
1840
(defthm teorema-main-con-pcc-in-range-su-variabile-non-interessata
 
1841
 (implies
 
1842
  (and
 
1843
   (gem-statep gstate)
 
1844
   (rtm-statep rstate)
 
1845
   (in-range (pcc gstate) (code gstate))
 
1846
   (in-range (pcc rstate) (code rstate))
 
1847
   (not (equal gvar1 (par1 (nth (pcc gstate) (code gstate))))))
 
1848
  (equal
 
1849
   (get-cell gvar1 (mem (execute-instruction gstate)))
 
1850
   (get-cell gvar1 (mem gstate))))
 
1851
 :hints (("Goal" :use (:instance only-par1-is-involved (var gvar1)))))
 
1852
 
 
1853
 
 
1854
(defun bad-idx-eqv-va (m gem-mem rtm-mem)
 
1855
  (cond
 
1856
   ( (endp m)
 
1857
     0 )
 
1858
   ( (not (equal-values-and-attributes 
 
1859
           (get-cell (gemvar-0 m) gem-mem)
 
1860
           (rtmintvars-0 m) 
 
1861
           rtm-mem
 
1862
           (type-0 m)))
 
1863
     0 )
 
1864
   (t (1+ (bad-idx-eqv-va (cdr m) gem-mem rtm-mem)))))
 
1865
 
 
1866
(defthm if-bad-index-in-range-thne-must-be-different-mc
 
1867
 (implies
 
1868
   (in-range (bad-idx-eqv-va m gem-mem rtm-mem) m) 
 
1869
  (not (m-correspondent-values-p m gem-mem rtm-mem)))
 
1870
 :hints (("Goal" :in-theory (enable gemvar-0))))
 
1871
 
 
1872
(defthm if-bad-index-in-range-thne-must-be-different-vs
 
1873
 (implies
 
1874
   (in-range (bad-idx-eqv-va m gem-mem rtm-mem) m) 
 
1875
  (not 
 
1876
   (equal-values-and-attributes 
 
1877
    (get-cell (car (nth (bad-idx-eqv-va m gem-mem rtm-mem) m))  gem-mem)
 
1878
    (cdr (nth (bad-idx-eqv-va m gem-mem rtm-mem) m))
 
1879
    rtm-mem
 
1880
    (type-i-idx m (bad-idx-eqv-va m gem-mem rtm-mem)))))
 
1881
 :hints (("Goal" :in-theory (e/d (type-0 gemvar-0 rtmintvars-0) 
 
1882
                                 (var-attribute var-attributes apply-direct-rns-to-value-according-to-type
 
1883
                                                var-values-of-1-variable-is-one-element-list-of-var-value
 
1884
                                                var-values equal-values 
 
1885
                                                )))))
 
1886
 
 
1887
 
 
1888
(defthm if-bad-index-not-in-range-then-m-corr
 
1889
  (implies
 
1890
   (and
 
1891
    (true-listp m)
 
1892
    (not (in-range (bad-idx-eqv-va m gem-mem rtm-mem) m))) 
 
1893
    (m-correspondent-values-p m gem-mem rtm-mem))
 
1894
  :hints (("Goal" :in-theory (e/d (gemvar-0) 
 
1895
                          ((:type-prescription retrieve-rtmvars) 
 
1896
                           retrieve-rtmvars)))))
 
1897
 
 
1898
(defthm execute-n-instructions-keeps-rtm-state-and-points-to-good
 
1899
 (implies
 
1900
  (and
 
1901
   (rtm-statep st)
 
1902
   (m-entries-point-to-good-rtm-var-sets m (mem st)))
 
1903
  (and
 
1904
   (rtm-statep (execute-n-instructions st n))
 
1905
   (m-entries-point-to-good-rtm-var-sets m (mem (execute-n-instructions st n)))))
 
1906
 :hints (("Goal" :induct (execute-n-instructions st n) )
 
1907
         ("Subgoal *1/2"
 
1908
          :in-theory '((:definition execute-n-instructions)
 
1909
                       (:rewrite executing-rtm-instruction-keeps-m-pointing-to-rtm-var-sets)
 
1910
                       (:rewrite executing-rtm-instruction-retrieves-a-rtm-state-from-rtm-state))))) 
 
1911
 
 
1912
 
 
1913
;;(ld "Proof-Of-Plus.lisp" :ld-error-action :error)
 
1914
 
 
1915
(in-theory (enable 
 
1916
            (:executable-counterpart build-values-by-rns)
 
1917
            (:type-prescription build-values-by-rns)
 
1918
            (:induction build-values-by-rns)
 
1919
            (:definition build-values-by-rns)
 
1920
            posp-all posp mod mod-+-exp mod-prod-makes-same-residues))
 
1921
 
 
1922
(in-theory (disable mod floor))
 
1923
 
 
1924
(defun sum-list (vl2 vl3 rns)
 
1925
  (if (endp vl2)
 
1926
      nil
 
1927
       (cons (mod (+ (car vl2) (car vl3)) (car rns)) 
 
1928
             (sum-list (cdr vl2) (cdr vl3) (cdr rns)))))
 
1929
 
 
1930
(defthm sum-correspondence-by-put-list
 
1931
 (implies
 
1932
  (and
 
1933
   (integerp gval1)
 
1934
   (integerp gval2)
 
1935
   (posp-all rns))
 
1936
   (equal (build-values-by-rns (+ gval1 gval2) rns)
 
1937
          (sum-list
 
1938
           (build-values-by-rns gval1 rns)
 
1939
           (build-values-by-rns gval2 rns)
 
1940
           rns)))
 
1941
   :hints (("Goal" :induct t)))
 
1942
 
 
1943
 
 
1944
 
 
1945
 
 
1946
(defthm sum-correspondence-by-put-list-2-fin
 
1947
 (implies
 
1948
  (and
 
1949
   (integerp gval1)
 
1950
   (integerp gval2)
 
1951
   (posp-all rns))          
 
1952
  (equal (build-values-by-rns (mod (+ gval1 gval2) (prod rns)) rns)
 
1953
         (sum-list
 
1954
          (build-values-by-rns  gval1 rns)
 
1955
          (build-values-by-rns  gval2 rns)
 
1956
         rns))))
 
1957
 
 
1958
(in-theory (disable mod-prod-makes-same-residues))
 
1959
 
 
1960
 
 
1961
 
 
1962
(in-theory (disable mod floor mod-+-exp mod-prod-makes-same-residues))
 
1963
 
 
1964
 
 
1965
 
 
1966
 
 
1967
 
 
1968
 
 
1969
 
 
1970
(defthm sum-correspondence-by-put-list-h
 
1971
 (implies
 
1972
  (and
 
1973
   (integerp gval1)
 
1974
   (integerp gval2)
 
1975
   (integer>1-listp rns))
 
1976
   (equal (build-values-by-rns (mod (+ gval1 gval2) (prod rns)) rns)
 
1977
          (sum-list
 
1978
           (build-values-by-rns gval1 rns)
 
1979
           (build-values-by-rns gval2 rns)
 
1980
           rns)))
 
1981
   :hints (("Goal" :use (sum-correspondence-by-put-list-2-fin greater-one-means-greater-zero))))
 
1982
 
 
1983
 
 
1984
 
 
1985
(defthm a-boolean-has-same-rnss-than-list-of-itself
 
1986
 (implies
 
1987
  (and
 
1988
   (integerp val)
 
1989
   (or (equal val 0) (equal val 1))
 
1990
   (integer>1-listp rns))
 
1991
  (equal 
 
1992
   (build-values-by-rns val rns) 
 
1993
   (make-n-list val (len rns))))
 
1994
 :hints (("Goal" :in-theory (enable mod-x-y-=-x-exp))))
 
1995
 
 
1996
 
 
1997
 
 
1998
 
 
1999
(defthm sum-correspondence-by-put-list-on-boolean
 
2000
 (implies
 
2001
  (and
 
2002
   (integerp gval1)
 
2003
   (integerp gval2)
 
2004
   (or (equal gval2 0) (equal gval2 1))
 
2005
   (integer>1-listp rns))
 
2006
   (equal (build-values-by-rns (mod (+ gval1 gval2) (prod rns)) rns)
 
2007
          (sum-list
 
2008
           (build-values-by-rns gval1 rns)
 
2009
           (make-n-list gval2 (len rns))
 
2010
           rns)))
 
2011
 :hints (("Goal" :in-theory nil
 
2012
          :use (sum-correspondence-by-put-list-h
 
2013
                (:instance a-boolean-has-same-rnss-than-list-of-itself (val gval2))))))
 
2014
 
 
2015
 
 
2016
 
 
2017
(defun equal-sum-and-updates (reslist par1list par2list par3list primelist mem memafterputs)
 
2018
  (if (endp reslist)
 
2019
      (null reslist)
 
2020
    (and
 
2021
     (equal 
 
2022
      (get-cell (car reslist) memafterputs) 
 
2023
      (sum-and-update 
 
2024
       (car par1list)
 
2025
       (car par2list)
 
2026
       (car par3list)
 
2027
       (car primelist)
 
2028
       mem))
 
2029
     (equal-sum-and-updates
 
2030
      (cdr reslist)
 
2031
      (cdr par1list)
 
2032
      (cdr par2list)
 
2033
      (cdr par3list)
 
2034
      (cdr primelist)
 
2035
      mem
 
2036
      memafterputs))))
 
2037
 
 
2038
 
 
2039
 
 
2040
 
 
2041
 
 
2042
(defthm equal-sum-and-updates-have-same-attributes
 
2043
 (implies
 
2044
  (and
 
2045
   (true-listp rtmvars1)
 
2046
   (true-listp rtmvarsres)
 
2047
   (equal (len rtmvars1) (len rtmvarsres))
 
2048
   (equal-sum-and-updates rtmvarsres rtmvars1 rtmvars2 rtmvars3 rns rtmmem rtmmemafter))
 
2049
  (equal (var-attributes rtmvarsres rtmmemafter) (var-attributes rtmvars1 rtmmem))))
 
2050
 
 
2051
(in-theory (enable sum-list))
 
2052
 
 
2053
(defthm equal-sum-and-updates-have-values-that-are-sum-lists
 
2054
  (implies
 
2055
   (and
 
2056
    (equal (len rtmvars1) (len rtmvarsres))
 
2057
    (equal (len rtmvars2) (len rtmvarsres))
 
2058
    (equal (len rtmvars3) (len rtmvarsres))
 
2059
    (equal-sum-and-updates rtmvarsres rtmvars1 rtmvars2 rtmvars3 rns rtmmem rtmmemafter))
 
2060
   (equal (var-values rtmvarsres rtmmemafter)
 
2061
         (sum-list
 
2062
          (var-values rtmvars2 rtmmem)
 
2063
          (var-values rtmvars3 rtmmem)
 
2064
          rns)))
 
2065
 :hints ( ("Subgoal *1/2" :in-theory (enable var-value get-cell make-cell))))
 
2066
 
 
2067
 
 
2068
 
 
2069
 
 
2070
 
 
2071
(defthm behaviour-of-sum-and-update-norest
 
2072
 (and
 
2073
  (equal 
 
2074
   (var-attribute (sum-and-update-norest c1 c2 c3 mem)) 
 
2075
   (var-attribute (get-cell c1 mem)))
 
2076
  (equal 
 
2077
   (var-value (sum-and-update-norest c1 c2 c3 mem)) 
 
2078
   (mod
 
2079
    (+
 
2080
     (var-value (get-cell c2 mem))
 
2081
     (var-value (get-cell c3 mem)))
 
2082
    (prod *rns*)))
 
2083
  (equal 
 
2084
   (var-type (sum-and-update-norest c1 c2 c3 mem)) 
 
2085
   (var-type (get-cell c1 mem))))   
 
2086
 :hints (("Goal" :in-theory (enable var-type var-value var-attribute make-cell))))
 
2087
 
 
2088
 
 
2089
 
 
2090
    
 
2091
(defthm defexpansion 
 
2092
  (implies 
 
2093
   (not (null (var-value gcell)))
 
2094
  (equal
 
2095
   (equal-values-and-attributes gcell rtmvars rtmmem 'Int)
 
2096
   (and
 
2097
    (equal-values (var-values rtmvars rtmmem)
 
2098
                  (build-values-by-rns (var-value gcell) *rns*))
 
2099
    (equal-elements (var-attribute gcell)
 
2100
                    (var-attributes rtmvars rtmmem)))))
 
2101
  :hints (("Goal" :in-theory '((:definition equal-values-and-attributes)
 
2102
                               (:definition apply-direct-rns-to-value-according-to-type))
 
2103
           :use (:instance build-values-by-rns-extended-behaves-standardly-on-non-nils 
 
2104
                           (gem-value (var-value gcell)) 
 
2105
                           (rns *rns*)))))
 
2106
 
 
2107
 
 
2108
(defthm if-gem-is-sum-and-update-inf-every-rtm-var-is-sum-and-update-then-equal-values-is-kept
 
2109
 (implies
 
2110
  (and
 
2111
   (true-listp rtmvars1)
 
2112
   (true-listp rtmvarsres)
 
2113
   (equal (len rtmvars1) (len rtmvarsres))
 
2114
   (equal (len rtmvars2) (len rtmvarsres))
 
2115
   (equal (len rtmvars3) (len rtmvarsres))
 
2116
   (not (null (var-value (get-cell gvar1 gemmem))))
 
2117
   (integerp (var-value (get-cell gvar2 gemmem)))
 
2118
   (integerp (var-value (get-cell gvar3 gemmem)))
 
2119
   (equal-sum-and-updates rtmvarsres rtmvars1 rtmvars2 rtmvars3 *rns* rtmmem rtmmemafter)
 
2120
   (equal-values-and-attributes (get-cell gvar1 gemmem) rtmvars1 rtmmem 'Int)
 
2121
   (equal-values-and-attributes (get-cell gvar2 gemmem) rtmvars2 rtmmem 'Int)
 
2122
   (equal-values-and-attributes (get-cell gvar3 gemmem) rtmvars3 rtmmem 'Int))
 
2123
  (equal-values-and-attributes 
 
2124
   (sum-and-update-norest gvar1 gvar2 gvar3 gemmem)
 
2125
   rtmvarsres
 
2126
   rtmmemafter
 
2127
   'Int))
 
2128
 :hints (("Goal" 
 
2129
          :in-theory (union-theories (current-theory 'ground-zero)
 
2130
                                     '(
 
2131
                                       (:definition integer>1-listp)
 
2132
                                       (:definition equal-values) 
 
2133
                                       (:rewrite defexpansion)))
 
2134
          :use (    
 
2135
                (:instance greater-one-means-greater-zero (rns *rns*))
 
2136
                (:instance equal-sum-and-updates-have-values-that-are-sum-lists (rns *rns*))
 
2137
                (:instance equal-sum-and-updates-have-same-attributes           (rns *rns*))
 
2138
                (:instance sum-correspondence-by-put-list-h
 
2139
                           (gval1 (var-value (get-cell gvar2 gemmem)))
 
2140
                           (gval2 (var-value (get-cell gvar3 gemmem)))
 
2141
                           (rns *rns*))
 
2142
                (:instance behaviour-of-sum-and-update-norest
 
2143
                           (c1 gvar1)
 
2144
                           (c2 gvar2)
 
2145
                           (c3 gvar3)
 
2146
                           (mem gemmem)))))
 
2147
 )
 
2148
 
 
2149
 
 
2150
 
 
2151
 
 
2152
 
 
2153
 
 
2154
 
 
2155
(defthm if-a-var-value-is-same-then-var-values-are-list-of
 
2156
 (implies
 
2157
  (equal (var-value (get-cell (car rtmvars) rtmmem)) (var-value gcell))
 
2158
  (equal-values (var-values (make-n-list (car rtmvars) (len rns)) rtmmem)
 
2159
                (make-n-list (var-value gcell) (len rns)))))
 
2160
 
 
2161
(defthm if-a-var-attribute-is-same-then-var-attributes-are-list-of
 
2162
 (implies
 
2163
  (equal (var-attribute (get-cell (car rtmvars) rtmmem)) (var-attribute gcell))
 
2164
  (equal-elements 
 
2165
   (var-attribute gcell)
 
2166
   (var-attributes (make-n-list (car rtmvars) (len rns)) rtmmem))))
 
2167
 
 
2168
 
 
2169
 
 
2170
(defthm defexpansion-bool-values
 
2171
  (implies 
 
2172
    (or (equal (var-value gcell) 0)
 
2173
        (equal (var-value gcell) 1))
 
2174
  (implies
 
2175
   (equal-values-and-attributes gcell rtmvars rtmmem 'Bool)
 
2176
   (equal-values (var-values (make-n-list (car rtmvars) (len *rns*)) rtmmem)
 
2177
                  (build-values-by-rns (var-value gcell) *rns*))))
 
2178
  :hints (("Goal" :use ( (:instance if-a-var-value-is-same-then-var-values-are-list-of                            
 
2179
                                    (rns *rns*))))))
 
2180
 
 
2181
 
 
2182
 
 
2183
 
 
2184
(defthm equal-values-on-list-entails-equality-on-first-els
 
2185
 (implies
 
2186
  (and
 
2187
   (integerp n)
 
2188
   (> n 0)
 
2189
  (equal-values (var-values (make-n-list el n) mem)
 
2190
                (make-n-list val n)))
 
2191
  (equal-values (var-values (list el) mem)
 
2192
                (list val)))
 
2193
 :hints (("Subgoal *1/3'" :use ( (:instance make-n-list (el el) (n 1))
 
2194
                                 (:instance make-n-list (el val) (n 1)) ))))
 
2195
 
 
2196
 
 
2197
(defthm cell-types
 
2198
  (implies
 
2199
   (is-mem-cell-p gcell)
 
2200
   (or 
 
2201
    (equal (var-type gcell) 'Bool)
 
2202
    (equal (var-type gcell) 'Int)))
 
2203
  :hints (("Goal" :in-theory (enable my-or-2)))
 
2204
  :rule-classes nil)
 
2205
 
 
2206
(defthm bool-cell
 
2207
  (implies
 
2208
   (and
 
2209
    (is-mem-cell-p gcell)
 
2210
    (equal (var-type gcell) 'Bool))
 
2211
   (and
 
2212
    (integerp (var-value gcell))
 
2213
    (or (equal (var-value gcell) 0)
 
2214
        (equal (var-value gcell) 1))))
 
2215
  :rule-classes nil)
 
2216
 
 
2217
(defthm int-cell
 
2218
  (implies
 
2219
   (and
 
2220
    (is-mem-cell-p gcell)
 
2221
    (equal (var-type gcell) 'Int))
 
2222
   (integerp (var-value gcell)))
 
2223
  :rule-classes nil)
 
2224
 
 
2225
 
 
2226
(defthm defexpansion-bool-values-inv
 
2227
  (implies 
 
2228
   (and
 
2229
    (is-mem-cell-p gcell) 
 
2230
    (equal (var-type gcell) 'Bool)
 
2231
    (equal (type-expected rtmvars) (var-type gcell)))
 
2232
  (implies
 
2233
   (equal-values (var-values (eventually-make-list rtmvars (len *rns*)) rtmmem)
 
2234
                 (build-values-by-rns (var-value gcell) *rns*))
 
2235
   (equal-values
 
2236
    (var-values rtmvars rtmmem)
 
2237
    (apply-direct-rns-to-value-according-to-type gcell (var-type gcell)))))
 
2238
  :hints (("Goal" :use (bool-cell
 
2239
                        (:instance equal-values-on-list-entails-equality-on-first-els
 
2240
                                   (mem rtmmem)
 
2241
                                   (n (len *rns*)) 
 
2242
                                   (el (car rtmvars))
 
2243
                                   (val (var-value gcell)))
 
2244
                        (:instance a-boolean-has-same-rnss-than-list-of-itself
 
2245
                                   (val (var-value gcell)) (rns *rns*))))))
 
2246
 
 
2247
 
 
2248
 
 
2249
 
 
2250
(defthm defexpansion-bool-attrs-1
 
2251
  (implies
 
2252
   (equal-values-and-attributes gcell rtmvars rtmmem 'Bool)
 
2253
   (equal (var-attribute (get-cell (car rtmvars) rtmmem)) (var-attribute gcell))))
 
2254
 
 
2255
 
 
2256
(defthm defexpansion-bool-attrs
 
2257
  (implies
 
2258
   (equal-values-and-attributes gcell rtmvars rtmmem 'Bool)
 
2259
   (equal-elements 
 
2260
    (var-attribute gcell)
 
2261
    (var-attributes (make-n-list (car rtmvars) (len *rns*)) rtmmem)))
 
2262
  :hints (("Goal" :use ( defexpansion-bool-attrs-1
 
2263
                         (:instance if-a-var-attribute-is-same-then-var-attributes-are-list-of
 
2264
                                    (rns *rns*))))))
 
2265
 
 
2266
 
 
2267
(defthm defexpansion-bool-attrs-inv-1
 
2268
  (implies
 
2269
   (equal (type-expected rtmvars) 'Bool) 
 
2270
   (equal 
 
2271
    (var-attributes rtmvars rtmmem)
 
2272
    (list (var-attribute (get-cell (car rtmvars) rtmmem)))))
 
2273
  :hints (("Subgoal 1'" :use (:theorem (implies 
 
2274
                                  (and (true-listp rtmvars2)
 
2275
                                       (equal (+ 1 (len rtmvars2)) 1))
 
2276
                                  (endp rtmvars2)))))
 
2277
  :otf-flg t)
 
2278
 
 
2279
(defthm defexpansion-bool-attrs-inv-2
 
2280
  (implies
 
2281
   (and
 
2282
    (equal (type-expected rtmvars) 'Bool) 
 
2283
    (equal val (var-attribute (get-cell (car rtmvars) rtmmem))))
 
2284
   (equal-elements val (var-attributes rtmvars rtmmem))))
 
2285
 
 
2286
 
 
2287
(defthm defexpansion-bool-attrs-inv-3
 
2288
  (implies
 
2289
   (and
 
2290
    (integerp n)
 
2291
    (> n 0))
 
2292
  (implies
 
2293
   (equal-elements 
 
2294
    val 
 
2295
    (var-attributes (make-n-list car-rtmvars n) rtmmem))
 
2296
   (equal
 
2297
    val
 
2298
    (var-attribute (get-cell car-rtmvars rtmmem)))))
 
2299
  :hints (("Subgoal *1/3'" :use (:instance make-n-list (el car-rtmvars) (n 1))))
 
2300
  :rule-classes nil)
 
2301
 
 
2302
 
 
2303
(defthm defexpansion-bool-attrs-inv
 
2304
  (implies
 
2305
   (and
 
2306
    (equal (var-type gcell) 'Bool)
 
2307
    (equal (type-expected rtmvars) (var-type gcell)))
 
2308
  (implies
 
2309
   (equal-elements 
 
2310
    (var-attribute gcell)
 
2311
    (var-attributes (make-n-list (car rtmvars) (len *rns*)) rtmmem))
 
2312
   (equal-elements 
 
2313
    (var-attribute gcell)
 
2314
    (var-attributes rtmvars rtmmem))))
 
2315
  :hints (("Goal" :use 
 
2316
           ( defexpansion-bool-attrs-inv-1
 
2317
             defexpansion-bool-attrs-inv-2
 
2318
             (:instance defexpansion-bool-attrs-inv-3 
 
2319
                        (n (len *rns*)) 
 
2320
                        (car-rtmvars (car rtmvars))
 
2321
                        (val (var-attribute gcell)))))))
 
2322
 
 
2323
(defthm defexpansion-bool
 
2324
  (implies
 
2325
   (and
 
2326
    (is-mem-cell-p gcell)
 
2327
    (equal (var-type gcell) 'Bool)
 
2328
    (equal (type-expected rtmvars) (var-type gcell)))
 
2329
  (equal
 
2330
   (equal-values-and-attributes gcell rtmvars rtmmem 'Bool)
 
2331
   (and
 
2332
    (equal-values (var-values (make-n-list (car rtmvars) (len *rns*)) rtmmem)
 
2333
                  (build-values-by-rns (var-value gcell) *rns*))
 
2334
    (equal-elements 
 
2335
     (var-attribute gcell)
 
2336
     (var-attributes (make-n-list (car rtmvars) (len *rns*)) rtmmem)))))
 
2337
  :hints (("Goal" :use
 
2338
           ( bool-cell
 
2339
             defexpansion-bool-attrs
 
2340
             defexpansion-bool-values 
 
2341
             defexpansion-bool-attrs-inv
 
2342
             defexpansion-bool-values-inv))))
 
2343
  
 
2344
 
 
2345
 
 
2346
 
 
2347
 
 
2348
(defthm defexpansion-generic-bool
 
2349
  (implies 
 
2350
   (and
 
2351
    (is-mem-cell-p gcell) 
 
2352
    (equal (var-type gcell) 'Bool)
 
2353
    (equal (type-expected rtmvars) (var-type gcell)))
 
2354
  (equal 
 
2355
   (equal-values-and-attributes gcell rtmvars rtmmem (var-type gcell))
 
2356
   (and
 
2357
    (equal-values (var-values (eventually-make-list rtmvars (len *rns*)) rtmmem)
 
2358
                  (build-values-by-rns (var-value gcell) *rns*))
 
2359
    (equal-elements (var-attribute gcell)
 
2360
                    (var-attributes (eventually-make-list rtmvars (len *rns*)) rtmmem)))))
 
2361
  :hints (("Goal" :in-theory (union-theories (current-theory 'ground-zero)
 
2362
                                             '((:definition type-expected)
 
2363
                                               (:definition eventually-make-list)))
 
2364
                                             :use (defexpansion-bool bool-cell))))
 
2365
                                               
 
2366
(defthm defexpansion-generic-int
 
2367
  (implies 
 
2368
   (and
 
2369
    (is-mem-cell-p gcell) 
 
2370
    (equal (var-type gcell) 'Int)
 
2371
    (equal (type-expected rtmvars) (var-type gcell)))
 
2372
  (equal
 
2373
   (equal-values-and-attributes gcell rtmvars rtmmem (var-type gcell))
 
2374
   (and
 
2375
    (equal-values (var-values (eventually-make-list rtmvars (len *rns*)) rtmmem)
 
2376
                  (build-values-by-rns (var-value gcell) *rns*))
 
2377
    (equal-elements (var-attribute gcell)
 
2378
                    (var-attributes (eventually-make-list rtmvars (len *rns*)) rtmmem)))))
 
2379
  :hints (("Goal" :in-theory (union-theories (current-theory 'ground-zero)
 
2380
                                             '((:definition type-expected)
 
2381
                                               (:definition eventually-make-list)))
 
2382
                                             :use (defexpansion int-cell))))
 
2383
                                               
 
2384
 
 
2385
 
 
2386
 
 
2387
(defthm defexpansion-generic 
 
2388
  (implies 
 
2389
   (and
 
2390
    (is-mem-cell-p gcell) 
 
2391
    (equal (type-expected rtmvars) (var-type gcell)))
 
2392
  (equal
 
2393
    (equal-values-and-attributes gcell rtmvars rtmmem (var-type gcell))
 
2394
   (and
 
2395
    (equal-values (var-values (eventually-make-list rtmvars (len *rns*)) rtmmem)
 
2396
                  (build-values-by-rns (var-value gcell) *rns*))
 
2397
    (equal-elements (var-attribute gcell)
 
2398
                    (var-attributes (eventually-make-list rtmvars (len *rns*)) rtmmem)))))
 
2399
  :hints (("Goal"  
 
2400
          :cases ( (equal (var-type gcell) 'Bool) 
 
2401
                   (equal (var-type gcell) 'Int) ))
 
2402
          ("Subgoal 3" :use cell-types)
 
2403
          ("Subgoal 2" :use defexpansion-generic-bool)
 
2404
          ("Subgoal 1" :use defexpansion-generic-int)))
 
2405
 
 
2406
 
 
2407
 
 
2408
 
 
2409
 
 
2410
 
 
2411
(defthm if-gem-is-sum-and-update-inf-every-rtm-var-is-sum-and-update-then-equal-values-is-kept-g
 
2412
 (implies
 
2413
  (and
 
2414
   (true-listp rtmvars1)
 
2415
   (true-listp rtmvarsres)
 
2416
   (equal (len rtmvars1)                                     (len rtmvarsres))
 
2417
   (equal (len (eventually-make-list rtmvars2 (len *rns*)))  (len rtmvarsres))
 
2418
   (equal (len (eventually-make-list rtmvars3 (len *rns*)))  (len rtmvarsres))
 
2419
   (equal (var-type (get-cell gvar2 gemmem)) (type-expected rtmvars2))
 
2420
   (equal (var-type (get-cell gvar3 gemmem)) (type-expected rtmvars3))
 
2421
   (is-mem-cell-p (get-cell gvar1 gemmem))
 
2422
   (equal (var-type (get-cell gvar1 gemmem)) 'Int)
 
2423
   (is-mem-cell-p (get-cell gvar2 gemmem))
 
2424
   (is-mem-cell-p (get-cell gvar3 gemmem))
 
2425
   (equal-sum-and-updates 
 
2426
    rtmvarsres 
 
2427
    rtmvars1 
 
2428
    (eventually-make-list rtmvars2 (len *rns*))
 
2429
    (eventually-make-list rtmvars3 (len *rns*))
 
2430
    *rns* rtmmem rtmmemafter)
 
2431
   (equal-values-and-attributes (get-cell gvar1 gemmem) rtmvars1 rtmmem 'Int)
 
2432
   (equal-values-and-attributes (get-cell gvar2 gemmem) rtmvars2 rtmmem (var-type (get-cell gvar2 gemmem)))
 
2433
   (equal-values-and-attributes (get-cell gvar3 gemmem) rtmvars3 rtmmem (var-type (get-cell gvar3 gemmem))))
 
2434
  (equal-values-and-attributes 
 
2435
   (sum-and-update-norest gvar1 gvar2 gvar3 gemmem)
 
2436
   rtmvarsres
 
2437
   rtmmemafter
 
2438
   'Int))
 
2439
 :hints (("Goal" 
 
2440
          :in-theory (union-theories (current-theory 'ground-zero)
 
2441
                                     '((:definition integer>1-listp)
 
2442
                                       (:definition equal-values)
 
2443
                                       (:definition is-mem-cell-p)
 
2444
                                       (:rewrite defexpansion)))
 
2445
          :use (     
 
2446
                (:instance defexpansion-generic
 
2447
                           (gcell (get-cell gvar2 gemmem))
 
2448
                           (rtmvars rtmvars2))
 
2449
                (:instance defexpansion-generic
 
2450
                           (gcell (get-cell gvar3 gemmem))
 
2451
                           (rtmvars rtmvars3))
 
2452
                (:instance equal-sum-and-updates-have-values-that-are-sum-lists 
 
2453
                           (rtmvars2 (eventually-make-list rtmvars2 (len *rns*)))
 
2454
                           (rtmvars3 (eventually-make-list rtmvars3 (len *rns*)))
 
2455
                           (rns *rns*))
 
2456
                (:instance equal-sum-and-updates-have-same-attributes           
 
2457
                           (rtmvars2 (eventually-make-list rtmvars2 (len *rns*)))
 
2458
                           (rtmvars3 (eventually-make-list rtmvars3 (len *rns*)))
 
2459
                           (rns *rns*))
 
2460
                (:instance sum-correspondence-by-put-list-h
 
2461
                           (gval1 (var-value (get-cell gvar2 gemmem)))
 
2462
                           (gval2 (var-value (get-cell gvar3 gemmem)))
 
2463
                           (rns *rns*))
 
2464
                (:instance behaviour-of-sum-and-update-norest
 
2465
                           (c1 gvar1)
 
2466
                           (c2 gvar2)
 
2467
                           (c3 gvar3)
 
2468
                           (mem gemmem))))))
 
2469
 
 
2470
 
 
2471
 
 
2472
 
 
2473
 
 
2474
(in-theory (disable sum-list sum-correspondence-by-put-list 
 
2475
                    equal-sum-and-updates-have-same-attributes
 
2476
                    equal-sum-and-updates-have-values-that-are-sum-lists
 
2477
                    behaviour-of-sum-and-update-norest
 
2478
                    defexpansion
 
2479
                    if-a-var-value-is-same-then-var-values-are-list-of
 
2480
                    if-a-var-attribute-is-same-then-var-attributes-are-list-of
 
2481
                    defexpansion-generic-bool
 
2482
                    defexpansion-generic-int
 
2483
                    defexpansion-generic
 
2484
                    defexpansion-bool-values-inv
 
2485
                    defexpansion-bool-values
 
2486
                    defexpansion-bool-attrs-inv
 
2487
                    defexpansion-bool-attrs-inv-1
 
2488
                    defexpansion-bool-attrs-inv-2
 
2489
                    defexpansion-bool-attrs
 
2490
                    defexpansion-bool-attrs-1
 
2491
                    equal-values-on-list-entails-equality-on-first-els
 
2492
                    ))
 
2493
 
 
2494
 
 
2495
 
 
2496
 
 
2497
 
 
2498
(defun execute-n-rtm-adds (st n)
 
2499
  (if
 
2500
      (zp n)
 
2501
      st
 
2502
    (execute-n-rtm-adds 
 
2503
     (rtm-add 
 
2504
      (par1 (nth (pcc st) (code st))) 
 
2505
      (par2 (nth (pcc st) (code st))) 
 
2506
      (par3 (nth (pcc st) (code st))) 
 
2507
      (par4 (nth (pcc st) (code st))) 
 
2508
     st)
 
2509
     (1- n))))
 
2510
 
 
2511
 
 
2512
(defthm all-rtm-adds-means-only-adds-are-executed
 
2513
 (implies
 
2514
  (all-rtm-adds-for-n-steps st n)
 
2515
  (equal
 
2516
   (execute-n-rtm-adds st n)
 
2517
   (execute-n-instructions st n)))
 
2518
 :hints (("Goal" :in-theory (disable rtm-add member-equal nth par1 par2 par3))))
 
2519
 
 
2520
 
 
2521
(defun adds-list-n (l1 l2 l3 l4 mem n)
 
2522
  (if (zp n)
 
2523
      mem
 
2524
    (adds-list-n (cdr l1) (cdr l2) (cdr l3) (cdr l4)
 
2525
               (put-cell 
 
2526
                (car l1) 
 
2527
                (sum-and-update 
 
2528
                 (car l1)
 
2529
                 (car l2)
 
2530
                 (car l3)
 
2531
                 (car l4)
 
2532
                 mem)
 
2533
                mem)
 
2534
               (1- n))))
 
2535
 
 
2536
 
 
2537
 
 
2538
 
 
2539
 
 
2540
      
 
2541
 
 
2542
(in-theory (disable member-equal))
 
2543
 
 
2544
 
 
2545
(in-theory (enable make-cell))
 
2546
 
 
2547
 
 
2548
 
 
2549
(defthm execute-n-rtm-adds-tantamount-to-add-list-n
 
2550
 (implies
 
2551
  (and
 
2552
   (all-rtm-adds-for-n-steps st n)
 
2553
   (>= (pcc st) 0)
 
2554
   (rtm-statep st))
 
2555
  (equal
 
2556
   (mem (execute-n-rtm-adds st n))
 
2557
   (adds-list-n 
 
2558
    (listpars1 st n)
 
2559
    (listpars2 st n)
 
2560
    (listpars3 st n)
 
2561
    (listpars4 st n)
 
2562
    (mem st)
 
2563
    n)))
 
2564
 :hints 
 
2565
         (("Goal" :induct t ) 
 
2566
          ("Subgoal *1/2.2" :in-theory '((:definition all-rtm-adds-for-n-steps)
 
2567
                                         (:definition execute-instruction)
 
2568
                                         (:definition rtm-add)
 
2569
                                         (:definition make-state)
 
2570
                                         (:definition mem))
 
2571
           )     
 
2572
          ("Subgoal *1/2" 
 
2573
                   :use ( execute-n-rtm-adds
 
2574
                          (:instance adds-list-n 
 
2575
                                     (l1 (listpars1 st n))
 
2576
                                     (l2 (listpars2 st n))
 
2577
                                     (l3 (listpars3 st n))
 
2578
                                     (l4 (listpars4 st n))
 
2579
                                     (mem (mem st)))
 
2580
                          lemma12-lp1r lemma12-lp2r lemma12-lp3r lemma12-lp4r 
 
2581
                          (:theorem
 
2582
                           (IMPLIES (AND (ALL-RTM-ADDS-FOR-N-STEPS ST N)
 
2583
                                         (>= (pcc st) 0)
 
2584
                                         (not (zp n)))
 
2585
                                    (equal (mem (execute-instruction st)) 
 
2586
                                           (PUT-CELL (CAR (LISTPARS1 ST N))
 
2587
                                                     (SUM-AND-UPDATE (CAR (LISTPARS1 ST N)) 
 
2588
                                                                     (CAR (LISTPARS2 ST N)) 
 
2589
                                                                     (CAR (LISTPARS3 ST N))
 
2590
                                                                     (CAR (LISTPARS4 ST N))
 
2591
                                                                     (MEM ST))
 
2592
                                                     (MEM ST)))))
 
2593
                          executing-rtm-instruction-retrieves-a-rtm-state-from-rtm-state
 
2594
                          instruction-incrementing-pvv))))
 
2595
 
 
2596
 
 
2597
(in-theory (disable lemma12-lp1r  lemma12-lp2r lemma12-lp3r lemma12-lp4r ))
 
2598
 
 
2599
 
 
2600
 
 
2601
 
 
2602
 
 
2603
 
 
2604
 
 
2605
 
 
2606
 
 
2607
 
 
2608
(defun adds-list-e (c1 c2 c3 c4 mem)
 
2609
  (if
 
2610
      (endp c1) 
 
2611
      mem
 
2612
    (adds-list-e
 
2613
     (cdr c1)
 
2614
     (cdr c2)
 
2615
     (cdr c3)
 
2616
     (cdr c4)
 
2617
     (put-cell (car c1) (sum-and-update (car c1) (car c2) (car c3) (car c4) mem) mem))))
 
2618
 
 
2619
     
 
2620
 
 
2621
(defthm adds-list-e-is-adds-list-n
 
2622
  (equal (adds-list-e c1 c2 c3 c4 mem) (adds-list-n c1 c2 c3 c4 mem (len c1)))
 
2623
  :rule-classes nil)
 
2624
 
 
2625
 
 
2626
 
 
2627
(defthm execute-n-instructions-tantamount-to-add-list-e
 
2628
 (implies
 
2629
  (and
 
2630
   (integerp n)
 
2631
   (>= n 0)
 
2632
   (all-rtm-adds-for-n-steps st n)
 
2633
   (>= (pcc st) 0)
 
2634
   (rtm-statep st))
 
2635
  (equal
 
2636
   (mem (execute-n-instructions st n))
 
2637
   (adds-list-e
 
2638
    (listpars1 st n)
 
2639
    (listpars2 st n)
 
2640
    (listpars3 st n)
 
2641
    (listpars4 st n)
 
2642
    (mem st))))
 
2643
 :hints (("Goal" :in-theory nil
 
2644
          :use ((:instance adds-list-e-is-adds-list-n 
 
2645
                           (c1 (listpars1 st n))
 
2646
                           (c2 (listpars2 st n))
 
2647
                           (c3 (listpars3 st n))
 
2648
                           (c4 (listpars4 st n))
 
2649
                           (mem (mem st)))
 
2650
                execute-n-rtm-adds-tantamount-to-add-list-n
 
2651
                all-rtm-adds-means-only-adds-are-executed
 
2652
                length-of-listpars1-n-is-n))))
 
2653
 
 
2654
 
 
2655
 
 
2656
 
 
2657
 
 
2658
 
 
2659
 
 
2660
 
 
2661
 
 
2662
 
 
2663
(defthm not-in-list-untouched-by-adds-list-e
 
2664
  (implies
 
2665
   (not (member-equal-bool v l1))
 
2666
   (equal (get-cell v (adds-list-e l1 l2 l3 l4 mem)) (get-cell v mem)))
 
2667
  :hints (("Goal" :in-theory (disable sum-and-update))))
 
2668
 
 
2669
(defthm not-in-list-untouched-by-adds-list-e-1
 
2670
  (implies
 
2671
   (not (member-equal-bool (car l1) (cdr l1)))
 
2672
   (equal (get-cell (car l1) (adds-list-e (cdr l1) (cdr l2) (cdr l3) (cdr l4) mem)) 
 
2673
          (get-cell (car l1) mem))))
 
2674
 
 
2675
 
 
2676
(defthm sum-and-update-independent-from-firstbn
 
2677
 (implies
 
2678
  (and
 
2679
   (not (member-equal-bool (nth idx l1) (firstn idx l1)))
 
2680
   (not (member-equal-bool (nth idx l2) (firstn idx l1)))
 
2681
   (not (member-equal-bool (nth idx l3) (firstn idx l1))))
 
2682
  (equal (sum-and-update 
 
2683
          (nth idx l1)
 
2684
          (nth idx l2)
 
2685
          (nth idx l3)
 
2686
          (nth idx l4)
 
2687
          (adds-list-e (firstn idx l1) (firstn idx l2) (firstn idx l3) (firstn idx l4) mem))
 
2688
         (sum-and-update 
 
2689
          (nth idx l1)
 
2690
          (nth idx l2)
 
2691
          (nth idx l3)
 
2692
          (nth idx l4)
 
2693
          mem))))
 
2694
 
 
2695
 
 
2696
 
 
2697
(defthm adds-list-decomp
 
2698
 (implies
 
2699
  (and
 
2700
   (in-range idx l1)
 
2701
   (in-range idx l2)
 
2702
   (in-range idx l3)
 
2703
   (in-range idx l4))
 
2704
  (equal
 
2705
   (adds-list-e l1 l2 l3 l4 mem)
 
2706
   (adds-list-e (nthcdr idx l1) (nthcdr idx l2) (nthcdr idx l3) (nthcdr idx l4)
 
2707
                (adds-list-e (firstn idx l1) (firstn idx l2) (firstn idx l3) (firstn idx l4) mem))))
 
2708
 :hints (("Goal" :in-theory (disable sum-and-update))))
 
2709
 
 
2710
 
 
2711
(defthm if-el-does-not-appear-after-its-position-then-adds-list-e-produces-its-sum
 
2712
 (implies
 
2713
  (and
 
2714
   (not (member-equal-bool (nth idx l1) (cdr (nthcdr idx l1))))
 
2715
   (in-range idx l1)
 
2716
   (in-range idx l2)
 
2717
   (in-range idx l3)
 
2718
   (in-range idx l4))
 
2719
  (equal
 
2720
   (get-cell (nth idx l1) (adds-list-e l1 l2 l3 l4 mem))
 
2721
   (sum-and-update 
 
2722
     (nth idx l1)
 
2723
     (nth idx l2)
 
2724
     (nth idx l3)
 
2725
     (nth idx l4)
 
2726
     (adds-list-e (firstn idx l1) (firstn idx l2) (firstn idx l3) (firstn idx l4) mem))))
 
2727
  :hints (("Goal" :in-theory (disable sum-and-update))))
 
2728
 
 
2729
 
 
2730
 
 
2731
 
 
2732
(defthm rtm-variable-of-adds-list-e-is-sum-of-correspondent-variables
 
2733
  (implies
 
2734
   (and
 
2735
    (positive-list rns)
 
2736
    (true-listp ll)
 
2737
    (no-duplicates-p (append-lists ll))
 
2738
    (in-range gem1 ll)
 
2739
    (in-range gem2 ll)
 
2740
    (in-range gem3 ll)
 
2741
    (in-range idx (nth gem1 ll))
 
2742
    (in-range idx (nth gem2 ll))
 
2743
    (in-range idx (nth gem3 ll))
 
2744
    (in-range idx rns))
 
2745
   (equal
 
2746
    (get-cell (nth idx (nth gem1 ll)) (adds-list-e (nth gem1 ll) (nth gem2 ll) (nth gem3 ll) rns mem))
 
2747
    (sum-and-update (nth idx (nth gem1 ll)) (nth idx (nth gem2 ll)) (nth idx (nth gem3 ll)) (nth idx rns) mem)))
 
2748
  :hints (("Goal" :in-theory (disable sum-and-update)
 
2749
           :use (
 
2750
                 (:instance no-duplicates-all-implies-no-duplicates-one (idx1 gem1))
 
2751
                 (:instance no-duplicates-means-an-element-does-not-appear-after-its-position (l (nth gem1 ll)))
 
2752
                 if-el-does-not-appear-after-its-position-then-adds-list-e-produces-its-sum
 
2753
                 (:instance adds-list-decomp 
 
2754
                            (l1 (nth gem1 ll)) (l2 (nth gem2 ll)) (l3 (nth gem3 ll)))
 
2755
                 (:instance sum-and-update-independent-from-firstbn
 
2756
                            (l1 (nth gem1 ll)) (l2 (nth gem2 ll)) (l3 (nth gem3 ll)))))))
 
2757
 
 
2758
 
 
2759
 
 
2760
(defun index-different-sum-and-updates (rtmvarsres rtmvars1 rtmvars2 rtmvars3 rns mem mem-after-add)
 
2761
  (cond
 
2762
   ( (endp rtmvarsres)
 
2763
     0 )
 
2764
   ( (not (equal (get-cell (car rtmvarsres) mem-after-add)
 
2765
                 (sum-and-update (car rtmvars1) (car rtmvars2) (car rtmvars3) (car rns) mem)))
 
2766
     0 )
 
2767
   ( t
 
2768
     (1+ (index-different-sum-and-updates 
 
2769
          (cdr rtmvarsres)
 
2770
          (cdr rtmvars1)
 
2771
          (cdr rtmvars2)
 
2772
          (cdr rtmvars3)
 
2773
          (cdr rns)
 
2774
          mem
 
2775
          mem-after-add)))))
 
2776
 
 
2777
(defthm if-bad-index-in-range-thne-must-be-nonsumandupdate
 
2778
  (let ((bad-idx (index-different-sum-and-updates rtmvarsres rtmvars1 rtmvars2 rtmvars3 rns mem mem-after-add)))
 
2779
    (implies 
 
2780
     (in-range bad-idx rtmvarsres) 
 
2781
     (not (equal 
 
2782
           (get-cell (nth bad-idx rtmvarsres) mem-after-add)
 
2783
           (sum-and-update 
 
2784
            (nth bad-idx rtmvars1)
 
2785
            (nth bad-idx rtmvars2)
 
2786
            (nth bad-idx rtmvars3)
 
2787
            (nth bad-idx rns)
 
2788
            mem)))))
 
2789
 :hints (("Goal" :in-theory (disable get-cell sum-and-update))))
 
2790
 
 
2791
 
 
2792
(defthm if-bad-index-not-in-range-then-every-equalsumandupdate
 
2793
  (let ((bad-idx (index-different-sum-and-updates rtmvarsres rtmvars1 rtmvars2 rtmvars3 rns mem mem-after-add)))
 
2794
    (implies (and (true-listp rtmvarsres)
 
2795
                  (not (in-range bad-idx rtmvarsres)))
 
2796
          (equal-sum-and-updates rtmvarsres rtmvars1 rtmvars2 rtmvars3 rns mem mem-after-add))))
 
2797
 
 
2798
 
 
2799
(defthm rtm-variable-of-adds-list-e-is-sum-and-updates
 
2800
  (implies
 
2801
   (and
 
2802
    (positive-list rns)
 
2803
    (true-listp ll)
 
2804
    (no-duplicates-p (append-lists ll))
 
2805
    (equal (len (nth gem1 ll)) (len (nth gem2 ll)))
 
2806
    (equal (len (nth gem1 ll)) (len (nth gem3 ll)))
 
2807
    (equal (len (nth gem1 ll)) (len rns))
 
2808
    (in-range gem1 ll)
 
2809
    (in-range gem2 ll)
 
2810
    (in-range gem3 ll)
 
2811
    (true-listp (nth gem1 ll)))
 
2812
   (equal-sum-and-updates (nth gem1 ll) (nth gem1 ll) (nth gem2 ll) (nth gem3 ll) rns mem 
 
2813
    (adds-list-e (nth gem1 ll) (nth gem2 ll) (nth gem3 ll) rns mem)))
 
2814
  :hints (("Goal" :use (:instance rtm-variable-of-adds-list-e-is-sum-of-correspondent-variables
 
2815
                                  (idx (index-different-sum-and-updates 
 
2816
                                        (nth gem1 ll) 
 
2817
                                        (nth gem1 ll) 
 
2818
                                        (nth gem2 ll) 
 
2819
                                        (nth gem3 ll) 
 
2820
                                        rns 
 
2821
                                        mem 
 
2822
                                        (adds-list-e (nth gem1 ll) (nth gem2 ll) (nth gem3 ll) rns mem)))))
 
2823
          ("Goal'" :cases ( (in-range (index-different-sum-and-updates 
 
2824
                                      (nth gem1 ll) 
 
2825
                                      (nth gem1 ll) 
 
2826
                                      (nth gem2 ll) 
 
2827
                                      (nth gem3 ll) 
 
2828
                                      rns 
 
2829
                                      mem 
 
2830
                                      (adds-list-e (nth gem1 ll) (nth gem2 ll) (nth gem3 ll) rns mem))
 
2831
                                     (nth gem1 ll)) ) )
 
2832
          ("Subgoal 1" :in-theory '((:definition in-range)
 
2833
                                    (:rewrite if-bad-index-in-range-thne-must-be-nonsumandupdate)))
 
2834
          ("Subgoal 2" :in-theory '((:rewrite if-bad-index-not-in-range-then-every-equalsumandupdate)))))
 
2835
          
 
2836
                                      
 
2837
          
 
2838
          
 
2839
(defthm any-element-of-make-list-does-not-appear-into-other-lists
 
2840
 (implies
 
2841
  (and
 
2842
   (integerp n)
 
2843
   (true-listp ll)
 
2844
   (no-duplicates-p (append-lists ll))
 
2845
   (in-range gem1 ll)
 
2846
   (in-range gem2 ll)
 
2847
   (not (equal gem1 gem2))
 
2848
   (equal (len (nth gem1 ll)) 1)
 
2849
   (in-range idx (make-n-list (car (nth gem1 ll)) n)))
 
2850
  (not (member-equal-bool 
 
2851
        (nth idx (make-n-list (car (nth gem1 ll)) n))
 
2852
        (nth gem2 ll))))
 
2853
 :hints (("Goal" :use 
 
2854
          (
 
2855
           (:instance 
 
2856
            el-of-makelist-is-el
 
2857
            (el (car (nth gem1 ll))))       
 
2858
           (:instance generalized-disjunctivity-unordered-2 
 
2859
                      (idx1 gem1) (idx2 gem2) (el1 (car (nth gem1 ll)))))))
 
2860
 :otf-flg t)
 
2861
 
 
2862
(defthm firstns-do-not-cotain-el-of-make-n-list-if-diff
 
2863
 (implies
 
2864
  (and
 
2865
   (integerp n)
 
2866
   (true-listp ll)
 
2867
   (no-duplicates-p (append-lists ll))
 
2868
   (in-range gem1 ll)
 
2869
   (in-range gem2 ll)
 
2870
   (not (equal gem1 gem2))
 
2871
   (equal (len (nth gem1 ll)) 1)
 
2872
   (in-range idx (make-n-list (car (nth gem1 ll)) n)))
 
2873
  (not (member-equal-bool 
 
2874
        (nth idx (make-n-list (car (nth gem1 ll)) n))
 
2875
        (firstn idx (nth gem2 ll)))))
 
2876
 :hints (("Goal" :use
 
2877
          (
 
2878
           (:instance no-member-holds-on-firstn 
 
2879
                      (el (nth idx (make-n-list (car (nth gem1 ll)) n)))
 
2880
                      (l (nth gem2 ll)))
 
2881
           any-element-of-make-list-does-not-appear-into-other-lists))))
 
2882
 
 
2883
 
 
2884
 
 
2885
(defthm rtm-variable-of-adds-list-e-is-sum-of-correspondent-variables-when-var-3-is-boolean
 
2886
  (implies
 
2887
   (and
 
2888
    (integerp n)
 
2889
    (positive-list rns)
 
2890
    (true-listp ll)
 
2891
    (no-duplicates-p (append-lists ll))
 
2892
    (in-range gem1 ll)
 
2893
    (in-range gem2 ll)
 
2894
    (in-range gem3 ll)
 
2895
    (not (equal gem1 gem3))
 
2896
    (equal (len (nth gem3 ll)) 1)
 
2897
    (in-range idx (nth gem1 ll))
 
2898
    (in-range idx (nth gem2 ll))
 
2899
    (in-range idx (make-n-list (car (nth gem3 ll)) n))
 
2900
    (in-range idx rns))
 
2901
   (equal
 
2902
    (get-cell (nth idx (nth gem1 ll)) 
 
2903
              (adds-list-e 
 
2904
               (nth gem1 ll) 
 
2905
               (nth gem2 ll) 
 
2906
               (make-n-list (car (nth gem3 ll)) n)
 
2907
               rns mem))
 
2908
    (sum-and-update 
 
2909
     (nth idx (nth gem1 ll)) 
 
2910
     (nth idx (nth gem2 ll)) 
 
2911
     (nth idx (make-n-list (car (nth gem3 ll)) n))
 
2912
     (nth idx rns) mem)))
 
2913
  :hints (("Goal" :in-theory (disable sum-and-update)
 
2914
           :use (
 
2915
                 (:instance firstns-do-not-cotain-el-of-make-n-list-if-diff (gem1 gem3) (gem2 gem1))
 
2916
                 (:instance no-duplicates-all-implies-no-duplicates-one (idx1 gem1))
 
2917
                 (:instance no-duplicates-means-an-element-does-not-appear-after-its-position (l (nth gem1 ll)))
 
2918
                 (:instance adds-list-decomp 
 
2919
                            (l1 (nth gem1 ll)) 
 
2920
                            (l2 (nth gem2 ll)) 
 
2921
                            (l3 (make-n-list (car (nth gem3 ll)) n))
 
2922
                            (l4 rns))                       
 
2923
                 (:instance sum-and-update-independent-from-firstbn
 
2924
                            (l1 (nth gem1 ll)) 
 
2925
                            (l2 (nth gem2 ll)) 
 
2926
                            (l3 (make-n-list (car (nth gem3 ll)) n))
 
2927
                            (l4 rns))))))
 
2928
                                
 
2929
(defthm rtm-variable-of-adds-list-e-is-sum-of-correspondent-variables-when-var-2-is-boolean
 
2930
  (implies
 
2931
   (and
 
2932
    (integerp n)
 
2933
    (positive-list rns)
 
2934
    (true-listp ll)
 
2935
    (no-duplicates-p (append-lists ll))
 
2936
    (in-range gem1 ll)
 
2937
    (in-range gem2 ll)
 
2938
    (in-range gem3 ll)
 
2939
    (not (equal gem1 gem2))
 
2940
    (equal (len (nth gem2 ll)) 1)
 
2941
    (in-range idx (nth gem1 ll))
 
2942
    (in-range idx (nth gem3 ll))
 
2943
    (in-range idx (make-n-list (car (nth gem2 ll)) n))
 
2944
    (in-range idx rns))
 
2945
   (equal
 
2946
    (get-cell (nth idx (nth gem1 ll)) 
 
2947
              (adds-list-e 
 
2948
               (nth gem1 ll) 
 
2949
               (make-n-list (car (nth gem2 ll)) n)
 
2950
               (nth gem3 ll) 
 
2951
               rns mem))
 
2952
    (sum-and-update 
 
2953
     (nth idx (nth gem1 ll)) 
 
2954
     (nth idx (make-n-list (car (nth gem2 ll)) n))
 
2955
     (nth idx (nth gem3 ll)) 
 
2956
     (nth idx rns) mem)))
 
2957
  :hints (("Goal" :in-theory (disable sum-and-update)
 
2958
           :use (
 
2959
                 (:instance firstns-do-not-cotain-el-of-make-n-list-if-diff (gem1 gem2) (gem2 gem1))
 
2960
                 (:instance no-duplicates-all-implies-no-duplicates-one (idx1 gem1))
 
2961
                 (:instance no-duplicates-means-an-element-does-not-appear-after-its-position (l (nth gem1 ll)))
 
2962
                 (:instance adds-list-decomp 
 
2963
                            (l1 (nth gem1 ll)) 
 
2964
                            (l2 (make-n-list (car (nth gem2 ll)) n))
 
2965
                            (l3 (nth gem3 ll)) 
 
2966
                            (l4 rns))                       
 
2967
                 (:instance sum-and-update-independent-from-firstbn
 
2968
                            (l1 (nth gem1 ll)) 
 
2969
                            (l2 (make-n-list (car (nth gem2 ll)) n))
 
2970
                            (l3 (nth gem3 ll)) 
 
2971
                            (l4 rns))))))
 
2972
                                
 
2973
(defthm rtm-variable-of-adds-list-e-is-sum-of-correspondent-variables-when-var-2and3-are-boolean
 
2974
  (implies
 
2975
   (and
 
2976
    (integerp n)
 
2977
    (positive-list rns)
 
2978
    (true-listp ll)
 
2979
    (no-duplicates-p (append-lists ll))
 
2980
    (in-range gem1 ll)
 
2981
    (in-range gem2 ll)
 
2982
    (in-range gem3 ll)
 
2983
    (not (equal gem1 gem2))
 
2984
    (not (equal gem1 gem3))
 
2985
    (equal (len (nth gem2 ll)) 1)
 
2986
    (equal (len (nth gem3 ll)) 1)
 
2987
    (in-range idx (nth gem1 ll))
 
2988
    (in-range idx (make-n-list (car (nth gem2 ll)) n))
 
2989
    (in-range idx (make-n-list (car (nth gem3 ll)) n))
 
2990
    (in-range idx rns))
 
2991
   (equal
 
2992
    (get-cell (nth idx (nth gem1 ll)) 
 
2993
              (adds-list-e 
 
2994
               (nth gem1 ll) 
 
2995
               (make-n-list (car (nth gem2 ll)) n)
 
2996
               (make-n-list (car (nth gem3 ll)) n)
 
2997
               rns mem))
 
2998
    (sum-and-update 
 
2999
     (nth idx (nth gem1 ll)) 
 
3000
     (nth idx (make-n-list (car (nth gem2 ll)) n))
 
3001
     (nth idx (make-n-list (car (nth gem3 ll)) n))
 
3002
     (nth idx rns) mem)))
 
3003
  :hints (("Goal" :in-theory (disable sum-and-update)
 
3004
           :use (
 
3005
                 (:instance firstns-do-not-cotain-el-of-make-n-list-if-diff (gem1 gem2) (gem2 gem1))
 
3006
                 (:instance firstns-do-not-cotain-el-of-make-n-list-if-diff (gem1 gem3) (gem2 gem1))
 
3007
                 (:instance no-duplicates-all-implies-no-duplicates-one (idx1 gem1))
 
3008
                 (:instance no-duplicates-means-an-element-does-not-appear-after-its-position (l (nth gem1 ll)))
 
3009
                 (:instance adds-list-decomp 
 
3010
                            (l1 (nth gem1 ll)) 
 
3011
                            (l2 (make-n-list (car (nth gem2 ll)) n))
 
3012
                            (l3 (make-n-list (car (nth gem3 ll)) n)) 
 
3013
                            (l4 rns))                       
 
3014
                 (:instance sum-and-update-independent-from-firstbn
 
3015
                            (l1 (nth gem1 ll)) 
 
3016
                            (l2 (make-n-list (car (nth gem2 ll)) n))
 
3017
                            (l3 (make-n-list (car (nth gem3 ll)) n))
 
3018
                            (l4 rns))))))
 
3019
                                
 
3020
 
 
3021
 
 
3022
 
 
3023
(defthm rtm-variable-of-adds-list-e-is-sum-of-correspondent-variables-with-all-vars-types
 
3024
  (implies
 
3025
   (and
 
3026
    (integerp n)
 
3027
    (positive-list rns)
 
3028
    (true-listp ll)
 
3029
    (no-duplicates-p (append-lists ll))
 
3030
    (in-range gem1 ll)
 
3031
    (in-range gem2 ll)
 
3032
    (in-range gem3 ll)
 
3033
    (not (equal (len (nth gem1 ll)) 1))
 
3034
    (in-range idx (nth gem1 ll))
 
3035
    (in-range idx (eventually-make-list (nth gem2 ll) n))
 
3036
    (in-range idx (eventually-make-list (nth gem3 ll) n))
 
3037
    (in-range idx rns))
 
3038
   (equal
 
3039
    (get-cell (nth idx (nth gem1 ll)) 
 
3040
              (adds-list-e 
 
3041
               (nth gem1 ll) 
 
3042
               (eventually-make-list (nth gem2 ll) n)
 
3043
               (eventually-make-list (nth gem3 ll) n)
 
3044
               rns mem))
 
3045
    (sum-and-update 
 
3046
     (nth idx (nth gem1 ll)) 
 
3047
     (nth idx (eventually-make-list (nth gem2 ll) n))
 
3048
     (nth idx (eventually-make-list (nth gem3 ll) n))
 
3049
     (nth idx rns) mem)))
 
3050
  :hints (("Goal" :in-theory (union-theories (current-theory 'ground-zero)
 
3051
                                                  '((:definition eventually-make-list)))
 
3052
          :cases
 
3053
           ( (and (not (equal (len (nth gem3 ll)) 1))      (equal (len (nth gem2 ll)) 1))
 
3054
             (and      (equal (len (nth gem3 ll)) 1)  (not (equal (len (nth gem2 ll)) 1)))
 
3055
             (and (not (equal (len (nth gem3 ll)) 1)) (not (equal (len (nth gem2 ll)) 1)))
 
3056
             (and      (equal (len (nth gem3 ll)) 1)       (equal (len (nth gem2 ll)) 1))))
 
3057
          ("Subgoal 4"
 
3058
           :use rtm-variable-of-adds-list-e-is-sum-of-correspondent-variables-when-var-2-is-boolean)
 
3059
          ("Subgoal 3"
 
3060
           :use rtm-variable-of-adds-list-e-is-sum-of-correspondent-variables-when-var-3-is-boolean)
 
3061
          ("Subgoal 2"
 
3062
           :use rtm-variable-of-adds-list-e-is-sum-of-correspondent-variables)
 
3063
          ("Subgoal 1"
 
3064
           :use rtm-variable-of-adds-list-e-is-sum-of-correspondent-variables-when-var-2and3-are-boolean)))
 
3065
 
 
3066
 
 
3067
 
 
3068
(defthm sum-and-updates-holding-for-every-variable-type
 
3069
  (implies
 
3070
   (and
 
3071
    (integerp n)
 
3072
    (not (equal (len (nth gem1 ll)) 1))
 
3073
    (positive-list rns)
 
3074
    (true-listp ll)
 
3075
    (no-duplicates-p (append-lists ll))
 
3076
    (equal (len (nth gem1 ll)) (len (eventually-make-list (nth gem2 ll) n)))
 
3077
    (equal (len (nth gem1 ll)) (len (eventually-make-list (nth gem3 ll) n)))
 
3078
    (equal (len (nth gem1 ll)) (len rns))
 
3079
    (in-range gem1 ll)
 
3080
    (in-range gem2 ll)
 
3081
    (in-range gem3 ll)
 
3082
    (true-listp (nth gem1 ll)))
 
3083
   (equal-sum-and-updates 
 
3084
    (nth gem1 ll) 
 
3085
    (nth gem1 ll) 
 
3086
    (eventually-make-list (nth gem2 ll) n)
 
3087
    (eventually-make-list (nth gem3 ll) n)
 
3088
    rns mem 
 
3089
    (adds-list-e 
 
3090
     (nth gem1 ll) 
 
3091
     (eventually-make-list (nth gem2 ll) n)
 
3092
     (eventually-make-list (nth gem3 ll) n)
 
3093
     rns mem)))
 
3094
  :hints (("Goal" :use (:instance rtm-variable-of-adds-list-e-is-sum-of-correspondent-variables-with-all-vars-types
 
3095
                                  (idx (index-different-sum-and-updates 
 
3096
                                        (nth gem1 ll) 
 
3097
                                        (nth gem1 ll) 
 
3098
                                        (eventually-make-list (nth gem2 ll) n)
 
3099
                                        (eventually-make-list (nth gem3 ll) n)
 
3100
                                        rns 
 
3101
                                        mem 
 
3102
                                        (adds-list-e 
 
3103
                                         (nth gem1 ll) 
 
3104
                                         (eventually-make-list (nth gem2 ll) n)
 
3105
                                         (eventually-make-list (nth gem3 ll) n)
 
3106
                                         rns mem)))))
 
3107
          ("Goal'" :cases ( (in-range (index-different-sum-and-updates 
 
3108
                                      (nth gem1 ll) 
 
3109
                                      (nth gem1 ll) 
 
3110
                                      (eventually-make-list (nth gem2 ll) n)
 
3111
                                      (eventually-make-list (nth gem3 ll) n)
 
3112
                                      rns 
 
3113
                                      mem 
 
3114
                                      (adds-list-e 
 
3115
                                       (nth gem1 ll) 
 
3116
                                       (eventually-make-list (nth gem2 ll) n)
 
3117
                                       (eventually-make-list (nth gem3 ll) n)
 
3118
                                       rns mem))
 
3119
                                     (nth gem1 ll)) ) )
 
3120
          ("Subgoal 1" :in-theory '((:definition in-range)
 
3121
                                    (:rewrite if-bad-index-in-range-thne-must-be-nonsumandupdate)))
 
3122
          ("Subgoal 2" :in-theory '((:rewrite if-bad-index-not-in-range-then-every-equalsumandupdate)))))
 
3123
          
 
3124
 
 
3125
 
 
3126
(defthm lemma2-only-adds-in-rtm-add
 
3127
  (implies
 
3128
   (and
 
3129
    (gem-statep gstate)
 
3130
    (rtm-statep rstate)
 
3131
    (in-range (pcc gstate) (code gstate))
 
3132
    (in-range (pcc rstate) (code rstate))
 
3133
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-add)
 
3134
    (good-translation-gem-rtm gstate rstate m))
 
3135
   (all-rtm-adds-for-n-steps rstate (len *rns*)))
 
3136
  :hints (("Goal" :expand 
 
3137
           ( (good-translation-gem-rtm gstate rstate m)
 
3138
             (gem-statep gstate)
 
3139
             (rtm-statep rstate)
 
3140
             (in-range (pcc gstate) (code gstate))
 
3141
             (in-range (pcc rstate) (code rstate)))
 
3142
           :in-theory nil))
 
3143
  :rule-classes nil)
 
3144
 
 
3145
        
 
3146
(defthm cells-untouched-by-execute-on-other-cell-add
 
3147
 (implies
 
3148
  (and
 
3149
   (integerp n)
 
3150
   (>= n 0)
 
3151
   (all-rtm-adds-for-n-steps st n)
 
3152
   (>= (pcc st) 0)
 
3153
   (rtm-statep st)
 
3154
   (not (member-equal-bool v (listpars1 st n))))
 
3155
  (equal (get-cell v (mem st))
 
3156
         (get-cell v (mem (execute-n-instructions st n)))))
 
3157
 :hints (("Goal" 
 
3158
          :use (execute-n-instructions-tantamount-to-add-list-e
 
3159
                (:instance not-in-list-untouched-by-adds-list-e
 
3160
                                  (v v)
 
3161
                                  (l1 (listpars1 st n))
 
3162
                                  (l2 (listpars2 st n))
 
3163
                                  (l3 (listpars3 st n))
 
3164
                                  (l4 (listpars4 st n))
 
3165
                                  (mem (mem st)))))))
 
3166
 
 
3167
 
 
3168
(defthm rtm-variable-of-other-cell-untouched-add
 
3169
  (implies
 
3170
   (and
 
3171
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-add)
 
3172
    (>= (pcc rstate) 0)
 
3173
    (rtm-statep rstate)
 
3174
    (good-translation-gem-rtm gstate rstate m)
 
3175
    (in-range (pcc gstate) (code gstate))
 
3176
    (assoc-equal (par1 (nth (pcc gstate) (code gstate))) m)  
 
3177
    (true-listp m)
 
3178
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
3179
    (assoc-equal gvar1 m)
 
3180
    (not (equal gvar1 (par1 (nth (pcc gstate) (code gstate)))))
 
3181
    (in-range idx1 (rtmintvars-i gvar1 m)))
 
3182
   (equal (get-cell (nth idx1 (rtmintvars-i gvar1 m)) (mem rstate))
 
3183
          (get-cell (nth idx1 (rtmintvars-i gvar1 m)) (mem (execute-n-instructions rstate (len *rns*))))))
 
3184
  :hints (("Goal" :in-theory (current-theory 'ground-zero)
 
3185
           :expand (     (in-range (pcc gstate) (code gstate))
 
3186
                         (good-translation-gem-rtm gstate rstate m) )
 
3187
           :use ( 
 
3188
                 (:instance lemma1-different-vars-do-not-belong  (gvar2 (par1 (nth (pcc gstate) (code gstate)))))
 
3189
                 (:instance cells-untouched-by-execute-on-other-cell-add (st rstate) (n (len *rns*)) 
 
3190
                            (v (nth idx1 (rtmintvars-i gvar1 m))))))))
 
3191
 
 
3192
(defthm rtm-variables-of-other-cell-untouched-add
 
3193
  (implies
 
3194
   (and
 
3195
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-add)
 
3196
    (>= (pcc rstate) 0)
 
3197
    (rtm-statep rstate)
 
3198
    (good-translation-gem-rtm gstate rstate m)
 
3199
    (in-range (pcc gstate) (code gstate))
 
3200
    (assoc-equal (par1 (nth (pcc gstate) (code gstate))) m)   
 
3201
    (true-listp m)
 
3202
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
3203
    (assoc-equal gvar1 m)
 
3204
    (true-listp (rtmintvars-i gvar1 m))                         
 
3205
    (not (equal gvar1 (par1 (nth (pcc gstate) (code gstate))))))
 
3206
   (equal-get-cells
 
3207
          (rtmintvars-i gvar1 m) (mem rstate) (mem (execute-n-instructions rstate (len *rns*)))))
 
3208
  :hints (("Goal" :in-theory nil
 
3209
           :use ( (:instance rtm-variable-of-other-cell-untouched-add 
 
3210
                             (idx1 (idx-different-cell 
 
3211
                                    (rtmintvars-i gvar1 m) 
 
3212
                                    (mem rstate) 
 
3213
                                    (mem (execute-n-instructions rstate (len *rns*)))))) ))
 
3214
          ("Goal'" :cases ( (in-range
 
3215
                             (idx-different-cell 
 
3216
                                    (rtmintvars-i gvar1 m) 
 
3217
                                    (mem rstate) 
 
3218
                                    (mem (execute-n-instructions rstate (len *rns*))))
 
3219
                             (rtmintvars-i gvar1 m))))
 
3220
          ("Subgoal 2" :in-theory '((:rewrite if-bad-index-not-in-range-then-every-equal)))
 
3221
          ("Subgoal 1" :in-theory '((:forward-chaining if-bad-index-in-range-then-cells-must-be-different)))))
 
3222
 
 
3223
 
 
3224
 
 
3225
 
 
3226
(defthm properies-of-type-and-existence-of-current-args-add 
 
3227
 (implies
 
3228
  (and
 
3229
   (gem-statep gstate)
 
3230
   (in-range (pcc gstate) (code gstate))
 
3231
   (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-add))
 
3232
  (and
 
3233
   (equal (var-type (get-cell (par1 (nth (pcc gstate) (code gstate))) (mem gstate))) 'Int)
 
3234
   (assoc-equal (par1 (nth (pcc gstate) (code gstate))) (mem gstate))
 
3235
   (assoc-equal (par2 (nth (pcc gstate) (code gstate))) (mem gstate))
 
3236
   (assoc-equal (par3 (nth (pcc gstate) (code gstate))) (mem gstate))))
 
3237
  :hints (("Goal" :in-theory (enable get-cell)
 
3238
           :use (:instance in-range-instruction-is-gem-instruction 
 
3239
                           (pcc (pcc gstate)) 
 
3240
                           (code (code gstate))
 
3241
                           (mem (mem gstate)))))
 
3242
  :rule-classes nil)
 
3243
 
 
3244
 
 
3245
(defthm par1-of-current-instruction-is-into-mapping-add 
 
3246
 (implies
 
3247
  (and
 
3248
   (vars-inclusion (mem gstate) m)
 
3249
   (gem-statep gstate)
 
3250
   (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-add)  
 
3251
   (in-range (pcc gstate) (code gstate)))
 
3252
  (assoc-equal (par1 (nth (pcc gstate) (code gstate))) m))
 
3253
 :hints (("Goal" :in-theory (enable get-cell)
 
3254
         :use (properies-of-type-and-existence-of-current-args-add
 
3255
               (:instance inclusion-trans 
 
3256
                          (v (par1 (nth (pcc gstate) (code gstate))))
 
3257
                          (m1 (mem gstate))
 
3258
                          (m2 m))
 
3259
               (:instance in-range-instruction-is-gem-instruction 
 
3260
                                 (pcc (pcc gstate)) 
 
3261
                                 (code (code gstate))
 
3262
                                 (mem (mem gstate)))))))
 
3263
 
 
3264
 
 
3265
 
 
3266
(defthm teorema-main-con-pcc-in-range-su-variabile-non-interessata-final-add
 
3267
 (implies
 
3268
  (and
 
3269
   (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-add)
 
3270
   (good-translation-gem-rtm gstate rstate m)
 
3271
   (vars-inclusion (mem gstate) m)
 
3272
   (true-listp m)
 
3273
   (assoc-equal gvar1 m)
 
3274
   (gem-statep gstate)
 
3275
   (rtm-statep rstate)
 
3276
   (in-range (pcc gstate) (code gstate))
 
3277
   (in-range (pcc rstate) (code rstate))
 
3278
   (not (equal gvar1 (par1 (nth (pcc gstate) (code gstate)))))
 
3279
   (m-correspondent-values-p m (mem gstate) (mem rstate))
 
3280
   (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
3281
   (correct-wrt-arity m (mem gstate)))
 
3282
  (equal-values-and-attributes 
 
3283
   (get-cell gvar1 (mem (execute-instruction gstate)))
 
3284
   (rtmintvars-i gvar1 m)
 
3285
   (mem (execute-n-instructions rstate (len *rns*)))
 
3286
   (type-i gvar1 m)))
 
3287
 :hints (("Goal"
 
3288
          :in-theory '((:definition good-translation-gem-rtm))
 
3289
          :use (
 
3290
                par1-of-current-instruction-is-into-mapping-add
 
3291
                (:instance correct-wrt-arity-has-rtmintvars-i-tl (mem (mem gstate)))
 
3292
                (:instance m-correspondent-values-implies-equal-values-and-attribus
 
3293
                           (memgstate (mem gstate)) (memrstate (mem rstate)))
 
3294
                (:instance in-range (idx (pcc gstate)) (l (code gstate)))
 
3295
                (:instance in-range (idx (pcc rstate)) (l (code rstate)))
 
3296
                rtm-variables-of-other-cell-untouched-add
 
3297
                teorema-main-con-pcc-in-range-su-variabile-non-interessata
 
3298
                (:instance equal-get-cells-implies-equal-values-and-attributes-still-works      
 
3299
                           (gemcell (get-cell gvar1 (mem gstate)))
 
3300
                           (lcell (rtmintvars-i gvar1 m))
 
3301
                           (mem1 (mem rstate))
 
3302
                           (mem2 (mem (execute-n-instructions rstate (len *rns*))))
 
3303
                           (type (type-i gvar1 m)))))))
 
3304
 
 
3305
 
 
3306
(defthm teorema-main-con-pcc-in-range-su-variabile-interessata-add
 
3307
 (implies
 
3308
  (and
 
3309
   (gem-statep gstate)
 
3310
   (rtm-statep rstate)
 
3311
   (in-range (pcc gstate) (code gstate))
 
3312
   (in-range (pcc rstate) (code rstate))
 
3313
   (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-add)
 
3314
   (good-translation-gem-rtm gstate rstate m))
 
3315
  (equal
 
3316
   (mem (execute-n-instructions rstate (len *rns*)))
 
3317
   (adds-list-e 
 
3318
    (rtmintvars-i (par1 (nth (pcc gstate) (code gstate))) m)
 
3319
    (eventually-make-list (rtmintvars-i (par2 (nth (pcc gstate) (code gstate))) m) (len *rns*)) ;new
 
3320
    (eventually-make-list (rtmintvars-i (par3 (nth (pcc gstate) (code gstate))) m) (len *rns*)) ;new
 
3321
    *rns*
 
3322
    (mem rstate))))
 
3323
  :hints (("Goal"          
 
3324
           :in-theory (union-theories (current-theory 'ground-zero) '((:definition in-range)))
 
3325
           :use (good-translation-gem-rtm
 
3326
                 lemma2-only-adds-in-rtm-add
 
3327
                 (:instance execute-n-instructions-tantamount-to-add-list-e
 
3328
                            (n (len *rns*))
 
3329
                            (st rstate)))))
 
3330
  :rule-classes nil)
 
3331
 
 
3332
 
 
3333
 
 
3334
 
 
3335
(defthm posinrg-add
 
3336
  (implies
 
3337
   (and
 
3338
    (vars-inclusion (mem gstate) m)
 
3339
    (gem-statep gstate)
 
3340
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-add) 
 
3341
    (in-range (pcc gstate) (code gstate)))
 
3342
   (and
 
3343
    (in-range (pos-equal-0 (par1 (nth (pcc gstate) (code gstate))) m) m)
 
3344
    (in-range (pos-equal-0 (par2 (nth (pcc gstate) (code gstate))) m) m)
 
3345
    (in-range (pos-equal-0 (par3 (nth (pcc gstate) (code gstate))) m) m)))
 
3346
   :hints (("Goal" 
 
3347
            :use (properies-of-type-and-existence-of-current-args-add
 
3348
                        (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
3349
                                   (v (par1 (nth (pcc gstate) (code gstate)))))
 
3350
                        (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
3351
                                   (v (par2 (nth (pcc gstate) (code gstate)))))
 
3352
                        (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
3353
                                   (v (par3 (nth (pcc gstate) (code gstate)))))
 
3354
                        (:instance assoc-means-pos-in-range
 
3355
                                   (el (par1 (nth (pcc gstate) (code gstate))))
 
3356
                                   (l m))
 
3357
                        (:instance assoc-means-pos-in-range
 
3358
                                   (el (par2 (nth (pcc gstate) (code gstate))))
 
3359
                                   (l m))
 
3360
                        (:instance assoc-means-pos-in-range
 
3361
                                   (el (par3 (nth (pcc gstate) (code gstate))))
 
3362
                                   (l m)))))
 
3363
   :rule-classes nil)
 
3364
   
 
3365
(defthm eqlenss-add
 
3366
  (implies
 
3367
   (and
 
3368
    (gem-statep gstate)
 
3369
    (rtm-statep rstate)
 
3370
    (in-range (pcc gstate) (code gstate))
 
3371
    (in-range (pcc rstate) (code rstate))
 
3372
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-add) 
 
3373
    (good-translation-gem-rtm gstate rstate m))
 
3374
   (and
 
3375
    (equal (len (rtmintvars-i (par1 (nth (pcc gstate) (code gstate))) m)) (len *rns*))
 
3376
    (equal (len (eventually-make-list (rtmintvars-i (par2 (nth (pcc gstate) (code gstate))) m) (len *rns*))) (len *rns*))    
 
3377
    (equal (len (eventually-make-list (rtmintvars-i (par3 (nth (pcc gstate) (code gstate))) m) (len *rns*))) (len *rns*))))
 
3378
  :hints (("Goal" 
 
3379
           :in-theory (union-theories (current-theory 'ground-zero) '((:definition in-range)))
 
3380
           :use 
 
3381
           (
 
3382
            good-translation-gem-rtm
 
3383
            (:instance length-of-listpars1-n-is-n (st rstate) (n (len *rns*)))
 
3384
            (:instance length-of-listpars2-n-is-n (st rstate) (n (len *rns*)))
 
3385
            (:instance length-of-listpars3-n-is-n (st rstate) (n (len *rns*))))))
 
3386
  :rule-classes nil)
 
3387
 
 
3388
  
 
3389
(defthm equal-sum-and-updates-after-n-instr
 
3390
  (implies
 
3391
   (and  
 
3392
    (true-listp m)
 
3393
    (correct-wrt-arity m (mem gstate))
 
3394
    (gem-statep gstate)
 
3395
    (rtm-statep rstate)
 
3396
    (vars-inclusion (mem gstate) m)
 
3397
    (in-range (pcc gstate) (code gstate))
 
3398
    (in-range (pcc rstate) (code rstate))
 
3399
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-add)
 
3400
    (good-translation-gem-rtm gstate rstate m)
 
3401
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
3402
    (assoc-equal gvar1 m)
 
3403
    (equal gvar1 (par1 (nth (pcc gstate) (code gstate)))))
 
3404
   (equal-sum-and-updates 
 
3405
    (rtmintvars-i gvar1 m)
 
3406
    (rtmintvars-i (par1 (nth (pcc gstate) (code gstate))) m)
 
3407
    (eventually-make-list (rtmintvars-i (par2 (nth (pcc gstate) (code gstate))) m) (len *rns*)) ;new
 
3408
    (eventually-make-list (rtmintvars-i (par3 (nth (pcc gstate) (code gstate))) m) (len *rns*)) ;new
 
3409
    *rns* 
 
3410
    (mem rstate) 
 
3411
    (mem (execute-n-instructions rstate (len *rns*)))))
 
3412
  :hints (("Goal" 
 
3413
           :in-theory (union-theories (current-theory 'ground-zero) 
 
3414
                                      '((:type-prescription retrieve-rtmvars)
 
3415
                                        (:definition positive-list)
 
3416
                                        (:definition positivep)
 
3417
                                        (:definition in-range)))
 
3418
           :use
 
3419
           ( 
 
3420
             (:instance correct-wrt-arity-has-rtmintvars-i-tl (mem (mem gstate)))
 
3421
             (:instance sum-and-updates-holding-for-every-variable-type
 
3422
                        (n (len *rns*))
 
3423
                        (ll (retrieve-rtmvars m))
 
3424
                        (rns *rns*)
 
3425
                        (gem1 (pos-equal-0 (par1 (nth (pcc gstate) (code gstate))) m))
 
3426
                        (gem2 (pos-equal-0 (par2 (nth (pcc gstate) (code gstate))) m))
 
3427
                        (gem3 (pos-equal-0 (par3 (nth (pcc gstate) (code gstate))) m))
 
3428
                        (mem (mem rstate)))
 
3429
             lemma-help2
 
3430
             eqlenss-add
 
3431
             posinrg-add
 
3432
             teorema-main-con-pcc-in-range-su-variabile-interessata-add
 
3433
             (:instance rtmintvars-i-is-pos-equal-0-of-retrieve-vars
 
3434
                        (gvar (par1 (nth (pcc gstate) (code gstate)))))
 
3435
             (:instance rtmintvars-i-is-pos-equal-0-of-retrieve-vars
 
3436
                        (gvar (par2 (nth (pcc gstate) (code gstate)))))
 
3437
             (:instance rtmintvars-i-is-pos-equal-0-of-retrieve-vars
 
3438
                        (gvar (par3 (nth (pcc gstate) (code gstate)))))
 
3439
             (:instance rtmintvars-i-is-pos-equal-0-of-retrieve-vars
 
3440
                        (gvar (par4 (nth (pcc gstate) (code gstate)))))))))
 
3441
 
 
3442
 
 
3443
(defthm equal-sum-and-update-norest-afetr-one-instr
 
3444
  (implies
 
3445
   (and
 
3446
    (gem-statep gstate)
 
3447
    (in-range (pcc gstate) (code gstate))
 
3448
    (good-translation-gem-rtm gstate rstate m)
 
3449
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-add)
 
3450
    (equal gvar1 (par1 (nth (pcc gstate) (code gstate))))
 
3451
    (equal gvar2 (par2 (nth (pcc gstate) (code gstate))))
 
3452
    (equal gvar3 (par3 (nth (pcc gstate) (code gstate)))))
 
3453
   (equal (get-cell gvar1 (mem (execute-instruction gstate)))
 
3454
          (sum-and-update-norest gvar1 gvar2 gvar3 (mem gstate))))
 
3455
  :hints (("Goal" :in-theory (e/d (put-cell get-cell) 
 
3456
                                  (par1 par2 par3 par4 opcode pcc code nth gem-instruction-list-p
 
3457
                                        gen-eq-update sum-and-update sub-and-update sub-and-update-norest sum-and-update-norest))))
 
3458
  :rule-classes nil)
 
3459
 
 
3460
 
 
3461
(DEFTHM mem-cellity-of-current-gem-args-add
 
3462
  (IMPLIES
 
3463
   (AND (GEM-STATEP GSTATE)
 
3464
        (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-add) 
 
3465
        (IN-RANGE (PCC GSTATE) (CODE GSTATE)))
 
3466
   (AND (is-mem-cell-p (get-cell  (PAR1 (NTH (PCC GSTATE) (CODE GSTATE))) (mem gstate)))
 
3467
        (is-mem-cell-p (get-cell  (PAR2 (NTH (PCC GSTATE) (CODE GSTATE))) (mem gstate)))
 
3468
        (is-mem-cell-p (get-cell  (PAR3 (NTH (PCC GSTATE) (CODE GSTATE))) (mem gstate)))))
 
3469
  :HINTS
 
3470
  (("Goal" 
 
3471
    :USE
 
3472
    (:INSTANCE IN-RANGE-INSTRUCTION-IS-GEM-INSTRUCTION
 
3473
               (PCC (PCC GSTATE))
 
3474
               (CODE (CODE GSTATE))
 
3475
               (MEM (MEM GSTATE))))))
 
3476
 
 
3477
 
 
3478
 
 
3479
(defthm type-is-for-pars-add
 
3480
 (implies
 
3481
   (and
 
3482
    (true-listp m)
 
3483
    (vars-inclusion (mem gstate) m)
 
3484
    (gem-statep gstate)
 
3485
    (correct-wrt-arity m (mem gstate))
 
3486
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-add) 
 
3487
    (equal gvar1 (par1 (nth (pcc gstate) (code gstate))))
 
3488
    (equal gvar2 (par2 (nth (pcc gstate) (code gstate))))
 
3489
    (equal gvar3 (par3 (nth (pcc gstate) (code gstate))))
 
3490
    (in-range (pcc gstate) (code gstate)))
 
3491
   (equal (type-i gvar1 m) 'int))
 
3492
 :hints (("Goal" 
 
3493
          :in-theory (disable type-i-is-type-expected rtmintvars-i-is-pos-equal-0-of-retrieve-vars)
 
3494
          :use ( properies-of-type-and-existence-of-current-args-add
 
3495
                 (:instance type-i-is-vartyper (gvar1 gvar1))
 
3496
                 (:instance type-i-is-vartyper (gvar1 gvar2))
 
3497
                 (:instance type-i-is-vartyper (gvar1 gvar3))
 
3498
                 (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
3499
                            (v (par1 (nth (pcc gstate) (code gstate)))))
 
3500
                 (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
3501
                            (v (par2 (nth (pcc gstate) (code gstate)))))
 
3502
                 (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
3503
                            (v (par3 (nth (pcc gstate) (code gstate))))))))
 
3504
 :rule-classes nil)
 
3505
 
 
3506
   
 
3507
(defthm m-correspondence-kept-on-same-gvar-add
 
3508
  (implies
 
3509
   (and
 
3510
    (good-translation-gem-rtm gstate rstate m)
 
3511
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-add)
 
3512
    (equal gvar1 (par1 (nth (pcc gstate) (code gstate))))
 
3513
    (true-listp m)
 
3514
    (correct-wrt-arity m (mem gstate))
 
3515
    (gem-statep gstate)
 
3516
    (rtm-statep rstate)
 
3517
    (vars-inclusion (mem gstate) m)
 
3518
    (in-range (pcc gstate) (code gstate))
 
3519
    (in-range (pcc rstate) (code rstate))
 
3520
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
3521
    (assoc-equal gvar1 m)
 
3522
    (m-correspondent-values-p m (mem gstate) (mem rstate)))
 
3523
  (equal-values-and-attributes 
 
3524
   (get-cell gvar1 (mem (execute-instruction gstate)))
 
3525
   (rtmintvars-i gvar1 m)
 
3526
   (mem (execute-n-instructions rstate (len *rns*)))
 
3527
   (type-i gvar1 m)))
 
3528
  :hints (("Goal"  :in-theory nil
 
3529
           :use ( 
 
3530
                 properies-of-type-and-existence-of-current-args-add
 
3531
                 mem-cellity-of-current-gem-args-add
 
3532
                 good-translation-gem-rtm 
 
3533
                 (:instance type-i-is-vartyper (gvar1 gvar1) (mem (mem gstate)))
 
3534
                 (:instance type-i-is-vartyper (gvar1 (par2 (nth (pcc gstate) (code gstate)))) (mem (mem gstate)))
 
3535
                 (:instance type-i-is-vartyper (gvar1 (par3 (nth (pcc gstate) (code gstate)))) (mem (mem gstate)))
 
3536
                 (:instance type-i-is-type-expected (gvar  gvar1) (mem (mem gstate)))
 
3537
                 (:instance type-i-is-type-expected (gvar  (par2 (nth (pcc gstate) (code gstate)))) (mem (mem gstate)))
 
3538
                 (:instance type-i-is-type-expected (gvar  (par3 (nth (pcc gstate) (code gstate)))) (mem (mem gstate)))
 
3539
                 (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
3540
                            (v (par1 (nth (pcc gstate) (code gstate)))))
 
3541
                 (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
3542
                            (v (par2 (nth (pcc gstate) (code gstate)))))
 
3543
                 (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
3544
                            (v (par3 (nth (pcc gstate) (code gstate)))))
 
3545
                  (:instance
 
3546
                   equal-sum-and-update-norest-afetr-one-instr
 
3547
                   (gvar2 (par2 (nth (pcc gstate) (code gstate))))
 
3548
                   (gvar3 (par3 (nth (pcc gstate) (code gstate))))
 
3549
                   )
 
3550
                  eqlenss-add
 
3551
                  (:instance correct-wrt-arity-has-rtmintvars-i-tl (mem (mem gstate)))                       
 
3552
                  (:instance type-is-for-pars-add
 
3553
                   (gvar2 (par2 (nth (pcc gstate) (code gstate))))
 
3554
                   (gvar3 (par3 (nth (pcc gstate) (code gstate)))))
 
3555
                  (:instance m-correspondent-values-implies-equal-values-and-attribus
 
3556
                             (memgstate (mem gstate)) (memrstate (mem rstate)) 
 
3557
                             (gvar1 gvar1))
 
3558
                  (:instance m-correspondent-values-implies-equal-values-and-attribus
 
3559
                             (memgstate (mem gstate)) (memrstate (mem rstate)) 
 
3560
                             (gvar1 (par2 (nth (pcc gstate) (code gstate)))))
 
3561
                  (:instance m-correspondent-values-implies-equal-values-and-attribus
 
3562
                             (memgstate (mem gstate)) (memrstate (mem rstate)) 
 
3563
                             (gvar1 (par3 (nth (pcc gstate) (code gstate)))))
 
3564
                  equal-sum-and-updates-after-n-instr
 
3565
                  (:instance
 
3566
                   if-gem-is-sum-and-update-inf-every-rtm-var-is-sum-and-update-then-equal-values-is-kept-g
 
3567
                   (gvar2 (par2 (nth (pcc gstate) (code gstate))))
 
3568
                   (gvar3 (par3 (nth (pcc gstate) (code gstate))))
 
3569
                   (rtmvars1   (rtmintvars-i gvar1 m))
 
3570
                   (rtmvars2   (rtmintvars-i (par2 (nth (pcc gstate) (code gstate))) m))
 
3571
                   (rtmvars3   (rtmintvars-i (par3 (nth (pcc gstate) (code gstate))) m))
 
3572
                   (rtmvarsres (rtmintvars-i gvar1 m))
 
3573
                   (gemmem (mem gstate))
 
3574
                   (rtmmem (mem rstate))
 
3575
                   (rtmmemafter (mem (execute-n-instructions rstate (len *rns*)))))))))
 
3576
 
 
3577
 
 
3578
(defthm equal-values-correspondence-kept-by-any-execution-add
 
3579
  (implies
 
3580
   (and
 
3581
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-add)
 
3582
    (good-translation-gem-rtm gstate rstate m)
 
3583
    (true-listp m)
 
3584
    (correct-wrt-arity m (mem gstate))
 
3585
    (gem-statep gstate)
 
3586
    (rtm-statep rstate)
 
3587
    (vars-inclusion (mem gstate) m)
 
3588
    (in-range (pcc gstate) (code gstate))
 
3589
    (in-range (pcc rstate) (code rstate))
 
3590
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
3591
    (assoc-equal gvar1 m)
 
3592
    (m-correspondent-values-p m (mem gstate) (mem rstate)))
 
3593
  (equal-values-and-attributes 
 
3594
   (get-cell gvar1 (mem (execute-instruction gstate)))
 
3595
   (rtmintvars-i gvar1 m)
 
3596
   (mem (execute-n-instructions rstate (len *rns*)))
 
3597
   (type-i gvar1 m)))
 
3598
  :hints (("Goal" :use (m-correspondence-kept-on-same-gvar-add
 
3599
                        teorema-main-con-pcc-in-range-su-variabile-non-interessata-final-add))))
 
3600
 
 
3601
 
 
3602
 
 
3603
(defthm equal-values-correspondence-kept-by-any-execution-idxed-add
 
3604
  (implies
 
3605
   (and
 
3606
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-add)
 
3607
    (no-duplicates-p (retrieve-gemvars m))
 
3608
    (good-translation-gem-rtm gstate rstate m)
 
3609
    (alistp m)
 
3610
    (correct-wrt-arity m (mem gstate))
 
3611
    (gem-statep gstate)
 
3612
    (rtm-statep rstate)
 
3613
    (vars-inclusion (mem gstate) m)
 
3614
    (in-range (pcc gstate) (code gstate))
 
3615
    (in-range (pcc rstate) (code rstate))
 
3616
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
3617
    (in-range idx m)
 
3618
    (m-correspondent-values-p m (mem gstate) (mem rstate)))
 
3619
  (equal-values-and-attributes 
 
3620
   (get-cell (car (nth idx m)) (mem (execute-instruction gstate)))
 
3621
   (cdr (nth idx m)) 
 
3622
   (mem (execute-n-instructions rstate (len *rns*)))
 
3623
   (type-i-idx m idx)))   
 
3624
  :hints (("Goal" :in-theory (union-theories (current-theory 'ground-zero) '((:definition in-range))) 
 
3625
           :use ( (:theorem
 
3626
                   (implies
 
3627
                    (and
 
3628
                     (alistp m)
 
3629
                     (in-range idx m))
 
3630
                    (and
 
3631
                     (true-listp m)
 
3632
                     (assoc-equal (car (nth idx m)) m))))
 
3633
                  type-i-idx
 
3634
                  (:instance type-i (gvar (car (nth idx m))))
 
3635
                  (:instance rtmintvars-i-is-cdr-of-nth-entry (gvar (car (nth idx m))))
 
3636
                  (:instance equal-values-correspondence-kept-by-any-execution-add (gvar1 (car (nth idx m))))
 
3637
                  (:instance no-duplicates-has-pos-equal-right-in-that-place (l m)))))
 
3638
  :otf-flg t)
 
3639
 
 
3640
(defthm m-correspondence-kept-by-any-execution-idxed-add
 
3641
  (implies
 
3642
   (and
 
3643
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-add)
 
3644
    (no-duplicates-p (retrieve-gemvars m))
 
3645
    (good-translation-gem-rtm gstate rstate m)
 
3646
    (alistp m)
 
3647
    (correct-wrt-arity m (mem gstate))
 
3648
    (gem-statep gstate)
 
3649
    (rtm-statep rstate)
 
3650
    (vars-inclusion (mem gstate) m)
 
3651
    (in-range (pcc gstate) (code gstate))
 
3652
    (in-range (pcc rstate) (code rstate))
 
3653
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
3654
    (m-correspondent-values-p m (mem gstate) (mem rstate)))
 
3655
  (m-correspondent-values-p 
 
3656
   m 
 
3657
   (mem (execute-instruction gstate))
 
3658
   (mem (execute-n-instructions rstate (len *rns*)))))
 
3659
  :hints (("Goal" :use (:instance equal-values-correspondence-kept-by-any-execution-idxed-add
 
3660
                                  (idx (bad-idx-eqv-va m 
 
3661
                                                       (mem (execute-instruction gstate))
 
3662
                                                       (mem (execute-n-instructions rstate (len *rns*)))))))
 
3663
          ("Goal'" :cases ( (in-range (bad-idx-eqv-va m (mem (execute-instruction gstate))
 
3664
                                                       (mem (execute-n-instructions rstate (len *rns*)))) m)))
 
3665
          ("Subgoal 2" :in-theory '((:forward-chaining alistp-forward-to-true-listp)
 
3666
                                    (:rewrite if-bad-index-not-in-range-then-m-corr)))
 
3667
          ("Subgoal 1" :in-theory '((:rewrite if-bad-index-in-range-thne-must-be-different-vs)))))
 
3668
 
 
3669
 
 
3670
 
 
3671
 
 
3672
(defthm m-correspondence-and-other-conditions-kept-by-any-execution-add
 
3673
  (implies
 
3674
   (and
 
3675
    (alistp m)
 
3676
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-add)
 
3677
    (no-duplicates-p (retrieve-gemvars m))
 
3678
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
3679
    (good-translation-gem-rtm gstate rstate m)
 
3680
    (correct-wrt-arity m (mem gstate))
 
3681
    (gem-statep gstate)
 
3682
    (rtm-statep rstate)
 
3683
    (vars-inclusion (mem gstate) m)
 
3684
    (vars-inclusion m (mem gstate))
 
3685
    (in-range (pcc gstate) (code gstate))
 
3686
    (in-range (pcc rstate) (code rstate))
 
3687
    (m-entries-point-to-good-rtm-var-sets m (mem rstate))
 
3688
    (m-correspondent-values-p m (mem gstate) (mem rstate)))
 
3689
   (and
 
3690
    (good-translation-gem-rtm (execute-instruction gstate) (execute-n-instructions rstate (len *rns*)) m)
 
3691
    (rtm-statep (execute-n-instructions rstate (len *rns*)))
 
3692
    (m-entries-point-to-good-rtm-var-sets m (mem (execute-n-instructions rstate (len *rns*))))
 
3693
    (gem-statep (execute-instruction gstate))
 
3694
    (correct-wrt-arity m (mem (execute-instruction gstate)))
 
3695
    (vars-inclusion (mem (execute-instruction gstate)) m)
 
3696
    (vars-inclusion m (mem (execute-instruction gstate)))
 
3697
    (m-correspondent-values-p 
 
3698
     m 
 
3699
     (mem (execute-instruction gstate))
 
3700
     (mem (execute-n-instructions rstate (len *rns*))))))
 
3701
:hints (("Goal" 
 
3702
         :in-theory (disable 
 
3703
                     rtm-statep gem-statep
 
3704
                     pcc code opcode 
 
3705
                     execute-instruction rtmintvars-i par1 par2 par3 nth len member-equal) 
 
3706
         :use 
 
3707
         (m-correspondence-kept-by-any-execution-idxed-add
 
3708
          good-translation-gem-rtm 
 
3709
          (:instance execute-n-instructions-keeps-rtm-state-and-points-to-good
 
3710
                     (st rstate) (n (len *rns*)))
 
3711
          (:instance executing-gem-instruction-retrieves-a-gem-state-from-gem-state (st gstate))
 
3712
          (:instance executing-gem-instruction-preserves-correctness-wrt-arity (st gstate))
 
3713
          (:instance executing-gem-instruction-keeps-vars-inclusion-right      (st gstate))
 
3714
          (:instance executing-gem-instruction-keeps-vars-inclusion-left       (st gstate))))))
 
3715
 
 
3716
 
 
3717
 
 
3718
 
 
3719
 
 
3720
 
 
3721
 
 
3722
 
 
3723
 
 
3724
 
 
3725
 
 
3726
;;(ld "Proof-Of-Minus.lisp" :ld-error-action :error)
 
3727
 
 
3728
 
 
3729
(in-theory (enable 
 
3730
            (:executable-counterpart build-values-by-rns)
 
3731
            (:type-prescription build-values-by-rns)
 
3732
            (:induction build-values-by-rns)
 
3733
            (:definition build-values-by-rns)
 
3734
            posp-all posp mod mod-- mod-prod-makes-same-residues))
 
3735
 
 
3736
(in-theory (disable mod floor))
 
3737
 
 
3738
(defun sub-list (vl2 vl3 rns)
 
3739
  (if (endp vl2)
 
3740
      nil
 
3741
       (cons (mod (- (car vl2) (car vl3)) (car rns)) 
 
3742
             (sub-list (cdr vl2) (cdr vl3) (cdr rns)))))
 
3743
 
 
3744
 
 
3745
(defthm sub-correspondence-by-put-list
 
3746
 (implies
 
3747
  (and
 
3748
   (integerp gval1)
 
3749
   (integerp gval2)
 
3750
   (posp-all rns))
 
3751
   (equal (build-values-by-rns (- gval1 gval2) rns)
 
3752
          (sub-list
 
3753
           (build-values-by-rns gval1 rns)
 
3754
           (build-values-by-rns gval2 rns)
 
3755
           rns)))
 
3756
   :hints (("Goal" :induct t)))
 
3757
 
 
3758
 
 
3759
 
 
3760
 
 
3761
(in-theory (disable mod floor)) 
 
3762
 
 
3763
(defthm sub-correspondence-by-put-list-2-fin
 
3764
 (implies
 
3765
  (and
 
3766
   (integerp gval1)
 
3767
   (integerp gval2)
 
3768
   (posp-all rns))          
 
3769
  (equal (build-values-by-rns (mod (- gval1 gval2) (prod rns)) rns)
 
3770
         (sub-list
 
3771
          (build-values-by-rns  gval1 rns)
 
3772
          (build-values-by-rns  gval2 rns)
 
3773
         rns)))
 
3774
 :hints (("Goal" :in-theory (disable sum-correspondence-by-put-list-2-fin sum-correspondence-by-put-list)
 
3775
          :use (sub-correspondence-by-put-list 
 
3776
                (:instance mod-prod-makes-same-residues (x (- gval1 gval2)))))))
 
3777
 
 
3778
 
 
3779
 
 
3780
(in-theory (disable mod floor mod-- mod-prod-makes-same-residues))
 
3781
 
 
3782
 
 
3783
(defthm sub-correspondence-by-put-list-h
 
3784
 (implies
 
3785
  (and
 
3786
   (integerp gval1)
 
3787
   (integerp gval2)
 
3788
   (integer>1-listp rns))
 
3789
   (equal (build-values-by-rns (mod (- gval1 gval2) (prod rns)) rns)
 
3790
          (sub-list
 
3791
           (build-values-by-rns gval1 rns)
 
3792
           (build-values-by-rns gval2 rns)
 
3793
           rns)))
 
3794
   :hints (("Goal" :use (sub-correspondence-by-put-list-2-fin greater-one-means-greater-zero))))
 
3795
 
 
3796
 
 
3797
 
 
3798
 
 
3799
(defthm a-boolean-has-same-rnss-than-list-of-itself
 
3800
 (implies
 
3801
  (and
 
3802
   (integerp val)
 
3803
   (or (equal val 0) (equal val 1))
 
3804
   (integer>1-listp rns))
 
3805
  (equal 
 
3806
   (build-values-by-rns val rns) 
 
3807
   (make-n-list val (len rns)))))
 
3808
 
 
3809
 
 
3810
 
 
3811
(defthm sub-correspondence-by-put-list-on-boolean
 
3812
 (implies
 
3813
  (and
 
3814
   (integerp gval1)
 
3815
   (integerp gval2)
 
3816
   (or (equal gval2 0) (equal gval2 1))
 
3817
   (integer>1-listp rns))
 
3818
   (equal (build-values-by-rns (mod (- gval1 gval2) (prod rns)) rns)
 
3819
          (sub-list
 
3820
           (build-values-by-rns gval1 rns)
 
3821
           (make-n-list gval2 (len rns))
 
3822
           rns)))
 
3823
 :hints (("Goal" :in-theory nil
 
3824
          :use (sub-correspondence-by-put-list-h 
 
3825
                (:instance a-boolean-has-same-rnss-than-list-of-itself (val gval2))))))
 
3826
 
 
3827
(in-theory (disable mod--))
 
3828
 
 
3829
 
 
3830
(defun equal-sub-and-updates (reslist par1list par2list par3list primelist mem memafterputs)
 
3831
  (if (endp reslist)
 
3832
      (null reslist)
 
3833
    (and
 
3834
     (equal 
 
3835
      (get-cell (car reslist) memafterputs) 
 
3836
      (sub-and-update 
 
3837
       (car par1list)
 
3838
       (car par2list)
 
3839
       (car par3list)
 
3840
       (car primelist)
 
3841
       mem))
 
3842
     (equal-sub-and-updates
 
3843
      (cdr reslist)
 
3844
      (cdr par1list)
 
3845
      (cdr par2list)
 
3846
      (cdr par3list)
 
3847
      (cdr primelist)
 
3848
      mem
 
3849
      memafterputs))))
 
3850
 
 
3851
 
 
3852
 
 
3853
 
 
3854
 
 
3855
(defthm equal-sub-and-updates-have-same-attributes
 
3856
 (implies
 
3857
  (and
 
3858
   (true-listp rtmvars1)
 
3859
   (true-listp rtmvarsres)
 
3860
   (equal (len rtmvars1) (len rtmvarsres))
 
3861
   (equal-sub-and-updates rtmvarsres rtmvars1 rtmvars2 rtmvars3 rns rtmmem rtmmemafter))
 
3862
  (equal (var-attributes rtmvarsres rtmmemafter) (var-attributes rtmvars1 rtmmem)))
 
3863
 :hints (("Goal" :in-theory (enable var-attribute make-cell))))
 
3864
 
 
3865
;(in-theory (enable sub-list))
 
3866
 
 
3867
(defthm equal-sub-and-updates-have-values-that-are-sub-lists
 
3868
  (implies
 
3869
   (and
 
3870
    (equal (len rtmvars1) (len rtmvarsres))
 
3871
    (equal (len rtmvars2) (len rtmvarsres))
 
3872
    (equal (len rtmvars3) (len rtmvarsres))
 
3873
    (equal-sub-and-updates rtmvarsres rtmvars1 rtmvars2 rtmvars3 rns rtmmem rtmmemafter))
 
3874
   (equal (var-values rtmvarsres rtmmemafter)
 
3875
         (sub-list
 
3876
          (var-values rtmvars2 rtmmem)
 
3877
          (var-values rtmvars3 rtmmem)
 
3878
          rns)))
 
3879
 :hints ( ("Subgoal *1/2" :in-theory (enable var-value get-cell make-cell))))
 
3880
 
 
3881
 
 
3882
 
 
3883
 
 
3884
 
 
3885
(defthm behaviour-of-sub-and-update-norest
 
3886
 (and
 
3887
  (equal 
 
3888
   (var-attribute (sub-and-update-norest c1 c2 c3 mem)) 
 
3889
   (var-attribute (get-cell c1 mem)))
 
3890
  (equal 
 
3891
   (var-value (sub-and-update-norest c1 c2 c3 mem)) 
 
3892
   (mod
 
3893
    (-
 
3894
     (var-value (get-cell c2 mem))
 
3895
     (var-value (get-cell c3 mem)))
 
3896
    (prod *rns*)))
 
3897
  (equal 
 
3898
   (var-type (sub-and-update-norest c1 c2 c3 mem)) 
 
3899
   (var-type (get-cell c1 mem))))   
 
3900
 :hints (("Goal" :in-theory (enable var-type var-value var-attribute make-cell))))
 
3901
 
 
3902
 
 
3903
 
 
3904
    
 
3905
(defthm defexpansion-sub
 
3906
  (implies 
 
3907
   (not (null (var-value gcell)))
 
3908
  (equal
 
3909
   (equal-values-and-attributes gcell rtmvars rtmmem 'Int)
 
3910
   (and
 
3911
    (equal-values (var-values rtmvars rtmmem)
 
3912
                  (build-values-by-rns (var-value gcell) *rns*))
 
3913
    (equal-elements (var-attribute gcell)
 
3914
                    (var-attributes rtmvars rtmmem)))))
 
3915
  :hints (("Goal" :in-theory '((:definition equal-values-and-attributes)
 
3916
                               (:definition apply-direct-rns-to-value-according-to-type))
 
3917
           :use (:instance build-values-by-rns-extended-behaves-standardly-on-non-nils 
 
3918
                           (gem-value (var-value gcell)) 
 
3919
                           (rns *rns*)))))
 
3920
 
 
3921
  
 
3922
 
 
3923
 
 
3924
 
 
3925
(defthm if-gem-is-sub-and-update-inf-every-rtm-var-is-sub-and-update-then-equal-values-is-kept
 
3926
 (implies
 
3927
  (and
 
3928
   (true-listp rtmvars1)
 
3929
   (true-listp rtmvarsres)
 
3930
   (equal (len rtmvars1) (len rtmvarsres))
 
3931
   (equal (len rtmvars2) (len rtmvarsres))
 
3932
   (equal (len rtmvars3) (len rtmvarsres))
 
3933
   (not (null (var-value (get-cell gvar1 gemmem))))
 
3934
   (integerp (var-value (get-cell gvar2 gemmem)))
 
3935
   (integerp (var-value (get-cell gvar3 gemmem)))
 
3936
   (equal-sub-and-updates rtmvarsres rtmvars1 rtmvars2 rtmvars3 *rns* rtmmem rtmmemafter)
 
3937
   (equal-values-and-attributes (get-cell gvar1 gemmem) rtmvars1 rtmmem 'Int)
 
3938
   (equal-values-and-attributes (get-cell gvar2 gemmem) rtmvars2 rtmmem 'Int)
 
3939
   (equal-values-and-attributes (get-cell gvar3 gemmem) rtmvars3 rtmmem 'Int))
 
3940
  (equal-values-and-attributes 
 
3941
   (sub-and-update-norest gvar1 gvar2 gvar3 gemmem)
 
3942
   rtmvarsres
 
3943
   rtmmemafter
 
3944
   'Int))
 
3945
 :hints (("Goal" 
 
3946
          :in-theory (union-theories (current-theory 'ground-zero)
 
3947
                                     '(
 
3948
                                       (:definition integer>1-listp)
 
3949
                                       (:definition equal-values) 
 
3950
                                       (:rewrite defexpansion-sub)))
 
3951
          :use (    
 
3952
                (:instance greater-one-means-greater-zero (rns *rns*))
 
3953
                (:instance equal-sub-and-updates-have-values-that-are-sub-lists (rns *rns*))
 
3954
                (:instance equal-sub-and-updates-have-same-attributes           (rns *rns*))
 
3955
                (:instance sub-correspondence-by-put-list-h
 
3956
                           (gval1 (var-value (get-cell gvar2 gemmem)))
 
3957
                           (gval2 (var-value (get-cell gvar3 gemmem)))
 
3958
                           (rns *rns*))
 
3959
                (:instance behaviour-of-sub-and-update-norest
 
3960
                           (c1 gvar1)
 
3961
                           (c2 gvar2)
 
3962
                           (c3 gvar3)
 
3963
                           (mem gemmem)))))
 
3964
 )
 
3965
 
 
3966
 
 
3967
 
 
3968
 
 
3969
 
 
3970
 
 
3971
 
 
3972
 
 
3973
 
 
3974
 
 
3975
 
 
3976
 
 
3977
(defthm if-gem-is-sub-and-update-inf-every-rtm-var-is-sub-and-update-then-equal-values-is-kept-g
 
3978
 (implies
 
3979
  (and
 
3980
   (true-listp rtmvars1)
 
3981
   (true-listp rtmvarsres)
 
3982
   (equal (len rtmvars1)                                     (len rtmvarsres))
 
3983
   (equal (len (eventually-make-list rtmvars2 (len *rns*)))  (len rtmvarsres))
 
3984
   (equal (len (eventually-make-list rtmvars3 (len *rns*)))  (len rtmvarsres))
 
3985
   (equal (var-type (get-cell gvar2 gemmem)) (type-expected rtmvars2))
 
3986
   (equal (var-type (get-cell gvar3 gemmem)) (type-expected rtmvars3))
 
3987
   (is-mem-cell-p (get-cell gvar1 gemmem))
 
3988
   (equal (var-type (get-cell gvar1 gemmem)) 'Int)
 
3989
   (is-mem-cell-p (get-cell gvar2 gemmem))
 
3990
   (is-mem-cell-p (get-cell gvar3 gemmem))
 
3991
   (equal-sub-and-updates 
 
3992
    rtmvarsres 
 
3993
    rtmvars1 
 
3994
    (eventually-make-list rtmvars2 (len *rns*))
 
3995
    (eventually-make-list rtmvars3 (len *rns*))
 
3996
    *rns* rtmmem rtmmemafter)
 
3997
   (equal-values-and-attributes (get-cell gvar1 gemmem) rtmvars1 rtmmem 'Int)
 
3998
   (equal-values-and-attributes (get-cell gvar2 gemmem) rtmvars2 rtmmem (var-type (get-cell gvar2 gemmem)))
 
3999
   (equal-values-and-attributes (get-cell gvar3 gemmem) rtmvars3 rtmmem (var-type (get-cell gvar3 gemmem))))
 
4000
  (equal-values-and-attributes 
 
4001
   (sub-and-update-norest gvar1 gvar2 gvar3 gemmem)
 
4002
   rtmvarsres
 
4003
   rtmmemafter
 
4004
   'Int))
 
4005
 :hints (("Goal" 
 
4006
          :in-theory (union-theories (current-theory 'ground-zero)
 
4007
                                     '((:definition integer>1-listp)
 
4008
                                       (:definition equal-values)
 
4009
                                       (:definition is-mem-cell-p)
 
4010
                                       (:rewrite defexpansion-sub)))
 
4011
          :use (     
 
4012
                (:instance defexpansion-generic
 
4013
                           (gcell (get-cell gvar2 gemmem))
 
4014
                           (rtmvars rtmvars2))
 
4015
                (:instance defexpansion-generic
 
4016
                           (gcell (get-cell gvar3 gemmem))
 
4017
                           (rtmvars rtmvars3))
 
4018
                (:instance equal-sub-and-updates-have-values-that-are-sub-lists 
 
4019
                           (rtmvars2 (eventually-make-list rtmvars2 (len *rns*)))
 
4020
                           (rtmvars3 (eventually-make-list rtmvars3 (len *rns*)))
 
4021
                           (rns *rns*))
 
4022
                (:instance equal-sub-and-updates-have-same-attributes           
 
4023
                           (rtmvars2 (eventually-make-list rtmvars2 (len *rns*)))
 
4024
                           (rtmvars3 (eventually-make-list rtmvars3 (len *rns*)))
 
4025
                           (rns *rns*))
 
4026
                (:instance sub-correspondence-by-put-list-h
 
4027
                           (gval1 (var-value (get-cell gvar2 gemmem)))
 
4028
                           (gval2 (var-value (get-cell gvar3 gemmem)))
 
4029
                           (rns *rns*))
 
4030
                (:instance behaviour-of-sub-and-update-norest
 
4031
                           (c1 gvar1)
 
4032
                           (c2 gvar2)
 
4033
                           (c3 gvar3)
 
4034
                           (mem gemmem))))))
 
4035
 
 
4036
 
 
4037
 
 
4038
 
 
4039
 
 
4040
(in-theory (disable sub-list sub-correspondence-by-put-list 
 
4041
                    sub-correspondence-by-put-list-h
 
4042
                    sub-correspondence-by-put-list-2-fin
 
4043
                    equal-sub-and-updates-have-same-attributes
 
4044
                    equal-sub-and-updates-have-values-that-are-sub-lists
 
4045
                    behaviour-of-sub-and-update-norest
 
4046
                    defexpansion
 
4047
                    if-a-var-value-is-same-then-var-values-are-list-of
 
4048
                    if-a-var-attribute-is-same-then-var-attributes-are-list-of
 
4049
                    defexpansion-generic-bool
 
4050
                    defexpansion-generic-int
 
4051
                    defexpansion-generic
 
4052
                    defexpansion-bool-values-inv
 
4053
                    defexpansion-bool-values
 
4054
                    defexpansion-bool-attrs-inv
 
4055
                    defexpansion-bool-attrs-inv-1
 
4056
                    defexpansion-bool-attrs-inv-2
 
4057
                    defexpansion-bool-attrs
 
4058
                    defexpansion-bool-attrs-1
 
4059
                    equal-values-on-list-entails-equality-on-first-els
 
4060
                    ))
 
4061
 
 
4062
 
 
4063
 
 
4064
 
 
4065
 
 
4066
(defun execute-n-rtm-subs (st n)
 
4067
  (if
 
4068
      (zp n)
 
4069
      st
 
4070
    (execute-n-rtm-subs 
 
4071
     (rtm-sub 
 
4072
      (par1 (nth (pcc st) (code st))) 
 
4073
      (par2 (nth (pcc st) (code st))) 
 
4074
      (par3 (nth (pcc st) (code st))) 
 
4075
      (par4 (nth (pcc st) (code st))) 
 
4076
     st)
 
4077
     (1- n))))
 
4078
 
 
4079
 
 
4080
(defthm all-rtm-subs-means-only-subs-are-executed
 
4081
 (implies
 
4082
  (all-rtm-subs-for-n-steps st n)
 
4083
  (equal
 
4084
   (execute-n-rtm-subs st n)
 
4085
   (execute-n-instructions st n)))
 
4086
 :hints (("Goal" :in-theory (disable rtm-sub member-equal nth par1 par2 par3))))
 
4087
 
 
4088
 
 
4089
(defun subs-list-n (l1 l2 l3 l4 mem n)
 
4090
  (if (zp n)
 
4091
      mem
 
4092
    (subs-list-n (cdr l1) (cdr l2) (cdr l3) (cdr l4)
 
4093
               (put-cell 
 
4094
                (car l1) 
 
4095
                (sub-and-update 
 
4096
                 (car l1)
 
4097
                 (car l2)
 
4098
                 (car l3)
 
4099
                 (car l4)
 
4100
                 mem)
 
4101
                mem)
 
4102
               (1- n))))
 
4103
 
 
4104
 
 
4105
 
 
4106
 
 
4107
 
 
4108
      
 
4109
 
 
4110
(in-theory (disable member-equal))
 
4111
 
 
4112
 
 
4113
(in-theory (enable make-cell))
 
4114
 
 
4115
 
 
4116
 
 
4117
(defthm execute-n-rtm-subs-tantamount-to-sub-list-n
 
4118
 (implies
 
4119
  (and
 
4120
   (all-rtm-subs-for-n-steps st n)
 
4121
   (>= (pcc st) 0)
 
4122
   (rtm-statep st))
 
4123
  (equal
 
4124
   (mem (execute-n-rtm-subs st n))
 
4125
   (subs-list-n 
 
4126
    (listpars1 st n)
 
4127
    (listpars2 st n)
 
4128
    (listpars3 st n)
 
4129
    (listpars4 st n)
 
4130
    (mem st)
 
4131
    n)))
 
4132
 :hints 
 
4133
         (("Goal" :induct t ) 
 
4134
          ("Subgoal *1/2.2" :in-theory '((:definition all-rtm-subs-for-n-steps)
 
4135
                                         (:definition execute-instruction)
 
4136
                                         (:definition rtm-sub)
 
4137
                                         (:definition make-state)
 
4138
                                         (:definition mem))
 
4139
           )     
 
4140
          ("Subgoal *1/2" 
 
4141
                   :use ( execute-n-rtm-subs
 
4142
                          (:instance subs-list-n 
 
4143
                                     (l1 (listpars1 st n))
 
4144
                                     (l2 (listpars2 st n))
 
4145
                                     (l3 (listpars3 st n))
 
4146
                                     (l4 (listpars4 st n))
 
4147
                                     (mem (mem st)))
 
4148
                          lemma12-lp1r lemma12-lp2r lemma12-lp3r lemma12-lp4r 
 
4149
                          (:theorem
 
4150
                           (IMPLIES (AND (ALL-RTM-SUBS-FOR-N-STEPS ST N)
 
4151
                                         (>= (pcc st) 0)
 
4152
                                         (not (zp n)))
 
4153
                                    (equal (mem (execute-instruction st)) 
 
4154
                                           (PUT-CELL (CAR (LISTPARS1 ST N))
 
4155
                                                     (SUB-AND-UPDATE (CAR (LISTPARS1 ST N)) 
 
4156
                                                                     (CAR (LISTPARS2 ST N)) 
 
4157
                                                                     (CAR (LISTPARS3 ST N))
 
4158
                                                                     (CAR (LISTPARS4 ST N))
 
4159
                                                                     (MEM ST))
 
4160
                                                     (MEM ST)))))
 
4161
                          executing-rtm-instruction-retrieves-a-rtm-state-from-rtm-state
 
4162
                          instruction-incrementing-pvv))))
 
4163
 
 
4164
 
 
4165
(in-theory (disable lemma12-lp1r  lemma12-lp2r lemma12-lp3r lemma12-lp4r ))
 
4166
 
 
4167
 
 
4168
 
 
4169
 
 
4170
 
 
4171
 
 
4172
 
 
4173
 
 
4174
 
 
4175
 
 
4176
(defun subs-list-e (c1 c2 c3 c4 mem)
 
4177
  (if
 
4178
      (endp c1) 
 
4179
      mem
 
4180
    (subs-list-e
 
4181
     (cdr c1)
 
4182
     (cdr c2)
 
4183
     (cdr c3)
 
4184
     (cdr c4)
 
4185
     (put-cell (car c1) (sub-and-update (car c1) (car c2) (car c3) (car c4) mem) mem))))
 
4186
 
 
4187
     
 
4188
 
 
4189
(defthm subs-list-e-is-subs-list-n
 
4190
  (equal (subs-list-e c1 c2 c3 c4 mem) (subs-list-n c1 c2 c3 c4 mem (len c1)))
 
4191
  :rule-classes nil)
 
4192
 
 
4193
 
 
4194
 
 
4195
(defthm execute-n-instructions-tantamount-to-sub-list-e
 
4196
 (implies
 
4197
  (and
 
4198
   (integerp n)
 
4199
   (>= n 0)
 
4200
   (all-rtm-subs-for-n-steps st n)
 
4201
   (>= (pcc st) 0)
 
4202
   (rtm-statep st))
 
4203
  (equal
 
4204
   (mem (execute-n-instructions st n))
 
4205
   (subs-list-e
 
4206
    (listpars1 st n)
 
4207
    (listpars2 st n)
 
4208
    (listpars3 st n)
 
4209
    (listpars4 st n)
 
4210
    (mem st))))
 
4211
 :hints (("Goal" :in-theory nil
 
4212
          :use ((:instance subs-list-e-is-subs-list-n 
 
4213
                           (c1 (listpars1 st n))
 
4214
                           (c2 (listpars2 st n))
 
4215
                           (c3 (listpars3 st n))
 
4216
                           (c4 (listpars4 st n))
 
4217
                           (mem (mem st)))
 
4218
                execute-n-rtm-subs-tantamount-to-sub-list-n
 
4219
                all-rtm-subs-means-only-subs-are-executed
 
4220
                length-of-listpars1-n-is-n))))
 
4221
 
 
4222
 
 
4223
 
 
4224
 
 
4225
 
 
4226
 
 
4227
 
 
4228
 
 
4229
 
 
4230
 
 
4231
(defthm not-in-list-untouched-by-subs-list-e
 
4232
  (implies
 
4233
   (not (member-equal-bool v l1))
 
4234
   (equal (get-cell v (subs-list-e l1 l2 l3 l4 mem)) (get-cell v mem)))
 
4235
  :hints (("Goal" :in-theory (disable sub-and-update))))
 
4236
 
 
4237
(defthm not-in-list-untouched-by-subs-list-e-1
 
4238
  (implies
 
4239
   (not (member-equal-bool (car l1) (cdr l1)))
 
4240
   (equal (get-cell (car l1) (subs-list-e (cdr l1) (cdr l2) (cdr l3) (cdr l4) mem)) 
 
4241
          (get-cell (car l1) mem))))
 
4242
 
 
4243
 
 
4244
(defthm sub-and-update-independent-from-firstbn
 
4245
 (implies
 
4246
  (and
 
4247
   (not (member-equal-bool (nth idx l1) (firstn idx l1)))
 
4248
   (not (member-equal-bool (nth idx l2) (firstn idx l1)))
 
4249
   (not (member-equal-bool (nth idx l3) (firstn idx l1))))
 
4250
  (equal (sub-and-update 
 
4251
          (nth idx l1)
 
4252
          (nth idx l2)
 
4253
          (nth idx l3)
 
4254
          (nth idx l4)
 
4255
          (subs-list-e (firstn idx l1) (firstn idx l2) (firstn idx l3) (firstn idx l4) mem))
 
4256
         (sub-and-update 
 
4257
          (nth idx l1)
 
4258
          (nth idx l2)
 
4259
          (nth idx l3)
 
4260
          (nth idx l4)
 
4261
          mem))))
 
4262
 
 
4263
 
 
4264
 
 
4265
(defthm subs-list-decomp
 
4266
 (implies
 
4267
  (and
 
4268
   (in-range idx l1)
 
4269
   (in-range idx l2)
 
4270
   (in-range idx l3)
 
4271
   (in-range idx l4))
 
4272
  (equal
 
4273
   (subs-list-e l1 l2 l3 l4 mem)
 
4274
   (subs-list-e (nthcdr idx l1) (nthcdr idx l2) (nthcdr idx l3) (nthcdr idx l4)
 
4275
                (subs-list-e (firstn idx l1) (firstn idx l2) (firstn idx l3) (firstn idx l4) mem))))
 
4276
 :hints (("Goal" :in-theory (disable sub-and-update))))
 
4277
 
 
4278
 
 
4279
(defthm if-el-does-not-appear-after-its-position-then-subs-list-e-produces-its-sub
 
4280
 (implies
 
4281
  (and
 
4282
   (not (member-equal-bool (nth idx l1) (cdr (nthcdr idx l1))))
 
4283
   (in-range idx l1)
 
4284
   (in-range idx l2)
 
4285
   (in-range idx l3)
 
4286
   (in-range idx l4))
 
4287
  (equal
 
4288
   (get-cell (nth idx l1) (subs-list-e l1 l2 l3 l4 mem))
 
4289
   (sub-and-update 
 
4290
     (nth idx l1)
 
4291
     (nth idx l2)
 
4292
     (nth idx l3)
 
4293
     (nth idx l4)
 
4294
     (subs-list-e (firstn idx l1) (firstn idx l2) (firstn idx l3) (firstn idx l4) mem))))
 
4295
  :hints (("Goal" :in-theory (disable sub-and-update))))
 
4296
 
 
4297
 
 
4298
 
 
4299
 
 
4300
(defthm rtm-variable-of-subs-list-e-is-sub-of-correspondent-variables
 
4301
  (implies
 
4302
   (and
 
4303
    (positive-list rns)
 
4304
    (true-listp ll)
 
4305
    (no-duplicates-p (append-lists ll))
 
4306
    (in-range gem1 ll)
 
4307
    (in-range gem2 ll)
 
4308
    (in-range gem3 ll)
 
4309
    (in-range idx (nth gem1 ll))
 
4310
    (in-range idx (nth gem2 ll))
 
4311
    (in-range idx (nth gem3 ll))
 
4312
    (in-range idx rns))
 
4313
   (equal
 
4314
    (get-cell (nth idx (nth gem1 ll)) (subs-list-e (nth gem1 ll) (nth gem2 ll) (nth gem3 ll) rns mem))
 
4315
    (sub-and-update (nth idx (nth gem1 ll)) (nth idx (nth gem2 ll)) (nth idx (nth gem3 ll)) (nth idx rns) mem)))
 
4316
  :hints (("Goal" :in-theory (disable sub-and-update)
 
4317
           :use (
 
4318
                 (:instance no-duplicates-all-implies-no-duplicates-one (idx1 gem1))
 
4319
                 (:instance no-duplicates-means-an-element-does-not-appear-after-its-position (l (nth gem1 ll)))
 
4320
                 if-el-does-not-appear-after-its-position-then-subs-list-e-produces-its-sub
 
4321
                 (:instance subs-list-decomp 
 
4322
                            (l1 (nth gem1 ll)) (l2 (nth gem2 ll)) (l3 (nth gem3 ll)))
 
4323
                 (:instance sub-and-update-independent-from-firstbn
 
4324
                            (l1 (nth gem1 ll)) (l2 (nth gem2 ll)) (l3 (nth gem3 ll)))))))
 
4325
 
 
4326
 
 
4327
 
 
4328
(defun index-different-sub-and-updates (rtmvarsres rtmvars1 rtmvars2 rtmvars3 rns mem mem-after-sub)
 
4329
  (cond
 
4330
   ( (endp rtmvarsres)
 
4331
     0 )
 
4332
   ( (not (equal (get-cell (car rtmvarsres) mem-after-sub)
 
4333
                 (sub-and-update (car rtmvars1) (car rtmvars2) (car rtmvars3) (car rns) mem)))
 
4334
     0 )
 
4335
   ( t
 
4336
     (1+ (index-different-sub-and-updates 
 
4337
          (cdr rtmvarsres)
 
4338
          (cdr rtmvars1)
 
4339
          (cdr rtmvars2)
 
4340
          (cdr rtmvars3)
 
4341
          (cdr rns)
 
4342
          mem
 
4343
          mem-after-sub)))))
 
4344
 
 
4345
(defthm if-bad-index-in-range-thne-must-be-nonsubandupdate
 
4346
  (let ((bad-idx (index-different-sub-and-updates rtmvarsres rtmvars1 rtmvars2 rtmvars3 rns mem mem-after-sub)))
 
4347
    (implies 
 
4348
     (in-range bad-idx rtmvarsres) 
 
4349
     (not (equal 
 
4350
           (get-cell (nth bad-idx rtmvarsres) mem-after-sub)
 
4351
           (sub-and-update 
 
4352
            (nth bad-idx rtmvars1)
 
4353
            (nth bad-idx rtmvars2)
 
4354
            (nth bad-idx rtmvars3)
 
4355
            (nth bad-idx rns)
 
4356
            mem)))))
 
4357
 :hints (("Goal" :in-theory (disable get-cell sub-and-update))))
 
4358
 
 
4359
 
 
4360
(defthm if-bad-index-not-in-range-then-every-equalsubandupdate
 
4361
  (let ((bad-idx (index-different-sub-and-updates rtmvarsres rtmvars1 rtmvars2 rtmvars3 rns mem mem-after-sub)))
 
4362
    (implies (and (true-listp rtmvarsres)
 
4363
                  (not (in-range bad-idx rtmvarsres)))
 
4364
          (equal-sub-and-updates rtmvarsres rtmvars1 rtmvars2 rtmvars3 rns mem mem-after-sub))))
 
4365
 
 
4366
 
 
4367
(defthm rtm-variable-of-subs-list-e-is-sub-and-updates
 
4368
  (implies
 
4369
   (and
 
4370
    (positive-list rns)
 
4371
    (true-listp ll)
 
4372
    (no-duplicates-p (append-lists ll))
 
4373
    (equal (len (nth gem1 ll)) (len (nth gem2 ll)))
 
4374
    (equal (len (nth gem1 ll)) (len (nth gem3 ll)))
 
4375
    (equal (len (nth gem1 ll)) (len rns))
 
4376
    (in-range gem1 ll)
 
4377
    (in-range gem2 ll)
 
4378
    (in-range gem3 ll)
 
4379
    (true-listp (nth gem1 ll)))
 
4380
   (equal-sub-and-updates (nth gem1 ll) (nth gem1 ll) (nth gem2 ll) (nth gem3 ll) rns mem 
 
4381
    (subs-list-e (nth gem1 ll) (nth gem2 ll) (nth gem3 ll) rns mem)))
 
4382
  :hints (("Goal" :use (:instance rtm-variable-of-subs-list-e-is-sub-of-correspondent-variables
 
4383
                                  (idx (index-different-sub-and-updates 
 
4384
                                        (nth gem1 ll) 
 
4385
                                        (nth gem1 ll) 
 
4386
                                        (nth gem2 ll) 
 
4387
                                        (nth gem3 ll) 
 
4388
                                        rns 
 
4389
                                        mem 
 
4390
                                        (subs-list-e (nth gem1 ll) (nth gem2 ll) (nth gem3 ll) rns mem)))))
 
4391
          ("Goal'" :cases ( (in-range (index-different-sub-and-updates 
 
4392
                                      (nth gem1 ll) 
 
4393
                                      (nth gem1 ll) 
 
4394
                                      (nth gem2 ll) 
 
4395
                                      (nth gem3 ll) 
 
4396
                                      rns 
 
4397
                                      mem 
 
4398
                                      (subs-list-e (nth gem1 ll) (nth gem2 ll) (nth gem3 ll) rns mem))
 
4399
                                     (nth gem1 ll)) ) )
 
4400
          ("Subgoal 1" :in-theory '((:definition in-range)
 
4401
                                    (:rewrite if-bad-index-in-range-thne-must-be-nonsubandupdate)))
 
4402
          ("Subgoal 2" :in-theory '((:rewrite if-bad-index-not-in-range-then-every-equalsubandupdate)))))
 
4403
          
 
4404
                                      
 
4405
          
 
4406
          
 
4407
(defthm any-element-of-make-list-does-not-appear-into-other-lists
 
4408
 (implies
 
4409
  (and
 
4410
   (integerp n)
 
4411
   (true-listp ll)
 
4412
   (no-duplicates-p (append-lists ll))
 
4413
   (in-range gem1 ll)
 
4414
   (in-range gem2 ll)
 
4415
   (not (equal gem1 gem2))
 
4416
   (equal (len (nth gem1 ll)) 1)
 
4417
   (in-range idx (make-n-list (car (nth gem1 ll)) n)))
 
4418
  (not (member-equal-bool 
 
4419
        (nth idx (make-n-list (car (nth gem1 ll)) n))
 
4420
        (nth gem2 ll))))
 
4421
 :hints (("Goal" :use 
 
4422
          (
 
4423
           (:instance 
 
4424
            el-of-makelist-is-el
 
4425
            (el (car (nth gem1 ll))))       
 
4426
           (:instance generalized-disjunctivity-unordered-2 
 
4427
                      (idx1 gem1) (idx2 gem2) (el1 (car (nth gem1 ll)))))))
 
4428
 :otf-flg t)
 
4429
 
 
4430
(defthm firstns-do-not-cotain-el-of-make-n-list-if-diff
 
4431
 (implies
 
4432
  (and
 
4433
   (integerp n)
 
4434
   (true-listp ll)
 
4435
   (no-duplicates-p (append-lists ll))
 
4436
   (in-range gem1 ll)
 
4437
   (in-range gem2 ll)
 
4438
   (not (equal gem1 gem2))
 
4439
   (equal (len (nth gem1 ll)) 1)
 
4440
   (in-range idx (make-n-list (car (nth gem1 ll)) n)))
 
4441
  (not (member-equal-bool 
 
4442
        (nth idx (make-n-list (car (nth gem1 ll)) n))
 
4443
        (firstn idx (nth gem2 ll)))))
 
4444
 :hints (("Goal" :use
 
4445
          (
 
4446
           (:instance no-member-holds-on-firstn 
 
4447
                      (el (nth idx (make-n-list (car (nth gem1 ll)) n)))
 
4448
                      (l (nth gem2 ll)))
 
4449
           any-element-of-make-list-does-not-appear-into-other-lists))))
 
4450
 
 
4451
 
 
4452
 
 
4453
(defthm rtm-variable-of-subs-list-e-is-sub-of-correspondent-variables-when-var-3-is-boolean
 
4454
  (implies
 
4455
   (and
 
4456
    (integerp n)
 
4457
    (positive-list rns)
 
4458
    (true-listp ll)
 
4459
    (no-duplicates-p (append-lists ll))
 
4460
    (in-range gem1 ll)
 
4461
    (in-range gem2 ll)
 
4462
    (in-range gem3 ll)
 
4463
    (not (equal gem1 gem3))
 
4464
    (equal (len (nth gem3 ll)) 1)
 
4465
    (in-range idx (nth gem1 ll))
 
4466
    (in-range idx (nth gem2 ll))
 
4467
    (in-range idx (make-n-list (car (nth gem3 ll)) n))
 
4468
    (in-range idx rns))
 
4469
   (equal
 
4470
    (get-cell (nth idx (nth gem1 ll)) 
 
4471
              (subs-list-e 
 
4472
               (nth gem1 ll) 
 
4473
               (nth gem2 ll) 
 
4474
               (make-n-list (car (nth gem3 ll)) n)
 
4475
               rns mem))
 
4476
    (sub-and-update 
 
4477
     (nth idx (nth gem1 ll)) 
 
4478
     (nth idx (nth gem2 ll)) 
 
4479
     (nth idx (make-n-list (car (nth gem3 ll)) n))
 
4480
     (nth idx rns) mem)))
 
4481
  :hints (("Goal" :in-theory (disable sub-and-update)
 
4482
           :use (
 
4483
                 (:instance firstns-do-not-cotain-el-of-make-n-list-if-diff (gem1 gem3) (gem2 gem1))
 
4484
                 (:instance no-duplicates-all-implies-no-duplicates-one (idx1 gem1))
 
4485
                 (:instance no-duplicates-means-an-element-does-not-appear-after-its-position (l (nth gem1 ll)))
 
4486
                 (:instance subs-list-decomp 
 
4487
                            (l1 (nth gem1 ll)) 
 
4488
                            (l2 (nth gem2 ll)) 
 
4489
                            (l3 (make-n-list (car (nth gem3 ll)) n))
 
4490
                            (l4 rns))                       
 
4491
                 (:instance sub-and-update-independent-from-firstbn
 
4492
                            (l1 (nth gem1 ll)) 
 
4493
                            (l2 (nth gem2 ll)) 
 
4494
                            (l3 (make-n-list (car (nth gem3 ll)) n))
 
4495
                            (l4 rns))))))
 
4496
                                
 
4497
(defthm rtm-variable-of-subs-list-e-is-sub-of-correspondent-variables-when-var-2-is-boolean
 
4498
  (implies
 
4499
   (and
 
4500
    (integerp n)
 
4501
    (positive-list rns)
 
4502
    (true-listp ll)
 
4503
    (no-duplicates-p (append-lists ll))
 
4504
    (in-range gem1 ll)
 
4505
    (in-range gem2 ll)
 
4506
    (in-range gem3 ll)
 
4507
    (not (equal gem1 gem2))
 
4508
    (equal (len (nth gem2 ll)) 1)
 
4509
    (in-range idx (nth gem1 ll))
 
4510
    (in-range idx (nth gem3 ll))
 
4511
    (in-range idx (make-n-list (car (nth gem2 ll)) n))
 
4512
    (in-range idx rns))
 
4513
   (equal
 
4514
    (get-cell (nth idx (nth gem1 ll)) 
 
4515
              (subs-list-e 
 
4516
               (nth gem1 ll) 
 
4517
               (make-n-list (car (nth gem2 ll)) n)
 
4518
               (nth gem3 ll) 
 
4519
               rns mem))
 
4520
    (sub-and-update 
 
4521
     (nth idx (nth gem1 ll)) 
 
4522
     (nth idx (make-n-list (car (nth gem2 ll)) n))
 
4523
     (nth idx (nth gem3 ll)) 
 
4524
     (nth idx rns) mem)))
 
4525
  :hints (("Goal" :in-theory (disable sub-and-update)
 
4526
           :use (
 
4527
                 (:instance firstns-do-not-cotain-el-of-make-n-list-if-diff (gem1 gem2) (gem2 gem1))
 
4528
                 (:instance no-duplicates-all-implies-no-duplicates-one (idx1 gem1))
 
4529
                 (:instance no-duplicates-means-an-element-does-not-appear-after-its-position (l (nth gem1 ll)))
 
4530
                 (:instance subs-list-decomp 
 
4531
                            (l1 (nth gem1 ll)) 
 
4532
                            (l2 (make-n-list (car (nth gem2 ll)) n))
 
4533
                            (l3 (nth gem3 ll)) 
 
4534
                            (l4 rns))                       
 
4535
                 (:instance sub-and-update-independent-from-firstbn
 
4536
                            (l1 (nth gem1 ll)) 
 
4537
                            (l2 (make-n-list (car (nth gem2 ll)) n))
 
4538
                            (l3 (nth gem3 ll)) 
 
4539
                            (l4 rns))))))
 
4540
                                
 
4541
(defthm rtm-variable-of-subs-list-e-is-sub-of-correspondent-variables-when-var-2and3-are-boolean
 
4542
  (implies
 
4543
   (and
 
4544
    (integerp n)
 
4545
    (positive-list rns)
 
4546
    (true-listp ll)
 
4547
    (no-duplicates-p (append-lists ll))
 
4548
    (in-range gem1 ll)
 
4549
    (in-range gem2 ll)
 
4550
    (in-range gem3 ll)
 
4551
    (not (equal gem1 gem2))
 
4552
    (not (equal gem1 gem3))
 
4553
    (equal (len (nth gem2 ll)) 1)
 
4554
    (equal (len (nth gem3 ll)) 1)
 
4555
    (in-range idx (nth gem1 ll))
 
4556
    (in-range idx (make-n-list (car (nth gem2 ll)) n))
 
4557
    (in-range idx (make-n-list (car (nth gem3 ll)) n))
 
4558
    (in-range idx rns))
 
4559
   (equal
 
4560
    (get-cell (nth idx (nth gem1 ll)) 
 
4561
              (subs-list-e 
 
4562
               (nth gem1 ll) 
 
4563
               (make-n-list (car (nth gem2 ll)) n)
 
4564
               (make-n-list (car (nth gem3 ll)) n)
 
4565
               rns mem))
 
4566
    (sub-and-update 
 
4567
     (nth idx (nth gem1 ll)) 
 
4568
     (nth idx (make-n-list (car (nth gem2 ll)) n))
 
4569
     (nth idx (make-n-list (car (nth gem3 ll)) n))
 
4570
     (nth idx rns) mem)))
 
4571
  :hints (("Goal" :in-theory (disable sub-and-update)
 
4572
           :use (
 
4573
                 (:instance firstns-do-not-cotain-el-of-make-n-list-if-diff (gem1 gem2) (gem2 gem1))
 
4574
                 (:instance firstns-do-not-cotain-el-of-make-n-list-if-diff (gem1 gem3) (gem2 gem1))
 
4575
                 (:instance no-duplicates-all-implies-no-duplicates-one (idx1 gem1))
 
4576
                 (:instance no-duplicates-means-an-element-does-not-appear-after-its-position (l (nth gem1 ll)))
 
4577
                 (:instance subs-list-decomp 
 
4578
                            (l1 (nth gem1 ll)) 
 
4579
                            (l2 (make-n-list (car (nth gem2 ll)) n))
 
4580
                            (l3 (make-n-list (car (nth gem3 ll)) n)) 
 
4581
                            (l4 rns))                       
 
4582
                 (:instance sub-and-update-independent-from-firstbn
 
4583
                            (l1 (nth gem1 ll)) 
 
4584
                            (l2 (make-n-list (car (nth gem2 ll)) n))
 
4585
                            (l3 (make-n-list (car (nth gem3 ll)) n))
 
4586
                            (l4 rns))))))
 
4587
                                
 
4588
 
 
4589
 
 
4590
 
 
4591
(defthm rtm-variable-of-subs-list-e-is-sub-of-correspondent-variables-with-all-vars-types
 
4592
  (implies
 
4593
   (and
 
4594
    (integerp n)
 
4595
    (positive-list rns)
 
4596
    (true-listp ll)
 
4597
    (no-duplicates-p (append-lists ll))
 
4598
    (in-range gem1 ll)
 
4599
    (in-range gem2 ll)
 
4600
    (in-range gem3 ll)
 
4601
    (not (equal (len (nth gem1 ll)) 1))
 
4602
    (in-range idx (nth gem1 ll))
 
4603
    (in-range idx (eventually-make-list (nth gem2 ll) n))
 
4604
    (in-range idx (eventually-make-list (nth gem3 ll) n))
 
4605
    (in-range idx rns))
 
4606
   (equal
 
4607
    (get-cell (nth idx (nth gem1 ll)) 
 
4608
              (subs-list-e 
 
4609
               (nth gem1 ll) 
 
4610
               (eventually-make-list (nth gem2 ll) n)
 
4611
               (eventually-make-list (nth gem3 ll) n)
 
4612
               rns mem))
 
4613
    (sub-and-update 
 
4614
     (nth idx (nth gem1 ll)) 
 
4615
     (nth idx (eventually-make-list (nth gem2 ll) n))
 
4616
     (nth idx (eventually-make-list (nth gem3 ll) n))
 
4617
     (nth idx rns) mem)))
 
4618
  :hints (("Goal" :in-theory (union-theories (current-theory 'ground-zero)
 
4619
                                                  '((:definition eventually-make-list)))
 
4620
          :cases
 
4621
           ( (and (not (equal (len (nth gem3 ll)) 1))      (equal (len (nth gem2 ll)) 1))
 
4622
             (and      (equal (len (nth gem3 ll)) 1)  (not (equal (len (nth gem2 ll)) 1)))
 
4623
             (and (not (equal (len (nth gem3 ll)) 1)) (not (equal (len (nth gem2 ll)) 1)))
 
4624
             (and      (equal (len (nth gem3 ll)) 1)       (equal (len (nth gem2 ll)) 1))))
 
4625
          ("Subgoal 4"
 
4626
           :use rtm-variable-of-subs-list-e-is-sub-of-correspondent-variables-when-var-2-is-boolean)
 
4627
          ("Subgoal 3"
 
4628
           :use rtm-variable-of-subs-list-e-is-sub-of-correspondent-variables-when-var-3-is-boolean)
 
4629
          ("Subgoal 2"
 
4630
           :use rtm-variable-of-subs-list-e-is-sub-of-correspondent-variables)
 
4631
          ("Subgoal 1"
 
4632
           :use rtm-variable-of-subs-list-e-is-sub-of-correspondent-variables-when-var-2and3-are-boolean)))
 
4633
 
 
4634
 
 
4635
 
 
4636
(defthm sub-and-updates-holding-for-every-variable-type
 
4637
  (implies
 
4638
   (and
 
4639
    (integerp n)
 
4640
    (not (equal (len (nth gem1 ll)) 1))
 
4641
    (positive-list rns)
 
4642
    (true-listp ll)
 
4643
    (no-duplicates-p (append-lists ll))
 
4644
    (equal (len (nth gem1 ll)) (len (eventually-make-list (nth gem2 ll) n)))
 
4645
    (equal (len (nth gem1 ll)) (len (eventually-make-list (nth gem3 ll) n)))
 
4646
    (equal (len (nth gem1 ll)) (len rns))
 
4647
    (in-range gem1 ll)
 
4648
    (in-range gem2 ll)
 
4649
    (in-range gem3 ll)
 
4650
    (true-listp (nth gem1 ll)))
 
4651
   (equal-sub-and-updates 
 
4652
    (nth gem1 ll) 
 
4653
    (nth gem1 ll) 
 
4654
    (eventually-make-list (nth gem2 ll) n)
 
4655
    (eventually-make-list (nth gem3 ll) n)
 
4656
    rns mem 
 
4657
    (subs-list-e 
 
4658
     (nth gem1 ll) 
 
4659
     (eventually-make-list (nth gem2 ll) n)
 
4660
     (eventually-make-list (nth gem3 ll) n)
 
4661
     rns mem)))
 
4662
  :hints (("Goal" :use (:instance rtm-variable-of-subs-list-e-is-sub-of-correspondent-variables-with-all-vars-types
 
4663
                                  (idx (index-different-sub-and-updates 
 
4664
                                        (nth gem1 ll) 
 
4665
                                        (nth gem1 ll) 
 
4666
                                        (eventually-make-list (nth gem2 ll) n)
 
4667
                                        (eventually-make-list (nth gem3 ll) n)
 
4668
                                        rns 
 
4669
                                        mem 
 
4670
                                        (subs-list-e 
 
4671
                                         (nth gem1 ll) 
 
4672
                                         (eventually-make-list (nth gem2 ll) n)
 
4673
                                         (eventually-make-list (nth gem3 ll) n)
 
4674
                                         rns mem)))))
 
4675
          ("Goal'" :cases ( (in-range (index-different-sub-and-updates 
 
4676
                                      (nth gem1 ll) 
 
4677
                                      (nth gem1 ll) 
 
4678
                                      (eventually-make-list (nth gem2 ll) n)
 
4679
                                      (eventually-make-list (nth gem3 ll) n)
 
4680
                                      rns 
 
4681
                                      mem 
 
4682
                                      (subs-list-e 
 
4683
                                       (nth gem1 ll) 
 
4684
                                       (eventually-make-list (nth gem2 ll) n)
 
4685
                                       (eventually-make-list (nth gem3 ll) n)
 
4686
                                       rns mem))
 
4687
                                     (nth gem1 ll)) ) )
 
4688
          ("Subgoal 1" :in-theory '((:definition in-range)
 
4689
                                    (:rewrite if-bad-index-in-range-thne-must-be-nonsubandupdate)))
 
4690
          ("Subgoal 2" :in-theory '((:rewrite if-bad-index-not-in-range-then-every-equalsubandupdate)))))
 
4691
          
 
4692
 
 
4693
 
 
4694
(defthm lemma2-only-subs-in-rtm-sub
 
4695
  (implies
 
4696
   (and
 
4697
    (gem-statep gstate)
 
4698
    (rtm-statep rstate)
 
4699
    (in-range (pcc gstate) (code gstate))
 
4700
    (in-range (pcc rstate) (code rstate))
 
4701
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-sub)
 
4702
    (good-translation-gem-rtm gstate rstate m))
 
4703
   (all-rtm-subs-for-n-steps rstate (len *rns*)))
 
4704
  :hints (("Goal" :expand 
 
4705
           ( (good-translation-gem-rtm gstate rstate m)
 
4706
             (gem-statep gstate)
 
4707
             (rtm-statep rstate)
 
4708
             (in-range (pcc gstate) (code gstate))
 
4709
             (in-range (pcc rstate) (code rstate)))
 
4710
           :in-theory nil))
 
4711
  :rule-classes nil)
 
4712
 
 
4713
        
 
4714
(defthm cells-untouched-by-execute-on-other-cell-sub
 
4715
 (implies
 
4716
  (and
 
4717
   (integerp n)
 
4718
   (>= n 0)
 
4719
   (all-rtm-subs-for-n-steps st n)
 
4720
   (>= (pcc st) 0)
 
4721
   (rtm-statep st)
 
4722
   (not (member-equal-bool v (listpars1 st n))))
 
4723
  (equal (get-cell v (mem st))
 
4724
         (get-cell v (mem (execute-n-instructions st n)))))
 
4725
 :hints (("Goal" 
 
4726
          :use (execute-n-instructions-tantamount-to-sub-list-e
 
4727
                (:instance not-in-list-untouched-by-subs-list-e
 
4728
                                  (v v)
 
4729
                                  (l1 (listpars1 st n))
 
4730
                                  (l2 (listpars2 st n))
 
4731
                                  (l3 (listpars3 st n))
 
4732
                                  (l4 (listpars4 st n))
 
4733
                                  (mem (mem st)))))))
 
4734
 
 
4735
 
 
4736
(defthm rtm-variable-of-other-cell-untouched-sub
 
4737
  (implies
 
4738
   (and
 
4739
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-sub)
 
4740
    (>= (pcc rstate) 0)
 
4741
    (rtm-statep rstate)
 
4742
    (good-translation-gem-rtm gstate rstate m)
 
4743
    (in-range (pcc gstate) (code gstate))
 
4744
    (assoc-equal (par1 (nth (pcc gstate) (code gstate))) m)  
 
4745
    (true-listp m)
 
4746
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
4747
    (assoc-equal gvar1 m)
 
4748
    (not (equal gvar1 (par1 (nth (pcc gstate) (code gstate)))))
 
4749
    (in-range idx1 (rtmintvars-i gvar1 m)))
 
4750
   (equal (get-cell (nth idx1 (rtmintvars-i gvar1 m)) (mem rstate))
 
4751
          (get-cell (nth idx1 (rtmintvars-i gvar1 m)) (mem (execute-n-instructions rstate (len *rns*))))))
 
4752
  :hints (("Goal" :in-theory (current-theory 'ground-zero)
 
4753
           :expand (     (in-range (pcc gstate) (code gstate))
 
4754
                         (good-translation-gem-rtm gstate rstate m) )
 
4755
           :use ( 
 
4756
                 (:instance lemma1-different-vars-do-not-belong  (gvar2 (par1 (nth (pcc gstate) (code gstate)))))
 
4757
                 (:instance cells-untouched-by-execute-on-other-cell-sub (st rstate) (n (len *rns*)) 
 
4758
                            (v (nth idx1 (rtmintvars-i gvar1 m))))))))
 
4759
 
 
4760
(defthm rtm-variables-of-other-cell-untouched-sub
 
4761
  (implies
 
4762
   (and
 
4763
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-sub)
 
4764
    (>= (pcc rstate) 0)
 
4765
    (rtm-statep rstate)
 
4766
    (good-translation-gem-rtm gstate rstate m)
 
4767
    (in-range (pcc gstate) (code gstate))
 
4768
    (assoc-equal (par1 (nth (pcc gstate) (code gstate))) m)   
 
4769
    (true-listp m)
 
4770
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
4771
    (assoc-equal gvar1 m)
 
4772
    (true-listp (rtmintvars-i gvar1 m))                         
 
4773
    (not (equal gvar1 (par1 (nth (pcc gstate) (code gstate))))))
 
4774
   (equal-get-cells
 
4775
          (rtmintvars-i gvar1 m) (mem rstate) (mem (execute-n-instructions rstate (len *rns*)))))
 
4776
  :hints (("Goal" :in-theory nil
 
4777
           :use ( (:instance rtm-variable-of-other-cell-untouched-sub 
 
4778
                             (idx1 (idx-different-cell 
 
4779
                                    (rtmintvars-i gvar1 m) 
 
4780
                                    (mem rstate) 
 
4781
                                    (mem (execute-n-instructions rstate (len *rns*)))))) ))
 
4782
          ("Goal'" :cases ( (in-range
 
4783
                             (idx-different-cell 
 
4784
                                    (rtmintvars-i gvar1 m) 
 
4785
                                    (mem rstate) 
 
4786
                                    (mem (execute-n-instructions rstate (len *rns*))))
 
4787
                             (rtmintvars-i gvar1 m))))
 
4788
          ("Subgoal 2" :in-theory '((:rewrite if-bad-index-not-in-range-then-every-equal)))
 
4789
          ("Subgoal 1" :in-theory '((:forward-chaining if-bad-index-in-range-then-cells-must-be-different)))))
 
4790
 
 
4791
 
 
4792
 
 
4793
 
 
4794
(defthm properies-of-type-and-existence-of-current-args-sub 
 
4795
 (implies
 
4796
  (and
 
4797
   (gem-statep gstate)
 
4798
   (in-range (pcc gstate) (code gstate))
 
4799
   (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-sub))
 
4800
  (and
 
4801
   (equal (var-type (get-cell (par1 (nth (pcc gstate) (code gstate))) (mem gstate))) 'Int)
 
4802
   (assoc-equal (par1 (nth (pcc gstate) (code gstate))) (mem gstate))
 
4803
   (assoc-equal (par2 (nth (pcc gstate) (code gstate))) (mem gstate))
 
4804
   (assoc-equal (par3 (nth (pcc gstate) (code gstate))) (mem gstate))))
 
4805
  :hints (("Goal" :in-theory (enable get-cell)
 
4806
           :use (:instance in-range-instruction-is-gem-instruction 
 
4807
                           (pcc (pcc gstate)) 
 
4808
                           (code (code gstate))
 
4809
                           (mem (mem gstate)))))
 
4810
  :rule-classes nil)
 
4811
 
 
4812
 
 
4813
(defthm par1-of-current-instruction-is-into-mapping-sub 
 
4814
 (implies
 
4815
  (and
 
4816
   (vars-inclusion (mem gstate) m)
 
4817
   (gem-statep gstate)
 
4818
   (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-sub)  
 
4819
   (in-range (pcc gstate) (code gstate)))
 
4820
  (assoc-equal (par1 (nth (pcc gstate) (code gstate))) m))
 
4821
 :hints (("Goal" :in-theory (enable get-cell)
 
4822
         :use (properies-of-type-and-existence-of-current-args-sub
 
4823
               (:instance inclusion-trans 
 
4824
                          (v (par1 (nth (pcc gstate) (code gstate))))
 
4825
                          (m1 (mem gstate))
 
4826
                          (m2 m))
 
4827
               (:instance in-range-instruction-is-gem-instruction 
 
4828
                                 (pcc (pcc gstate)) 
 
4829
                                 (code (code gstate))
 
4830
                                 (mem (mem gstate)))))))
 
4831
 
 
4832
 
 
4833
 
 
4834
(defthm teorema-main-con-pcc-in-range-su-variabile-non-interessata-final-sub
 
4835
 (implies
 
4836
  (and
 
4837
   (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-sub)
 
4838
   (good-translation-gem-rtm gstate rstate m)
 
4839
   (vars-inclusion (mem gstate) m)
 
4840
   (true-listp m)
 
4841
   (assoc-equal gvar1 m)
 
4842
   (gem-statep gstate)
 
4843
   (rtm-statep rstate)
 
4844
   (in-range (pcc gstate) (code gstate))
 
4845
   (in-range (pcc rstate) (code rstate))
 
4846
   (not (equal gvar1 (par1 (nth (pcc gstate) (code gstate)))))
 
4847
   (m-correspondent-values-p m (mem gstate) (mem rstate))
 
4848
   (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
4849
   (correct-wrt-arity m (mem gstate)))
 
4850
  (equal-values-and-attributes 
 
4851
   (get-cell gvar1 (mem (execute-instruction gstate)))
 
4852
   (rtmintvars-i gvar1 m)
 
4853
   (mem (execute-n-instructions rstate (len *rns*)))
 
4854
   (type-i gvar1 m)))
 
4855
 :hints (("Goal"
 
4856
          :in-theory '((:definition good-translation-gem-rtm))
 
4857
          :use (
 
4858
                par1-of-current-instruction-is-into-mapping-sub
 
4859
                (:instance correct-wrt-arity-has-rtmintvars-i-tl (mem (mem gstate)))
 
4860
                (:instance m-correspondent-values-implies-equal-values-and-attribus
 
4861
                           (memgstate (mem gstate)) (memrstate (mem rstate)))
 
4862
                (:instance in-range (idx (pcc gstate)) (l (code gstate)))
 
4863
                (:instance in-range (idx (pcc rstate)) (l (code rstate)))
 
4864
                rtm-variables-of-other-cell-untouched-sub
 
4865
                teorema-main-con-pcc-in-range-su-variabile-non-interessata
 
4866
                (:instance equal-get-cells-implies-equal-values-and-attributes-still-works      
 
4867
                           (gemcell (get-cell gvar1 (mem gstate)))
 
4868
                           (lcell (rtmintvars-i gvar1 m))
 
4869
                           (mem1 (mem rstate))
 
4870
                           (mem2 (mem (execute-n-instructions rstate (len *rns*))))
 
4871
                           (type (type-i gvar1 m)))))))
 
4872
 
 
4873
 
 
4874
(defthm teorema-main-con-pcc-in-range-su-variabile-interessata-sub
 
4875
 (implies
 
4876
  (and
 
4877
   (gem-statep gstate)
 
4878
   (rtm-statep rstate)
 
4879
   (in-range (pcc gstate) (code gstate))
 
4880
   (in-range (pcc rstate) (code rstate))
 
4881
   (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-sub)
 
4882
   (good-translation-gem-rtm gstate rstate m))
 
4883
  (equal
 
4884
   (mem (execute-n-instructions rstate (len *rns*)))
 
4885
   (subs-list-e 
 
4886
    (rtmintvars-i (par1 (nth (pcc gstate) (code gstate))) m)
 
4887
    (eventually-make-list (rtmintvars-i (par2 (nth (pcc gstate) (code gstate))) m) (len *rns*)) ;new
 
4888
    (eventually-make-list (rtmintvars-i (par3 (nth (pcc gstate) (code gstate))) m) (len *rns*)) ;new
 
4889
    *rns*
 
4890
    (mem rstate))))
 
4891
  :hints (("Goal"          
 
4892
           :in-theory (union-theories (current-theory 'ground-zero) '((:definition in-range)))
 
4893
           :use (good-translation-gem-rtm
 
4894
                 lemma2-only-subs-in-rtm-sub
 
4895
                 (:instance execute-n-instructions-tantamount-to-sub-list-e
 
4896
                            (n (len *rns*))
 
4897
                            (st rstate)))))
 
4898
  :rule-classes nil)
 
4899
 
 
4900
 
 
4901
 
 
4902
 
 
4903
(defthm posinrg-sub
 
4904
  (implies
 
4905
   (and
 
4906
    (vars-inclusion (mem gstate) m)
 
4907
    (gem-statep gstate)
 
4908
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-sub) 
 
4909
    (in-range (pcc gstate) (code gstate)))
 
4910
   (and
 
4911
    (in-range (pos-equal-0 (par1 (nth (pcc gstate) (code gstate))) m) m)
 
4912
    (in-range (pos-equal-0 (par2 (nth (pcc gstate) (code gstate))) m) m)
 
4913
    (in-range (pos-equal-0 (par3 (nth (pcc gstate) (code gstate))) m) m)))
 
4914
   :hints (("Goal" 
 
4915
            :use (properies-of-type-and-existence-of-current-args-sub
 
4916
                        (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
4917
                                   (v (par1 (nth (pcc gstate) (code gstate)))))
 
4918
                        (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
4919
                                   (v (par2 (nth (pcc gstate) (code gstate)))))
 
4920
                        (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
4921
                                   (v (par3 (nth (pcc gstate) (code gstate)))))
 
4922
                        (:instance assoc-means-pos-in-range
 
4923
                                   (el (par1 (nth (pcc gstate) (code gstate))))
 
4924
                                   (l m))
 
4925
                        (:instance assoc-means-pos-in-range
 
4926
                                   (el (par2 (nth (pcc gstate) (code gstate))))
 
4927
                                   (l m))
 
4928
                        (:instance assoc-means-pos-in-range
 
4929
                                   (el (par3 (nth (pcc gstate) (code gstate))))
 
4930
                                   (l m)))))
 
4931
   :rule-classes nil)
 
4932
   
 
4933
(defthm eqlenss-sub
 
4934
  (implies
 
4935
   (and
 
4936
    (gem-statep gstate)
 
4937
    (rtm-statep rstate)
 
4938
    (in-range (pcc gstate) (code gstate))
 
4939
    (in-range (pcc rstate) (code rstate))
 
4940
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-sub) 
 
4941
    (good-translation-gem-rtm gstate rstate m))
 
4942
   (and
 
4943
    (equal (len (rtmintvars-i (par1 (nth (pcc gstate) (code gstate))) m)) (len *rns*))
 
4944
    (equal (len (eventually-make-list (rtmintvars-i (par2 (nth (pcc gstate) (code gstate))) m) (len *rns*))) (len *rns*))    
 
4945
    (equal (len (eventually-make-list (rtmintvars-i (par3 (nth (pcc gstate) (code gstate))) m) (len *rns*))) (len *rns*))))
 
4946
  :hints (("Goal" 
 
4947
           :in-theory (union-theories (current-theory 'ground-zero) '((:definition in-range)))
 
4948
           :use 
 
4949
           (
 
4950
            good-translation-gem-rtm
 
4951
            (:instance length-of-listpars1-n-is-n (st rstate) (n (len *rns*)))
 
4952
            (:instance length-of-listpars2-n-is-n (st rstate) (n (len *rns*)))
 
4953
            (:instance length-of-listpars3-n-is-n (st rstate) (n (len *rns*))))))
 
4954
  :rule-classes nil)
 
4955
 
 
4956
  
 
4957
(defthm equal-sub-and-updates-after-n-instr
 
4958
  (implies
 
4959
   (and  
 
4960
    (true-listp m)
 
4961
    (correct-wrt-arity m (mem gstate))
 
4962
    (gem-statep gstate)
 
4963
    (rtm-statep rstate)
 
4964
    (vars-inclusion (mem gstate) m)
 
4965
    (in-range (pcc gstate) (code gstate))
 
4966
    (in-range (pcc rstate) (code rstate))
 
4967
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-sub)
 
4968
    (good-translation-gem-rtm gstate rstate m)
 
4969
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
4970
    (assoc-equal gvar1 m)
 
4971
    (equal gvar1 (par1 (nth (pcc gstate) (code gstate)))))
 
4972
   (equal-sub-and-updates 
 
4973
    (rtmintvars-i gvar1 m)
 
4974
    (rtmintvars-i (par1 (nth (pcc gstate) (code gstate))) m)
 
4975
    (eventually-make-list (rtmintvars-i (par2 (nth (pcc gstate) (code gstate))) m) (len *rns*)) ;new
 
4976
    (eventually-make-list (rtmintvars-i (par3 (nth (pcc gstate) (code gstate))) m) (len *rns*)) ;new
 
4977
    *rns* 
 
4978
    (mem rstate) 
 
4979
    (mem (execute-n-instructions rstate (len *rns*)))))
 
4980
  :hints (("Goal" 
 
4981
           :in-theory (union-theories (current-theory 'ground-zero) 
 
4982
                                      '((:type-prescription retrieve-rtmvars)
 
4983
                                        (:definition positive-list)
 
4984
                                        (:definition positivep)
 
4985
                                        (:definition in-range)))
 
4986
           :use
 
4987
           ( 
 
4988
             (:instance correct-wrt-arity-has-rtmintvars-i-tl (mem (mem gstate)))
 
4989
             (:instance sub-and-updates-holding-for-every-variable-type
 
4990
                        (n (len *rns*))
 
4991
                        (ll (retrieve-rtmvars m))
 
4992
                        (rns *rns*)
 
4993
                        (gem1 (pos-equal-0 (par1 (nth (pcc gstate) (code gstate))) m))
 
4994
                        (gem2 (pos-equal-0 (par2 (nth (pcc gstate) (code gstate))) m))
 
4995
                        (gem3 (pos-equal-0 (par3 (nth (pcc gstate) (code gstate))) m))
 
4996
                        (mem (mem rstate)))
 
4997
             lemma-help2
 
4998
             eqlenss-sub
 
4999
             posinrg-sub
 
5000
             teorema-main-con-pcc-in-range-su-variabile-interessata-sub
 
5001
             (:instance rtmintvars-i-is-pos-equal-0-of-retrieve-vars
 
5002
                        (gvar (par1 (nth (pcc gstate) (code gstate)))))
 
5003
             (:instance rtmintvars-i-is-pos-equal-0-of-retrieve-vars
 
5004
                        (gvar (par2 (nth (pcc gstate) (code gstate)))))
 
5005
             (:instance rtmintvars-i-is-pos-equal-0-of-retrieve-vars
 
5006
                        (gvar (par3 (nth (pcc gstate) (code gstate)))))
 
5007
             (:instance rtmintvars-i-is-pos-equal-0-of-retrieve-vars
 
5008
                        (gvar (par4 (nth (pcc gstate) (code gstate)))))))))
 
5009
 
 
5010
 
 
5011
(defthm equal-sub-and-update-norest-afetr-one-instr
 
5012
  (implies
 
5013
   (and
 
5014
    (gem-statep gstate)
 
5015
    (in-range (pcc gstate) (code gstate))
 
5016
    (good-translation-gem-rtm gstate rstate m)
 
5017
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-sub)
 
5018
    (equal gvar1 (par1 (nth (pcc gstate) (code gstate))))
 
5019
    (equal gvar2 (par2 (nth (pcc gstate) (code gstate))))
 
5020
    (equal gvar3 (par3 (nth (pcc gstate) (code gstate)))))
 
5021
   (equal (get-cell gvar1 (mem (execute-instruction gstate)))
 
5022
          (sub-and-update-norest gvar1 gvar2 gvar3 (mem gstate))))
 
5023
  :hints (("Goal" :in-theory (e/d (put-cell get-cell) 
 
5024
                                  (par1 par2 par3 par4 opcode pcc code nth gem-instruction-list-p
 
5025
                                        gen-eq-update sub-and-update sub-and-update sub-and-update-norest sub-and-update-norest))))
 
5026
  :rule-classes nil)
 
5027
 
 
5028
 
 
5029
(DEFTHM mem-cellity-of-current-gem-args-sub
 
5030
  (IMPLIES
 
5031
   (AND (GEM-STATEP GSTATE)
 
5032
        (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-sub) 
 
5033
        (IN-RANGE (PCC GSTATE) (CODE GSTATE)))
 
5034
   (AND (is-mem-cell-p (get-cell  (PAR1 (NTH (PCC GSTATE) (CODE GSTATE))) (mem gstate)))
 
5035
        (is-mem-cell-p (get-cell  (PAR2 (NTH (PCC GSTATE) (CODE GSTATE))) (mem gstate)))
 
5036
        (is-mem-cell-p (get-cell  (PAR3 (NTH (PCC GSTATE) (CODE GSTATE))) (mem gstate)))))
 
5037
  :HINTS
 
5038
  (("Goal" 
 
5039
    :USE
 
5040
    (:INSTANCE IN-RANGE-INSTRUCTION-IS-GEM-INSTRUCTION
 
5041
               (PCC (PCC GSTATE))
 
5042
               (CODE (CODE GSTATE))
 
5043
               (MEM (MEM GSTATE))))))
 
5044
 
 
5045
 
 
5046
 
 
5047
(defthm type-is-for-pars-sub
 
5048
 (implies
 
5049
   (and
 
5050
    (true-listp m)
 
5051
    (vars-inclusion (mem gstate) m)
 
5052
    (gem-statep gstate)
 
5053
    (correct-wrt-arity m (mem gstate))
 
5054
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-sub) 
 
5055
    (equal gvar1 (par1 (nth (pcc gstate) (code gstate))))
 
5056
    (equal gvar2 (par2 (nth (pcc gstate) (code gstate))))
 
5057
    (equal gvar3 (par3 (nth (pcc gstate) (code gstate))))
 
5058
    (in-range (pcc gstate) (code gstate)))
 
5059
   (equal (type-i gvar1 m) 'int))
 
5060
 :hints (("Goal" 
 
5061
          :in-theory (disable type-i-is-type-expected rtmintvars-i-is-pos-equal-0-of-retrieve-vars)
 
5062
          :use ( properies-of-type-and-existence-of-current-args-sub
 
5063
                 (:instance type-i-is-vartyper (gvar1 gvar1))
 
5064
                 (:instance type-i-is-vartyper (gvar1 gvar2))
 
5065
                 (:instance type-i-is-vartyper (gvar1 gvar3))
 
5066
                 (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
5067
                            (v (par1 (nth (pcc gstate) (code gstate)))))
 
5068
                 (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
5069
                            (v (par2 (nth (pcc gstate) (code gstate)))))
 
5070
                 (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
5071
                            (v (par3 (nth (pcc gstate) (code gstate))))))))
 
5072
 :rule-classes nil)
 
5073
 
 
5074
   
 
5075
(defthm m-correspondence-kept-on-same-gvar-sub
 
5076
  (implies
 
5077
   (and
 
5078
    (good-translation-gem-rtm gstate rstate m)
 
5079
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-sub)
 
5080
    (equal gvar1 (par1 (nth (pcc gstate) (code gstate))))
 
5081
    (true-listp m)
 
5082
    (correct-wrt-arity m (mem gstate))
 
5083
    (gem-statep gstate)
 
5084
    (rtm-statep rstate)
 
5085
    (vars-inclusion (mem gstate) m)
 
5086
    (in-range (pcc gstate) (code gstate))
 
5087
    (in-range (pcc rstate) (code rstate))
 
5088
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
5089
    (assoc-equal gvar1 m)
 
5090
    (m-correspondent-values-p m (mem gstate) (mem rstate)))
 
5091
  (equal-values-and-attributes 
 
5092
   (get-cell gvar1 (mem (execute-instruction gstate)))
 
5093
   (rtmintvars-i gvar1 m)
 
5094
   (mem (execute-n-instructions rstate (len *rns*)))
 
5095
   (type-i gvar1 m)))
 
5096
  :hints (("Goal"  :in-theory nil
 
5097
           :use ( 
 
5098
                 properies-of-type-and-existence-of-current-args-sub
 
5099
                 mem-cellity-of-current-gem-args-sub
 
5100
                 good-translation-gem-rtm 
 
5101
                 (:instance type-i-is-vartyper (gvar1 gvar1) (mem (mem gstate)))
 
5102
                 (:instance type-i-is-vartyper (gvar1 (par2 (nth (pcc gstate) (code gstate)))) (mem (mem gstate)))
 
5103
                 (:instance type-i-is-vartyper (gvar1 (par3 (nth (pcc gstate) (code gstate)))) (mem (mem gstate)))
 
5104
                 (:instance type-i-is-type-expected (gvar  gvar1) (mem (mem gstate)))
 
5105
                 (:instance type-i-is-type-expected (gvar  (par2 (nth (pcc gstate) (code gstate)))) (mem (mem gstate)))
 
5106
                 (:instance type-i-is-type-expected (gvar  (par3 (nth (pcc gstate) (code gstate)))) (mem (mem gstate)))
 
5107
                 (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
5108
                            (v (par1 (nth (pcc gstate) (code gstate)))))
 
5109
                 (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
5110
                            (v (par2 (nth (pcc gstate) (code gstate)))))
 
5111
                 (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
5112
                            (v (par3 (nth (pcc gstate) (code gstate)))))
 
5113
                  (:instance
 
5114
                   equal-sub-and-update-norest-afetr-one-instr
 
5115
                   (gvar2 (par2 (nth (pcc gstate) (code gstate))))
 
5116
                   (gvar3 (par3 (nth (pcc gstate) (code gstate))))
 
5117
                   )
 
5118
                  eqlenss-sub
 
5119
                  (:instance correct-wrt-arity-has-rtmintvars-i-tl (mem (mem gstate)))                       
 
5120
                  (:instance type-is-for-pars-sub
 
5121
                   (gvar2 (par2 (nth (pcc gstate) (code gstate))))
 
5122
                   (gvar3 (par3 (nth (pcc gstate) (code gstate)))))
 
5123
                  (:instance m-correspondent-values-implies-equal-values-and-attribus
 
5124
                             (memgstate (mem gstate)) (memrstate (mem rstate)) 
 
5125
                             (gvar1 gvar1))
 
5126
                  (:instance m-correspondent-values-implies-equal-values-and-attribus
 
5127
                             (memgstate (mem gstate)) (memrstate (mem rstate)) 
 
5128
                             (gvar1 (par2 (nth (pcc gstate) (code gstate)))))
 
5129
                  (:instance m-correspondent-values-implies-equal-values-and-attribus
 
5130
                             (memgstate (mem gstate)) (memrstate (mem rstate)) 
 
5131
                             (gvar1 (par3 (nth (pcc gstate) (code gstate)))))
 
5132
                  equal-sub-and-updates-after-n-instr
 
5133
                  (:instance
 
5134
                   if-gem-is-sub-and-update-inf-every-rtm-var-is-sub-and-update-then-equal-values-is-kept-g
 
5135
                   (gvar2 (par2 (nth (pcc gstate) (code gstate))))
 
5136
                   (gvar3 (par3 (nth (pcc gstate) (code gstate))))
 
5137
                   (rtmvars1   (rtmintvars-i gvar1 m))
 
5138
                   (rtmvars2   (rtmintvars-i (par2 (nth (pcc gstate) (code gstate))) m))
 
5139
                   (rtmvars3   (rtmintvars-i (par3 (nth (pcc gstate) (code gstate))) m))
 
5140
                   (rtmvarsres (rtmintvars-i gvar1 m))
 
5141
                   (gemmem (mem gstate))
 
5142
                   (rtmmem (mem rstate))
 
5143
                   (rtmmemafter (mem (execute-n-instructions rstate (len *rns*)))))))))
 
5144
 
 
5145
 
 
5146
(defthm equal-values-correspondence-kept-by-any-execution-sub
 
5147
  (implies
 
5148
   (and
 
5149
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-sub)
 
5150
    (good-translation-gem-rtm gstate rstate m)
 
5151
    (true-listp m)
 
5152
    (correct-wrt-arity m (mem gstate))
 
5153
    (gem-statep gstate)
 
5154
    (rtm-statep rstate)
 
5155
    (vars-inclusion (mem gstate) m)
 
5156
    (in-range (pcc gstate) (code gstate))
 
5157
    (in-range (pcc rstate) (code rstate))
 
5158
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
5159
    (assoc-equal gvar1 m)
 
5160
    (m-correspondent-values-p m (mem gstate) (mem rstate)))
 
5161
  (equal-values-and-attributes 
 
5162
   (get-cell gvar1 (mem (execute-instruction gstate)))
 
5163
   (rtmintvars-i gvar1 m)
 
5164
   (mem (execute-n-instructions rstate (len *rns*)))
 
5165
   (type-i gvar1 m)))
 
5166
  :hints (("Goal" :use (m-correspondence-kept-on-same-gvar-sub
 
5167
                        teorema-main-con-pcc-in-range-su-variabile-non-interessata-final-sub))))
 
5168
 
 
5169
 
 
5170
 
 
5171
(defthm equal-values-correspondence-kept-by-any-execution-idxed-sub
 
5172
  (implies
 
5173
   (and
 
5174
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-sub)
 
5175
    (no-duplicates-p (retrieve-gemvars m))
 
5176
    (good-translation-gem-rtm gstate rstate m)
 
5177
    (alistp m)
 
5178
    (correct-wrt-arity m (mem gstate))
 
5179
    (gem-statep gstate)
 
5180
    (rtm-statep rstate)
 
5181
    (vars-inclusion (mem gstate) m)
 
5182
    (in-range (pcc gstate) (code gstate))
 
5183
    (in-range (pcc rstate) (code rstate))
 
5184
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
5185
    (in-range idx m)
 
5186
    (m-correspondent-values-p m (mem gstate) (mem rstate)))
 
5187
  (equal-values-and-attributes 
 
5188
   (get-cell (car (nth idx m)) (mem (execute-instruction gstate)))
 
5189
   (cdr (nth idx m)) 
 
5190
   (mem (execute-n-instructions rstate (len *rns*)))
 
5191
   (type-i-idx m idx)))   
 
5192
  :hints (("Goal" :in-theory (union-theories (current-theory 'ground-zero) '((:definition in-range))) 
 
5193
           :use ( (:theorem
 
5194
                   (implies
 
5195
                    (and
 
5196
                     (alistp m)
 
5197
                     (in-range idx m))
 
5198
                    (and
 
5199
                     (true-listp m)
 
5200
                     (assoc-equal (car (nth idx m)) m))))
 
5201
                  type-i-idx
 
5202
                  (:instance type-i (gvar (car (nth idx m))))
 
5203
                  (:instance rtmintvars-i-is-cdr-of-nth-entry (gvar (car (nth idx m))))
 
5204
                  (:instance equal-values-correspondence-kept-by-any-execution-sub (gvar1 (car (nth idx m))))
 
5205
                  (:instance no-duplicates-has-pos-equal-right-in-that-place (l m)))))
 
5206
  :otf-flg t)
 
5207
 
 
5208
(defthm m-correspondence-kept-by-any-execution-idxed-sub
 
5209
  (implies
 
5210
   (and
 
5211
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-sub)
 
5212
    (no-duplicates-p (retrieve-gemvars m))
 
5213
    (good-translation-gem-rtm gstate rstate m)
 
5214
    (alistp m)
 
5215
    (correct-wrt-arity m (mem gstate))
 
5216
    (gem-statep gstate)
 
5217
    (rtm-statep rstate)
 
5218
    (vars-inclusion (mem gstate) m)
 
5219
    (in-range (pcc gstate) (code gstate))
 
5220
    (in-range (pcc rstate) (code rstate))
 
5221
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
5222
    (m-correspondent-values-p m (mem gstate) (mem rstate)))
 
5223
  (m-correspondent-values-p 
 
5224
   m 
 
5225
   (mem (execute-instruction gstate))
 
5226
   (mem (execute-n-instructions rstate (len *rns*)))))
 
5227
  :hints (("Goal" :use (:instance equal-values-correspondence-kept-by-any-execution-idxed-sub
 
5228
                                  (idx (bad-idx-eqv-va m 
 
5229
                                                       (mem (execute-instruction gstate))
 
5230
                                                       (mem (execute-n-instructions rstate (len *rns*)))))))
 
5231
          ("Goal'" :cases ( (in-range (bad-idx-eqv-va m (mem (execute-instruction gstate))
 
5232
                                                       (mem (execute-n-instructions rstate (len *rns*)))) m)))
 
5233
          ("Subgoal 2" :in-theory '((:forward-chaining alistp-forward-to-true-listp)
 
5234
                                    (:rewrite if-bad-index-not-in-range-then-m-corr)))
 
5235
          ("Subgoal 1" :in-theory '((:rewrite if-bad-index-in-range-thne-must-be-different-vs)))))
 
5236
 
 
5237
 
 
5238
 
 
5239
 
 
5240
(defthm m-correspondence-and-other-conditions-kept-by-any-execution-sub
 
5241
  (implies
 
5242
   (and
 
5243
    (alistp m)
 
5244
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-sub)
 
5245
    (no-duplicates-p (retrieve-gemvars m))
 
5246
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
5247
    (good-translation-gem-rtm gstate rstate m)
 
5248
    (correct-wrt-arity m (mem gstate))
 
5249
    (gem-statep gstate)
 
5250
    (rtm-statep rstate)
 
5251
    (vars-inclusion (mem gstate) m)
 
5252
    (vars-inclusion m (mem gstate))
 
5253
    (in-range (pcc gstate) (code gstate))
 
5254
    (in-range (pcc rstate) (code rstate))
 
5255
    (m-entries-point-to-good-rtm-var-sets m (mem rstate))
 
5256
    (m-correspondent-values-p m (mem gstate) (mem rstate)))
 
5257
   (and
 
5258
    (good-translation-gem-rtm (execute-instruction gstate) (execute-n-instructions rstate (len *rns*)) m)
 
5259
    (rtm-statep (execute-n-instructions rstate (len *rns*)))
 
5260
    (m-entries-point-to-good-rtm-var-sets m (mem (execute-n-instructions rstate (len *rns*))))
 
5261
    (gem-statep (execute-instruction gstate))
 
5262
    (correct-wrt-arity m (mem (execute-instruction gstate)))
 
5263
    (vars-inclusion (mem (execute-instruction gstate)) m)
 
5264
    (vars-inclusion m (mem (execute-instruction gstate)))
 
5265
    (m-correspondent-values-p 
 
5266
     m 
 
5267
     (mem (execute-instruction gstate))
 
5268
     (mem (execute-n-instructions rstate (len *rns*))))))
 
5269
:hints (("Goal" 
 
5270
         :in-theory (disable 
 
5271
                     rtm-statep gem-statep
 
5272
                     pcc code opcode 
 
5273
                     execute-instruction rtmintvars-i par1 par2 par3 nth len member-equal) 
 
5274
         :use 
 
5275
         (m-correspondence-kept-by-any-execution-idxed-sub
 
5276
          good-translation-gem-rtm 
 
5277
          (:instance execute-n-instructions-keeps-rtm-state-and-points-to-good
 
5278
                     (st rstate) (n (len *rns*)))
 
5279
          (:instance executing-gem-instruction-retrieves-a-gem-state-from-gem-state (st gstate))
 
5280
          (:instance executing-gem-instruction-preserves-correctness-wrt-arity (st gstate))
 
5281
          (:instance executing-gem-instruction-keeps-vars-inclusion-right      (st gstate))
 
5282
          (:instance executing-gem-instruction-keeps-vars-inclusion-left       (st gstate))))))
 
5283
 
 
5284
 
 
5285
 
 
5286
 
 
5287
 
 
5288
 
 
5289
 
 
5290
;;(ld "Proof-Of-Comparison.lisp" :ld-error-action :error)
 
5291
 
 
5292
 
 
5293
 
 
5294
(defthm listinstr-of-2-unfolding-f
 
5295
 (equal 
 
5296
  (listinstr st 2)
 
5297
  (list
 
5298
   (nth (pcc st) (code st))
 
5299
   (nth (pcc (execute-instruction st)) (code (execute-instruction st)))))
 
5300
 :hints (("Goal"
 
5301
          :in-theory (current-theory 'ground-zero)
 
5302
          :use ( (:instance listinstr (n 2))
 
5303
                 (:instance listinstr (st (execute-instruction st)) (n 1))
 
5304
                 (:instance listinstr (st (execute-instruction (execute-instruction st))) (n 0))))))
 
5305
 
 
5306
   
 
5307
 
 
5308
(defthm listinstr-of-2-has-the-two-instructions
 
5309
 (implies
 
5310
  (equal (listinstr st 2)
 
5311
         (rtm-eq-and v1 v2 tmp res))
 
5312
  (and
 
5313
   (equal (nth (pcc st) (code st))  
 
5314
          (list 'rtm-equ tmp v1 v2))
 
5315
   (equal (nth (pcc (execute-instruction st)) (code (execute-instruction st))) 
 
5316
          (list 'rtm-and res tmp res))))
 
5317
 :hints (("Goal" :in-theory (current-theory 'ground-zero)
 
5318
          :use (rtm-eq-and
 
5319
                listinstr-of-2-unfolding-f ))))
 
5320
 
 
5321
(defthm listinstr-of-2-has-the-two-opcodes
 
5322
 (implies
 
5323
  (equal (listinstr st 2)
 
5324
         (rtm-eq-and v1 v2 tmp res))
 
5325
  (and
 
5326
   (equal (opcode (nth (pcc st) (code st))) 'rtm-equ)
 
5327
   (equal (par1   (nth (pcc st) (code st)))        tmp)
 
5328
   (equal (par2   (nth (pcc st) (code st)))        v1)
 
5329
   (equal (par3   (nth (pcc st) (code st)))        v2)   
 
5330
   (equal (opcode (nth (pcc (execute-instruction st)) (code (execute-instruction st)))) 'rtm-and)
 
5331
   (equal (par1   (nth (pcc (execute-instruction st)) (code (execute-instruction st)))) res)
 
5332
   (equal (par2   (nth (pcc (execute-instruction st)) (code (execute-instruction st)))) tmp)
 
5333
   (equal (par3   (nth (pcc (execute-instruction st)) (code (execute-instruction st)))) res)))
 
5334
 :hints (("Goal" :in-theory (union-theories (current-theory 'ground-zero) 
 
5335
                                            '((:definition par1)
 
5336
                                              (:definition par2)
 
5337
                                              (:definition par3)
 
5338
                                              (:definition opcode))) 
 
5339
          :use (listinstr-of-2-has-the-two-instructions
 
5340
                (:instance
 
5341
                 (:theorem  (and
 
5342
                             (equal (nth 0 (list a b c d)) a)
 
5343
                             (equal (nth 1 (list a b c d)) b)
 
5344
                             (equal (nth 2 (list a b c d)) c)
 
5345
                             (equal (nth 3 (list a b c d)) d)))
 
5346
                 (a 'rtm-equ)
 
5347
                 (b tmp)
 
5348
                 (c v1)
 
5349
                 (d v2))
 
5350
                (:instance
 
5351
                 (:theorem  (and
 
5352
                             (equal (nth 0 (list a b c d)) a)
 
5353
                             (equal (nth 1 (list a b c d)) b)
 
5354
                             (equal (nth 2 (list a b c d)) c)
 
5355
                             (equal (nth 3 (list a b c d)) d)))
 
5356
                 (a 'rtm-and)
 
5357
                 (b res)
 
5358
                 (c tmp)
 
5359
                 (d res))))))
 
5360
 
 
5361
 
 
5362
 
 
5363
(defthm listinstr-of-2-or-the-two-instructions
 
5364
 (implies
 
5365
  (equal (listinstr st 2)
 
5366
         (rtm-eq-or v1 v2 tmp res))
 
5367
  (and
 
5368
   (equal (nth (pcc st) (code st))  
 
5369
          (list 'rtm-equ tmp v1 v2))
 
5370
   (equal (nth (pcc (execute-instruction st)) (code (execute-instruction st))) 
 
5371
          (list 'rtm-or res tmp tmp))))
 
5372
 :hints (("Goal" :in-theory (current-theory 'ground-zero)
 
5373
          :use (rtm-eq-or
 
5374
                listinstr-of-2-unfolding-f ))))
 
5375
 
 
5376
(defthm listinstr-of-2-or-has-the-two-opcodes
 
5377
 (implies
 
5378
  (equal (listinstr st 2)
 
5379
         (rtm-eq-or v1 v2 tmp res))
 
5380
  (and
 
5381
   (equal (opcode (nth (pcc st) (code st)))   'rtm-equ)
 
5382
   (equal (par1   (nth (pcc st) (code st)))        tmp)
 
5383
   (equal (par2   (nth (pcc st) (code st)))         v1)
 
5384
   (equal (par3   (nth (pcc st) (code st)))         v2)   
 
5385
   (equal (opcode (nth (pcc (execute-instruction st)) (code (execute-instruction st)))) 'rtm-or)
 
5386
   (equal (par1   (nth (pcc (execute-instruction st)) (code (execute-instruction st)))) res)
 
5387
   (equal (par2   (nth (pcc (execute-instruction st)) (code (execute-instruction st)))) tmp)
 
5388
   (equal (par3   (nth (pcc (execute-instruction st)) (code (execute-instruction st)))) tmp)))
 
5389
 :hints (("Goal" :in-theory (union-theories (current-theory 'ground-zero) 
 
5390
                                            '((:definition par1)
 
5391
                                              (:definition par2)
 
5392
                                              (:definition par3)
 
5393
                                              (:definition opcode))) 
 
5394
          :use (listinstr-of-2-or-the-two-instructions
 
5395
                (:instance
 
5396
                 (:theorem  (and
 
5397
                             (equal (nth 0 (list a b c d)) a)
 
5398
                             (equal (nth 1 (list a b c d)) b)
 
5399
                             (equal (nth 2 (list a b c d)) c)
 
5400
                             (equal (nth 3 (list a b c d)) d)))
 
5401
                 (a 'rtm-equ)
 
5402
                 (b tmp)
 
5403
                 (c v1)
 
5404
                 (d v2))
 
5405
                (:instance
 
5406
                 (:theorem  (and
 
5407
                             (equal (nth 0 (list a b c d)) a)
 
5408
                             (equal (nth 1 (list a b c d)) b)
 
5409
                             (equal (nth 2 (list a b c d)) c)
 
5410
                             (equal (nth 3 (list a b c d)) d)))
 
5411
                 (a 'rtm-or)
 
5412
                 (b res)
 
5413
                 (c tmp)
 
5414
                 (d tmp))))))
 
5415
 
 
5416
 
 
5417
 
 
5418
 
 
5419
 
 
5420
(defthm one-steps-of-execution
 
5421
 (implies
 
5422
   (equal (listinstr st 2)
 
5423
          (rtm-eq-and v1 v2 tmp res))
 
5424
    (equal (execute-instruction st)
 
5425
           (generic-eql tmp v1 v2 st)))
 
5426
  :hints (("Goal" 
 
5427
           :in-theory '((:definition execute-instruction)) 
 
5428
           :use (listinstr-of-2-has-the-two-opcodes))))
 
5429
 
 
5430
(defthm two-steps-of-execution
 
5431
 (implies
 
5432
   (equal (listinstr st 2)
 
5433
          (rtm-eq-and v1 v2 tmp res))   
 
5434
    (equal (execute-instruction (execute-instruction st))
 
5435
           (rtm-and res tmp res (generic-eql tmp v1 v2 st))))
 
5436
  :hints (("Goal" 
 
5437
           :in-theory '((:definition execute-instruction)) 
 
5438
           :use (listinstr-of-2-has-the-two-opcodes))))
 
5439
 
 
5440
 
 
5441
; Note: Below I have disabled a couple of names.  This was not in the
 
5442
; original script.  In the conversion from Version 2.5 to 2.6, we
 
5443
; added the case-split-limitations and choked it down from (nil nil)
 
5444
; -- the old default -- to something smaller.  The first proof to
 
5445
; break was two-steps-inertia, below.  In analyzing why it broke, I
 
5446
; realized that two-steps-of-execution was being :USEd but not
 
5447
; DISABLEd.  So it could be rewritten away.  Disabling it, however,
 
5448
; had no good effect.  Then I realized that it could be rewritten away
 
5449
; by proving it again, which meant using the definition of
 
5450
; execute-instruction.  So I disabled that too.  And voila, the proof
 
5451
; happens very quickly, without significant case analysis -- certainly
 
5452
; without approaching the case-split-limitations.  You will see a
 
5453
; similar pair of disables once more below.
 
5454
 
 
5455
(defthm two-steps-inertia
 
5456
 (implies
 
5457
  (and
 
5458
   (equal (listinstr st 2)
 
5459
          (rtm-eq-and v1 v2 tmp res))
 
5460
   (not (equal tmp vx1))
 
5461
   (not (equal res vx1)))
 
5462
  (equal (get-cell vx1 (mem (execute-instruction (execute-instruction st))))
 
5463
         (get-cell vx1 (mem st))))
 
5464
 :hints (("Goal" :in-theory (disable execute-instruction     ; (See note above.)
 
5465
                                     two-steps-of-execution  ; (See note above.)
 
5466
                                     opcode one-steps-of-execution;par1 par2 par3 pcc code 
 
5467
                                     gem-add gem-sub rtm-add rtm-sub and-update gen-eq-update)
 
5468
          :use (two-steps-of-execution))))
 
5469
 
 
5470
 
 
5471
 
 
5472
(defthm two-steps-inertia-on-sequence-of-vars
 
5473
 (implies
 
5474
  (and
 
5475
   (equal (listinstr st 2) (rtm-eq-and v1 v2 tmp res))
 
5476
   (not (member-equal-bool tmp listvars1))
 
5477
   (not (member-equal-bool res listvars1)))
 
5478
  (equal
 
5479
   (var-values listvars1 (mem st))
 
5480
   (var-values listvars1 (mem (execute-instruction (execute-instruction st))))))
 
5481
 :hints (("Goal" 
 
5482
          :induct    (var-values listvars1 (mem st))
 
5483
          :in-theory (disable listinstr-of-2-unfolding-f
 
5484
                              two-steps-of-execution execute-instruction one-steps-of-execution))
 
5485
         ("Subgoal *1/2" :use (:instance two-steps-inertia (vx1 (car listvars1))))))
 
5486
 
 
5487
 
 
5488
(defthm two-steps-res
 
5489
 (implies
 
5490
  (and
 
5491
   (equal (listinstr st 2)
 
5492
          (rtm-eq-and v1 v2 tmp res))
 
5493
   (not (equal tmp v1))
 
5494
   (not (equal tmp v2))
 
5495
   (not (equal res v1))
 
5496
   (not (equal res v2))
 
5497
   (not (equal tmp res)))
 
5498
  (equal (var-value (get-cell res (mem (rtm-and res tmp res (generic-eql tmp v1 v2 st)))))
 
5499
         (boolean-to-int 
 
5500
          (and 
 
5501
           (int-to-bool 
 
5502
            (boolean-to-int (equal (var-value (get-cell v1 (mem st)))
 
5503
                                   (var-value (get-cell v2 (mem st))))))
 
5504
           (int-to-bool (var-value (get-cell res (mem st))))))))
 
5505
 :hints (("Goal" 
 
5506
          :in-theory (e/d 
 
5507
          (make-cell put-cell get-cell var-value) 
 
5508
          (opcode one-steps-of-execution execute-instruction
 
5509
                  int-to-bool boolean-to-int
 
5510
                  gem-add gem-sub rtm-add rtm-sub )))))
 
5511
 
 
5512
 
 
5513
(defthm one-steps-of-execution-or
 
5514
 (implies
 
5515
   (equal (listinstr st 2)
 
5516
          (rtm-eq-or v1 v2 tmp res))
 
5517
    (equal (execute-instruction st)
 
5518
           (generic-eql tmp v1 v2 st)))
 
5519
  :hints (("Goal" 
 
5520
           :in-theory '((:definition execute-instruction)) 
 
5521
           :use (listinstr-of-2-or-has-the-two-opcodes))))
 
5522
 
 
5523
(defthm two-steps-of-execution-or
 
5524
 (implies
 
5525
   (equal (listinstr st 2)
 
5526
          (rtm-eq-or v1 v2 tmp res))   
 
5527
    (equal (execute-instruction (execute-instruction st))
 
5528
           (rtm-or res tmp tmp (generic-eql tmp v1 v2 st))))
 
5529
  :hints (("Goal" 
 
5530
           :in-theory '((:definition execute-instruction)) 
 
5531
           :use (listinstr-of-2-or-has-the-two-opcodes))))
 
5532
 
 
5533
 
 
5534
(defthm two-steps-inertia-or
 
5535
 (implies
 
5536
  (and
 
5537
   (equal (listinstr st 2)
 
5538
          (rtm-eq-or v1 v2 tmp res))
 
5539
   (not (equal tmp vx1))
 
5540
   (not (equal res vx1)))
 
5541
  (equal (get-cell vx1 (mem (execute-instruction (execute-instruction st))))
 
5542
         (get-cell vx1 (mem st))))
 
5543
 :hints (("Goal" :in-theory (disable execute-instruction       ; (See note above.)
 
5544
                                     two-steps-of-execution-or ; (See note above.)
 
5545
                                     opcode one-steps-of-execution-or ;par1 par2 par3 pcc code 
 
5546
                                     gem-add gem-sub rtm-add rtm-sub and-update gen-eq-update or-update)
 
5547
          :use (two-steps-of-execution-or))))
 
5548
 
 
5549
 
 
5550
 
 
5551
(defthm two-steps-inertia-on-sequence-of-vars-or
 
5552
 (implies
 
5553
  (and
 
5554
   (equal (listinstr st 2) (rtm-eq-or v1 v2 tmp res))
 
5555
   (not (member-equal-bool tmp listvars1))
 
5556
   (not (member-equal-bool res listvars1)))
 
5557
  (equal
 
5558
   (var-values listvars1 (mem st))
 
5559
   (var-values listvars1 (mem (execute-instruction (execute-instruction st))))))
 
5560
 :hints (("Goal" 
 
5561
          :induct    (var-values listvars1 (mem st))
 
5562
          :in-theory (disable listinstr-of-2-unfolding-f
 
5563
                              two-steps-of-execution-or execute-instruction one-steps-of-execution-or))
 
5564
         ("Subgoal *1/2" :use (:instance two-steps-inertia-or (vx1 (car listvars1))))))
 
5565
 
 
5566
 
 
5567
(defthm two-steps-res-or
 
5568
 (implies
 
5569
  (and
 
5570
   (equal (listinstr st 2)
 
5571
          (rtm-eq-or v1 v2 tmp res))
 
5572
   (not (equal tmp v1))
 
5573
   (not (equal tmp v2))
 
5574
   (not (equal res v1))
 
5575
   (not (equal res v2))
 
5576
   (not (equal tmp res)))
 
5577
  (equal (var-value (get-cell res (mem (rtm-or res tmp tmp (generic-eql tmp v1 v2 st)))))
 
5578
         (boolean-to-int 
 
5579
          (equal (var-value (get-cell v1 (mem st)))
 
5580
                 (var-value (get-cell v2 (mem st)))))))
 
5581
 :hints (("Goal" 
 
5582
          :use (:theorem
 
5583
                (equal
 
5584
                 (or 
 
5585
                  (int-to-bool 
 
5586
                   (boolean-to-int (equal (var-value (get-cell v1 (mem st)))
 
5587
                                          (var-value (get-cell v2 (mem st))))))
 
5588
                  (int-to-bool
 
5589
                   (boolean-to-int (equal (var-value (get-cell v1 (mem st)))
 
5590
                                          (var-value (get-cell v2 (mem st)))))))
 
5591
                 (equal (var-value (get-cell v1 (mem st)))
 
5592
                        (var-value (get-cell v2 (mem st))))))
 
5593
          :in-theory (e/d 
 
5594
          (make-cell put-cell get-cell var-value) 
 
5595
          (opcode one-steps-of-execution-or execute-instruction
 
5596
                  int-to-bool boolean-to-int
 
5597
                  gem-add gem-sub rtm-add rtm-sub )))))
 
5598
 
 
5599
 
 
5600
 
 
5601
(defthm execute-instruction-2-unfolding
 
5602
  (equal 
 
5603
   (execute-n-instructions st 2) 
 
5604
   (execute-instruction (execute-instruction st)))
 
5605
  :hints (("Goal" 
 
5606
           :in-theory (current-theory 'ground-zero)
 
5607
           :use 
 
5608
           ((:instance execute-n-instructions (n 2))
 
5609
            (:instance execute-n-instructions (st (execute-instruction st)) (n 1))
 
5610
            (:instance execute-n-instructions (st (execute-instruction (execute-instruction st))) (n 0))))))
 
5611
 
 
5612
 
 
5613
 
 
5614
(defthm two-steps-res-2
 
5615
 (implies
 
5616
  (and
 
5617
   (equal (listinstr st 2)
 
5618
          (rtm-eq-and v1 v2 tmp res))
 
5619
   (not (equal tmp v1))
 
5620
   (not (equal tmp v2))
 
5621
   (not (equal res v1))
 
5622
   (not (equal res v2))
 
5623
   (not (equal tmp res)))
 
5624
  (equal (var-value (get-cell res (mem (execute-n-instructions st 2))))
 
5625
         (boolean-to-int 
 
5626
          (and 
 
5627
           (equal (var-value (get-cell v1 (mem st)))
 
5628
                  (var-value (get-cell v2 (mem st))))
 
5629
           (int-to-bool (var-value (get-cell res (mem st))))))))
 
5630
 :hints (("Goal" :in-theory '((:definition int-to-bool) 
 
5631
                              (:definition boolean-to-int))
 
5632
          :use (two-steps-res two-steps-of-execution execute-instruction-2-unfolding))))
 
5633
 
 
5634
 
 
5635
(defthm two-steps-res-or-2
 
5636
 (implies
 
5637
  (and
 
5638
   (equal (listinstr st 2)
 
5639
          (rtm-eq-or v1 v2 tmp res))
 
5640
   (not (equal tmp v1))
 
5641
   (not (equal tmp v2))
 
5642
   (not (equal res v1))
 
5643
   (not (equal res v2))
 
5644
   (not (equal tmp res)))
 
5645
  (equal (var-value (get-cell res (mem (execute-n-instructions st 2))))
 
5646
         (boolean-to-int 
 
5647
          (equal (var-value (get-cell v1 (mem st)))
 
5648
                 (var-value (get-cell v2 (mem st)))))))
 
5649
 :hints (("Goal" :in-theory '((:definition int-to-bool) 
 
5650
                              (:definition boolean-to-int))
 
5651
          :use (two-steps-res-or two-steps-of-execution-or execute-instruction-2-unfolding))))
 
5652
 
 
5653
 
 
5654
(defthm int-bool-int-cancellation 
 
5655
     (equal (int-to-bool (boolean-to-int  (equal v1 v2))) (equal v1 v2)))
 
5656
 
 
5657
(defthm bool-int-bool-cancellation 
 
5658
  (implies
 
5659
   (or (equal res 0) (equal res 1))
 
5660
  (equal (boolean-to-int (int-to-bool res)) res)))
 
5661
 
 
5662
(defun eq-values (listvars1 listvars2 res mem n)
 
5663
  (if (zp n)
 
5664
      res
 
5665
    (eq-values 
 
5666
     (cdr listvars1) 
 
5667
     (cdr listvars2)
 
5668
     (boolean-to-int 
 
5669
      (and 
 
5670
       (equal (var-value (get-cell (car listvars1) mem))
 
5671
              (var-value (get-cell (car listvars2) mem)))
 
5672
       (int-to-bool res)))
 
5673
     mem
 
5674
     (1- n))))
 
5675
 
 
5676
 
 
5677
(defun equal-lv (listvars1 listvars2 mem n)
 
5678
  (declare (xargs :measure (acl2-count n)))
 
5679
  (if (zp n)
 
5680
      t
 
5681
    (and 
 
5682
     (equal 
 
5683
      (var-value (get-cell (car listvars1) mem))
 
5684
      (var-value (get-cell (car listvars2) mem)))
 
5685
     (equal-lv (cdr listvars1) (cdr listvars2) mem (1- n)))))
 
5686
 
 
5687
 
 
5688
(defthm case-zero 
 
5689
  (equal (eq-values listvars1 listvars2 0 mem n) 0))
 
5690
 
 
5691
(defthm case-one
 
5692
  (equal (eq-values listvars1 listvars2 1 mem n) (boolean-to-int (equal-lv listvars1 listvars2 mem n))))
 
5693
 
 
5694
(defthm eq-values-is-equal-lv
 
5695
 (implies
 
5696
  (and
 
5697
   (or (equal res 0) (equal res 1))
 
5698
   (equal n (len listvars2))
 
5699
   (equal n (len listvars1)))
 
5700
  (equal
 
5701
   (eq-values listvars1 listvars2 res mem n)
 
5702
   (boolean-to-int 
 
5703
    (and 
 
5704
     (equal-lv listvars1 listvars2 mem n)
 
5705
     (int-to-bool res)))))
 
5706
 :hints (("Goal" :in-theory (disable int-to-bool boolean-to-int))))
 
5707
 
 
5708
    
 
5709
(defthm equal-lv-is-equal-values
 
5710
 (implies
 
5711
  (and
 
5712
   (equal n (len listvars1))
 
5713
   (equal n (len listvars2))) 
 
5714
  (equal
 
5715
   (equal-lv listvars1 listvars2 mem n)
 
5716
   (equal-values 
 
5717
    (var-values listvars1 mem)
 
5718
    (var-values listvars2 mem)))))
 
5719
     
 
5720
 
 
5721
(defthm eq-values-is-equal-values
 
5722
 (implies
 
5723
  (and
 
5724
   (or (equal res 0) (equal res 1))
 
5725
   (equal n (len listvars2))
 
5726
   (equal n (len listvars1)))
 
5727
  (equal
 
5728
   (eq-values listvars1 listvars2 res mem n)
 
5729
   (boolean-to-int 
 
5730
    (and 
 
5731
     (equal-values 
 
5732
      (var-values listvars1 mem)
 
5733
      (var-values listvars2 mem))     
 
5734
     (int-to-bool res))))))
 
5735
 
 
5736
 
 
5737
(defun induct-support (listvars1 listvars2 tmp res st)
 
5738
  (if
 
5739
      (endp listvars1)
 
5740
      nil
 
5741
    (cons (list (car listvars1) (car listvars2) tmp res (pcc st))
 
5742
          (induct-support
 
5743
           (cdr listvars1)
 
5744
           (cdr listvars2)
 
5745
           tmp
 
5746
           res
 
5747
           (execute-n-instructions st 2)))))
 
5748
 
 
5749
(defthm support-1
 
5750
 (implies
 
5751
  (and
 
5752
   (not (endp listvars1))
 
5753
   (not (member-equal-bool tmp listvars1))
 
5754
   (not (member-equal-bool tmp listvars2))
 
5755
   (not (member-equal-bool res listvars1))
 
5756
   (not (member-equal-bool res listvars2)))
 
5757
  (and
 
5758
   (not (member-equal-bool tmp (cdr listvars1)))
 
5759
   (not (member-equal-bool tmp (cdr listvars2)))
 
5760
   (not (member-equal-bool res (cdr listvars1)))
 
5761
   (not (member-equal-bool res (cdr listvars2))))))
 
5762
 
 
5763
(defthm listinstr-is-decomposed 
 
5764
 (implies
 
5765
  (and
 
5766
   (integerp n)
 
5767
   (>= n 0))
 
5768
  (equal
 
5769
   (listinstr (execute-n-instructions st n) m)
 
5770
   (nthcdr n (listinstr st (+ n m)))))
 
5771
 :hints (("Goal" 
 
5772
          :induct (execute-n-instructions st n)
 
5773
          :in-theory (disable execute-instruction))))
 
5774
 
 
5775
(defthm nthcdr-2-unfolding 
 
5776
  (equal (nthcdr 2 l) (cddr l)))
 
5777
 
 
5778
(defthm nthcdr2ofeqtrans2
 
5779
 (implies
 
5780
  (not (endp listvars1))
 
5781
  (equal
 
5782
   (equality-trans2 (cdr listvars1) (cdr listvars2) tmp res)
 
5783
   (nthcdr 2 (equality-trans2 listvars1 listvars2 tmp res))))
 
5784
 :hints (("Goal" :use 
 
5785
          ( (:instance nthcdr-2-unfolding
 
5786
                       (l (equality-trans2 listvars1 listvars2 tmp res)))
 
5787
            equality-trans2)
 
5788
          :in-theory (union-theories (current-theory 'ground-zero) '((:definition rtm-eq-and))))))
 
5789
   
 
5790
(in-theory (disable nthcdr-2-unfolding nthcdr2ofeqtrans2 listinstr-is-decomposed))
 
5791
 
 
5792
(defthm support-2a
 
5793
 (implies
 
5794
   (not (endp listvars1))
 
5795
   (equal (listinstr (execute-n-instructions st 2) (* 2 (len (cdr listvars1))))
 
5796
          (nthcdr 2 (listinstr st (* 2 (len listvars1))))))
 
5797
 :hints (("Goal"
 
5798
          :use (
 
5799
                (:instance listinstr-is-decomposed
 
5800
                          (n 2)
 
5801
                          (m (* 2 (len (cdr listvars1))))))
 
5802
          :in-theory (disable execute-instruction execute-instruction-2-unfolding is-mem-cell-p))))
 
5803
 
 
5804
(defthm support-2
 
5805
 (implies
 
5806
  (and
 
5807
   (not (endp listvars1))
 
5808
   (equal (listinstr st (* 2 (len listvars1)))
 
5809
          (equality-trans2 listvars1 listvars2 tmp res)))
 
5810
   (equal (listinstr (execute-n-instructions st 2) (* 2 (len (cdr listvars1))))
 
5811
          (equality-trans2 (cdr listvars1) (cdr listvars2) tmp res)))
 
5812
 :hints (("Goal"
 
5813
          :in-theory nil
 
5814
          :use (nthcdr2ofeqtrans2 support-2a))))
 
5815
 
 
5816
 
 
5817
 
 
5818
(defthm listinstr-append
 
5819
 (implies
 
5820
  (and
 
5821
   (integerp n)
 
5822
   (integerp m)
 
5823
   (>= m 0)
 
5824
   (>= n 0))
 
5825
  (equal 
 
5826
   (listinstr st (+ m n))
 
5827
   (append (listinstr st m)
 
5828
         (listinstr (execute-n-instructions st m) n))))
 
5829
 :hints (("Goal" 
 
5830
          :in-theory (disable execute-instruction))))
 
5831
 
 
5832
(defthm silly-00
 
5833
 (implies
 
5834
  (and
 
5835
   (equal l (append l1 l2))
 
5836
   (>= (len l1) 2))
 
5837
  (and
 
5838
   (equal (car l1) (car l))
 
5839
   (equal (cadr l1) (cadr l)))))
 
5840
 
 
5841
(defthm length-of-listintr
 
5842
  (implies 
 
5843
   (and
 
5844
    (integerp n)
 
5845
    (>= n 0))
 
5846
   (equal (len (listinstr st n)) n)))
 
5847
 
 
5848
(defthm first-2-instr-are-same-if-many
 
5849
 (implies
 
5850
  (and
 
5851
   (integerp le)
 
5852
   (>= le 2))
 
5853
   (and
 
5854
    (equal (car (listinstr st 2))  (car  (listinstr st le)))
 
5855
    (equal (cadr (listinstr st 2)) (cadr (listinstr st le)))))
 
5856
 :hints (("Goal" :in-theory (current-theory 'ground-zero)
 
5857
          :use 
 
5858
          (
 
5859
           (:theorem (implies (integerp le) (equal (+ 2 -2 le) le)))
 
5860
           (:instance silly-00
 
5861
                      (l1 (listinstr st 2))
 
5862
                      (l2 (listinstr (execute-n-instructions st 2) (- le 2)))
 
5863
                      (l (listinstr st le)))
 
5864
           (:instance length-of-listintr (n 2))
 
5865
           (:instance listinstr-append
 
5866
                      (m 2)
 
5867
                      (n (- le 2)))))))
 
5868
 
 
5869
 
 
5870
(defthm first-2-instr-are-same-if-many-inst
 
5871
 (implies
 
5872
  (not (endp listvars1))
 
5873
  (and
 
5874
   (equal (car (listinstr st 2))  (car  (listinstr st (* 2 (len listvars1)))))
 
5875
   (equal (cadr (listinstr st 2)) (cadr (listinstr st (* 2 (len listvars1)))))))
 
5876
 :hints (("Goal" 
 
5877
          :in-theory (current-theory 'ground-zero)
 
5878
          :use (:instance first-2-instr-are-same-if-many (le (* 2 (len listvars1))))))
 
5879
 :otf-flg t)
 
5880
 
 
5881
 
 
5882
 
 
5883
(defthm first-two-instructions-are-eq-and
 
5884
 (implies
 
5885
  (and
 
5886
   (not (endp listvars1))
 
5887
   (equal (listinstr st (* 2 (len listvars1)))
 
5888
          (equality-trans2 listvars1 listvars2 tmp res)))
 
5889
  (equal (listinstr st 2) (rtm-eq-and (car listvars1) (car listvars2) tmp res)))
 
5890
 :hints (("Goal" 
 
5891
          :in-theory (disable execute-instruction)
 
5892
          :use first-2-instr-are-same-if-many-inst)))
 
5893
 
 
5894
 
 
5895
 
 
5896
(defthm support-3a
 
5897
 (implies
 
5898
  (and
 
5899
   (equal (listinstr st (* 2 (len listvars1)))
 
5900
          (equality-trans2 listvars1 listvars2 tmp res))
 
5901
   (not (endp listvars1))
 
5902
   (not (endp listvars2))
 
5903
   (not (member-equal-bool tmp listvars1))
 
5904
   (not (member-equal-bool tmp listvars2))
 
5905
   (not (member-equal-bool res listvars1))
 
5906
   (not (member-equal-bool res listvars2))
 
5907
   (not (equal tmp res)))
 
5908
  (equal
 
5909
   (eq-values 
 
5910
    listvars1 
 
5911
    listvars2 
 
5912
    (var-value (get-cell res (mem st))) 
 
5913
    (mem st) 
 
5914
    (len listvars1))
 
5915
   (eq-values
 
5916
    (cdr listvars1)
 
5917
    (cdr listvars2)
 
5918
    (var-value (get-cell res (mem (execute-n-instructions st 2))))
 
5919
    (mem st)
 
5920
    (len (cdr listvars1)))))
 
5921
 :hints (("Goal" 
 
5922
          :in-theory (disable listinstr-append listinstr-of-2-unfolding-f
 
5923
                              execute-instruction one-steps-of-execution execute-instruction-2-unfolding)
 
5924
          :use 
 
5925
          (first-two-instructions-are-eq-and
 
5926
           (:instance two-steps-res-2 (v1 (car listvars1)) (v2 (car listvars2)))))))
 
5927
 
 
5928
 
 
5929
 
 
5930
 
 
5931
 
 
5932
(defthm support-3
 
5933
 (implies
 
5934
  (and
 
5935
   (equal (listinstr st (* 2 (len listvars1)))
 
5936
          (equality-trans2 listvars1 listvars2 tmp res))
 
5937
   (not (endp listvars1))
 
5938
   (not (endp listvars2))
 
5939
   (equal (len listvars1) (len listvars2))
 
5940
   (not (member-equal-bool tmp listvars1))
 
5941
   (not (member-equal-bool tmp listvars2))
 
5942
   (not (member-equal-bool res listvars1))
 
5943
   (not (member-equal-bool res listvars2))
 
5944
   (not (equal tmp res)))
 
5945
  (equal
 
5946
   (eq-values 
 
5947
    listvars1 
 
5948
    listvars2 
 
5949
    (var-value (get-cell res (mem st))) 
 
5950
    (mem st) 
 
5951
    (len listvars1))
 
5952
   (eq-values
 
5953
    (cdr listvars1)
 
5954
    (cdr listvars2)
 
5955
    (var-value (get-cell res (mem (execute-n-instructions st 2))))
 
5956
    (mem (execute-instruction (execute-instruction st)))
 
5957
    (len (cdr listvars1)))))
 
5958
 :hints (("Goal" 
 
5959
          :in-theory (disable listinstr-append listinstr-of-2-unfolding-f
 
5960
                              execute-instruction one-steps-of-execution execute-instruction-2-unfolding)
 
5961
          :use 
 
5962
          (first-two-instructions-are-eq-and
 
5963
           (:instance two-steps-inertia-on-sequence-of-vars
 
5964
                      (v1 (car listvars1))
 
5965
                      (v2 (car listvars2))
 
5966
                      (listvars1 (cdr listvars1)))
 
5967
           (:instance two-steps-inertia-on-sequence-of-vars
 
5968
                      (v1 (car listvars1))
 
5969
                      (v2 (car listvars2))
 
5970
                      (listvars1 (cdr listvars2)))
 
5971
           (:instance two-steps-res-2 (v1 (car listvars1)) (v2 (car listvars2)))))))
 
5972
 
 
5973
   
 
5974
 
 
5975
  
 
5976
 
 
5977
 
 
5978
 
 
5979
   
 
5980
(defthm value-of-result-after-executing-2n-instr
 
5981
 (implies
 
5982
  (and
 
5983
   (not (member-equal-bool tmp listvars1))
 
5984
   (not (member-equal-bool tmp listvars2))
 
5985
   (not (member-equal-bool res listvars1))
 
5986
   (not (member-equal-bool res listvars2))
 
5987
   (equal (len listvars1) (len listvars2))
 
5988
   (not (equal tmp res))
 
5989
   (equal (listinstr st (* 2 (len listvars1)))
 
5990
          (equality-trans2 listvars1 listvars2 tmp res)))
 
5991
 (equal 
 
5992
  (var-value 
 
5993
   (get-cell 
 
5994
    res
 
5995
    (mem (execute-n-instructions st (* 2 (len listvars1))))))
 
5996
  (eq-values 
 
5997
   listvars1 
 
5998
   listvars2 
 
5999
   (var-value (get-cell res (mem st))) 
 
6000
   (mem st) 
 
6001
   (len listvars1))))
 
6002
 :hints (("Goal" 
 
6003
          :in-theory (disable execute-instruction is-mem-cell-p)
 
6004
          :induct (induct-support listvars1 listvars2 tmp res st))
 
6005
         ("Subgoal *1/2" :use (support-1 support-2 support-3))))
 
6006
 
 
6007
 
 
6008
(defthm value-of-result-after-executing-2n-instr-fin
 
6009
 (implies
 
6010
  (and
 
6011
   (not (member-equal-bool tmp listvars1))
 
6012
   (not (member-equal-bool tmp listvars2))
 
6013
   (not (member-equal-bool res listvars1))
 
6014
   (not (member-equal-bool res listvars2))
 
6015
   (equal (len listvars1) (len listvars2))
 
6016
   (or
 
6017
    (equal (var-value (get-cell res (mem st))) 0)
 
6018
    (equal (var-value (get-cell res (mem st))) 1))
 
6019
   (not (equal tmp res))
 
6020
   (equal (listinstr st (* 2 (len listvars1)))
 
6021
          (equality-trans2 listvars1 listvars2 tmp res)))
 
6022
 (equal 
 
6023
  (var-value 
 
6024
   (get-cell 
 
6025
    res
 
6026
    (mem (execute-n-instructions st (* 2 (len listvars1))))))
 
6027
  (boolean-to-int
 
6028
   (and
 
6029
    (equal-values 
 
6030
     (var-values listvars1 (mem st))
 
6031
     (var-values listvars2 (mem st)))
 
6032
    (int-to-bool (var-value (get-cell res (mem st))))))))
 
6033
 :hints (("Goal" 
 
6034
          :in-theory (disable execute-instruction is-mem-cell-p)
 
6035
          :use (value-of-result-after-executing-2n-instr))))
 
6036
(defthm nthcdr2ofeqtrans3
 
6037
  (equal
 
6038
   (equality-trans2 (cdr listvars1) (cdr listvars2) tmp res)
 
6039
   (nthcdr 2 (equality-trans3 listvars1 listvars2 tmp res)))
 
6040
 :hints (("Goal" :use 
 
6041
          ( (:instance nthcdr-2-unfolding
 
6042
                       (l (equality-trans3 listvars1 listvars2 tmp res)))
 
6043
            equality-trans3)
 
6044
          :in-theory (union-theories (current-theory 'ground-zero) '((:definition rtm-eq-or))))))
 
6045
   
 
6046
(in-theory (disable nthcdr-2-unfolding nthcdr2ofeqtrans3 listinstr-is-decomposed))
 
6047
 
 
6048
 
 
6049
(defthm support-2b
 
6050
 (implies
 
6051
  (and
 
6052
   (not (endp listvars1))
 
6053
   (equal (listinstr st (* 2 (len listvars1)))
 
6054
          (equality-trans3 listvars1 listvars2 tmp res)))
 
6055
   (equal (listinstr (execute-n-instructions st 2) (* 2 (len (cdr listvars1))))
 
6056
          (equality-trans2 (cdr listvars1) (cdr listvars2) tmp res)))
 
6057
 :hints (("Goal"
 
6058
          :in-theory nil
 
6059
          :use (nthcdr2ofeqtrans3 support-2a))))
 
6060
 
 
6061
 
 
6062
 
 
6063
(defthm first-two-instructions-are-eq-or
 
6064
 (implies
 
6065
  (and
 
6066
   (not (endp listvars1))
 
6067
   (equal (listinstr st (* 2 (len listvars1)))
 
6068
          (equality-trans3 listvars1 listvars2 tmp res)))
 
6069
  (equal (listinstr st 2) (rtm-eq-or (car listvars1) (car listvars2) tmp res)))
 
6070
 :hints (("Goal" 
 
6071
          :in-theory (disable nthcdr nthcdr2ofeqtrans3 execute-instruction
 
6072
                              ;; v2-6 mod:
 
6073
                              listinstr-append)
 
6074
          :use first-2-instr-are-same-if-many-inst)))
 
6075
 
 
6076
 
 
6077
 
 
6078
 
 
6079
(defthm support4
 
6080
 (implies
 
6081
  (not (endp listvars1))
 
6082
  (EQUAL
 
6083
   (EXECUTE-N-INSTRUCTIONS (EXECUTE-N-INSTRUCTIONS ST 2) (* 2 (LEN (CDR LISTVARS1))))
 
6084
   (EXECUTE-N-INSTRUCTIONS ST (* 2 (LEN LISTVARS1)))))
 
6085
 :hints (("Goal" 
 
6086
          :in-theory (current-theory 'ground-zero) 
 
6087
          :use 
 
6088
          (:instance execute-n-instruction-decomposition
 
6089
                     (n1 2)
 
6090
                     (n2 (* 2 (1- (len listvars1))))))
 
6091
         ("Subgoal 1" 
 
6092
          :use ((:theorem (equal (+ -2 2   (* 2 (LEN (CDR LISTVARS1))))
 
6093
                                           (* 2 (LEN (CDR LISTVARS1)))))
 
6094
                (:theorem (equal (+ 2      (* 2 (LEN (CDR LISTVARS1))))
 
6095
                                 (+ 2 -2 2 (* 2 (LEN (CDR LISTVARS1))))))))))
 
6096
 
 
6097
 
 
6098
(defthm value-of-result-after-executing-2n-+2instr-fin
 
6099
 (implies
 
6100
  (and
 
6101
   (not (member-equal-bool tmp listvars1))
 
6102
   (not (member-equal-bool tmp listvars2))
 
6103
   (not (member-equal-bool res listvars1))
 
6104
   (not (member-equal-bool res listvars2))
 
6105
   (equal (len listvars1) (len listvars2))
 
6106
   (not (endp listvars1))
 
6107
   (not (equal tmp res))
 
6108
   (equal (listinstr st (* 2 (len listvars1)))
 
6109
          (equality-trans3 listvars1 listvars2 tmp res)))
 
6110
 (equal 
 
6111
  (var-value 
 
6112
   (get-cell 
 
6113
    res
 
6114
    (mem (execute-n-instructions st (* 2 (len listvars1))))))
 
6115
  (boolean-to-int
 
6116
   (and
 
6117
    (equal-values 
 
6118
     (var-values (cdr listvars1) (mem (execute-n-instructions st 2)))
 
6119
     (var-values (cdr listvars2) (mem (execute-n-instructions st 2))))
 
6120
    (int-to-bool 
 
6121
     (boolean-to-int 
 
6122
      (equal (var-value (get-cell (car listvars1) (mem st)))
 
6123
             (var-value (get-cell (car listvars2) (mem st))))))))))
 
6124
 :hints (("Goal" 
 
6125
          :in-theory (union-theories (current-theory 'ground-zero) 
 
6126
                                     '((:definition member-equal-bool)
 
6127
                                       (:definition boolean-to-int)))
 
6128
          :use 
 
6129
          (
 
6130
           support-2b
 
6131
           support4
 
6132
           first-two-instructions-are-eq-or
 
6133
           (:instance value-of-result-after-executing-2n-instr-fin 
 
6134
                      (st (execute-n-instructions st 2))
 
6135
                      (listvars1 (cdr listvars1))
 
6136
                      (listvars2 (cdr listvars2)))
 
6137
           (:instance two-steps-res-or-2
 
6138
                      (v1 (car listvars1))
 
6139
                      (v2 (car listvars2)))))))
 
6140
 
 
6141
 
 
6142
(defthm at-the-end-equality-on-all
 
6143
 (implies
 
6144
  (and
 
6145
   (not (endp listvars1))
 
6146
   (equal (len listvars1) (len listvars2)))
 
6147
  (equal
 
6148
   (boolean-to-int
 
6149
    (equal-values 
 
6150
     (var-values listvars1 (mem st ))
 
6151
     (var-values listvars2 (mem st ))))   
 
6152
   (boolean-to-int
 
6153
    (and
 
6154
     (equal-values 
 
6155
      (var-values (cdr listvars1) (mem st ))
 
6156
      (var-values (cdr listvars2) (mem st )))
 
6157
     (int-to-bool 
 
6158
      (boolean-to-int 
 
6159
       (equal (var-value (get-cell (car listvars1) (mem st)))
 
6160
              (var-value (get-cell (car listvars2) (mem st)))))))))))
 
6161
 
 
6162
 
 
6163
 
 
6164
 
 
6165
 
 
6166
 
 
6167
 
 
6168
(defthm value-of-result-after-executing-2n-+2instr-finale
 
6169
 (implies
 
6170
  (and
 
6171
   (not (member-equal-bool tmp listvars1))
 
6172
   (not (member-equal-bool tmp listvars2))
 
6173
   (not (member-equal-bool res listvars1))
 
6174
   (not (member-equal-bool res listvars2))
 
6175
   (equal (len listvars1) (len listvars2))
 
6176
   (not (endp listvars1))
 
6177
   (not (equal tmp res))
 
6178
   (equal (listinstr st (* 2 (len listvars1)))
 
6179
          (equality-trans3 listvars1 listvars2 tmp res)))
 
6180
 (equal 
 
6181
  (var-value 
 
6182
   (get-cell 
 
6183
    res
 
6184
    (mem (execute-n-instructions st (* 2 (len listvars1))))))
 
6185
  (boolean-to-int
 
6186
    (equal-values 
 
6187
     (var-values  listvars1 (mem st ))
 
6188
     (var-values  listvars2 (mem st ))))))
 
6189
 :hints (("Goal" 
 
6190
          :in-theory
 
6191
          (union-theories (current-theory 'ground-zero) 
 
6192
                                     '((:rewrite execute-instruction-2-unfolding)
 
6193
                                       (:definition member-equal-bool)))
 
6194
          :use (
 
6195
                (:instance two-steps-inertia-on-sequence-of-vars-or
 
6196
                           (v1 (car listvars1))
 
6197
                           (v2 (car listvars2))
 
6198
                           (listvars1 (cdr listvars1)))
 
6199
                (:instance two-steps-inertia-on-sequence-of-vars-or
 
6200
                           (v1 (car listvars1))
 
6201
                           (v2 (car listvars2))
 
6202
                           (listvars1 (cdr listvars2)))
 
6203
                first-two-instructions-are-eq-or
 
6204
                value-of-result-after-executing-2n-+2instr-fin
 
6205
                at-the-end-equality-on-all))))
 
6206
 
 
6207
 
 
6208
(in-theory (disable
 
6209
listinstr-of-2-unfolding-f listinstr-of-2-has-the-two-instructions listinstr-of-2-has-the-two-opcodes
 
6210
listinstr-of-2-or-the-two-instructions listinstr-of-2-or-has-the-two-opcodes
 
6211
one-steps-of-execution two-steps-of-execution two-steps-inertia
 
6212
two-steps-inertia-on-sequence-of-vars two-steps-res
 
6213
one-steps-of-execution-or two-steps-of-execution-or two-steps-inertia-or
 
6214
two-steps-inertia-on-sequence-of-vars-or two-steps-res-or
 
6215
execute-instruction-2-unfolding two-steps-res-2 two-steps-res-or-2 
 
6216
int-bool-int-cancellation bool-int-bool-cancellation case-zero case-one
 
6217
equal-lv-is-equal-values eq-values-is-equal-values
 
6218
support-1 listinstr-is-decomposed nthcdr-2-unfolding support-2a support-2
 
6219
listinstr-append silly-00 length-of-listintr
 
6220
first-2-instr-are-same-if-many first-2-instr-are-same-if-many-inst
 
6221
first-two-instructions-are-eq-and support-3a support-3
 
6222
value-of-result-after-executing-2n-instr value-of-result-after-executing-2n-instr-fin
 
6223
equality-trans3 nthcdr2ofeqtrans3 support-2b 
 
6224
first-two-instructions-are-eq-or support4
 
6225
value-of-result-after-executing-2n-+2instr-fin
 
6226
at-the-end-equality-on-all value-of-result-after-executing-2n-+2instr-finale))
 
6227
 
 
6228
(defun pars1-instructions (listinstr)
 
6229
  (if (endp listinstr)
 
6230
      nil
 
6231
    (cons (par1 (car listinstr))
 
6232
          (pars1-instructions (cdr listinstr)))))
 
6233
 
 
6234
(defthm pars1-instruction-is-listpars1 
 
6235
  (equal 
 
6236
   (pars1-instructions (listinstr st n)) 
 
6237
   (listpars1 st n)))
 
6238
 
 
6239
 
 
6240
 
 
6241
(defun eqtr2 (l1 tmp res)
 
6242
  (if
 
6243
      (endp l1)
 
6244
      nil
 
6245
    (append (list tmp res) (eqtr2 (cdr l1) tmp res))))
 
6246
 
 
6247
(defun eqtr3 (l1 tmp res)
 
6248
  (append (list tmp res) (eqtr2 (cdr l1) tmp res)))
 
6249
 
 
6250
(defthm cgr1 (equal (pars1-instructions (equality-trans2 l1 l2 tmp res)) (eqtr2 l1 tmp res)))
 
6251
 
 
6252
(defthm pars1iappend
 
6253
  (equal (pars1-instructions (append l1 l2)) 
 
6254
         (append (pars1-instructions l1) (pars1-instructions l2))))
 
6255
 
 
6256
(defthm parsi-instructions-of-eq3-are-eqtr3
 
6257
  (equal (pars1-instructions (equality-trans3 l1 l2 tmp res)) (eqtr3 l1 tmp res))
 
6258
     :hints (("Subgoal 2" :in-theory nil)
 
6259
             ("Goal" :use (eqtr3
 
6260
                           (:instance pars1iappend 
 
6261
                                      (l1 (rtm-eq-or (car l1) (car l2 ) tmp res))
 
6262
                                      (l2 (equality-trans2 (cdr l1) (cdr l2) tmp res)))
 
6263
                           (:instance cgr1 (l1 (cdr l1)) (l2 (cdr l2)))
 
6264
                           (:theorem (equal (pars1-instructions (rtm-eq-or (car l1) (car l2) tmp res)) (list tmp res)))
 
6265
                           (:instance equality-trans3 (listvars1 l1) (listvars2 l2))))))
 
6266
 
 
6267
 
 
6268
(defthm only-tmp-res-into-eqtr3 
 
6269
 (implies
 
6270
  (and
 
6271
   (not (equal v tmp))
 
6272
   (not (equal v res)))
 
6273
  (not (member-equal-bool v (eqtr3 l1 tmp res))))
 
6274
 :otf-flg t)
 
6275
 
 
6276
 
 
6277
 
 
6278
 
 
6279
 
 
6280
(defthm equality-trans3-has-par1-made-of-tmp-res
 
6281
  (implies
 
6282
   (and
 
6283
    (not (equal v tmp))
 
6284
    (not (equal v res))
 
6285
    (equal 
 
6286
     (listinstr st n)
 
6287
     (equality-trans3 l1 l2 tmp res)))
 
6288
  (not (member-equal-bool v (listpars1 st n))))
 
6289
:hints (("Goal" :in-theory nil
 
6290
         :use (pars1-instruction-is-listpars1
 
6291
               parsi-instructions-of-eq3-are-eqtr3
 
6292
               only-tmp-res-into-eqtr3))))
 
6293
 
 
6294
 
 
6295
 
 
6296
 
 
6297
 
 
6298
 
 
6299
 
 
6300
 
 
6301
(DEFUN LISTOPCODES (ST N)
 
6302
                    (IF (ZP N)
 
6303
                        NIL
 
6304
                        (CONS (OPCODE (NTH (PCC ST) (CODE ST)))
 
6305
                              (LISTOPCODES (EXECUTE-INSTRUCTION ST)
 
6306
                                         (1- N)))))
 
6307
(defun all-par1ops (opcodes)
 
6308
  (if (endp opcodes)
 
6309
      t
 
6310
    (and
 
6311
     (or
 
6312
      (equal (car opcodes) 'rtm-and)
 
6313
      (equal (car opcodes) 'rtm-or)
 
6314
      (equal (car opcodes) 'rtm-equ)
 
6315
      (equal (car opcodes) 'rtm-add)
 
6316
      (equal (car opcodes) 'rtm-sub))
 
6317
     (all-par1ops (cdr opcodes)))))
 
6318
 
 
6319
(defun all-par1opso (st n)
 
6320
  (declare (xargs :measure (acl2-count n)))
 
6321
  (if (zp n)
 
6322
      t
 
6323
    (and
 
6324
     (or
 
6325
      (null (NTH (PCC ST) (CODE ST)))
 
6326
      (equal  (OPCODE (NTH (PCC ST) (CODE ST))) 'rtm-and)
 
6327
      (equal  (OPCODE (NTH (PCC ST) (CODE ST))) 'rtm-or)
 
6328
      (equal  (OPCODE (NTH (PCC ST) (CODE ST))) 'rtm-equ)
 
6329
      (equal  (OPCODE (NTH (PCC ST) (CODE ST))) 'rtm-add)
 
6330
      (equal  (OPCODE (NTH (PCC ST) (CODE ST))) 'rtm-sub))
 
6331
     (all-par1opso (execute-instruction st) (1- n)))))
 
6332
 
 
6333
 
 
6334
 
 
6335
(defthm if-only-par1-involving-ops-are-there-then-other-vars-are-untouched
 
6336
 (implies
 
6337
  (and
 
6338
   (all-par1opso st n)
 
6339
   (not (member-equal-bool v (listpars1 st n))))
 
6340
  (equal (get-cell v (mem st)) (get-cell v (mem (execute-n-instructions st n)))))
 
6341
 :hints (("Goal" :in-theory (disable execute-instruction))
 
6342
         ("Subgoal *1/2" :use (:instance only-par1-is-involved-rtm
 
6343
                                         (gstate st)
 
6344
                                         (var v)))))
 
6345
 
 
6346
 
 
6347
 
 
6348
 
 
6349
(defun pars1-opcodes (listinstr)
 
6350
  (if (endp listinstr)
 
6351
      nil
 
6352
    (cons (opcode (car listinstr))
 
6353
          (pars1-opcodes (cdr listinstr)))))
 
6354
 
 
6355
(defthm pars1-opcodes-is-listopcodes 
 
6356
  (equal 
 
6357
   (pars1-opcodes (listinstr st n)) 
 
6358
   (listopcodes st n)))
 
6359
 
 
6360
(defun eqtr2o (l1)
 
6361
  (if
 
6362
      (endp l1)
 
6363
      nil
 
6364
    (append (list 'rtm-equ 'rtm-and) (eqtr2o (cdr l1)))))
 
6365
 
 
6366
(defun eqtr3o (l1)
 
6367
  (append (list 'rtm-equ 'rtm-or) (eqtr2o (cdr l1))))
 
6368
 
 
6369
(defthm cgr2 (equal (pars1-opcodes (equality-trans2 l1 l2 tmp res)) (eqtr2o l1)))
 
6370
 
 
6371
(defthm pars1oappend
 
6372
  (equal (pars1-opcodes (append l1 l2)) 
 
6373
         (append (pars1-opcodes l1) (pars1-opcodes l2))))
 
6374
 
 
6375
(defthm parsi-opcodes-of-eq3-are-eqtr3o
 
6376
  (equal (pars1-opcodes (equality-trans3 l1 l2 tmp res)) (eqtr3o l1))
 
6377
     :hints (("Subgoal 2" :in-theory nil)
 
6378
             ("Goal" :use (eqtr3o
 
6379
                           (:instance pars1oappend 
 
6380
                                      (l1 (rtm-eq-or (car l1) (car l2 ) tmp res))
 
6381
                                      (l2 (equality-trans2 (cdr l1) (cdr l2) tmp res)))
 
6382
                           (:instance cgr2 (l1 (cdr l1)) (l2 (cdr l2)))
 
6383
                           (:theorem (equal (pars1-opcodes (rtm-eq-or (car l1) (car l2) tmp res)) (list 'rtm-equ 'rtm-or)))
 
6384
                           (:instance equality-trans3 (listvars1 l1) (listvars2 l2))))))
 
6385
 
 
6386
 
 
6387
(defthm eqtr3o-makes-par1-instrs 
 
6388
  (all-par1ops (eqtr3o l))
 
6389
  :otf-flg t)
 
6390
 
 
6391
 
 
6392
 
 
6393
(defthm opcodes-on-par1-imply-instructions-on-par1 
 
6394
 (implies 
 
6395
  (all-par1ops (pars1-opcodes (listinstr st n)))
 
6396
  (all-par1opso st n)))
 
6397
 
 
6398
(defthm if-instructions-are-trans3-and-v-non-in-par1-v-untouched
 
6399
 (implies
 
6400
  (and
 
6401
   (equal (listinstr st n)
 
6402
          (equality-trans3 l1 l2 tmp res))
 
6403
   (not (member-equal-bool v (listpars1 st n))))
 
6404
  (equal 
 
6405
   (get-cell v (mem st)) 
 
6406
   (get-cell v (mem (execute-n-instructions st n)))))
 
6407
 :hints (("Goal"
 
6408
          :in-theory nil
 
6409
          :use 
 
6410
          (opcodes-on-par1-imply-instructions-on-par1
 
6411
           pars1-opcodes-is-listopcodes
 
6412
           parsi-opcodes-of-eq3-are-eqtr3o
 
6413
           (:instance eqtr3o-makes-par1-instrs (l l1))
 
6414
           if-only-par1-involving-ops-are-there-then-other-vars-are-untouched))))
 
6415
 
 
6416
 
 
6417
(defthm equality-trans3-means-touching-just-tmp-res
 
6418
  (implies
 
6419
   (and
 
6420
    (not (equal v tmp))
 
6421
    (not (equal v res))
 
6422
    (equal 
 
6423
     (listinstr st n)
 
6424
     (equality-trans3 l1 l2 tmp res)))
 
6425
  (equal 
 
6426
   (get-cell v (mem st)) 
 
6427
   (get-cell v (mem (execute-n-instructions st n)))))
 
6428
  :hints (("Goal" 
 
6429
           :use 
 
6430
           (if-instructions-are-trans3-and-v-non-in-par1-v-untouched
 
6431
            equality-trans3-has-par1-made-of-tmp-res))))
 
6432
 
 
6433
 
 
6434
 
 
6435
 
 
6436
 
 
6437
(in-theory (disable
 
6438
            pars1-instructions  pars1-instruction-is-listpars1 
 
6439
            eqtr2 eqtr3 cgr1 pars1iappend parsi-instructions-of-eq3-are-eqtr3
 
6440
            only-tmp-res-into-eqtr3 equality-trans3-has-par1-made-of-tmp-res
 
6441
            all-par1ops all-par1opso 
 
6442
            if-only-par1-involving-ops-are-there-then-other-vars-are-untouched
 
6443
            pars1-opcodes pars1-opcodes-is-listopcodes
 
6444
            eqtr2o eqtr3o cgr2 pars1oappend parsi-opcodes-of-eq3-are-eqtr3o
 
6445
            eqtr3o-makes-par1-instrs opcodes-on-par1-imply-instructions-on-par1
 
6446
            if-instructions-are-trans3-and-v-non-in-par1-v-untouched))
 
6447
            
 
6448
        
 
6449
 
 
6450
(defthm lemma2-only-adds-in-rtm-equ
 
6451
  (implies
 
6452
   (and
 
6453
    (gem-statep gstate)
 
6454
    (rtm-statep rstate)
 
6455
    (in-range (pcc gstate) (code gstate))
 
6456
    (in-range (pcc rstate) (code rstate))
 
6457
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-equ)
 
6458
    (good-translation-gem-rtm gstate rstate m))
 
6459
   (and
 
6460
    (equal (listinstr     rstate (* 2 (len *rns*)) ) 
 
6461
           (equality-trans3 
 
6462
            (eventually-make-list (rtmintvars-i (par2 (nth (pcc gstate) (code gstate))) m) (len *rns*))
 
6463
            (eventually-make-list (rtmintvars-i (par3 (nth (pcc gstate) (code gstate))) m) (len *rns*))
 
6464
            'tmp
 
6465
            (car (rtmintvars-i (par1 (nth (pcc gstate) (code gstate))) m))))
 
6466
    (not (equal 
 
6467
          (par1 (nth (pcc gstate) (code gstate)))
 
6468
          (par2 (nth (pcc gstate) (code gstate)))))
 
6469
    (not (equal 
 
6470
          (par1 (nth (pcc gstate) (code gstate)))
 
6471
          (par3 (nth (pcc gstate) (code gstate)))))))
 
6472
  :hints (("Goal" :expand 
 
6473
           ( (good-translation-gem-rtm gstate rstate m)
 
6474
             (gem-statep gstate)
 
6475
             (rtm-statep rstate)
 
6476
             (in-range (pcc gstate) (code gstate))
 
6477
             (in-range (pcc rstate) (code rstate)))
 
6478
           :in-theory nil))
 
6479
  :rule-classes nil)
 
6480
 
 
6481
 
 
6482
 
 
6483
(defthm lemma1-different-vars-do-not-belong-ref
 
6484
  (implies
 
6485
   (and
 
6486
    (true-listp m)
 
6487
    (not (endp (rtmintvars-i gvar2 m)))
 
6488
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
6489
    (assoc-equal gvar1 m)
 
6490
    (assoc-equal gvar2 m)
 
6491
    (not (equal gvar1 gvar2))
 
6492
    (in-range idx1 (rtmintvars-i gvar1 m)))
 
6493
  (not (equal (nth idx1 (rtmintvars-i gvar1 m))
 
6494
                     (car (rtmintvars-i gvar2 m)))))
 
6495
  :hints (("Goal" :in-theory nil
 
6496
           :use (lemma1-different-vars-do-not-belong
 
6497
                        (:instance member-equal-bool 
 
6498
                                   (el (nth idx1 (rtmintvars-i gvar1 m)))
 
6499
                                   (l (rtmintvars-i gvar2 m)))))))
 
6500
 
 
6501
(defun no-tmp-into-mapping (m)
 
6502
  (if (endp m)
 
6503
      t
 
6504
    (and
 
6505
     (not (member-equal-bool 'tmp (rtmintvars-0 m)))
 
6506
     (no-tmp-into-mapping (cdr m)))))
 
6507
 
 
6508
(defthm a-variable-is-never-tmp
 
6509
  (implies
 
6510
   (and
 
6511
    (no-tmp-into-mapping m)
 
6512
    (assoc-equal gvar1 m)
 
6513
    (in-range idx1 (rtmintvars-i gvar1 m)))
 
6514
   (not (equal (nth idx1 (rtmintvars-i gvar1 m)) 'tmp)))
 
6515
  :hints (("Goal" :in-theory (enable rtmintvars-0))))
 
6516
 
 
6517
 
 
6518
(defthm an-m-entry-is-never-nil
 
6519
 (implies
 
6520
  (and
 
6521
    (true-listp m)
 
6522
    (m-entries-point-to-good-rtm-var-sets m rtm-mem)
 
6523
    (assoc-equal var m))
 
6524
  (not (endp (rtmintvars-i var m))))
 
6525
 :hints (("Goal" :in-theory (enable rtmintvars-0))))
 
6526
 
 
6527
 
 
6528
(defthm rtm-variable-of-other-cell-untouched-equ
 
6529
  (implies
 
6530
   (and
 
6531
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-equ)
 
6532
    (>= (pcc rstate) 0)
 
6533
    (rtm-statep rstate)
 
6534
    (no-tmp-into-mapping m)
 
6535
    (m-entries-point-to-good-rtm-var-sets m (mem rstate))
 
6536
    (good-translation-gem-rtm gstate rstate m)
 
6537
    (in-range (pcc gstate) (code gstate))
 
6538
    (assoc-equal (par1 (nth (pcc gstate) (code gstate))) m)  
 
6539
    (true-listp m)
 
6540
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
6541
    (assoc-equal gvar1 m)
 
6542
    (not (equal gvar1 (par1 (nth (pcc gstate) (code gstate)))))
 
6543
    (in-range idx1 (rtmintvars-i gvar1 m)))
 
6544
   (equal (get-cell (nth idx1 (rtmintvars-i gvar1 m)) (mem rstate))
 
6545
          (get-cell (nth idx1 (rtmintvars-i gvar1 m)) (mem (execute-n-instructions rstate (* 2 (len *rns*)))))))
 
6546
  :hints (("Goal" :in-theory (current-theory 'ground-zero) 
 
6547
           :expand (     (in-range (pcc gstate) (code gstate))
 
6548
                         (good-translation-gem-rtm gstate rstate m) )
 
6549
           :use (
 
6550
                 (:instance a-variable-is-never-tmp (gvar1 gvar1))
 
6551
                 (:instance an-m-entry-is-never-nil 
 
6552
                            (rtm-mem (mem rstate))
 
6553
                            (var (par1 (nth (pcc gstate) (code gstate)))))
 
6554
                 (:instance equality-trans3-means-touching-just-tmp-res
 
6555
                            (v (nth idx1 (rtmintvars-i gvar1 m)))
 
6556
                            (l1 (eventually-make-list (rtmintvars-i (par2 (nth (pcc gstate) (code gstate))) m) (len *rns*)))
 
6557
                            (l2 (eventually-make-list (rtmintvars-i (par3 (nth (pcc gstate) (code gstate))) m) (len *rns*)))
 
6558
                            (st rstate)
 
6559
                            (tmp 'tmp)
 
6560
                            (res (car (rtmintvars-i (par1 (nth (pcc gstate) (code gstate))) m)))
 
6561
                            (n (* 2 (len *rns*))))
 
6562
                 (:instance lemma1-different-vars-do-not-belong-ref  (gvar2 (par1 (nth (pcc gstate) (code gstate)))))))))
 
6563
                 
 
6564
 
 
6565
 
 
6566
(defthm rtm-variables-of-other-cell-untouched-equ
 
6567
  (implies
 
6568
   (and
 
6569
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-equ)
 
6570
    (no-tmp-into-mapping m)
 
6571
    (m-entries-point-to-good-rtm-var-sets m (mem rstate))
 
6572
    (>= (pcc rstate) 0)
 
6573
    (rtm-statep rstate)
 
6574
    (good-translation-gem-rtm gstate rstate m)
 
6575
    (in-range (pcc gstate) (code gstate))
 
6576
    (assoc-equal (par1 (nth (pcc gstate) (code gstate))) m)   
 
6577
    (true-listp m)
 
6578
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
6579
    (assoc-equal gvar1 m)
 
6580
    (true-listp (rtmintvars-i gvar1 m))                         
 
6581
    (not (equal gvar1 (par1 (nth (pcc gstate) (code gstate))))))
 
6582
   (equal-get-cells
 
6583
          (rtmintvars-i gvar1 m) (mem rstate) (mem (execute-n-instructions rstate (* 2 (len *rns*))))))
 
6584
  :hints (("Goal" :in-theory nil
 
6585
           :use ( (:instance rtm-variable-of-other-cell-untouched-equ
 
6586
                             (idx1 (idx-different-cell 
 
6587
                                    (rtmintvars-i gvar1 m) 
 
6588
                                    (mem rstate) 
 
6589
                                    (mem (execute-n-instructions rstate (* 2 (len *rns*)))))) )))
 
6590
          ("Goal'" :cases ( (in-range
 
6591
                             (idx-different-cell 
 
6592
                                    (rtmintvars-i gvar1 m) 
 
6593
                                    (mem rstate) 
 
6594
                                    (mem (execute-n-instructions rstate (* 2 (len *rns*)))))
 
6595
                             (rtmintvars-i gvar1 m))))
 
6596
          ("Subgoal 2" :in-theory '((:rewrite if-bad-index-not-in-range-then-every-equal)))
 
6597
          ("Subgoal 1" :in-theory '((:forward-chaining if-bad-index-in-range-then-cells-must-be-different)))))
 
6598
 
 
6599
 
 
6600
 
 
6601
(defthm properies-of-type-and-existence-of-current-args-equ 
 
6602
 (implies
 
6603
  (and
 
6604
   (gem-statep gstate)
 
6605
   (in-range (pcc gstate) (code gstate))
 
6606
   (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-equ))
 
6607
  (and
 
6608
   (equal (var-type (get-cell (par1 (nth (pcc gstate) (code gstate))) (mem gstate))) 'Bool)
 
6609
   (assoc-equal (par1 (nth (pcc gstate) (code gstate))) (mem gstate))
 
6610
   (assoc-equal (par2 (nth (pcc gstate) (code gstate))) (mem gstate))
 
6611
   (assoc-equal (par3 (nth (pcc gstate) (code gstate))) (mem gstate))))
 
6612
  :hints (("Goal" :in-theory (enable get-cell)
 
6613
           :use (:instance in-range-instruction-is-gem-instruction 
 
6614
                           (pcc (pcc gstate)) 
 
6615
                           (code (code gstate))
 
6616
                           (mem (mem gstate)))))
 
6617
  :rule-classes nil)
 
6618
 
 
6619
 
 
6620
(defthm par1-of-current-instruction-is-into-mapping-equ 
 
6621
 (implies
 
6622
  (and
 
6623
   (vars-inclusion (mem gstate) m)
 
6624
   (gem-statep gstate)
 
6625
   (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-equ)  
 
6626
   (in-range (pcc gstate) (code gstate)))
 
6627
  (assoc-equal (par1 (nth (pcc gstate) (code gstate))) m))
 
6628
 :hints (("Goal" :in-theory (enable get-cell)
 
6629
         :use (properies-of-type-and-existence-of-current-args-equ
 
6630
               (:instance inclusion-trans 
 
6631
                          (v (par1 (nth (pcc gstate) (code gstate))))
 
6632
                          (m1 (mem gstate))
 
6633
                          (m2 m))
 
6634
               (:instance in-range-instruction-is-gem-instruction 
 
6635
                                 (pcc (pcc gstate)) 
 
6636
                                 (code (code gstate))
 
6637
                                 (mem (mem gstate)))))))
 
6638
 
 
6639
 
 
6640
 
 
6641
 
 
6642
(defthm teorema-main-con-pcc-in-range-su-variabile-non-interessata-final-equ
 
6643
 (implies
 
6644
  (and
 
6645
   (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-equ)
 
6646
   (no-tmp-into-mapping m)
 
6647
   (m-entries-point-to-good-rtm-var-sets m (mem rstate))
 
6648
   (good-translation-gem-rtm gstate rstate m)
 
6649
   (vars-inclusion (mem gstate) m)
 
6650
   (true-listp m)
 
6651
   (assoc-equal gvar1 m)
 
6652
   (gem-statep gstate)
 
6653
   (rtm-statep rstate)
 
6654
   (in-range (pcc gstate) (code gstate))
 
6655
   (in-range (pcc rstate) (code rstate))
 
6656
   (not (equal gvar1 (par1 (nth (pcc gstate) (code gstate)))))
 
6657
   (m-correspondent-values-p m (mem gstate) (mem rstate))
 
6658
   (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
6659
   (correct-wrt-arity m (mem gstate)))
 
6660
  (equal-values-and-attributes 
 
6661
   (get-cell gvar1 (mem (execute-instruction gstate)))
 
6662
   (rtmintvars-i gvar1 m)
 
6663
   (mem (execute-n-instructions rstate (* 2 (len *rns*))))
 
6664
   (type-i gvar1 m)))
 
6665
 :hints (("Goal"
 
6666
          :in-theory '((:definition good-translation-gem-rtm))
 
6667
          :use (
 
6668
                par1-of-current-instruction-is-into-mapping-equ
 
6669
                (:instance correct-wrt-arity-has-rtmintvars-i-tl (mem (mem gstate)))
 
6670
                (:instance m-correspondent-values-implies-equal-values-and-attribus
 
6671
                           (memgstate (mem gstate)) (memrstate (mem rstate)))
 
6672
                (:instance in-range (idx (pcc gstate)) (l (code gstate)))
 
6673
                (:instance in-range (idx (pcc rstate)) (l (code rstate)))
 
6674
                rtm-variables-of-other-cell-untouched-equ
 
6675
                teorema-main-con-pcc-in-range-su-variabile-non-interessata
 
6676
                (:instance equal-get-cells-implies-equal-values-and-attributes-still-works      
 
6677
                           (gemcell (get-cell gvar1 (mem gstate)))
 
6678
                           (lcell (rtmintvars-i gvar1 m))
 
6679
                           (mem1 (mem rstate))
 
6680
                           (mem2 (mem (execute-n-instructions rstate (* 2 (len *rns*)))))
 
6681
                           (type (type-i gvar1 m)))))))
 
6682
 
 
6683
 
 
6684
(defthm posinrg-equ
 
6685
  (implies
 
6686
   (and
 
6687
    (vars-inclusion (mem gstate) m)
 
6688
    (gem-statep gstate)
 
6689
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-equ) 
 
6690
    (in-range (pcc gstate) (code gstate)))
 
6691
    (and
 
6692
     (in-range (pos-equal-0 (par1 (nth (pcc gstate) (code gstate))) m) m)
 
6693
     (in-range (pos-equal-0 (par2 (nth (pcc gstate) (code gstate))) m) m)
 
6694
     (in-range (pos-equal-0 (par3 (nth (pcc gstate) (code gstate))) m) m)))
 
6695
   :hints (("Goal" :use (properies-of-type-and-existence-of-current-args-equ
 
6696
                        (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
6697
                                   (v (par1 (nth (pcc gstate) (code gstate)))))
 
6698
                        (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
6699
                                   (v (par2 (nth (pcc gstate) (code gstate)))))
 
6700
                        (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
6701
                                   (v (par3 (nth (pcc gstate) (code gstate)))))
 
6702
                        (:instance assoc-means-pos-in-range
 
6703
                                   (el (par1 (nth (pcc gstate) (code gstate))))
 
6704
                                   (l m))
 
6705
                        (:instance assoc-means-pos-in-range
 
6706
                                   (el (par2 (nth (pcc gstate) (code gstate))))
 
6707
                                   (l m))
 
6708
                        (:instance assoc-means-pos-in-range
 
6709
                                   (el (par3 (nth (pcc gstate) (code gstate))))
 
6710
                                   (l m)))))
 
6711
   :rule-classes nil)
 
6712
   
 
6713
   
 
6714
(defthm equal-eq-update-norest-afetr-one-instr
 
6715
  (implies
 
6716
   (and
 
6717
    (gem-statep gstate)
 
6718
    (in-range (pcc gstate) (code gstate))
 
6719
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-equ)
 
6720
    (good-translation-gem-rtm gstate rstate m)
 
6721
    (equal gvar1 (par1 (nth (pcc gstate) (code gstate))))
 
6722
    (equal gvar2 (par2 (nth (pcc gstate) (code gstate))))
 
6723
    (equal gvar3 (par3 (nth (pcc gstate) (code gstate)))))
 
6724
   (equal (get-cell gvar1 (mem (execute-instruction gstate)))
 
6725
          (gen-eq-update gvar1 gvar2 gvar3 (mem gstate))))
 
6726
  :hints (("Goal" :in-theory (e/d (put-cell get-cell) 
 
6727
                                  (par1 par2 par3 par4 opcode pcc code nth gem-instruction-list-p
 
6728
                                        gen-eq-update sum-and-update sub-and-update sub-and-update-norest sum-and-update-norest))))
 
6729
  :rule-classes nil)
 
6730
 
 
6731
(DEFTHM mem-cellity-of-current-gem-args-equ
 
6732
  (IMPLIES
 
6733
   (AND (GEM-STATEP GSTATE)
 
6734
        (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-equ) 
 
6735
        (IN-RANGE (PCC GSTATE) (CODE GSTATE)))
 
6736
   (AND (is-mem-cell-p (get-cell  (PAR1 (NTH (PCC GSTATE) (CODE GSTATE))) (mem gstate)))
 
6737
        (is-mem-cell-p (get-cell  (PAR2 (NTH (PCC GSTATE) (CODE GSTATE))) (mem gstate)))
 
6738
        (is-mem-cell-p (get-cell  (PAR3 (NTH (PCC GSTATE) (CODE GSTATE))) (mem gstate)))))
 
6739
  :HINTS
 
6740
  (("Goal" 
 
6741
    :USE
 
6742
    (:INSTANCE IN-RANGE-INSTRUCTION-IS-GEM-INSTRUCTION
 
6743
               (PCC (PCC GSTATE))
 
6744
               (CODE (CODE GSTATE))
 
6745
               (MEM (MEM GSTATE))))))
 
6746
 
 
6747
 
 
6748
    
 
6749
 
 
6750
(DEFTHM
 
6751
  VAR-ATTRIBUTES-OF-1-VARIABLE-IS-ONE-ELEMENT-LIST-OF-VAR-ATTRIBUTE
 
6752
  (IMPLIES (AND (TRUE-LISTP VARS)
 
6753
                (EQUAL (LEN VARS) 1))
 
6754
           (EQUAL (VAR-ATTRIBUTES VARS MEM)
 
6755
                  (LIST (VAR-ATTRIBUTE (GET-CELL (CAR VARS) MEM)))))
 
6756
  :HINTS
 
6757
  (("Subgoal *1/2.2"
 
6758
    :USE
 
6759
    (:THEOREM (IMPLIES (AND (TRUE-LISTP VARS)
 
6760
                            (EQUAL (LEN VARS) 1))
 
6761
                       (AND (EQUAL (LEN (CDR VARS)) 0)
 
6762
                            (TRUE-LISTP (CDR VARS))))))))
 
6763
 
 
6764
 
 
6765
(defthm equal-values-and-attributes-in-boolean-case
 
6766
 (implies
 
6767
  (equal (type-expected rtmvars) 'Bool)
 
6768
  (equal
 
6769
   (equal-values-and-attributes gcell rtmvars rtmmem 'Bool)
 
6770
   (and
 
6771
    (equal
 
6772
     (var-value (get-cell (car rtmvars) rtmmem))
 
6773
     (var-value gcell))
 
6774
    (equal
 
6775
     (var-attribute gcell)
 
6776
     (var-attribute (get-cell (car rtmvars) rtmmem)))))))
 
6777
 
 
6778
 
 
6779
 
 
6780
 
 
6781
 
 
6782
(defthm type-is-for-pars-equ
 
6783
 (implies
 
6784
   (and
 
6785
    (true-listp m)
 
6786
    (vars-inclusion (mem gstate) m)
 
6787
    (gem-statep gstate)
 
6788
    (correct-wrt-arity m (mem gstate))
 
6789
    (equal gvar1 (par1 (nth (pcc gstate) (code gstate))))
 
6790
    (equal gvar2 (par2 (nth (pcc gstate) (code gstate))))
 
6791
    (equal gvar3 (par3 (nth (pcc gstate) (code gstate))))
 
6792
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-equ) 
 
6793
    (in-range (pcc gstate) (code gstate)))
 
6794
   (equal (type-i gvar1 m) 'bool))
 
6795
 :hints (("Goal" 
 
6796
          :in-theory nil ;(current-theory 'ground-zero)
 
6797
          :use ( properies-of-type-and-existence-of-current-args-equ
 
6798
                 (:instance type-i-is-vartyper (gvar1 gvar1) (mem (mem gstate)))
 
6799
                 (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
6800
                            (v (par1 (nth (pcc gstate) (code gstate))))))))
 
6801
:rule-classes nil)
 
6802
 
 
6803
 
 
6804
 
 
6805
 
 
6806
 
 
6807
(defthm goal15
 
6808
(IMPLIES
 
6809
 (INTEGERP VAR-VALUE-GCELL2)
 
6810
 (EQUAL (BUILD-VALUES-BY-RNS-EXTENDED-FOR-NIL VAR-VALUE-GCELL2
 
6811
                                              '(11 13 15 17 19))
 
6812
        (LIST (MOD VAR-VALUE-GCELL2 11)
 
6813
              (MOD VAR-VALUE-GCELL2 13)
 
6814
              (MOD VAR-VALUE-GCELL2 15)
 
6815
              (MOD VAR-VALUE-GCELL2 17)
 
6816
              (MOD VAR-VALUE-GCELL2 19))))
 
6817
:hints (("Goal" :use ( 
 
6818
                      (:instance build-values-by-rns-extended-for-nil 
 
6819
                                 (gem-value VAR-VALUE-GCELL2)
 
6820
                                 (rns '(11 13 15 17 19)))
 
6821
                      (:instance build-values-by-rns-extended-for-nil 
 
6822
                                 (gem-value VAR-VALUE-GCELL2)
 
6823
                                 (rns '(13 15 17 19)))
 
6824
                      (:instance build-values-by-rns-extended-for-nil 
 
6825
                                 (gem-value VAR-VALUE-GCELL2)
 
6826
                                 (rns '(15 17 19)))
 
6827
                      (:instance build-values-by-rns-extended-for-nil 
 
6828
                                 (gem-value VAR-VALUE-GCELL2)
 
6829
                                 (rns '(17 19)))
 
6830
                      (:instance build-values-by-rns-extended-for-nil 
 
6831
                                 (gem-value VAR-VALUE-GCELL2)
 
6832
                                 (rns '(19)))
 
6833
                      (:instance build-values-by-rns-extended-for-nil 
 
6834
                                 (gem-value VAR-VALUE-GCELL2)
 
6835
                                 (rns nil)))))
 
6836
:rule-classes nil)
 
6837
 
 
6838
(defthm var-values-of-n-list
 
6839
 (equal 
 
6840
  (var-values (make-n-list gvar n) mem) 
 
6841
  (make-n-list (var-value (get-cell gvar mem)) n))
 
6842
 :rule-classes nil)
 
6843
 
 
6844
(defthm make-n-list-expansion-5 
 
6845
 (equal 
 
6846
  (make-n-list el 5) 
 
6847
  (list el el el el el))
 
6848
 :hints (("Goal" :use 
 
6849
          ( (:instance make-n-list (n 5))
 
6850
            (:instance make-n-list (n 4))
 
6851
            (:instance make-n-list (n 3))
 
6852
            (:instance make-n-list (n 2))
 
6853
            (:instance make-n-list (n 1))
 
6854
            (:instance make-n-list (n 0)) ) ))
 
6855
 :rule-classes nil)
 
6856
 
 
6857
 
 
6858
 
 
6859
(defthm subgoal41
 
6860
(IMPLIES 
 
6861
 (EQUAL (VAR-VALUE (GET-CELL RTMINTVARS-I-GVAR3 RTMMEM))
 
6862
                     1)
 
6863
         (EQUAL (VAR-VALUES (MAKE-N-LIST RTMINTVARS-I-GVAR3 5)
 
6864
                            RTMMEM)
 
6865
                '(1 1 1 1 1)))
 
6866
:hints (("Goal" :use ( (:instance make-n-list-expansion-5 (el (VAR-VALUE (GET-CELL RTMINTVARS-I-GVAR3 RTMMEM))))
 
6867
                       (:instance var-values-of-n-list 
 
6868
                                  (gvar RTMINTVARS-I-GVAR3)
 
6869
                                  (n 5)
 
6870
                                  (mem rtmmem)))))
 
6871
:rule-classes nil)
 
6872
 
 
6873
(defthm subgoal21
 
6874
(IMPLIES 
 
6875
 (EQUAL (VAR-VALUE (GET-CELL RTMINTVARS-I-GVAR3 RTMMEM))
 
6876
                     0)
 
6877
         (EQUAL (VAR-VALUES (MAKE-N-LIST RTMINTVARS-I-GVAR3 5)
 
6878
                            RTMMEM)
 
6879
                '(0 0 0 0 0)))
 
6880
:hints (("Goal" :use ( (:instance make-n-list-expansion-5 (el (VAR-VALUE (GET-CELL RTMINTVARS-I-GVAR3 RTMMEM))))
 
6881
                       (:instance var-values-of-n-list 
 
6882
                                  (gvar RTMINTVARS-I-GVAR3)
 
6883
                                  (n 5)
 
6884
                                  (mem rtmmem)))))
 
6885
:rule-classes nil)
 
6886
 
 
6887
 
 
6888
 
 
6889
(defthm var-values-of-evmakelist-is-rns-anyway
 
6890
 (implies
 
6891
  (and
 
6892
   (is-mem-cell-p gcell2)
 
6893
   (equal (type-expected rtmintvars-i-gvar2) (var-type gcell2))
 
6894
   (equal-values-and-attributes gcell2 rtmintvars-i-gvar2 rtmmem (var-type gcell2)))
 
6895
  (equal 
 
6896
   (var-values (eventually-make-list rtmintvars-i-gvar2 (len *rns*)) rtmmem)
 
6897
   (build-values-by-rns (var-value gcell2) *rns*)))
 
6898
 :hints (("Goal" :in-theory (enable my-or-2))
 
6899
         ("Subgoal 5'''" :use (:instance goal15 (var-value-gcell2 (var-value gcell2))))
 
6900
; fcd/Satriani v3.7 Moore - used to Subgoal 4.1
 
6901
         ("Subgoal 1.1" :use subgoal41)
 
6902
; fcd/Satriani v3.7 Moore - used to Subgoal 2.1
 
6903
         ("Subgoal 3.1" :use subgoal21)))
 
6904
 
 
6905
 
 
6906
 
 
6907
(defthm ax-on-rns-values
 
6908
  (implies
 
6909
   (and
 
6910
    (natp gval1)
 
6911
    (< gval1 (prod *rns*))
 
6912
    (natp gval2)
 
6913
    (< gval2 (prod *rns*))
 
6914
    (not (equal gval1 gval2)))
 
6915
   (not (equal (build-values-by-rns gval1 *rns*) (build-values-by-rns gval2 *rns*))))
 
6916
  :hints (("Goal" :use ( fact-bout-rns
 
6917
                         (:instance crt-inversion (val gval1) (rns *rns*))
 
6918
                         (:instance crt-inversion (val gval2) (rns *rns*))))))
 
6919
 
 
6920
(defthm hlp1 
 
6921
  (implies
 
6922
   (and
 
6923
    (is-mem-cell-p cell)
 
6924
    (bounded-value cell))
 
6925
   (and
 
6926
    (natp (var-value cell))
 
6927
    (< (var-value cell) (prod *rns*))))
 
6928
  :rule-classes nil)
 
6929
 
 
6930
(defthm equal-equality-of-var-values-euqlity-of-evlists
 
6931
 (implies
 
6932
  (and
 
6933
   (is-mem-cell-p gcell2)
 
6934
   (is-mem-cell-p gcell3)
 
6935
   (bounded-value gcell2)
 
6936
   (bounded-value gcell3)
 
6937
   (equal (type-expected rtmintvars-i-gvar2) (var-type gcell2))
 
6938
   (equal (type-expected rtmintvars-i-gvar3) (var-type gcell3))
 
6939
   (equal-values-and-attributes gcell2 rtmintvars-i-gvar2 rtmmem (var-type gcell2))
 
6940
   (equal-values-and-attributes gcell3 rtmintvars-i-gvar3 rtmmem (var-type gcell3)))
 
6941
 (equal
 
6942
  (equal
 
6943
   (var-value gcell2) 
 
6944
   (var-value gcell3) )
 
6945
  (equal
 
6946
   (var-values (eventually-make-list rtmintvars-i-gvar2  (len *rns*)) rtmmem)
 
6947
   (var-values (eventually-make-list rtmintvars-i-gvar3  (len *rns*)) rtmmem))))
 
6948
 :hints (("Goal" 
 
6949
          :in-theory nil 
 
6950
          :use
 
6951
          ( (:instance hlp1 (cell gcell2))
 
6952
            (:instance hlp1 (cell gcell3))
 
6953
            (:instance ax-on-rns-values
 
6954
                       (gval1 (var-value gcell2))
 
6955
                       (gval2 (var-value gcell3)))
 
6956
            (:instance var-values-of-evmakelist-is-rns-anyway 
 
6957
                       (gcell2 gcell2)
 
6958
                       (rtmintvars-i-gvar2 rtmintvars-i-gvar2))
 
6959
            (:instance var-values-of-evmakelist-is-rns-anyway 
 
6960
                       (gcell2 gcell3)
 
6961
                       (rtmintvars-i-gvar2 rtmintvars-i-gvar3))))))
 
6962
 
 
6963
(in-theory (disable ax-on-rns-values))
 
6964
 
 
6965
              
 
6966
 
 
6967
 
 
6968
 
 
6969
(defthm length-of-makelist-n
 
6970
 (implies
 
6971
  (and
 
6972
   (integerp n)
 
6973
   (>= n 0))
 
6974
  (equal (len (make-n-list l n)) n)))
 
6975
 
 
6976
(defthm if-type-exepcted-is-ok-eventually-always-has-len-of-rns
 
6977
 (implies
 
6978
  (my-or-2
 
6979
   (equal (type-expected l) 'Bool)
 
6980
   (equal (type-expected l) 'Int))
 
6981
  (equal (len (eventually-make-list l (len *rns*))) (len *rns*))))
 
6982
 
 
6983
(defthm tmp-never-appears
 
6984
  (implies
 
6985
   (and
 
6986
    (no-tmp-into-mapping m)
 
6987
    (assoc-equal gvar1 m))
 
6988
   (not (member-equal-bool 'tmp (eventually-make-list (rtmintvars-i gvar1 m) n))))
 
6989
  :hints (("Goal" :in-theory (enable rtmintvars-0))))
 
6990
 
 
6991
(defthm tmp-never-appears-simple
 
6992
  (implies
 
6993
   (and
 
6994
    (no-tmp-into-mapping m)
 
6995
    (assoc-equal gvar1 m))
 
6996
   (not (member-equal-bool 'tmp (rtmintvars-i gvar1 m) )))
 
6997
  :hints (("Goal" :in-theory (enable rtmintvars-0))))
 
6998
 
 
6999
(defthm type-of-a-mem-cell 
 
7000
  (implies
 
7001
   (is-mem-cell-p cell)
 
7002
   (my-or-2
 
7003
    (equal (var-type cell) 'Bool)
 
7004
    (equal (var-type cell) 'Int)))
 
7005
  :hints (("Goal" :in-theory (enable my-or-2)))
 
7006
  :rule-classes nil)
 
7007
 
 
7008
 
 
7009
(defthm sillllly  
 
7010
 (equal (make-n-list l1 1) (list l1))
 
7011
 :hints (("Goal" :use (:instance make-n-list (el l1) (n 1))))
 
7012
 :rule-classes nil)
 
7013
 
 
7014
; Added by Matt K. for v3-5.  Heuristic changes to linear arithmetic were
 
7015
; preventing the next lemma, not-member-equal-bool-holds-on-ev, from going
 
7016
; through.  But the original proof involved generalization and three levels of
 
7017
; induction, so rather than investigate further, we'll just prove the following
 
7018
; lemma.  With it, the proof of not-member-equal-bool-holds-on-ev goes through
 
7019
; without :hints.
 
7020
(local
 
7021
 (defthm helper-from-matt-k
 
7022
   (implies (not (equal el l1))
 
7023
            (not (member-equal-bool el (make-n-list l1 n))))))
 
7024
 
 
7025
(defthm not-member-equal-bool-holds-on-ev
 
7026
 (implies
 
7027
  (and
 
7028
   (integerp n)
 
7029
   (> n 0)
 
7030
   (not (member-equal-bool el l)))
 
7031
  (not (member-equal-bool el (eventually-make-list l n))))
 
7032
 :hints (("Subgoal *1.1/4''" :use sillllly) ; Modified for v2-6 by Matt K.
 
7033
         ("Subgoal *1.1/4.1"  :use sillllly))
 
7034
 :rule-classes nil) 
 
7035
 
 
7036
(defthm not-memb-1
 
7037
 (implies
 
7038
  (and
 
7039
   (true-listp m)
 
7040
   (equal (len (rtmintvars-i gvar1 m)) 1) 
 
7041
   (assoc-equal gvar1 m)
 
7042
   (assoc-equal gvar2 m)
 
7043
   (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
7044
   (not (equal gvar1 gvar2)))
 
7045
  (not (member-equal-bool 
 
7046
        (car (rtmintvars-i gvar1 m))
 
7047
        (rtmintvars-i gvar2 m))))
 
7048
 :hints (("Goal" 
 
7049
          :use ( (:instance lemma1-different-vars-do-not-belong (idx1 0)))))
 
7050
 :rule-classes nil)
 
7051
 
 
7052
(defthm not-memb-2
 
7053
 (implies
 
7054
  (and
 
7055
   (true-listp m)
 
7056
   (equal (len (rtmintvars-i gvar1 m)) 1) 
 
7057
   (assoc-equal gvar1 m)
 
7058
   (assoc-equal gvar2 m)
 
7059
   (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
7060
   (not (equal gvar1 gvar2)))
 
7061
  (not (member-equal-bool 
 
7062
        (car (rtmintvars-i gvar1 m))
 
7063
        (eventually-make-list (rtmintvars-i gvar2 m) (len *rns*)))))
 
7064
 :hints (("Goal" 
 
7065
          :use ( not-memb-1
 
7066
                 (:instance not-member-equal-bool-holds-on-ev 
 
7067
                            (el (car (rtmintvars-i gvar1 m)))
 
7068
                            (l (rtmintvars-i gvar2 m))
 
7069
                            (n (len *rns*))))))
 
7070
 :rule-classes nil)
 
7071
 
 
7072
 
 
7073
(defthm eq-and-update-behaviour
 
7074
  (and
 
7075
   (equal
 
7076
    (var-value (gen-eq-update c1 c2 c3 mem)) 
 
7077
    (boolean-to-int (equal
 
7078
                     (var-value (get-cell c2 mem))
 
7079
                     (var-value (get-cell c3 mem)))))
 
7080
   (equal
 
7081
    (var-attribute (gen-eq-update c1 c2 c3 mem)) 
 
7082
    (var-attribute (get-cell c1 mem))))
 
7083
  :hints (("Goal" :in-theory (enable var-value var-attribute))))
 
7084
  
 
7085
 
 
7086
(defthm var-attribute-of-a-var-is-same-after-n-steps
 
7087
 (implies
 
7088
  (rtm-statep st)
 
7089
  (equal (var-attribute (get-cell anyvar (mem st)))
 
7090
         (var-attribute (get-cell anyvar (mem (execute-n-instructions st n))))))
 
7091
 :hints (("Goal" 
 
7092
          :induct (execute-n-instructions st n)
 
7093
          :in-theory (disable rtm-statep execute-instruction))
 
7094
         ("Subgoal *1/2" 
 
7095
          :use
 
7096
          (
 
7097
           (:instance execute-instruction-is-type-and-attribute-invariant-on-any-var (cell anyvar))
 
7098
           executing-rtm-instruction-retrieves-a-rtm-state-from-rtm-state))))
 
7099
 
 
7100
 
 
7101
(defthm bool-to-int-strip
 
7102
 (iff
 
7103
  (equal (boolean-to-int (equal a b)) (boolean-to-int (equal-values c d)))
 
7104
  (equal (equal a b) (equal c d))))
 
7105
 
 
7106
 
 
7107
(defthm equal-equality-of-var-values-euqlity-of-evlists-2
 
7108
 (implies
 
7109
  (and
 
7110
   (is-mem-cell-p gcell2)
 
7111
   (is-mem-cell-p gcell3)
 
7112
   (bounded-value gcell2)
 
7113
   (bounded-value gcell3)
 
7114
   (equal (type-expected rtmintvars-i-gvar2) (var-type gcell2))
 
7115
   (equal (type-expected rtmintvars-i-gvar3) (var-type gcell3))
 
7116
   (equal-values-and-attributes gcell2 rtmintvars-i-gvar2 rtmmem (var-type gcell2))
 
7117
   (equal-values-and-attributes gcell3 rtmintvars-i-gvar3 rtmmem (var-type gcell3)))
 
7118
 (equal
 
7119
  (boolean-to-int
 
7120
   (equal
 
7121
    (var-value gcell2) 
 
7122
    (var-value gcell3) ))
 
7123
  (boolean-to-int
 
7124
   (equal-values
 
7125
    (var-values (eventually-make-list rtmintvars-i-gvar2  (len *rns*)) rtmmem)
 
7126
    (var-values (eventually-make-list rtmintvars-i-gvar3  (len *rns*)) rtmmem)))))
 
7127
 :hints (("Goal" 
 
7128
          :in-theory nil
 
7129
          :use 
 
7130
          ((:instance bool-to-int-strip 
 
7131
                     (a (var-value gcell2)) 
 
7132
                     (b (var-value gcell3))
 
7133
                     (c (var-values (eventually-make-list rtmintvars-i-gvar2  (len *rns*)) rtmmem))
 
7134
                     (d (var-values (eventually-make-list rtmintvars-i-gvar3  (len *rns*)) rtmmem)))
 
7135
                     equal-equality-of-var-values-euqlity-of-evlists))))
 
7136
 
 
7137
 
 
7138
 
 
7139
(defthm sil-support-2
 
7140
 (implies
 
7141
  (and
 
7142
   (integerp n)
 
7143
   (> n 0)
 
7144
   (or
 
7145
    (equal (type-expected l) 'Bool)
 
7146
    (equal (type-expected l) 'Int)))
 
7147
   (not (endp (eventually-make-list l n))))
 
7148
 :hints (("Subgoal *1.1/3'" :use sillllly))
 
7149
 :otf-flg t)
 
7150
 
 
7151
(defthm sil-support-3
 
7152
 (implies
 
7153
  (my-or-2
 
7154
   (equal (type-expected l) 'Bool)
 
7155
   (equal (type-expected l) 'Int))
 
7156
   (not (endp (eventually-make-list l (len *rns*)))))
 
7157
 :hints (("Goal" :use (:instance sil-support-2 (n (len *rns*))))))
 
7158
 
 
7159
 
 
7160
(defthm not-in-car-if-no-memb
 
7161
 (implies
 
7162
  (and
 
7163
   (equal (len l) 1)
 
7164
   (not (member-equal-bool 'tmp l)))
 
7165
  (not (equal 'tmp (car l)))))
 
7166
 
 
7167
(defthm sil-support-1
 
7168
 (implies 
 
7169
  (equal (type-i gvar1 m) 'bool)
 
7170
  (equal  (LEN (RTMINTVARS-I gvar1 m)) 1)))
 
7171
 
 
7172
 
 
7173
(defthm bounded-are-bounded
 
7174
 (implies
 
7175
  (and
 
7176
   (bounded-amem-p mem)
 
7177
   (assoc-equal cell mem))
 
7178
  (bounded-value (get-cell cell mem)))
 
7179
 :hints (("Goal" :in-theory (enable get-cell)))
 
7180
 :rule-classes nil)
 
7181
 
 
7182
 
 
7183
 
 
7184
 
 
7185
(defthm m-correspondence-kept-on-same-gvar-equ
 
7186
 (implies
 
7187
  (and
 
7188
    (NOT (ENDP (EVENTUALLY-MAKE-LIST
 
7189
                    (RTMINTVARS-I (PAR2 (NTH (PCC GSTATE) (CODE GSTATE)))
 
7190
                                  M)
 
7191
                    (LEN '(11 13 15 17 19)))))
 
7192
    (NOT (EQUAL 'TMP
 
7193
                (CAR (RTMINTVARS-I (PAR1 (NTH (PCC GSTATE) (CODE GSTATE))) 
 
7194
                                   M))))
 
7195
    (EQUAL (LEN (RTMINTVARS-I (PAR1 (NTH (PCC GSTATE) (CODE GSTATE))) M)) 1)
 
7196
   (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-equ)
 
7197
   (no-tmp-into-mapping m)
 
7198
   (good-translation-gem-rtm gstate rstate m)
 
7199
   (vars-inclusion (mem gstate) m)
 
7200
   (true-listp m)
 
7201
   (assoc-equal gvar1 m)
 
7202
   (gem-statep gstate)
 
7203
   (rtm-statep rstate)
 
7204
   (in-range (pcc gstate) (code gstate))
 
7205
   (in-range (pcc rstate) (code rstate))
 
7206
   (equal gvar1 (par1 (nth (pcc gstate) (code gstate))))
 
7207
   (m-correspondent-values-p m (mem gstate) (mem rstate))
 
7208
   (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
7209
   (correct-wrt-arity m (mem gstate)))
 
7210
  (equal-values-and-attributes 
 
7211
   (get-cell gvar1 (mem (execute-instruction gstate)))
 
7212
   (rtmintvars-i gvar1 m)
 
7213
   (mem (execute-n-instructions rstate (* 2 (len *rns*))))
 
7214
   (type-i gvar1 m)))
 
7215
 :hints (("Goal" :in-theory nil
 
7216
          :use ( 
 
7217
                (:instance gem-statep (x gstate))
 
7218
                (:instance bounded-are-bounded (cell (par2 (nth (pcc gstate) (code gstate)))) (mem (mem gstate)))
 
7219
                (:instance bounded-are-bounded (cell (par3 (nth (pcc gstate) (code gstate)))) (mem (mem gstate)))
 
7220
                (:instance  eq-and-update-behaviour
 
7221
                            (c1 gvar1)
 
7222
                            (c2 (par2 (nth (pcc gstate) (code gstate))))
 
7223
                            (c3 (par3 (nth (pcc gstate) (code gstate))))
 
7224
                            (mem (mem gstate)))
 
7225
                (:instance var-attribute-of-a-var-is-same-after-n-steps
 
7226
                            (st rstate)
 
7227
                            (anyvar (car  (rtmintvars-i (par1 (nth (pcc gstate) (code gstate))) m)))
 
7228
                            (n (* 2 (len *rns*))))
 
7229
                 (:instance in-range (idx (pcc gstate)) (l (code gstate))) 
 
7230
                 (:instance not-memb-2 
 
7231
                            (gvar1 (par1 (nth (pcc gstate) (code gstate))))
 
7232
                            (gvar2 (par2 (nth (pcc gstate) (code gstate)))))
 
7233
                 (:instance not-memb-2 
 
7234
                            (gvar1 (par1 (nth (pcc gstate) (code gstate))))
 
7235
                            (gvar2 (par3 (nth (pcc gstate) (code gstate)))))
 
7236
                 (:instance type-of-a-mem-cell (cell (get-cell (par2 (nth (pcc gstate) (code gstate))) (mem gstate))))
 
7237
                 (:instance type-of-a-mem-cell (cell (get-cell (par3 (nth (pcc gstate) (code gstate))) (mem gstate))))
 
7238
                 properies-of-type-and-existence-of-current-args-equ
 
7239
                 mem-cellity-of-current-gem-args-equ
 
7240
                 good-translation-gem-rtm 
 
7241
                 (:instance tmp-never-appears (n (len *rns*)) (gvar1 (par2 (nth (pcc gstate) (code gstate)))))
 
7242
                 (:instance tmp-never-appears (n (len *rns*)) (gvar1 (par3 (nth (pcc gstate) (code gstate)))))
 
7243
                 (:instance if-type-exepcted-is-ok-eventually-always-has-len-of-rns
 
7244
                            (l (rtmintvars-i (par2 (nth (pcc gstate) (code gstate))) m)))
 
7245
                 (:instance if-type-exepcted-is-ok-eventually-always-has-len-of-rns
 
7246
                            (l (rtmintvars-i (par3 (nth (pcc gstate) (code gstate))) m)))
 
7247
                 (:instance type-i-is-vartyper (gvar1 gvar1) (mem (mem gstate)))
 
7248
                 (:instance type-i-is-vartyper (gvar1 (par2 (nth (pcc gstate) (code gstate)))) (mem (mem gstate)))
 
7249
                 (:instance type-i-is-vartyper (gvar1 (par3 (nth (pcc gstate) (code gstate)))) (mem (mem gstate)))
 
7250
                 (:instance type-i-is-type-expected (gvar  gvar1) (mem (mem gstate)))
 
7251
                 (:instance type-i-is-type-expected (gvar  (par2 (nth (pcc gstate) (code gstate)))) (mem (mem gstate)))
 
7252
                 (:instance type-i-is-type-expected (gvar  (par3 (nth (pcc gstate) (code gstate)))) (mem (mem gstate)))
 
7253
                 (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
7254
                            (v (par1 (nth (pcc gstate) (code gstate)))))
 
7255
                 (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
7256
                            (v (par2 (nth (pcc gstate) (code gstate)))))
 
7257
                 (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
7258
                            (v (par3 (nth (pcc gstate) (code gstate)))))
 
7259
                  (:instance
 
7260
                   equal-eq-update-norest-afetr-one-instr
 
7261
                   (gvar2 (par2 (nth (pcc gstate) (code gstate))))
 
7262
                   (gvar3 (par3 (nth (pcc gstate) (code gstate))))
 
7263
                   )
 
7264
                  (:instance type-is-for-pars-equ
 
7265
                   (gvar2 (par2 (nth (pcc gstate) (code gstate))))
 
7266
                   (gvar3 (par3 (nth (pcc gstate) (code gstate)))))
 
7267
                  (:instance equal-values-and-attributes-in-boolean-case
 
7268
                             (rtmvars (rtmintvars-i gvar1 m))
 
7269
                             (gcell (get-cell gvar1 (mem gstate)))
 
7270
                             (rtmmem (mem rstate)))
 
7271
                  (:instance equal-values-and-attributes-in-boolean-case
 
7272
                             (rtmvars (rtmintvars-i gvar1 m))
 
7273
                             (gcell (get-cell gvar1 (mem (execute-instruction gstate))))
 
7274
                             (rtmmem (mem (execute-n-instructions rstate (* 2 (len *rns*))))))
 
7275
                  (:instance m-correspondent-values-implies-equal-values-and-attribus
 
7276
                             (memgstate (mem gstate)) (memrstate (mem rstate)) 
 
7277
                             (gvar1 (par1 (nth (pcc gstate) (code gstate)))))
 
7278
                  (:instance m-correspondent-values-implies-equal-values-and-attribus
 
7279
                             (memgstate (mem gstate)) (memrstate (mem rstate)) 
 
7280
                             (gvar1 (par2 (nth (pcc gstate) (code gstate)))))
 
7281
                  (:instance m-correspondent-values-implies-equal-values-and-attribus
 
7282
                             (memgstate (mem gstate)) (memrstate (mem rstate)) 
 
7283
                             (gvar1 (par3 (nth (pcc gstate) (code gstate)))))
 
7284
                  (:instance value-of-result-after-executing-2n-+2instr-finale
 
7285
                             (tmp 'tmp)
 
7286
                             (res (car  (rtmintvars-i (par1 (nth (pcc gstate) (code gstate))) m)))
 
7287
                             (listvars1 (eventually-make-list (rtmintvars-i (par2 (nth (pcc gstate) (code gstate))) m) (len *rns*)))
 
7288
                             (listvars2 (eventually-make-list (rtmintvars-i (par3 (nth (pcc gstate) (code gstate))) m) (len *rns*)))
 
7289
                             (st rstate))
 
7290
                  (:instance equal-equality-of-var-values-euqlity-of-evlists-2
 
7291
                             (gcell2 (get-cell (par2 (nth (pcc gstate) (code gstate))) (mem gstate)))
 
7292
                             (gcell3 (get-cell (par3 (nth (pcc gstate) (code gstate))) (mem gstate)))
 
7293
                             (rtmintvars-i-gvar2 (rtmintvars-i (par2 (nth (pcc gstate) (code gstate))) m))
 
7294
                             (rtmintvars-i-gvar3 (rtmintvars-i (par3 (nth (pcc gstate) (code gstate))) m))
 
7295
                             (rtmmem (mem rstate)))))))
 
7296
 
 
7297
 
 
7298
(defthm m-correspondence-kept-on-same-gvar-equ-supp
 
7299
 (implies
 
7300
  (and
 
7301
   (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-equ)
 
7302
   (no-tmp-into-mapping m)
 
7303
   (equal gvar1 (par1 (nth (pcc gstate) (code gstate))))
 
7304
   (assoc-equal gvar1 m)
 
7305
   (vars-inclusion (mem gstate) m)
 
7306
   (true-listp m)
 
7307
   (gem-statep gstate)
 
7308
   (rtm-statep rstate)
 
7309
   (in-range (pcc gstate) (code gstate))
 
7310
   (in-range (pcc rstate) (code rstate))
 
7311
   (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
7312
   (correct-wrt-arity m (mem gstate)))
 
7313
  (and
 
7314
   (NOT (ENDP (EVENTUALLY-MAKE-LIST
 
7315
               (RTMINTVARS-I (PAR2 (NTH (PCC GSTATE) (CODE GSTATE)))
 
7316
                             M)
 
7317
               (LEN '(11 13 15 17 19)))))
 
7318
   (NOT (EQUAL 'TMP
 
7319
             (CAR (RTMINTVARS-I (PAR1 (NTH (PCC GSTATE) (CODE GSTATE))) 
 
7320
                                  M))))
 
7321
   (EQUAL (LEN (RTMINTVARS-I (PAR1 (NTH (PCC GSTATE) (CODE GSTATE))) M)) 1)))
 
7322
 :hints (("Goal" :in-theory  nil 
 
7323
          :use ( 
 
7324
                (:instance sil-support-3 (l (RTMINTVARS-I (PAR2 (NTH (PCC GSTATE) (CODE GSTATE))) M) ))
 
7325
                (:instance not-in-car-if-no-memb (l (RTMINTVARS-I (PAR1 (NTH (PCC GSTATE) (CODE GSTATE))) m)))
 
7326
                (:instance sil-support-1 (gvar1 (PAR1 (NTH (PCC GSTATE) (CODE GSTATE)))))
 
7327
                (:instance in-range (idx (pcc gstate)) (l (code gstate))) 
 
7328
                (:instance type-of-a-mem-cell (cell (get-cell (par2 (nth (pcc gstate) (code gstate))) (mem gstate))))
 
7329
                (:instance type-of-a-mem-cell (cell (get-cell (par3 (nth (pcc gstate) (code gstate))) (mem gstate))))
 
7330
                (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
7331
                           (v (par1 (nth (pcc gstate) (code gstate)))))
 
7332
                (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
7333
                            (v (par2 (nth (pcc gstate) (code gstate)))))
 
7334
                (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
7335
                           (v (par3 (nth (pcc gstate) (code gstate)))))
 
7336
                 properies-of-type-and-existence-of-current-args-equ
 
7337
                 mem-cellity-of-current-gem-args-equ
 
7338
                 (:instance tmp-never-appears-simple  (gvar1 (par1 (nth (pcc gstate) (code gstate)))))
 
7339
                 (:instance type-i-is-vartyper (gvar1 gvar1) (mem (mem gstate)))
 
7340
                 (:instance type-i-is-vartyper (gvar1 (par2 (nth (pcc gstate) (code gstate)))) (mem (mem gstate)))
 
7341
                 (:instance type-i-is-vartyper (gvar1 (par3 (nth (pcc gstate) (code gstate)))) (mem (mem gstate)))
 
7342
                 (:instance type-i-is-type-expected (gvar  gvar1) (mem (mem gstate)))
 
7343
                 (:instance type-i-is-type-expected (gvar  (par2 (nth (pcc gstate) (code gstate)))) (mem (mem gstate)))
 
7344
                 (:instance type-i-is-type-expected (gvar  (par3 (nth (pcc gstate) (code gstate)))) (mem (mem gstate)))
 
7345
                 (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
7346
                            (v (par1 (nth (pcc gstate) (code gstate)))))
 
7347
                 (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
7348
                            (v (par2 (nth (pcc gstate) (code gstate)))))
 
7349
                 (:instance inclusion-trans (m1 (mem gstate)) (m2 m)
 
7350
                            (v (par3 (nth (pcc gstate) (code gstate)))))
 
7351
                 (:instance type-is-for-pars-equ
 
7352
                            (gvar2 (par2 (nth (pcc gstate) (code gstate))))
 
7353
                            (gvar3 (par3 (nth (pcc gstate) (code gstate)))))))))
 
7354
 
 
7355
 
 
7356
 
 
7357
(defthm equal-values-correspondence-kept-by-any-execution-equ
 
7358
  (implies
 
7359
   (and
 
7360
   (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-equ)
 
7361
   (no-tmp-into-mapping m)
 
7362
   (good-translation-gem-rtm gstate rstate m)
 
7363
   (vars-inclusion (mem gstate) m)
 
7364
   (true-listp m)
 
7365
   (assoc-equal gvar1 m)
 
7366
   (gem-statep gstate)
 
7367
   (rtm-statep rstate)
 
7368
   (in-range (pcc gstate) (code gstate))
 
7369
   (in-range (pcc rstate) (code rstate))
 
7370
   (m-correspondent-values-p m (mem gstate) (mem rstate))
 
7371
   (M-ENTRIES-POINT-TO-GOOD-RTM-VAR-SETS M (MEM RSTATE))
 
7372
   (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
7373
   (correct-wrt-arity m (mem gstate)))
 
7374
  (equal-values-and-attributes 
 
7375
   (get-cell gvar1 (mem (execute-instruction gstate)))
 
7376
   (rtmintvars-i gvar1 m)
 
7377
   (mem (execute-n-instructions rstate (* 2 (len *rns*))))
 
7378
   (type-i gvar1 m)))
 
7379
  :hints (("Goal" :in-theory nil
 
7380
           :use (m-correspondence-kept-on-same-gvar-equ
 
7381
                 m-correspondence-kept-on-same-gvar-equ-supp
 
7382
                 teorema-main-con-pcc-in-range-su-variabile-non-interessata-final-equ))))
 
7383
 
 
7384
 
 
7385
(defthm rtmintvars-i-iscdrnth
 
7386
 (implies
 
7387
  (and
 
7388
   (true-listp m)
 
7389
   (in-range idx m)
 
7390
   (no-duplicates-p (retrieve-gemvars m)))
 
7391
  (equal (rtmintvars-i (car (nth idx m)) m)
 
7392
         (cdr (nth idx m))))
 
7393
 :hints (("Goal" 
 
7394
          :in-theory nil
 
7395
          :use (
 
7396
          (:instance no-duplicates-has-pos-equal-right-in-that-place (l m))
 
7397
          (:instance  rtmintvars-i-is-cdr-of-nth-entry (gvar (car (nth idx m))))))))
 
7398
 
 
7399
(defthm type-i-is-typeidx
 
7400
 (implies
 
7401
  (and
 
7402
   (true-listp m)
 
7403
   (in-range idx m)
 
7404
   (no-duplicates-p (retrieve-gemvars m)))
 
7405
  (equal (type-i (car (nth idx m)) m) 
 
7406
         (type-i-idx m idx))))
 
7407
 
 
7408
 
 
7409
 
 
7410
(defthm equal-values-correspondence-kept-by-any-execution-idxed-equ
 
7411
  (implies
 
7412
   (and
 
7413
   (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-equ)
 
7414
   (no-tmp-into-mapping m)
 
7415
   (good-translation-gem-rtm gstate rstate m)
 
7416
   (vars-inclusion (mem gstate) m)
 
7417
   (alistp m)
 
7418
   (in-range idx m)
 
7419
   (gem-statep gstate)
 
7420
   (rtm-statep rstate)
 
7421
   (in-range (pcc gstate) (code gstate))
 
7422
   (in-range (pcc rstate) (code rstate))
 
7423
   (m-correspondent-values-p m (mem gstate) (mem rstate))
 
7424
   (M-ENTRIES-POINT-TO-GOOD-RTM-VAR-SETS M (MEM RSTATE))
 
7425
   (no-duplicates-p (retrieve-gemvars m))
 
7426
   (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
7427
   (correct-wrt-arity m (mem gstate)))
 
7428
  (equal-values-and-attributes 
 
7429
   (get-cell (car (nth idx m)) (mem (execute-instruction gstate)))
 
7430
   (cdr (nth idx m))
 
7431
   (mem (execute-n-instructions rstate (* 2 (len *rns*))))
 
7432
   (type-i-idx m idx)))
 
7433
  :hints (("Subgoal 2" :in-theory nil)
 
7434
          ("Goal" :in-theory (union-theories (current-theory 'ground-zero) 
 
7435
                                             '((:definition in-range))) 
 
7436
           :use ( (:theorem
 
7437
                   (implies
 
7438
                    (and
 
7439
                     (alistp m)
 
7440
                     (in-range idx m))
 
7441
                    (and
 
7442
                     (true-listp m)
 
7443
                     (assoc-equal (car (nth idx m)) m))))
 
7444
 
 
7445
                  rtmintvars-i-iscdrnth
 
7446
                  type-i-is-typeidx
 
7447
                  (:instance equal-values-correspondence-kept-by-any-execution-equ (gvar1 (car (nth idx m)))))))
 
7448
  :otf-flg t)
 
7449
 
 
7450
 
 
7451
 
 
7452
 
 
7453
(defthm m-correspondence-kept-by-any-execution-idxed-equ
 
7454
  (implies
 
7455
   (and
 
7456
   (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-equ)
 
7457
   (no-tmp-into-mapping m)
 
7458
   (good-translation-gem-rtm gstate rstate m)
 
7459
   (vars-inclusion (mem gstate) m)
 
7460
   (alistp m)
 
7461
   (gem-statep gstate)
 
7462
   (rtm-statep rstate)
 
7463
   (in-range (pcc gstate) (code gstate))
 
7464
   (in-range (pcc rstate) (code rstate))
 
7465
   (m-correspondent-values-p m (mem gstate) (mem rstate))
 
7466
   (M-ENTRIES-POINT-TO-GOOD-RTM-VAR-SETS M (MEM RSTATE))
 
7467
   (no-duplicates-p (retrieve-gemvars m))
 
7468
   (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
7469
   (correct-wrt-arity m (mem gstate)))
 
7470
  (m-correspondent-values-p 
 
7471
   m 
 
7472
   (mem (execute-instruction gstate))
 
7473
   (mem (execute-n-instructions rstate (* 2 (len *rns*))))))
 
7474
  :hints (("Goal" :use (:instance equal-values-correspondence-kept-by-any-execution-idxed-equ
 
7475
                                  (idx (bad-idx-eqv-va m 
 
7476
                                                       (mem (execute-instruction gstate))
 
7477
                                                       (mem (execute-n-instructions rstate (* 2 (len *rns*))))))))
 
7478
          ("Goal'" :cases ( (in-range (bad-idx-eqv-va m (mem (execute-instruction gstate))
 
7479
                                                       (mem (execute-n-instructions rstate (* 2 (len *rns*))))) m)))
 
7480
          ("Subgoal 2" :in-theory '((:forward-chaining alistp-forward-to-true-listp)
 
7481
                                    (:rewrite if-bad-index-not-in-range-then-m-corr)))
 
7482
          ("Subgoal 1" :in-theory '((:rewrite if-bad-index-in-range-thne-must-be-different-vs)))))
 
7483
 
 
7484
 
 
7485
 
 
7486
(defthm m-correspondence-and-other-conditions-kept-by-any-execution-idxed-equ
 
7487
  (implies
 
7488
   (and
 
7489
    (equal (opcode (nth (pcc gstate) (code gstate))) 'gem-equ)
 
7490
    (no-tmp-into-mapping m)
 
7491
    (good-translation-gem-rtm gstate rstate m)
 
7492
    (vars-inclusion (mem gstate) m)
 
7493
    (vars-inclusion m (mem gstate))
 
7494
    (alistp m)
 
7495
    (gem-statep gstate)
 
7496
    (rtm-statep rstate)
 
7497
    (in-range (pcc gstate) (code gstate))
 
7498
    (in-range (pcc rstate) (code rstate))
 
7499
    (m-correspondent-values-p m (mem gstate) (mem rstate))
 
7500
    (M-ENTRIES-POINT-TO-GOOD-RTM-VAR-SETS M (MEM RSTATE))
 
7501
    (no-duplicates-p (retrieve-gemvars m))
 
7502
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
7503
    (correct-wrt-arity m (mem gstate)))
 
7504
   (and
 
7505
    (good-translation-gem-rtm (execute-instruction gstate) (execute-n-instructions rstate (* 2 (len *rns*))) m)
 
7506
    (rtm-statep (execute-n-instructions rstate (* 2 (len *rns*))))
 
7507
    (m-entries-point-to-good-rtm-var-sets m (mem (execute-n-instructions rstate (* 2 (len *rns*)))))
 
7508
    (gem-statep (execute-instruction gstate))
 
7509
    (correct-wrt-arity m (mem (execute-instruction gstate)))
 
7510
    (vars-inclusion (mem (execute-instruction gstate)) m)
 
7511
    (vars-inclusion m (mem (execute-instruction gstate)))
 
7512
    (m-correspondent-values-p 
 
7513
     m 
 
7514
     (mem (execute-instruction gstate))
 
7515
     (mem (execute-n-instructions rstate (* 2 (len *rns*)))))))
 
7516
  :hints (("Goal" 
 
7517
           :in-theory ;nil 
 
7518
           (disable 
 
7519
                       rtm-statep gem-statep
 
7520
                       pcc code opcode 
 
7521
                       execute-instruction rtmintvars-i par1 par2 par3 nth len member-equal) 
 
7522
           :use 
 
7523
           (m-correspondence-kept-by-any-execution-idxed-equ
 
7524
            good-translation-gem-rtm 
 
7525
            (:instance execute-n-instructions-keeps-rtm-state-and-points-to-good
 
7526
                       (st rstate) (n (* 2 (len *rns*))))
 
7527
            (:instance executing-gem-instruction-retrieves-a-gem-state-from-gem-state (st gstate))
 
7528
            (:instance executing-gem-instruction-preserves-correctness-wrt-arity (st gstate))
 
7529
            (:instance executing-gem-instruction-keeps-vars-inclusion-right      (st gstate))
 
7530
            (:instance executing-gem-instruction-keeps-vars-inclusion-left       (st gstate))))))
 
7531
 
 
7532
 
 
7533
 
 
7534
(encapsulate
 
7535
 ()
 
7536
;;; Modified 12/24/2014 to avoid the nu-rewriter, which is being eliminated.
 
7537
; (set-nu-rewriter-mode nil) ; to avoid skip-proofs below
 
7538
 (defthm after-n-instructions-out-of-range-rtmstate-untouched
 
7539
   (implies
 
7540
    (and
 
7541
     (rtm-statep rstate)
 
7542
     (>= (pcc rstate) (len (code rstate))))
 
7543
    (equal (execute-n-instructions rstate n) rstate))
 
7544
   :hints (("Goal" :in-theory (enable execute-not-in-range-instruction-retrieves-same-state)))))
 
7545
 
 
7546
 
 
7547
 
 
7548
(defun correspondent-steps-to-current-gem-instruction (gstate)
 
7549
    (case (opcode (nth (pcc gstate) (code gstate)))
 
7550
      (gem-add  (len *rns*))
 
7551
      (gem-sub  (len *rns*))
 
7552
      (gem-equ  (* 2 (len *rns*)))
 
7553
      (otherwise 0)))
 
7554
 
 
7555
 
 
7556
 
 
7557
(defun correspondent-steps (n gstate)
 
7558
  (if (zp n)
 
7559
      0
 
7560
    (+ (correspondent-steps-to-current-gem-instruction gstate)
 
7561
       (correspondent-steps (1- n) (execute-instruction gstate)))))
 
7562
         
 
7563
 
 
7564
 
 
7565
 
 
7566
 
 
7567
(defthm m-correspondence-and-other-conditions-kept-by-out-of-range-execution-2
 
7568
  (implies
 
7569
   (and
 
7570
    (alistp m)
 
7571
    (no-duplicates-p (retrieve-gemvars m))
 
7572
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
7573
    (good-translation-gem-rtm gstate rstate m)
 
7574
    (correct-wrt-arity m (mem gstate))
 
7575
    (gem-statep gstate)
 
7576
    (rtm-statep rstate)
 
7577
    (vars-inclusion (mem gstate) m)
 
7578
    (vars-inclusion m (mem gstate))
 
7579
    (not (in-range (pcc gstate) (code gstate)))
 
7580
    (>= (pcc gstate) 0)
 
7581
    (>= (pcc rstate) (len (code rstate)))
 
7582
    (m-entries-point-to-good-rtm-var-sets m (mem rstate))
 
7583
    (m-correspondent-values-p m (mem gstate) (mem rstate)))
 
7584
   (and
 
7585
    (good-translation-gem-rtm 
 
7586
     (execute-instruction gstate) 
 
7587
     (execute-n-instructions rstate 
 
7588
                             (correspondent-steps-to-current-gem-instruction gstate)) m)
 
7589
    (rtm-statep (execute-n-instructions rstate (correspondent-steps-to-current-gem-instruction gstate)))
 
7590
    (m-entries-point-to-good-rtm-var-sets 
 
7591
     m 
 
7592
     (mem (execute-n-instructions rstate (correspondent-steps-to-current-gem-instruction gstate))))
 
7593
    (gem-statep (execute-instruction gstate))
 
7594
    (correct-wrt-arity m (mem (execute-instruction gstate)))
 
7595
    (vars-inclusion (mem (execute-instruction gstate)) m)
 
7596
    (vars-inclusion m (mem (execute-instruction gstate)))
 
7597
    (m-correspondent-values-p 
 
7598
     m 
 
7599
     (mem (execute-instruction gstate))
 
7600
     (mem (execute-n-instructions rstate (correspondent-steps-to-current-gem-instruction gstate))))))
 
7601
  :hints (("Goal" 
 
7602
           :in-theory '((in-range))
 
7603
           :use
 
7604
           ( 
 
7605
            (:instance after-n-instructions-out-of-range-rtmstate-untouched 
 
7606
                       (n (correspondent-steps-to-current-gem-instruction gstate)))
 
7607
             (:instance execute-not-in-range-instruction-retrieves-same-state (st gstate))))))
 
7608
 
 
7609
 
 
7610
 
 
7611
 
 
7612
 
 
7613
(defthm m-correspondence-and-other-conditions-kept-execution-2
 
7614
  (implies
 
7615
   (and
 
7616
    (alistp m)
 
7617
    (no-tmp-into-mapping m)
 
7618
    (no-duplicates-p (retrieve-gemvars m))
 
7619
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
7620
    (good-translation-gem-rtm gstate rstate m)
 
7621
    (correct-wrt-arity m (mem gstate))
 
7622
    (gem-statep gstate)
 
7623
    (rtm-statep rstate)
 
7624
    (vars-inclusion (mem gstate) m)
 
7625
    (vars-inclusion m (mem gstate))
 
7626
    (>= (pcc gstate) 0)
 
7627
    (m-entries-point-to-good-rtm-var-sets m (mem rstate))
 
7628
    (m-correspondent-values-p m (mem gstate) (mem rstate)))
 
7629
   (and
 
7630
    (>= (pcc (execute-instruction gstate)) 0)
 
7631
    (good-translation-gem-rtm 
 
7632
     (execute-instruction gstate) 
 
7633
     (execute-n-instructions rstate (correspondent-steps-to-current-gem-instruction gstate)) m)
 
7634
    (rtm-statep (execute-n-instructions rstate (correspondent-steps-to-current-gem-instruction gstate)))
 
7635
    (m-entries-point-to-good-rtm-var-sets 
 
7636
     m 
 
7637
     (mem (execute-n-instructions rstate (correspondent-steps-to-current-gem-instruction gstate))))
 
7638
    (gem-statep (execute-instruction gstate))
 
7639
    (correct-wrt-arity m (mem (execute-instruction gstate)))
 
7640
    (vars-inclusion (mem (execute-instruction gstate)) m)
 
7641
    (vars-inclusion m (mem (execute-instruction gstate)))
 
7642
    (m-correspondent-values-p 
 
7643
     m 
 
7644
     (mem (execute-instruction gstate))
 
7645
     (mem (execute-n-instructions rstate (correspondent-steps-to-current-gem-instruction gstate))))))
 
7646
   :hints (("Goal" :in-theory '((:definition in-range)) 
 
7647
            :use ((:instance instruction-incrementing-pvv (st gstate))
 
7648
                         correspondent-steps-to-current-gem-instruction
 
7649
                         good-translation-gem-rtm 
 
7650
                         m-correspondence-and-other-conditions-kept-by-out-of-range-execution-2
 
7651
                         m-correspondence-and-other-conditions-kept-by-any-execution-add
 
7652
                         m-correspondence-and-other-conditions-kept-by-any-execution-sub
 
7653
                         m-correspondence-and-other-conditions-kept-by-any-execution-idxed-equ))))
 
7654
 
 
7655
 
 
7656
 
 
7657
 
 
7658
 
 
7659
 
 
7660
 
 
7661
 
 
7662
 
 
7663
 
 
7664
 
 
7665
 
 
7666
 
 
7667
 
 
7668
(defun parallel-exec (gstate rstate n)
 
7669
  (if (zp n)
 
7670
      (list gstate rstate)
 
7671
    (parallel-exec 
 
7672
     (execute-instruction gstate)
 
7673
     (execute-n-instructions rstate (correspondent-steps-to-current-gem-instruction gstate))
 
7674
     (1- n))))
 
7675
 
 
7676
 
 
7677
 
 
7678
 
 
7679
 
 
7680
 
 
7681
 
 
7682
 
 
7683
 
 
7684
 
 
7685
 
 
7686
 
 
7687
(defthm m-correspondence-and-other-conditions-kept-execution-on-n
 
7688
  (implies
 
7689
   (and
 
7690
    (integerp n)
 
7691
    (>= n 0)
 
7692
    (alistp m)
 
7693
    (no-duplicates-p (retrieve-gemvars m))
 
7694
    (no-duplicates-p (append-lists (retrieve-rtmvars m)))
 
7695
    (no-tmp-into-mapping m)
 
7696
    (good-translation-gem-rtm gstate rstate m)
 
7697
    (correct-wrt-arity m (mem gstate))
 
7698
    (gem-statep gstate)
 
7699
    (rtm-statep rstate)
 
7700
    (vars-inclusion (mem gstate) m)
 
7701
    (vars-inclusion m (mem gstate))
 
7702
    (>= (pcc gstate) 0)
 
7703
    (m-entries-point-to-good-rtm-var-sets m (mem rstate))
 
7704
    (m-correspondent-values-p m (mem gstate) (mem rstate)))
 
7705
   (and
 
7706
    (>= (pcc (execute-n-instructions gstate n)) 0)
 
7707
    (good-translation-gem-rtm 
 
7708
     (execute-n-instructions gstate n) 
 
7709
     (execute-n-instructions rstate (correspondent-steps n gstate)) m)
 
7710
    (rtm-statep (execute-n-instructions rstate (correspondent-steps n gstate)))
 
7711
    (m-entries-point-to-good-rtm-var-sets 
 
7712
     m 
 
7713
     (mem (execute-n-instructions rstate (correspondent-steps n gstate))))
 
7714
    (gem-statep (execute-n-instructions gstate n))
 
7715
    (correct-wrt-arity m (mem (execute-n-instructions gstate n)))
 
7716
    (vars-inclusion (mem (execute-n-instructions gstate n)) m)
 
7717
    (vars-inclusion m (mem (execute-n-instructions gstate n)))
 
7718
    (m-correspondent-values-p 
 
7719
     m 
 
7720
     (mem (execute-n-instructions gstate n))
 
7721
     (mem (execute-n-instructions rstate (correspondent-steps n gstate))))))
 
7722
  :hints (("Goal" :in-theory 
 
7723
           ;(current-theory 'ground-zero)
 
7724
           (disable executing-gem-instruction-preserves-correctness-wrt-arity
 
7725
                                      execute-instruction-is-type-and-attribute-invariant-on-any-var
 
7726
                                      ;executing-gem-instruction-is-type-attribute-invariant
 
7727
                                      executing-gem-instruction-keeps-vars-inclusion-left
 
7728
                                      executing-gem-instruction-keeps-vars-inclusion-right
 
7729
                                      execute-n-instructions-keeps-rtm-state-and-points-to-good
 
7730
                                      correspondent-steps-to-current-gem-instruction
 
7731
                                      execute-n-instructions-tantamount-to-add-list-e
 
7732
                                      m-correspondence-and-other-conditions-kept-by-any-execution-add
 
7733
                                      m-correspondence-and-other-conditions-kept-by-any-execution-sub
 
7734
                                      m-correspondence-and-other-conditions-kept-by-any-execution-idxed-equ
 
7735
                                      m-correspondence-and-other-conditions-kept-by-out-of-range-execution-2
 
7736
                                      executing-gem-instruction-retrieves-a-gem-state-from-gem-state
 
7737
                                      executing-rtm-instruction-retrieves-a-rtm-state-from-rtm-state
 
7738
                                      instruction-incrementing-pvv
 
7739
                                      good-translation-gem-rtm
 
7740
                                      all-rtm-adds-for-n-steps
 
7741
                                      null-opcode-implies-execution-does-not-touch-state
 
7742
                                      bad-idx-eqv-va                                  
 
7743
                                      mem pcc code opcode retrieve-rtmvars gem-statep rtm-statep execute-instruction)
 
7744
          :induct (parallel-exec gstate rstate n))
 
7745
          ("Subgoal *1/2" :use 
 
7746
           (        
 
7747
            (:instance execute-n-instruction-decomposition 
 
7748
                      (n1 (correspondent-steps (1- n) gstate))
 
7749
                      (n2 (correspondent-steps-to-current-gem-instruction gstate))
 
7750
                      (st rstate))
 
7751
            (:instance m-correspondence-and-other-conditions-kept-execution-2
 
7752
                       (gstate (execute-instruction gstate))
 
7753
                       (rstate (execute-n-instructions rstate (correspondent-steps-to-current-gem-instruction gstate))))))))
 
7754
 
 
7755
 
 
7756
 
 
7757
 
 
7758
(defthm simple-fact-about-initial-gemstate
 
7759
 (implies
 
7760
  (gem-program-p gemprog)
 
7761
 (and
 
7762
  (>= (pcc (initial-state gemprog)) 0)
 
7763
  (gem-statep (initial-state gemprog)))))
 
7764
 
 
7765
(defthm simple-fact-about-initial-rtmstate
 
7766
 (implies
 
7767
  (rtm-program-p rtmprog)
 
7768
 (and
 
7769
  (>= (pcc (initial-state rtmprog)) 0)
 
7770
  (rtm-statep (initial-state rtmprog)))))
 
7771
 
 
7772
 
 
7773
(defun good-mapping (m)
 
7774
  (and
 
7775
   (alistp m)
 
7776
   (no-tmp-into-mapping m)
 
7777
   (no-duplicates-p (retrieve-gemvars m))
 
7778
   (no-duplicates-p (append-lists (retrieve-rtmvars m)))))
 
7779
 
 
7780
(defun good-mapping-wrt-memories (m mem-gstate mem-rstate) 
 
7781
  (and
 
7782
   (correct-wrt-arity m mem-gstate)
 
7783
   (vars-inclusion mem-gstate m)
 
7784
   (vars-inclusion m mem-gstate)
 
7785
   (m-entries-point-to-good-rtm-var-sets m mem-rstate)
 
7786
   (m-correspondent-values-p m mem-gstate mem-rstate)))
 
7787
 
 
7788
 
 
7789
 
 
7790
 
 
7791
(defun correct-translation (gemprog rtmprog m)
 
7792
  (good-translation-gem-rtm (initial-state gemprog) (initial-state rtmprog) m))
 
7793
 
 
7794
 
 
7795
(defthm execution-of-correctly-translated-gem-and-rtm-yields-same-output
 
7796
  (let
 
7797
      ((gstate (initial-state gemprog))
 
7798
       (rstate (initial-state rtmprog))
 
7799
       (n (len (code gstate))))
 
7800
  (implies
 
7801
   (and
 
7802
    (gem-program-p gemprog)
 
7803
    (rtm-program-p rtmprog)
 
7804
    (good-mapping m)
 
7805
    (good-mapping-wrt-memories m (mem gstate) (mem rstate))
 
7806
    (correct-translation gemprog rtmprog m))
 
7807
   (equal-memories
 
7808
    (decode m (projectio (mem (execute-n-instructions rstate (correspondent-steps n gstate))) attr))
 
7809
    (projectio (mem (execute-n-instructions gstate n)) attr))))
 
7810
  :hints (("Goal"
 
7811
           :in-theory (union-theories (current-theory 'ground-zero)
 
7812
                                      '((:rewrite equalities-on-io) 
 
7813
                                        (:definition correct-translation)
 
7814
                                        (:definition good-mapping-wrt-memories) 
 
7815
                                        (:definition gem-statep) 
 
7816
                                        (:definition rtm-statep)
 
7817
                                        (:definition good-mapping)))
 
7818
           :use
 
7819
           (
 
7820
            fact-bout-rns
 
7821
            simple-fact-about-initial-rtmstate
 
7822
            simple-fact-about-initial-gemstate
 
7823
            (:instance m-correspondence-and-other-conditions-kept-execution-on-n 
 
7824
                       (gstate (initial-state gemprog))
 
7825
                       (rstate (initial-state rtmprog))
 
7826
                       (n (len (code gstate))))))))
 
7827
            
 
7828