Partial merge from kind-backend branch, including Minisat and CNF work to
[cvc5.git] / src / theory / builtin / kinds
1 # kinds [for builtin theory] -*- sh -*-
2 #
3 # This "kinds" file is written in a domain-specific language for
4 # declaring CVC4 kinds. Comments are marked with #, as this line is.
5 #
6 # The first non-blank, non-comment line in this file must be a theory
7 # declaration:
8 #
9 # theory ID T header
10 #
11 # Thereafter, ID is bound to your theory. It becomes part of an
12 # enumeration that identifies all theories. If your theory has
13 # several, distinct implementations, they still all share a kinds
14 # file, a theory ID, all the defined kinds/operators/types for the
15 # theory, typechecker, etc. They should also share a base class
16 # (that's the T above). The header is the header for this base
17 # class.
18 #
19 # The very end of this file should end with:
20 #
21 # endtheory
22 #
23 # There are several basic commands:
24 #
25 # properties PROPERTIES...
26 #
27 # This command declares properties of the theory. It can occur
28 # more than once, in which case the effect is additive.
29 #
30 # The current set of properties and their meanings are:
31 #
32 # finite the theory is finite
33 # stable-infinite the theory is stably infinite
34 # polite the theory is polite
35 #
36 # check the theory supports the check() function
37 # propagate the theory supports propagate() (and explain())
38 # staticLearning the theory supports staticLearning()
39 # notifyRestart the theory supports notifyRestart()
40 # presolve the theory supports presolve()
41 #
42 # In the case of the "theory-supports-function" properties, you
43 # need to declare these for your theory or the functions will not
44 # be called! This is used to speed up the core where functionality
45 # is not needed.
46 #
47 # rewriter T header
48 #
49 # This declares a rewriter class T for your theory, declared in
50 # header. Your rewriter class provides four functions:
51 #
52 # static void init();
53 # static void shutdown();
54 # static RewriteResponse preRewrite(TNode node);
55 # static RewriteResponse postRewrite(TNode node);
56 #
57 # ...BUT please note that init() and shutdown() may be removed in
58 # future, so if possible, do not rely on them being called (and
59 # implement them as a no-op).
60 #
61 # typechecker header
62 #
63 # Declare that this theory's typechecker class is defined in the
64 # given header. (#include'd by the TypeChecker class in the expr
65 # package.)
66 #
67 # variable K ["comment"]
68 #
69 # This declares a kind K that has no operator (it's conceptually a
70 # VARIABLE). This is appropriate for things like VARIABLE and
71 # SKOLEM.
72 #
73 # operator K #children ["comment"]
74 #
75 # Declares a "built-in" operator kind K. Really this is the same
76 # as "variable" except that it has an operator (automatically
77 # generated by NodeManager).
78 #
79 # You can specify an exact # of children required as the second
80 # argument to the operator command. In debug mode, assertions are
81 # automatically included to ensure that no Nodes can ever be
82 # created violating this. (FIXME: the public Expr stuff should
83 # enforce them regardless of whether debugging or not.) For
84 # example, a binary operator could be specified as:
85 #
86 # operator LESS_THAN 2 "arithmetic comparison, x < y"
87 #
88 # Alternatively, a range can be specified for #children as
89 # "LB:[UB]", LB and UB representing lower and upper bounds on the
90 # number of children (inclusive). If there is no lower bound, put
91 # a "1" (operators must have at least one child). If there is no
92 # upper bound, leave the colon after LB, but omit UB. For example,
93 # an N-ary operator might be defined as:
94 #
95 # operator PLUS 2: "addition on two or more arguments"
96 #
97 # parameterized K #children ["comment"]
98 #
99 # Declares a "built-in" parameterized operator kind K. This is a
100 # theory-specific APPLY, e.g., APPLY_UF, which applies its first
101 # parameter (say, "f"), to its operands (say, "x" and "y", making
102 # the full application "f(x,y)"). Nodes with such a kind will
103 # have an operator (Node::hasOperator() returns true, and
104 # Node::getOperator() returns the Node of functional type
105 # representing "f" here), and the "children" are defined to be
106 # this operator's parameters, and don't include the operator
107 # itself (here, there are only two children "x" and "y").
108 #
109 # LB and UB are the same as documented for the operator command,
110 # except that parameterized operators may have zero children. The
111 # first parameter (the function being applied) does not count as a
112 # child.
113 #
114 # For consistency these should start with "APPLY_", but this is
115 # not enforced.
116 #
117 # constant K T Hasher header ["comment"]
118 #
119 # Declares a constant kind K. T is the C++ type representing the
120 # constant internally (and it should be
121 # ::fully::qualified::like::this), and header is the header needed
122 # to define it. Hasher is a hash functor type defined like this:
123 #
124 # struct MyHashFcn {
125 # static size_t hash(const T& val);
126 # };
127 #
128 # For consistency, constants taking a non-void payload should
129 # start with "CONST_", but this is not enforced.
130 #
131 # typerule K typechecker-class
132 #
133 # Declares that a (previously-declared) kind K is typechecked by
134 # the typechecker-class. This class should be defined by the
135 # header given to the "typechecker" command, above. The
136 # typechecker-class is used this way by the main TypeChecker code:
137 #
138 # typechecker-class::computeType(NodeManager* nm, TNode n, bool check)
139 #
140 # It returns TypeNode. It should compute the type of n and return it,
141 # and if "check" is true, should actually perform type checking instead
142 # of simply type computation.
143 #
144 # sort K cardinality [well-founded ground-term header | not-well-founded] ["comment"]
145 #
146 # This creates a kind K that represents a sort (a "type constant").
147 # These kinds of types are "atomic" types; if you need to describe
148 # a complex type that takes type arguments (like arrays), use
149 # "operator"; if you need to describe one that takes "constant"
150 # arguments (like bitvectors), use "constant", and if you invent
151 # one that takes both, you could try "parameterized". In those
152 # cases, you'll want to provide a cardinality separately for your
153 # type.
154 #
155 # The cardinality argument is a nonnegative number (if the sort is
156 # finite), or Cardinality::INTEGERS if the sort has the same
157 # cardinality as the integers, or Cardinality::REALS if the sort
158 # has the same cardinality as the reals.
159 #
160 # If the sort is well-founded (i.e., there exist ground terms),
161 # then the argument should be the string "well-founded"; if not,
162 # it should be the string "not-well-founded". If well-founded,
163 # two extra arguments immediately follow---a C++ expression that
164 # constructs a ground term (as a Node), and the header that must
165 # be #included for that expression to compile.
166 #
167 # For consistency, sorts should end with "_TYPE", but this is not
168 # enforced.
169 #
170 # cardinality K cardinality-computer [header]
171 #
172 # This command does not define a kind; the kind K needs to be
173 # defined by one of the other commands above. This command just
174 # provides a cardinality for types of kind K. The
175 # "cardinality-computer" is a C++ expression that will yield a
176 # Cardinality for the type. In that expression, the sequence of
177 # characters "%TYPE%" will be rewritten with a variable containing
178 # a TypeNode of kind K. The optional "header" argument is an
179 # include file necessary to compile the cardinality-computer
180 # expression.
181 #
182 # If the cardinality need not be computed per-type (i.e., it's the
183 # same for all types of kind K, but the "sort" gesture above could
184 # not be used---in which case it doesn't already have a registered
185 # cardinality), you can simply construct a Cardinality temporary.
186 # For example:
187 #
188 # cardinality MY_TYPE Cardinality(Cardinality::INTEGERS)
189 #
190 # If not, you might opt to use a computer; a common place to put it
191 # is with your type checker:
192 #
193 # cardinality MY_TYPE \
194 # ::CVC4::theory::foo::TheoryFoo::CardinalityComputer(%TYPE%) \
195 # "theory/foo/theory_foo_type_rules.h"
196 #
197 # well-founded K wellfoundedness-computer ground-term-computer [header]
198 #
199 # Analogous to the "cardinality" command above, the well-founded
200 # command provides a well-foundedness computer for the type. A
201 # ground term computer is required unless the
202 # wellfoundedness-computer is the constant "false". The ground
203 # term computer should return a Node, and it should return the
204 # same Node each time for a given type (although usually it's only
205 # ever called once anyway since the result is cached).
206 #
207 #
208 # Lines may be broken with a backslash between arguments; for example:
209 #
210 # constant CONST_INT \
211 # int IntHash \
212 # "" \
213 # "This is a constant representing an INT.
214 # Its payload is the C++ int type.
215 # It is used by the theory of arithmetic."
216 #
217 # As shown in the example, ["comment"] fields may be broken across
218 # multiple lines too.
219 #
220 # The expr package guarantees that Nodes built with kinds have the
221 # following constraints imposed on them. (The #children guarantee
222 # only holds when assertions are turned on.)
223 #
224 # Node meta-kind has operator? # children
225 # ================== ================= =======================
226 # variable no zero
227 # operator yes as documented above
228 # parameterized yes as documented above
229 # constant no zero
230 #
231 # NOTE THAT This file is actually an executable Bourne shell script
232 # (sourced by the processing scripts after defining functions called
233 # "theory," "variable," "operator," "parameterized," and "constant").
234 # Please don't do anything else in this file other than using these
235 # commands.
236 #
237
238 theory THEORY_BUILTIN ::CVC4::theory::builtin::TheoryBuiltin "theory/builtin/theory_builtin.h"
239 typechecker "theory/builtin/theory_builtin_type_rules.h"
240
241 properties stable-infinite
242
243 # Rewriter responisble for all the terms of the theory
244 rewriter ::CVC4::theory::builtin::TheoryBuiltinRewriter "theory/builtin/theory_builtin_rewriter.h"
245
246 sort BUILTIN_OPERATOR_TYPE \
247 Cardinality::INTEGERS \
248 not-well-founded \
249 "Built in type for built in operators"
250
251 # Justified because we can have an unbounded-but-finite number of
252 # sorts. Assuming we have |Z| is probably ok for now..
253 sort KIND_TYPE \
254 Cardinality::INTEGERS \
255 not-well-founded \
256 "Uninterpreted Sort"
257
258 variable SORT_TAG "sort tag"
259 parameterized SORT_TYPE SORT_TAG 0: "sort type"
260 # This is really "unknown" cardinality, but maybe this will be good
261 # enough (for now) ? Once we support quantifiers, maybe reconsider
262 # this..
263 cardinality SORT_TYPE "Cardinality(Cardinality::INTEGERS)"
264 well-founded SORT_TYPE \
265 "::CVC4::theory::builtin::SortProperties::isWellFounded(%TYPE%)" \
266 "::CVC4::theory::builtin::SortProperties::mkGroundTerm(%TYPE%)"
267
268 # A kind representing "inlined" operators defined with OPERATOR
269 # Conceptually, (EQUAL a b) is actually an (APPLY EQUAL a b), but it's
270 # not stored that way. If you ask for the operator of (EQUAL a b),
271 # you'll get a special, singleton (BUILTIN EQUAL) Node.
272 constant BUILTIN \
273 ::CVC4::Kind \
274 ::CVC4::kind::KindHashStrategy \
275 "expr/kind.h" \
276 "The kind of nodes representing built-in operators"
277
278 variable FUNCTION "function"
279 parameterized APPLY FUNCTION 0: "defined function application"
280
281 operator EQUAL 2 "equality"
282 operator DISTINCT 2: "disequality"
283 variable SKOLEM "skolem var"
284 variable VARIABLE "variable"
285 operator TUPLE 2: "a tuple"
286
287 constant TYPE_CONSTANT \
288 ::CVC4::TypeConstant \
289 ::CVC4::TypeConstantHashStrategy \
290 "expr/kind.h" \
291 "basic types"
292 operator FUNCTION_TYPE 2: "function type"
293 cardinality FUNCTION_TYPE \
294 "::CVC4::theory::builtin::FunctionProperties::computeCardinality(%TYPE%)" \
295 "theory/builtin/theory_builtin_type_rules.h"
296 well-founded FUNCTION_TYPE false
297 operator TUPLE_TYPE 2: "tuple type"
298 cardinality TUPLE_TYPE \
299 "::CVC4::theory::builtin::TupleProperties::computeCardinality(%TYPE%)" \
300 "theory/builtin/theory_builtin_type_rules.h"
301 well-founded TUPLE_TYPE \
302 "::CVC4::theory::builtin::TupleProperties::isWellFounded(%TYPE%)" \
303 "::CVC4::theory::builtin::TupleProperties::mkGroundTerm(%TYPE%)" \
304 "theory/builtin/theory_builtin_type_rules.h"
305
306 # These will eventually move to a theory of strings.
307 #
308 # For now these are unbounded strings over a fixed, finite alphabet
309 # (this may change).
310 sort STRING_TYPE \
311 Cardinality::INTEGERS \
312 well-founded \
313 "NodeManager::currentNM()->mkConst(::std::string())" \
314 "string" \
315 "String type"
316 constant CONST_STRING \
317 ::std::string \
318 ::CVC4::StringHashStrategy \
319 "util/hash.h" \
320 "a string of characters"
321 typerule CONST_STRING ::CVC4::theory::builtin::StringConstantTypeRule
322
323 typerule APPLY ::CVC4::theory::builtin::ApplyTypeRule
324 typerule EQUAL ::CVC4::theory::builtin::EqualityTypeRule
325 typerule DISTINCT ::CVC4::theory::builtin::DistinctTypeRule
326 typerule TUPLE ::CVC4::theory::builtin::TupleTypeRule
327
328 constant SUBTYPE_TYPE \
329 ::CVC4::Predicate \
330 ::CVC4::PredicateHashStrategy \
331 "util/predicate.h" \
332 "predicate subtype"
333 cardinality SUBTYPE_TYPE \
334 "::CVC4::theory::builtin::SubtypeProperties::computeCardinality(%TYPE%)" \
335 "theory/builtin/theory_builtin_type_rules.h"
336 well-founded SUBTYPE_TYPE \
337 "::CVC4::theory::builtin::SubtypeProperties::isWellFounded(%TYPE%)" \
338 "::CVC4::theory::builtin::SubtypeProperties::mkGroundTerm(%TYPE%)" \
339 "theory/builtin/theory_builtin_type_rules.h"
340
341 endtheory