File: ev-theoremp.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 (240 lines) | stat: -rw-r--r-- 9,451 bytes parent folder | download | duplicates (5)
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
; Reasoning about evaluators and falsifiers
; Copyright (C) 2010 Centaur Technology
;
; Contact:
;   Centaur Technology Formal Verification Group
;   7600-C N. Capital of Texas Highway, Suite 300, Austin, TX 78731, USA.
;   http://www.centtech.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: Sol Swords <sswords@centtech.com>

(in-package "ACL2")

;; (include-book "misc/untranslate-patterns" :dir :system)
(include-book "join-thms")
;; This is a sadly incomplete book for reasoning about evaluators and
;; "falsifier" functions.  An evaluator ev gives a value to a term X
;; under an alist A, and a falsifier evf provides for a given X an
;; alist A under which it evaluates to NIL, if one exists.  Therefore,
;; if (ev X (evf X)) is non-nil, then (ev X A) is nonnil for all A,
;; and we say X is a theorem under evaluator ev.

;; Reasoning about this concept gets much more complicated when one
;; considers evaluations of terms under falsifiers of other terms.
;; For example, (ev (and A B) (evf (and A B))) says that (and A B) is
;; a theorem, meaning that A and B are both theorems.  But commonly,
;; rewrite rules will decompose that term into
;; (and (ev A (evf (and A B)))
;;      (ev B (evf (and A B))))
;; But separately, each of (ev A (evf (and A B))) and
;; (ev B (evf (and A B))) don't tell us much.  We'd rather rewrite the
;; original form to
;; (and (ev A (evf A))
;;      (ev B (evf B))).

