3
;; Negation normal form (NNF): definition, syntactic correctness
4
;; theorem, soundness theorem, and some preservation-of-property theorems.
8
(defmacro car-and (f) (list 'equal (list 'car f) ''and))
9
(defmacro car-or (f) (list 'equal (list 'car f) ''or))
10
(defmacro car-imp (f) (list 'equal (list 'car f) ''imp))
11
(defmacro car-iff (f) (list 'equal (list 'car f) ''iff))
12
(defmacro car-all (f) (list 'equal (list 'car f) ''all))
13
(defmacro car-exists (f) (list 'equal (list 'car f) ''exists))
15
;;==================================================================
16
;; Function nnf converts a formula to negation normal form.
17
;; That is, in terms of and/or/not, where all nots are up against
18
;; simple formulas. ('true and 'false are not simplified away.)
21
(declare (xargs :guard (wff f)))
24
(cond ((car-and f) (list 'and (nnf (a1 f)) (nnf (a2 f))))
25
((car-or f) (list 'or (nnf (a1 f)) (nnf (a2 f))))
26
((car-imp f) (list 'or (nnf (list 'not (a1 f))) (nnf (a2 f))))
27
((car-iff f) (list 'and
28
(list 'or (nnf (list 'not (a1 f))) (nnf (a2 f)))
29
(list 'or (nnf (a1 f)) (nnf (list 'not (a2 f))))))
30
(t f))) ; should not happen if (wff f)
33
(cond ((car-all f) (list 'all (a1 f) (nnf (a2 f))))
34
((car-exists f) (list 'exists (a1 f) (nnf (a2 f))))
35
(t f))) ; should not happen if (wff f)
38
(cond ((wfbinary (a1 f))
39
(cond ((car-and (a1 f)) (list 'or
40
(nnf (list 'not (a1 (a1 f))))
41
(nnf (list 'not (a2 (a1 f))))))
42
((car-or (a1 f)) (list 'and
43
(nnf (list 'not (a1 (a1 f))))
44
(nnf (list 'not (a2 (a1 f))))))
45
((car-imp (a1 f)) (list 'and
47
(nnf (list 'not (a2 (a1 f))))))
48
((car-iff (a1 f)) (list 'and
53
(nnf (list 'not (a1 (a1 f))))
54
(nnf (list 'not (a2 (a1 f)))))))
55
(t f))) ; should not happen if (wff f)
57
(cond ((car-all (a1 f))
58
(list 'exists (a1 (a1 f)) (nnf (list 'not (a2 (a1 f))))))
60
(list 'all (a1 (a1 f)) (nnf (list 'not (a2 (a1 f))))))
61
(t f))) ; should not happen if (wff f)
63
((wfnot (a1 f)) (nnf (a1 (a1 f))))
67
;; Prove that nnf preserves well-formedness.
73
;; Prove that nnf applied to a wff gives negation normal form.
79
(defthm subst-nnf-commute
80
(equal (subst-free (nnf f) x tm)
81
(nnf (subst-free f x tm))))
83
;;---------------------------------
84
;; Prove that nnf is sound. The proof seems to be easier with xeval.
86
(defthm nnf-xsound-for-not
87
(equal (xeval (nnf (list 'not f)) dom i)
88
(xeval (list 'not (nnf f)) dom i))
90
:induct (xeval-i f dom i))))
93
(equal (xeval (nnf f) dom i)
96
:induct (xeval-i f dom i))))
99
(equal (feval (nnf f) i)
102
:in-theory (enable xeval-feval))))
104
;;---------------------------------
105
;; Prove that nnf preserves the set of free variables.
107
(defthm nnf-preserves-free-vars
108
(equal (free-vars (nnf f)) (free-vars f)))