-
Notifications
You must be signed in to change notification settings - Fork 1
/
boot-strap-pass-2-a.lisp
1354 lines (1127 loc) · 51 KB
/
boot-strap-pass-2-a.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; ACL2 Version 8.4 -- A Computational Logic for Applicative Common Lisp
; Copyright (C) 2021, Regents of the University of Texas
; This version of ACL2 is a descendent of ACL2 Version 1.9, Copyright
; (C) 1997 Computational Logic, Inc. See the documentation topic NOTE-2-0.
; This program is free software; you can redistribute it and/or modify
; it under the terms of the LICENSE file distributed with ACL2.
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; LICENSE for more details.
; Written by: Matt Kaufmann and J Strother Moore
; email: Kaufmann@cs.utexas.edu and Moore@cs.utexas.edu
; Department of Computer Science
; University of Texas at Austin
; Austin, TX 78712 U.S.A.
(in-package "ACL2")
; This file is the first of a pair of files, boot-strap-pass-2-a.lisp and
; boot-strap-pass-2-b.lisp. They are compiled and loaded; but they are only
; processed during the second pass of the boot-strap process, not the first.
; We introduce proper defattach events, i.e., without :skip-checks t. Here are
; some guiding principles for making system functions available for attachment
; by users.
; - The initial attachment is named by adding the suffix -builtin. For
; example, worse-than is a constrained function initially attached to
; worse-than-builtin.
; - Use the weakest logical specs we can (even if T), without getting
; distracted by names. For example, we do not specify a relationship between
; worse-than-or-equal and worse-than.
; - Only make functions attachable if they are used in our sources somewhere
; outside their definitions. So for example, we do not introduce
; worse-than-list as a constrained function, since its only use is in the
; mutual-recursion event that defines worse-than.
; We conclude by defining some theories, near the end so that they pick up much
; of the rest of this file.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Miscellaneous verify-termination and guard verification
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; cons-term and symbol-class -- at one point during development, used in
; fncall-term, but anyhow, generally useful to have in logic mode
(verify-termination-boot-strap quote-listp) ; and guards
(verify-termination-boot-strap cons-term1) ; and guards
(verify-termination-boot-strap cons-term) ; and guards
(verify-termination-boot-strap symbol-class) ; and guards
; packn1, packn, and pack-to-string
(verify-termination-boot-strap packn1) ; and guards
(encapsulate ()
(local
(defthm character-listp-explode-nonnegative-integer
(implies (character-listp z)
(character-listp (explode-nonnegative-integer x y z)))
:rule-classes ((:forward-chaining :trigger-terms
((explode-nonnegative-integer x y z))))))
(local
(defthm character-listp-explode-atom
(character-listp (explode-atom x y))
:rule-classes ((:forward-chaining :trigger-terms
((explode-atom x y))))))
(verify-termination-boot-strap packn-pos) ; and guards
(verify-termination-boot-strap find-first-non-cl-symbol) ; and guards
(verify-termination-boot-strap packn) ; and guards
(verify-termination-boot-strap pack-to-string) ; and guards
)
(verify-termination-boot-strap read-file-into-string1) ; and guards
; miscellaneous
(verify-termination-boot-strap guard-or-termination-theorem-msg) ; and guards
(verify-termination-boot-strap alist-keys-subsetp) ; and guards
(verify-termination-boot-strap keyword-listp) ; and guards
(verify-termination-boot-strap pairlis-x1) ; and guards
(verify-termination-boot-strap pairlis-x2) ; and guards
(verify-termination-boot-strap first-keyword) ; and guards
(verify-termination-boot-strap symbol-name-lst) ; and guards
; for case-match expansions:
(verify-termination-boot-strap symbol-name-equal) ; and guards
(verify-termination-boot-strap fix-pkg) ; and guards
(verify-termination-boot-strap unmake-true-list-cons-nest) ; and guards
(verify-termination-boot-strap dumb-negate-lit) ; and guards
(verify-termination-boot-strap flatten-ands-in-lit) ; and guards
(verify-termination-boot-strap union-equal-to-end) ; and guards
(verify-termination-boot-strap flatten-ands-in-lit!) ; and guards
(verify-guards warranted-fns-of-world)
; Convert defproxy events to :logic mode.
(defstub initialize-event-user (* * state) => state)
(defstub finalize-event-user (* * state) => state)
(defstub acl2x-expansion-alist (* state) => *)
#+acl2-loop-only
(partial-encapsulate
(((canonical-pathname * * state) => *))
; Supporters = nil since each missing axiom equates a call of
; canonical-pathname on explicit arguments with its result.
nil
(local (defun canonical-pathname (x dir-p state)
(declare (xargs :mode :logic))
(declare (ignore dir-p state))
(if (stringp x) x nil)))
(defthm canonical-pathname-is-idempotent
(equal (canonical-pathname (canonical-pathname x dir-p state) dir-p state)
(canonical-pathname x dir-p state)))
(defthm canonical-pathname-type
(or (equal (canonical-pathname x dir-p state) nil)
(stringp (canonical-pathname x dir-p state)))
:rule-classes :type-prescription))
#+acl2-loop-only
(partial-encapsulate
(((magic-ev-fncall * * state * *) => (mv * *)))
; Supporters = nil since each missing axiom equates a call of
; magic-ev-fncall on explicit arguments with its result.
nil
(logic)
(local (defun magic-ev-fncall (fn args state hard-error-returns-nilp aok)
(declare (xargs :mode :logic)
(ignore fn args state hard-error-returns-nilp aok))
(mv nil nil))))
#+acl2-loop-only
(partial-encapsulate
(((mfc-ap-fn * * state *) => *)
((mfc-relieve-hyp-fn * * * * * * state *) => *)
((mfc-relieve-hyp-ttree * * * * * * state *) => (mv * *))
((mfc-rw+-fn * * * * * state *) => *)
((mfc-rw+-ttree * * * * * state *) => (mv * *))
((mfc-rw-fn * * * * state *) => *)
((mfc-rw-ttree * * * * state *) => (mv * *))
((mfc-ts-fn * * state *) => *)
((mfc-ts-ttree * * state *) => (mv * *)))
; Supporters = nil since each missing axiom equates a call of one of the
; signature functions (above) on explicit arguments with its result.
nil
(logic)
(set-ignore-ok t)
(set-irrelevant-formals-ok t)
(local (defun mfc-ts-fn (term mfc state forcep)
t))
(local (defun mfc-ts-ttree (term mfc state forcep)
(mv t t)))
(local (defun mfc-rw-fn (term obj equiv-info mfc state forcep)
t))
(local (defun mfc-rw-ttree (term obj equiv-info mfc state forcep)
(mv t t)))
(local (defun mfc-rw+-fn (term alist obj equiv-info mfc state forcep)
t))
(local (defun mfc-rw+-ttree (term alist obj equiv-info mfc state forcep)
(mv t t)))
(local (defun mfc-relieve-hyp-fn (hyp alist rune target bkptr mfc state
forcep)
t))
(local (defun mfc-relieve-hyp-ttree (hyp alist rune target bkptr mfc state
forcep)
(mv t t)))
(local (defun mfc-ap-fn (term mfc state forcep)
t)))
(verify-termination-boot-strap print-object$-fn) ; and guards
(verify-termination-boot-strap print-object$) ; and guards
(verify-termination-boot-strap print-object$-preserving-case) ; and guards
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Attachment: too-many-ifs-post-rewrite and too-many-ifs-pre-rewrite
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#+acl2-loop-only
; The above readtime conditional avoids a CLISP warning, and lets the defproxy
; for print-clause-id-okp provide the raw Lisp definition.
(encapsulate
((too-many-ifs-post-rewrite (args val) t
:guard (and (pseudo-term-listp args)
(pseudo-termp val))))
(local (defun too-many-ifs-post-rewrite (args val)
(list args val))))
; The following events are derived from the original version of community book
; books/system/too-many-ifs.lisp. But here we provide a proof that does not
; depend on books. Our approach was to take the proof in the above book,
; eliminate the unnecessary use of an arithmetic book, expand away all uses of
; macros and make-events, avoid use of (theory 'minimal-theory) since that
; theory didn't yet exist (where these events were originally placed), and
; apply some additional hand-editing in order (for example) to remove hints
; depending on the tools/flag community book. We have left original events
; from the book as comments.
(encapsulate
()
(logic)
;;; (include-book "tools/flag" :dir :system)
; In the original book, but not needed for its certification:
; (include-book "arithmetic/top-with-meta" :dir :system)
; Comments like the following show events from the original book.
;;; (make-flag pseudo-termp-flg
;;; pseudo-termp
;;; :flag-var flg
;;; :flag-mapping ((pseudo-termp term)
;;; (pseudo-term-listp list))
;;; :defthm-macro-name defthm-pseudo-termp
;;; :local t)
(local
(defun-nx pseudo-termp-flg (flg x lst)
(declare (xargs :verify-guards nil
:normalize nil
:measure (case flg (term (acl2-count x))
(otherwise (acl2-count lst)))))
(case flg
(term (if (consp x)
(cond ((equal (car x) 'quote)
(and (consp (cdr x))
(equal (cddr x) nil)))
((true-listp x)
(and (pseudo-termp-flg 'list nil (cdr x))
(cond ((symbolp (car x)) t)
((true-listp (car x))
(and (equal (length (car x)) 3)
(equal (caar x) 'lambda)
(symbol-listp (cadar x))
(pseudo-termp-flg 'term (caddar x) nil)
(equal (length (cadar x))
(length (cdr x)))))
(t nil))))
(t nil))
(symbolp x)))
(otherwise (if (consp lst)
(and (pseudo-termp-flg 'term (car lst) nil)
(pseudo-termp-flg 'list nil (cdr lst)))
(equal lst nil))))))
(local
(defthm pseudo-termp-flg-equivalences
(equal (pseudo-termp-flg flg x lst)
(case flg (term (pseudo-termp x))
(otherwise (pseudo-term-listp lst))))
:hints
(("goal" :induct (pseudo-termp-flg flg x lst)))))
(local (in-theory (disable (:definition pseudo-termp-flg))))
; Added here (not present or needed in the certified book):
(verify-termination-boot-strap max) ; and guards
(verify-termination-boot-strap var-counts1)
;;; (make-flag var-counts1-flg
;;; var-counts1
;;; :flag-var flg
;;; :flag-mapping ((var-counts1 term)
;;; (var-counts1-lst list))
;;; :defthm-macro-name defthm-var-counts1
;;; :local t)
(local
(defun-nx var-counts1-flg (flg rhs arg lst acc)
(declare (xargs :verify-guards nil
:normalize nil
:measure (case flg (term (acl2-count rhs))
(otherwise (acl2-count lst)))
:hints nil
:well-founded-relation o<
:mode :logic)
(ignorable rhs arg lst acc))
(case flg
(term (cond ((equal arg rhs) (+ 1 acc))
((consp rhs)
(cond ((equal 'quote (car rhs)) acc)
((equal (car rhs) 'if)
(max (var-counts1-flg 'term
(caddr rhs)
arg nil acc)
(var-counts1-flg 'term
(cadddr rhs)
arg nil acc)))
(t (var-counts1-flg 'list
nil arg (cdr rhs)
acc))))
(t acc)))
(otherwise (if (consp lst)
(var-counts1-flg 'list
nil arg (cdr lst)
(var-counts1-flg 'term
(car lst)
arg nil acc))
acc)))))
(local
(defthm
var-counts1-flg-equivalences
(equal (var-counts1-flg flg rhs arg lst acc)
(case flg (term (var-counts1 arg rhs acc))
(otherwise (var-counts1-lst arg lst acc))))))
(local (in-theory (disable (:definition var-counts1-flg))))
;;; (defthm-var-counts1 natp-var-counts1
;;; (term
;;; (implies (natp acc)
;;; (natp (var-counts1 arg rhs acc)))
;;; :rule-classes :type-prescription)
;;; (list
;;; (implies (natp acc)
;;; (natp (var-counts1-lst arg lst acc)))
;;; :rule-classes :type-prescription)
;;; :hints (("Goal" :induct (var-counts1-flg flg rhs arg lst acc))))
(local
(defthm natp-var-counts1
(case flg
(term (implies (natp acc)
(natp (var-counts1 arg rhs acc))))
(otherwise (implies (natp acc)
(natp (var-counts1-lst arg lst acc)))))
:hints (("Goal" :induct (var-counts1-flg flg rhs arg lst acc)))
:rule-classes nil))
(local
(defthm natp-var-counts1-term
(implies (natp acc)
(natp (var-counts1 arg rhs acc)))
:hints (("Goal" ; :in-theory (theory 'minimal-theory)
:use ((:instance natp-var-counts1 (flg 'term)))))
:rule-classes :type-prescription))
(local
(defthm natp-var-counts1-list
(implies (natp acc)
(natp (var-counts1-lst arg lst acc)))
:hints (("Goal" ; :in-theory (theory 'minimal-theory)
:use ((:instance natp-var-counts1 (flg 'list)))))
:rule-classes :type-prescription))
(verify-guards var-counts1)
(verify-termination-boot-strap var-counts) ; and guards
;;; Since the comment about var-counts says that var-counts returns a list of
;;; nats as long as lhs-args, I prove those facts, speculatively.
; Except, we reason instead about integer-listp. See the comment just above
; the commented-out definition of nat-listp in the source code (file
; rewrite.lisp).
; (verify-termination nat-listp)
(local
(defthm integer-listp-var-counts
(integer-listp (var-counts lhs-args rhs))))
(local
(defthm len-var-counts
(equal (len (var-counts lhs-args rhs))
(len lhs-args))))
(verify-termination-boot-strap count-ifs) ; and guards
; Added here (not present or needed in the certified book):
(verify-termination-boot-strap ifix) ; and guards
; Added here (not present or needed in the certified book):
(verify-termination-boot-strap abs) ; and guards
; Added here (not present or needed in the certified book):
(verify-termination-boot-strap expt) ; and guards
; Added here (not present or needed in the certified book):
(local (defthm natp-expt
(implies (and (integerp base)
(integerp n)
(<= 0 n))
(integerp (expt base n)))
:rule-classes :type-prescription))
; Added here (not present or needed in the certified book):
(verify-termination-boot-strap signed-byte-p) ; and guards
(verify-termination-boot-strap too-many-ifs0) ; and guards
(verify-termination-boot-strap too-many-ifs-pre-rewrite-builtin) ; and guards
(verify-termination-boot-strap occur-cnt-bounded)
;;; (make-flag occur-cnt-bounded-flg
;;; occur-cnt-bounded
;;; :flag-var flg
;;; :flag-mapping ((occur-cnt-bounded term)
;;; (occur-cnt-bounded-lst list))
;;; :defthm-macro-name defthm-occur-cnt-bounded
;;; :local t)
(local
(defun-nx occur-cnt-bounded-flg (flg term2 term1 lst a m bound-m)
(declare (xargs :verify-guards nil
:normalize nil
:measure (case flg (term (acl2-count term2))
(otherwise (acl2-count lst))))
(ignorable term2 term1 lst a m bound-m))
(case flg
(term (cond ((equal term1 term2)
(if (< bound-m a) -1 (+ a m)))
((consp term2)
(if (equal 'quote (car term2))
a
(occur-cnt-bounded-flg 'list
nil term1 (cdr term2)
a m bound-m)))
(t a)))
(otherwise (if (consp lst)
(let ((new (occur-cnt-bounded-flg 'term
(car lst)
term1 nil a m bound-m)))
(if (equal new -1)
-1
(occur-cnt-bounded-flg 'list
nil term1 (cdr lst)
new m bound-m)))
a)))))
(local
(defthm occur-cnt-bounded-flg-equivalences
(equal (occur-cnt-bounded-flg flg term2 term1 lst a m bound-m)
(case flg
(term (occur-cnt-bounded term1 term2 a m bound-m))
(otherwise (occur-cnt-bounded-lst term1 lst a m bound-m))))))
(local (in-theory (disable (:definition occur-cnt-bounded-flg))))
;;; (defthm-occur-cnt-bounded integerp-occur-cnt-bounded
;;; (term
;;; (implies (and (integerp a)
;;; (integerp m))
;;; (integerp (occur-cnt-bounded term1 term2 a m bound-m)))
;;; :rule-classes :type-prescription)
;;; (list
;;; (implies (and (integerp a)
;;; (integerp m))
;;; (integerp (occur-cnt-bounded-lst term1 lst a m bound-m)))
;;; :rule-classes :type-prescription)
;;; :hints (("Goal" :induct (occur-cnt-bounded-flg flg term2 term1 lst a m
;;; bound-m))))
(local
(defthm integerp-occur-cnt-bounded
(case flg
(term (implies (and (integerp a) (integerp m))
(integerp (occur-cnt-bounded term1 term2 a m bound-m))))
(otherwise
(implies (and (integerp a) (integerp m))
(integerp (occur-cnt-bounded-lst term1 lst a m bound-m)))))
:rule-classes nil
:hints
(("Goal" :induct (occur-cnt-bounded-flg flg term2 term1 lst a m bound-m)))))
(local
(defthm integerp-occur-cnt-bounded-term
(implies (and (integerp a) (integerp m))
(integerp (occur-cnt-bounded term1 term2 a m bound-m)))
:rule-classes :type-prescription
:hints (("goal" ; :in-theory (theory 'minimal-theory)
:use ((:instance integerp-occur-cnt-bounded
(flg 'term)))))))
(local
(defthm integerp-occur-cnt-bounded-list
(implies (and (integerp a) (integerp m))
(integerp (occur-cnt-bounded-lst term1 lst a m bound-m)))
:rule-classes :type-prescription
:hints (("goal" ; :in-theory (theory 'minimal-theory)
:use ((:instance integerp-occur-cnt-bounded
(flg 'list)))))))
;;; (defthm-occur-cnt-bounded signed-byte-p-30-occur-cnt-bounded-flg
;;; (term
;;; (implies (and (force (signed-byte-p 30 a))
;;; (signed-byte-p 30 m)
;;; (signed-byte-p 30 (+ bound-m m))
;;; (force (<= 0 a))
;;; (<= 0 m)
;;; (<= 0 bound-m)
;;; (<= a (+ bound-m m)))
;;; (and (<= -1 (occur-cnt-bounded term1 term2 a m bound-m))
;;; (<= (occur-cnt-bounded term1 term2 a m bound-m) (+ bound-m m))))
;;; :rule-classes :linear)
;;; (list
;;; (implies (and (force (signed-byte-p 30 a))
;;; (signed-byte-p 30 m)
;;; (signed-byte-p 30 (+ bound-m m))
;;; (force (<= 0 a))
;;; (<= 0 m)
;;; (<= 0 bound-m)
;;; (<= a (+ bound-m m)))
;;; (and (<= -1 (occur-cnt-bounded-lst term1 lst a m bound-m))
;;; (<= (occur-cnt-bounded-lst term1 lst a m bound-m) (+ bound-m m))))
;;; :rule-classes :linear)
;;; :hints (("Goal" :induct (occur-cnt-bounded-flg flg term2 term1 lst a m
;;; bound-m))))
(local
(defthm signed-byte-p-30-occur-cnt-bounded-flg
(case flg
(term (implies (and (force (signed-byte-p 30 a))
(signed-byte-p 30 m)
(signed-byte-p 30 (+ bound-m m))
(force (<= 0 a))
(<= 0 m)
(<= 0 bound-m)
(<= a (+ bound-m m)))
(and (<= -1
(occur-cnt-bounded term1 term2 a m bound-m))
(<= (occur-cnt-bounded term1 term2 a m bound-m)
(+ bound-m m)))))
(otherwise
(implies (and (force (signed-byte-p 30 a))
(signed-byte-p 30 m)
(signed-byte-p 30 (+ bound-m m))
(force (<= 0 a))
(<= 0 m)
(<= 0 bound-m)
(<= a (+ bound-m m)))
(and (<= -1
(occur-cnt-bounded-lst term1 lst a m bound-m))
(<= (occur-cnt-bounded-lst term1 lst a m bound-m)
(+ bound-m m))))))
:rule-classes nil
:hints
(("Goal" :induct (occur-cnt-bounded-flg flg term2 term1 lst a m bound-m)))))
(local
(defthm signed-byte-p-30-occur-cnt-bounded-flg-term
(implies (and (force (signed-byte-p 30 a))
(signed-byte-p 30 m)
(signed-byte-p 30 (+ bound-m m))
(force (<= 0 a))
(<= 0 m)
(<= 0 bound-m)
(<= a (+ bound-m m)))
(and (<= -1
(occur-cnt-bounded term1 term2 a m bound-m))
(<= (occur-cnt-bounded term1 term2 a m bound-m)
(+ bound-m m))))
:rule-classes :linear
:hints (("Goal" ; :in-theory (theory 'minimal-theory)
:use ((:instance signed-byte-p-30-occur-cnt-bounded-flg
(flg 'term)))))))
(local
(defthm signed-byte-p-30-occur-cnt-bounded-flg-list
(implies (and (force (signed-byte-p 30 a))
(signed-byte-p 30 m)
(signed-byte-p 30 (+ bound-m m))
(force (<= 0 a))
(<= 0 m)
(<= 0 bound-m)
(<= a (+ bound-m m)))
(and (<= -1
(occur-cnt-bounded-lst term1 lst a m bound-m))
(<= (occur-cnt-bounded-lst term1 lst a m bound-m)
(+ bound-m m))))
:rule-classes :linear
:hints (("Goal" ; :in-theory (theory 'minimal-theory)
:use ((:instance signed-byte-p-30-occur-cnt-bounded-flg
(flg 'list)))))))
(verify-guards occur-cnt-bounded)
(verify-termination-boot-strap too-many-ifs1) ; and guards
(verify-termination-boot-strap too-many-ifs-post-rewrite-builtin) ; and guards
)
(defattach too-many-ifs-post-rewrite too-many-ifs-post-rewrite-builtin)
; Complete too-many-ifs-pre-rewrite.
#+acl2-loop-only
; The above readtime conditional avoids a CLISP warning, and lets the defproxy
; for print-clause-id-okp provide the raw Lisp definition.
(encapsulate
((too-many-ifs-pre-rewrite (args counts) t
:guard
(and (pseudo-term-listp args)
(integer-listp counts)
(equal (len args) (len counts)))))
(local (defun too-many-ifs-pre-rewrite (args counts)
(list args counts))))
(defattach (too-many-ifs-pre-rewrite too-many-ifs-pre-rewrite-builtin))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Attachment: ancestors-check, worse-than, worse-than-or-equal
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(verify-termination-boot-strap pseudo-variantp)
(verify-termination-boot-strap member-char-stringp)
(verify-termination-boot-strap terminal-substringp1)
(verify-termination-boot-strap terminal-substringp)
(verify-termination-boot-strap evg-occur)
(verify-termination-boot-strap min-fixnum)
(verify-termination-boot-strap fn-count-evg-rec ; but not guards
(declare (xargs :verify-guards nil)))
(defthm fn-count-evg-rec-type-prescription
(implies (natp acc)
(natp (fn-count-evg-rec evg acc calls)))
:rule-classes :type-prescription)
(defthm fn-count-evg-rec-bound
(< (fn-count-evg-rec evg acc calls)
536870912) ; (expt 2 29)
:rule-classes :linear)
(verify-guards fn-count-evg-rec)
(verify-termination-boot-strap occur)
(verify-termination-boot-strap worse-than-builtin-clocked) ; and mut-rec nest
(verify-termination-boot-strap worse-than-builtin)
(verify-termination-boot-strap worse-than-or-equal-builtin)
(verify-termination-boot-strap ancestor-listp)
(verify-termination-boot-strap earlier-ancestor-biggerp)
(verify-termination-boot-strap fn-count-1) ; but not guards
(defthm fn-count-1-type
(implies (and (integerp fn-count-acc)
(integerp p-fn-count-acc))
(and (integerp (car (fn-count-1 flag term
fn-count-acc p-fn-count-acc)))
(integerp (mv-nth 0 (fn-count-1 flag term
fn-count-acc
p-fn-count-acc)))
(integerp (mv-nth 1 (fn-count-1 flag term
fn-count-acc
p-fn-count-acc)))
(integerp (nth 0 (fn-count-1 flag term
fn-count-acc
p-fn-count-acc)))
(integerp (nth 1 (fn-count-1 flag term
fn-count-acc
p-fn-count-acc)))))
:rule-classes ((:forward-chaining
:trigger-terms
((fn-count-1 flag term fn-count-acc p-fn-count-acc)))))
(verify-guards fn-count-1)
(verify-termination-boot-strap var-fn-count-1) ; but not guards
(defthm symbol-listp-cdr-assoc-equal
(implies (symbol-list-listp x)
(symbol-listp (cdr (assoc-equal key x)))))
; We state the following three rules in all forms that we think might be useful
; to those who want to reason about var-fn-count-1, for example if they are
; developing attachments to ancestors-check.
(defthm integerp-nth-0-var-fn-count-1
(implies (integerp var-count-acc)
(integerp (nth 0 (var-fn-count-1
flg x
var-count-acc fn-count-acc p-fn-count-acc
invisible-fns invisible-fns-table))))
:rule-classes
((:forward-chaining
:trigger-terms
((var-fn-count-1 flg x var-count-acc fn-count-acc
p-fn-count-acc invisible-fns
invisible-fns-table))
:corollary
(implies (integerp var-count-acc)
(and (integerp (nth 0 (var-fn-count-1
flg x
var-count-acc fn-count-acc p-fn-count-acc
invisible-fns invisible-fns-table)))
(integerp (mv-nth 0 (var-fn-count-1
flg x
var-count-acc fn-count-acc p-fn-count-acc
invisible-fns invisible-fns-table)))
(integerp (car (var-fn-count-1
flg x
var-count-acc fn-count-acc p-fn-count-acc
invisible-fns invisible-fns-table))))))))
(defthm integerp-nth-1-var-fn-count-1
(implies (integerp fn-count-acc)
(integerp (nth 1 (var-fn-count-1
flg x
var-count-acc fn-count-acc p-fn-count-acc
invisible-fns invisible-fns-table))))
:rule-classes
((:forward-chaining
:trigger-terms
((var-fn-count-1 flg x var-count-acc fn-count-acc
p-fn-count-acc invisible-fns
invisible-fns-table))
:corollary
(implies (integerp fn-count-acc)
(and (integerp (nth 1 (var-fn-count-1
flg x
var-count-acc fn-count-acc p-fn-count-acc
invisible-fns invisible-fns-table)))
(integerp (mv-nth 1 (var-fn-count-1
flg x
var-count-acc fn-count-acc p-fn-count-acc
invisible-fns invisible-fns-table))))))))
(defthm integerp-nth-2-var-fn-count-1
(implies (integerp p-fn-count-acc)
(integerp (nth 2 (var-fn-count-1
flg x
var-count-acc fn-count-acc p-fn-count-acc
invisible-fns invisible-fns-table))))
:rule-classes
((:forward-chaining
:trigger-terms
((var-fn-count-1 flg x var-count-acc fn-count-acc
p-fn-count-acc invisible-fns
invisible-fns-table))
:corollary
(implies (integerp p-fn-count-acc)
(and (integerp (nth 2 (var-fn-count-1
flg x
var-count-acc fn-count-acc p-fn-count-acc
invisible-fns invisible-fns-table)))
(integerp (mv-nth 2 (var-fn-count-1
flg x
var-count-acc fn-count-acc p-fn-count-acc
invisible-fns invisible-fns-table))))))))
(verify-guards var-fn-count-1)
(verify-termination-boot-strap equal-mod-commuting) ; and guards
(verify-termination-boot-strap ancestors-check1)
(verify-termination-boot-strap ancestors-check-builtin)
(defun member-equal-mod-commuting (x lst wrld)
(declare (xargs :guard (and (pseudo-termp x)
(pseudo-term-listp lst)
(plist-worldp wrld))))
(cond ((endp lst) nil)
((equal-mod-commuting x (car lst) wrld) lst)
(t (member-equal-mod-commuting x (cdr lst) wrld))))
; In the following, terms (nth 0 ...) and (nth 1 ...) in the hints were
; originally (car ...) and (mv-nth 1 ...), respectively, but those didn't
; work. It would be good at some point to explore why not, given that the
; original versions worked outside the build.
(defun strip-ancestor-literals (ancestors)
(declare (xargs :guard (ancestor-listp ancestors)))
(cond ((endp ancestors) nil)
(t (cons (access ancestor (car ancestors) :lit)
(strip-ancestor-literals (cdr ancestors))))))
(encapsulate
()
(local
(defthm ancestors-check1-property
(mv-let (on-ancestors assumed-true)
(ancestors-check1 lit-atm lit var-cnt fn-cnt p-fn-cnt ancestors
tokens)
(implies (and on-ancestors
assumed-true)
(member-equal-mod-commuting
lit
(strip-ancestor-literals ancestors)
nil)))
:rule-classes nil))
(defthmd ancestors-check-builtin-property
(mv-let (on-ancestors assumed-true)
(ancestors-check-builtin lit ancestors tokens)
(implies (and on-ancestors
assumed-true)
(member-equal-mod-commuting
lit
(strip-ancestor-literals ancestors)
nil)))
:hints (("Goal"
:use
((:instance
ancestors-check1-property
(lit-atm lit)
(var-cnt 0)
(fn-cnt 0)
(p-fn-cnt 0))
(:instance
ancestors-check1-property
(lit-atm lit)
(var-cnt (nth 0 (var-fn-count-1 nil lit 0 0 0 nil nil)))
(fn-cnt (nth 1 (var-fn-count-1 nil lit 0 0 0 nil nil)))
(p-fn-cnt (nth 2 (var-fn-count-1 nil lit 0 0 0 nil nil))))
(:instance
ancestors-check1-property
(lit-atm (cadr lit))
(var-cnt (nth 0 (var-fn-count-1 nil (cadr lit) 0 0 0 nil nil)))
(fn-cnt (nth 1 (var-fn-count-1 nil (cadr lit) 0 0 0 nil nil)))
(p-fn-cnt (nth 2
(var-fn-count-1 nil (cadr lit) 0 0 0
nil nil)))))))))
#+acl2-loop-only
; The above readtime conditional avoids a CLISP warning, and lets the defproxy
; for print-clause-id-okp provide the raw Lisp definition.
(encapsulate
((ancestors-check (lit ancestors tokens) (mv t t)
:guard (and (pseudo-termp lit)
(ancestor-listp ancestors)
(true-listp tokens))))
(local (defun ancestors-check (lit ancestors tokens)
(ancestors-check-builtin lit ancestors tokens)))
(defthmd ancestors-check-constraint
(implies (and (pseudo-termp lit)
(ancestor-listp ancestors)
(true-listp tokens))
(mv-let (on-ancestors assumed-true)
(ancestors-check lit ancestors tokens)
(implies (and on-ancestors
assumed-true)
(member-equal-mod-commuting
lit
(strip-ancestor-literals ancestors)
nil))))
:hints (("Goal" :use ancestors-check-builtin-property))))
(defattach (ancestors-check ancestors-check-builtin)
:hints (("Goal" :by ancestors-check-builtin-property)))
(defattach worse-than worse-than-builtin)
(defattach worse-than-or-equal worse-than-or-equal-builtin)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Attachment: acl2x-expansion-alist
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(verify-termination-boot-strap hons-copy-with-state) ; and guards
(verify-termination-boot-strap identity-with-state) ; and guards
(defattach (acl2x-expansion-alist
; User-modifiable; see comment in the defstub introducing
; acl2x-expansion-alist.
identity-with-state))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Attachments: rw-cache utilities
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(verify-termination-boot-strap rw-cache-debug-builtin) ; and guards
(defattach rw-cache-debug rw-cache-debug-builtin)
(verify-termination-boot-strap rw-cache-debug-action-builtin) ; and guards
(defattach rw-cache-debug-action rw-cache-debug-action-builtin)
(verify-termination-boot-strap rw-cacheable-failure-reason-builtin) ; and guards
(defattach rw-cacheable-failure-reason rw-cacheable-failure-reason-builtin)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Attachments: print-clause-id-okp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(verify-termination-boot-strap all-digits-p) ; and guards
(verify-termination-boot-strap ; and guards
(d-pos-listp
(declare
(xargs
:guard-hints
(("Goal"
:use ((:instance coerce-inverse-2
(x (symbol-name (car lst))))
(:instance character-listp-coerce
(str (symbol-name (car lst)))))
:expand ((len (coerce (symbol-name (car lst)) 'list)))
:in-theory (disable coerce-inverse-2
character-listp-coerce)))))))
(verify-termination-boot-strap pos-listp)
(verify-guards pos-listp)
(defthm d-pos-listp-forward-to-true-listp
(implies (d-pos-listp x)
(true-listp x))
:rule-classes :forward-chaining)
(verify-termination-boot-strap clause-id-p) ; and guards
#+acl2-loop-only
; The above readtime conditional avoids a CLISP warning, and lets the defproxy
; for print-clause-id-okp provide the raw Lisp definition.
(encapsulate
(((print-clause-id-okp *) => * :formals (cl-id) :guard (clause-id-p cl-id)))
(local (defun print-clause-id-okp (x)
x)))
(verify-termination-boot-strap print-clause-id-okp-builtin) ; and guards
(defattach print-clause-id-okp print-clause-id-okp-builtin)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Attachments: oncep-tp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; We could avoid the forms below by replacing the earlier forms
; (defproxy oncep-tp (* *) => *)
; (defun oncep-tp-builtin ...) ; :guard t
; (defattach (oncep-tp oncep-tp-builtin) :skip-checks t)
; in place, by changing defproxy to defstub and removing :skip-checks t.
; However, the guard on once-tp would then be left with a guard of t, which
; might be stronger than we'd like.
#+acl2-loop-only
; The above readtime conditional avoids a CLISP warning, and lets the defproxy
; for print-clause-id-okp provide the raw Lisp definition.
(encapsulate
(((oncep-tp * *) => *
:formals (rune wrld)
:guard (and (plist-worldp wrld)
; Although (runep rune wrld) is appropriate here, we don't want to fight the
; battle yet of putting runep into :logic mode. So we just lay down the
; syntactic part of its code, which should suffice for user-defined attachments
; to oncep-tp.
(and (consp rune)
(consp (cdr rune))
(symbolp (cadr rune))))))
(logic)
(local (defun oncep-tp (rune wrld)
(oncep-tp-builtin rune wrld))))
(defattach oncep-tp oncep-tp-builtin)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; verify-termination and guard verification:
; string-for-tilde-@-clause-id-phrase and some subsidiary functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; David Rager proved termination and guards for
; string-for-tilde-@-clause-id-phrase, with a proof that included community
; books unicode/explode-atom and unicode/explode-nonnegative-integer. Here, we
; rework that proof a bit to avoid those dependencies. Note that this proof
; depends on d-pos-listp, whose termination and guard verification are
; performed above.
; We proved true-listp-explode-nonnegative-integer here, but then found it was
; already proved locally in axioms.lisp. So we made that defthm non-local (and
; strengthened it to its current form).
(verify-termination-boot-strap chars-for-tilde-@-clause-id-phrase/periods)
(verify-termination-boot-strap chars-for-tilde-@-clause-id-phrase/primes)
(defthm pos-listp-forward-to-integer-listp
(implies (pos-listp x)
(integer-listp x))
:rule-classes :forward-chaining)
(verify-termination-boot-strap chars-for-tilde-@-clause-id-phrase)
(defthm true-listp-chars-for-tilde-@-clause-id-phrase/periods
(true-listp (chars-for-tilde-@-clause-id-phrase/periods lst))