File: evaluator.lisp

package info (click to toggle)
acl2 8.6%2Bdfsg-3
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 1,138,276 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,978; makefile: 3,840; ruby: 2,633; yacc: 1,126; ml: 763; awk: 295; csh: 233; lex: 197; php: 178; tcl: 49; asm: 23; haskell: 17
file content (426 lines) | stat: -rw-r--r-- 19,727 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
; 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 "definitions")
(%interactive)


(%autoadmit flag-generic-evaluator)
(%autoadmit generic-evaluator)
(%autoadmit generic-evaluator-list)

(%autoprove definition-of-generic-evaluator
            (%enable default generic-evaluator generic-evaluator-list)
            (%restrict default flag-generic-evaluator (equal x 'x)))

(%autoprove definition-of-generic-evaluator-list
            (%enable default generic-evaluator generic-evaluator-list)
            (%restrict default flag-generic-evaluator (equal x 'x)))

(%autoprove flag-generic-evaluator-when-term
            (%enable default generic-evaluator))

(%autoprove flag-generic-evaluator-when-list
            (%enable default generic-evaluator-list))

(%autoprove generic-evaluator-list-when-not-consp
            (%restrict default definition-of-generic-evaluator-list (equal x 'x)))

(%autoprove generic-evaluator-list-of-cons
            (%restrict default definition-of-generic-evaluator-list (equal x '(cons a x))))

(%autoprove true-listp-of-generic-evaluator-list
            (%cdr-induction x))

(%autoprove forcing-len-of-cdr-of-generic-evaluator-list
            (%cdr-induction x))

(%autoprove consp-of-generic-evaluator-list
            (%cdr-induction x))



(defmacro %flag-generic-evaluator-induction (flag x defs n)
  `(%induct (two-nats-measure ,n (rank ,x))

            ((and (equal ,flag 'term)
                  (zp ,n))
             nil)

            ((and (equal ,flag 'term)
                  (not (zp ,n))
                  (logic.functionp ,x)
                  (equal (logic.function-name ,x) 'if)
                  (equal (len (logic.function-args ,x)) '3))
             (((,flag 'term) (,x (first (logic.function-args ,x))))
              ((,flag 'term) (,x (second (logic.function-args ,x))))
              ((,flag 'term) (,x (third (logic.function-args ,x))))))

             ((and (equal ,flag 'term)
                   (not (zp ,n))
                   (logic.functionp ,x)
                   (not (and (equal (logic.function-name ,x) 'if)
                             (equal (len (logic.function-args ,x)) '3))))
              (((,flag 'list) (,x (logic.function-args ,x)))
               ((,flag 'term)
                (x
                 (logic.substitute
                  (logic.=rhs (definition-list-lookup (logic.function-name ,x) ,defs))
                  (pair-lists
                   (logic.function-args
                    (logic.=lhs (definition-list-lookup (logic.function-name ,x) ,defs)))
                   (cdr (flag-generic-evaluator 'list
                                                (logic.function-args ,x)
                                                ,defs ,n)))))
                (,n (- ,n '1)))))

             ((and (equal ,flag 'term)
                   (not (zp ,n))
                   (logic.lambdap ,x))
              (((,flag 'list) (,x (logic.lambda-actuals ,x)))
               ((,flag 'term)
                (,x (logic.substitute
                    (logic.lambda-body ,x)
                    (pair-lists (logic.lambda-formals ,x)
                                (cdr (flag-generic-evaluator 'list
                                                             (logic.lambda-actuals ,x)
                                                             ,defs ,n)))))
                (,n (- ,n '1)))))

             ((and (equal ,flag 'term)
                   (not (zp ,n))
                   (not (logic.functionp ,x))
                   (not (logic.lambdap ,x)))
              nil)

             ((and (not (equal ,flag 'term))
                   (consp ,x))
              (((,flag 'term) (,x (car ,x)))
               ((,flag 'list) (,x (cdr ,x)))))

             ((and (not (equal ,flag 'term))
                   (not (consp ,x)))
              nil)))

;; (defmacro %flag-generic-evaluator-induction (flag x defs n)
;;   `(%induct (two-nats-measure ,n (rank ,x))
;;             ((and (equal ,flag 'term)
;;                   (zp ,n))
;;              nil)
;;             ((and (equal ,flag 'term)
;;                   (not (zp ,n))
;;                   (logic.constantp ,x))
;;              nil)
;;             ((and (equal ,flag 'term)
;;                   (not (zp ,n))
;;                   (logic.variablep ,x))
;;              nil)
;;             ((and (equal ,flag 'term)
;;                   (not (zp ,n))
;;                   (logic.functionp ,x)
;;                   (equal (logic.function-name ,x) 'if)
;;                   (equal (len (logic.function-args ,x)) '3))
;;              (((,flag 'term) (,x (first (logic.function-args ,x))))
;;               ((,flag 'term) (,x (second (logic.function-args ,x))))
;;               ((,flag 'term) (,x (third (logic.function-args ,x))))))
;;              ((and (equal ,flag 'term)
;;                    (not (zp ,n))
;;                    (logic.functionp ,x)
;;                    (not (and (equal (logic.function-name ,x) 'if)
;;                              (equal (len (logic.function-args ,x)) '3))))
;;               (((,flag 'list) (,x (logic.function-args ,x)))
;;                ((,flag 'term)
;;                 (x
;;                  (logic.substitute
;;                   (logic.=rhs (definition-list-lookup (logic.function-name ,x) ,defs))
;;                   (pair-lists
;;                    (logic.function-args
;;                     (logic.=lhs (definition-list-lookup (logic.function-name ,x) ,defs)))
;;                    (cdr (flag-generic-evaluator 'list
;;                                                 (logic.function-args ,x)
;;                                                 ,defs ,n)))))
;;                 (,n (- ,n '1)))))
;;              ((and (equal ,flag 'term)
;;                    (not (zp ,n))
;;                    (logic.lambdap ,x))
;;               (((,flag 'list) (,x (logic.lambda-actuals ,x)))
;;                ((,flag 'term)
;;                 (,x (logic.substitute
;;                     (logic.lambda-body ,x)
;;                     (pair-lists (logic.lambda-formals ,x)
;;                                 (cdr (flag-generic-evaluator 'list
;;                                                              (logic.lambda-actuals ,x)
;;                                                              ,defs ,n)))))
;;                 (,n (- ,n '1)))))
;;              ((and (equal ,flag 'term)
;;                    (not (zp ,n))
;;                    (not (logic.constantp ,x))
;;                    (not (logic.variablep ,x))
;;                    (not (logic.functionp ,x))
;;                    (not (logic.lambdap ,x)))
;;               nil)
;;              ((and (not (equal ,flag 'term))
;;                    (consp ,x))
;;               (((,flag 'term) (,x (car ,x)))
;;                ((,flag 'list) (,x (cdr ,x)))))
;;              ((and (not (equal ,flag 'term))
;;                    (not (consp ,x)))
;;               nil)))

;; (defthmd open-generic-evaluator-when-zp
;;   (implies (and (syntaxp (equal x 'x))
;;                 (zp n))
;;            (equal (generic-evaluator x defs n)
;;                   nil))
;;   :rule-classes ((:rewrite :backchain-limit-lst 0))
;;   :hints(("Goal" :in-theory (enable definition-of-generic-evaluator))))

;; (defthmd open-generic-evaluator-when-logic.constantp
;;   (implies (and (syntaxp (equal x 'x))
;;                 (not (zp n))
;;                 (logic.constantp x))
;;            (equal (generic-evaluator x defs n)
;;                   x))
;;   :rule-classes ((:rewrite :backchain-limit-lst 0))
;;   :hints(("Goal" :in-theory (enable definition-of-generic-evaluator))))

;; (defthmd open-generic-evaluator-when-logic.variablep
;;   (implies (and (syntaxp (equal x 'x))
;;                 (logic.variablep x))
;;            (equal (generic-evaluator x defs n)
;;                   nil))
;;   :rule-classes ((:rewrite :backchain-limit-lst 0))
;;   :hints(("Goal" :in-theory (enable definition-of-generic-evaluator))))

;; (defthmd open-generic-evaluator-when-if
;;   (implies (and (syntaxp (equal x 'x))
;;                 (not (zp n))
;;                 (logic.functionp x)
;;                 (equal (logic.function-name x) 'if)
;;                 (equal (len (logic.function-args x)) 3))
;;            (equal (generic-evaluator x defs n)
;;                   (let* ((args (logic.function-args x))
;;                          (eval-test (generic-evaluator (first args) defs n)))
;;                     (and eval-test
;;                          (if (logic.unquote eval-test)
;;                              (generic-evaluator (second args) defs n)
;;                            (generic-evaluator (third args) defs n))))))
;;   :rule-classes ((:rewrite :backchain-limit-lst 0))
;;   :hints(("Goal" :in-theory (e/d (definition-of-generic-evaluator)
;;                                  ((:executable-counterpart ACL2::force))))))

;; (defthmd open-generic-evaluator-when-not-if
;;   (implies (and (syntaxp (equal x 'x))
;;                 (not (zp n))
;;                 (logic.functionp x)
;;                 (not (equal (logic.function-name x) 'if)))
;;            (equal (generic-evaluator x defs n)
;;                   (let* ((name (logic.function-name x))
;;                          (args (logic.function-args x))
;;                          (eval-args (generic-evaluator-list args defs n)))
;;                     (and eval-args
;;                          (let ((values (cdr eval-args)))
;;                            (if (memberp name (domain (logic.initial-arity-table)))
;;                                (and (equal (cdr (lookup name (logic.initial-arity-table))) (len values))
;;                                     (logic.base-evaluator (logic.function name values)))
;;                              (let* ((def (definition-list-lookup name defs)))
;;                                (and def
;;                                     (let ((formals (logic.function-args (logic.=lhs def)))
;;                                           (body    (logic.=rhs def)))
;;                                       (and (equal (len formals) (len values))
;;                                            (generic-evaluator (logic.substitute body (pair-lists formals values))
;;                                                               defs (- n 1))))))))))))
;;   :rule-classes ((:rewrite :backchain-limit-lst 0))
;;   :hints(("Goal" :in-theory (e/d (definition-of-generic-evaluator)
;;                                  ((:executable-counterpart ACL2::force))))))

;; (defthmd open-generic-evaluator-when-not-length-three
;;   (implies (and (syntaxp (equal x 'x))
;;                 (not (zp n))
;;                 (logic.functionp x)
;;                 (not (equal (len (logic.function-args x)) 3)))
;;            (equal (generic-evaluator x defs n)
;;                   (let* ((name (logic.function-name x))
;;                          (args (logic.function-args x))
;;                          (eval-args (generic-evaluator-list args defs n)))
;;                     (and eval-args
;;                          (let ((values (cdr eval-args)))
;;                            (if (memberp name (domain (logic.initial-arity-table)))
;;                                (and (equal (cdr (lookup name (logic.initial-arity-table))) (len values))
;;                                     (logic.base-evaluator (logic.function name values)))
;;                              (let* ((def (definition-list-lookup name defs)))
;;                                (and def
;;                                     (let ((formals (logic.function-args (logic.=lhs def)))
;;                                           (body    (logic.=rhs def)))
;;                                       (and (equal (len formals) (len values))
;;                                            (generic-evaluator (logic.substitute body (pair-lists formals values))
;;                                                               defs (- n 1))))))))))))
;;   :rule-classes ((:rewrite :backchain-limit-lst 0))
;;   :hints(("Goal"
;;           :expand (generic-evaluator x defs n)
;;           :in-theory (e/d (definition-of-generic-evaluator)
;;                           ((:executable-counterpart ACL2::force))))))

;; (defthmd open-generic-evaluator-when-logic.lambdap
;;   (implies (and (syntaxp (equal x 'x))
;;                 (not (zp n))
;;                 (logic.lambdap x))
;;            (equal (generic-evaluator x defs n)
;;                   (let ((formals (logic.lambda-formals x))
;;                         (body    (logic.lambda-body x))
;;                         (actuals (logic.lambda-actuals x)))
;;                     (let ((eval-actuals (generic-evaluator-list actuals defs n)))
;;                       (and eval-actuals
;;                            (let ((values (cdr eval-actuals)))
;;                              (generic-evaluator (logic.substitute body (pair-lists formals values))
;;                                                 defs (- n 1))))))))
;;   :rule-classes ((:rewrite :backchain-limit-lst 0))
;;   :hints(("Goal" :in-theory (e/d (definition-of-generic-evaluator)
;;                                  ((:executable-counterpart ACL2::force))))))

;; (defthmd open-generic-evaluator-when-degenerate
;;   (implies (and (syntaxp (equal x 'x))
;;                 (not (logic.constantp x))
;;                 (not (logic.variablep x))
;;                 (not (logic.functionp x))
;;                 (not (logic.lambdap x)))
;;            (equal (generic-evaluator x defs n)
;;                   nil))
;;   :rule-classes ((:rewrite :backchain-limit-lst 0))
;;   :hints(("Goal" :in-theory (enable definition-of-generic-evaluator))))

;; (deftheory open-generic-evaluator-theory
;;   '(open-generic-evaluator-when-zp
;;     open-generic-evaluator-when-logic.constantp
;;     open-generic-evaluator-when-logic.variablep
;;     open-generic-evaluator-when-if
;;     open-generic-evaluator-when-not-if
;;     open-generic-evaluator-when-not-length-three
;;     open-generic-evaluator-when-logic.lambdap
;;     open-generic-evaluator-when-degenerate))







;; (%autoprove open-generic-evaluator-when-zp
;;             (%restrict default definition-of-generic-evaluator (equal x 'x)))

;; (%autoprove open-generic-evaluator-when-logic.constantp
;;             (%restrict default definition-of-generic-evaluator (equal x 'x)))

;; (%autoprove open-generic-evaluator-when-logic.variablep
;;             (%restrict default definition-of-generic-evaluator (equal x 'x)))

;; (%autoprove open-generic-evaluator-when-if
;;             (%restrict default definition-of-generic-evaluator (equal x 'x)))

;; (%autoprove open-generic-evaluator-when-not-if
;;             (%restrict default definition-of-generic-evaluator (equal x 'x)))

;; (%autoprove open-generic-evaluator-when-not-length-three
;;             (%restrict default definition-of-generic-evaluator (equal x 'x)))

;; (%autoprove open-generic-evaluator-when-logic.lambdap
;;             (%restrict default definition-of-generic-evaluator (equal x 'x)))

;; (%autoprove open-generic-evaluator-when-degenerate
;;             (%restrict default definition-of-generic-evaluator (equal x 'x)))


;; (%create-theory open-generic-evaluator-theory)
;; (%enable open-generic-evaluator-theory
;;          open-generic-evaluator-when-zp
;;          open-generic-evaluator-when-logic.constantp
;;          open-generic-evaluator-when-logic.variablep
;;          open-generic-evaluator-when-if
;;          open-generic-evaluator-when-not-if
;;          open-generic-evaluator-when-not-length-three
;;          open-generic-evaluator-when-logic.lambdap
;;          open-generic-evaluator-when-degenerate)



;; But I think it may be relevant to note that there wasn't much of a savings at all by
;; using the opener theory instead of the definitions themselves.  With the original
;; induction scheme, we're looking at 338K with openers versus 346K with restrict.
;;
;;  -  also consider consolidated induction schemes, and see if they are any use.
;;     (they might work using the restrict style, even if they aren't suited for openers.)
;;   -- Wow!  That reduced the proof to 110M conses.  And, the compiling time was only
;;      a minute. (of course building the skeleton took longer than that).
;;
;;  -  also try opening the functions right away, not waiting for one pass of auto
;;     to go first.  eeeeh, this seems bad.
;;
;;  - how about not forcing until we've issued the restrict hints?  hrmn, that seems to
;;    be very slow during rewriting.  i got bored and didn't let it finish.

;; 338K conses, 1306 seconds to compile.  damn.
;; (%autoprove lemma-for-forcing-logic.constantp-of-cdr-of-generic-evaluator
;;             (%flag-generic-evaluator-induction flag x defs n)
;;             (%auto :strategy (cleanup split urewrite))
;;             (%disable default  ;; speed hint
;;                       logic.termp-when-logic.formulap
;;                       logic.constantp-when-logic.variablep
;;                       logic.variablep-when-logic.constantp
;;                       logic.constantp-when-logic.functionp
;;                       same-length-prefixes-equal-cheap
;;                       not-equal-when-less
;;                       not-equal-when-less-two)
;;             (%crewrite default)
;;             (%enable default open-generic-evaluator-theory))


;; trying new induction scheme.
;; orig scheme: 346k conses this way.  bleh.  but only 1134 seconds to compile.
;; new scheme: way fewer initial goals (4500 vs 50k)

;; also, consider not forcing until we open up the definitions?
(%autoprove lemma-for-forcing-logic.constantp-of-cdr-of-generic-evaluator
            (%flag-generic-evaluator-induction flag x defs n)
            (%auto)
            (%restrict default definition-of-generic-evaluator (equal x 'x))
            (%restrict default definition-of-generic-evaluator-list (equal x 'x))
            (%auto :steps 90))


(%autoprove forcing-logic.constantp-of-cdr-of-generic-evaluator
            (%use (%instance (%thm lemma-for-forcing-logic.constantp-of-cdr-of-generic-evaluator)
                             (flag 'term))))

(%autoprove forcing-logic.constant-listp-of-cdr-of-generic-evaluator-list
            (%use (%instance (%thm lemma-for-forcing-logic.constantp-of-cdr-of-generic-evaluator)
                             (flag 'list))))