File: replace-proofs.lisp

package info (click to toggle)
acl2 8.6%2Bdfsg-2
  • links: PTS
  • area: main
  • in suites: trixie
  • size: 1,111,420 kB
  • sloc: lisp: 17,818,294; java: 125,359; python: 28,122; javascript: 23,458; cpp: 18,851; ansic: 11,569; perl: 7,678; xml: 5,591; sh: 3,976; makefile: 3,833; ruby: 2,633; yacc: 1,126; ml: 763; awk: 295; csh: 233; lex: 197; php: 178; tcl: 49; asm: 23; haskell: 17
file content (329 lines) | stat: -rw-r--r-- 15,158 bytes parent folder | download | duplicates (8)
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
; Milawa - A Reflective Theorem Prover
; Copyright (C) 2005-2009 Kookamara LLC
;
; Contact:
;
;   Kookamara LLC
;   11410 Windermere Meadows
;   Austin, TX 78759, USA
;   http://www.kookamara.com/
;
; License: (An MIT/X11-style license)
;
;   Permission is hereby granted, free of charge, to any person obtaining a
;   copy of this software and associated documentation files (the "Software"),
;   to deal in the Software without restriction, including without limitation
;   the rights to use, copy, modify, merge, publish, distribute, sublicense,
;   and/or sell copies of the Software, and to permit persons to whom the
;   Software is furnished to do so, subject to the following conditions:
;
;   The above copyright notice and this permission notice shall be included in
;   all copies or substantial portions of the Software.
;
;   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
;   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;   DEALINGS IN THE SOFTWARE.
;
; Original author: Jared Davis <jared@kookamara.com>

(in-package "MILAWA")
(include-book "find-proof")
(set-verify-guards-eagerness 2)
(set-case-split-limitations nil)
(set-well-founded-relation ord<)
(set-measure-function rank)


