3
;; The pull books are arranged like this:
7
;; pull-pulls pull-sound
11
;; This book (pull) has the main definitions and some
12
;; preservation-of-property theorems. The top definition
13
;; is (pull-quants f), which pulls quantifiers to the
16
(include-book "wfftype")
17
(include-book "permutations")
19
;;--------------------------------------
20
;; Function pull (f) moves quantifiers toward the root of a formula
21
;; as much as possible, using rules like
22
;; (or p (all x q)) <=> (all x (or p q)) if x is not free in p.
23
;; Bound variables are NOT renamed. If all bound variables are
24
;; unique, the formula is closed nnf, then all quantifiers should
25
;; come to the top. (That property proved elsewhere.) Here,
26
;; we define the functions and prove soundness.
28
;; Pull-top-left pulls quantifiers up from the left side, and
29
;; pull-top-right from the right side.
31
;; The first functions I wrote were a little simpler than these.
32
;; Originally, when pull-top right got to the base case, it called
33
;; pull-top-left. Now, they are independent (and the same except for
34
;; left/right): we first pull-top-left, then call down-right,
35
;; which goes back down to the 'and or 'or and calls pull-top-right.
39
;; q1 q3 pull-top-left or down-right q3
40
;; q2 q4 / \ (pull-top-right) q4
45
;; I changed to the current version, because I had trouble getting
46
;; a soundness proof for the original.
48
(defun pull-top-right (op f g)
49
(declare (xargs :guard (and (or (equal op 'and) (equal op 'or))
52
(if (and (or (equal op 'and) (equal op 'or))
54
(not (free-occurrence (a1 g) f)))
55
(list (car g) (a1 g) (pull-top-right op f (a2 g)))
58
(defun pull-top-left (op f g)
59
(declare (xargs :guard (and (or (equal op 'and) (equal op 'or))
62
(if (and (or (equal op 'and) (equal op 'or))
64
(not (free-occurrence (a1 f) g)))
65
(list (car f) (a1 f) (pull-top-left op (a2 f) g))
69
(declare (xargs :guard (and (wff f) (nnfp f))))
70
(cond ((wfquant f) (list (car f) (a1 f) (down-right (a2 f))))
72
(wfor f)) (pull-top-right (car f) (a1 f) (a2 f)))
75
;; Beware! Something about pull, I don't know what, causes
76
;; rewrite explosions. Even to get guards verified, I had to
77
;; disable pull. In other proofs below, down-right is disabled,
78
;; which helps somewhat.
81
(declare (xargs :guard (and (wff f) (nnfp f))
84
(wfor f)) (down-right (pull-top-left (car f)
87
((wfquant f) (list (car f) (a1 f) (pull (a2 f))))
91
;; Prove the the pull functions preserve wff and nnfp, and finally
92
;; verify guards for pull.
94
(defthm pull-top-right-wff
97
(or (equal op 'and) (equal op 'or)
98
(equal op 'imp) (equal op 'iff)))
99
(wff (pull-top-right op f g))))
101
(defthm pull-top-right-nnfp
102
(implies (and (nnfp f)
104
(or (equal op 'and) (equal op 'or)))
105
(nnfp (pull-top-right op f g)))
107
:induct (pull-top-right op f g))))
109
(defthm pull-top-left-wff
110
(implies (and (wff f)
112
(or (equal op 'and) (equal op 'or)
113
(equal op 'imp) (equal op 'iff)))
114
(wff (pull-top-left op f g))))
116
(defthm pull-top-left-nnfp
117
(implies (and (nnfp f)
119
(or (equal op 'and) (equal op 'or)))
120
(nnfp (pull-top-left op f g)))
122
:induct (pull-top-left op f g))))
124
(defthm down-right-wff
126
(wff (down-right f))))
128
(defthm down-right-nnfp
130
(nnfp (down-right f)))
132
:induct (down-right f))))
138
:in-theory (disable down-right))))
144
:in-theory (disable down-right))))
148
:in-theory (disable pull))))
150
;;----------------------------------------
151
;; Here is a wrapper for pull. This checks the (unnecessary I think) setp
152
;; condition in the soundness theorem.
154
(defun pull-quants (f)
155
(declare (xargs :guard (and (wff f) (nnfp f))))
156
(if (setp (quantified-vars f))
160
(defthm pull-quants-wff
162
(wff (pull-quants f)))
164
:in-theory (disable pull))))
166
(defthm pull-quants-nnfp
168
(nnfp (pull-quants f)))
170
:in-theory (disable pull))))
173
;; Show that each pull functions preserves the set of free variables.
175
(defthm ptr-preserves-free-vars
176
(implies (or (equal op 'and) (equal op 'or))
177
(equal (free-vars (pull-top-right op f g))
178
(union-equal (free-vars f) (free-vars g))))
180
:induct (pull-top-right op f g))))
182
(defthm ptl-preserves-free-vars
183
(implies (or (equal op 'and) (equal op 'or))
184
(equal (free-vars (pull-top-left op f g))
185
(union-equal (free-vars f) (free-vars g))))
187
:induct (pull-top-left op f g))))
189
(defthm down-right-preserves-free-vars
190
(equal (free-vars (down-right f))
193
:induct (down-right f))))
195
(defthm pull-preserves-free-vars
196
(equal (free-vars (pull f))
201
(defthm pull-quants-preserves-free-vars
202
(equal (free-vars (pull-quants f))
206
:in-theory (disable pull))))
208
;;------------------------------------
209
;; The various operations preserve the set of quantified variables.
210
;; Note equality for pull-top-right, permutation for the rest.
211
;; (If the original formula is closed nnf with unique quantified
212
;; variables, all quantifiers come to the top, then does equality hold.
213
;; If I had proved this, some later things would have been simpler.)
215
(defthm ptl-preserves-qvars
216
(implies (and (or (equal op 'and) (equal op 'or)))
217
(equal (quantified-vars (pull-top-left op f g))
218
(append (quantified-vars f)
219
(quantified-vars g)))))
221
(defthm ptr-unique-qvars-2
222
(implies (or (equal op 'and) (equal op 'or))
223
(perm (quantified-vars (pull-top-right op f g))
224
(append (quantified-vars f)
225
(quantified-vars g)))))
227
(defthm down-right-unique-vars-2
228
(perm (quantified-vars (down-right f))
229
(quantified-vars f)))
231
(defthm pull-unique-vars-2
232
(perm (quantified-vars (pull f))
235
:in-theory (disable down-right set-equal))))
237
;;---------------------------
238
;; The pull operations preserve exists-count.
240
(defthm ptl-preserves-exists-count
241
(implies (or (equal op 'and) (equal op 'or))
242
(equal (exists-count (pull-top-left op f g))
243
(+ (exists-count f) (exists-count g))))
245
:induct (pull-top-left op f g))))
247
(defthm ptr-preserves-exists-count
248
(implies (or (equal op 'and) (equal op 'or))
249
(equal (exists-count (pull-top-right op f g))
250
(+ (exists-count f) (exists-count g))))
252
:induct (pull-top-right op f g))))
254
(defthm down-right-preserves-exists-count
255
(equal (exists-count (down-right f))
258
:induct (down-right f))))
260
(defthm pull-preserves-exists-count
261
(equal (exists-count (pull f))
264
:in-theory (disable pull-top-left pull-top-right down-right))))
266
(defthm pull-quants-preserves-exists-count
267
(equal (exists-count (pull-quants f))
270
:in-theory (disable pull-top-left pull-top-right down-right))))
274
(defthm pull-quants-setp
275
(implies (setp (quantified-vars f))
276
(setp (quantified-vars (pull-quants f))))
278
:in-theory (disable pull))))