File: replace-subterm.lisp

package info (click to toggle)
acl2 8.5dfsg-5
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 991,452 kB
  • sloc: lisp: 15,567,759; javascript: 22,820; cpp: 13,929; ansic: 12,092; perl: 7,150; java: 4,405; xml: 3,884; makefile: 3,507; sh: 3,187; ruby: 2,633; ml: 763; python: 746; yacc: 723; awk: 295; csh: 186; php: 171; lex: 154; tcl: 49; asm: 23; haskell: 17
file content (595 lines) | stat: -rw-r--r-- 30,049 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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
; 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 "lambda")
(set-verify-guards-eagerness 2)
(set-case-split-limitations nil)
(set-well-founded-relation ord<)
(set-measure-function rank)

(defun build.flag-replace-subterm (flag x old new proof)
  (declare (xargs :guard (and (if (equal flag 'term)
                                  (logic.termp x)
                                (and (equal flag 'list)
                                     (logic.term-listp x)))
                              (logic.termp old)
                              (logic.termp new)
                              (logic.appealp proof)
                              (equal (logic.conclusion proof) (logic.pequal old new)))
                  :verify-guards nil))
  (if (equal flag 'term)
      (cond ((equal x old)
             (logic.appeal-identity proof))
            ((logic.constantp x)
             (build.reflexivity x))
            ((logic.variablep x)
             (build.reflexivity x))
            ((logic.functionp x)
             (let* ((name       (logic.function-name x))
                    (args       (logic.function-args x))
                    (arg-proofs (build.flag-replace-subterm 'list args old new proof)))
               (build.pequal-by-args name arg-proofs)))
            ((logic.lambdap x)
             (let* ((formals       (logic.lambda-formals x))
                    (body          (logic.lambda-body x))
                    (actuals       (logic.lambda-actuals x))
                    (actual-proofs (build.flag-replace-subterm 'list actuals old new proof)))
               (build.lambda-pequal-by-args formals body actual-proofs)))
            ;; Sneaky twiddle for hypless iff theorem
            (t t))
    (if (consp x)
        (cons (build.flag-replace-subterm 'term (car x) old new proof)
              (build.flag-replace-subterm 'list (cdr x) old new proof))
      nil)))

(definlined build.replace-subterm (x old new proof)
  (declare (xargs :guard (and (logic.termp x)
                              (logic.termp old)
                              (logic.termp new)
                              (logic.appealp proof)
                              (equal (logic.conclusion proof) (logic.pequal old new)))
                  :verify-guards nil))
  (build.flag-replace-subterm 'term x old new proof))

(definlined build.replace-subterm-list (x old new proof)
  (declare (xargs :guard (and (logic.term-listp x)
                              (logic.termp old)
                              (logic.termp new)
                              (logic.appealp proof)
                              (equal (logic.conclusion proof) (logic.pequal old new)))
                  :verify-guards nil))
  (build.flag-replace-subterm 'list x old new proof))

(defobligations build.flag-replace-subterm
  (logic.appeal-identity
   build.reflexivity
   build.pequal-by-args
   build.lambda-pequal-by-args))

(defobligations build.replace-subterm
  (build.flag-replace-subterm))

(defobligations build.replace-subterm-list
  (build.flag-replace-subterm))

(defthmd definition-of-build.replace-subterm
  (equal (build.replace-subterm x old new proof)
         (cond ((equal x old)
                (logic.appeal-identity proof))
               ((logic.constantp x)
                (build.reflexivity x))
               ((logic.variablep x)
                (build.reflexivity x))
               ((logic.functionp x)
                (let* ((name       (logic.function-name x))
                       (args       (logic.function-args x))
                       (arg-proofs (build.replace-subterm-list args old new proof)))
                  (build.pequal-by-args name arg-proofs)))
               ((logic.lambdap x)
                (let* ((formals       (logic.lambda-formals x))
                       (body          (logic.lambda-body x))
                       (actuals       (logic.lambda-actuals x))
                       (actual-proofs (build.replace-subterm-list actuals old new proof)))
                  (build.lambda-pequal-by-args formals body actual-proofs)))
               ;; Sneaky twiddle for hypless iff theorem
               (t t)))
  :rule-classes :definition
  :hints(("Goal" :in-theory (enable build.replace-subterm build.replace-subterm-list))))

(defthmd definition-of-build.replace-subterm-list
  (equal (build.replace-subterm-list x old new proof)
         (if (consp x)
             (cons (build.replace-subterm (car x) old new proof)
                   (build.replace-subterm-list (cdr x) old new proof))
           nil))
  :rule-classes :definition
  :hints(("Goal" :in-theory (enable build.replace-subterm build.replace-subterm-list))))

(defthm build.flag-replace-subterm-of-term
  (equal (build.flag-replace-subterm 'term x old new proof)
         (build.replace-subterm x old new proof))
  :hints(("Goal" :in-theory (enable build.replace-subterm))))

(defthm build.flag-replace-subterm-of-list
  (equal (build.flag-replace-subterm 'list x old new proof)
         (build.replace-subterm-list x old new proof))
  :hints(("Goal" :in-theory (enable build.replace-subterm-list))))

(ACL2::theory-invariant (not (ACL2::active-runep '(:definition build.replace-subterm))))
(ACL2::theory-invariant (not (ACL2::active-runep '(:definition build.replace-subterm-list))))

(encapsulate
 ()
 (defthm build.replace-subterm-list-when-not-consp
   (implies (not (consp x))
            (equal (build.replace-subterm-list x old new proof)
                   nil))
   :hints(("Goal" :in-theory (enable definition-of-build.replace-subterm-list))))

 (defthm build.replace-subterm-list-of-cons
   (equal (build.replace-subterm-list (cons a x) old new proof)
          (cons (build.replace-subterm a old new proof)
                (build.replace-subterm-list x old new proof)))
   :hints(("Goal" :in-theory (enable definition-of-build.replace-subterm-list))))

 (defprojection
   :list (build.replace-subterm-list x old new proof)
   :element (build.replace-subterm x old new proof)
   :already-definedp t))

(encapsulate
 ()
 (local (defthm lemma
          (if (equal flag 'term)
              (implies (and (logic.termp x)
                            (logic.termp old)
                            (logic.termp new)
                            (logic.appealp proof)
                            (equal (logic.conclusion proof) (logic.pequal old new)))
                       (and (logic.appealp (build.replace-subterm x old new proof))
                            (equal (logic.conclusion (build.replace-subterm x old new proof))
                                   (logic.pequal x (logic.replace-subterm x old new)))))
            (implies (and (logic.term-listp x)
                          (logic.termp old)
                          (logic.termp new)
                          (logic.appealp proof)
                          (equal (logic.conclusion proof) (logic.pequal old new)))
                     (and (logic.appeal-listp (build.replace-subterm-list x old new proof))
                          (equal (logic.strip-conclusions (build.replace-subterm-list x old new proof))
                                 (logic.pequal-list x (logic.replace-subterm-list x old new))))))
          :rule-classes nil
          :hints(("Goal"
                  :expand ((build.replace-subterm x old new proof)
                           (build.replace-subterm old old new proof)
                           (logic.replace-subterm x old new)
                           (logic.replace-subterm old old new))
                  ;; :restrict ((forcing-lookup-of-logic.function-name ((atbl atbl))))
                  :induct (build.flag-replace-subterm flag x old new proof)))))

 (defthm forcing-logic.appealp-of-build.replace-subterm
   (implies (force (and (logic.termp x)
                        (logic.termp old)
                        (logic.termp new)
                        (logic.appealp proof)
                        (equal (logic.conclusion proof) (logic.pequal old new))))
            (equal (logic.appealp (build.replace-subterm x old new proof))
                   t))
   :hints(("Goal" :use ((:instance lemma (flag 'term))))))

 (defthm forcing-logic.conclusion-of-build.replace-subterm
   (implies (force (and (logic.termp x)
                        (logic.termp old)
                        (logic.termp new)
                        (logic.appealp proof)
                        (equal (logic.conclusion proof) (logic.pequal old new))))
            (equal (logic.conclusion (build.replace-subterm x old new proof))
                   (logic.pequal x (logic.replace-subterm x old new))))
   :rule-classes ((:rewrite :backchain-limit-lst 0))
   :hints(("Goal" :use ((:instance lemma (flag 'term))))))

 (defthm forcing-logic.appeal-listp-of-build.replace-subterm-list
   (implies (force (and (logic.term-listp x)
                        (logic.termp old)
                        (logic.termp new)
                        (logic.appealp proof)
                        (equal (logic.conclusion proof) (logic.pequal old new))))
            (equal (logic.appeal-listp (build.replace-subterm-list x old new proof))
                   t))
   :hints(("Goal" :use ((:instance lemma (flag 'list))))))

 (defthm forcing-logic.strip-conclusions-of-build.replace-subterm-list
   (implies (force (and (logic.term-listp x)
                        (logic.termp old)
                        (logic.termp new)
                        (logic.appealp proof)
                        (equal (logic.conclusion proof) (logic.pequal old new))))
            (equal (logic.strip-conclusions (build.replace-subterm-list x old new proof))
                   (logic.pequal-list x (logic.replace-subterm-list x old new))))
   :rule-classes ((:rewrite :backchain-limit-lst 0))
   :hints(("Goal" :use ((:instance lemma (flag 'list)))))))

(encapsulate
 ()
 (local (defthm@ lemma
          (if (equal flag 'term)
              (implies (and (logic.termp x)
                            (logic.termp old)
                            (logic.termp new)
                            (logic.appealp proof)
                            (equal (logic.conclusion proof) (logic.pequal old new))
                            ;; ---
                            (logic.term-atblp x atbl)
                            (logic.proofp proof axioms thms atbl)
                            (@obligations build.replace-subterm))
                       (logic.proofp (build.replace-subterm x old new proof) axioms thms atbl))
            (implies (and (logic.term-listp x)
                          (logic.termp old)
                          (logic.termp new)
                          (logic.appealp proof)
                          (equal (logic.conclusion proof) (logic.pequal old new))
                          ;; ---
                          (logic.term-list-atblp x atbl)
                          (logic.proofp proof axioms thms atbl)
                          (@obligations build.replace-subterm-list))
                     (logic.proof-listp (build.replace-subterm-list x old new proof) axioms thms atbl)))
          :rule-classes nil
          :hints(("Goal"
                  :expand ((build.replace-subterm x old new proof)
                           (build.replace-subterm old old new proof))
                  ;; :restrict ((forcing-lookup-of-logic.function-name ((atbl atbl))))
                  :induct (build.flag-replace-subterm flag x old new proof)))))

 (defthm@ forcing-logic.proofp-of-build.replace-subterm
   (implies (force (and (logic.termp x)
                        (logic.termp old)
                        (logic.termp new)
                        (logic.appealp proof)
                        (equal (logic.conclusion proof) (logic.pequal old new))
                        ;; ---
                        (logic.term-atblp x atbl)
                        (logic.proofp proof axioms thms atbl)
                        (@obligations build.replace-subterm)))
            (equal (logic.proofp (build.replace-subterm x old new proof) axioms thms atbl)
                   t))
   :hints(("Goal" :use ((:instance lemma (flag 'term))))))

 (defthm@ forcing-logic.proof-listp-of-build.replace-subterm-list
   (implies (force (and (logic.term-listp x)
                        (logic.termp old)
                        (logic.termp new)
                        (logic.appealp proof)
                        (equal (logic.conclusion proof) (logic.pequal old new))
                        ;; ---
                        (logic.term-list-atblp x atbl)
                        (logic.proofp proof axioms thms atbl)
                        (@obligations build.replace-subterm-list)))
            (equal (logic.proof-listp (build.replace-subterm-list x old new proof) axioms thms atbl)
                   t))
   :hints(("Goal" :use ((:instance lemma (flag 'list)))))))

(verify-guards build.flag-replace-subterm)
(verify-guards build.replace-subterm)
(verify-guards build.replace-subterm-list)






(defun build.flag-disjoined-replace-subterm (flag x old new proof)
  (declare (xargs :guard (and (if (equal flag 'term)
                                  (logic.termp x)
                                (and (equal flag 'list)
                                     (logic.term-listp x)))
                              (logic.termp old)
                              (logic.termp new)
                              (logic.appealp proof)
                              (equal (logic.fmtype (logic.conclusion proof)) 'por*)
                              (equal (logic.vrhs (logic.conclusion proof)) (logic.pequal old new)))
                  :verify-guards nil))
  (if (equal flag 'term)
      (cond ((equal x old)
             (logic.appeal-identity proof))
            ((logic.constantp x)
             (build.expansion (logic.vlhs (logic.conclusion proof))
                              (build.reflexivity x)))
            ((logic.variablep x)
             (build.expansion (logic.vlhs (logic.conclusion proof))
                              (build.reflexivity x)))
            ((logic.functionp x)
             (let* ((name       (logic.function-name x))
                    (args       (logic.function-args x))
                    (arg-proofs (build.flag-disjoined-replace-subterm 'list args old new proof)))
               (build.disjoined-pequal-by-args name (logic.vlhs (logic.conclusion proof)) arg-proofs)))
            ((logic.lambdap x)
             (let* ((formals       (logic.lambda-formals x))
                    (body          (logic.lambda-body x))
                    (actuals       (logic.lambda-actuals x))
                    (actual-proofs (build.flag-disjoined-replace-subterm 'list actuals old new proof)))
               (build.disjoined-lambda-pequal-by-args formals body (logic.vlhs (logic.conclusion proof)) actual-proofs)))
            ;; Sneaky twiddle for hypless iff theorem
            (t t))
    (if (consp x)
        (cons (build.flag-disjoined-replace-subterm 'term (car x) old new proof)
              (build.flag-disjoined-replace-subterm 'list (cdr x) old new proof))
      nil)))

(definlined build.disjoined-replace-subterm (x old new proof)
  (declare (xargs :guard (and (logic.termp x)
                              (logic.termp old)
                              (logic.termp new)
                              (logic.appealp proof)
                              (equal (logic.fmtype (logic.conclusion proof)) 'por*)
                              (equal (logic.vrhs (logic.conclusion proof)) (logic.pequal old new)))
                  :verify-guards nil))
  (build.flag-disjoined-replace-subterm 'term x old new proof))

(definlined build.disjoined-replace-subterm-list (x old new proof)
  (declare (xargs :guard (and (logic.term-listp x)
                              (logic.termp old)
                              (logic.termp new)
                              (logic.appealp proof)
                              (equal (logic.fmtype (logic.conclusion proof)) 'por*)
                              (equal (logic.vrhs (logic.conclusion proof)) (logic.pequal old new)))
                  :verify-guards nil))
  (build.flag-disjoined-replace-subterm 'list x old new proof))

(defobligations build.flag-disjoined-replace-subterm
  (logic.appeal-identity
   build.reflexivity
   build.expansion
   build.disjoined-pequal-by-args
   build.disjoined-lambda-pequal-by-args))

(defobligations build.disjoined-replace-subterm
  (build.flag-disjoined-replace-subterm))

(defobligations build.disjoined-replace-subterm-list
  (build.flag-disjoined-replace-subterm))

(defthmd definition-of-build.disjoined-replace-subterm
  (equal (build.disjoined-replace-subterm x old new proof)
         (cond ((equal x old)
                (logic.appeal-identity proof))
               ((logic.constantp x)
                (build.expansion (logic.vlhs (logic.conclusion proof))
                                 (build.reflexivity x)))
               ((logic.variablep x)
                (build.expansion (logic.vlhs (logic.conclusion proof))
                                 (build.reflexivity x)))
               ((logic.functionp x)
                (let* ((name       (logic.function-name x))
                       (args       (logic.function-args x))
                       (arg-proofs (build.disjoined-replace-subterm-list args old new proof)))
                  (build.disjoined-pequal-by-args name (logic.vlhs (logic.conclusion proof)) arg-proofs)))
               ((logic.lambdap x)
                (let* ((formals       (logic.lambda-formals x))
                       (body          (logic.lambda-body x))
                       (actuals       (logic.lambda-actuals x))
                       (actual-proofs (build.disjoined-replace-subterm-list actuals old new proof)))
                  (build.disjoined-lambda-pequal-by-args formals body (logic.vlhs (logic.conclusion proof)) actual-proofs)))
               ;; Sneaky twiddle for hypless iff theorem
               (t t)))
  :rule-classes :definition
  :hints(("Goal" :in-theory (enable build.disjoined-replace-subterm build.disjoined-replace-subterm-list))))

(defthmd definition-of-build.disjoined-replace-subterm-list
  (equal (build.disjoined-replace-subterm-list x old new proof)
         (if (consp x)
             (cons (build.disjoined-replace-subterm (car x) old new proof)
                   (build.disjoined-replace-subterm-list (cdr x) old new proof))
           nil))
  :rule-classes :definition
  :hints(("Goal" :in-theory (enable build.disjoined-replace-subterm build.disjoined-replace-subterm-list))))

(defthm build.flag-disjoined-replace-subterm-of-term
  (equal (build.flag-disjoined-replace-subterm 'term x old new proof)
         (build.disjoined-replace-subterm x old new proof))
  :hints(("Goal" :in-theory (enable build.disjoined-replace-subterm))))

(defthm build.flag-disjoined-replace-subterm-of-list
  (equal (build.flag-disjoined-replace-subterm 'list x old new proof)
         (build.disjoined-replace-subterm-list x old new proof))
  :hints(("Goal" :in-theory (enable build.disjoined-replace-subterm-list))))

(ACL2::theory-invariant (not (ACL2::active-runep '(:definition build.disjoined-replace-subterm))))
(ACL2::theory-invariant (not (ACL2::active-runep '(:definition build.disjoined-replace-subterm-list))))

(encapsulate
 ()
 (defthm build.disjoined-replace-subterm-list-when-not-consp
   (implies (not (consp x))
            (equal (build.disjoined-replace-subterm-list x old new proof)
                   nil))
   :hints(("Goal" :in-theory (enable definition-of-build.disjoined-replace-subterm-list))))

 (defthm build.disjoined-replace-subterm-list-of-cons
   (equal (build.disjoined-replace-subterm-list (cons a x) old new proof)
          (cons (build.disjoined-replace-subterm a old new proof)
                (build.disjoined-replace-subterm-list x old new proof)))
   :hints(("Goal" :in-theory (enable definition-of-build.disjoined-replace-subterm-list))))

 (defprojection
   :list (build.disjoined-replace-subterm-list x old new proof)
   :element (build.disjoined-replace-subterm x old new proof)
   :already-definedp t))

(encapsulate
 ()
 (local (defthm lemma
          (if (equal flag 'term)
              (implies (and (logic.termp x)
                            (logic.termp old)
                            (logic.termp new)
                            (logic.appealp proof)
                            (equal (logic.fmtype (logic.conclusion proof)) 'por*)
                            (equal (logic.vrhs (logic.conclusion proof)) (logic.pequal old new)))
                       (and (logic.appealp (build.disjoined-replace-subterm x old new proof))
                            (equal (logic.conclusion (build.disjoined-replace-subterm x old new proof))
                                   (logic.por (logic.vlhs (logic.conclusion proof))
                                              (logic.pequal x (logic.replace-subterm x old new))))))
            (implies (and (logic.term-listp x)
                          (logic.termp old)
                          (logic.termp new)
                          (logic.appealp proof)
                          (equal (logic.fmtype (logic.conclusion proof)) 'por*)
                          (equal (logic.vrhs (logic.conclusion proof)) (logic.pequal old new)))
                     (and (logic.appeal-listp (build.disjoined-replace-subterm-list x old new proof))
                          (equal (logic.strip-conclusions (build.disjoined-replace-subterm-list x old new proof))
                                 (logic.por-list (repeat (logic.vlhs (logic.conclusion proof)) (len x))
                                                 (logic.pequal-list x (logic.replace-subterm-list x old new)))))))
          :rule-classes nil
          :hints(("Goal"
                  :expand ((build.disjoined-replace-subterm x old new proof)
                           (build.disjoined-replace-subterm old old new proof)
                           (logic.replace-subterm x old new)
                           (logic.replace-subterm old old new))
                  ;; :restrict ((forcing-lookup-of-logic.function-name ((atbl atbl))))
                  :induct (build.flag-disjoined-replace-subterm flag x old new proof)))))

 (defthm forcing-logic.appealp-of-build.disjoined-replace-subterm
   (implies (force (and (logic.termp x)
                        (logic.termp old)
                        (logic.termp new)
                        (logic.appealp proof)
                        (equal (logic.fmtype (logic.conclusion proof)) 'por*)
                        (equal (logic.vrhs (logic.conclusion proof)) (logic.pequal old new))))
            (equal (logic.appealp (build.disjoined-replace-subterm x old new proof))
                   t))
   :hints(("Goal" :use ((:instance lemma (flag 'term))))))

 (defthm forcing-logic.conclusion-of-build.disjoined-replace-subterm
   (implies (force (and (logic.termp x)
                        (logic.termp old)
                        (logic.termp new)
                        (logic.appealp proof)
                        (equal (logic.fmtype (logic.conclusion proof)) 'por*)
                        (equal (logic.vrhs (logic.conclusion proof)) (logic.pequal old new))))
            (equal (logic.conclusion (build.disjoined-replace-subterm x old new proof))
                   (logic.por (logic.vlhs (logic.conclusion proof))
                              (logic.pequal x (logic.replace-subterm x old new)))))
   :rule-classes ((:rewrite :backchain-limit-lst 0))
   :hints(("Goal" :use ((:instance lemma (flag 'term))))))

 (defthm forcing-logic.appeal-listp-of-build.disjoined-replace-subterm-list
   (implies (force (and (logic.term-listp x)
                        (logic.termp old)
                        (logic.termp new)
                        (logic.appealp proof)
                        (equal (logic.fmtype (logic.conclusion proof)) 'por*)
                        (equal (logic.vrhs (logic.conclusion proof)) (logic.pequal old new))))
            (equal (logic.appeal-listp (build.disjoined-replace-subterm-list x old new proof))
                   t))
   :hints(("Goal" :use ((:instance lemma (flag 'list))))))

 (defthm forcing-logic.strip-conclusions-of-build.disjoined-replace-subterm-list
   (implies (force (and (logic.term-listp x)
                        (logic.termp old)
                        (logic.termp new)
                        (logic.appealp proof)
                        (equal (logic.fmtype (logic.conclusion proof)) 'por*)
                        (equal (logic.vrhs (logic.conclusion proof)) (logic.pequal old new))))
            (equal (logic.strip-conclusions (build.disjoined-replace-subterm-list x old new proof))
                   (logic.por-list (repeat (logic.vlhs (logic.conclusion proof)) (len x))
                                   (logic.pequal-list x (logic.replace-subterm-list x old new)))))
   :rule-classes ((:rewrite :backchain-limit-lst 0))
   :hints(("Goal" :use ((:instance lemma (flag 'list)))))))

(encapsulate
 ()
 (local (defthm@ lemma
          (if (equal flag 'term)
              (implies (and (logic.termp x)
                            (logic.termp old)
                            (logic.termp new)
                            (logic.appealp proof)
                            (equal (logic.fmtype (logic.conclusion proof)) 'por*)
                            (equal (logic.vrhs (logic.conclusion proof)) (logic.pequal old new))
                            ;; ---
                            (logic.term-atblp x atbl)
                            (logic.proofp proof axioms thms atbl)
                            (@obligations build.disjoined-replace-subterm))
                       (logic.proofp (build.disjoined-replace-subterm x old new proof) axioms thms atbl))
            (implies (and (logic.term-listp x)
                          (logic.termp old)
                          (logic.termp new)
                          (logic.appealp proof)
                          (equal (logic.fmtype (logic.conclusion proof)) 'por*)
                          (equal (logic.vrhs (logic.conclusion proof)) (logic.pequal old new))
                          ;; ---
                          (logic.term-list-atblp x atbl)
                          (logic.proofp proof axioms thms atbl)
                          (@obligations build.disjoined-replace-subterm-list))
                     (logic.proof-listp (build.disjoined-replace-subterm-list x old new proof) axioms thms atbl)))
          :rule-classes nil
          :hints(("Goal"
                  :expand ((build.disjoined-replace-subterm x old new proof)
                           (build.disjoined-replace-subterm old old new proof))
                  ;; :restrict ((forcing-lookup-of-logic.function-name ((atbl atbl))))
                  :induct (build.flag-disjoined-replace-subterm flag x old new proof)))))

 (defthm@ forcing-logic.proofp-of-build.disjoined-replace-subterm
   (implies (force (and (logic.termp x)
                        (logic.termp old)
                        (logic.termp new)
                        (logic.appealp proof)
                        (equal (logic.fmtype (logic.conclusion proof)) 'por*)
                        (equal (logic.vrhs (logic.conclusion proof)) (logic.pequal old new))
                        ;; ---
                        (logic.term-atblp x atbl)
                        (logic.proofp proof axioms thms atbl)
                        (@obligations build.disjoined-replace-subterm)))
            (equal (logic.proofp (build.disjoined-replace-subterm x old new proof) axioms thms atbl)
                   t))
   :hints(("Goal" :use ((:instance lemma (flag 'term))))))

 (defthm@ forcing-logic.proof-listp-of-build.disjoined-replace-subterm-list
   (implies (force (and (logic.term-listp x)
                        (logic.termp old)
                        (logic.termp new)
                        (logic.appealp proof)
                        (equal (logic.fmtype (logic.conclusion proof)) 'por*)
                        (equal (logic.vrhs (logic.conclusion proof)) (logic.pequal old new))
                        ;; ---
                        (logic.term-list-atblp x atbl)
                        (logic.proofp proof axioms thms atbl)
                        (@obligations build.disjoined-replace-subterm-list)))
            (equal (logic.proof-listp (build.disjoined-replace-subterm-list x old new proof) axioms thms atbl)
                   t))
   :hints(("Goal" :use ((:instance lemma (flag 'list)))))))

(verify-guards build.flag-disjoined-replace-subterm)
(verify-guards build.disjoined-replace-subterm)
(verify-guards build.disjoined-replace-subterm-list)