; Proof Replacement.
;
; A basic goal of this file is to be able to support reasoning of the form,
;
;  Given: BLDR is sound as long as FOO is a theorem.
;  Given: A proof of FOO.
;  Conclude: BLDR's conclusions are sound even when FOO is not a theorem.
;
; To carry out this sort of thing, we introduce a proof-replacing function,
; which walks through an appeal and replaces any conclusions of some form
; with a new proof.  Then, we see that
;
;   Replace(BLDR's output, Proof of FOO)
;
; Is a proof of BLDR's output which is true even without having FOO as a
; theorem of the history.

(defund logic.flag-replace-proofs (flag x proofs)
  (declare (xargs :guard (and (if (equal flag 'proof)
                                  (logic.appealp x)
                                (and (equal flag 'list)
                                     (logic.appeal-listp x)))
                              (logic.appeal-listp proofs))
                  :measure (two-nats-measure (rank x) (if (equal flag 'proof) 1 0))
                  :verify-guards nil))
  (if (equal flag 'proof)
      (or (logic.find-proof (logic.conclusion x) proofs)
          (logic.appeal (logic.method x)
                        (logic.conclusion x)
                        (logic.flag-replace-proofs 'list (logic.subproofs x) proofs)
                        (logic.extras x)))
    (if (consp x)
        (cons (logic.flag-replace-proofs 'proof (car x) proofs)
              (logic.flag-replace-proofs 'list (cdr x) proofs))
      nil)))

(defund logic.replace-proofs (x proofs)
  (declare (xargs :guard (and (logic.appealp x)
                              (logic.appeal-listp proofs))
                  :verify-guards nil))
  (logic.flag-replace-proofs 'proof x proofs))

(defund logic.replace-proofs-list (x proofs)
  (declare (xargs :guard (and (logic.appeal-listp x)
                              (logic.appeal-listp proofs))
                  :verify-guards nil))
  (logic.flag-replace-proofs 'list x proofs))

(defthmd definition-of-logic.replace-proofs
  (equal (logic.replace-proofs x proofs)
         (or (logic.find-proof (logic.conclusion x) proofs)
             (logic.appeal (logic.method x)
                           (logic.conclusion x)
                           (logic.replace-proofs-list (logic.subproofs x) proofs)
                           (logic.extras x))))
  :rule-classes :definition
  :hints(("Goal" :in-theory (enable logic.flag-replace-proofs
                                    logic.replace-proofs
                                    logic.replace-proofs-list))))

(defthmd definition-of-logic.replace-proofs-list
  (equal (logic.replace-proofs-list x proofs)
         (if (consp x)
             (cons (logic.replace-proofs (car x) proofs)
                   (logic.replace-proofs-list (cdr x) proofs))
           nil))
  :rule-classes :definition
  :hints(("Goal"
          :in-theory (enable logic.flag-replace-proofs
                             logic.replace-proofs
                             logic.replace-proofs-list)
          :expand (logic.flag-replace-proofs 'list x proofs))))

(ACL2::theory-invariant (not (ACL2::active-runep '(:definition logic.replace-proofs))))
(ACL2::theory-invariant (not (ACL2::active-runep '(:definition logic.replace-proofs-list))))

(defthm logic.replace-proofs-list-when-not-consp
  (implies (not (consp x))
           (equal (logic.replace-proofs-list x proofs)
                  nil))
  :hints(("Goal" :in-theory (enable definition-of-logic.replace-proofs-list))))

(defthm logic.replace-proofs-list-of-cons
  (equal (logic.replace-proofs-list (cons a x) proofs)
         (cons (logic.replace-proofs a proofs)
               (logic.replace-proofs-list x proofs)))
  :hints(("Goal" :in-theory (enable definition-of-logic.replace-proofs-list))))

(defprojection
  :list (logic.replace-proofs-list x proofs)
  :element (logic.replace-proofs x proofs)
  :already-definedp t)



(defthms-flag
  :shared-hyp (force (logic.appeal-listp proofs))
  :thms ((proof logic.appealp-of-logic.replace-proofs
                (implies (force (logic.appealp x))
                         (equal (logic.appealp (logic.replace-proofs x proofs))
                                t)))
         (t logic.appeal-listp-of-logic.replace-proofs-list
            (implies (force (logic.appeal-listp x))
                     (equal (logic.appeal-listp (logic.replace-proofs-list x proofs))
                            t))))
  :hints(("Goal"
          :induct (logic.appeal-induction flag x)
          :in-theory (e/d (definition-of-logic.replace-proofs)
                          ((ACL2::force))))))

(defthms-flag
  :shared-hyp (force (logic.appeal-listp proofs))
  :thms ((proof logic.conclusion-of-logic.replace-proofs
                (implies (force (logic.appealp x))
                         (equal (logic.conclusion (logic.replace-proofs x proofs))
                                (logic.conclusion x))))
         (t logic.strip-conclusions-of-logic.replace-proofs-list
            (implies (force (logic.appeal-listp x))
                     (equal (logic.strip-conclusions (logic.replace-proofs-list x proofs))
                            (logic.strip-conclusions x)))))
  :hints(("Goal"
          :induct (logic.appeal-induction flag x)
          :in-theory (e/d (definition-of-logic.replace-proofs)
                          ((ACL2::force))))))

(defthmd lemma-1-for-logic.proofp-of-logic.replace-proofs
  (implies (and (not (equal (logic.method x) 'axiom))
                (not (equal (logic.method x) 'theorem)))
           (equal
            (logic.appeal-step-okp x
                                   (difference axioms remove)
                                   (difference thms remove)
                                   atbl)
            (logic.appeal-step-okp x axioms thms atbl)))
  :hints(("Goal" :in-theory (enable logic.appeal-step-okp))))

(defthmd lemma-2-for-logic.proofp-of-logic.replace-proofs
  (implies (and (or (equal (logic.method x) 'axiom)
                    (equal (logic.method x) 'theorem))
                (not (memberp (logic.conclusion x) remove)))
           (equal
            (logic.appeal-step-okp x
                                   (difference axioms remove)
                                   (difference thms remove)
                                   atbl)
            (logic.appeal-step-okp x axioms thms atbl)))
  :hints(("Goal" :in-theory (enable logic.appeal-step-okp
                                    logic.axiom-okp
                                    logic.theorem-okp))))

(defthmd lemma-3-for-logic.proofp-of-logic.replace-proofs
  (implies (not (memberp (logic.conclusion x) remove))
           (equal (logic.appeal-step-okp x
                                         (difference axioms remove)
                                         (difference thms remove)
                                         atbl)
                  (logic.appeal-step-okp x axioms thms atbl)))
  :hints(("Goal" :use ((:instance lemma-1-for-logic.proofp-of-logic.replace-proofs)
                       (:instance lemma-2-for-logic.proofp-of-logic.replace-proofs)))))

(defthmd lemma-4-for-logic.proofp-of-logic.replace-proofs
  (implies (and (logic.proof-listp (logic.replace-proofs-list (logic.subproofs x) proofs)
                                   (difference axioms (logic.strip-conclusions proofs))
                                   (difference thms (logic.strip-conclusions proofs))
                                   atbl)
                (logic.appeal-listp proofs)
                (logic.proof-listp proofs
                                   (difference axioms (logic.strip-conclusions proofs))
                                   (difference thms (logic.strip-conclusions proofs))
                                   atbl)
                (logic.appealp x)
                (logic.appeal-step-okp x axioms thms atbl)
                (logic.proof-listp (logic.subproofs x) axioms thms atbl)
                (not (logic.find-proof (logic.conclusion x) proofs)))
           (logic.proofp (logic.appeal (logic.method x)
                                       (logic.conclusion x)
                                       (logic.replace-proofs-list (logic.subproofs x)
                                                                  proofs)
                                       (logic.extras x))
                         (difference axioms (logic.strip-conclusions proofs))
                         (difference thms (logic.strip-conclusions proofs))
                         atbl))
  :hints(("Goal"
          :in-theory (enable definition-of-logic.proofp)
          :use ((:instance lemma-appeal-step-for-forcing-logic.provablep-when-logic.subproofs-provable
                           (new-subproofs (logic.replace-proofs-list (logic.subproofs x) proofs)))
                (:instance lemma-3-for-logic.proofp-of-logic.replace-proofs
                           (x (logic.appeal (logic.method x)
                                            (logic.conclusion x)
                                            (logic.replace-proofs-list (logic.subproofs x) proofs)
                                            (logic.extras x)))
                           (remove (logic.strip-conclusions proofs)))))))

(defthms-flag
  :shared-hyp (and (force (logic.appeal-listp proofs))
                   (force (logic.proof-listp proofs
                                             (difference axioms (logic.strip-conclusions proofs))
                                             (difference thms (logic.strip-conclusions proofs))
                                             atbl)))
  :thms ((proof logic.proofp-of-logic.replace-proofs
                (implies (and (force (logic.appealp x))
                              (force (logic.proofp x axioms thms atbl)))
                         (equal (logic.proofp (logic.replace-proofs x proofs)
                                              (difference axioms (logic.strip-conclusions proofs))
                                              (difference thms (logic.strip-conclusions proofs))
                                              atbl)
                                t)))

         (t logic.proof-listp-of-logic.replace-proofs-list
            (implies (and (force (logic.appeal-listp x))
                          (force (logic.proof-listp x axioms thms atbl)))
                     (equal (logic.proof-listp (logic.replace-proofs-list x proofs)
                                               (difference axioms (logic.strip-conclusions proofs))
                                               (difference thms (logic.strip-conclusions proofs))
                                               atbl)
                            t))))
  :hints(("Goal"
          :induct (logic.appeal-induction flag x)
          :in-theory (enable definition-of-logic.replace-proofs
                             definition-of-logic.proofp
                             lemma-4-for-logic.proofp-of-logic.replace-proofs))))



(defthm logic.appeal-step-okp-in-larger-axiom-set
  (implies (and (subsetp axioms more-axioms)
                (logic.appeal-step-okp x axioms thms atbl))
           (equal (logic.appeal-step-okp x more-axioms thms atbl)
                  t))
  :hints(("Goal" :in-theory (enable logic.appeal-step-okp
                                    logic.axiom-okp))))

(defthms-flag
  :shared-hyp (subsetp axioms more-axioms)
  :thms ((proof logic.proofp-in-larger-axiom-set
                (implies (logic.proofp x axioms thms atbl)
                         (equal (logic.proofp x more-axioms thms atbl)
                                t)))
         (t logic.proof-listp-in-larger-axiom-set
            (implies (logic.proof-listp x axioms thms atbl)
                     (equal (logic.proof-listp x more-axioms thms atbl)
                            t))))
  :hints(("Goal"
          :induct (logic.appeal-induction flag x)
          :in-theory (enable definition-of-logic.proofp))))

(defthm logic-provablep-in-larger-axiom-set
  (implies (and (subsetp axioms more-axioms)
                (logic.provablep x axioms thms atbl))
           (equal (logic.provablep x more-axioms thms atbl)
                  t))
  :hints(("Goal" :in-theory (e/d (logic.provablep)
                                 ((ACL2::force))))))



(defthm logic.appeal-step-okp-in-larger-theorem-set
  (implies (and (subsetp thms more-thms)
                (logic.appeal-step-okp x axioms thms atbl))
           (equal (logic.appeal-step-okp x axioms more-thms atbl)
                  t))
  :hints(("Goal" :in-theory (enable logic.appeal-step-okp
                                    logic.theorem-okp))))

(defthms-flag
  :shared-hyp (subsetp thms more-thms)
  :thms ((proof logic.proofp-in-larger-theorem-set
                (implies (logic.proofp x axioms thms atbl)
                         (equal (logic.proofp x axioms more-thms atbl)
                                t)))
         (t logic.proof-listp-in-larger-theorem-set
            (implies (logic.proof-listp x axioms thms atbl)
                     (equal (logic.proof-listp x axioms more-thms atbl)
                            t))))
  :hints(("Goal"
          :induct (logic.appeal-induction flag x)
          :in-theory (enable definition-of-logic.proofp))))

(defthm logic-provablep-in-larger-theorem-set
  (implies (and (subsetp thms more-thms)
                (logic.provablep x axioms thms atbl))
           (equal (logic.provablep x axioms thms atbl)
                  t))
  :hints(("Goal" :in-theory (e/d (logic.provablep)
                                 ((ACL2::force))))))