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