584
578
`(("Goal" :in-theory (enable ,fn ,@(if (eq fn 'binding-equal) '(bound?-equal) ()))))
585
579
;; The functional instance of the domain and range element types are
586
580
;; presented as lambda forms, since these may be defined as macros.
587
(let ((domain-elem-type-instance (if (equal dom-elem-type-fn *defalist-true-fn*)
581
(let ((domain-elem-type-instance (if (equal dom-elem-type-fn *defalist-true-fn*)
588
582
(remove-equal '(declare (ignore x)) dom-elem-type-fn)
589
583
(cond ((and (consp dom-elem-type-fn)
590
584
(eq (car dom-elem-type-fn) 'acl2::lambda))
591
585
dom-elem-type-fn)
592
586
(t `(lambda (x) (,dom-elem-type-fn x))))))
593
(domain-type-instance (if (equal dom-type-fn *defalist-true-fn*)
587
(domain-type-instance (if (equal dom-type-fn *defalist-true-fn*)
594
588
(remove-equal '(declare (ignore x)) dom-type-fn)
596
(range-elem-type-instance (if (equal ran-elem-type-fn *defalist-true-fn*)
590
(range-elem-type-instance (if (equal ran-elem-type-fn *defalist-true-fn*)
597
591
(remove-equal '(declare (ignore x)) ran-elem-type-fn)
598
592
(cond ((and (consp ran-elem-type-fn)
599
593
(eq (car ran-elem-type-fn) 'acl2::lambda))
600
594
ran-elem-type-fn)
601
595
(t `(lambda (x) (,ran-elem-type-fn x))))))
602
(range-type-instance (if (equal ran-type-fn *defalist-true-fn*)
596
(range-type-instance (if (equal ran-type-fn *defalist-true-fn*)
603
597
(remove-equal '(declare (ignore x)) ran-type-fn)
605
599
`(("Goal" :do-not-induct t
719
713
(all-bindings-equal (not (equal ran-type-fn *defalist-true-fn*)))
723
(defmacro defalist (name formals &rest body)
724
":doc-section data-structures
725
Define a new alist type, and a theory of the alist type.
718
:parents (data-structures)
719
:short "Define a new alist type, and a theory of the alist type."
729
723
(defalist symbol-to-integer-alistp (l)
730
724
\"Recognizes an alist mapping symbols to integers.\"
731
(symbolp . integerp))
725
(symbolp . integerp))
733
727
(defalist symbol-to-bnatural-alistp (l lub)
734
728
\"Recognizes an alists mapping symbols to naturals bounded by lub.\"
735
729
(symbolp . (lambda (x) (bnaturalp x lub))))
737
731
(defalist symbol-alistp (l)
738
732
\"Define an alist theory alists from an unspecified domain type to
740
734
((lambda (x) t) . symbolp)
741
735
(:options :omit-defun (:range-type symbol-listp)))
743
737
(defalist string-to-integer-alistp (l)
744
\"Recognizes an alist mapping strings to integers. Produce a minimal
738
\"Recognizes an alist mapping strings to integers. Produce a minimal
745
739
theory, and store the BINDING-EQUAL lemma as a :TYPE-PRESCRIPTION.\"
746
740
(stringp . integerp)
747
741
(:options (:theory nth put) (:binding-equal-rule-classes :type-prescription)
748
742
(:domain-type string-listp) (:range-type integer-listp)))
752
748
DEFALIST name arglist [documentation] {declaration}* type-pair [option-list]
754
750
option-list ::= (:OPTIONS <<!options>>)
756
752
options ::= !binding-equal-rule-classes-option |
757
753
!omit-defun-option |
759
755
!domain-type-option |
760
756
!range-type-option |
763
759
theory-option ::= (:THEORY <<!alist-functions>>)
765
761
theory-name-option ::= (:THEORY-NAME theory-name)
767
763
alist-functions ::= acons | alistp | all-bindings-equal| all-bound?-equal | append |
768
assoc-equal | bind-all-equal | bind-equal | bind-pairs-equal |
764
assoc-equal | bind-all-equal | bind-equal | bind-pairs-equal |
769
765
binding-equal | bound?-equal | collect-bound-equal | domain |
770
766
domain-restrict-equal | pairlis$ | range | rembind-all-equal |
773
769
binding-equal-rule-classes-option ::= (:BINDING-EQUAL-RULE-CLASSES rule-classes)
775
771
omit-defun-option ::= :OMIT-DEFUN
777
Arguments and Values:
774
<p>Arguments and Values:</p>
779
777
arglist -- an argument list satisfying ACL2::ARGLISTP, and containing
780
778
exactly one symbol whose `print-name' is \"L\".
782
780
declaration -- any valid declaration.
784
782
documentation -- a string; not evaluated.
786
784
name -- a symbol.
788
786
theory-name -- any symbol that is a legal name for a deftheory event.
790
788
type-pair -- A pair (d . r) where d and r are either a function symbol
791
or a one argument LAMBDA function or the constant T.
792
d designates a predicate to be applied to each element of the domain
789
or a one argument LAMBDA function or the constant T.
790
d designates a predicate to be applied to each element of the domain
793
791
of the alist, and r designates a predicate to be applied to each element
794
792
of the range of the alist. T means no type restriction.
799
797
Acl2-theory-expression -- Any legal Acl2 theory expression
803
DEFALIST defines a recognizer for association lists whose pairs map
804
keys of a given type to values of a given type, and by default creates
805
an extensive theory for alists of the newly defined type.
807
To define an alist type with DEFALIST you must supply a name for the alist
800
<h3>Description:</h3>
802
<p>DEFALIST defines a recognizer for association lists whose pairs map
803
keys of a given type to values of a given type, and by default creates
804
an extensive theory for alists of the newly defined type.</p>
806
<p>To define an alist type with DEFALIST you must supply a name for the alist
808
807
recognizer, an argument list for the recognizer, and predicate designator for
809
808
elements of the alist's range. The name may be any symbol. The argument list
810
809
must be valid as a functional argument list, and must contain exactly one
811
810
symbol whose `print-name'is \"L\". By convention this is the alist argument
812
recognized by the function defined by DEFALIST.
811
recognized by the function defined by DEFALIST.</p>
814
The type of the domain and range of the alist is given by a pair (d . r)
813
<p>The type of the domain and range of the alist is given by a pair (d . r)
815
814
where d identifies the type of an element of the alist's domain, and r
816
815
specifies the type of an element of the alist's range. Either of these
817
816
may be specified by a symbol which names a one-argument function (or macro)
818
817
which tests the elements of the domain and range of L. Either of d and r may
819
818
also be specified as a single-argument LAMBDA function. Finally, either of d
820
and r may be specified as the constant t, indicating no type constraint.
822
Any number of other arguments to the alist functions may be supplied,
823
but only the L argument will change in the recursive structure of the recognizer.
825
Note that DEFALIST does not create any guards for L or any other argument.
819
and r may be specified as the constant t, indicating no type constraint.</p>
821
<p>Any number of other arguments to the alist functions may be supplied,
822
but only the L argument will change in the recursive structure of the recognizer.</p>
824
<p>Note that DEFALIST does not create any guards for L or any other argument.
826
825
Guards may be specified in the usual way since any number of DECLARE forms
827
826
may preceed the predicate specification in the DEFALIST form. Bear in mind
828
827
that if you are defining a function to be used as a guard, then you are
829
828
advised to consider what impact guarding the arguments of the function may
830
829
have on its utility. In general the most useful guard functions are those
835
By default, DEFALIST creates an extensive theory for the recognized alists.
836
This theory contains appropriate lemmas for all of the alist functions
830
that are guard-free.</p>
834
<p>By default, DEFALIST creates an extensive theory for the recognized alists.
835
This theory contains appropriate lemmas for all of the alist functions
837
836
appearing in the `alist-functions' syntax description above. One can select
838
837
a subset of this theory to be generated by using the :THEORY option
839
(see below). DEFALIST always creates a :FORWARD-CHAINING rule from the
840
recognizer to ALISTP.
838
(see below). DEFALIST always creates a :FORWARD-CHAINING rule from the
839
recognizer to ALISTP.</p>
842
DEFALIST also creates a DEFTHEORY event that lists all of the lemmas created
841
<p>DEFALIST also creates a DEFTHEORY event that lists all of the lemmas created
843
842
by the DEFALIST. The name of the theory is formed by concatenating the
844
843
function name and the string \"-THEORY\", and INTERNing the resulting string
845
in the package of the function name.
849
DEFALIST options are specified with a special :OPTIONS list systax. If
844
in the package of the function name.</p>
848
<p>DEFALIST options are specified with a special :OPTIONS list systax. If
850
849
present, the :OPTIONS list must appear as the last form in the body of the
855
If the :OMIT-DEFUN keyword is present then the definition will not be
854
<dd>If the :OMIT-DEFUN keyword is present then the definition will not be
856
855
created. Instead, only the list theory for the function is
857
856
generated. Use this option to create a list theory for recognizers
862
This option is used to specify that only a subset of the list theory be
857
defined elsewhere.</dd>
860
<dd>This option is used to specify that only a subset of the list theory be
863
861
created. In the STRINGP-LISTP example above we specify that only lemmas
864
862
about STRINGP-LISTP viz-a-viz NTH and PUT are to be generated. By default
865
863
the complete list theory for the recognizer is created. If the option is
866
864
given as (:THEORY) then the entire theory will be suppressed,
867
except for the :FORWARD-CHAINING rule from the recognizer to TRUE-LISTP.
869
:BINDING-EQUAL-RULE-CLASSES
871
This option specifies a value for the :RULE-CLASSES keyword for the
865
except for the :FORWARD-CHAINING rule from the recognizer to TRUE-LISTP.</dd>
867
<dt>:BINDING-EQUAL-RULE-CLASSES</dt>
868
<dd>This option specifies a value for the :RULE-CLASSES keyword for the
872
869
DEFTHM generated for the BINDING-EQUAL function (and for CDRASSOC) applied to
873
an alist recognized by the DEFALIST recognizer. The default is :REWRITE.
877
This option specifies a predicate that recognizes a list of domain elements.
870
an alist recognized by the DEFALIST recognizer. The default is :REWRITE.</dd>
872
<dt>:DOMAIN-TYPE</dt>
873
<dd>This option specifies a predicate that recognizes a list of domain elements.
878
874
It may be either a symbol or LAMBDA form. If present, and when not prevented
879
875
by a :THEORY specification, a rewrite rule for the type of the domain
880
876
will be generated. A lemma will be generated to check the compatibility
881
of the specified domain type and domain element type.
885
This option specifies a predicate that recognizes a list of range elements.
877
of the specified domain type and domain element type.</dd>
880
<dd>This option specifies a predicate that recognizes a list of range elements.
886
881
It may be either a symbol or LAMBDA form. If present, and when not prevented
887
882
by a :THEORY specification, a rewrite rule for the type of the range
888
883
will be generated. A lemma will be generated to check the compatibility
889
of the specified range type and domain element type.
893
This option allows the user to define the name of the deftheory event
884
of the specified range type and domain element type.</dd>
886
<dt>:THEORY-NAME</dt>
887
<dd>This option allows the user to define the name of the deftheory event
894
888
that is automatically generated, and which includes the defthms that
889
are generated.</dd>")
891
(defmacro defalist (name formals &rest body)
898
893
((syntax-err (defalist-check-syntax name formals body))
899
894
(last-form (car (last body)))