Major Section: SYNTAXP
See syntaxp for a basic discussion of the use of
syntaxp to control
A common syntactic restriction is
(SYNTAXP (AND (CONSP X) (EQ (CAR X) 'QUOTE)))or, equivalently,
(SYNTAXP (QUOTEP X)).A rule with such a hypothesis can be applied only if
xis bound to a specific constant. Thus, if
23(which is actually represented internally as
(quote 23)), the test evaluates to
t; but if
(+ 11 12)then the test evaluates to
(car x)is the symbol
binary-+). We see the use of this restriction in the rule
(implies (and (syntaxp (quotep c)) (syntaxp (quotep d))) (equal (+ c d x) (+ (+ c d) x))).If
dare constants, then the
binary-+will evaluate the sum of
d. For instance, under the influence of this rule
(+ 11 12 foo)rewrites to
(+ (+ 11 12) foo)which in turn rewrites to
(+ 23 foo). Without the syntactic restriction, this rule would loop with the built-in rules
We here recommend that the reader try the affects of entering expressions such as the following at the top level ACL2 prompt.
(+ 11 23) (+ '11 23) (+ '11 '23) (+ ''11 ''23) :trans (+ 11 23) :trans (+ '11 23) :trans (+ ''11 23) :trans (+ c d x) :trans (+ (+ c d) x)We also recommend that the reader verify our claim above about looping by trying the affect of each of the following rules individually.
(defthm good (implies (and (syntaxp (quotep c)) (syntaxp (quotep d))) (equal (+ c d x) (+ (+ c d) x))))on (the false) theorems:
(defthm bad (implies (and (acl2-numberp c) (acl2-numberp d)) (equal (+ c d x) (+ (+ c d) x))))
(thm (equal (+ 11 12 x) y))One can use
(thm (implies (and (acl2-numberp c) (acl2-numberp d) (acl2-numberp x)) (equal (+ c d x) y))).
brr, perhaps in conjunction with
cw-gstack, to investigate any looping.
Here is a simple example showing the value of rule
good above. Without
thm form below fails.
(defstub foo (x) t)
(thm (equal (foo (+ 3 4 x)) (foo (+ 7 x))))
The next three examples further explore the use of
We continue the examples of
syntaxp hypotheses with a rule from
books/finite-set-theory/set-theory.lisp. We will not discuss
here the meaning of this rule, but it is necessary to point out that
(ur-elementp nil) is true in this book.
(defthm scons-nil (implies (and (syntaxp (not (equal a ''nil))) (ur-elementp a)) (= (scons e a) (scons e nil)))).Here also,
syntaxpis used to prevent looping. Without the restriction,
(scons e nil)would be rewritten to itself since
(ur-elementp nil)is true.
Nilis a constant just as 23 is. Try
:trans (cons a nil),
:trans (cons 'a 'nil), and
:trans (cons ''a ''nil). Also, don't forget that the arguments to a function are evaluated before the function is applied.
The next two rules move negative constants to the other side of an inequality.
(defthm |(< (+ (- c) x) y)| (implies (and (syntaxp (quotep c)) (syntaxp (< (cadr c) 0)) (acl2-numberp y)) (equal (< (+ c x) y) (< (fix x) (+ (- c) y)))))Questions: What would happen if
(defthm |(< y (+ (- c) x))| (implies (and (syntaxp (quotep c)) (syntaxp (< (cadr c) 0)) (acl2-numberp y)) (equal (< y (+ c x)) (< (+ (- c) y) (fix x)))))
(< (cadr c) '0)were used? What about
(< (cadr c) ''0)?
One can also use
syntaxp to restrict the application of a rule
to a particular set of variable bindings as in the following taken from
(encapsulate ()We recommend the use of
(local (defthm floor-+-crock (implies (and (real/rationalp x) (real/rationalp y) (real/rationalp z) (syntaxp (and (eq x 'x) (eq y 'y) (eq z 'z)))) (equal (floor (+ x y) z) (floor (+ (+ (mod x z) (mod y z)) (* (+ (floor x z) (floor y z)) z)) z)))))
(defthm floor-+ (implies (and (force (real/rationalp x)) (force (real/rationalp y)) (force (real/rationalp z)) (force (not (equal z 0)))) (equal (floor (+ x y) z) (+ (floor (+ (mod x z) (mod y z)) z) (+ (floor x z) (floor y z))))))
brrto investigate the use of
Another useful restriction is defined by
(defun rewriting-goal-literal (x mfc state)We use this restriction in the rule
;; Are we rewriting a top-level goal literal, rather than rewriting ;; to establish a hypothesis from a rewrite (or other) rule?
(declare (ignore x state)) (null (access metafunction-context mfc :ancestors))).
(defthm |(< (* x y) 0)| (implies (and (syntaxp (rewriting-goal-literal x mfc state)) (rationalp x) (rationalp y)) (equal (< (* x y) 0) (cond ((equal x 0) nil) ((equal y 0) nil) ((< x 0) (< 0 y)) ((< 0 x) (< y 0))))))which has been found to be useful, but which also leads to excessive thrashing in the linear arithmetic package if used indiscriminately.
See extended-metafunctions for information on the use of