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