-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprove.lisp
8290 lines (7293 loc) · 362 KB
/
prove.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.6 -- A Computational Logic for Applicative Common Lisp
; Copyright (C) 2025, 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: [email protected] and [email protected]
; Department of Computer Science
; University of Texas at Austin
; Austin, TX 78712 U.S.A.
(in-package "ACL2")
; Section: PUSH-CLAUSE and The Pool
; At the opposite end of the waterfall from the preprocessor is push-clause,
; where we actually put a clause into the pool. We develop it now.
(defun more-than-simplifiedp (hist)
; Return t if hist contains a process besides simplify-clause (and its
; mates settled-down-clause and preprocess-clause), where we don't count
; certain top-level hints: :OR, or top-level hints that create hidden clauses.
(cond ((null hist) nil)
((member-eq (caar hist) '(settled-down-clause
simplify-clause
preprocess-clause))
(more-than-simplifiedp (cdr hist)))
((eq (caar hist) 'apply-top-hints-clause)
(if (or (tagged-objectsp 'hidden-clause
(access history-entry (car hist) :ttree))
(tagged-objectsp ':or
(access history-entry (car hist) :ttree)))
(more-than-simplifiedp (cdr hist))
t))
(t t)))
(defun remove1-assoc-eq-lst (lst alist)
(declare (xargs :guard (if (symbol-listp lst)
(alistp alist)
(symbol-alistp alist))))
(if (consp lst)
(remove1-assoc-eq-lst (cdr lst)
(remove1-assoc-eq (car lst) alist))
alist))
(defun delete-assumptions-1 (recs only-immediatep)
; See comment for delete-assumptions. This function returns (mv changedp
; new-recs), where if changedp is nil then new-recs equals recs.
(cond ((endp recs) (mv nil nil))
(t (mv-let (changedp new-cdr-recs)
(delete-assumptions-1 (cdr recs) only-immediatep)
(cond ((cond
((eq only-immediatep 'non-nil)
(access assumption (car recs) :immediatep))
((eq only-immediatep 'case-split)
(eq (access assumption (car recs) :immediatep)
'case-split))
((eq only-immediatep t)
(eq (access assumption (car recs) :immediatep)
t))
(t t))
(mv t new-cdr-recs))
(changedp
(mv t
(cons (car recs) new-cdr-recs)))
(t (mv nil recs)))))))
(defun delete-assumptions (ttree only-immediatep)
; We delete the assumptions in ttree. We give the same interpretation to
; only-immediatep as in collect-assumptions.
(let ((objects (tagged-objects 'assumption ttree)))
(cond (objects
(mv-let
(changedp new-objects)
(delete-assumptions-1 objects only-immediatep)
(cond ((null changedp) ttree)
(new-objects
(extend-tag-tree
'assumption
new-objects
(remove-tag-from-tag-tree! 'assumption ttree)))
(t (remove-tag-from-tag-tree! 'assumption ttree)))))
(t ttree))))
#+acl2-par
(defun save-and-print-acl2p-checkpoint (cl-id prettyified-clause
old-pspv-pool-lst forcing-round
state)
; We almost note that we are changing the global state of the program by
; returning a modified state. However, we manually ensure that this global
; change is thread-safe by calling with-acl2p-checkpoint-saving-lock, and so
; instead, we give ourselves the Okay to call f-put-global@par.
(declare (ignorable cl-id prettyified-clause state))
(let* ((new-pair (cons cl-id prettyified-clause))
(newp
(with-acl2p-checkpoint-saving-lock
(cond
((member-equal new-pair (f-get-global 'acl2p-checkpoints-for-summary
state))
nil)
(t
(prog2$
(f-put-global@par 'acl2p-checkpoints-for-summary
(cons new-pair
(f-get-global
'acl2p-checkpoints-for-summary state))
state)
t))))))
(and
newp
(with-output-lock
(progn$
(cw "~%~%([ An ACL2(p) key checkpoint:~%~%~s0~%"
(string-for-tilde-@-clause-id-phrase cl-id))
(cw "~x0" prettyified-clause)
; Parallelism no-fix: we are encountering a problem that we've known about from
; within the first few months of looking at parallelizing the waterfall. When
; two sibling subgoals both push for induction, the second push doesn't know
; about the first proof's push in parallel mode. So, the number of the second
; proof (e.g., *1.2) gets printed as if the first push hasn't happened (e.g.,
; *1.2 gets mistakenly called *1.1). Rather than fix this (the problem is
; inherent to the naming scheme of ACL2), we punt and say what the name _could_
; be (e.g., we print *1.1 for what's really *1.2). The following non-theorem
; showcases this problem. See :doc topic set-waterfall-printing.
; (thm (equal (append (car (cons x x)) y z) (append x x y)))
; The sentence in the following cw call concerning the halting of the proof
; attempt is motivated by the following example -- which is relevant because
; ACL2(p) with :limited waterfall-printing does not print a message that says
; the :do-not-induct hint causes the proof to abort.
; (thm (equal (append x (append y z)) (append (append x y) z))
; :hints (("Goal" :do-not-induct t)))
(cw "~%~%The above subgoal may cause a goal to be pushed for proof by ~
induction. The pushed goal's new name might be ~@0. Note that ~
we may instead decide (either now or later) to prove the original ~
conjecture by induction. Also note that if a hint indicates that ~
this subgoal or the original conjecture should not be proved by ~
induction, the proof attempt will halt.~%~%])~%~%"
(tilde-@-pool-name-phrase
forcing-round
old-pspv-pool-lst)))))))
#+acl2-par
(defun find-the-first-checkpoint (h checkpoint-processors)
; "H" is the history reversed, which really means h is in the order that the
; entries were added. E.g. the history entry for subgoal 1.2 is before the
; entry for 1.1.4. To remind us that this is not the "standard ACL2 history"
; (which is often in the other order), we name the variable "h" instead of
; "hist."
(cond ((atom h) ; occurs when we are at the top-level goal
nil)
((atom (cdr h))
(car h)) ; maybe this should also be an error
((member (access history-entry (cadr h) :processor)
checkpoint-processors)
(car h))
; Parallelism blemish: we haven't thought through how specious entries affect
; this function. The following code is left as a hint at what might be needed.
; ((or (and (consp (access history-entry (cadr h) :processor))
; (equal (access history-entry (cadr h) :processor)
; 'specious))
(t (find-the-first-checkpoint (cdr h) checkpoint-processors))))
#+acl2-par
(defun acl2p-push-clause-printing (cl hist pspv wrld state)
(cond
((null cl)
; The following non-theorem illustrates the case where we generate the clause
; nil, and instead of printing the associated key checkpoint, we inform the
; user that nil was generated from that checkpoint.
; (thm (equal (append (car (cons x x)) y z) (append x x y)))
(cw "~%~%A goal of ~x0 has been generated! Obviously, the proof attempt ~
has failed.~%"
cl))
(t
(let* ((hist-entry
(find-the-first-checkpoint
(reverse hist)
(f-get-global 'checkpoint-processors state)))
(checkpoint-clause
(or (access history-entry hist-entry :clause)
; We should be able to add an assertion that, if the hist-entry is nil (and
; thus, the :clause field of hist-entry is also nil), cl always has the same
; printed representation as the original conjecture. However, since we do not
; have access to the original conjecture in this function, we avoid such an
; assertion.
cl))
(cl-id (access history-entry hist-entry :cl-id))
(cl-id (if cl-id cl-id *initial-clause-id*))
(forcing-round (access clause-id cl-id :forcing-round))
(old-pspv-pool-lst
(pool-lst (cdr (access prove-spec-var pspv :pool))))
(prettyified-clause (prettyify-clause checkpoint-clause
(let*-abstractionp state)
wrld)))
(save-and-print-acl2p-checkpoint cl-id prettyified-clause
old-pspv-pool-lst forcing-round
state)))))
(defun induction-depth-limit (wrld)
(cdr (assoc-eq t (table-alist 'induction-depth-limit-table wrld))))
(defun@par push-clause (cl-id cl hist pspv wrld state)
; Roughly speaking, we drop cl into the pool of pspv and return.
; However, we sometimes cause the waterfall to abort further
; processing (either to go straight to induction or to fail) and we
; also sometimes choose to push a different clause into the pool. We
; even sometimes miss and let the waterfall fall off the end of the
; ledge! We make this precise in the code below.
; The pool is actually a list of pool-elements and is treated as a
; stack. The clause-set is a set of clauses and is almost always a
; singleton set. The exception is when it contains the clausification
; of the user's initial conjecture.
; The expected tags are:
; 'TO-BE-PROVED-BY-INDUCTION - the clause set is to be given to INDUCT
; 'BEING-PROVED-BY-INDUCTION - the clause set has been given to INDUCT and
; we are working on its subgoals now.
; Like all clause processors, we return four values: the signal,
; which is either 'hit, 'miss or 'abort, the new set of clauses, in this
; case nil, the ttree for whatever action we take, and the new
; value of pspv (containing the new pool).
; Warning: Generally speaking, this function either 'HITs or 'ABORTs.
; But it is here that we look out for :DO-NOT-INDUCT name hints. For
; such hints we want to act like a :BY name-clause-id was present for
; the clause. But we don't know the clause-id and the :BY handling is
; so complicated we don't want to reproduce it. So what we do instead
; is 'MISS and let the waterfall fall off the ledge to the nil ledge.
; See waterfall0. This function should NEVER return a 'MISS unless
; there is a :DO-NOT-INDUCT name hint present in the hint-settings,
; since waterfall0 assumes that it falls off the ledge only in that
; case.
(declare (ignorable state wrld)) ; actually ignored in #-acl2-par
(prog2$
; Every branch of the cond below, with the exception of when cl is null,
; results in an ACL2(p) key checkpoint. As such, it is reasonable to print the
; checkpoint at the very beginning of this function.
; Acl2p-push-clause-printing contains code that handles the case where cl is
; nil.
; Parallelism blemish: create a :doc topic on ACL2(p) checkpoints and reference
; it in the above comment.
(parallel-only@par (acl2p-push-clause-printing cl hist pspv wrld state))
(let ((pool (access prove-spec-var pspv :pool))
(do-not-induct-hint-val
(cdr (assoc-eq :do-not-induct
(access prove-spec-var pspv :hint-settings)))))
(cond
((null cl)
; The empty clause was produced. Stop the waterfall by aborting. Produce the
; ttree that explains the abort. Drop the clause set containing the empty
; clause into the pool so that when we look for the next goal we see it and
; quit.
(mv 'abort
nil
(add-to-tag-tree! 'abort-cause 'empty-clause nil)
(change prove-spec-var pspv
:pool (cons (make pool-element
:tag 'TO-BE-PROVED-BY-INDUCTION
:clause-set '(nil)
:hint-settings nil)
pool))))
((and do-not-induct-hint-val
(not (member-eq do-not-induct-hint-val '(t :otf :otf-flg-override)))
(not (assoc-eq :induct
(access prove-spec-var pspv :hint-settings))))
; In this case, we have seen a :DO-NOT-INDUCT name hint (where name isn't t)
; that is not overridden by an :INDUCT hint. We would like to give this clause
; a :BY. We can't do it here, as explained above. So we will 'MISS instead.
(mv 'miss nil nil nil))
((and (or (and (not (access prove-spec-var pspv :otf-flg))
(eq do-not-induct-hint-val t))
(eq do-not-induct-hint-val :otf-flg-override)
(let ((limit (induction-depth-limit wrld)))
; It is tempting just to use eql instead of <= below. But a hint of :induct t
; takes priority, in which case we want to stop the next level of induction,
; where we have already exceeded the "maximum".
(and limit
(<= limit
(length (access clause-id cl-id :pool-lst))))))
(not (assoc-eq :induct (access prove-spec-var pspv
:hint-settings))))
; We need induction but can't use it. Stop the waterfall by aborting. Produce
; the ttree that explains the abort. Drop the clause set containing the empty
; clause into the pool so that when we look for the next goal we see it and
; quit. Note that if :otf-flg is specified, then we skip this case because we
; do not want to quit just yet. We will see the :do-not-induct value again in
; prove-loop1 when we return to the goal we are pushing.
(mv 'abort
nil
(add-to-tag-tree! 'abort-cause
(cond
((eq do-not-induct-hint-val :otf-flg-override)
'do-not-induct-otf-flg-override)
((and (not (access prove-spec-var pspv :otf-flg))
(eq do-not-induct-hint-val t))
'do-not-induct)
(t
'induction-depth-limit-exceeded))
nil)
(change prove-spec-var pspv
:pool (cons (make pool-element
:tag 'TO-BE-PROVED-BY-INDUCTION
:clause-set '(nil)
:hint-settings nil)
pool))))
((and (not (access prove-spec-var pspv :otf-flg))
(not (eq do-not-induct-hint-val :otf))
(or
(and (null pool) ;(a)
(more-than-simplifiedp hist)
(not (assoc-eq :induct (access prove-spec-var pspv
:hint-settings))))
(and pool ;(b)
(not (assoc-eq 'being-proved-by-induction pool))
(not (assoc-eq :induct (access prove-spec-var pspv
:hint-settings))))))
; We have not been told to press Onward Thru the Fog and
; either (a) this is the first time we've ever pushed anything and we have
; applied processes other than simplification to it and we have not been
; explicitly instructed to induct for this formula, or (b) we have already put
; at least one goal into the pool but we have not yet done our first induction
; and we are not being explicitly instructed to induct for this formula.
; Stop the waterfall by aborting. Produce the ttree explaining the abort.
; Drop the clausification of the user's input into the pool in place of
; everything else in the pool.
; Note: We once reverted to the output of preprocess-clause in prove. However,
; preprocess (and clausify-input) applies unconditional :REWRITE rules and we
; want users to be able to type exactly what the system should go into
; induction on. The theorem that preprocess-clause screwed us on was HACK1.
; It screwed us by distributing * and GCD.
(mv 'abort
nil
(add-to-tag-tree! 'abort-cause 'revert nil)
(change prove-spec-var pspv
; Before Version_2.6 we did not modify the tag-tree here. The result was that
; assumptions created by forcing before reverting to the original goal still
; generated forcing rounds after the subsequent proof by induction. When this
; bug was discovered we added code below to use delete-assumptions to remove
; assumptions from the tag-tree. Note that we are not modifying the
; 'accumulated-ttree in state, so these assumptions still reside there; but
; since that ttree is only used for reporting rules used and is intended to
; reflect the entire proof attempt, this decision seems reasonable.
; Version_2.6 was released on November 29, 2001. On January 18, 2002, we
; received email from Francisco J. Martin-Mateos reporting a soundness bug,
; with an example that is included after the definition of push-clause. The
; problem turned out to be that we did not remove :use and :by tagged values
; from the tag-tree here. The result was that if the early part of a
; successful proof attempt had involved a :use or :by hint but then the early
; part was thrown away and we reverted to the original goal, the :use or :by
; tagged value remained in the tag-tree. When the proof ultimately succeeded,
; this tagged value was used to update (global-val
; 'proved-functional-instances-alist (w state)), which records proved
; constraints so that subsequent proofs can avoid proving them again. But
; because the prover reverted to the original goal rather than taking advantage
; of the :use hint, those constraints were not actually proved in this case and
; might not be valid!
; So, we have decided that rather than remove assumptions and :by/:use tags
; from the :tag-tree of pspv, we would just replace that tag-tree by the empty
; tag-tree. We do not want to get burned by a third such problem!
:tag-tree nil
:pool (list (make pool-element
:tag 'TO-BE-PROVED-BY-INDUCTION
:clause-set
; At one time we clausified here. But some experiments suggested that the
; prover can perhaps do better by simply doing its thing on each induction
; goal, starting at the top of the waterfall. So, now we pass the same clause
; to induction as it would get if there were a hint of the form ("Goal" :induct
; term), where term is the user-supplied-term.
(list (list
(access prove-spec-var pspv
:user-supplied-term)))
; Below we set the :hint-settings for the input clause, doing exactly what
; find-applicable-hint-settings does. Unfortunately, we haven't defined that
; function yet. Fortunately, it's just a simple assoc-equal. In addition,
; that function goes on to compute a second value we don't need here. So
; rather than go to the bother of moving its definition up to here we just open
; code the part we need. We also remove top-level hints that were supposed to
; apply before we got to push-clause.
:hint-settings
(remove1-assoc-eq-lst
(cons ':reorder *top-hint-keywords*)
; We could also delete :induct, but we know it's not here!
(cdr
(assoc-equal
*initial-clause-id*
(access prove-spec-var pspv
:orig-hints)))))))))
#+acl2-par
((and (serial-first-form-parallel-second-form@par nil t)
(not (access prove-spec-var pspv :otf-flg))
(not (eq do-not-induct-hint-val :otf))
(null pool)
;; (not (more-than-simplifiedp hist)) ; implicit to the cond
(not (assoc-eq :induct (access prove-spec-var pspv
:hint-settings))))
(mv 'hit
nil
(add-to-tag-tree! 'abort-cause 'maybe-revert nil)
(change prove-spec-var pspv
; Parallelism blemish: there may be a bug in ACL2(p) related to the comment
; above (in this function's definition) that starts with "Before Version_2.6 we
; did not modify the tag-tree here." To fix this (likely) bug, don't reset the
; tag-tree here -- just remove the ":tag-tree nil" -- and instead do it when we
; convert a maybe-to-be-proved-by-induction to a to-be-proved-by-induction.
:tag-tree nil
:pool
(append
(list
(list 'maybe-to-be-proved-by-induction
(make pool-element
:tag 'TO-BE-PROVED-BY-INDUCTION
:clause-set (list cl)
:hint-settings (access prove-spec-var pspv
:hint-settings))
(make pool-element
:tag 'TO-BE-PROVED-BY-INDUCTION
:clause-set
; See above comment that starts with "At one time we clausified here."
(list (list
(access prove-spec-var pspv
:user-supplied-term)))
; See above comment that starts with "Below we set the :hint-settings for..."
:hint-settings
(remove1-assoc-eq-lst
(cons ':reorder *top-hint-keywords*)
; We could also delete :induct, but we know it's not here!
(cdr
(assoc-equal
*initial-clause-id*
(access prove-spec-var pspv
:orig-hints)))))))
pool))))
(t (mv 'hit
nil
nil
(change prove-spec-var pspv
:pool
(cons
(make pool-element
:tag 'TO-BE-PROVED-BY-INDUCTION
:clause-set (list cl)
:hint-settings (access prove-spec-var pspv
:hint-settings))
pool))))))))
; Below is the soundness bug example reported by Francisco J. Martin-Mateos.
; ;;;============================================================================
;
; ;;;
; ;;; A bug in ACL2 (2.5 and 2.6). Proving "0=1".
; ;;; Francisco J. Martin-Mateos
; ;;; email: [email protected]
; ;;; Dpt. of Computer Science and Artificial Intelligence
; ;;; University of SEVILLE
; ;;;
; ;;;============================================================================
;
; ;;; I've found a bug in ACL2 (2.5 and 2.6). The following events prove that
; ;;; "0=1".
;
; (in-package "ACL2")
;
; (encapsulate
; (((g1) => *))
;
; (local
; (defun g1 ()
; 0))
;
; (defthm 0=g1
; (equal 0 (g1))
; :rule-classes nil))
;
; (defun g1-lst (lst)
; (cond ((endp lst) (g1))
; (t (g1-lst (cdr lst)))))
;
; (defthm g1-lst=g1
; (equal (g1-lst lst) (g1)))
;
; (encapsulate
; (((f1) => *))
;
; (local
; (defun f1 ()
; 1)))
;
; (defun f1-lst (lst)
; (cond ((endp lst) (f1))
; (t (f1-lst (cdr lst)))))
;
; (defthm f1-lst=f1
; (equal (f1-lst lst) (f1))
; :hints (("Goal"
; :use (:functional-instance g1-lst=g1
; (g1 f1)
; (g1-lst f1-lst)))))
;
; (defthm 0=f1
; (equal 0 (f1))
; :rule-classes nil
; :hints (("Goal"
; :use (:functional-instance 0=g1
; (g1 f1)))))
;
; (defthm 0=1
; (equal 0 1)
; :rule-classes nil
; :hints (("Goal"
; :use (:functional-instance 0=f1
; (f1 (lambda () 1))))))
;
; ;;; The theorem F1-LST=F1 is not proved via functional instantiation but it
; ;;; can be proved via induction. So, the constraints generated by the
; ;;; functional instantiation hint has not been proved. But when the theorem
; ;;; 0=F1 is considered, the constraints generated in the functional
; ;;; instantiation hint are bypassed because they ".. have been proved when
; ;;; processing the event F1-LST=F1", and the theorem is proved !!!. Finally,
; ;;; an instance of 0=F1 can be used to prove 0=1.
;
; ;;;============================================================================
; We now develop the functions for reporting what push-clause did. Except,
; pool-lst has already been defined, in support of proof-trees.
(defun push-clause-msg1-abort (cl-id ttree pspv state)
; Ttree has exactly one object associated with the tag 'abort-cause.
(let ((temp (tagged-object 'abort-cause ttree))
(cl-id-phrase (tilde-@-clause-id-phrase cl-id))
(gag-mode (gag-mode)))
(case temp
(empty-clause
(if gag-mode
(msg "A goal of NIL, ~@0, has been generated! Obviously, the ~
proof attempt has failed.~|"
cl-id-phrase)
""))
((do-not-induct do-not-induct-otf-flg-override)
(msg "Normally we would attempt to prove ~@0 by induction. However, a ~
:DO-NOT-INDUCT hint was supplied to abort the proof attempt.~|"
cl-id-phrase
(if (eq temp 'do-not-induct)
t
:otf-flg-override)))
(induction-depth-limit-exceeded
(msg "Normally we would attempt to prove ~@0 by induction. However, ~
that would cause the induction-depth-limit of ~x1 to be ~
exceeded. See :DOC induction-depth-limit.~|"
cl-id-phrase
(length (access clause-id cl-id :pool-lst))))
(otherwise
(msg "Normally we would attempt to prove ~@0 by induction. However, ~
we prefer in this instance to focus on the original input ~
conjecture rather than this simplified special case. We ~
therefore abandon our previous work on this conjecture and ~
reassign the name ~@1 to the original conjecture. (See :DOC ~
otf-flg.)~#2~[~/ [Note: Thanks again for the hint.]~]~|"
cl-id-phrase
(tilde-@-pool-name-phrase
(access clause-id cl-id :forcing-round)
(pool-lst
(cdr (access prove-spec-var pspv
:pool))))
(if (and (not gag-mode)
(access prove-spec-var pspv
:hint-settings))
1
0))))))
(defun push-clause-msg1 (cl-id signal clauses ttree pspv state)
; Push-clause was given a clause and produced a signal and ttree. We
; are responsible for printing out an explanation of what happened.
; We look at the ttree to determine what happened. We return state.
(declare (ignore clauses))
(cond ((eq signal 'abort)
(fms "~@0"
(list (cons #\0 (push-clause-msg1-abort cl-id ttree pspv state)))
(proofs-co state)
state
nil))
(t
(fms "Name the formula above ~@0.~|"
(list (cons #\0 (tilde-@-pool-name-phrase
(access clause-id cl-id :forcing-round)
(pool-lst
(cdr (access prove-spec-var pspv
:pool))))))
(proofs-co state)
state
nil))))
; Section: Use and By hints
(defun clause-set-subsumes-1 (init-subsumes-count cl-set1 cl-set2 acc)
; We return t if the first set of clauses subsumes the second in the sense that
; for every member of cl-set2 there exists a member of cl-set1 that subsumes
; it. We return '? if we don't know (but this can only happen if
; init-subsumes-count is non-nil); see the comment in subsumes.
(cond ((null cl-set2) acc)
(t (let ((temp (some-member-subsumes init-subsumes-count
cl-set1 (car cl-set2) nil)))
(and temp ; thus t or maybe, if init-subsumes-count is non-nil, ?
(clause-set-subsumes-1 init-subsumes-count
cl-set1 (cdr cl-set2) temp))))))
(defun clause-set-subsumes (init-subsumes-count cl-set1 cl-set2)
; This function is intended to be identical, as a function, to
; clause-set-subsumes-1 (with acc set to t). The first two disjuncts are
; optimizations that may often apply.
(or (equal cl-set1 cl-set2)
(and cl-set1
cl-set2
(null (cdr cl-set2))
(subsetp-equal (car cl-set1) (car cl-set2)))
(clause-set-subsumes-1 init-subsumes-count cl-set1 cl-set2 t)))
(defun preprocess-clause? (cl hist pspv wrld state step-limit)
(cond ((member-eq 'preprocess-clause
(assoc-eq :do-not (access prove-spec-var pspv
:hint-settings)))
(mv step-limit 'miss nil nil nil))
(t (preprocess-clause cl hist pspv wrld state step-limit))))
(defun apply-use-hint-clauses (temp clauses pspv wrld state step-limit)
; Note: There is no apply-use-hint-clause. We just call this function
; on a singleton list of clauses.
; Temp is the result of assoc-eq :use in a pspv :hint-settings and is
; non-nil. We discuss its shape below. But this function applies the
; given :use hint to each clause in clauses and returns (mv 'hit
; new-clauses ttree new-pspv).
; Temp is of the form (:USE lmi-lst (hyp1 ... hypn) constraint-cl k
; event-names new-entries) where each hypi is a theorem and
; constraint-cl is a clause that expresses the conjunction of all k
; constraints. Lmi-lst is the list of lmis that generated these hyps.
; Constraint-cl is (probably) of the form {(if constr1 (if constr2 ...
; (if constrk t nil)... nil) nil)}. We add each hypi as a hypothesis
; to each goal clause, cl, and in addition, create one new goal for
; each constraint. Note that we discard the extended goal clause if
; it is a tautology. Note too that the constraints generated by the
; production of the hyps are conjoined into a single clause in temp.
; But we hit that constraint-cl with preprocess-clause to pick out its
; (non-tautological) cases and that code will readily unpack the if
; structure of a typical conjunct. We remove the :use hint from the
; hint-settings so we don't fire the same :use again on the subgoals.
; We return (mv new-step-limit 'hit new-clauses ttree new-pspv).
; The ttree returned has at most two tags. The first is :use and has
; ((lmi-lst hyps constraint-cl k event-names new-entries)
; . non-tautp-applications) as its value, where non-tautp-applications
; is the number of non-tautologous clauses we got by adding the hypi
; to each clause. However, it is possible the :use tag is not
; present: if clauses is nil, we don't report a :use. The optional
; second tag is the ttree produced by preprocess-clause on the
; constraint-cl. If the preprocess-clause is to be hidden anyway, we
; ignore its tree (but use its clauses).
(let* ((hyps (caddr temp))
(constraint-cl (cadddr temp))
(new-pspv (change prove-spec-var pspv
:hint-settings
(remove1-equal temp
(access prove-spec-var
pspv
:hint-settings))))
(A (disjoin-clause-segment-to-clause-set (dumb-negate-lit-lst hyps)
clauses))
(non-tautp-applications (length A)))
; In this treatment, the final set of goal clauses will the union of
; sets A and C. A stands for the "application clauses" (obtained by
; adding the use hyps to each clause) and C stands for the "constraint
; clauses." Non-tautp-applications is |A|.
(cond
((null clauses)
; In this case, there is no point in generating the constraints! We
; anticipate this happening if the user provides both a :use and a
; :cases hint and the :cases hint (which is applied first) proves the
; goal completely. If that were to happen, clauses would be output of
; the :cases hint and pspv would be its output pspv, from which the
; :cases had been deleted. So we just delete the :use hint from that
; pspv and call it quits, without reporting a :use hint at all.
(mv step-limit 'hit nil nil new-pspv))
(t
(sl-let
(signal C ttree irrel-pspv)
(preprocess-clause? constraint-cl nil pspv wrld state step-limit)
(declare (ignore irrel-pspv))
(cond
((eq signal 'miss)
(mv step-limit
'hit
(conjoin-clause-sets
A
(conjoin-clause-to-clause-set constraint-cl
nil))
(add-to-tag-tree! :use
(cons (cdr temp)
non-tautp-applications)
nil)
new-pspv))
((or (tag-tree-occur 'hidden-clause
t
ttree)
(and C
(null (cdr C))
constraint-cl
(null (cdr constraint-cl))
(equal (prettyify-clause-simple (car C))
(car constraint-cl))))
(mv step-limit
'hit
(conjoin-clause-sets A C)
(add-to-tag-tree! :use
(cons (cdr temp)
non-tautp-applications)
nil)
new-pspv))
(t (mv step-limit
'hit
(conjoin-clause-sets A C)
(add-to-tag-tree! :use
(cons (cdr temp)
non-tautp-applications)
(add-to-tag-tree! 'preprocess-ttree
ttree
nil))
new-pspv))))))))
(defun apply-cases-hint-clause (temp cl pspv wrld)
; Temp is the value associated with :cases in a pspv :hint-settings
; and is non-nil. It is thus of the form (:cases term1 ... termn).
; For each termi we create a new clause by adding its negation to the
; goal clause, cl, and in addition, we create a final goal by adding
; all termi. As with a :use hint, we remove the :cases hint from the
; hint-settings so that the waterfall doesn't loop!
; We return (mv 'hit new-clauses ttree new-pspv).
(let ((new-clauses
(remove-trivial-clauses
(conjoin-clause-to-clause-set
(disjoin-clauses
(cdr temp)
cl)
(split-on-assumptions
; We reverse the term-list so the user can see goals corresponding to the
; order of the terms supplied.
(dumb-negate-lit-lst (reverse (cdr temp)))
cl
nil))
wrld)))
(mv 'hit
new-clauses
(add-to-tag-tree! :cases (cons (cdr temp) new-clauses) nil)
(change prove-spec-var pspv
:hint-settings
(remove1-equal temp
(access prove-spec-var
pspv
:hint-settings))))))
(defun non-term-listp-msg (x w)
; Perhaps ~Y01 should be ~y below. If someone complains about a large term
; being printed, consider making that change.
(declare (xargs :guard t))
(cond
((atom x)
(assert$
x
"that fails to satisfy true-listp."))
((not (termp (car x) w))
(msg "that contains the following non-termp (see :DOC term):~|~% ~Y01"
(car x)
nil))
(t (non-term-listp-msg (cdr x) w))))
(defun non-term-list-listp-msg (l w)
; Perhaps ~Y01 should be ~y below. If someone complains about a large term
; being printed, consider making that change.
(declare (xargs :guard t))
(cond
((atom l)
(assert$
l
"which fails to satisfy true-listp."))
((not (term-listp (car l) w))
(msg "which has a member~|~% ~Y01~|~%~@2"
(car l)
nil
(non-term-listp-msg (car l) w)))
(t (non-term-list-listp-msg (cdr l) w))))
(defun all-ffn-symbs-lst-lst (lst ans)
(cond ((null lst) ans)
(t (all-ffn-symbs-lst-lst (cdr lst)
(all-ffn-symbs-lst (car lst) ans)))))
(defun tilde-@-unknown-names-phrase (lst field wrld acc)
; This function returns nil if every element of lst references a known name.
; Otherwise, a message is returned suitable for printing after "..., because ".
(declare (xargs :guard (and (true-listp lst)
(plist-worldp wrld)
(null (collect-non-hint-events lst t)))))
(cond ((endp lst)
(and acc
(msg "its ~x0 field contains the following that ~#1~[does not ~
name an event~/do not name events~]: ~&1"
field acc)))
(t (let ((name (if (symbolp (car lst))
(car lst)
(cadr (car lst)))))
(cond ((getpropc name 'absolute-event-number nil wrld)
(tilde-@-unknown-names-phrase (cdr lst) field wrld acc))
(t (tilde-@-unknown-names-phrase (cdr lst)
field
wrld
(cons name acc))))))))
(defun tilde-@-illegal-hint-events-phrase (lst field wrld)
; This function returns nil if lst is a true list of objects suitable for the
; given summary field, all of whose elements reference a known name.
; Otherwise, a message is returned suitable for printing after "..., because ".
(declare (xargs :guard (and (member-eq field '(:use-names
:by-names
:clause-processor-fns))
(plist-worldp wrld))))
(cond
((not (true-listp lst))
(msg "its ~x0 field, ~x1, is not a true-list"
field
lst))
(t (let* ((non-symbols-okp (member-eq field '(:use-names :by-names)))
(bad (collect-non-hint-events lst non-symbols-okp)))
(cond (bad (msg "its ~x0 field contains the following illegal ~
object~#1~[/s~]: ~&1"
field bad))
(t (tilde-@-unknown-names-phrase lst field wrld nil)))))))
(defun collect-non-runes-from-summary-data (runes wrld)
(declare (xargs :mode :program
:guard ; partial guard
(and (true-listp runes)
(plist-worldp wrld))))
(cond ((endp runes) nil)
((let ((r (car runes)))
(and (consp r)
(consp (cdr r))
(or (null (cadr r)) ; fake rune
(runep r wrld))))
(collect-non-runes-from-summary-data (cdr runes) wrld))
(t (cons (car runes)
(collect-non-runes-from-summary-data (cdr runes) wrld)))))
(defun tilde-@-illegal-summary-data-phrase (x wrld)
; Returns a msg suitable for printing after "is not a valid summary-data
; record: ", which should not include the closing period.
(declare (xargs :mode :program))
(and x ; nil is legal
(or (and (not (weak-summary-data-p x))
(msg "it is not a summary-data record. Use ~x0 to ~
create such a record (see :DOC make-summary-data)"
'make-summary-data))
(let ((runes (access summary-data x :runes)))
(or (and (not (true-listp runes))
(msg "its :runes field, ~x0, is not a true-list"
runes))
(let ((bad (collect-non-runes-from-summary-data runes wrld)))
(and bad
(msg "its :runes field contains the following list of ~
unknown runes: ~x0"
bad)))))
(tilde-@-illegal-hint-events-phrase (access summary-data x
:use-names)
:use-names
wrld)
(tilde-@-illegal-hint-events-phrase (access summary-data x
:by-names)
:by-names
wrld)
(tilde-@-illegal-hint-events-phrase (access summary-data x
:clause-processor-fns)
:clause-processor-fns
wrld))))
(defun eval-clause-processor (clause term stobjs-out verified-p pspv ctx state)
; Verified-p is either nil, t, or a well-formedness-guarantee of the form
; ((name fn thm-name1) . arity-alist).
; Should we do our evaluation in safe-mode? For a relevant discussion, see the
; comment in protected-eval about safe-mode.
; Keep in sync with eval-clause-processor@par.
(revert-world-on-error
(let ((original-wrld (w state))
(cl-term (subst-var (kwote clause) 'clause term)))
(protect-system-state-globals
(mv-let