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