Make higher-order a flag in logic info. (#1318)
[cvc5.git] / src / theory / logic_info.h
1 /********************* */
2 /*! \file logic_info.h
3 ** \verbatim
4 ** Top contributors (to current version):
5 ** Morgan Deters, Tim King, Paul Meng
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2017 by the authors listed in the file AUTHORS
8 ** in the top-level source directory) and their institutional affiliations.
9 ** All rights reserved. See the file COPYING in the top-level source
10 ** directory for licensing information.\endverbatim
11 **
12 ** \brief A class giving information about a logic (group a theory modules
13 ** and configuration information)
14 **
15 ** A class giving information about a logic (group of theory modules and
16 ** configuration information).
17 **/
18
19 #include "cvc4_public.h"
20
21 #ifndef __CVC4__LOGIC_INFO_H
22 #define __CVC4__LOGIC_INFO_H
23
24 #include <string>
25 #include <vector>
26 #include "expr/kind.h"
27
28 namespace CVC4 {
29
30 /**
31 * A LogicInfo instance describes a collection of theory modules and some
32 * basic configuration about them. Conceptually, it provides a background
33 * context for all operations in CVC4. Typically, when CVC4's SmtEngine
34 * is created, it is issued a setLogic() command indicating features of the
35 * assertions and queries to follow---for example, whether quantifiers are
36 * used, whether integers or reals (or both) will be used, etc.
37 *
38 * Most places in CVC4 will only ever need to access a const reference to an
39 * instance of this class. Such an instance is generally set by the SmtEngine
40 * when setLogic() is called. However, mutating member functions are also
41 * provided by this class so that it can be used as a more general mechanism
42 * (e.g., for communicating to the SmtEngine which theories should be used,
43 * rather than having to provide an SMT-LIB string).
44 */
45 class CVC4_PUBLIC LogicInfo {
46 mutable std::string d_logicString; /**< an SMT-LIB-like logic string */
47 std::vector<bool> d_theories; /**< set of active theories */
48 size_t d_sharingTheories; /**< count of theories that need sharing */
49
50 /** are integers used in this logic? */
51 bool d_integers;
52 /** are reals used in this logic? */
53 bool d_reals;
54 /** linear-only arithmetic in this logic? */
55 bool d_linear;
56 /** difference-only arithmetic in this logic? */
57 bool d_differenceLogic;
58 /** cardinality constraints in this logic? */
59 bool d_cardinalityConstraints;
60 /** higher-order constraints in this logic? */
61 bool d_higherOrder;
62
63 bool d_locked; /**< is this LogicInfo instance locked (and thus immutable)? */
64
65 /**
66 * Returns true iff this is a "true" theory (one that must be worried
67 * about for sharing
68 */
69 static inline bool isTrueTheory(theory::TheoryId theory) {
70 switch(theory) {
71 case theory::THEORY_BUILTIN:
72 case theory::THEORY_BOOL:
73 case theory::THEORY_QUANTIFIERS:
74 return false;
75 default:
76 return true;
77 }
78 }
79
80 public:
81
82 /**
83 * Constructs a LogicInfo for the most general logic (quantifiers, all
84 * background theory modules, ...).
85 */
86 LogicInfo();
87
88 /**
89 * Construct a LogicInfo from an SMT-LIB-like logic string.
90 * Throws an IllegalArgumentException if the logic string cannot
91 * be interpreted.
92 */
93 LogicInfo(std::string logicString) throw(IllegalArgumentException);
94
95 /**
96 * Construct a LogicInfo from an SMT-LIB-like logic string.
97 * Throws an IllegalArgumentException if the logic string cannot
98 * be interpreted.
99 */
100 LogicInfo(const char* logicString) throw(IllegalArgumentException);
101
102 // ACCESSORS
103
104 /**
105 * Get an SMT-LIB-like logic string. These are only guaranteed to
106 * be SMT-LIB-compliant if an SMT-LIB-compliant string was used in
107 * the constructor and no mutating functions were called.
108 */
109 std::string getLogicString() const;
110
111 /** Is sharing enabled for this logic? */
112 bool isSharingEnabled() const;
113
114 /** Is the given theory module active in this logic? */
115 bool isTheoryEnabled(theory::TheoryId theory) const;
116
117 /** Is this a quantified logic? */
118 bool isQuantified() const;
119
120 /** Is this the all-inclusive logic? */
121 bool hasEverything() const;
122
123 /** Is this the all-exclusive logic? (Here, that means propositional logic) */
124 bool hasNothing() const;
125
126 /**
127 * Is this a pure logic (only one "true" background theory). Quantifiers
128 * can exist in such logics though; to test for quantifier-free purity,
129 * use "isPure(theory) && !isQuantified()".
130 */
131 bool isPure(theory::TheoryId theory) const;
132
133 // these are for arithmetic
134
135 /** Are integers in this logic? */
136 bool areIntegersUsed() const;
137
138 /** Are reals in this logic? */
139 bool areRealsUsed() const;
140
141 /** Does this logic only linear arithmetic? */
142 bool isLinear() const;
143
144 /** Does this logic only permit difference reasoning? (implies linear) */
145 bool isDifferenceLogic() const;
146
147 /** Does this logic allow cardinality constraints? */
148 bool hasCardinalityConstraints() const;
149
150 /** Is this a higher order logic? */
151 bool isHigherOrder() const;
152
153 // MUTATORS
154
155 /**
156 * Initialize the LogicInfo with an SMT-LIB-like logic string.
157 * Throws an IllegalArgumentException if the string can't be
158 * interpreted.
159 */
160 void setLogicString(std::string logicString) throw(IllegalArgumentException);
161
162 /**
163 * Enable all functionality. All theories, plus quantifiers, will be
164 * enabled.
165 */
166 void enableEverything();
167
168 /**
169 * Disable all functionality. The result will be a LogicInfo with
170 * the BUILTIN and BOOLEAN theories enabled only ("QF_SAT").
171 */
172 void disableEverything();
173
174 /**
175 * Enable the given theory module.
176 */
177 void enableTheory(theory::TheoryId theory);
178
179 /**
180 * Disable the given theory module. THEORY_BUILTIN and THEORY_BOOL cannot
181 * be disabled (and if given here, the request will be silently ignored).
182 */
183 void disableTheory(theory::TheoryId theory);
184
185 /**
186 * Quantifiers are a special case, since two theory modules handle them.
187 */
188 void enableQuantifiers() {
189 enableTheory(theory::THEORY_QUANTIFIERS);
190 }
191
192 /**
193 * Quantifiers are a special case, since two theory modules handle them.
194 */
195 void disableQuantifiers() {
196 disableTheory(theory::THEORY_QUANTIFIERS);
197 }
198
199 // these are for arithmetic
200
201 /** Enable the use of integers in this logic. */
202 void enableIntegers();
203 /** Disable the use of integers in this logic. */
204 void disableIntegers();
205 /** Enable the use of reals in this logic. */
206 void enableReals();
207 /** Disable the use of reals in this logic. */
208 void disableReals();
209 /** Only permit difference arithmetic in this logic. */
210 void arithOnlyDifference();
211 /** Only permit linear arithmetic in this logic. */
212 void arithOnlyLinear();
213 /** Permit nonlinear arithmetic in this logic. */
214 void arithNonLinear();
215
216 // for cardinality constraints
217
218 /** Enable the use of cardinality constraints in this logic. */
219 void enableCardinalityConstraints();
220 /** Disable the use of cardinality constraints in this logic. */
221 void disableCardinalityConstraints();
222
223 // for higher-order
224
225 /** Enable the use of higher-order in this logic. */
226 void enableHigherOrder();
227 /** Disable the use of higher-order in this logic. */
228 void disableHigherOrder();
229
230 // LOCKING FUNCTIONALITY
231
232 /** Lock this LogicInfo, disabling further mutation and allowing queries */
233 void lock() { d_locked = true; }
234 /** Check whether this LogicInfo is locked, disallowing further mutation */
235 bool isLocked() const { return d_locked; }
236 /** Get a copy of this LogicInfo that is identical, but unlocked */
237 LogicInfo getUnlockedCopy() const;
238
239 // COMPARISON
240
241 /** Are these two LogicInfos equal? */
242 bool operator==(const LogicInfo& other) const;
243
244 /** Are these two LogicInfos disequal? */
245 bool operator!=(const LogicInfo& other) const {
246 return !(*this == other);
247 }
248
249 /** Is this LogicInfo "greater than" (does it contain everything and more) the other? */
250 bool operator>(const LogicInfo& other) const {
251 return *this >= other && *this != other;
252 }
253
254 /** Is this LogicInfo "less than" (does it contain strictly less) the other? */
255 bool operator<(const LogicInfo& other) const {
256 return *this <= other && *this != other;
257 }
258 /** Is this LogicInfo "less than or equal" the other? */
259 bool operator<=(const LogicInfo& other) const;
260
261 /** Is this LogicInfo "greater than or equal" the other? */
262 bool operator>=(const LogicInfo& other) const;
263
264 /** Are two LogicInfos comparable? That is, is one of <= or > true? */
265 bool isComparableTo(const LogicInfo& other) const {
266 return *this <= other || *this >= other;
267 }
268
269 };/* class LogicInfo */
270
271 std::ostream& operator<<(std::ostream& out, const LogicInfo& logic) CVC4_PUBLIC;
272
273 }/* CVC4 namespace */
274
275 #endif /* __CVC4__LOGIC_INFO_H */