(defmacro def-ev-theoremp (ev)
  (let* ((falsify (intern-in-package-of-symbol
                   (concatenate 'string (symbol-name ev)
                                "-FALSIFY")
                   ev))
         (theoremp (intern-in-package-of-symbol
                    (concatenate 'string (symbol-name ev)
                                 "-THEOREMP")
                    ev))
         (subst
          `((ev . ,ev)
            (falsify . ,falsify)
            (theoremp . ,theoremp)
            (disjoin-cons-unless-theoremp
             . ,(intern-in-package-of-symbol
                 (concatenate 'string (symbol-name theoremp)
                              "-DISJOIN-CONS-UNLESS-THEOREMP")
                 ev))
            (disjoin-when-consp-unless-theoremp
             . ,(intern-in-package-of-symbol
                 (concatenate 'string (symbol-name theoremp)
                              "-DISJOIN-WHEN-CONSP-UNLESS-THEOREMP")
                 ev))
            (conjoin-cons
             . ,(intern-in-package-of-symbol
                 (concatenate 'string (symbol-name theoremp)
                              "-CONJOIN-CONS")
                 ev))
            (conjoin-append
             . ,(intern-in-package-of-symbol
                 (concatenate 'string (symbol-name theoremp)
                              "-CONJOIN-APPEND")
                 ev))
            (conjoin-clauses-cons
             . ,(intern-in-package-of-symbol
                 (concatenate 'string (symbol-name theoremp)
                              "-CONJOIN-CLAUSES-CONS")
                 ev))
            (conjoin-clauses-append
             . ,(intern-in-package-of-symbol
                 (concatenate 'string (symbol-name theoremp)
                              "-CONJOIN-CLAUSES-APPEND")
                 ev))
            (disjoin-cons . ,(ev-mk-rulename ev 'disjoin-cons))
            (disjoin-when-consp . ,(ev-mk-rulename ev 'disjoin-when-consp))))
         (event
          (sublis
           subst
           '(encapsulate nil
              (local (in-theory nil))

              (def-join-thms ev)

              (defchoose falsify (a) (x)
                (not (ev x a)))

              (defmacro theoremp (x)
                `(ev ,x (falsify ,x)))

              (defthm conjoin-cons
                (iff (theoremp (conjoin (cons a b)))
                     (and (theoremp a)
                          (theoremp (conjoin b))))
                :hints (("goal" :use
                         ((:instance
                           falsify
                           (x (conjoin (cons a b)))
                           (a (falsify a)))
                          (:instance
                           falsify
                           (x a)
                           (a (falsify (conjoin (cons a b)))))
                          (:instance
                           falsify
                           (x (conjoin (cons a b)))
                           (a (falsify (conjoin b))))
                          (:instance
                           falsify
                           (x (conjoin b))
                           (a (falsify (conjoin (cons a b)))))))))

              (defthm conjoin-append
                (iff (theoremp (conjoin (append a b)))
                     (and (theoremp (conjoin a))
                          (theoremp (conjoin b))))
                :hints(("Goal" :in-theory (enable append endp car-cdr-elim))))

              (defthm conjoin-clauses-cons
                (iff (theoremp
                      (conjoin-clauses (cons cl1 clrest)))
                     (and (theoremp (disjoin cl1))
                          (theoremp (conjoin-clauses clrest))))
                :hints(("Goal" :in-theory (enable conjoin-clauses disjoin-lst
                                                  car-cons cdr-cons))))

              (defthm conjoin-clauses-append
                (iff (theoremp
                      (conjoin-clauses (append cls1 cls2)))
                     (and (theoremp (conjoin-clauses cls1))
                          (theoremp (conjoin-clauses cls2))))
                :hints (("goal" :in-theory (enable append endp car-cdr-elim)
                         :induct (append cls1 cls2))))

              (defthm disjoin-cons-unless-theoremp
                (implies (and (equal aa (falsify (disjoin (cons x y))))
                              (syntaxp (not (equal a aa))))
                         (iff (ev (disjoin (cons x y)) a)
                              (or (ev x a)
                                  (ev (disjoin y) a)))))

              (defthmd disjoin-when-consp-unless-theoremp
                (implies (syntaxp (not (equal a `(falsify ,x))))
                         (implies (consp x)
                                  (iff (ev (disjoin x) a)
                                       (or (ev (car x) a)
                                           (ev (disjoin (cdr x)) a)))))
                :hints(("Goal" :in-theory (enable disjoin-when-consp))))

              (in-theory (disable disjoin-cons))))))
    event))


(local
 (progn
   (defevaluator test-ev test-ev-lst ((if a b c)))
   (def-ev-theoremp test-ev)))


#||
(defevaluator evthmp-ev evthmp-ev-lst
  ((if a b c) (not a)))


(def-join-thms evthmp-ev)

(defchoose evthmp-ev-falsify (a) (x)
  (not (evthmp-ev x a)))

(defmacro evthmp-ev-theoremp (x)
  `(evthmp-ev ,x (evthmp-ev-falsify ,x)))

(defthm evthmp-ev-theoremp-conjoin-cons
  (iff (evthmp-ev-theoremp (conjoin (cons a b)))
       (and (evthmp-ev-theoremp a)
            (evthmp-ev-theoremp (conjoin b))))
  :hints (("goal" :use
           ((:instance
             evthmp-ev-falsify
             (x (conjoin (cons a b)))
             (a (evthmp-ev-falsify a)))
            (:instance
             evthmp-ev-falsify
             (x a)
             (a (evthmp-ev-falsify (conjoin (cons a b)))))
            (:instance
             evthmp-ev-falsify
             (x (conjoin (cons a b)))
             (a (evthmp-ev-falsify (conjoin b))))
            (:instance
             evthmp-ev-falsify
             (x (conjoin b))
             (a (evthmp-ev-falsify (conjoin (cons a b)))))))))

||#


;; (defthmd evthmp-ev-theoremp-remove-first-lit-when-false
;;   (implies (evthmp-ev-theoremp (list 'not lit))
;;            (iff (evthmp-ev-theoremp (disjoin (cons lit clause)))
;;                 (evthmp-ev-theoremp (disjoin clause))))
;;   :hints (("Goal" :use
;;            ((:instance evthmp-ev-falsify
;;                        (x (disjoin clause))
;;                        (a (evthmp-ev-falsify (disjoin (cons lit clause)))))
;;             (:instance evthmp-ev-falsify
;;                        (x (list 'not lit))
;;                        (a (evthmp-ev-falsify (disjoin clause))))
;;             (:instance evthmp-ev-falsify
;;                        (x (disjoin (cons lit clause)))
;;                        (a (evthmp-ev-falsify (disjoin clause)))))))
;;   :otf-flg t)