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