File: mfc-utils.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 (161 lines) | stat: -rw-r--r-- 5,387 bytes parent folder | download | duplicates (6)
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
; MFC Utilities
; Copyright (C) 2008-2013 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.
;
; mfc-utils.lisp -- some generally useful syntaxp/metafunction stuff
;
; Original author: Jared Davis <jared@centtech.com>
;                  Sol Swords <sswords@centtech.com>


; BOZO probably belongs in std/ks, but, surprise surprise, circular dependencies
; would arise, so we're putting it in lists.


(in-package "ACL2")
(program)

; REWRITING-POSITIVE-LITERAL
;
; Recall that an ACL2 goal like (IMPLIES (AND HYP1 ... HYPN) CONCL) is really
; represented as a clause, e.g.,
;
;      (NOT HYP1) \/ (NOT HYP2) \/ ... \/ (NOT HYPN) \/ CONCL
;
; In this representation, ordinarily the hyps are "negative" literals and the
; conclusion is a "positive" literal.  Of course, thanks to eliminating
; double-negatives, a hypothesis like (NOT (EQUAL X Y)) is also a positive
; literal.
;
; Sometimes we want a rewrite rule only to apply when we are rewriting a
; positive literal.
;
; A classic example is:
;
;  - If the CONCL is (EQUAL X Y), and we know that X and Y are sets, then we
;    might want to do something drastic like replace (EQUAL X Y) with (EQUAL
;    (MEMBER A X) (MEMBER A Y)) for some new fresh variable A.
;
;  - But if a HYP is (EQUAL X Y), we probably do not want to apply this same
;    rewrite, because knowing that (MEMBER A X) = (MEMBER A Y) is a much weaker
;    hypothesis than knowing (EQUAL X Y).
;
; Given a rewrite rule such as:
;
;    (implies (and hyp1 ... hypN) (equiv (foo x y z) rhs))
;
; We can restrict the rule to only apply to positive literals by adding a new
; hyp like this:
;
;    (rewriting-positive-literal `(foo ,x ,y ,z))
;
; This expands to a syntaxp hypothesis that looks at the MFC to decide if we
; are currently rewriting a positive literal of the specified form.

(defun mfc-rcnst (mfc state)
  (declare (xargs :stobjs state)
           (ignore state))
  (access metafunction-context mfc :rcnst))

(defun mfc-current-literal (mfc state)
  (declare (xargs :stobjs state))
  (let ((rcnst (mfc-rcnst mfc state)))
    (access rewrite-constant rcnst :current-literal)))

(defun rewriting-positive-literal-fn (term mfc state)
  (declare (xargs :stobjs state))
  (and (or (equal (mfc-current-literal mfc state)
                  (cons nil term)))
       (or (null (mfc-ancestors mfc)))))

(defmacro rewriting-positive-literal (term)
  `(syntaxp (rewriting-positive-literal-fn ,term mfc state)))


(defun rewriting-negative-literal-fn (term mfc state)
  (declare (xargs :stobjs state))
  (and (or (equal (mfc-current-literal mfc state)
                  (cons t term)))
       (or (null (mfc-ancestors mfc)))))

(defmacro rewriting-negative-literal (term)
  `(syntaxp (rewriting-negative-literal-fn ,term mfc state)))

(defun print-mfc (name mfc state)
  (declare (xargs :stobjs state)
           (ignore state))
  (cw "~x0 mfc: ~X12~%" name
      mfc
      (evisc-tuple
       nil nil
       `((,(access metafunction-context mfc :wrld) . "<world>")
         (,(access rewrite-constant
                   (access metafunction-context mfc :rcnst)
                   :current-enabled-structure) "<ens>")) nil)))

;; Arrgh, I'm not really sure how to craft theorems with must-fail/etc that
;; will ensure this is working properly, in case ACL2's MFC representation
;; changes.

;; (logic)

;; (encapsulate
;;   (((hyp *) => *)
;;    ((foo * * *) => *))
;;   (local (defun hyp (x) (declare (ignore x)) nil))
;;   (local (defun foo (x y z) (declare (ignore x y z)) t))
;;   (defthmd constraint
;;     (implies (hyp x) (foo x y z))))

;; (defthm rule1
;;   (implies (and (rewriting-positive-literal `(foo ,x ,y ,z))
;;                 (hyp x))
;;            (foo x y z))
;;   :hints(("Goal" :in-theory (enable constraint))))

;; (defthm test1
;;   (implies (and (posp z)
;;                 (consp y)
;;                 (hyp x)
;;                 (foo x y z))
;;            x)
;;   :rule-classes nil))


;; (defthm test1
;;   (implies (hyp x)
;;            (foo x y z))
;;   :rule-classes nil))

;; (defthm test2
;;   (implies (hyp x)
;;            (not (foo x y z)))
;;   :rule-classes nil))