1
; Copyright (C) 2006 University of Texas at Austin
3
; This program is free software; you can redistribute it and/or modify
4
; it under the terms of the GNU General Public License as published by
5
; the Free Software Foundation; either version 2 of the License, or
6
; (at your option) any later version.
8
; This program is distributed in the hope that it will be useful,
9
; but WITHOUT ANY WARRANTY; without even the implied warranty of
10
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
; GNU General Public License for more details.
13
; You should have received a copy of the GNU General Public License
14
; along with this program; if not, write to the Free Software
15
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
; Written by: Matt Kaufmann
18
; email: Kaufmann@cs.utexas.edu
19
; Department of Computer Sciences
20
; University of Texas at Austin
21
; Austin, TX 78712-1188 U.S.A.
27
; If you submit (bash term), then the result is a list of goals to which ACL2
28
; can simplify term when attempting to prove it. (In particular, if the result
29
; is nil, then ACL2 can prove term.) More accurately: (bash term) returns (mv
30
; erp val state), where: erp is nil unless there is an error; and val is a list
31
; of terms, in untranslated (user-level) form, whose provability implies the
32
; provability of the input term. If ACL2 cannot simplify the input term, then
33
; there is an error, i.e., erp is not nil.
37
; This book defines a utility similar to the proof-checker's bash command, but
38
; for use in the top-level loop. The input term can be a user-level term,
39
; i.e., it need not be translated. Thus this bash utility is given a term, and
40
; it returns an error triple (mv erp termlist state) where if erp is not nil,
41
; then termlist is the list of goals that ACL2 would get stuck on, if you were
42
; to attempt to prove the given term with only simplification, i.e., with a
43
; "Goal" hint of :do-not '(generalize eliminate-destructors fertilize
44
; eliminate-irrelevance) and with induction turned off. Bash does all the
45
; normal simplification stuff, including forward chaining. Use :hints to
46
; specify hints using the same syntax as for thm and defthm. Use a non-nil
47
; value of :verbose if you want output, including the proof attempt. The
48
; keyword values are not evaluated, so :hints could be of the form (("Goal
49
; ...)) but not '(("Goal" ...)).
51
; This book also includes a functional (non-macro) version of bash, bash-fn.
52
; At the end is a variant contributed by Dave Greve, bash-term-to-dnf, that
53
; returns a list of goals (implicitly conjoined) where each goal has the form
54
; (lit1 lit2 ... litk), for which the goal is equivalent to the negation of the
55
; conjunction of the liti.
60
ACL2 !>(bash (equal (append x y) (append (car (cons x a)) z)))
61
((EQUAL (APPEND X Y) (APPEND X Z)))
62
ACL2 !>(bash (equal (car (cons x y)) x))
64
ACL2 !>(bash (implies (true-listp x) (equal (append x y) zzz))
65
:hints (("Goal" :expand ((true-listp x)
69
(IMPLIES (AND (CONSP X)
71
(TRUE-LISTP (CDDR X)))
76
(IMPLIES (AND (CONSP X) (NOT (CDR X)))
77
(EQUAL (CONS (CAR X) Y) ZZZ)))
78
ACL2 !>(bash-term-to-dnf
79
'(implies (true-listp x) (equal (append x y) zzz))
80
'(("Goal" :expand ((true-listp x)
87
(NOT (TRUE-LISTP (CDDR X)))
94
(EQUAL (CONS (CAR X) Y) ZZZ)))
104
(defun simplify-with-prover (form hints ctx state)
106
; This is patterned after (define-pc-primitive prove ...).
108
(let ((wrld (w state))
112
((thints (translate-hints
115
; Keep the following in sync with the definition of the proof-checker :bash
119
*bash-skip-forcing-round-hints*
120
(add-string-val-pair-to-string-val-alist
123
(list 'quote '(generalize eliminate-destructors fertilize
124
eliminate-irrelevance))
125
(add-string-val-pair-to-string-val-alist
130
(default-hints wrld))
132
(tterm (translate form t t t ctx wrld state)))
133
(mv-let (erp ttree state)
134
(pc-prove tterm form thints t ens wrld ctx state)
135
(cond (erp (mv t nil state))
136
(t (let ((clauses (unproved-pc-prove-terms ttree)))
137
(cond ((and (eql (length clauses) 1)
138
(eql (length (car clauses)) 1)
139
(eql (caar clauses) tterm))
140
(mv 'no-change nil state))
141
(t (value clauses))))))))))
143
(defun bash-fn (form hints verbose ctx state)
145
; Keep this in sync with bash-term-to-dnf.
150
(simplify-with-prover form hints ctx state))
153
((inhibit-output-lst *valid-output-names*))
154
(simplify-with-prover form hints ctx state))))
159
"Unable to simplify the input term~@0"
160
(cond ((eq erp 'no-change)
162
(t (msg " because an error occurred.~@0"
165
(t " Try setting the verbose flag to t in ~
166
order to see what is going on."))))))
167
(value (list form))))
169
(value (prettyify-clause-lst clauses (let*-abstractionp state) (w state)))))))
171
(defmacro bash (term &key verbose hints)
172
`(bash-fn ',term ',hints ',verbose 'bash state))
174
; Dave Greve has contributed the following (only slightly modified here), to
175
; create a variant bash-term-to-dnf of bash-fn. This example may suggest other
176
; variants; feel free to contribute yours to Matt Kaufmann,
177
; kaufmann@cs.utexas.edu.
179
(defun goals-to-cnf (goals)
180
(cond ((endp goals) nil)
181
(t (cons (append (access goal (car goals) :hyps)
182
(list (dumb-negate-lit (access goal (car goals)
184
(goals-to-cnf (cdr goals))))))
186
(defun untranslate-lst-lst (list iff-flg wrld)
190
(t (cons (untranslate-lst (car list) iff-flg wrld)
191
(untranslate-lst-lst (cdr list) iff-flg wrld)))))
193
(defun bash-term-to-dnf (form hints verbose state)
195
; Keep this in sync with bash-fn.
197
(let ((ctx 'bash-term-to-dnf))
201
(simplify-with-prover form hints ctx state))
204
((inhibit-output-lst *valid-output-names*))
205
(simplify-with-prover form hints ctx state))))
210
"Unable to simplify the input term~@0"
211
(cond ((eq erp 'no-change)
213
(t (msg " because an error occurred.~@0"
216
(t " Try setting the verbose flag to t in ~
217
order to see what is going on."))))))
218
(value (list (list form)))))
220
(value (untranslate-lst-lst clauses t (w state))))))))