3
(defthm equal-cons-cases
4
(equal (equal (cons a b) c)
10
(if (consp x) (lastatom (cdr x))
13
(defthm lastatom-update-nth-<
16
(equal (lastatom (update-nth a v x))
19
(defthm lastatom-update-nth->
21
(not (< (nfix a) (len x)))
22
(equal (lastatom (update-nth a v x))
25
(defthm lastatom-update-nth
26
(equal (lastatom (update-nth a v x))
27
(if (< (nfix a) (len x))
31
(defun nfix-equiv (a b)
35
(defthmd equal-nfix-rewrite
36
(iff (equal (nfix a) b)
42
(:definition nfix-equiv)
43
(:rewrite equal-nfix-rewrite)
48
(defcong nfix-equiv equal (nth a x) 1
49
:hints (("goal" :in-theory (enable nth))))
51
(defcong nfix-equiv equal (update-nth a v x) 1
52
:hints (("goal" :in-theory (enable update-nth))))
54
(defun nmx-induction (n m x)
57
(nmx-induction (1- n) (1- m) (cdr x)))))
59
(defthm update-nth-of-update-nth
62
(equal (update-nth a v (update-nth b w x))
64
:hints (("Goal" :induct (nmx-induction a b x)
65
:in-theory (enable update-nth))))
67
(defthm update-nth-over-update-nth
69
(not (nfix-equiv a b))
70
(equal (update-nth a v (update-nth b w x))
71
(update-nth b w (update-nth a v x))))
72
:hints (("Goal" :induct (nmx-induction a b x)
73
:in-theory (enable update-nth))))
75
(defthm nfix-equiv-nfix
76
(nfix-equiv (nfix x) x))
81
(defthm lastatom-clr-nth
82
(equal (lastatom (clr-nth a x))
83
(if (< (nfix a) (len x))
86
:hints (("Goal" :in-theory (enable clr-nth))))
89
(equal (len (clr-nth a x))
90
(max (1+ (nfix a)) (len x)))
91
:hints (("Goal" :in-theory (enable clr-nth))))
93
(defcong nfix-equiv equal (clr-nth a x) 1
94
:hints (("goal" :in-theory (enable clr-nth))))
98
(if (zp n) (cons nil (cdr x))
100
(clr-nth (1- n) (cdr x)))))
101
:hints (("Goal" :in-theory (enable clr-nth update-nth)))
102
:rule-classes (:definition))
110
(clr-nth (1- n) (cdr x)))))
114
(cons nil (cdr x))))))
116
(defthm open-update-nth
120
(equal (update-nth n v x)
122
(update-nth (1- n) v (cdr x)))))
125
(equal (update-nth n v x)
128
(defthm clr-nth-update-nth
129
(equal (clr-nth a (update-nth b v x))
130
(if (nfix-equiv a b) (clr-nth a x)
131
(update-nth b v (clr-nth a x))))
132
:hints (("Goal" :in-theory (enable clr-nth))))
134
(defthm clr-nth-of-clr-nth
135
(equal (clr-nth a (clr-nth a x))
137
:hints (("goal" :in-theory (enable clr-nth))))
139
(defthm clr-nth-over-clr-nth
140
(equal (clr-nth a (clr-nth b x))
141
(clr-nth b (clr-nth a x)))
142
:hints (("goal" :in-theory (enable clr-nth))))
145
(equal (nth a (clr-nth b x))
146
(if (nfix-equiv a b) nil
148
:hints (("Goal" :in-theory (enable clr-nth))))
150
(defun equal-nth-conclusion (a x y)
151
(and (equal (lastatom x) (lastatom y))
152
(equal (len x) (len y))
153
(equal (nth a x) (nth a y))
157
(defthm open-equal-nth-conclusion
158
(equal (equal-nth-conclusion n x y)
159
(if (zp n) (if (and (consp x) (consp y))
160
(and (equal (car x) (car y))
161
(equal (cdr x) (cdr y)))
165
(and (equal (car x) (car y))
166
(equal-nth-conclusion (1- n) (cdr x) (cdr y)))
168
:rule-classes (:definition))
170
(defun equal-nth-conclusion-fn (n x y)
171
(if (zp n) (if (and (consp x) (consp y))
172
(and (equal (car x) (car y))
173
(equal (cdr x) (cdr y)))
177
(and (equal (car x) (car y))
178
(equal-nth-conclusion-fn (1- n) (cdr x) (cdr y)))
181
(defthmd equal-nth-conclusion-fn-to-equal-nth-conclusion
182
(equal (equal-nth-conclusion n x y)
183
(equal-nth-conclusion-fn n x y)))
185
(defthm equal-nth-conclusion-fn-to-equal
186
(equal (equal-nth-conclusion-fn n x y)
189
(defthmd equal-to-nth-reduction
191
(equal-nth-conclusion n x y))
192
:hints (("Goal" :in-theory '(equal-nth-conclusion-fn-to-equal-nth-conclusion
193
equal-nth-conclusion-fn-to-equal))))
195
(defthm equal-update-nth-reduction
196
(equal (equal (update-nth n v x) y)
197
(and (< (nfix n) (len y))
201
:hints (("Goal" :use (:instance equal-to-nth-reduction
202
(x (update-nth n v x))))))
204
(defthm update-nth-nth
207
(equal (update-nth n (nth n x) x) x)))
211
(defun nil-list (n v)
213
(cons nil (nil-list (1- n) v))))
215
(defthm update-nth-to-append
217
(<= (len x) (nfix n))
218
(equal (update-nth n v x)
219
(append x (nil-list (- (nfix n) (len x)) v))))
220
:hints (("Goal" :in-theory (enable append update-nth))))
222
(defthm nth-nil-list-nfix-equiv
225
(equal (nth a (nil-list m v)) v))
226
:hints (("Goal" :in-theory (enable nth))))
228
(defthm nth-nil-list-not-nfix-equiv
230
(not (nfix-equiv a m))
231
(equal (nth a (nil-list m v)) nil))
232
:hints (("Goal" :induct (nm-induction a m)
233
:in-theory (enable nth))))
236
(equal (nth a (nil-list m v))
237
(if (nfix-equiv a m) v
239
:hints (("Goal" :in-theory
240
'(nth-nil-list-not-nfix-equiv
241
nth-nil-list-nfix-equiv))))
243
(defthm nthcdr-nil-list
244
(equal (nthcdr n (nil-list m v))
245
(if (<= (nfix n) (nfix m))
246
(nil-list (- (nfix m) (nfix n)) v)
248
:hints (("Goal" :induct (nm-induction n m)
249
:in-theory (enable nthcdr))))
251
(xxinclude-book "basic" :dir :lists)
253
(defthm firstn-nil-list
256
(equal (firstn n (nil-list m v))
257
(if (<= (nfix n) (nfix m))
258
(nil-list (1- (nfix n)) nil)
260
:hints (("Goal" :induct (nm-induction n m)
261
:in-theory (enable firstn))))
263
(defthm car-nil-list-nil
264
(equal (car (nil-list n nil))
269
#| equal append rules ..
271
(defthm equal-append-append-tail-equal
272
(equal (equal (append x y) (append z y))
274
:hints (("goal" :induct (list::len-len-induction x z)
275
:in-theory (enable append))))
277
(defthmd equal-to-equiv
281
(equal (lastatom x) (lastatom y))))
282
:hints (("goal" :induct (list::len-len-induction x y))))
284
(defun equal-append-append-case (x a y b)
285
(and (list::equiv x (firstn (len x) a))
286
(list::equiv (firstn (- (len a) (len x)) y)
288
(equal (nthcdr (- (len a) (len x)) y)
291
(defthm equiv-append-reduction-1
292
(equal (list::equiv (append x y) z)
293
(and (list::equiv x (firstn (len x) z))
294
(list::equiv y (nthcdr (len x) z))))
295
:hints (("Goal" :in-theory (e/d (LIST::EQUAL-APPEND-REDUCTION! list::equiv)
296
(LIST::LIST-EQUIV-HACK LIST::EQUAL-OF-FIXES)))))
298
(defthm equiv-append-reduction-2
299
(equal (list::equiv z (append x y))
300
(and (list::equiv x (firstn (len x) z))
301
(list::equiv y (nthcdr (len x) z))))
302
:hints (("Goal" :in-theory (e/d (LIST::EQUAL-APPEND-REDUCTION! list::equiv)
303
(LIST::LIST-EQUIV-HACK LIST::EQUAL-OF-FIXES)))))
305
(defthmd equal-append-append-reduction2!
306
(equal (equal (append x y) (append a b))
307
(if (< (len x) (len a))
308
(equal-append-append-case x a y b)
309
(equal-append-append-case a x b y)))
310
:hints (("goal" :in-theory '(LIST::EQUAL-APPEND-REDUCTION!))
311
(and stable-under-simplificationp
312
'(:in-theory (current-theory :here)))
313
(and stable-under-simplificationp
314
'(:in-theory '(LIST::EQUAL-APPEND-REDUCTION!)))
315
(and stable-under-simplificationp
316
'(:in-theory (current-theory :here)))))
320
(in-theory (disable nfix nfix-equiv))
321
(in-theory (enable equal-nfix-rewrite))
322
(in-theory (disable nth update-nth))
324
(defun nfix-list (list)
326
(cons (nfix (car list))
327
(nfix-list (cdr list)))
330
(defun nfix-list-equiv (x y)
334
(defequiv nfix-list-equiv)
336
(defthm open-nfix-list-equiv
340
(equal (nfix-list-equiv x y)
342
(equal (nfix (car x))
344
(nfix-list-equiv (cdr x) (cdr y)))))
347
(equal (nfix-list-equiv x y)
350
(in-theory (disable nfix-list-equiv))
353
(defun nth* (list st)
355
(cons (nth (car list) st)
356
(nth* (cdr list) st))
359
(defund nth*-equiv (list st1 st2)
360
(equal (nth* list st1)
363
(defthm nth*-equiv-def
364
(equal (nth*-equiv list st1 st2)
366
(and (equal (nth (car list) st1)
367
(nth (car list) st2))
368
(nth*-equiv (cdr list) st1 st2))
370
:hints (("Goal" :in-theory (enable nth*-equiv)))
371
:rule-classes (:definition))
373
(defun clr-nth* (list st)
376
(clr-nth* (cdr list) st))
379
(defthm open-clr-nth*
382
(equal (clr-nth* list st)
384
(clr-nth* (cdr list) st)))))
386
(defthm clr-nth-clr-nth*
387
(equal (clr-nth* list (clr-nth a st))
388
(clr-nth a (clr-nth* list st)))
389
:hints (("Subgoal *1/1" :cases ((nfix-equiv a (car list))))))
391
(defun equal-nth*-conclusion (list x y)
392
(and (equal (lastatom x) (lastatom y))
393
(equal (len x) (len y))
394
(nth*-equiv list x y)
395
(equal (clr-nth* list x)
398
(defthm nth*-equiv-over-clr-nth-backchaining
400
(nth*-equiv list x y)
401
(nth*-equiv list (clr-nth a x) (clr-nth a y)))
402
:hints (("Goal" :in-theory (enable nth*-equiv))))
404
(defthm nth*-equiv-identity
405
(nth*-equiv list x x)
406
:hints (("Goal" :in-theory (enable nth*-equiv))))
408
(defun equal-nth*-induction (list x y)
410
(equal-nth*-induction (cdr list)
411
(clr-nth (car list) x)
412
(clr-nth (car list) y))
415
(defthmd equal-nth*-reduction
417
(equal-nth*-conclusion list x y))
418
:hints (("Goal" :induct (equal-nth*-induction list x y)
419
:in-theory (disable equal-nth*-conclusion lastatom-clr-nth len-clr-nth))
420
("Subgoal *1/2" :in-theory (enable equal-nth*-conclusion))
421
("Subgoal *1/1" :in-theory (enable equal-nth*-conclusion)
422
:use ((:instance equal-to-nth-reduction
426
(defun copy-nth* (list st1 st2)
428
(update-nth (car list)
430
(copy-nth* (cdr list) st1 st2))
434
;; Does the default ordering go the wrong way?
436
(defthm clr-nth-thru-clr-nth*
437
(equal (clr-nth ZZZZ (clr-nth* list (update-nth ZZZZ v x)))
438
(clr-nth ZZZZ (clr-nth* list x))))
440
(defthm nth*-clr-copy-nth*
441
(equal (clr-nth* list (copy-nth* list st1 st2))
442
(clr-nth* list st2)))
444
(defund nth*-copy-equiv (list x y z)
445
(equal (copy-nth* list x z)
446
(copy-nth* list y z)))
452
(defun maxval-p (a list)
454
(if (< (nfix a) (nfix (car list))) nil
455
(maxval-p a (cdr list)))
460
(if (maxval-p (car list) (cdr list))
465
(defthm maxval-p-maxval-prop
466
(IMPLIES (AND (NOT (MAXVAL-P A Z))
468
(< (NFIX X) (NFIX A)))
469
(< (NFIX X) (MAXVAL Z)))
470
:rule-classes (:linear :rewrite))
472
(defthm not-maxval-p-maxval-prop-2
474
(not (maxval-p x list))
475
(< (nfix x) (maxval list)))
476
:rule-classes (:rewrite :linear))
478
(defthm maxval-p-maxval-prop-3
481
(<= (maxval list) (nfix x)))
482
:rule-classes (:rewrite :linear))
484
(defund maxsize (list)
491
(equal (max (1+ (nfix x)) (maxsize list))
492
(if (maxval-p x list) (1+ (nfix x))
494
:hints (("Goal" :in-theory (enable maxsize)))))
500
(equal (maxsize list)
501
(if (maxval-p (car list) (cdr list))
502
(1+ (nfix (car list)))
503
(maxsize (cdr list)))))
504
:hints (("goal" :in-theory (enable maxsize)))))
507
(defthm equal-max-reduction
508
(implies (equal (max a b) d)
509
(iff (equal (max a (max b c))
512
(defthm len-copy-nth*
513
(equal (len (copy-nth* list x y))
514
(max (maxsize list) (len y)))
515
:hints (("Goal" :induct (copy-nth* list x y)
516
:in-theory (disable max))
517
("Subgoal *1/2" :in-theory (enable maxsize max))))
522
(defthm nth*-copy-equiv-reduction
523
(equal (nth*-copy-equiv list x y z)
524
(equal-nth*-conclusion list (copy-nth* list x z) (copy-nth* list y z)))
525
:hints (("Goal" :in-theory (enable nth*-copy-equiv)
526
:use (:instance equal-nth*-reduction
527
(x (copy-nth* list x z))
528
(y (copy-nth* list y z))
531
(defthm nth*-equiv-update-nth-chaining
534
(nth*-equiv list x y)
536
(nth*-equiv list (update-nth a v x) y))
537
:hints (("goal" :induct (len list))))
539
(defthm nth*-equiv-copy-nth*
540
(nth*-equiv list (copy-nth* list x y) x))
542
(defthm nth*-copy-nth*
543
(equal (nth* list (copy-nth* list x y))
545
:hints (("Goal" :in-theory `(nth*-equiv)
546
:use (:instance nth*-equiv-copy-nth*))))
548
(defthm nth*-equiv-copy-nth*-copy-nth*
549
(equal (nth*-equiv list (copy-nth* list x a)
550
(copy-nth* list y b))
551
(nth*-equiv list x y))
552
:hints (("Goal" :in-theory (enable nth*-equiv))))
554
(defthm lastatom-copy-nth*
555
(equal (lastatom (copy-nth* list x y))
556
(if (or (not (consp list)) (< (maxval list) (len y)))
559
:hints (("Goal" :in-theory (enable maxsize)))
562
(defthm nth*-equiv-reduction
563
(equal (nth*-equiv list x y)
564
(nth*-copy-equiv list x y z)))
567
(copy-nth* list st nil))
571
(member (nfix n) (nfix-list list))
572
(equal (nth n (use list x))
574
:hints (("Goal" :in-theory (enable use))))
576
(defthm nth*-get-copy-equivalence
577
(equal (equal (nth* list x)
581
:hints (("goal" :in-theory '(use
584
:use (:instance nth*-equiv-reduction
587
(defthm nth-copy-nth*
588
(equal (nth a (copy-nth* list x y))
589
(if (member (nfix a) (nfix-list list)) (nth a x)
592
(defthm update-nth-nil-reduction
593
(equal (update-nth a nil x)
595
:hints (("Goal" :in-theory (enable clr-nth))))
597
(defthm clr-nth-copy-nth*-member
599
(member (nfix a) (nfix-list list))
600
(equal (clr-nth a (copy-nth* list x y))
601
(copy-nth* list (clr-nth a x) y)))
602
:hints (("Goal" :in-theory (disable EQUAL-UPDATE-NTH-REDUCTION))))
604
(defthm clr-nth-copy-nth*-non-member
606
(not (member (nfix a) (nfix-list list)))
607
(equal (clr-nth a (copy-nth* list x y))
608
(copy-nth* list x (clr-nth a y))))
609
:hints (("Goal" :in-theory (disable EQUAL-UPDATE-NTH-REDUCTION))))
611
(defthm clr-nth*-copy-nth*
612
(equal (clr-nth a (copy-nth* list x y))
613
(if (member (nfix a) (nfix-list list)) (copy-nth* list (clr-nth a x) y)
614
(copy-nth* list x (clr-nth a y)))))
616
(defthm update-nth-thru-copy-nth*
617
(equal (update-nth a v (copy-nth* list (update-nth a w x) y))
618
(update-nth a v (copy-nth* list x y))))
620
(defthm copy-nth*-update-nth-member
622
(member (nfix a) (nfix-list list))
623
(equal (copy-nth* list (update-nth a v x) z)
624
(update-nth a v (copy-nth* list x z))))
625
:hints (("Goal" :in-theory (disable EQUAL-UPDATE-NTH-REDUCTION))))
627
(defthm copy-nth*-update-nth-non-member
629
(not (member (nfix a) (nfix-list list)))
630
(equal (copy-nth* list (update-nth a v x) z)
631
(copy-nth* list x z)))
632
:hints (("Goal" :in-theory (disable EQUAL-UPDATE-NTH-REDUCTION))))
634
(defthm copy-nth*-update-nth
635
(equal (copy-nth* list (update-nth a v x) z)
636
(if (member (nfix a) (nfix-list list))
637
(update-nth a v (copy-nth* list x z))
638
(copy-nth* list x z)))
639
:hints (("Goal" :in-theory '(copy-nth*-update-nth-member
640
copy-nth*-update-nth-non-member
643
(defthm use-update-nth-non-member
645
(not (member (nfix a) (nfix-list list)))
646
(equal (use list (update-nth a v x))
649
(defthmd use-update-nth-member
651
(member (nfix a) (nfix-list list))
652
(equal (use list (update-nth a v x))
653
(update-nth a v (use list x)))))
655
(defthmd use-update-nth
656
(equal (use list (update-nth a v x))
657
(if (member (nfix a) (nfix-list list))
658
(update-nth a v (use list x))
660
:hints (("Goal" :in-theory '(use-update-nth-non-member
661
use-update-nth-member
665
(equal (use list (use list x))
668
(defthm member-append
669
(iff (member x (append y z))
673
(defthm nfix-list-append
674
(equal (nfix-list (append x y))
675
(append (nfix-list x) (nfix-list y))))
682
(update-nth (car list) (nth (car list) x)
683
(use (cdr list) x))))
686
(equal (use list x) nil)))
687
:hints (("Goal" :in-theory (e/d (use) (EQUAL-UPDATE-NTH-REDUCTION)))))
692
(and (member (car x) y)
699
(equal (nth* list (use listx st))
701
:hints (("Goal" :in-theory (e/d (use)
702
(NTH*-GET-COPY-EQUIVALENCE)))))
704
(defthm subset-append
705
(subset list (append list y)))
707
(defthm equal-nth*-append-reduction
708
(equal (equal (nth* (append x y) a)
709
(nth* (append x y) b))
710
(and (equal (nth* x a)
714
:hints (("Goal" :in-theory (disable
715
NTH*-GET-COPY-EQUIVALENCE
720
(member (nfix a) (nfix-list list))
721
(equal (clr-nth a (use list x))
722
(use list (clr-nth a x))))
723
:hints (("Goal" :in-theory (enable use))))
725
(in-theory (disable OPEN-UPDATE-NTH))