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

theory THEORY_BUILTIN ::CVC4::theory::builtin::TheoryBuiltin "theory/builtin/theory_builtin.h"
typechecker "theory/builtin/theory_builtin_type_rules.h"

properties stable-infinite

# Rewriter responisble for all the terms of the theory
rewriter ::CVC4::theory::builtin::TheoryBuiltinRewriter "theory/builtin/theory_builtin_rewriter.h"

sort BUILTIN_OPERATOR_TYPE \
    Cardinality::INTEGERS \
    not-well-founded \
    "Built in type for built in operators"

variable SORT_TAG "sort tag"
parameterized SORT_TYPE SORT_TAG 0: "sort type"
# This is really "unknown" cardinality, but maybe this will be good
# enough (for now) ?  Once we support quantifiers, maybe reconsider
# this..
cardinality SORT_TYPE "Cardinality(Cardinality::INTEGERS)"
well-founded SORT_TYPE \
    "::CVC4::theory::builtin::SortProperties::isWellFounded(%TYPE%)" \
    "::CVC4::theory::builtin::SortProperties::mkGroundTerm(%TYPE%)"

constant UNINTERPRETED_CONSTANT \
    ::CVC4::UninterpretedConstant \
    ::CVC4::UninterpretedConstantHashFunction \
    "util/uninterpreted_constant.h" \
    "The kind of expressions representing uninterpreted constants"
typerule UNINTERPRETED_CONSTANT ::CVC4::theory::builtin::UninterpretedConstantTypeRule
enumerator SORT_TYPE \
    ::CVC4::theory::builtin::UninterpretedSortEnumerator \
    "theory/builtin/type_enumerator.h"

constant ABSTRACT_VALUE \
    ::CVC4::AbstractValue \
    ::CVC4::AbstractValueHashFunction \
    "util/abstract_value.h" \
    "The kind of expressions representing abstract values (other than uninterpreted sort constants)"
typerule ABSTRACT_VALUE ::CVC4::theory::builtin::AbstractValueTypeRule

# A kind representing "inlined" operators defined with OPERATOR
# Conceptually, (EQUAL a b) is actually an (APPLY EQUAL a b), but it's
# not stored that way.  If you ask for the operator of (EQUAL a b),
# you'll get a special, singleton (BUILTIN EQUAL) Node.
constant BUILTIN \
    ::CVC4::Kind \
    ::CVC4::kind::KindHashFunction \
    "expr/kind.h" \
    "The kind of expressions representing built-in operators"

variable FUNCTION "function"
parameterized APPLY FUNCTION 0: "defined function application"

operator EQUAL 2 "equality"
operator DISTINCT 2: "disequality"
variable VARIABLE "variable"
variable BOUND_VARIABLE "bound variable"
variable SKOLEM "skolem var"
operator SEXPR 0: "a symbolic expression"

operator LAMBDA 2 "lambda"

parameterized CHAIN CHAIN_OP 2: "chained operator"
constant CHAIN_OP \
    ::CVC4::Chain \
    ::CVC4::ChainHashFunction \
    "util/chain.h" \
    "the chained operator"

constant TYPE_CONSTANT \
    ::CVC4::TypeConstant \
    ::CVC4::TypeConstantHashFunction \
    "expr/kind.h" \
    "basic types"
operator FUNCTION_TYPE 2: "function type"
cardinality FUNCTION_TYPE \
    "::CVC4::theory::builtin::FunctionProperties::computeCardinality(%TYPE%)" \
    "theory/builtin/theory_builtin_type_rules.h"
well-founded FUNCTION_TYPE false
operator SEXPR_TYPE 0: "symbolic expression type"
cardinality SEXPR_TYPE \
    "::CVC4::theory::builtin::SExprProperties::computeCardinality(%TYPE%)" \
    "theory/builtin/theory_builtin_type_rules.h"
well-founded SEXPR_TYPE \
    "::CVC4::theory::builtin::SExprProperties::isWellFounded(%TYPE%)" \
    "::CVC4::theory::builtin::SExprProperties::mkGroundTerm(%TYPE%)" \
    "theory/builtin/theory_builtin_type_rules.h"

# These will eventually move to a theory of strings.
#
# For now these are unbounded strings over a fixed, finite alphabet
# (this may change).
sort STRING_TYPE \
    Cardinality::INTEGERS \
    well-founded \
        "NodeManager::currentNM()->mkConst(::std::string())" \
        "string" \
    "String type"
constant CONST_STRING \
    ::std::string \
    ::CVC4::StringHashFunction \
    "util/hash.h" \
    "a string of characters"
typerule CONST_STRING ::CVC4::theory::builtin::StringConstantTypeRule

typerule APPLY ::CVC4::theory::builtin::ApplyTypeRule
typerule EQUAL ::CVC4::theory::builtin::EqualityTypeRule
typerule DISTINCT ::CVC4::theory::builtin::DistinctTypeRule
typerule SEXPR ::CVC4::theory::builtin::SExprTypeRule
typerule LAMBDA ::CVC4::theory::builtin::LambdaTypeRule
typerule CHAIN ::CVC4::theory::builtin::ChainTypeRule
typerule CHAIN_OP ::CVC4::theory::builtin::ChainedOperatorTypeRule

constant SUBTYPE_TYPE \
    ::CVC4::Predicate \
    ::CVC4::PredicateHashFunction \
    "util/predicate.h" \
    "predicate subtype"
cardinality SUBTYPE_TYPE \
    "::CVC4::theory::builtin::SubtypeProperties::computeCardinality(%TYPE%)" \
    "theory/builtin/theory_builtin_type_rules.h"
well-founded SUBTYPE_TYPE \
    "::CVC4::theory::builtin::SubtypeProperties::isWellFounded(%TYPE%)" \
    "::CVC4::theory::builtin::SubtypeProperties::mkGroundTerm(%TYPE%)" \
    "theory/builtin/theory_builtin_type_rules.h"

endtheory
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback