Update theory rewriter ownership, add stats to strings (#4202)
[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 "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/resource_manager.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 d_node;
64 theory::TheoryId d_theory;
65 size_t d_timestamp;
66 NodeTheoryPair(TNode n, theory::TheoryId t, size_t ts = 0)
67 : d_node(n), d_theory(t), d_timestamp(ts)
68 {
69 }
70 NodeTheoryPair() : d_theory(theory::THEORY_LAST), d_timestamp() {}
71 // Comparison doesn't take into account the timestamp
72 bool operator == (const NodeTheoryPair& pair) const {
73 return d_node == pair.d_node && d_theory == pair.d_theory;
74 }
75 };/* struct NodeTheoryPair */
76
77 struct NodeTheoryPairHashFunction {
78 NodeHashFunction hashFunction;
79 // Hash doesn't take into account the timestamp
80 size_t operator()(const NodeTheoryPair& pair) const {
81 uint64_t hash = fnv1a::fnv1a_64(NodeHashFunction()(pair.d_node));
82 return static_cast<size_t>(fnv1a::fnv1a_64(pair.d_theory, hash));
83 }
84 };/* struct NodeTheoryPairHashFunction */
85
86
87 /* Forward declarations */
88 namespace theory {
89 class TheoryModel;
90 class TheoryEngineModelBuilder;
91
92 namespace eq {
93 class EqualityEngine;
94 }/* CVC4::theory::eq namespace */
95
96 namespace quantifiers {
97 class TermDb;
98 }
99
100 class EntailmentCheckParameters;
101 class EntailmentCheckSideEffects;
102 }/* CVC4::theory namespace */
103
104 class RemoveTermFormulas;
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 /** Our context */
122 context::Context* d_context;
123
124 /** Our user context */
125 context::UserContext* d_userContext;
126
127 /**
128 * A table of from theory IDs to theory pointers. Never use this table
129 * directly, use theoryOf() instead.
130 */
131 theory::Theory* d_theoryTable[theory::THEORY_LAST];
132
133 /**
134 * A collection of theories that are "active" for the current run.
135 * This set is provided by the user (as a logic string, say, in SMT-LIBv2
136 * format input), or else by default it's all-inclusive. This is important
137 * because we can optimize for single-theory runs (no sharing), can reduce
138 * the cost of walking the DAG on registration, etc.
139 */
140 const LogicInfo& d_logicInfo;
141
142 /**
143 * The database of shared terms.
144 */
145 SharedTermsDatabase d_sharedTerms;
146
147 /**
148 * Master equality engine, to share with theories.
149 */
150 theory::eq::EqualityEngine* d_masterEqualityEngine;
151
152 /** notify class for master equality engine */
153 class NotifyClass : public theory::eq::EqualityEngineNotify {
154 TheoryEngine& d_te;
155 public:
156 NotifyClass(TheoryEngine& te): d_te(te) {}
157 bool eqNotifyTriggerEquality(TNode equality, bool value) override
158 {
159 return true;
160 }
161 bool eqNotifyTriggerPredicate(TNode predicate, bool value) override
162 {
163 return true;
164 }
165 bool eqNotifyTriggerTermEquality(theory::TheoryId tag,
166 TNode t1,
167 TNode t2,
168 bool value) override
169 {
170 return true;
171 }
172 void eqNotifyConstantTermMerge(TNode t1, TNode t2) override {}
173 void eqNotifyNewClass(TNode t) override { d_te.eqNotifyNewClass(t); }
174 void eqNotifyPreMerge(TNode t1, TNode t2) override
175 {
176 }
177 void eqNotifyPostMerge(TNode t1, TNode t2) override
178 {
179 }
180 void eqNotifyDisequal(TNode t1, TNode t2, TNode reason) override
181 {
182 }
183 };/* class TheoryEngine::NotifyClass */
184 NotifyClass d_masterEENotify;
185
186 /**
187 * notification methods
188 */
189 void eqNotifyNewClass(TNode t);
190 void eqNotifyPreMerge(TNode t1, TNode t2);
191 void eqNotifyPostMerge(TNode t1, TNode t2);
192 void eqNotifyDisequal(TNode t1, TNode t2, TNode reason);
193
194 /**
195 * The quantifiers engine
196 */
197 theory::QuantifiersEngine* d_quantEngine;
198 /**
199 * The decision manager
200 */
201 std::unique_ptr<theory::DecisionManager> d_decManager;
202
203 /**
204 * Default model object
205 */
206 theory::TheoryModel* d_curr_model;
207 bool d_aloc_curr_model;
208 /**
209 * Model builder object
210 */
211 theory::TheoryEngineModelBuilder* d_curr_model_builder;
212 bool d_aloc_curr_model_builder;
213 /** are we in eager model building mode? (see setEagerModelBuilding). */
214 bool d_eager_model_building;
215
216 typedef std::unordered_map<Node, Node, NodeHashFunction> NodeMap;
217 typedef std::unordered_map<TNode, Node, TNodeHashFunction> TNodeMap;
218
219 /**
220 * Cache for theory-preprocessing of assertions
221 */
222 NodeMap d_ppCache;
223
224 /**
225 * Used for "missed-t-propagations" dumping mode only. A set of all
226 * theory-propagable literals.
227 */
228 context::CDList<TNode> d_possiblePropagations;
229
230 /**
231 * Used for "missed-t-propagations" dumping mode only. A
232 * context-dependent set of those theory-propagable literals that
233 * have been propagated.
234 */
235 context::CDHashSet<Node, NodeHashFunction> d_hasPropagated;
236
237
238 /**
239 * Statistics for a particular theory.
240 */
241 class Statistics {
242
243 static std::string mkName(std::string prefix,
244 theory::TheoryId theory,
245 std::string suffix) {
246 std::stringstream ss;
247 ss << prefix << theory << suffix;
248 return ss.str();
249 }
250
251 public:
252 IntStat conflicts, propagations, lemmas, requirePhase, restartDemands;
253
254 Statistics(theory::TheoryId theory);
255 ~Statistics();
256 };/* class TheoryEngine::Statistics */
257
258 /**
259 * An output channel for Theory that passes messages
260 * back to a TheoryEngine.
261 */
262 class EngineOutputChannel : public theory::OutputChannel {
263 friend class TheoryEngine;
264
265 /**
266 * The theory engine we're communicating with.
267 */
268 TheoryEngine* d_engine;
269
270 /**
271 * The statistics of the theory interractions.
272 */
273 Statistics d_statistics;
274
275 /** The theory owning this channel. */
276 theory::TheoryId d_theory;
277
278 public:
279 EngineOutputChannel(TheoryEngine* engine, theory::TheoryId theory)
280 : d_engine(engine), d_statistics(theory), d_theory(theory) {}
281
282 void safePoint(ResourceManager::Resource r) override
283 {
284 spendResource(r);
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(ResourceManager::Resource r) override
326 {
327 d_engine->spendResource(r);
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 public:
469 /** Constructs a theory engine */
470 TheoryEngine(context::Context* context,
471 context::UserContext* userContext,
472 RemoveTermFormulas& iteRemover,
473 const LogicInfo& logic);
474
475 /** Destroys a theory engine */
476 ~TheoryEngine();
477
478 void interrupt();
479
480 /** "Spend" a resource during a search or preprocessing.*/
481 void spendResource(ResourceManager::Resource r);
482
483 /**
484 * Adds a theory. Only one theory per TheoryId can be present, so if
485 * there is another theory it will be deleted.
486 */
487 template <class TheoryClass>
488 inline void addTheory(theory::TheoryId theoryId)
489 {
490 Assert(d_theoryTable[theoryId] == NULL && d_theoryOut[theoryId] == NULL);
491 d_theoryOut[theoryId] = new EngineOutputChannel(this, theoryId);
492 d_theoryTable[theoryId] = new TheoryClass(d_context,
493 d_userContext,
494 *d_theoryOut[theoryId],
495 theory::Valuation(this),
496 d_logicInfo);
497 theory::Rewriter::registerTheoryRewriter(
498 theoryId, d_theoryTable[theoryId]->getTheoryRewriter());
499 }
500
501 void setPropEngine(prop::PropEngine* propEngine)
502 {
503 d_propEngine = propEngine;
504 }
505
506 /** Called when all initialization of options/logic is done */
507 void finishInit();
508
509 /**
510 * Get a pointer to the underlying propositional engine.
511 */
512 inline prop::PropEngine* getPropEngine() const {
513 return d_propEngine;
514 }
515
516 /**
517 * Get a pointer to the underlying sat context.
518 */
519 inline context::Context* getSatContext() const {
520 return d_context;
521 }
522
523 /**
524 * Get a pointer to the underlying user context.
525 */
526 inline context::Context* getUserContext() const {
527 return d_userContext;
528 }
529
530 /**
531 * Get a pointer to the underlying quantifiers engine.
532 */
533 theory::QuantifiersEngine* getQuantifiersEngine() const {
534 return d_quantEngine;
535 }
536 /**
537 * Get a pointer to the underlying decision manager.
538 */
539 theory::DecisionManager* getDecisionManager() const
540 {
541 return d_decManager.get();
542 }
543
544 private:
545 /**
546 * Helper for preprocess
547 */
548 Node ppTheoryRewrite(TNode term);
549
550 /**
551 * Queue of nodes for pre-registration.
552 */
553 std::queue<TNode> d_preregisterQueue;
554
555 /**
556 * Boolean flag denoting we are in pre-registration.
557 */
558 bool d_inPreregister;
559
560 /**
561 * Did the theories get any new facts since the last time we called
562 * check()
563 */
564 context::CDO<bool> d_factsAsserted;
565
566 /**
567 * Map from equality atoms to theories that would like to be notified about them.
568 */
569
570
571 /**
572 * Assert the formula to the given theory.
573 * @param assertion the assertion to send (not necesserily normalized)
574 * @param original the assertion as it was sent in from the propagating theory
575 * @param toTheoryId the theory to assert to
576 * @param fromTheoryId the theory that sent it
577 */
578 void assertToTheory(TNode assertion, TNode originalAssertion, theory::TheoryId toTheoryId, theory::TheoryId fromTheoryId);
579
580 /**
581 * Marks a theory propagation from a theory to a theory where a
582 * theory could be the THEORY_SAT_SOLVER for literals coming from
583 * or being propagated to the SAT solver. If the receiving theory
584 * already recieved the literal, the method returns false, otherwise
585 * it returns true.
586 *
587 * @param assertion the normalized assertion being sent
588 * @param originalAssertion the actual assertion that was sent
589 * @param toTheoryId the theory that is on the receiving end
590 * @param fromTheoryId the theory that sent the assertino
591 * @return true if a new assertion, false if theory already got it
592 */
593 bool markPropagation(TNode assertion, TNode originalAssertions, theory::TheoryId toTheoryId, theory::TheoryId fromTheoryId);
594
595 /**
596 * Computes the explanation by travarsing the propagation graph and
597 * asking relevant theories to explain the propagations. Initially
598 * the explanation vector should contain only the element (node, theory)
599 * where the node is the one to be explained, and the theory is the
600 * theory that sent the literal. The lemmaProofRecipe will contain a list
601 * of the explanation steps required to produce the original node.
602 */
603 void getExplanation(std::vector<NodeTheoryPair>& explanationVector, LemmaProofRecipe* lemmaProofRecipe);
604
605 public:
606
607 /**
608 * Signal the start of a new round of assertion preprocessing
609 */
610 void preprocessStart();
611
612 /**
613 * Runs theory specific preprocessing on the non-Boolean parts of
614 * the formula. This is only called on input assertions, after ITEs
615 * have been removed.
616 */
617 Node preprocess(TNode node);
618
619 /** Notify (preprocessed) assertions. */
620 void notifyPreprocessedAssertions(const std::vector<Node>& assertions);
621
622 /** Return whether or not we are incomplete (in the current context). */
623 inline bool isIncomplete() const { return d_incomplete; }
624
625 /**
626 * Returns true if we need another round of checking. If this
627 * returns true, check(FULL_EFFORT) _must_ be called by the
628 * propositional layer before reporting SAT.
629 *
630 * This is especially necessary for incomplete theories that lazily
631 * output some lemmas on FULL_EFFORT check (e.g. quantifier reasoning
632 * outputing quantifier instantiations). In such a case, a lemma can
633 * be asserted that is simplified away (perhaps it's already true).
634 * However, we must maintain the invariant that, if a theory uses the
635 * OutputChannel, it implicitly requests that another check(FULL_EFFORT)
636 * be performed before exit, even if no new facts are on its fact queue,
637 * as it might decide to further instantiate some lemmas, precluding
638 * a SAT response.
639 */
640 inline bool needCheck() const {
641 return d_outputChannelUsed || d_lemmasAdded;
642 }
643
644 /**
645 * This is called at shutdown time by the SmtEngine, just before
646 * destruction. It is important because there are destruction
647 * ordering issues between PropEngine and Theory.
648 */
649 void shutdown();
650
651 /**
652 * Solve the given literal with a theory that owns it.
653 */
654 theory::Theory::PPAssertStatus solve(TNode literal,
655 theory::SubstitutionMap& substitutionOut);
656
657 /**
658 * Preregister a Theory atom with the responsible theory (or
659 * theories).
660 */
661 void preRegister(TNode preprocessed);
662
663 /**
664 * Assert the formula to the appropriate theory.
665 * @param node the assertion
666 */
667 void assertFact(TNode node);
668
669 /**
670 * Check all (currently-active) theories for conflicts.
671 * @param effort the effort level to use
672 */
673 void check(theory::Theory::Effort effort);
674
675 /**
676 * Run the combination framework.
677 */
678 void combineTheories();
679
680 /**
681 * Calls ppStaticLearn() on all theories, accumulating their
682 * combined contributions in the "learned" builder.
683 */
684 void ppStaticLearn(TNode in, NodeBuilder<>& learned);
685
686 /**
687 * Calls presolve() on all theories and returns true
688 * if one of the theories discovers a conflict.
689 */
690 bool presolve();
691
692 /**
693 * Calls postsolve() on all theories.
694 */
695 void postsolve();
696
697 /**
698 * Calls notifyRestart() on all active theories.
699 */
700 void notifyRestart();
701
702 void getPropagatedLiterals(std::vector<TNode>& literals) {
703 for (; d_propagatedLiteralsIndex < d_propagatedLiterals.size(); d_propagatedLiteralsIndex = d_propagatedLiteralsIndex + 1) {
704 Debug("getPropagatedLiterals") << "TheoryEngine::getPropagatedLiterals: propagating: " << d_propagatedLiterals[d_propagatedLiteralsIndex] << std::endl;
705 literals.push_back(d_propagatedLiterals[d_propagatedLiteralsIndex]);
706 }
707 }
708
709 /**
710 * Returns the next decision request, or null if none exist. The next
711 * decision request is a literal that this theory engine prefers the SAT
712 * solver to make as its next decision. Decision requests are managed by
713 * the decision manager d_decManager.
714 */
715 Node getNextDecisionRequest();
716
717 bool properConflict(TNode conflict) const;
718 bool properPropagation(TNode lit) const;
719 bool properExplanation(TNode node, TNode expl) const;
720
721 /**
722 * Returns an explanation of the node propagated to the SAT solver.
723 */
724 Node getExplanation(TNode node);
725
726 /**
727 * Returns an explanation of the node propagated to the SAT solver and the theory
728 * that propagated it.
729 */
730 Node getExplanationAndRecipe(TNode node, LemmaProofRecipe* proofRecipe);
731
732 /**
733 * collect model info
734 */
735 bool collectModelInfo(theory::TheoryModel* m);
736 /** post process model */
737 void postProcessModel( theory::TheoryModel* m );
738
739 /**
740 * Get the pointer to the model object used by this theory engine.
741 */
742 theory::TheoryModel* getModel();
743 /**
744 * Get the current model for the current set of assertions. This method
745 * should only be called immediately after a satisfiable or unknown
746 * response to a check-sat call, and only if produceModels is true.
747 *
748 * If the model is not already built, this will cause this theory engine
749 * to build the model.
750 *
751 * If the model is not available (for instance, if the last call to check-sat
752 * was interrupted), then this returns the null pointer.
753 */
754 theory::TheoryModel* getBuiltModel();
755 /** set eager model building
756 *
757 * If this method is called, then this TheoryEngine will henceforth build
758 * its model immediately after every satisfiability check that results
759 * in a satisfiable or unknown result. The motivation for this mode is to
760 * accomodate API users that get the model object from the TheoryEngine,
761 * where we want to ensure that this model is always valid.
762 * TODO (#2648): revisit this.
763 */
764 void setEagerModelBuilding() { d_eager_model_building = true; }
765
766 /** get synth solutions
767 *
768 * This method returns true if there is a synthesis solution available. This
769 * is the case if the last call to check satisfiability originated in a
770 * check-synth call, and the synthesis solver successfully found a solution
771 * for all active synthesis conjectures.
772 *
773 * This method adds entries to sol_map that map functions-to-synthesize with
774 * their solutions, for all active conjectures. This should be called
775 * immediately after the solver answers unsat for sygus input.
776 *
777 * For details on what is added to sol_map, see
778 * SynthConjecture::getSynthSolutions.
779 */
780 bool getSynthSolutions(std::map<Node, std::map<Node, Node> >& sol_map);
781
782 /**
783 * Get the model builder
784 */
785 theory::TheoryEngineModelBuilder* getModelBuilder() { return d_curr_model_builder; }
786
787 /**
788 * Get the theory associated to a given Node.
789 *
790 * @returns the theory, or NULL if the TNode is
791 * of built-in type.
792 */
793 inline theory::Theory* theoryOf(TNode node) const {
794 return d_theoryTable[theory::Theory::theoryOf(node)];
795 }
796
797 /**
798 * Get the theory associated to a the given theory id.
799 *
800 * @returns the theory
801 */
802 inline theory::Theory* theoryOf(theory::TheoryId theoryId) const {
803 Assert(theoryId < theory::THEORY_LAST);
804 return d_theoryTable[theoryId];
805 }
806
807 inline bool isTheoryEnabled(theory::TheoryId theoryId) const {
808 return d_logicInfo.isTheoryEnabled(theoryId);
809 }
810 /** get the logic info used by this theory engine */
811 const LogicInfo& getLogicInfo() const;
812 /**
813 * Returns the equality status of the two terms, from the theory
814 * that owns the domain type. The types of a and b must be the same.
815 */
816 theory::EqualityStatus getEqualityStatus(TNode a, TNode b);
817
818 /**
819 * Returns the value that a theory that owns the type of var currently
820 * has (or null if none);
821 */
822 Node getModelValue(TNode var);
823
824 /**
825 * Takes a literal and returns an equivalent literal that is guaranteed to be a SAT literal
826 */
827 Node ensureLiteral(TNode n);
828
829 /**
830 * Print all instantiations made by the quantifiers module.
831 */
832 void printInstantiations( std::ostream& out );
833
834 /**
835 * Print solution for synthesis conjectures found by ce_guided_instantiation module
836 */
837 void printSynthSolution( std::ostream& out );
838
839 /**
840 * Get list of quantified formulas that were instantiated
841 */
842 void getInstantiatedQuantifiedFormulas( std::vector< Node >& qs );
843
844 /**
845 * Get instantiation methods
846 * first inputs forall x.q[x] and returns ( q[a], ..., q[z] )
847 * second inputs forall x.q[x] and returns ( a, ..., z )
848 * third and fourth return mappings e.g. forall x.q1[x] -> ( q1[a]...q1[z] ) , ... , forall x.qn[x] -> ( qn[a]...qn[z] )
849 */
850 void getInstantiations( Node q, std::vector< Node >& insts );
851 void getInstantiationTermVectors( Node q, std::vector< std::vector< Node > >& tvecs );
852 void getInstantiations( std::map< Node, std::vector< Node > >& insts );
853 void getInstantiationTermVectors( std::map< Node, std::vector< std::vector< Node > > >& insts );
854
855 /**
856 * Get instantiated conjunction, returns q[t1] ^ ... ^ q[tn] where t1...tn are current set of instantiations for q.
857 * Can be used for quantifier elimination when satisfiable and q[t1] ^ ... ^ q[tn] |= q
858 */
859 Node getInstantiatedConjunction( Node q );
860
861 /**
862 * Forwards an entailment check according to the given theoryOfMode.
863 * See theory.h for documentation on entailmentCheck().
864 */
865 std::pair<bool, Node> entailmentCheck(
866 options::TheoryOfMode mode,
867 TNode lit,
868 const theory::EntailmentCheckParameters* params = NULL,
869 theory::EntailmentCheckSideEffects* out = NULL);
870
871 private:
872 /** Default visitor for pre-registration */
873 PreRegisterVisitor d_preRegistrationVisitor;
874
875 /** Visitor for collecting shared terms */
876 SharedTermsVisitor d_sharedTermsVisitor;
877
878 /** Dump the assertions to the dump */
879 void dumpAssertions(const char* tag);
880
881 /** For preprocessing pass lifting bit-vectors of size 1 to booleans */
882 public:
883 void staticInitializeBVOptions(const std::vector<Node>& assertions);
884
885 Node ppSimpITE(TNode assertion);
886 /** Returns false if an assertion simplified to false. */
887 bool donePPSimpITE(std::vector<Node>& assertions);
888
889 SharedTermsDatabase* getSharedTermsDatabase() { return &d_sharedTerms; }
890
891 theory::eq::EqualityEngine* getMasterEqualityEngine() { return d_masterEqualityEngine; }
892
893 RemoveTermFormulas* getTermFormulaRemover() { return &d_tform_remover; }
894
895 SortInference* getSortInference() { return &d_sortInfer; }
896
897 /** Prints the assertions to the debug stream */
898 void printAssertions(const char* tag);
899
900 private:
901
902 std::map< std::string, std::vector< theory::Theory* > > d_attr_handle;
903
904 public:
905 /** Set user attribute.
906 *
907 * This function is called when an attribute is set by a user. In SMT-LIBv2
908 * this is done via the syntax (! n :attr)
909 */
910 void setUserAttribute(const std::string& attr,
911 Node n,
912 const std::vector<Node>& node_values,
913 const std::string& str_value);
914
915 /** Handle user attribute.
916 *
917 * Associates theory t with the attribute attr. Theory t will be
918 * notified whenever an attribute of name attr is set.
919 */
920 void handleUserAttribute(const char* attr, theory::Theory* t);
921
922 /**
923 * Check that the theory assertions are satisfied in the model.
924 * This function is called from the smt engine's checkModel routine.
925 */
926 void checkTheoryAssertionsWithModel(bool hardFailure);
927
928 private:
929 IntStat d_arithSubstitutionsAdded;
930
931 };/* class TheoryEngine */
932
933 }/* CVC4 namespace */
934
935 #endif /* CVC4__THEORY_ENGINE_H */