#| Author: Pete Manolios Date: 9/29/2021 Code used in lecture 10 of Computer-Aided Reasoning. |# (in-package "ACL2S") (set-gag-mode nil) "Let's look at some other examples of macros. Here is an example when we discussed defdata. Defdata is a macro, so let's see what it translates into." :trans1 (defdata file (list string nat)) "Notice the with-output form. It allows us to control how much output a user sees. So, if something fails, or if we want to explore, we can strip that out. Next, let's look at the defdata::defdata-events form. " (DEFDATA::DEFDATA-EVENTS (DEFDATA::PARSE-DEFDATA '(FILE (LIST STRING NAT)) (CURRENT-PACKAGE STATE) (W STATE)) (W STATE)) "First, notice state and (w state), the world. The ACL2 logical world is a data structure that includes all logical content resulting from the commands evaluated. The world includes a representation of the current logical theory, as well as some extra-logical information such as the values of ACL2 tables. Let's look at the documentation on state. " "Back to the defdata. Again, we can pull out the with-output body, which is a progn and we can submit each argument to the progn to ACL2 to see what happens. We won't do that, but notice the definitions of the recognizer, the enumerator and a version of the enumerator that takes a seed: (DEFUN FILEP (DEFDATA::V1) (DEFUN NTH-FILE-BUILTIN (DEFDATA::I1) (DEFUN NTH-FILE/ACC-BUILTIN (DEFDATA::SIZE1 DEFDATA::_SEED) Let's submit this. " (defdata file (list string nat)) "Now, the more interesting form. " :trans1 (defdata (dir (list string dir-file-list)) (dir-file-list (listof file-dir)) (file-dir (or file dir))) "As before, let's look at the defdata::defdata-events form. " (DEFDATA::DEFDATA-EVENTS (DEFDATA::PARSE-DEFDATA '((DIR (LIST STRING DIR-FILE-LIST)) (DIR-FILE-LIST (LISTOF FILE-DIR)) (FILE-DIR (OR FILE DIR))) (CURRENT-PACKAGE STATE) (W STATE)) (W STATE)) "I bring your attention to the following form that shows how to define mutually recursive functions. I remove package names to make this more readable. (MUTUAL-RECURSION (DEFUN DIRP (V1) (DECLARE (XARGS :GUARD T)) (AND (CONSP V1) (STRINGP (CAR V1)) (AND (CONSP (CDR V1)) (DIR-FILE-LISTP (CAR (CDR V1))) (EQUAL (CDR (CDR V1)) NIL)))) (DEFUN DIR-FILE-LISTP (V1) (DECLARE (XARGS :GUARD T)) (OR (EQUAL V1 NIL) (AND (CONSP V1) (FILE-DIRP (CAR V1)) (DIR-FILE-LISTP (CDR V1))))) (DEFUN FILE-DIRP (V1) (DECLARE (XARGS :GUARD T)) (OR (FILEP V1) (DIRP V1)))) Notice that we need to prove termination to show that this defdata makes sense. " "Let's submit it. " (defdata (dir (list string dir-file-list)) (dir-file-list (listof file-dir)) (file-dir (or file dir))) "Can you write defdatas that don't make sense? Sure. Here is an example that differs from the above by a few characters. " :u (defdata (dir (list string dir-file-list)) (dir-file-list (listof file-dir)) (file-dir (or file file-dir))) "Here is simpler example. " (defdata (foo (or string bar)) (bar (or nat foo))) "Let's discuss libraries and books. " :pbt -5 "Let's look at some of the books that are included. Let's start with base-theory. " "Next, let's look at std/lists/top. " "Notice that there are lots of libraries (books) that are used to reason about true-lists, app, len, rev, etc. So, example, we can see what rules are available for reasoning about true-listp, as follows. " :pl append :doc pl :pl tlp :pl (rev (app x y)) "Especially with all of these theorems pre-loaded, you may want to figure out why something is taking so long. A really useful utility is accumulated-persistence." :doc accumulated-persistence