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