(primitive) apply a rewrite rule

(rewrite reverse-reverse)
   -- apply the rewrite rule `reverse-reverse'
(rewrite (:rewrite reverse-reverse))
   -- same as above
(rewrite 2)
      that associates 7 to the ``free variable'' y

General Form: (rewrite &optional rule-id substitution)

Replace the current subterm with a new term by applying a rewrite rule. If rule-id is a positive integer n, then the nth rewrite rule as displayed by show-rewrites is the one that is applied. If rule-id is nil or is not supplied, then it is treated as the number 1. Otherwise, rule-id should be either a rune of or name of a rewrite rule. If a name is supplied, then any rule of that name may be used. More explanation of all of these points follows below.


(implies (true-listp x)



First, a rewrite rule is selected according to the arguments of the rewrite instruction. The selection is made as explained above under ``General Form'' above. The ``disambiguating rare arguments'' will rarely be of interest to the user; as explained just above, the stored instruction always contains the name of the rewrite rule, so if there is more than one rule of that name then the system creates and stores these extra arguments in order to make the resulting instruction unambiguous, i.e., so that only one rewrite rule applies. For what it's worth, they correspond respectively to the fields of a rewrite rule record named lhs, rhs, hyps, and equiv.


Now an attempt is made to relieve the hypotheses, in much the same sense as the theorem prover relieves hypotheses except that there is no call to the rewriter. Essentially, this means that the substitution unify-subst is applied to the hypotheses and the system then checks whether all hypotheses are ``clearly'' true in the current context. If there are variables in the hypotheses of the rewrite rule that do not occur in the left-hand side of the conclusion even after the user-supplied substitution (default: nil) is applied, then a weak attempt is made to extend that substitution so that even those hypotheses can be relieved. However, if even one hypothesis remains unrelieved, then no automatic extension of the substitution is made, and in fact hypotheses that contain even one uninstantiated variable will remain unrelieved.

Finally, the instruction is applied as follows. The current subterm is replaced by applying the final substitution, i.e., the extension of unify-subst by the user-supplied substitution which may in turn be extended by the system (as explained above) in order to relieve all hypotheses, to the right-hand side of the selected rewrite rule. And, one new subgoal is created for each unrelieved hypothesis of the rule, whose top-level hypotheses are the governors and top-level hypotheses of the current goal and whose conclusion and current subterm are the instance, by that same final substitution, of that unrelieved hypothesis.
