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