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