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
|
; 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 "ACL2")
;; assume.lisp
;;
;; We introduce a utility for sharing assumptions across theorems.
;;
;; BOZO this file should be submitted to the ACL2 distribution and removed from
;; our sources. It should become a "misc" book.
;;; The following legacy doc string was replaced Nov. 2014 by the
;;; auto-generated defxdoc form just below.
; (defdoc assume
; ":Doc-Section Events
;
; a system for sharing assumptions across many theorems~/
;
; We provide a simple table-based system for reusable assumptions. To the
; user, this system takes on the following interface:
; ~bv[]
; (assume <term>)
; adds term to the local assumptions
;
; (unassume <term>)
; removes <term> from the local assumptions
;
; (conclude <name> <thm> :hints ... :rule-classes ...)
; like defth, but proves <thm> under the current assumptions
; ~ev[]
;
; For example, consider the following ACL2 rules:
; ~bv[]
; (defthm natp-of-plus
; (implies (and (natp x)
; (natp y))
; (natp (+ x y))))
;
; (defthm natp-of-minus
; (implies (and (natp x)
; (natp y)
; (< y x))
; (natp (- x y))))
; ~ev[]
;
; We can convert these into the assume/conclude style as follows:
; ~bv[]
; (assume (natp x))
; (assume (natp y))
; (conclude natp-of-plus (natp (+ x y)))
; (conclude natp-of-minus (implies (< y x) (natp (- x y))))
; ~ev[]~/
;
; The ~c[assume] and ~c[unassume] commands are implicitly ~il[local], so you
; can use ~il[encapsulate] in addition to ~c[unassume] to limit the scope of
; your assumptions.
;
; The ~c[conclude] command recognizes ~c[thm]s of the following forms:
; ~bv[]
; (implies (and hyp1 ... hypN) concl)
; (implies hyp1 concl)
; concl
; ~ev[]
;
; It augments the <thm> by injecting the current assumptions after the last
; hyp. That is, we produce:
; ~bv[]
; (implies (and hyp1 ... hypN assm1 ... assmK) concl)
; (implies (and hyp1 assm1 ... assmK) concl)
; (implies (and assm1 ... assmK) concl)
; ~ev[]
;
; We expect this to be appropriate most of the time, since shared hyps tend to
; be ``common'' sorts of things, e.g., type constraints, etc. Meanwhile, the
; unshared hyps should tend to be more complicated and unusual, so we place
; them at the front of the rule in an effort to make ``fast failing'' rules.")
(include-book "xdoc/top" :dir :system)
(defxdoc assume
:parents (events)
:short "A system for sharing assumptions across many theorems"
:long "<p>We provide a simple table-based system for reusable assumptions.
To the user, this system takes on the following interface:</p>
@({
(assume <term>)
adds term to the local assumptions
(unassume <term>)
removes <term> from the local assumptions
(conclude <name> <thm> :hints ... :rule-classes ...)
like defth, but proves <thm> under the current assumptions
})
<p>For example, consider the following ACL2 rules:</p>
@({
(defthm natp-of-plus
(implies (and (natp x)
(natp y))
(natp (+ x y))))
(defthm natp-of-minus
(implies (and (natp x)
(natp y)
(< y x))
(natp (- x y))))
})
<p>We can convert these into the assume/conclude style as follows:</p>
@({
(assume (natp x))
(assume (natp y))
(conclude natp-of-plus (natp (+ x y)))
(conclude natp-of-minus (implies (< y x) (natp (- x y))))
})
<p>The @('assume') and @('unassume') commands are implicitly @(see local), so
you can use @(see encapsulate) in addition to @('unassume') to limit the scope
of your assumptions.</p>
<p>The @('conclude') command recognizes @('thm')s of the following forms:</p>
@({
(implies (and hyp1 ... hypN) concl)
(implies hyp1 concl)
concl
})
<p>It augments the <thm> by injecting the current assumptions after the
last hyp. That is, we produce:</p>
@({
(implies (and hyp1 ... hypN assm1 ... assmK) concl)
(implies (and hyp1 assm1 ... assmK) concl)
(implies (and assm1 ... assmK) concl)
})
<p>We expect this to be appropriate most of the time, since shared hyps tend
to be ``common'' sorts of things, e.g., type constraints, etc. Meanwhile, the
unshared hyps should tend to be more complicated and unusual, so we place them
at the front of the rule in an effort to make ``fast failing'' rules.</p>")
(table assume.table 'assumptions nil)
(defun assume.get-assumptions (world)
(declare (xargs :mode :program))
(cdr (assoc-eq 'assumptions (table-alist 'assume.table world))))
(defun assume.assume-fn (assm)
`(local (table assume.table 'assumptions
(cons ',assm (assume.get-assumptions world)))))
(defmacro assume (assm)
(assume.assume-fn assm))
(defun assume.unassume-fn (assm)
(declare (xargs :mode :program))
`(local (table assume.table 'assumptions
(remove-equal ',assm (assume.get-assumptions world)))))
(defmacro unassume (assm)
(assume.unassume-fn assm))
(defun assume.conclude-fn (name thm extra-args world)
(declare (xargs :mode :program))
(cond ((and (consp thm)
(equal (first thm) 'implies)
(consp (second thm))
(equal (first (second thm)) 'and))
;; Thm has the form (implies (and hyp1 ... hypN) concl)
(let ((hyps (cdr (second thm)))
(concl (third thm)))
`(defthm ,name
(implies (and ,@(append hyps (assume.get-assumptions world)))
,concl)
,@extra-args)))
((and (consp thm)
(equal (first thm) 'implies))
;; Thm has the form (implies hyp1 concl)
(let ((hyps (list (second thm)))
(concl (third thm)))
`(defthm ,name
(implies (and ,@(append hyps (assume.get-assumptions world)))
,concl)
,@extra-args)))
(t
;; Thm has the form concl
`(defthm ,name
(implies (and ,@(assume.get-assumptions world))
,thm)
,@extra-args))))
(defmacro conclude (name thm &rest extra-args)
`(make-event (assume.conclude-fn ',name ',thm ',extra-args (w state))))
(defmacro MILAWA::assume (&rest args)
`(ACL2::assume ,@args))
(defmacro MILAWA::unassume (&rest args)
`(ACL2::unassume ,@args))
(defun milawa-conclude-fn (name thm extra-args world)
(declare (xargs :mode :program))
(cond ((and (consp thm)
(equal (first thm) 'implies)
(consp (second thm))
(equal (first (second thm)) 'and))
;; Thm has the form (implies (and hyp1 ... hypN) concl)
(let ((hyps (cdr (second thm)))
(concl (third thm)))
`(MILAWA::defthm ,name
(implies (and ,@(ACL2::append hyps (ACL2::assume.get-assumptions world)))
,concl)
,@extra-args)))
((and (consp thm)
(equal (first thm) 'implies))
;; Thm has the form (implies hyp1 concl)
(let ((hyps (list (second thm)))
(concl (third thm)))
`(MILAWA::defthm ,name
(implies (and ,@(ACL2::append hyps (ACL2::assume.get-assumptions world)))
,concl)
,@extra-args)))
(t
;; Thm has the form concl
`(MILAWA::defthm ,name
(implies (and ,@(ACL2::assume.get-assumptions world))
,thm)
,@extra-args))))
(defmacro MILAWA::conclude (name thm &rest extra-args)
`(ACL2::make-event (milawa-conclude-fn ',name ',thm ',extra-args (ACL2::w ACL2::state))))
|