File: ev-find-rules.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 (162 lines) | stat: -rw-r--r-- 5,682 bytes parent folder | download | duplicates (4)
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
; ev-find-rules.lisp
; Copyright (C) 2012 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 authors: Sol Swords <sswords@centtech.com>

(in-package "ACL2")

;; Provides a way of finding certain rules about evaluators.  Not 100%
;; foolproof, but should be fairly reliable.

;; This is useful for defining evaluator-related utilities that work whether
;; the evaluator was defined with defevaluator or defevaluator-fast,
;; with :namedp t or nil, etc.

;; If this doesn't work as expected, it's because it's looking for certain
;; theorems in the world, and either:
;; -- it found one that seems to match, but wasn't the one you were thinking
;; of.  This could happen because a theorem was proved that was sufficiently
;; similar to the original that our matching was fooled.
;; -- it didn't find any.  This could happen if, say, the exact phrasing of the
;; evaluator theorems is changed.

;; find the ev-lst function given the ev function or vice versa.  Should be its
;; only sibling.
(defun find-ev-counterpart (ev world)
  (car (remove ev (fgetprop ev 'siblings nil world))))


;; Rewrite-rule fields are:
;; rune nume hyps equiv lhs rhs subclass heuristic-info backchain-limit-lst
;; var-info match-free
(defun find-matching-rule (hyps equiv lhs rhs lemmas)
  (if (atom lemmas)
      nil
    (or (let* ((rune  (access rewrite-rule (car lemmas) :rune))
               (rhyps  (access rewrite-rule (car lemmas) :hyps))
               (rlhs   (access rewrite-rule (car lemmas) :lhs))
               (rrhs   (access rewrite-rule (car lemmas) :rhs))
               (requiv (access rewrite-rule (car lemmas) :equiv)))
          (and (or (eq hyps :dont-care)  (equal rhyps hyps))
               (or (eq lhs :dont-care)   (equal rlhs lhs))
               (or (eq rhs :dont-care)   (equal rrhs rhs))
               (or (eq equiv :dont-care) (equal requiv equiv))
               rune))
        (find-matching-rule hyps equiv lhs rhs (cdr lemmas)))))

(defun ev-find-fncall-rule-in-lemmas (ev fn lemmas)
  (find-matching-rule
   `((consp x) (equal (car x) ',fn))        ;; hyps
   'equal
   `(,ev x a)                               ;; lhs
   :dont-care
   lemmas))

(defun ev-find-fncall-rule (ev fn world)
  (find-matching-rule
   `((consp x) (equal (car x) ',fn))        ;; hyps
   'equal
   `(,ev x a)                               ;; lhs
   :dont-care ;; could construct it but this seems basically specific enough
   (fgetprop ev 'lemmas nil world)))

(defun ev-find-fncall-generic-rule (ev world)
  (let ((ev-lst (find-ev-counterpart ev world)))
    (find-matching-rule
     '((consp x)
       (synp 'nil '(syntaxp (not (equal a ''nil)))
             '(if (not (equal a ''nil)) 't 'nil))
       (not (equal (car x) 'quote)))
     'equal
     `(,ev x a)
     `(,ev (cons (car x) (kwote-lst (,ev-lst (cdr x) a))) 'nil)
     (fgetprop ev 'lemmas nil world))))

(defun ev-find-variable-rule (ev world)
  (find-matching-rule
   '((symbolp x))
   'equal
   `(,ev x a)
   '(if x (cdr (assoc-equal x a)) 'nil)
   (fgetprop ev 'lemmas nil world)))

(defun ev-find-nonsymbol-atom-rule (ev world)
  (find-matching-rule
   '((not (consp x))
     (not (symbolp x)))
   'equal
   `(,ev x a)
   ''nil
   (fgetprop ev 'lemmas nil world)))

(defun ev-find-bad-fncall-rule (ev world)
  (find-matching-rule
   '((consp x)
     (not (consp (car x)))
     (not (symbolp (car x))))
   'equal
   `(,ev x a)
   ''nil
   (fgetprop ev 'lemmas nil world)))

(defun ev-find-quote-rule (ev world)
  (find-matching-rule
   '((consp x) (equal (car x) 'quote))
   'equal
   `(,ev x a)
   '(car (cdr x))
   (fgetprop ev 'lemmas nil world)))

(defun ev-find-lambda-rule (ev world)
  (let ((ev-lst (find-ev-counterpart ev world)))
    (find-matching-rule
     '((consp x) (consp (car x)))
     'equal
     `(,ev x a)
     `(,ev (car (cdr (cdr (car x))))
           (pairlis$ (car (cdr (car x)))
                     (,ev-lst (cdr x) a)))
     (fgetprop ev 'lemmas nil world))))

(defun ev-lst-find-atom-rule (ev-lst world)
  (find-matching-rule
   '((not (consp x-lst)))
   'equal
   `(,ev-lst x-lst a)
   ''nil
   (fgetprop ev-lst 'lemmas nil world)))

(defun ev-lst-find-cons-rule (ev-lst world)
  (let ((ev (find-ev-counterpart ev-lst world)))
    (find-matching-rule
     '((consp x-lst))
     'equal
     `(,ev-lst x-lst a)
     `(cons (,ev (car x-lst) a)
            (,ev-lst (cdr x-lst) a))
     (fgetprop ev-lst 'lemmas nil world))))