Included Books
other
(in-package "ACL2")
include-book
(include-book "std/util/bstar" :dir :system)
other
(defxdoc def-functional-instance :parents (functional-instantiation) :short "Functionally instantiate a pre-existing theorem to prove a new one." :long "<p>Usage:</p> @({ (def-functional-instance new-thm-name orig-thm-name ((orig-fn substitute-fn) ...) :hints (...) ;; optional :rule-classes rule-classes) ;; optional }) <p>Def-functional-instance attempts to define a new theorem based on functionally instantiating an existing one with a user-provided function substitution. It looks up the body of the theorem named ORIG-THM-NAME in the ACL2 world and applies the functional substitution, replacing each ORIG-FN with SUBSTITUTE-FN in the theorem body. It then submits this as a new theorem named NEW-THM-NAME with a hint to prove it using a functional instance of the original theorem. This theorem has either the given rule-classes or, if this argument is omitted, the rule-classes of the original theorem.</p> <p>Sometimes further hints are needed to show that the functional instantiation is valid. These may be given by the :hints keyword. Note, however, that there is already a hint provided at "goal", so that if one of the user-provided hints uses this as its subgoal specifier, this hint will be ignored. The extra hints given should either be computed hints or reference later subgoals.</p>")
look-for-goal-hintfunction
(defun look-for-goal-hint (hints) (if (atom hints) nil (or (and (consp (car hints)) (stringp (caar hints)) (standard-char-listp (coerce (caar hints) 'list)) (equal (string-upcase (caar hints)) "GOAL") (car hints)) (look-for-goal-hint (cdr hints)))))
def-functional-instance-fnfunction
(defun def-functional-instance-fn (newname oldname subst hints rule-classes rule-classesp translate macro-subst by-hint-p state) (declare (xargs :stobjs state :mode :program)) (b* ((world (w state)) (body (if translate (fgetprop oldname 'theorem nil world) (fgetprop oldname 'untranslated-theorem nil world))) (rule-classes (if rule-classesp rule-classes (fgetprop oldname 'classes nil world))) ((unless body) (er soft 'def-functional-instance-fn "Theorem ~x0 not found in the ACL2 world" oldname)) (alist (append (pairlis$ (strip-cars subst) (strip-cadrs subst)) (pairlis$ (strip-cars macro-subst) (strip-cadrs macro-subst)))) (new-body (sublis alist body)) (untrans-body (if translate (untranslate new-body nil world) new-body)) (form `(defthm ,NEWNAME ,UNTRANS-BODY :hints (("goal" ,@(IF BY-HINT-P `(:BY (:FUNCTIONAL-INSTANCE ,OLDNAME . ,SUBST)) `(:USE ((:FUNCTIONAL-INSTANCE ,OLDNAME . ,SUBST)))) . ,(CDR (LOOK-FOR-GOAL-HINT HINTS))) . ,HINTS) :rule-classes ,RULE-CLASSES))) (value form)))
def-functional-instancemacro
(defmacro def-functional-instance (newname oldname subst &key hints (rule-classes 'nil rule-classesp) (translate 't) (by-hint-p 'nil) macro-subst) `(make-event (def-functional-instance-fn ',NEWNAME ',OLDNAME ',SUBST ',HINTS ',RULE-CLASSES ',RULE-CLASSESP ',TRANSLATE ',MACRO-SUBST ',BY-HINT-P state)))