1 /********************* */
4 ** Top contributors (to current version):
5 ** Dejan Jovanovic, Morgan Deters, Tim King
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2020 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
12 ** \brief Base of the theory interface.
14 ** Base of the theory interface.
17 #include "cvc4_private.h"
19 #ifndef CVC4__THEORY__THEORY_H
20 #define CVC4__THEORY__THEORY_H
26 #include <unordered_set>
28 #include "context/cdhashset.h"
29 #include "context/cdlist.h"
30 #include "context/cdo.h"
31 #include "context/context.h"
32 #include "expr/node.h"
34 #include "options/options.h"
35 #include "options/theory_options.h"
36 #include "smt/command.h"
38 #include "smt/logic_request.h"
39 #include "theory/assertion.h"
40 #include "theory/care_graph.h"
41 #include "theory/decision_manager.h"
42 #include "theory/logic_info.h"
43 #include "theory/output_channel.h"
44 #include "theory/theory_id.h"
45 #include "theory/theory_rewriter.h"
46 #include "theory/trust_node.h"
47 #include "theory/valuation.h"
48 #include "util/statistics_registry.h"
53 class ProofNodeManager
;
57 class QuantifiersEngine
;
59 class SubstitutionMap
;
63 class EntailmentCheckParameters
;
64 class EntailmentCheckSideEffects
;
67 class CandidateGenerator
;
68 }/* CVC4::theory::rrinst namespace */
72 }/* CVC4::theory::eq namespace */
75 * Base class for T-solvers. Abstract DPLL(T).
77 * This is essentially an interface class. The TheoryEngine has
78 * pointers to Theory. Note that only one specific Theory type (e.g.,
79 * TheoryUF) can exist per NodeManager, because of how the
80 * RegisteredAttr works. (If you need multiple instances of the same
81 * theory, you'll have to write a multiplexed theory that dispatches
86 friend class ::CVC4::TheoryEngine
;
88 // Disallow default construction, copy, assignment.
90 Theory(const Theory
&) = delete;
91 Theory
& operator=(const Theory
&) = delete;
93 /** An integer identifying the type of the theory. */
96 /** Name of this theory instance. Along with the TheoryId this should provide
97 * an unique string identifier for each instance of a Theory class. We need
98 * this to ensure unique statistics names over multiple theory instances. */
99 std::string d_instanceName
;
101 /** The SAT search context for the Theory. */
102 context::Context
* d_satContext
;
104 /** The user level assertion context for the Theory. */
105 context::UserContext
* d_userContext
;
107 /** Information about the logic we're operating within. */
108 const LogicInfo
& d_logicInfo
;
110 /** Pointer to proof node manager */
111 ProofNodeManager
* d_pnm
;
114 * The assertFact() queue.
116 * These can not be TNodes as some atoms (such as equalities) are sent
117 * across theories without being stored in a global map.
119 context::CDList
<Assertion
> d_facts
;
121 /** Index into the head of the facts list */
122 context::CDO
<unsigned> d_factsHead
;
124 /** Add shared term to the theory. */
125 void addSharedTermInternal(TNode node
);
127 /** Indices for splitting on the shared terms. */
128 context::CDO
<unsigned> d_sharedTermsIndex
;
130 /** The care graph the theory will use during combination. */
131 CareGraph
* d_careGraph
;
134 * Pointer to the quantifiers engine (or NULL, if quantifiers are not
135 * supported or not enabled). Not owned by the theory.
137 QuantifiersEngine
* d_quantEngine
;
139 /** Pointer to the decision manager. */
140 DecisionManager
* d_decManager
;
142 /** Extended theory module or NULL. Owned by the theory. */
143 ExtTheory
* d_extTheory
;
147 // === STATISTICS ===
148 /** time spent in check calls */
149 TimerStat d_checkTime
;
150 /** time spent in theory combination */
151 TimerStat d_computeCareGraphTime
;
154 * The only method to add suff to the care graph.
156 void addCarePair(TNode t1
, TNode t2
);
159 * The function should compute the care graph over the shared terms.
160 * The default function returns all the pairs among the shared variables.
162 virtual void computeCareGraph();
165 * A list of shared terms that the theory has.
167 context::CDList
<TNode
> d_sharedTerms
;
170 * Helper function for computeRelevantTerms
172 void collectTerms(TNode n
,
173 std::set
<Kind
>& irrKinds
,
174 std::set
<Node
>& termSet
) const;
177 * Scans the current set of assertions and shared terms top-down
178 * until a theory-leaf is reached, and adds all terms found to
179 * termSet. This is used by collectModelInfo to delimit the set of
180 * terms that should be used when constructing a model.
182 * irrKinds: The kinds of terms that appear in assertions that should *not*
183 * be included in termSet. Note that the kinds EQUAL and NOT are always
184 * treated as irrelevant kinds.
186 * includeShared: Whether to include shared terms in termSet. Notice that
187 * shared terms are not influenced by irrKinds.
189 void computeRelevantTerms(std::set
<Node
>& termSet
,
190 std::set
<Kind
>& irrKinds
,
191 bool includeShared
= true) const;
192 /** same as above, but with empty irrKinds */
193 void computeRelevantTerms(std::set
<Node
>& termSet
, bool includeShared
= true) const;
196 * Construct a Theory.
198 * The pair <id, instance> is assumed to uniquely identify this Theory
199 * w.r.t. the SmtEngine.
202 context::Context
* satContext
,
203 context::UserContext
* userContext
,
206 const LogicInfo
& logicInfo
,
207 ProofNodeManager
* pnm
,
208 std::string instance
= ""); // taking : No default.
211 * This is called at shutdown time by the TheoryEngine, just before
212 * destruction. It is important because there are destruction
213 * ordering issues between PropEngine and Theory (based on what
214 * hard-links to Nodes are outstanding). As the fact queue might be
215 * nonempty, we ensure here that it's clear. If you overload this,
216 * you must make an explicit call here to this->Theory::shutdown()
219 virtual void shutdown() { }
222 * The output channel for the Theory.
224 OutputChannel
* d_out
;
227 * The valuation proxy for the Theory to communicate back with the
228 * theory engine (and other theories).
230 Valuation d_valuation
;
233 * Whether proofs are enabled
236 bool d_proofsEnabled
;
239 * Returns the next assertion in the assertFact() queue.
241 * @return the next assertion in the assertFact() queue
243 inline Assertion
get();
245 const LogicInfo
& getLogicInfo() const {
250 * The theory that owns the uninterpreted sort.
252 static TheoryId s_uninterpretedSortOwner
;
254 void printFacts(std::ostream
& os
) const;
255 void debugPrintFacts() const;
257 /** is legal elimination
259 * Returns true if x -> val is a legal elimination of variable x. This is
260 * useful for ppAssert, when x = val is an entailed equality. This function
261 * determines whether indeed x can be eliminated from the problem via the
262 * substituion x -> val.
264 * The following criteria imply that x -> val is *not* a legal elimination:
265 * (1) If x is contained in val,
266 * (2) If the type of val is not a subtype of the type of x,
267 * (3) If val contains an operator that cannot be evaluated, and produceModels
268 * is true. For example, x -> sqrt(2) is not a legal elimination if we
269 * are producing models. This is because we care about the value of x, and
270 * its value must be computed (approximated) by the non-linear solver.
272 bool isLegalElimination(TNode x
, TNode val
);
276 * Return the ID of the theory responsible for the given type.
278 static inline TheoryId
theoryOf(TypeNode typeNode
) {
279 Trace("theory::internal") << "theoryOf(" << typeNode
<< ")" << std::endl
;
281 if (typeNode
.getKind() == kind::TYPE_CONSTANT
) {
282 id
= typeConstantToTheoryId(typeNode
.getConst
<TypeConstant
>());
284 id
= kindToTheoryId(typeNode
.getKind());
286 if (id
== THEORY_BUILTIN
) {
287 Trace("theory::internal") << "theoryOf(" << typeNode
<< ") == " << s_uninterpretedSortOwner
<< std::endl
;
288 return s_uninterpretedSortOwner
;
294 * Returns the ID of the theory responsible for the given node.
296 static TheoryId
theoryOf(options::TheoryOfMode mode
, TNode node
);
299 * Returns the ID of the theory responsible for the given node.
301 static inline TheoryId
theoryOf(TNode node
) {
302 return theoryOf(options::theoryOfMode(), node
);
306 * Set the owner of the uninterpreted sort.
308 static void setUninterpretedSortOwner(TheoryId theory
) {
309 s_uninterpretedSortOwner
= theory
;
313 * Get the owner of the uninterpreted sort.
315 static TheoryId
getUninterpretedSortOwner() {
316 return s_uninterpretedSortOwner
;
320 * Checks if the node is a leaf node of this theory
322 inline bool isLeaf(TNode node
) const {
323 return node
.getNumChildren() == 0 || theoryOf(node
) != d_id
;
327 * Checks if the node is a leaf node of a theory.
329 inline static bool isLeafOf(TNode node
, TheoryId theoryId
) {
330 return node
.getNumChildren() == 0 || theoryOf(node
) != theoryId
;
333 /** Returns true if the assertFact queue is empty*/
334 bool done() const { return d_factsHead
== d_facts
.size(); }
336 * Destructs a Theory.
341 * @return The theory rewriter associated with this theory.
343 virtual TheoryRewriter
* getTheoryRewriter() = 0;
346 * Subclasses of Theory may add additional efforts. DO NOT CHECK
347 * equality with one of these values (e.g. if STANDARD xxx) but
348 * rather use range checks (or use the helper functions below).
349 * Normally we call QUICK_CHECK or STANDARD; at the leaves we call
354 * Standard effort where theory need not do anything
356 EFFORT_STANDARD
= 50,
358 * Full effort requires the theory make sure its assertions are satisfiable or not
362 * Combination effort means that the individual theories are already satisfied, and
363 * it is time to put some effort into propagation of shared term equalities
365 EFFORT_COMBINATION
= 150,
367 * Last call effort, reserved for quantifiers.
369 EFFORT_LAST_CALL
= 200
372 static inline bool standardEffortOrMore(Effort e
) CVC4_CONST_FUNCTION
373 { return e
>= EFFORT_STANDARD
; }
374 static inline bool standardEffortOnly(Effort e
) CVC4_CONST_FUNCTION
375 { return e
>= EFFORT_STANDARD
&& e
< EFFORT_FULL
; }
376 static inline bool fullEffort(Effort e
) CVC4_CONST_FUNCTION
377 { return e
== EFFORT_FULL
; }
378 static inline bool combination(Effort e
) CVC4_CONST_FUNCTION
379 { return e
== EFFORT_COMBINATION
; }
382 * Get the id for this Theory.
384 TheoryId
getId() const {
389 * Get the SAT context associated to this Theory.
391 context::Context
* getSatContext() const {
396 * Get the context associated to this Theory.
398 context::UserContext
* getUserContext() const {
399 return d_userContext
;
403 * Set the output channel associated to this theory.
405 void setOutputChannel(OutputChannel
& out
) {
410 * Get the output channel associated to this theory.
412 OutputChannel
& getOutputChannel() {
417 * Get the valuation associated to this theory.
419 Valuation
& getValuation() {
424 * Get the quantifiers engine associated to this theory.
426 QuantifiersEngine
* getQuantifiersEngine() {
427 return d_quantEngine
;
431 * Get the quantifiers engine associated to this theory (const version).
433 const QuantifiersEngine
* getQuantifiersEngine() const {
434 return d_quantEngine
;
437 /** Get the decision manager associated to this theory. */
438 DecisionManager
* getDecisionManager() { return d_decManager
; }
441 * Finish theory initialization. At this point, options and the logic
442 * setting are final, and the master equality engine and quantifiers
443 * engine (if any) are initialized. This base class implementation
446 virtual void finishInit() { }
449 * Expand definitions in the term node. This returns a term that is
450 * equivalent to node. It wraps this term in a TrustNode of kind
451 * TrustNodeKind::REWRITE. If node is unchanged by this method, the
452 * null TrustNode may be returned. This is an optimization to avoid
453 * constructing the trivial equality (= node node) internally within
456 * The purpose of this method is typically to eliminate the operators in node
457 * that are syntax sugar that cannot otherwise be eliminated during rewriting.
458 * For example, division relies on the introduction of an uninterpreted
459 * function for the divide-by-zero case, which we do not introduce with
460 * the rewriter, since this function may be cached in a non-global fashion.
462 * Some theories have kinds that are effectively definitions and should be
463 * expanded before they are handled. Definitions allow a much wider range of
464 * actions than the normal forms given by the rewriter. However no
465 * assumptions can be made about subterms having been expanded or rewritten.
466 * Where possible rewrite rules should be used, definitions should only be
467 * used when rewrites are not possible, for example in handling
468 * under-specified operations using partially defined functions.
470 * Some theories like sets use expandDefinition as a "context
471 * independent preRegisterTerm". This is required for cases where
472 * a theory wants to be notified about a term before preprocessing
473 * and simplification but doesn't necessarily want to rewrite it.
475 virtual TrustNode
expandDefinition(Node node
)
477 // by default, do nothing
478 return TrustNode::null();
482 * Pre-register a term. Done one time for a Node per SAT context level.
484 virtual void preRegisterTerm(TNode
) { }
487 * Assert a fact in the current context.
489 void assertFact(TNode assertion
, bool isPreregistered
) {
490 Trace("theory") << "Theory<" << getId() << ">::assertFact["
491 << d_satContext
->getLevel() << "](" << assertion
<< ", "
492 << (isPreregistered
? "true" : "false") << ")" << std::endl
;
493 d_facts
.push_back(Assertion(assertion
, isPreregistered
));
497 * This method is called to notify a theory that the node n should
498 * be considered a "shared term" by this theory
500 virtual void addSharedTerm(TNode n
) { }
503 * Called to set the master equality engine.
505 virtual void setMasterEqualityEngine(eq::EqualityEngine
* eq
) { }
507 /** Called to set the quantifiers engine. */
508 void setQuantifiersEngine(QuantifiersEngine
* qe
);
509 /** Called to set the decision manager. */
510 void setDecisionManager(DecisionManager
* dm
);
512 /** Setup an ExtTheory module for this Theory. Can only be called once. */
513 void setupExtTheory();
516 * Return the current theory care graph. Theories should overload
517 * computeCareGraph to do the actual computation, and use addCarePair to add
518 * pairs to the care graph.
520 void getCareGraph(CareGraph
* careGraph
);
523 * Return the status of two terms in the current context. Should be
524 * implemented in sub-theories to enable more efficient theory-combination.
526 virtual EqualityStatus
getEqualityStatus(TNode a
, TNode b
) {
527 return EQUALITY_UNKNOWN
;
531 * Return the model value of the give shared term (or null if not available).
533 virtual Node
getModelValue(TNode var
) { return Node::null(); }
536 * Check the current assignment's consistency.
538 * An implementation of check() is required to either:
539 * - return a conflict on the output channel,
541 * - throw an exception
542 * - or call get() until done() is true.
544 virtual void check(Effort level
= EFFORT_FULL
) { }
546 /** Needs last effort check? */
547 virtual bool needsCheckLastEffort() { return false; }
549 /** T-propagate new literal assignments in the current context. */
550 virtual void propagate(Effort level
= EFFORT_FULL
) { }
553 * Return an explanation for the literal represented by parameter n
554 * (which was previously propagated by this theory).
556 virtual TrustNode
explain(TNode n
)
558 Unimplemented() << "Theory " << identify()
559 << " propagated a node but doesn't implement the "
560 "Theory::explain() interface!";
564 * Get all relevant information in this theory regarding the current
565 * model. This should be called after a call to check( FULL_EFFORT )
566 * for all theories with no conflicts and no lemmas added.
568 * This method returns true if and only if the equality engine of m is
569 * consistent as a result of this call.
571 virtual bool collectModelInfo(TheoryModel
* m
) { return true; }
572 /** if theories want to do something with model after building, do it here */
573 virtual void postProcessModel( TheoryModel
* m
){ }
575 * Statically learn from assertion "in," which has been asserted
576 * true at the top level. The theory should only add (via
577 * ::operator<< or ::append()) to the "learned" builder---it should
578 * *never* clear it. It is a conjunction to add to the formula at
579 * the top-level and may contain other theories' contributions.
581 virtual void ppStaticLearn(TNode in
, NodeBuilder
<>& learned
) { }
583 enum PPAssertStatus
{
584 /** Atom has been solved */
585 PP_ASSERT_STATUS_SOLVED
,
586 /** Atom has not been solved */
587 PP_ASSERT_STATUS_UNSOLVED
,
588 /** Atom is inconsistent */
589 PP_ASSERT_STATUS_CONFLICT
593 * Given a literal, add the solved substitutions to the map, if any.
594 * The method should return true if the literal can be safely removed.
596 virtual PPAssertStatus
ppAssert(TNode in
, SubstitutionMap
& outSubstitutions
);
599 * Given an atom of the theory coming from the input formula, this
600 * method can be overridden in a theory implementation to rewrite
601 * the atom into an equivalent form. This is only called just
602 * before an input atom to the engine. This method returns a TrustNode of
603 * kind TrustNodeKind::REWRITE, which carries information about the proof
604 * generator for the rewrite. Similarly to expandDefinition, this method may
605 * return the null TrustNode if atom is unchanged.
607 virtual TrustNode
ppRewrite(TNode atom
) { return TrustNode::null(); }
610 * Notify preprocessed assertions. Called on new assertions after
611 * preprocessing before they are asserted to theory engine.
613 virtual void ppNotifyAssertions(const std::vector
<Node
>& assertions
) {}
616 * A Theory is called with presolve exactly one time per user
617 * check-sat. presolve() is called after preregistration,
618 * rewriting, and Boolean propagation, (other theories'
619 * propagation?), but the notified Theory has not yet had its
620 * check() or propagate() method called. A Theory may empty its
621 * assertFact() queue using get(). A Theory can raise conflicts,
622 * add lemmas, and propagate literals during presolve().
624 * NOTE: The presolve property must be added to the kinds file for
627 virtual void presolve() { }
630 * A Theory is called with postsolve exactly one time per user
631 * check-sat. postsolve() is called after the query has completed
632 * (regardless of whether sat, unsat, or unknown), and after any
633 * model-querying related to the query has been performed.
634 * After this call, the theory will not get another check() or
635 * propagate() call until presolve() is called again. A Theory
636 * cannot raise conflicts, add lemmas, or propagate literals during
639 virtual void postsolve() { }
642 * Notification sent to the theory wheneven the search restarts.
643 * Serves as a good time to do some clean-up work, and you can
644 * assume you're at DL 0 for the purposes of Contexts. This function
645 * should not use the output channel.
647 virtual void notifyRestart() { }
650 * Identify this theory (for debugging, dynamic configuration,
653 virtual std::string
identify() const = 0;
655 /** Set user attribute
656 * This function is called when an attribute is set by a user. In SMT-LIBv2 this is done
657 * via the syntax (! n :attr)
659 virtual void setUserAttribute(const std::string
& attr
, Node n
, std::vector
<Node
> node_values
, std::string str_value
) {
660 Unimplemented() << "Theory " << identify()
661 << " doesn't support Theory::setUserAttribute interface";
664 /** A set of theories */
665 typedef uint32_t Set
;
667 /** A set of all theories */
668 static const Set AllTheories
= (1 << theory::THEORY_LAST
) - 1;
670 /** Pops a first theory off the set */
671 static inline TheoryId
setPop(Set
& set
) {
672 uint32_t i
= ffs(set
); // Find First Set (bit)
673 if (i
== 0) { return THEORY_LAST
; }
674 TheoryId id
= (TheoryId
)(i
-1);
675 set
= setRemove(id
, set
);
679 /** Returns the size of a set of theories */
680 static inline size_t setSize(Set set
) {
682 while (setPop(set
) != THEORY_LAST
) {
688 /** Returns the index size of a set of theories */
689 static inline size_t setIndex(TheoryId id
, Set set
) {
690 Assert(setContains(id
, set
));
692 while (setPop(set
) != id
) {
698 /** Add the theory to the set. If no set specified, just returns a singleton set */
699 static inline Set
setInsert(TheoryId theory
, Set set
= 0) {
700 return set
| (1 << theory
);
703 /** Add the theory to the set. If no set specified, just returns a singleton set */
704 static inline Set
setRemove(TheoryId theory
, Set set
= 0) {
705 return setDifference(set
, setInsert(theory
));
708 /** Check if the set contains the theory */
709 static inline bool setContains(TheoryId theory
, Set set
) {
710 return set
& (1 << theory
);
713 static inline Set
setComplement(Set a
) {
714 return (~a
) & AllTheories
;
717 static inline Set
setIntersection(Set a
, Set b
) {
721 static inline Set
setUnion(Set a
, Set b
) {
726 static inline Set
setDifference(Set a
, Set b
) {
730 static inline std::string
setToString(theory::Theory::Set theorySet
) {
731 std::stringstream ss
;
733 for(unsigned theoryId
= 0; theoryId
< theory::THEORY_LAST
; ++theoryId
) {
734 if (theory::Theory::setContains((theory::TheoryId
)theoryId
, theorySet
)) {
735 ss
<< (theory::TheoryId
) theoryId
<< " ";
742 typedef context::CDList
<Assertion
>::const_iterator assertions_iterator
;
745 * Provides access to the facts queue, primarily intended for theory
746 * debugging purposes.
748 * @return the iterator to the beginning of the fact queue
750 assertions_iterator
facts_begin() const {
751 return d_facts
.begin();
755 * Provides access to the facts queue, primarily intended for theory
756 * debugging purposes.
758 * @return the iterator to the end of the fact queue
760 assertions_iterator
facts_end() const {
761 return d_facts
.end();
764 * Whether facts have been asserted to this theory.
766 * @return true iff facts have been asserted to this theory.
769 return !d_facts
.empty();
772 /** Return total number of facts asserted to this theory */
773 size_t numAssertions() {
774 return d_facts
.size();
777 typedef context::CDList
<TNode
>::const_iterator shared_terms_iterator
;
780 * Provides access to the shared terms, primarily intended for theory
781 * debugging purposes.
783 * @return the iterator to the beginning of the shared terms list
785 shared_terms_iterator
shared_terms_begin() const {
786 return d_sharedTerms
.begin();
790 * Provides access to the facts queue, primarily intended for theory
791 * debugging purposes.
793 * @return the iterator to the end of the shared terms list
795 shared_terms_iterator
shared_terms_end() const {
796 return d_sharedTerms
.end();
801 * This is a utility function for constructing a copy of the currently shared terms
802 * in a queriable form. As this is
804 std::unordered_set
<TNode
, TNodeHashFunction
> currentlySharedTerms() const;
807 * This allows the theory to be queried for whether a literal, lit, is
808 * entailed by the theory. This returns a pair of a Boolean and a node E.
810 * If the Boolean is true, then E is a formula that entails lit and E is propositionally
811 * entailed by the assertions to the theory.
813 * If the Boolean is false, it is "unknown" if lit is entailed and E may be
816 * The literal lit is either an atom a or (not a), which must belong to the theory:
817 * There is some TheoryOfMode m s.t. Theory::theoryOf(m, a) == this->getId().
819 * There are NO assumptions that a or the subterms of a have been
820 * preprocessed in any form. This includes ppRewrite, rewriting,
821 * preregistering, registering, definition expansion or ITE removal!
823 * Theories are free to limit the amount of effort they use and so may
824 * always opt to return "unknown". Both "unknown" and "not entailed",
825 * may return for E a non-boolean Node (e.g. Node::null()). (There is no explicit output
826 * for the negation of lit is entailed.)
828 * If lit is theory valid, the return result may be the Boolean constant
831 * If lit is entailed by multiple assertions on the theory's getFact()
832 * queue, a_1, a_2, ... and a_k, this may return E=(and a_1 a_2 ... a_k) or
833 * another theory entailed explanation E=(and (and a_1 a_2) (and a3 a_4) ... a_k)
835 * If lit is entailed by a single assertion on the theory's getFact()
836 * queue, say a, this may return E=a.
838 * The theory may always return false!
840 * The search is controlled by the parameter params. For default behavior,
841 * this may be left NULL.
843 * Theories that want parameters extend the virtual EntailmentCheckParameters
844 * class. Users ask the theory for an appropriate subclass from the theory
845 * and configure that. How this is implemented is on a per theory basis.
847 * The search may provide additional output to guide the user of
848 * this function. This output is stored in a EntailmentCheckSideEffects*
849 * output parameter. The implementation of this is theory specific. For
850 * no output, this is NULL.
852 * Theories may not touch their output stream during an entailment check.
854 * @param lit a literal belonging to the theory.
855 * @param params the control parameters for the entailment check.
856 * @param out a theory specific output object of the entailment search.
857 * @return a pair <b,E> s.t. if b is true, then a formula E such that
858 * E |= lit in the theory.
860 virtual std::pair
<bool, Node
> entailmentCheck(
861 TNode lit
, const EntailmentCheckParameters
* params
= NULL
,
862 EntailmentCheckSideEffects
* out
= NULL
);
864 /* equality engine TODO: use? */
865 virtual eq::EqualityEngine
* getEqualityEngine() { return NULL
; }
867 /* Get extended theory if one has been installed. */
868 ExtTheory
* getExtTheory();
870 /* get current substitution at an effort
873 * where ( exp[vars[i]] => vars[i] = subs[i] ) holds for all i
875 virtual bool getCurrentSubstitution(int effort
, std::vector
<Node
>& vars
,
876 std::vector
<Node
>& subs
,
877 std::map
<Node
, std::vector
<Node
> >& exp
) {
881 /* is extended function reduced */
882 virtual bool isExtfReduced( int effort
, Node n
, Node on
, std::vector
< Node
>& exp
) { return n
.isConst(); }
885 * Get reduction for node
886 * If return value is not 0, then n is reduced.
887 * If return value <0 then n is reduced SAT-context-independently (e.g. by a
888 * lemma that persists at this user-context level).
889 * If nr is non-null, then ( n = nr ) should be added as a lemma by caller,
890 * and return value should be <0.
892 virtual int getReduction( int effort
, Node n
, Node
& nr
) { return 0; }
894 /** Turn on proof-production mode. */
895 void produceProofs() { d_proofsEnabled
= true; }
899 std::ostream
& operator<<(std::ostream
& os
, theory::Theory::Effort level
);
902 inline theory::Assertion
Theory::get() {
903 Assert(!done()) << "Theory::get() called with assertion queue empty!";
906 Assertion fact
= d_facts
[d_factsHead
];
907 d_factsHead
= d_factsHead
+ 1;
909 Trace("theory") << "Theory::get() => " << fact
<< " (" << d_facts
.size() - d_factsHead
<< " left)" << std::endl
;
911 if(Dump
.isOn("state")) {
912 Dump("state") << AssertCommand(fact
.d_assertion
.toExpr());
918 inline std::ostream
& operator<<(std::ostream
& out
,
919 const CVC4::theory::Theory
& theory
) {
920 return out
<< theory
.identify();
923 inline std::ostream
& operator << (std::ostream
& out
, theory::Theory::PPAssertStatus status
) {
925 case theory::Theory::PP_ASSERT_STATUS_SOLVED
:
926 out
<< "SOLVE_STATUS_SOLVED"; break;
927 case theory::Theory::PP_ASSERT_STATUS_UNSOLVED
:
928 out
<< "SOLVE_STATUS_UNSOLVED"; break;
929 case theory::Theory::PP_ASSERT_STATUS_CONFLICT
:
930 out
<< "SOLVE_STATUS_CONFLICT"; break;
937 class EntailmentCheckParameters
{
941 EntailmentCheckParameters(TheoryId tid
);
943 TheoryId
getTheoryId() const;
944 virtual ~EntailmentCheckParameters();
945 };/* class EntailmentCheckParameters */
947 class EntailmentCheckSideEffects
{
951 EntailmentCheckSideEffects(TheoryId tid
);
953 TheoryId
getTheoryId() const;
954 virtual ~EntailmentCheckSideEffects();
955 };/* class EntailmentCheckSideEffects */
957 }/* CVC4::theory namespace */
958 }/* CVC4 namespace */
960 #endif /* CVC4__THEORY__THEORY_H */