3
;; The rename books are arranged like this:
7
;; rename-unique rename-sound
11
;; This book (rename) has the main definitions and some
12
;; preservation-of-property theorems. The top definition
13
;; is (rename-all f), which renames all bound variables
14
;; (left-to-right, in separate passes) to unique new
17
(include-book "wfftype")
19
;;===================== step-wise rename
21
;; Function rename-bound (f old new) renames the first bound occurrence
22
;; of old to new. Safeness of "new" is not checked.
24
(defun rename-bound (f old new)
25
(declare (xargs :guard (and (wff f)
27
(variable-term new))))
28
(cond ((wfnot f) (list 'not (rename-bound (a1 f) old new)))
29
((wfbinary f) (if (bound-occurrence old (a1 f))
31
(rename-bound (a1 f) old new)
35
(rename-bound (a2 f) old new))))
36
((wfquant f) (if (equal (a1 f) old)
39
(subst-free (a2 f) (a1 f) new))
42
(rename-bound (a2 f) old new))))
45
(defthm rename-bound-wff
48
(wff (rename-bound f old new))))
50
(defthm rename-bound-preserves-car
51
(equal (car (rename-bound f old new)) (car f)))
53
(defthm rename-bound-preserves-nnfp
55
(nnfp (rename-bound f x y))))
57
;;===============================================
58
;; Function rename-bunch (f oldvars newvars) renames the members of oldvars
59
;; to the corresponding members of newvars.
61
(defun rename-bunch (f oldvars newvars)
62
(declare (xargs :guard (and (wff f) (var-list oldvars) (var-list newvars)
63
(equal (len oldvars) (len newvars)))))
64
(if (or (atom oldvars) (atom newvars))
66
(rename-bunch (rename-bound f (car oldvars) (car newvars))
67
(cdr oldvars) (cdr newvars))))
69
(defthm rename-bunch-wff
72
(wff (rename-bunch f oldvars newvars))))
74
(defthm rename-bunch-preserves-nnfp
76
(nnfp (rename-bunch f old new))))
78
;; Function (all-safe vars f) is true if no member of vars has a
79
;; bound or free occurrence in formula f.
81
(defun all-safe (vars f)
82
(declare (xargs :guard (and (wff f) (var-list vars))))
84
((bound-occurrence (car vars) f) nil)
85
((free-occurrence (car vars) f) nil)
86
(t (all-safe (cdr vars) f))))
88
;;------------------------------------------------
89
;; Now what should the newvars be?
91
;; Get the gensym book, define a function to get a list of new
92
;; symbols, and prove some properties.
94
(include-book "gensym-e")
96
(defun gen-symbols (n sym lst)
97
(declare (xargs :guard (and (natp n)
102
(let ((newsym (gen-symbol sym lst)))
103
(cons newsym (gen-symbols (1- n) sym (cons newsym lst))))))
105
(defthm gen-symbols-ok
106
(implies (symbolp sym)
107
(disjoint (gen-symbols n sym lst) lst)))
109
(defthm gen-symbols-len
111
(equal (len (gen-symbols n sym lst)) n)))
113
(defthm member-member-not-disjoint
114
(implies (and (member-equal x a)
116
(not (disjoint a b)))
119
(defthm gen-symbols-member
120
(implies (symbolp sym)
121
(not (member-equal a (gen-symbols n sym (cons a lst)))))
123
:use ((:instance member-member-not-disjoint
125
(a (gen-symbols n sym (cons a lst)))
126
(b (cons a lst)))))))
128
(defthm gen-symbols-setp
129
(implies (symbolp sym)
130
(setp (gen-symbols n sym lst))))
132
;;------------------------------------------------
134
(defthm var-list-symbol-listp
135
(implies (var-list lst)
139
(declare (xargs :guard (wff f)))
140
(gen-symbols (len (quantified-vars f))
142
(append (quantified-vars f) (free-vars f))))
144
(defthm free-free-append
145
(implies (free-occurrence x f)
146
(member-equal x (append (quantified-vars f)
149
:use ((:instance free-free)))))
151
(defthm bound-bound-append
152
(implies (bound-occurrence x f)
153
(member-equal x (append (quantified-vars f)
156
:use ((:instance quantified-iff-bound)))))
158
(defthm disjoint-all-safe
159
(implies (disjoint a (append (quantified-vars f) (free-vars f)))
162
(defthm safe-list-all-safe
163
(all-safe (safe-list f) f))
165
(defmacro var-set (vars)
166
(list 'and (list 'var-list vars) (list 'setp vars)))
168
(defthm gen-symbols-var-list
169
(var-list (gen-symbols n sym lst)))
171
(defthm safe-list-varset
172
(var-set (safe-list f)))
174
;;---------------------------------
175
;; Function (rename-all f) renames all bound variables.
177
(defthm var-list-append
178
(implies (and (var-list qvs0)
180
(var-list (append qvs0 qvs))))
182
(defun rename-all (f)
183
(declare (xargs :guard (wff f)))
184
(rename-bunch f (quantified-vars f) (safe-list f)))
186
(defthm rename-all-wff
188
(wff (rename-all f))))
190
(defthm rename-all-preserves-nnfp
192
(nnfp (rename-all f))))
194
;;------------------------------------------------
195
;; Prove that the rename functions preserve free-vars
197
(defthm rename-bound-preserves-free-vars
198
(implies (and (variable-term y)
199
(not (bound-occurrence y f))
200
(not (free-occurrence y f)))
201
(equal (free-vars (rename-bound f x y))
204
(defthm rename-bound-doesnt-introduce-free-vars
205
(implies (not (free-occurrence z f))
206
(not (free-occurrence z (rename-bound f x y)))))
208
(defthm rename-bound-still-safe
209
(implies (and (all-safe new2 f)
210
(not (member-equal new1 new2))
211
(not (bound-occurrence new1 f))
212
(not (free-occurrence new1 f)))
213
(all-safe new2 (rename-bound f old1 new1))))
215
(defthm rename-bunch-preserves-free-vars
216
(implies (and (all-safe new f)
218
(equal (free-vars (rename-bunch f old new))
221
:induct (rename-bunch f old new))))
223
(defthm rename-all-preserves-free-vars
224
(equal (free-vars (rename-all f))