1 /********************* */
4 ** Top contributors (to current version):
5 ** Morgan Deters, Dejan Jovanovic, Tim King
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2017 by the authors listed in the file AUTHORS
8 ** in the top-level source directory) and their institutional affiliations.
9 ** All rights reserved. See the file COPYING in the top-level source
10 ** directory for licensing information.\endverbatim
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/cdlist.h"
29 #include "context/cdhashset.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 "options/theoryof_mode.h"
37 #include "smt/command.h"
39 #include "smt/logic_request.h"
40 #include "theory/assertion.h"
41 #include "theory/care_graph.h"
42 #include "theory/logic_info.h"
43 #include "theory/output_channel.h"
44 #include "theory/valuation.h"
45 #include "util/statistics_registry.h"
53 class QuantifiersEngine
;
55 class SubstitutionMap
;
58 class EntailmentCheckParameters
;
59 class EntailmentCheckSideEffects
;
62 class CandidateGenerator
;
63 }/* CVC4::theory::rrinst namespace */
67 }/* CVC4::theory::eq namespace */
70 * Base class for T-solvers. Abstract DPLL(T).
72 * This is essentially an interface class. The TheoryEngine has
73 * pointers to Theory. Note that only one specific Theory type (e.g.,
74 * TheoryUF) can exist per NodeManager, because of how the
75 * RegisteredAttr works. (If you need multiple instances of the same
76 * theory, you'll have to write a multiplexed theory that dispatches
83 friend class ::CVC4::TheoryEngine
;
85 // Disallow default construction, copy, assignment.
86 Theory() CVC4_UNDEFINED
;
87 Theory(const Theory
&) CVC4_UNDEFINED
;
88 Theory
& operator=(const Theory
&) CVC4_UNDEFINED
;
90 /** An integer identifying the type of the theory. */
93 /** Name of this theory instance. Along with the TheoryId this should provide
94 * an unique string identifier for each instance of a Theory class. We need
95 * this to ensure unique statistics names over multiple theory instances. */
96 std::string d_instanceName
;
98 /** The SAT search context for the Theory. */
99 context::Context
* d_satContext
;
101 /** The user level assertion context for the Theory. */
102 context::UserContext
* d_userContext
;
104 /** Information about the logic we're operating within. */
105 const LogicInfo
& d_logicInfo
;
108 * The assertFact() queue.
110 * These can not be TNodes as some atoms (such as equalities) are sent
111 * across theories without being stored in a global map.
113 context::CDList
<Assertion
> d_facts
;
115 /** Index into the head of the facts list */
116 context::CDO
<unsigned> d_factsHead
;
118 /** Add shared term to the theory. */
119 void addSharedTermInternal(TNode node
);
121 /** Indices for splitting on the shared terms. */
122 context::CDO
<unsigned> d_sharedTermsIndex
;
124 /** The care graph the theory will use during combination. */
125 CareGraph
* d_careGraph
;
128 * Pointer to the quantifiers engine (or NULL, if quantifiers are not
129 * supported or not enabled). Not owned by the theory.
131 QuantifiersEngine
* d_quantEngine
;
133 /** Extended theory module or NULL. Owned by the theory. */
134 ExtTheory
* d_extTheory
;
139 // === STATISTICS ===
140 /** time spent in check calls */
141 TimerStat d_checkTime
;
142 /** time spent in theory combination */
143 TimerStat d_computeCareGraphTime
;
146 * The only method to add suff to the care graph.
148 void addCarePair(TNode t1
, TNode t2
);
151 * The function should compute the care graph over the shared terms.
152 * The default function returns all the pairs among the shared variables.
154 virtual void computeCareGraph();
157 * A list of shared terms that the theory has.
159 context::CDList
<TNode
> d_sharedTerms
;
162 * Helper function for computeRelevantTerms
164 void collectTerms(TNode n
, std::set
<Node
>& termSet
) const;
167 * Scans the current set of assertions and shared terms top-down
168 * until a theory-leaf is reached, and adds all terms found to
169 * termSet. This is used by collectModelInfo to delimit the set of
170 * terms that should be used when constructing a model
172 void computeRelevantTerms(std::set
<Node
>& termSet
, bool includeShared
= true) const;
175 * Construct a Theory.
177 * The pair <id, instance> is assumed to uniquely identify this Theory
178 * w.r.t. the SmtEngine.
180 Theory(TheoryId id
, context::Context
* satContext
,
181 context::UserContext
* userContext
, OutputChannel
& out
,
182 Valuation valuation
, const LogicInfo
& logicInfo
,
183 std::string instance
= "") throw(); // taking : No default.
186 * This is called at shutdown time by the TheoryEngine, just before
187 * destruction. It is important because there are destruction
188 * ordering issues between PropEngine and Theory (based on what
189 * hard-links to Nodes are outstanding). As the fact queue might be
190 * nonempty, we ensure here that it's clear. If you overload this,
191 * you must make an explicit call here to this->Theory::shutdown()
194 virtual void shutdown() { }
197 * The output channel for the Theory.
199 OutputChannel
* d_out
;
202 * The valuation proxy for the Theory to communicate back with the
203 * theory engine (and other theories).
205 Valuation d_valuation
;
208 * Whether proofs are enabled
211 bool d_proofsEnabled
;
214 * Returns the next assertion in the assertFact() queue.
216 * @return the next assertion in the assertFact() queue
218 inline Assertion
get();
220 const LogicInfo
& getLogicInfo() const {
225 * The theory that owns the uninterpreted sort.
227 static TheoryId s_uninterpretedSortOwner
;
229 void printFacts(std::ostream
& os
) const;
230 void debugPrintFacts() const;
233 * Whether proofs are enabled
241 * Return the ID of the theory responsible for the given type.
243 static inline TheoryId
theoryOf(TypeNode typeNode
) {
244 Trace("theory::internal") << "theoryOf(" << typeNode
<< ")" << std::endl
;
246 if (typeNode
.getKind() == kind::TYPE_CONSTANT
) {
247 id
= typeConstantToTheoryId(typeNode
.getConst
<TypeConstant
>());
249 id
= kindToTheoryId(typeNode
.getKind());
251 if (id
== THEORY_BUILTIN
) {
252 Trace("theory::internal") << "theoryOf(" << typeNode
<< ") == " << s_uninterpretedSortOwner
<< std::endl
;
253 return s_uninterpretedSortOwner
;
259 * Returns the ID of the theory responsible for the given node.
261 static TheoryId
theoryOf(TheoryOfMode mode
, TNode node
);
264 * Returns the ID of the theory responsible for the given node.
266 static inline TheoryId
theoryOf(TNode node
) {
267 return theoryOf(options::theoryOfMode(), node
);
271 * Set the owner of the uninterpreted sort.
273 static void setUninterpretedSortOwner(TheoryId theory
) {
274 s_uninterpretedSortOwner
= theory
;
278 * Get the owner of the uninterpreted sort.
280 static TheoryId
getUninterpretedSortOwner() {
281 return s_uninterpretedSortOwner
;
285 * Checks if the node is a leaf node of this theory
287 inline bool isLeaf(TNode node
) const {
288 return node
.getNumChildren() == 0 || theoryOf(node
) != d_id
;
292 * Checks if the node is a leaf node of a theory.
294 inline static bool isLeafOf(TNode node
, TheoryId theoryId
) {
295 return node
.getNumChildren() == 0 || theoryOf(node
) != theoryId
;
299 * Returns true if the assertFact queue is empty
301 bool done() const throw() {
302 return d_factsHead
== d_facts
.size();
306 * Destructs a Theory.
311 * Subclasses of Theory may add additional efforts. DO NOT CHECK
312 * equality with one of these values (e.g. if STANDARD xxx) but
313 * rather use range checks (or use the helper functions below).
314 * Normally we call QUICK_CHECK or STANDARD; at the leaves we call
319 * Standard effort where theory need not do anything
321 EFFORT_STANDARD
= 50,
323 * Full effort requires the theory make sure its assertions are satisfiable or not
327 * Combination effort means that the individual theories are already satisfied, and
328 * it is time to put some effort into propagation of shared term equalities
330 EFFORT_COMBINATION
= 150,
332 * Last call effort, reserved for quantifiers.
334 EFFORT_LAST_CALL
= 200
337 static inline bool standardEffortOrMore(Effort e
) CVC4_CONST_FUNCTION
338 { return e
>= EFFORT_STANDARD
; }
339 static inline bool standardEffortOnly(Effort e
) CVC4_CONST_FUNCTION
340 { return e
>= EFFORT_STANDARD
&& e
< EFFORT_FULL
; }
341 static inline bool fullEffort(Effort e
) CVC4_CONST_FUNCTION
342 { return e
== EFFORT_FULL
; }
343 static inline bool combination(Effort e
) CVC4_CONST_FUNCTION
344 { return e
== EFFORT_COMBINATION
; }
347 * Get the id for this Theory.
349 TheoryId
getId() const {
354 * Returns a string that uniquely identifies this theory solver w.r.t. the
357 std::string
getFullInstanceName() const;
361 * Get the SAT context associated to this Theory.
363 context::Context
* getSatContext() const {
368 * Get the context associated to this Theory.
370 context::UserContext
* getUserContext() const {
371 return d_userContext
;
375 * Set the output channel associated to this theory.
377 void setOutputChannel(OutputChannel
& out
) {
382 * Get the output channel associated to this theory.
384 OutputChannel
& getOutputChannel() {
389 * Get the valuation associated to this theory.
391 Valuation
& getValuation() {
396 * Get the quantifiers engine associated to this theory.
398 QuantifiersEngine
* getQuantifiersEngine() {
399 return d_quantEngine
;
403 * Get the quantifiers engine associated to this theory (const version).
405 const QuantifiersEngine
* getQuantifiersEngine() const {
406 return d_quantEngine
;
410 * Finish theory initialization. At this point, options and the logic
411 * setting are final, and the master equality engine and quantifiers
412 * engine (if any) are initialized. This base class implementation
415 virtual void finishInit() { }
418 * Some theories have kinds that are effectively definitions and
419 * should be expanded before they are handled. Definitions allow
420 * a much wider range of actions than the normal forms given by the
421 * rewriter; they can enable other theories and create new terms.
422 * However no assumptions can be made about subterms having been
423 * expanded or rewritten. Where possible rewrite rules should be
424 * used, definitions should only be used when rewrites are not
425 * possible, for example in handling under-specified operations
426 * using partially defined functions.
428 * TODO (github issue #1076):
429 * some theories like sets use expandDefinition as a "context
430 * independent preRegisterTerm". This is required for cases where
431 * a theory wants to be notified about a term before preprocessing
432 * and simplification but doesn't necessarily want to rewrite it.
434 virtual Node
expandDefinition(LogicRequest
&logicRequest
, Node node
) {
435 // by default, do nothing
440 * Pre-register a term. Done one time for a Node per SAT context level.
442 virtual void preRegisterTerm(TNode
) { }
445 * Assert a fact in the current context.
447 void assertFact(TNode assertion
, bool isPreregistered
) {
448 Trace("theory") << "Theory<" << getId() << ">::assertFact["
449 << d_satContext
->getLevel() << "](" << assertion
<< ", "
450 << (isPreregistered
? "true" : "false") << ")" << std::endl
;
451 d_facts
.push_back(Assertion(assertion
, isPreregistered
));
455 * This method is called to notify a theory that the node n should
456 * be considered a "shared term" by this theory
458 virtual void addSharedTerm(TNode n
) { }
461 * Called to set the master equality engine.
463 virtual void setMasterEqualityEngine(eq::EqualityEngine
* eq
) { }
465 /** Called to set the quantifiers engine. */
466 virtual void setQuantifiersEngine(QuantifiersEngine
* qe
);
468 /** Setup an ExtTheory module for this Theory. Can only be called once. */
469 void setupExtTheory();
472 * Return the current theory care graph. Theories should overload
473 * computeCareGraph to do the actual computation, and use addCarePair to add
474 * pairs to the care graph.
476 void getCareGraph(CareGraph
* careGraph
);
479 * Return the status of two terms in the current context. Should be
480 * implemented in sub-theories to enable more efficient theory-combination.
482 virtual EqualityStatus
getEqualityStatus(TNode a
, TNode b
) {
483 return EQUALITY_UNKNOWN
;
487 * Return the model value of the give shared term (or null if not available).
489 virtual Node
getModelValue(TNode var
) { return Node::null(); }
492 * Check the current assignment's consistency.
494 * An implementation of check() is required to either:
495 * - return a conflict on the output channel,
497 * - throw an exception
498 * - or call get() until done() is true.
500 virtual void check(Effort level
= EFFORT_FULL
) { }
502 /** Needs last effort check? */
503 virtual bool needsCheckLastEffort() { return false; }
505 /** T-propagate new literal assignments in the current context. */
506 virtual void propagate(Effort level
= EFFORT_FULL
) { }
509 * Return an explanation for the literal represented by parameter n
510 * (which was previously propagated by this theory).
512 virtual Node
explain(TNode n
) {
513 Unimplemented("Theory %s propagated a node but doesn't implement the "
514 "Theory::explain() interface!", identify().c_str());
518 * Get all relevant information in this theory regarding the current
519 * model. This should be called after a call to check( FULL_EFFORT )
520 * for all theories with no conflicts and no lemmas added.
522 virtual void collectModelInfo( TheoryModel
* m
){ }
524 /** if theories want to do something with model after building, do it here */
525 virtual void postProcessModel( TheoryModel
* m
){ }
527 * Return a decision request, if the theory has one, or the NULL node
529 * If returning non-null node, should set priority to
530 * 0 if decision is necessary for model-soundness,
531 * 1 if decision is necessary for completeness,
534 virtual Node
getNextDecisionRequest( unsigned& priority
) { return Node(); }
537 * Statically learn from assertion "in," which has been asserted
538 * true at the top level. The theory should only add (via
539 * ::operator<< or ::append()) to the "learned" builder---it should
540 * *never* clear it. It is a conjunction to add to the formula at
541 * the top-level and may contain other theories' contributions.
543 virtual void ppStaticLearn(TNode in
, NodeBuilder
<>& learned
) { }
545 enum PPAssertStatus
{
546 /** Atom has been solved */
547 PP_ASSERT_STATUS_SOLVED
,
548 /** Atom has not been solved */
549 PP_ASSERT_STATUS_UNSOLVED
,
550 /** Atom is inconsistent */
551 PP_ASSERT_STATUS_CONFLICT
555 * Given a literal, add the solved substitutions to the map, if any.
556 * The method should return true if the literal can be safely removed.
558 virtual PPAssertStatus
ppAssert(TNode in
, SubstitutionMap
& outSubstitutions
);
561 * Given an atom of the theory coming from the input formula, this
562 * method can be overridden in a theory implementation to rewrite
563 * the atom into an equivalent form. This is only called just
564 * before an input atom to the engine.
566 virtual Node
ppRewrite(TNode atom
) { return atom
; }
569 * Don't preprocess subterm of this term
571 virtual bool ppDontRewriteSubterm(TNode atom
) { return false; }
574 * Notify preprocessed assertions. Called on new assertions after
575 * preprocessing before they are asserted to theory engine.
577 virtual void ppNotifyAssertions(const std::vector
<Node
>& assertions
) {}
580 * A Theory is called with presolve exactly one time per user
581 * check-sat. presolve() is called after preregistration,
582 * rewriting, and Boolean propagation, (other theories'
583 * propagation?), but the notified Theory has not yet had its
584 * check() or propagate() method called. A Theory may empty its
585 * assertFact() queue using get(). A Theory can raise conflicts,
586 * add lemmas, and propagate literals during presolve().
588 * NOTE: The presolve property must be added to the kinds file for
591 virtual void presolve() { }
594 * A Theory is called with postsolve exactly one time per user
595 * check-sat. postsolve() is called after the query has completed
596 * (regardless of whether sat, unsat, or unknown), and after any
597 * model-querying related to the query has been performed.
598 * After this call, the theory will not get another check() or
599 * propagate() call until presolve() is called again. A Theory
600 * cannot raise conflicts, add lemmas, or propagate literals during
603 virtual void postsolve() { }
606 * Notification sent to the theory wheneven the search restarts.
607 * Serves as a good time to do some clean-up work, and you can
608 * assume you're at DL 0 for the purposes of Contexts. This function
609 * should not use the output channel.
611 virtual void notifyRestart() { }
614 * Identify this theory (for debugging, dynamic configuration,
617 virtual std::string
identify() const = 0;
619 /** Set user attribute
620 * This function is called when an attribute is set by a user. In SMT-LIBv2 this is done
621 * via the syntax (! n :attr)
623 virtual void setUserAttribute(const std::string
& attr
, Node n
, std::vector
<Node
> node_values
, std::string str_value
) {
624 Unimplemented("Theory %s doesn't support Theory::setUserAttribute interface",
628 /** A set of theories */
629 typedef uint32_t Set
;
631 /** A set of all theories */
632 static const Set AllTheories
= (1 << theory::THEORY_LAST
) - 1;
634 /** Pops a first theory off the set */
635 static inline TheoryId
setPop(Set
& set
) {
636 uint32_t i
= ffs(set
); // Find First Set (bit)
637 if (i
== 0) { return THEORY_LAST
; }
638 TheoryId id
= (TheoryId
)(i
-1);
639 set
= setRemove(id
, set
);
643 /** Returns the size of a set of theories */
644 static inline size_t setSize(Set set
) {
646 while (setPop(set
) != THEORY_LAST
) {
652 /** Returns the index size of a set of theories */
653 static inline size_t setIndex(TheoryId id
, Set set
) {
654 Assert (setContains(id
, set
));
656 while (setPop(set
) != id
) {
662 /** Add the theory to the set. If no set specified, just returns a singleton set */
663 static inline Set
setInsert(TheoryId theory
, Set set
= 0) {
664 return set
| (1 << theory
);
667 /** Add the theory to the set. If no set specified, just returns a singleton set */
668 static inline Set
setRemove(TheoryId theory
, Set set
= 0) {
669 return setDifference(set
, setInsert(theory
));
672 /** Check if the set contains the theory */
673 static inline bool setContains(TheoryId theory
, Set set
) {
674 return set
& (1 << theory
);
677 static inline Set
setComplement(Set a
) {
678 return (~a
) & AllTheories
;
681 static inline Set
setIntersection(Set a
, Set b
) {
685 static inline Set
setUnion(Set a
, Set b
) {
690 static inline Set
setDifference(Set a
, Set b
) {
694 static inline std::string
setToString(theory::Theory::Set theorySet
) {
695 std::stringstream ss
;
697 for(unsigned theoryId
= 0; theoryId
< theory::THEORY_LAST
; ++theoryId
) {
698 if (theory::Theory::setContains((theory::TheoryId
)theoryId
, theorySet
)) {
699 ss
<< (theory::TheoryId
) theoryId
<< " ";
706 typedef context::CDList
<Assertion
>::const_iterator assertions_iterator
;
709 * Provides access to the facts queue, primarily intended for theory
710 * debugging purposes.
712 * @return the iterator to the beginning of the fact queue
714 assertions_iterator
facts_begin() const {
715 return d_facts
.begin();
719 * Provides access to the facts queue, primarily intended for theory
720 * debugging purposes.
722 * @return the iterator to the end of the fact queue
724 assertions_iterator
facts_end() const {
725 return d_facts
.end();
728 * Whether facts have been asserted to this theory.
730 * @return true iff facts have been asserted to this theory.
733 return !d_facts
.empty();
736 /** Return total number of facts asserted to this theory */
737 size_t numAssertions() {
738 return d_facts
.size();
741 typedef context::CDList
<TNode
>::const_iterator shared_terms_iterator
;
744 * Provides access to the shared terms, primarily intended for theory
745 * debugging purposes.
747 * @return the iterator to the beginning of the shared terms list
749 shared_terms_iterator
shared_terms_begin() const {
750 return d_sharedTerms
.begin();
754 * Provides access to the facts queue, primarily intended for theory
755 * debugging purposes.
757 * @return the iterator to the end of the shared terms list
759 shared_terms_iterator
shared_terms_end() const {
760 return d_sharedTerms
.end();
765 * This is a utility function for constructing a copy of the currently shared terms
766 * in a queriable form. As this is
768 std::unordered_set
<TNode
, TNodeHashFunction
> currentlySharedTerms() const;
771 * This allows the theory to be queried for whether a literal, lit, is
772 * entailed by the theory. This returns a pair of a Boolean and a node E.
774 * If the Boolean is true, then E is a formula that entails lit and E is propositionally
775 * entailed by the assertions to the theory.
777 * If the Boolean is false, it is "unknown" if lit is entailed and E may be
780 * The literal lit is either an atom a or (not a), which must belong to the theory:
781 * There is some TheoryOfMode m s.t. Theory::theoryOf(m, a) == this->getId().
783 * There are NO assumptions that a or the subterms of a have been
784 * preprocessed in any form. This includes ppRewrite, rewriting,
785 * preregistering, registering, definition expansion or ITE removal!
787 * Theories are free to limit the amount of effort they use and so may
788 * always opt to return "unknown". Both "unknown" and "not entailed",
789 * may return for E a non-boolean Node (e.g. Node::null()). (There is no explicit output
790 * for the negation of lit is entailed.)
792 * If lit is theory valid, the return result may be the Boolean constant
795 * If lit is entailed by multiple assertions on the theory's getFact()
796 * queue, a_1, a_2, ... and a_k, this may return E=(and a_1 a_2 ... a_k) or
797 * another theory entailed explanation E=(and (and a_1 a_2) (and a3 a_4) ... a_k)
799 * If lit is entailed by a single assertion on the theory's getFact()
800 * queue, say a, this may return E=a.
802 * The theory may always return false!
804 * The search is controlled by the parameter params. For default behavior,
805 * this may be left NULL.
807 * Theories that want parameters extend the virtual EntailmentCheckParameters
808 * class. Users ask the theory for an appropriate subclass from the theory
809 * and configure that. How this is implemented is on a per theory basis.
811 * The search may provide additional output to guide the user of
812 * this function. This output is stored in a EntailmentCheckSideEffects*
813 * output parameter. The implementation of this is theory specific. For
814 * no output, this is NULL.
816 * Theories may not touch their output stream during an entailment check.
818 * @param lit a literal belonging to the theory.
819 * @param params the control parameters for the entailment check.
820 * @param out a theory specific output object of the entailment search.
821 * @return a pair <b,E> s.t. if b is true, then a formula E such that
822 * E |= lit in the theory.
824 virtual std::pair
<bool, Node
> entailmentCheck(
825 TNode lit
, const EntailmentCheckParameters
* params
= NULL
,
826 EntailmentCheckSideEffects
* out
= NULL
);
828 /* equality engine TODO: use? */
829 virtual eq::EqualityEngine
* getEqualityEngine() { return NULL
; }
831 /* Get extended theory if one has been installed. */
832 ExtTheory
* getExtTheory();
834 /* get current substitution at an effort
837 * where ( exp[vars[i]] => vars[i] = subs[i] ) holds for all i
839 virtual bool getCurrentSubstitution(int effort
, std::vector
<Node
>& vars
,
840 std::vector
<Node
>& subs
,
841 std::map
<Node
, std::vector
<Node
> >& exp
) {
845 /* is extended function reduced */
846 virtual bool isExtfReduced( int effort
, Node n
, Node on
, std::vector
< Node
>& exp
) { return n
.isConst(); }
849 * Get reduction for node
850 * If return value is not 0, then n is reduced.
851 * If return value <0 then n is reduced SAT-context-independently (e.g. by a
852 * lemma that persists at this user-context level).
853 * If nr is non-null, then ( n = nr ) should be added as a lemma by caller,
854 * and return value should be <0.
856 virtual int getReduction( int effort
, Node n
, Node
& nr
) { return 0; }
858 /** Turn on proof-production mode. */
859 void produceProofs() { d_proofsEnabled
= true; }
863 std::ostream
& operator<<(std::ostream
& os
, theory::Theory::Effort level
);
866 inline theory::Assertion
Theory::get() {
867 Assert( !done(), "Theory::get() called with assertion queue empty!" );
870 Assertion fact
= d_facts
[d_factsHead
];
871 d_factsHead
= d_factsHead
+ 1;
873 Trace("theory") << "Theory::get() => " << fact
<< " (" << d_facts
.size() - d_factsHead
<< " left)" << std::endl
;
875 if(Dump
.isOn("state")) {
876 Dump("state") << AssertCommand(fact
.assertion
.toExpr());
882 inline std::ostream
& operator<<(std::ostream
& out
,
883 const CVC4::theory::Theory
& theory
) {
884 return out
<< theory
.identify();
887 inline std::ostream
& operator << (std::ostream
& out
, theory::Theory::PPAssertStatus status
) {
889 case theory::Theory::PP_ASSERT_STATUS_SOLVED
:
890 out
<< "SOLVE_STATUS_SOLVED"; break;
891 case theory::Theory::PP_ASSERT_STATUS_UNSOLVED
:
892 out
<< "SOLVE_STATUS_UNSOLVED"; break;
893 case theory::Theory::PP_ASSERT_STATUS_CONFLICT
:
894 out
<< "SOLVE_STATUS_CONFLICT"; break;
901 class EntailmentCheckParameters
{
905 EntailmentCheckParameters(TheoryId tid
);
907 TheoryId
getTheoryId() const;
908 virtual ~EntailmentCheckParameters();
909 };/* class EntailmentCheckParameters */
911 class EntailmentCheckSideEffects
{
915 EntailmentCheckSideEffects(TheoryId tid
);
917 TheoryId
getTheoryId() const;
918 virtual ~EntailmentCheckSideEffects();
919 };/* class EntailmentCheckSideEffects */
923 typedef context::CDHashMap
<Node
, bool, NodeHashFunction
> NodeBoolMap
;
924 typedef context::CDHashSet
<Node
, NodeHashFunction
> NodeSet
;
927 static std::vector
<Node
> collectVars(Node n
);
928 // is context dependent inactive
929 bool isContextIndependentInactive( Node n
) const;
930 //do inferences internal
931 bool doInferencesInternal(int effort
, const std::vector
<Node
>& terms
,
932 std::vector
<Node
>& nred
, bool batch
, bool isRed
);
934 bool sendLemma( Node lem
, bool preprocess
= false );
935 // register term (recursive)
936 void registerTermRec(Node n
, std::set
<Node
>* visited
);
940 //extended string terms, map to whether they are active
941 NodeBoolMap d_ext_func_terms
;
942 //set of terms from d_ext_func_terms that are SAT-context-independently inactive
943 // (e.g. term t when a reduction lemma of the form t = t' was added)
944 NodeSet d_ci_inactive
;
945 //watched term for checking if any non-reduced extended functions exist
946 context::CDO
< Node
> d_has_extf
;
948 std::map
< Kind
, bool > d_extf_kind
;
949 //information for each term in d_ext_func_terms
952 //all variables in this term
953 std::vector
< Node
> d_vars
;
955 std::map
< Node
, ExtfInfo
> d_extf_info
;
957 //cache of all lemmas sent
961 // if d_cacheEnabled=true :
962 //cache for getSubstitutedTerms
966 std::vector
< Node
> d_exp
;
968 std::map
< int, std::map
< Node
, SubsTermInfo
> > d_gst_cache
;
971 ExtTheory(Theory
* p
, bool cacheEnabled
= false );
972 virtual ~ExtTheory() {}
974 void addFunctionKind(Kind k
) { d_extf_kind
[k
] = true; }
975 bool hasFunctionKind(Kind k
) const {
976 return d_extf_kind
.find(k
) != d_extf_kind
.end();
979 // adds n to d_ext_func_terms if addFunctionKind( n.getKind() ) was called
980 void registerTerm( Node n
);
981 void registerTermRec( Node n
);
982 // set n as reduced/inactive
983 // if contextDepend = false, then n remains inactive in the duration of this user-context level
984 void markReduced( Node n
, bool contextDepend
= true );
985 // mark that a and b are congruent terms: set b inactive, set a to inactive if b was inactive
986 void markCongruent( Node a
, Node b
);
987 //getSubstitutedTerms
988 // input : effort, terms
989 // output : sterms, exp, where ( exp[i] => terms[i] = sterms[i] ) for all i
990 Node
getSubstitutedTerm( int effort
, Node term
, std::vector
< Node
>& exp
, bool useCache
= false );
991 void getSubstitutedTerms(int effort
, const std::vector
<Node
>& terms
,
992 std::vector
<Node
>& sterms
,
993 std::vector
<std::vector
<Node
> >& exp
, bool useCache
= false);
995 // * input : effort, terms, batch (whether to send one lemma or lemmas for
997 // * sends rewriting lemmas of the form ( exp => t = c ) where t is in terms
998 // and c is a constant, c = rewrite( t*sigma ) where exp |= sigma
999 // * output : nred (the terms that are still active)
1000 // * return : true iff lemma is sent
1001 bool doInferences(int effort
, const std::vector
<Node
>& terms
,
1002 std::vector
<Node
>& nred
, bool batch
= true);
1003 bool doInferences(int effort
, std::vector
<Node
>& nred
, bool batch
= true);
1005 // same as doInferences, but will send reduction lemmas of the form ( t = t' )
1006 // where t is in terms, t' is equivalent, reduced term.
1007 bool doReductions(int effort
, const std::vector
<Node
>& terms
,
1008 std::vector
<Node
>& nred
, bool batch
= true);
1009 bool doReductions(int effort
, std::vector
<Node
>& nred
, bool batch
= true);
1011 //get the set of terms from d_ext_func_terms
1012 void getTerms( std::vector
< Node
>& terms
);
1014 bool hasActiveTerm();
1016 bool isActive(Node n
);
1017 // get the set of active terms from d_ext_func_terms
1018 std::vector
<Node
> getActive() const;
1019 // get the set of active terms from d_ext_func_terms of kind k
1020 std::vector
<Node
> getActive(Kind k
) const;
1025 }/* CVC4::theory namespace */
1026 }/* CVC4 namespace */
1028 #endif /* __CVC4__THEORY__THEORY_H */