forked from acl2/acl2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
history-management.lisp
18806 lines (16395 loc) · 805 KB
/
history-management.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.5 -- A Computational Logic for Applicative Common Lisp
; Copyright (C) 2024, 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: Proof Trees
; We develop proof trees in this file, rather than in prove.lisp, because
; print-summary calls print-proof-tree.
; A goal tree is a structure of the following form, with the fields indicated
; below. We put the two non-changing fields at the end; note:
; ACL2 p>:sbt 4
;
; The Binary Trees with Four Tips
; 2.000 ((2 . 2) 2 . 2)
; 2.250 (1 2 3 . 3)
(defrec goal-tree (children processor cl-id . fanout) nil)
; Cl-id is a clause-id record for the name of the goal.
; Children is a list of goal trees whose final cdr is either nil or a positive
; integer. In the latter case, this positive integer indicates the remaining
; number of children for which to build goal trees.
; Fanout is the original number of children.
; Processor is one of the processors from *preprocess-clause-ledge* (except for
; settled-down-clause, which has no use here), except that we have two special
; annotations and two "fictitious" processors.
; Instead of push-clause, we use (push-clause cl-id), where cl-id is the
; clause-id of the clause pushed (e.g., the clause-id corresponding to "*1").
; Except: (push-clause cl-id :REVERT) is used when we are reverting to the
; original goal, and in this case, cl-id always corresponds to *1; also,
; (push-clause cl-id :ABORT) is used when the proof is aborted by push-clause.
; Instead of a processor pr, we may have (pr :forced), which indicates that
; this processor forced assumptions (but remember, some of those might get
; proved during the final clean-up phase). When we enter the next forcing
; round, we will "decorate" the above "processor" by adding a list of new goals
; created by that forcing: (pr :forced clause-id_1 ... clause-id_n). As we go
; along we may prune away some of those new clause ids.
; Finally, occasionally the top-level node in a goal-tree is "fictitious", such
; as the one for "[1]Goal" if the first forcing round presented more than one
; forced goal, and such as any goal to be proved by induction. In that case,
; the "processor" is one of the keyword labels :INDUCT or :FORCING-ROUND or a
; list headed by such keywords, e.g. if we want to say what induction scheme is
; being used.
; A proof tree is simply a non-empty list of goal trees. The "current" goal
; tree is the CAR of the current proof tree; it's the one for the current
; forcing round or proof by induction.
; There is always a current proof tree, (@ proof-tree), except when we are
; inhibiting proof-tree output or are not yet in a proof. The current goal in
; a proof is always the first one associated with the first subtree of the
; current goal-tree that has a non-nil final CDR, via a left-to-right
; depth-first traversal of that tree. We keep the proof tree pruned, trimming
; away proved subgoals and their children.
; The proof tree is printed to the screen, enclosed in #\n\<0 ... #\n\>. We
; start with # because that seems like a rare character, and we want to leave
; emacs as unburdened as possible in its use of string-matching. And, we put a
; newline in front of \ because in ordinary PRINT-like (as opposed to
; PRINC-like) printing, as done by the prover, \ is always quoted and hence
; would not appear in a sequence such as <newline>\?, where ? is any character
; besides \. Naturally, this output can be inhibited, simply by putting
; 'proof-tree on the state global variable inhibit-output-lst. Mike Smith has
; built, and we have modified, a "filter" tool for redirecting such output in a
; nice form to appropriate emacs buffers. People who do not want to use the
; emacs facility (or some other display utility) should probably inhibit
; proof-tree output using :stop-proof-tree.
(defun start-proof-tree-fn (remove-inhibit-p state)
; Note that we do not override existing values of the indicated state global
; variables.
(if remove-inhibit-p
(f-put-global 'inhibit-output-lst
(remove1-eq 'proof-tree
(f-get-global 'inhibit-output-lst state))
state)
state))
#+acl2-loop-only
(defmacro start-proof-tree ()
'(pprogn (start-proof-tree-fn t state)
(fms "Proof tree output is now enabled. Note that ~
:START-PROOF-TREE works by removing 'proof-tree from ~
the inhibit-output-lst; see :DOC ~
set-inhibit-output-lst.~%"
nil
(standard-co state)
state
nil)
(value :invisible)))
#-acl2-loop-only
(defmacro start-proof-tree ()
'(let ((state *the-live-state*))
(fms "IT IS ILLEGAL to invoke (START-PROOF-TREE) from raw Lisp. Please ~
first enter the ACL2 command loop with (LP)."
nil
(proofs-co state)
state
nil)
(values)))
(defmacro checkpoint-forced-goals (val)
`(pprogn (f-put-global 'checkpoint-forced-goals ',val state)
(value ',val)))
(defun stop-proof-tree-fn (state)
(f-put-global 'inhibit-output-lst
(add-to-set-eq 'proof-tree
(f-get-global 'inhibit-output-lst state))
state))
(defmacro stop-proof-tree ()
'(pprogn (stop-proof-tree-fn state)
(fms "Proof tree output is now inhibited. Note that ~
:STOP-PROOF-TREE works by adding 'proof-tree to the ~
inhibit-output-lst; see :DOC set-inhibit-output-lst.~%"
nil
(standard-co state)
state
nil)
(value :invisible)))
(mutual-recursion
(defun insert-into-goal-tree-rec (cl-id processor n goal-tree)
(let ((new-children (insert-into-goal-tree-lst
cl-id processor n
(access goal-tree goal-tree :children))))
(and new-children
(change goal-tree goal-tree
:children new-children))))
(defun insert-into-goal-tree-lst (cl-id processor n goal-tree-lst)
(cond
((consp goal-tree-lst)
(let ((new-child (insert-into-goal-tree-rec
cl-id processor n (car goal-tree-lst))))
(if new-child
(cons new-child (cdr goal-tree-lst))
(let ((rest-children (insert-into-goal-tree-lst
cl-id processor n (cdr goal-tree-lst))))
(if rest-children
(cons (car goal-tree-lst) rest-children)
nil)))))
((integerp goal-tree-lst)
(cons (make goal-tree
:cl-id cl-id
:processor processor
:children n
:fanout (or n 0))
(if (eql goal-tree-lst 1)
nil
(1- goal-tree-lst))))
(t nil)))
)
(defun insert-into-goal-tree (cl-id processor n goal-tree)
; This function updates the indicated goal-tree by adding a new goal tree built
; from cl-id, processor, and n, in place of the first integer "children" field
; of a subgoal in a left-to-right depth-first traversal of the goal-tree.
; (Recall that an integer represents the number of unproved children remaining;
; hence the first integer found corresponds to the goal that corresponds to the
; parameters of this function.) However, we return nil if no integer
; "children" field is found; similarly for the -rec and -lst versions, above.
; Note that n should be nil or a (strictly) positive integer. Also note that
; when cl-id is *initial-clause-id*, then goal-tree doesn't matter (for
; example, it may be nil).
(cond
((equal cl-id *initial-clause-id*)
(make goal-tree
:cl-id cl-id
:processor processor
:children n
:fanout (or n 0)))
(t (insert-into-goal-tree-rec cl-id processor n goal-tree))))
(defun set-difference-equal-changedp (l1 l2)
; Like set-difference-equal, but returns (mv changedp lst) where lst is the set
; difference and changedp is t iff the set difference is not equal to l1.
(declare (xargs :guard (and (true-listp l1)
(true-listp l2))))
(cond ((endp l1) (mv nil nil))
(t (mv-let (changedp lst)
(set-difference-equal-changedp (cdr l1) l2)
(cond
((member-equal (car l1) l2)
(mv t lst))
(changedp (mv t (cons (car l1) lst)))
(t (mv nil l1)))))))
(mutual-recursion
(defun prune-goal-tree (forcing-round dead-clause-ids goal-tree)
; Removes all proved goals from a goal tree, where all dead-clause-ids are
; considered proved. Actually returns two values: a new goal tree (or nil),
; and a new (extended) list of dead-clause-ids.
; Goals with processor (push-clause id . x) are handled similarly to forced
; goals, except that we know that there is a unique child.
; Note that a non-nil final cdr prevents a goal from being considered proved
; (unless its clause-id is dead, which shouldn't happen), which is appropriate.
(let* ((processor (access goal-tree goal-tree :processor))
(cl-id (access goal-tree goal-tree :cl-id))
(goal-forcing-round (access clause-id cl-id :forcing-round)))
(cond ((member-equal cl-id dead-clause-ids)
(mv (er hard 'prune-goal-tree
"Surprise! We didn't think this case could occur.")
dead-clause-ids))
((and (not (= forcing-round goal-forcing-round))
; So, current goal is from a previous forcing round.
(consp processor)
(eq (cadr processor) :forced))
; So, processor is of the form (pr :forced clause-id_1 ... clause-id_n).
(mv-let
(changedp forced-clause-ids)
(set-difference-equal-changedp (cddr processor) dead-clause-ids)
(cond
((null forced-clause-ids)
(mv nil (cons cl-id dead-clause-ids)))
; Notice that goal-tree may have children, even though it comes from an earlier
; forcing round, because it may have generated children that themselves did
; some forcing.
(t
(mv-let
(children new-dead-clause-ids)
(prune-goal-tree-lst
forcing-round
dead-clause-ids
(access goal-tree goal-tree :children))
(cond
(changedp
(mv (change goal-tree goal-tree
:processor
(list* (car processor) :forced forced-clause-ids)
:children children)
new-dead-clause-ids))
(t (mv (change goal-tree goal-tree
:children children)
new-dead-clause-ids))))))))
((and (consp processor)
(eq (car processor) 'push-clause))
(assert$
(null (access goal-tree goal-tree :children))
; It is tempting also to assert (null (cddr processor)), i.e., that we have not
; reverted or aborted. But that can fail for a branch of a disjunctive (:or)
; split.
(if (member-equal (cadr processor) dead-clause-ids)
(mv nil (cons cl-id dead-clause-ids))
(mv goal-tree dead-clause-ids))))
(t
(mv-let (children new-dead-clause-ids)
(prune-goal-tree-lst forcing-round
dead-clause-ids
(access goal-tree goal-tree :children))
(cond
((or children
; Note that the following test implies that we're in the current forcing round,
; and hence "decoration" (adding a list of new goals created by that forcing)
; has not yet been done.
(and (consp processor)
(eq (cadr processor) :forced)))
(mv (change goal-tree goal-tree
:children children)
new-dead-clause-ids))
(t (mv nil (cons cl-id new-dead-clause-ids)))))))))
(defun prune-goal-tree-lst (forcing-round dead-clause-ids goal-tree-lst)
(cond
((consp goal-tree-lst)
(mv-let (x new-dead-clause-ids)
(prune-goal-tree forcing-round dead-clause-ids (car goal-tree-lst))
(if x
(mv-let (rst newer-dead-clause-ids)
(prune-goal-tree-lst
forcing-round new-dead-clause-ids (cdr goal-tree-lst))
(mv (cons x rst)
newer-dead-clause-ids))
(prune-goal-tree-lst
forcing-round new-dead-clause-ids (cdr goal-tree-lst)))))
(t (mv goal-tree-lst dead-clause-ids))))
)
(defun prune-proof-tree (forcing-round dead-clause-ids proof-tree)
(if (null proof-tree)
nil
(mv-let (new-goal-tree new-dead-clause-ids)
(prune-goal-tree forcing-round dead-clause-ids (car proof-tree))
(if new-goal-tree
(cons new-goal-tree
(prune-proof-tree forcing-round
new-dead-clause-ids
(cdr proof-tree)))
(prune-proof-tree forcing-round
new-dead-clause-ids
(cdr proof-tree))))))
(defun print-string-repeat (increment level col channel state)
(declare (type #.*fixnat-type* col level))
(the2s
#.*fixnat-type*
(if (= level 0)
(mv col state)
(mv-letc (col state)
(fmt1 "~s0"
(list (cons #\0 increment))
col channel state nil)
(print-string-repeat increment (1-f level) col channel state)))))
(defconst *format-proc-alist*
'((apply-top-hints-clause-or-hit . ":OR")
(apply-top-hints-clause . "top-level-hints")
(preprocess-clause . "preprocess")
(simplify-clause . "simp")
;;settled-down-clause
(eliminate-destructors-clause . "ELIM")
(fertilize-clause . "FERT")
(generalize-clause . "GEN")
(eliminate-irrelevance-clause . "IRREL")
;;push-clause
))
(defun format-forced-subgoals (clause-ids col max-col channel state)
; Print the "(FORCED ...)" annotation, e.g., the part after "(FORCED" on this
; line:
; 0 | Subgoal 3 simp (FORCED [1]Subgoal 1)
(cond
((null clause-ids)
(princ$ ")" channel state))
(t (let ((goal-name (string-for-tilde-@-clause-id-phrase (car clause-ids))))
(if (or (null max-col)
; We must leave room for final " ...)" if there are more goals, in addition to
; the space, the goal name, and the comma. Otherwise, we need room for the
; space and the right paren.
(if (null (cdr clause-ids))
(<= (+ 2 col (length goal-name)) max-col)
(<= (+ 7 col (length goal-name)) max-col)))
(mv-let (col state)
(fmt1 " ~s0~#1~[~/,~]"
(list (cons #\0 goal-name)
(cons #\1 clause-ids))
col channel state nil)
(format-forced-subgoals
(cdr clause-ids) col max-col channel state))
(princ$ " ...)" channel state))))))
(defun format-processor (col goal-tree channel state)
(let ((proc (access goal-tree goal-tree :processor)))
(cond
((consp proc)
(cond
((eq (car proc) 'push-clause)
(mv-let
(col state)
(fmt1 "~s0 ~@1"
(list (cons #\0 "PUSH")
(cons #\1
(cond
((eq (caddr proc) :REVERT)
"(reverting)")
((eq (caddr proc) :ABORT)
"*ABORTING*")
(t
(tilde-@-pool-name-phrase
(access clause-id
(cadr proc)
:forcing-round)
(access clause-id
(cadr proc)
:pool-lst))))))
col channel state nil)
(declare (ignore col))
state))
((eq (cadr proc) :forced)
(mv-let (col state)
(fmt1 "~s0 (FORCED"
; Note that (car proc) is in *format-proc-alist*, because neither push-clause
; nor either of the "fake" processors (:INDUCT, :FORCING-ROUND) forces in the
; creation of subgoals.
(list (cons #\0 (cdr (assoc-eq (car proc)
*format-proc-alist*))))
col channel state nil)
(format-forced-subgoals
(cddr proc) col
(f-get-global 'proof-tree-buffer-width state)
channel state)))
(t (let ((err (er hard 'format-processor
"Unexpected shape for goal-tree processor, ~x0"
proc)))
(declare (ignore err))
state))))
(t (princ$ (or (cdr (assoc-eq proc *format-proc-alist*))
proc)
channel state)))))
(mutual-recursion
(defun format-goal-tree-lst
(goal-tree-lst level fanout increment checkpoints
checkpoint-forced-goals channel state)
(cond
((null goal-tree-lst)
state)
((atom goal-tree-lst)
(mv-let (col state)
(pprogn (princ$ " " channel state)
(print-string-repeat
increment
(the-fixnat! level 'format-goal-tree-lst)
5 channel state))
(mv-let (col state)
(fmt1 "<~x0 ~#1~[~/more ~]subgoal~#2~[~/s~]>~%"
(list (cons #\0 goal-tree-lst)
(cons #\1 (if (= fanout goal-tree-lst) 0 1))
(cons #\2 (if (eql goal-tree-lst 1)
0
1)))
col channel state nil)
(declare (ignore col))
state)))
(t
(pprogn
(format-goal-tree
(car goal-tree-lst) level increment checkpoints
checkpoint-forced-goals channel state)
(format-goal-tree-lst
(cdr goal-tree-lst) level fanout increment checkpoints
checkpoint-forced-goals channel state)))))
(defun format-goal-tree (goal-tree level increment checkpoints
checkpoint-forced-goals channel state)
(let* ((cl-id (access goal-tree goal-tree :cl-id))
(pool-lst (access clause-id cl-id :pool-lst))
(fanout (access goal-tree goal-tree :fanout))
(raw-processor (access goal-tree goal-tree :processor))
(processor (if (atom raw-processor)
raw-processor
(car raw-processor))))
(mv-letc
(col state)
(pprogn (mv-letc
(col state)
(fmt1 "~#0~[c~/ ~]~c1 "
(list (cons #\0 (if (or (member-eq processor checkpoints)
(and checkpoint-forced-goals
(consp raw-processor)
(eq (cadr raw-processor)
:forced)))
0
1))
(cons #\1 (cons fanout 3)))
0 channel state nil)
(print-string-repeat increment
(the-fixnat! level 'format-goal-tree)
col channel state)))
(mv-letc
(col state)
(if (and (null (access clause-id cl-id :case-lst))
(= (access clause-id cl-id :primes) 0)
pool-lst)
(fmt1 "~@0 "
(list (cons #\0 (tilde-@-pool-name-phrase
(access clause-id cl-id :forcing-round)
pool-lst)))
col channel state nil)
(fmt1 "~@0 "
(list (cons #\0 (tilde-@-clause-id-phrase cl-id)))
col channel state nil))
(pprogn
(format-processor col goal-tree channel state)
(pprogn
(newline channel state)
(format-goal-tree-lst
(access goal-tree goal-tree :children)
(1+ level) fanout increment checkpoints checkpoint-forced-goals
channel state)))))))
)
(defun format-proof-tree (proof-tree-rev increment checkpoints
checkpoint-forced-goals channel state)
; Recall that most recent forcing rounds correspond to the goal-trees closest
; to the front of a proof-tree. But here, proof-tree-rev is the reverse of a
; proof-tree.
(if (null proof-tree-rev)
state
(pprogn (format-goal-tree
(car proof-tree-rev) 0 increment checkpoints
checkpoint-forced-goals channel state)
(if (null (cdr proof-tree-rev))
state
(mv-let (col state)
(fmt1 "++++++++++++++++++++++++++++++~%"
nil 0 channel state nil)
(declare (ignore col))
state))
(format-proof-tree
(cdr proof-tree-rev) increment checkpoints
checkpoint-forced-goals channel state))))
(defun print-proof-tree1 (ctx channel state)
(let ((proof-tree (f-get-global 'proof-tree state)))
(if (null proof-tree)
(if (and (consp ctx) (eq (car ctx) :failed))
state
(princ$ "Q.E.D." channel state))
(format-proof-tree (reverse proof-tree)
(f-get-global 'proof-tree-indent state)
(f-get-global 'checkpoint-processors state)
(f-get-global 'checkpoint-forced-goals state)
channel
state))))
(defconst *proof-failure-string*
"******** FAILED ********~|")
(defun print-proof-tree-ctx (ctx channel state)
(let* ((failed-p (and (consp ctx) (eq (car ctx) :failed)))
(actual-ctx (if failed-p (cdr ctx) ctx)))
(mv-let
(erp val state)
(state-global-let*
((fmt-hard-right-margin 1000 set-fmt-hard-right-margin)
(fmt-soft-right-margin 1000 set-fmt-soft-right-margin))
; We need the event name to fit on a single line, hence the state-global-let*
; above.
(mv-let (col state)
(fmt-ctx actual-ctx 0 channel state)
(mv-let
(col state)
(fmt1 "~|~@0"
(list (cons #\0
(if failed-p *proof-failure-string* "")))
col channel state nil)
(declare (ignore col))
(value nil))))
(declare (ignore erp val))
state)))
(defconst *proof-tree-start-delimiter* "#<\\<0")
(defconst *proof-tree-end-delimiter* "#>\\>")
(defun print-proof-tree-finish (state)
(if (f-get-global 'proof-tree-start-printed state)
(pprogn (mv-let (col state)
(fmt1! "~s0"
(list (cons #\0 *proof-tree-end-delimiter*))
0 (proofs-co state) state nil)
(declare (ignore col))
(f-put-global 'proof-tree-start-printed nil state)))
state))
(defun print-proof-tree (state)
; WARNING: Every call of print-proof-tree should be underneath some call of the
; form (io? ...). We thus avoid enclosing the body below with (io? proof-tree
; ...).
(let ((chan (proofs-co state))
(ctx (f-get-global 'proof-tree-ctx state)))
(pprogn
(if (f-get-global 'window-interfacep state)
state
(pprogn
(f-put-global 'proof-tree-start-printed t state)
(mv-let (col state)
(fmt1 "~s0"
(list (cons #\0 *proof-tree-start-delimiter*))
0 chan state nil)
(declare (ignore col)) ;print-proof-tree-ctx starts with newline
state)))
(print-proof-tree-ctx ctx chan state)
(print-proof-tree1 ctx chan state)
(print-proof-tree-finish state))))
(mutual-recursion
(defun decorate-forced-goals-1 (goal-tree clause-id-list forced-clause-id)
(let ((cl-id (access goal-tree goal-tree :cl-id))
(new-children (decorate-forced-goals-1-lst
(access goal-tree goal-tree :children)
clause-id-list
forced-clause-id)))
(cond
((member-equal cl-id clause-id-list)
(let ((processor (access goal-tree goal-tree :processor)))
(change goal-tree goal-tree
:processor
(list* (car processor) :forced forced-clause-id (cddr processor))
:children new-children)))
(t
(change goal-tree goal-tree
:children new-children)))))
(defun decorate-forced-goals-1-lst
(goal-tree-lst clause-id-list forced-clause-id)
(cond
((null goal-tree-lst)
nil)
((atom goal-tree-lst)
; By the time we've gotten this far, we've gotten to the next forcing round,
; and hence there shouldn't be any children remaining to process. Of course, a
; forced goal can generate forced subgoals, so we can't say that there are no
; children -- but we CAN say that there are none remaining to process.
(er hard 'decorate-forced-goals-1-lst
"Unexpected goal-tree in call ~x0"
(list 'decorate-forced-goals-1-lst
goal-tree-lst
clause-id-list
forced-clause-id)))
(t (cons (decorate-forced-goals-1
(car goal-tree-lst) clause-id-list forced-clause-id)
(decorate-forced-goals-1-lst
(cdr goal-tree-lst) clause-id-list forced-clause-id)))))
)
(defun decorate-forced-goals (forcing-round goal-tree clause-id-list-list n)
; See decorate-forced-goals-in-proof-tree.
(if (null clause-id-list-list)
goal-tree
(decorate-forced-goals
forcing-round
(decorate-forced-goals-1 goal-tree
(car clause-id-list-list)
(make clause-id
:forcing-round forcing-round
:pool-lst nil
:case-lst (and n (list n))
:primes 0))
(cdr clause-id-list-list)
(and n (1- n)))))
(defun decorate-forced-goals-in-proof-tree
(forcing-round proof-tree clause-id-list-list n)
; This function decorates the goal trees in proof-tree so that the appropriate
; previous forcing round's goals are "blamed" for the new forcing round goals.
; See also extend-proof-tree-for-forcing-round.
; At the top level, n is either an integer greater than 1 or else is nil. This
; corresponds respectively to whether or not there is more than one goal
; produced by the forcing round.
(if (null proof-tree)
nil
(cons (decorate-forced-goals
forcing-round (car proof-tree) clause-id-list-list n)
(decorate-forced-goals-in-proof-tree
forcing-round (cdr proof-tree) clause-id-list-list n))))
(defun assumnote-list-to-clause-id-list (assumnote-list)
(if (null assumnote-list)
nil
(cons (access assumnote (car assumnote-list) :cl-id)
(assumnote-list-to-clause-id-list (cdr assumnote-list)))))
(defun assumnote-list-list-to-clause-id-list-list (assumnote-list-list)
(if (null assumnote-list-list)
nil
(cons (assumnote-list-to-clause-id-list (car assumnote-list-list))
(assumnote-list-list-to-clause-id-list-list (cdr assumnote-list-list)))))
(defun extend-proof-tree-for-forcing-round
(forcing-round parent-clause-id clause-id-list-list state)
; This function pushes a new goal tree onto the global proof-tree. However, it
; decorates the existing goal trees so that the appropriate previous forcing
; round's goals are "blamed" for the new forcing round goals. Specifically, a
; previous goal with clause id in a member of clause-id-list-list is blamed for
; creating the appropriate newly-forced goal, with (car clause-id-list-list)
; associated with the highest-numbered (first) forced goal, etc.
(cond
((null clause-id-list-list)
; then the proof is complete!
state)
(t
(let ((n (length clause-id-list-list))) ;note n>0
(f-put-global
'proof-tree
(cons (make goal-tree
:cl-id parent-clause-id
:processor :FORCING-ROUND
:children n
:fanout n)
(decorate-forced-goals-in-proof-tree
forcing-round
(f-get-global 'proof-tree state)
clause-id-list-list
(if (null (cdr clause-id-list-list))
nil
(length clause-id-list-list))))
state)))))
(defun initialize-proof-tree1 (parent-clause-id x pool-lst forcing-round ctx
state)
; X is from the "x" argument of waterfall. Thus, if we are starting a forcing
; round then x is list of pairs (assumnote-lst . clause) where the clause-ids
; from the assumnotes are the names of goals from the preceding forcing round
; to "blame" for the creation of that clause.
(pprogn
; The user might have started up proof trees with something like (assign
; inhibit-output-lst nil). In that case we need to ensure that appropriate
; state globals are initialized. Note that start-proof-tree-fn does not
; override existing bindings of those state globals (which the user may have
; deliberately set).
(start-proof-tree-fn nil state)
(f-put-global 'proof-tree-ctx ctx state)
(cond
((and (null pool-lst)
(eql forcing-round 0))
(f-put-global 'proof-tree nil state))
(pool-lst
(f-put-global 'proof-tree
(cons (let ((n (length x)))
(make goal-tree
:cl-id parent-clause-id
:processor :INDUCT
:children (if (= n 0) nil n)
:fanout n))
(f-get-global 'proof-tree state))
state))
(t
(extend-proof-tree-for-forcing-round
forcing-round parent-clause-id
(assumnote-list-list-to-clause-id-list-list (strip-cars x))
state)))))
(defun initialize-proof-tree (parent-clause-id x ctx state)
; X is from the "x" argument of waterfall. See initialize-proof-tree1.
; We assume (not (output-ignored-p 'proof-tree state)).
(let ((pool-lst (access clause-id parent-clause-id :pool-lst))
(forcing-round (access clause-id parent-clause-id
:forcing-round)))
(pprogn
(io? proof-tree nil state
(ctx forcing-round pool-lst x parent-clause-id)
(initialize-proof-tree1 parent-clause-id x pool-lst forcing-round ctx
state))
(io? prove nil state
(forcing-round pool-lst)
(cond ((intersectp-eq '(prove proof-tree)
(f-get-global 'inhibit-output-lst state))
state)
((and (null pool-lst)
(eql forcing-round 0))
(fms "<< Starting proof tree logging >>~|"
nil (proofs-co state) state nil))
(t state))))))
(defconst *star-1-clause-id*
(make clause-id
:forcing-round 0
:pool-lst '(1)
:case-lst nil
:primes 0))
(mutual-recursion
(defun revert-goal-tree-rec (cl-id revertp goal-tree)
; See revert-goal-tree. This nest also returns a value cl-id-foundp, which is
; nil if the given cl-id was not found in goal-tree or any subsidiary goal
; trees, else :or-found if cl-id is found under a disjunctive split, else t.
(let ((processor (access goal-tree goal-tree :processor)))
(cond
((and (consp processor)
(eq (car processor) 'push-clause))
(mv (equal cl-id (access goal-tree goal-tree :cl-id))
(if revertp
(change goal-tree goal-tree
:processor
(list 'push-clause *star-1-clause-id* :REVERT))
goal-tree)))
(t (mv-let (cl-id-foundp new-children)
(revert-goal-tree-lst (eq processor
'apply-top-hints-clause-or-hit)
cl-id
revertp
(access goal-tree goal-tree :children))
(mv cl-id-foundp
(change goal-tree goal-tree :children new-children)))))))
(defun revert-goal-tree-lst (or-p cl-id revertp goal-tree-lst)
; Or-p is true if we want to limit changes to the member of goal-tree-lst that
; is, or has a subsidiary, goal-tree for cl-id.
(cond
((atom goal-tree-lst)
(mv nil nil))
(t (mv-let (cl-id-foundp new-goal-tree)
(revert-goal-tree-rec cl-id revertp (car goal-tree-lst))
(cond ((or (eq cl-id-foundp :or-found)
(and cl-id-foundp or-p))
(mv :or-found
(cons new-goal-tree (cdr goal-tree-lst))))
(t (mv-let (cl-id-foundp2 new-goal-tree-lst)
(revert-goal-tree-lst or-p
cl-id
revertp
(cdr goal-tree-lst))
(mv (or cl-id-foundp2 cl-id-foundp)
(cons (if (eq cl-id-foundp2 :or-found)
(car goal-tree-lst)
new-goal-tree)
new-goal-tree-lst)))))))))
)
(defun revert-goal-tree (cl-id revertp goal-tree)
; If there are no disjunctive (:or) splits, this function replaces every final
; cdr of any :children field of each subsidiary goal tree (including goal-tree)
; by nil, for other than push-clause processors, indicating that there are no
; children left to consider proving. If revertp is true, it also replaces each
; (push-clause *n) with (push-clause *star-1-clause-id* :REVERT), meaning that
; we are reverting.
; The spec in the case of disjunctive splits is similar, except that if cl-id
; is under such a split, then the changes described above are limited to the
; innermost disjunct containing cl-id.
(mv-let (cl-id-foundp new-goal-tree)
(revert-goal-tree-rec cl-id revertp goal-tree)
(assert$ cl-id-foundp
new-goal-tree)))
; The pool is a list of pool-elements, as shown below. We explain
; in push-clause.
(defrec pool-element (tag clause-set . hint-settings) t)
(defun pool-lst1 (pool n ans)
(cond ((null pool) (cons n ans))
((eq (access pool-element (car pool) :tag)
'to-be-proved-by-induction)
(pool-lst1 (cdr pool) (1+ n) ans))
(t (pool-lst1 (cdr pool) 1 (cons n ans)))))
(defun pool-lst (pool)
; Pool is a pool as constructed by push-clause. That is, it is a list
; of pool-elements and the tag of each is either 'to-be-proved-by-
; induction or 'being-proved-by-induction. Generally when we refer to
; a pool-lst we mean the output of this function, which is a list of
; natural numbers. For example, '(3 2 1) is a pool-lst and *3.2.1 is
; its printed representation.
; If one thinks of the pool being divided into gaps by the
; 'being-proved-by-inductions (with gaps at both ends) then the lst
; has as many elements as there are gaps and the ith element, k, in
; the lst tells us there are k-1 'to-be-proved-by-inductions in the
; ith gap.
; Warning: It is assumed that the value of this function is always
; non-nil. See the use of "jppl-flg" in the waterfall and in
; pop-clause.
(pool-lst1 pool 1 nil))
(defun increment-proof-tree
(cl-id ttree processor clause-count new-hist signal pspv state)
; Modifies the global proof-tree so that it incorporates the given cl-id, which
; creates n child goals via processor. Also prints out the proof tree.
(if (or (eq processor 'settled-down-clause)
(and (consp new-hist)
(consp (access history-entry (car new-hist)
:processor))))
state
(let* ((forcing-round (access clause-id cl-id :forcing-round))
(aborting-p (and (eq signal 'abort)
(not (equal (tagged-objects 'abort-cause ttree)
'(revert)))))
(clause-count
(cond ((eq signal 'or-hit)
(assert$
(eq processor 'apply-top-hints-clause)
(length (nth 2 (tagged-object :or ttree)))))
(t clause-count)))
(processor
(cond
((tagged-objectsp 'assumption ttree)
(assert$ (and (not (eq processor 'push-clause))
(not (eq signal 'or-hit)))
(list processor :forced)))
((eq processor 'push-clause)
(list* 'push-clause
(make clause-id
:forcing-round forcing-round
:pool-lst
(pool-lst
(cdr (access prove-spec-var pspv
:pool)))
:case-lst nil
:primes 0)
(if aborting-p '(:ABORT) nil)))
((eq signal 'or-hit)
'apply-top-hints-clause-or-hit)
(t processor)))
(starting-proof-tree (f-get-global 'proof-tree state))
(new-goal-tree
(insert-into-goal-tree cl-id
processor
(if (eql clause-count 0)
nil
clause-count)
(car starting-proof-tree))))
(pprogn
(if new-goal-tree
(f-put-global 'proof-tree
(if (and (consp processor)
(eq (car processor) 'push-clause)
(eq signal 'abort)
(not aborting-p))
(if (and (= forcing-round 0)
(null (cdr starting-proof-tree)))
(list (revert-goal-tree cl-id t new-goal-tree))
(er hard 'increment-proof-tree
"Internal Error: Attempted to ``revert'' ~
the proof tree with forcing round ~x0 and ~
proof tree of length ~x1. This reversion ~
should only have been tried with forcing ~
round 0 and proof tree of length 1. ~