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