Update copyright headers.
[cvc5.git] / src / theory / theory_engine.h
1 /********************* */
2 /*! \file theory_engine.h
3 ** \verbatim
4 ** Top contributors (to current version):
5 ** Dejan Jovanovic, Andrew Reynolds, Morgan Deters
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2020 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 The theory engine
13 **
14 ** The theory engine.
15 **/
16
17 #include "cvc4_private.h"
18
19 #ifndef CVC4__THEORY_ENGINE_H
20 #define CVC4__THEORY_ENGINE_H
21
22 #include <deque>
23 #include <memory>
24 #include <set>
25 #include <unordered_map>
26 #include <utility>
27 #include <vector>
28
29 #include "base/check.h"
30 #include "context/cdhashset.h"
31 #include "expr/node.h"
32 #include "options/options.h"
33 #include "options/smt_options.h"
34 #include "options/theory_options.h"
35 #include "prop/prop_engine.h"
36 #include "smt/command.h"
37 #include "theory/atom_requests.h"
38 #include "theory/decision_manager.h"
39 #include "theory/engine_output_channel.h"
40 #include "theory/interrupted.h"
41 #include "theory/rewriter.h"
42 #include "theory/shared_terms_database.h"
43 #include "theory/sort_inference.h"
44 #include "theory/substitutions.h"
45 #include "theory/term_registration_visitor.h"
46 #include "theory/theory.h"
47 #include "theory/theory_preprocessor.h"
48 #include "theory/uf/equality_engine.h"
49 #include "theory/valuation.h"
50 #include "util/hash.h"
51 #include "util/resource_manager.h"
52 #include "util/statistics_registry.h"
53 #include "util/unsafe_interrupt_exception.h"
54
55 namespace CVC4 {
56
57 class ResourceManager;
58 class LemmaProofRecipe;
59
60 /**
61 * A pair of a theory and a node. This is used to mark the flow of
62 * propagations between theories.
63 */
64 struct NodeTheoryPair {
65 Node d_node;
66 theory::TheoryId d_theory;
67 size_t d_timestamp;
68 NodeTheoryPair(TNode n, theory::TheoryId t, size_t ts = 0)
69 : d_node(n), d_theory(t), d_timestamp(ts)
70 {
71 }
72 NodeTheoryPair() : d_theory(theory::THEORY_LAST), d_timestamp() {}
73 // Comparison doesn't take into account the timestamp
74 bool operator == (const NodeTheoryPair& pair) const {
75 return d_node == pair.d_node && d_theory == pair.d_theory;
76 }
77 };/* struct NodeTheoryPair */
78
79 struct NodeTheoryPairHashFunction {
80 NodeHashFunction hashFunction;
81 // Hash doesn't take into account the timestamp
82 size_t operator()(const NodeTheoryPair& pair) const {
83 uint64_t hash = fnv1a::fnv1a_64(NodeHashFunction()(pair.d_node));
84 return static_cast<size_t>(fnv1a::fnv1a_64(pair.d_theory, hash));
85 }
86 };/* struct NodeTheoryPairHashFunction */
87
88
89 /* Forward declarations */
90 namespace theory {
91 class TheoryModel;
92 class TheoryEngineModelBuilder;
93
94 namespace eq {
95 class EqualityEngine;
96 }/* CVC4::theory::eq namespace */
97
98 namespace quantifiers {
99 class TermDb;
100 }
101
102 class EntailmentCheckParameters;
103 class EntailmentCheckSideEffects;
104 }/* CVC4::theory namespace */
105
106 class RemoveTermFormulas;
107
108 /**
109 * This is essentially an abstraction for a collection of theories. A
110 * TheoryEngine provides services to a PropEngine, making various
111 * T-solvers look like a single unit to the propositional part of
112 * CVC4.
113 */
114 class TheoryEngine {
115
116 /** Shared terms database can use the internals notify the theories */
117 friend class SharedTermsDatabase;
118 friend class theory::quantifiers::TermDb;
119 friend class theory::EngineOutputChannel;
120
121 /** Associated PropEngine engine */
122 prop::PropEngine* d_propEngine;
123
124 /** Our context */
125 context::Context* d_context;
126
127 /** Our user context */
128 context::UserContext* d_userContext;
129
130 /**
131 * A table of from theory IDs to theory pointers. Never use this table
132 * directly, use theoryOf() instead.
133 */
134 theory::Theory* d_theoryTable[theory::THEORY_LAST];
135
136 /**
137 * A collection of theories that are "active" for the current run.
138 * This set is provided by the user (as a logic string, say, in SMT-LIBv2
139 * format input), or else by default it's all-inclusive. This is important
140 * because we can optimize for single-theory runs (no sharing), can reduce
141 * the cost of walking the DAG on registration, etc.
142 */
143 const LogicInfo& d_logicInfo;
144
145 /**
146 * The database of shared terms.
147 */
148 SharedTermsDatabase d_sharedTerms;
149
150 /**
151 * Master equality engine, to share with theories.
152 */
153 theory::eq::EqualityEngine* d_masterEqualityEngine;
154
155 /** notify class for master equality engine */
156 class NotifyClass : public theory::eq::EqualityEngineNotify {
157 TheoryEngine& d_te;
158 public:
159 NotifyClass(TheoryEngine& te): d_te(te) {}
160 bool eqNotifyTriggerEquality(TNode equality, bool value) override
161 {
162 return true;
163 }
164 bool eqNotifyTriggerPredicate(TNode predicate, bool value) override
165 {
166 return true;
167 }
168 bool eqNotifyTriggerTermEquality(theory::TheoryId tag,
169 TNode t1,
170 TNode t2,
171 bool value) override
172 {
173 return true;
174 }
175 void eqNotifyConstantTermMerge(TNode t1, TNode t2) override {}
176 void eqNotifyNewClass(TNode t) override { d_te.eqNotifyNewClass(t); }
177 void eqNotifyPreMerge(TNode t1, TNode t2) override
178 {
179 }
180 void eqNotifyPostMerge(TNode t1, TNode t2) override
181 {
182 }
183 void eqNotifyDisequal(TNode t1, TNode t2, TNode reason) override
184 {
185 }
186 };/* class TheoryEngine::NotifyClass */
187 NotifyClass d_masterEENotify;
188
189 /**
190 * notification methods
191 */
192 void eqNotifyNewClass(TNode t);
193 void eqNotifyPreMerge(TNode t1, TNode t2);
194 void eqNotifyPostMerge(TNode t1, TNode t2);
195 void eqNotifyDisequal(TNode t1, TNode t2, TNode reason);
196
197 /**
198 * The quantifiers engine
199 */
200 theory::QuantifiersEngine* d_quantEngine;
201 /**
202 * The decision manager
203 */
204 std::unique_ptr<theory::DecisionManager> d_decManager;
205
206 /**
207 * Default model object
208 */
209 theory::TheoryModel* d_curr_model;
210 bool d_aloc_curr_model;
211 /**
212 * Model builder object
213 */
214 theory::TheoryEngineModelBuilder* d_curr_model_builder;
215 bool d_aloc_curr_model_builder;
216 /** are we in eager model building mode? (see setEagerModelBuilding). */
217 bool d_eager_model_building;
218
219 typedef std::unordered_map<Node, Node, NodeHashFunction> NodeMap;
220 typedef std::unordered_map<TNode, Node, TNodeHashFunction> TNodeMap;
221
222 /**
223 * Used for "missed-t-propagations" dumping mode only. A set of all
224 * theory-propagable literals.
225 */
226 context::CDList<TNode> d_possiblePropagations;
227
228 /**
229 * Used for "missed-t-propagations" dumping mode only. A
230 * context-dependent set of those theory-propagable literals that
231 * have been propagated.
232 */
233 context::CDHashSet<Node, NodeHashFunction> d_hasPropagated;
234
235 /**
236 * Output channels for individual theories.
237 */
238 theory::EngineOutputChannel* d_theoryOut[theory::THEORY_LAST];
239
240 /**
241 * Are we in conflict.
242 */
243 context::CDO<bool> d_inConflict;
244
245 /**
246 * Are we in "SAT mode"? In this state, the user can query for the model.
247 * This corresponds to the state in Figure 4.1, page 52 of the SMT-LIB
248 * standard, version 2.6.
249 */
250 bool d_inSatMode;
251
252 /**
253 * Called by the theories to notify of a conflict.
254 */
255 void conflict(TNode conflict, theory::TheoryId theoryId);
256
257 /**
258 * Debugging flag to ensure that shutdown() is called before the
259 * destructor.
260 */
261 bool d_hasShutDown;
262
263 /**
264 * True if a theory has notified us of incompleteness (at this
265 * context level or below).
266 */
267 context::CDO<bool> d_incomplete;
268
269 /**
270 * Called by the theories to notify that the current branch is incomplete.
271 */
272 void setIncomplete(theory::TheoryId theory) {
273 d_incomplete = true;
274 }
275
276
277 /**
278 * Mapping of propagations from recievers to senders.
279 */
280 typedef context::CDHashMap<NodeTheoryPair, NodeTheoryPair, NodeTheoryPairHashFunction> PropagationMap;
281 PropagationMap d_propagationMap;
282
283 /**
284 * Timestamp of propagations
285 */
286 context::CDO<size_t> d_propagationMapTimestamp;
287
288 /**
289 * Literals that are propagated by the theory. Note that these are TNodes.
290 * The theory can only propagate nodes that have an assigned literal in the
291 * SAT solver and are hence referenced in the SAT solver.
292 */
293 context::CDList<TNode> d_propagatedLiterals;
294
295 /**
296 * The index of the next literal to be propagated by a theory.
297 */
298 context::CDO<unsigned> d_propagatedLiteralsIndex;
299
300 /**
301 * Called by the output channel to propagate literals and facts
302 * @return false if immediate conflict
303 */
304 bool propagate(TNode literal, theory::TheoryId theory);
305
306 /**
307 * Internal method to call the propagation routines and collect the
308 * propagated literals.
309 */
310 void propagate(theory::Theory::Effort effort);
311
312 /**
313 * A variable to mark if we added any lemmas.
314 */
315 bool d_lemmasAdded;
316
317 /**
318 * A variable to mark if the OutputChannel was "used" by any theory
319 * since the start of the last check. If it has been, we require
320 * a FULL_EFFORT check before exiting and reporting SAT.
321 *
322 * See the documentation for the needCheck() function, below.
323 */
324 bool d_outputChannelUsed;
325
326 /** Atom requests from lemmas */
327 AtomRequests d_atomRequests;
328
329 /**
330 * Adds a new lemma, returning its status.
331 * @param node the lemma
332 * @param negated should the lemma be asserted negated
333 * @param removable can the lemma be remove (restrictions apply)
334 * @param needAtoms if not THEORY_LAST, then
335 */
336 theory::LemmaStatus lemma(TNode node,
337 ProofRule rule,
338 bool negated,
339 bool removable,
340 bool preprocess,
341 theory::TheoryId atomsTo);
342
343 /** Enusre that the given atoms are send to the given theory */
344 void ensureLemmaAtoms(const std::vector<TNode>& atoms, theory::TheoryId theory);
345
346 /** sort inference module */
347 SortInference d_sortInfer;
348
349 /** The theory preprocessor */
350 theory::TheoryPreprocessor d_tpp;
351
352 /** Time spent in theory combination */
353 TimerStat d_combineTheoriesTime;
354
355 Node d_true;
356 Node d_false;
357
358 /** Whether we were just interrupted (or not) */
359 bool d_interrupted;
360 ResourceManager* d_resourceManager;
361
362 public:
363 /** Constructs a theory engine */
364 TheoryEngine(context::Context* context,
365 context::UserContext* userContext,
366 RemoveTermFormulas& iteRemover,
367 const LogicInfo& logic);
368
369 /** Destroys a theory engine */
370 ~TheoryEngine();
371
372 void interrupt();
373
374 /** "Spend" a resource during a search or preprocessing.*/
375 void spendResource(ResourceManager::Resource r);
376
377 /**
378 * Adds a theory. Only one theory per TheoryId can be present, so if
379 * there is another theory it will be deleted.
380 */
381 template <class TheoryClass>
382 inline void addTheory(theory::TheoryId theoryId)
383 {
384 Assert(d_theoryTable[theoryId] == NULL && d_theoryOut[theoryId] == NULL);
385 d_theoryOut[theoryId] = new theory::EngineOutputChannel(this, theoryId);
386 d_theoryTable[theoryId] = new TheoryClass(d_context,
387 d_userContext,
388 *d_theoryOut[theoryId],
389 theory::Valuation(this),
390 d_logicInfo);
391 theory::Rewriter::registerTheoryRewriter(
392 theoryId, d_theoryTable[theoryId]->getTheoryRewriter());
393 }
394
395 void setPropEngine(prop::PropEngine* propEngine)
396 {
397 d_propEngine = propEngine;
398 }
399
400 /** Called when all initialization of options/logic is done */
401 void finishInit();
402
403 /**
404 * Get a pointer to the underlying propositional engine.
405 */
406 inline prop::PropEngine* getPropEngine() const {
407 return d_propEngine;
408 }
409
410 /**
411 * Get a pointer to the underlying sat context.
412 */
413 inline context::Context* getSatContext() const {
414 return d_context;
415 }
416
417 /**
418 * Get a pointer to the underlying user context.
419 */
420 inline context::Context* getUserContext() const {
421 return d_userContext;
422 }
423
424 /**
425 * Get a pointer to the underlying quantifiers engine.
426 */
427 theory::QuantifiersEngine* getQuantifiersEngine() const {
428 return d_quantEngine;
429 }
430 /**
431 * Get a pointer to the underlying decision manager.
432 */
433 theory::DecisionManager* getDecisionManager() const
434 {
435 return d_decManager.get();
436 }
437
438 private:
439 /**
440 * Queue of nodes for pre-registration.
441 */
442 std::queue<TNode> d_preregisterQueue;
443
444 /**
445 * Boolean flag denoting we are in pre-registration.
446 */
447 bool d_inPreregister;
448
449 /**
450 * Did the theories get any new facts since the last time we called
451 * check()
452 */
453 context::CDO<bool> d_factsAsserted;
454
455 /**
456 * Map from equality atoms to theories that would like to be notified about them.
457 */
458
459
460 /**
461 * Assert the formula to the given theory.
462 * @param assertion the assertion to send (not necesserily normalized)
463 * @param original the assertion as it was sent in from the propagating theory
464 * @param toTheoryId the theory to assert to
465 * @param fromTheoryId the theory that sent it
466 */
467 void assertToTheory(TNode assertion, TNode originalAssertion, theory::TheoryId toTheoryId, theory::TheoryId fromTheoryId);
468
469 /**
470 * Marks a theory propagation from a theory to a theory where a
471 * theory could be the THEORY_SAT_SOLVER for literals coming from
472 * or being propagated to the SAT solver. If the receiving theory
473 * already recieved the literal, the method returns false, otherwise
474 * it returns true.
475 *
476 * @param assertion the normalized assertion being sent
477 * @param originalAssertion the actual assertion that was sent
478 * @param toTheoryId the theory that is on the receiving end
479 * @param fromTheoryId the theory that sent the assertion
480 * @return true if a new assertion, false if theory already got it
481 */
482 bool markPropagation(TNode assertion, TNode originalAssertions, theory::TheoryId toTheoryId, theory::TheoryId fromTheoryId);
483
484 /**
485 * Computes the explanation by travarsing the propagation graph and
486 * asking relevant theories to explain the propagations. Initially
487 * the explanation vector should contain only the element (node, theory)
488 * where the node is the one to be explained, and the theory is the
489 * theory that sent the literal. The lemmaProofRecipe will contain a list
490 * of the explanation steps required to produce the original node.
491 */
492 void getExplanation(std::vector<NodeTheoryPair>& explanationVector, LemmaProofRecipe* lemmaProofRecipe);
493
494 public:
495
496 /**
497 * Signal the start of a new round of assertion preprocessing
498 */
499 void preprocessStart();
500
501 /**
502 * Runs theory specific preprocessing on the non-Boolean parts of
503 * the formula. This is only called on input assertions, after ITEs
504 * have been removed.
505 */
506 Node preprocess(TNode node);
507
508 /** Notify (preprocessed) assertions. */
509 void notifyPreprocessedAssertions(const std::vector<Node>& assertions);
510
511 /** Return whether or not we are incomplete (in the current context). */
512 inline bool isIncomplete() const { return d_incomplete; }
513
514 /**
515 * Returns true if we need another round of checking. If this
516 * returns true, check(FULL_EFFORT) _must_ be called by the
517 * propositional layer before reporting SAT.
518 *
519 * This is especially necessary for incomplete theories that lazily
520 * output some lemmas on FULL_EFFORT check (e.g. quantifier reasoning
521 * outputing quantifier instantiations). In such a case, a lemma can
522 * be asserted that is simplified away (perhaps it's already true).
523 * However, we must maintain the invariant that, if a theory uses the
524 * OutputChannel, it implicitly requests that another check(FULL_EFFORT)
525 * be performed before exit, even if no new facts are on its fact queue,
526 * as it might decide to further instantiate some lemmas, precluding
527 * a SAT response.
528 */
529 inline bool needCheck() const {
530 return d_outputChannelUsed || d_lemmasAdded;
531 }
532
533 /**
534 * This is called at shutdown time by the SmtEngine, just before
535 * destruction. It is important because there are destruction
536 * ordering issues between PropEngine and Theory.
537 */
538 void shutdown();
539
540 /**
541 * Solve the given literal with a theory that owns it.
542 */
543 theory::Theory::PPAssertStatus solve(TNode literal,
544 theory::SubstitutionMap& substitutionOut);
545
546 /**
547 * Preregister a Theory atom with the responsible theory (or
548 * theories).
549 */
550 void preRegister(TNode preprocessed);
551
552 /**
553 * Assert the formula to the appropriate theory.
554 * @param node the assertion
555 */
556 void assertFact(TNode node);
557
558 /**
559 * Check all (currently-active) theories for conflicts.
560 * @param effort the effort level to use
561 */
562 void check(theory::Theory::Effort effort);
563
564 /**
565 * Run the combination framework.
566 */
567 void combineTheories();
568
569 /**
570 * Calls ppStaticLearn() on all theories, accumulating their
571 * combined contributions in the "learned" builder.
572 */
573 void ppStaticLearn(TNode in, NodeBuilder<>& learned);
574
575 /**
576 * Calls presolve() on all theories and returns true
577 * if one of the theories discovers a conflict.
578 */
579 bool presolve();
580
581 /**
582 * Calls postsolve() on all theories.
583 */
584 void postsolve();
585
586 /**
587 * Calls notifyRestart() on all active theories.
588 */
589 void notifyRestart();
590
591 void getPropagatedLiterals(std::vector<TNode>& literals) {
592 for (; d_propagatedLiteralsIndex < d_propagatedLiterals.size(); d_propagatedLiteralsIndex = d_propagatedLiteralsIndex + 1) {
593 Debug("getPropagatedLiterals") << "TheoryEngine::getPropagatedLiterals: propagating: " << d_propagatedLiterals[d_propagatedLiteralsIndex] << std::endl;
594 literals.push_back(d_propagatedLiterals[d_propagatedLiteralsIndex]);
595 }
596 }
597
598 /**
599 * Returns the next decision request, or null if none exist. The next
600 * decision request is a literal that this theory engine prefers the SAT
601 * solver to make as its next decision. Decision requests are managed by
602 * the decision manager d_decManager.
603 */
604 Node getNextDecisionRequest();
605
606 bool properConflict(TNode conflict) const;
607 bool properPropagation(TNode lit) const;
608 bool properExplanation(TNode node, TNode expl) const;
609
610 /**
611 * Returns an explanation of the node propagated to the SAT solver.
612 */
613 Node getExplanation(TNode node);
614
615 /**
616 * Returns an explanation of the node propagated to the SAT solver and the theory
617 * that propagated it.
618 */
619 Node getExplanationAndRecipe(TNode node, LemmaProofRecipe* proofRecipe);
620
621 /**
622 * collect model info
623 */
624 bool collectModelInfo(theory::TheoryModel* m);
625 /** post process model */
626 void postProcessModel( theory::TheoryModel* m );
627
628 /**
629 * Get the pointer to the model object used by this theory engine.
630 */
631 theory::TheoryModel* getModel();
632 /**
633 * Get the current model for the current set of assertions. This method
634 * should only be called immediately after a satisfiable or unknown
635 * response to a check-sat call, and only if produceModels is true.
636 *
637 * If the model is not already built, this will cause this theory engine
638 * to build the model.
639 *
640 * If the model is not available (for instance, if the last call to check-sat
641 * was interrupted), then this returns the null pointer.
642 */
643 theory::TheoryModel* getBuiltModel();
644 /** set eager model building
645 *
646 * If this method is called, then this TheoryEngine will henceforth build
647 * its model immediately after every satisfiability check that results
648 * in a satisfiable or unknown result. The motivation for this mode is to
649 * accomodate API users that get the model object from the TheoryEngine,
650 * where we want to ensure that this model is always valid.
651 * TODO (#2648): revisit this.
652 */
653 void setEagerModelBuilding() { d_eager_model_building = true; }
654
655 /** get synth solutions
656 *
657 * This method returns true if there is a synthesis solution available. This
658 * is the case if the last call to check satisfiability originated in a
659 * check-synth call, and the synthesis solver successfully found a solution
660 * for all active synthesis conjectures.
661 *
662 * This method adds entries to sol_map that map functions-to-synthesize with
663 * their solutions, for all active conjectures. This should be called
664 * immediately after the solver answers unsat for sygus input.
665 *
666 * For details on what is added to sol_map, see
667 * SynthConjecture::getSynthSolutions.
668 */
669 bool getSynthSolutions(std::map<Node, std::map<Node, Node> >& sol_map);
670
671 /**
672 * Get the model builder
673 */
674 theory::TheoryEngineModelBuilder* getModelBuilder() { return d_curr_model_builder; }
675
676 /**
677 * Get the theory associated to a given Node.
678 *
679 * @returns the theory, or NULL if the TNode is
680 * of built-in type.
681 */
682 inline theory::Theory* theoryOf(TNode node) const {
683 return d_theoryTable[theory::Theory::theoryOf(node)];
684 }
685
686 /**
687 * Get the theory associated to a the given theory id.
688 *
689 * @returns the theory
690 */
691 inline theory::Theory* theoryOf(theory::TheoryId theoryId) const {
692 Assert(theoryId < theory::THEORY_LAST);
693 return d_theoryTable[theoryId];
694 }
695
696 inline bool isTheoryEnabled(theory::TheoryId theoryId) const {
697 return d_logicInfo.isTheoryEnabled(theoryId);
698 }
699 /** get the logic info used by this theory engine */
700 const LogicInfo& getLogicInfo() const;
701 /**
702 * Returns the equality status of the two terms, from the theory
703 * that owns the domain type. The types of a and b must be the same.
704 */
705 theory::EqualityStatus getEqualityStatus(TNode a, TNode b);
706
707 /**
708 * Returns the value that a theory that owns the type of var currently
709 * has (or null if none);
710 */
711 Node getModelValue(TNode var);
712
713 /**
714 * Takes a literal and returns an equivalent literal that is guaranteed to be a SAT literal
715 */
716 Node ensureLiteral(TNode n);
717
718 /**
719 * Print all instantiations made by the quantifiers module.
720 */
721 void printInstantiations( std::ostream& out );
722
723 /**
724 * Print solution for synthesis conjectures found by ce_guided_instantiation module
725 */
726 void printSynthSolution( std::ostream& out );
727
728 /**
729 * Get list of quantified formulas that were instantiated
730 */
731 void getInstantiatedQuantifiedFormulas( std::vector< Node >& qs );
732
733 /**
734 * Get instantiation methods
735 * first inputs forall x.q[x] and returns ( q[a], ..., q[z] )
736 * second inputs forall x.q[x] and returns ( a, ..., z )
737 * third and fourth return mappings e.g. forall x.q1[x] -> ( q1[a]...q1[z] ) , ... , forall x.qn[x] -> ( qn[a]...qn[z] )
738 */
739 void getInstantiations( Node q, std::vector< Node >& insts );
740 void getInstantiationTermVectors( Node q, std::vector< std::vector< Node > >& tvecs );
741 void getInstantiations( std::map< Node, std::vector< Node > >& insts );
742 void getInstantiationTermVectors( std::map< Node, std::vector< std::vector< Node > > >& insts );
743
744 /**
745 * Get instantiated conjunction, returns q[t1] ^ ... ^ q[tn] where t1...tn are current set of instantiations for q.
746 * Can be used for quantifier elimination when satisfiable and q[t1] ^ ... ^ q[tn] |= q
747 */
748 Node getInstantiatedConjunction( Node q );
749
750 /**
751 * Forwards an entailment check according to the given theoryOfMode.
752 * See theory.h for documentation on entailmentCheck().
753 */
754 std::pair<bool, Node> entailmentCheck(
755 options::TheoryOfMode mode,
756 TNode lit,
757 const theory::EntailmentCheckParameters* params = NULL,
758 theory::EntailmentCheckSideEffects* out = NULL);
759
760 private:
761 /** Default visitor for pre-registration */
762 PreRegisterVisitor d_preRegistrationVisitor;
763
764 /** Visitor for collecting shared terms */
765 SharedTermsVisitor d_sharedTermsVisitor;
766
767 /** Dump the assertions to the dump */
768 void dumpAssertions(const char* tag);
769
770 /** For preprocessing pass lifting bit-vectors of size 1 to booleans */
771 public:
772 void staticInitializeBVOptions(const std::vector<Node>& assertions);
773
774 Node ppSimpITE(TNode assertion);
775 /** Returns false if an assertion simplified to false. */
776 bool donePPSimpITE(std::vector<Node>& assertions);
777
778 SharedTermsDatabase* getSharedTermsDatabase() { return &d_sharedTerms; }
779
780 theory::eq::EqualityEngine* getMasterEqualityEngine() { return d_masterEqualityEngine; }
781
782 SortInference* getSortInference() { return &d_sortInfer; }
783
784 /** Prints the assertions to the debug stream */
785 void printAssertions(const char* tag);
786
787 private:
788
789 std::map< std::string, std::vector< theory::Theory* > > d_attr_handle;
790
791 public:
792 /** Set user attribute.
793 *
794 * This function is called when an attribute is set by a user. In SMT-LIBv2
795 * this is done via the syntax (! n :attr)
796 */
797 void setUserAttribute(const std::string& attr,
798 Node n,
799 const std::vector<Node>& node_values,
800 const std::string& str_value);
801
802 /** Handle user attribute.
803 *
804 * Associates theory t with the attribute attr. Theory t will be
805 * notified whenever an attribute of name attr is set.
806 */
807 void handleUserAttribute(const char* attr, theory::Theory* t);
808
809 /**
810 * Check that the theory assertions are satisfied in the model.
811 * This function is called from the smt engine's checkModel routine.
812 */
813 void checkTheoryAssertionsWithModel(bool hardFailure);
814
815 private:
816 IntStat d_arithSubstitutionsAdded;
817
818 };/* class TheoryEngine */
819
820 }/* CVC4 namespace */
821
822 #endif /* CVC4__THEORY_ENGINE_H */