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