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