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-2016 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
22 #include <ext/hash_set>
26 #include "context/cdlist.h"
27 #include "context/cdhashset.h"
28 #include "context/cdo.h"
29 #include "context/context.h"
30 #include "expr/node.h"
32 #include "options/options.h"
33 #include "options/theory_options.h"
34 #include "options/theoryof_mode.h"
35 #include "smt/command.h"
37 #include "smt/logic_request.h"
38 #include "theory/logic_info.h"
39 #include "theory/output_channel.h"
40 #include "theory/valuation.h"
41 #include "util/statistics_registry.h"
49 class QuantifiersEngine
;
51 class SubstitutionMap
;
54 class EntailmentCheckParameters
;
55 class EntailmentCheckSideEffects
;
58 class CandidateGenerator
;
59 }/* CVC4::theory::rrinst namespace */
63 }/* CVC4::theory::eq namespace */
66 * Information about an assertion for the theories.
72 /** Has this assertion been preregistered with this theory */
75 Assertion(TNode assertion
, bool isPreregistered
)
76 : assertion(assertion
), isPreregistered(isPreregistered
) {}
79 * Convert the assertion to a TNode.
81 operator TNode () const {
86 * Convert the assertion to a Node.
88 operator Node () const {
92 };/* struct Assertion */
95 * A (oredered) pair of terms a theory cares about.
104 CarePair(TNode a
, TNode b
, TheoryId theory
)
105 : a(a
< b
? a
: b
), b(a
< b
? b
: a
), theory(theory
) {}
107 bool operator == (const CarePair
& other
) const {
108 return (theory
== other
.theory
) && (a
== other
.a
) && (b
== other
.b
);
111 bool operator < (const CarePair
& other
) const {
112 if (theory
< other
.theory
) return true;
113 if (theory
> other
.theory
) return false;
114 if (a
< other
.a
) return true;
115 if (a
> other
.a
) return false;
119 };/* struct CarePair */
122 * A set of care pairs.
124 typedef std::set
<CarePair
> CareGraph
;
127 * Base class for T-solvers. Abstract DPLL(T).
129 * This is essentially an interface class. The TheoryEngine has
130 * pointers to Theory. Note that only one specific Theory type (e.g.,
131 * TheoryUF) can exist per NodeManager, because of how the
132 * RegisteredAttr works. (If you need multiple instances of the same
133 * theory, you'll have to write a multiplexed theory that dispatches
134 * all calls to them.)
140 friend class ::CVC4::TheoryEngine
;
142 // Disallow default construction, copy, assignment.
143 Theory() CVC4_UNDEFINED
;
144 Theory(const Theory
&) CVC4_UNDEFINED
;
145 Theory
& operator=(const Theory
&) CVC4_UNDEFINED
;
148 * An integer identifying the type of the theory
152 /** Name of this theory instance. Along with the TheoryId this should provide
153 * an unique string identifier for each instance of a Theory class. We need
154 * this to ensure unique statistics names over multiple theory instances. */
155 std::string d_instanceName
;
158 * The SAT search context for the Theory.
160 context::Context
* d_satContext
;
163 * The user level assertion context for the Theory.
165 context::UserContext
* d_userContext
;
168 * Information about the logic we're operating within.
170 const LogicInfo
& d_logicInfo
;
173 * The assertFact() queue.
175 * These can not be TNodes as some atoms (such as equalities) are sent
176 * across theories without being stored in a global map.
178 context::CDList
<Assertion
> d_facts
;
180 /** Index into the head of the facts list */
181 context::CDO
<unsigned> d_factsHead
;
184 * Add shared term to the theory.
186 void addSharedTermInternal(TNode node
);
189 * Indices for splitting on the shared terms.
191 context::CDO
<unsigned> d_sharedTermsIndex
;
194 * The care graph the theory will use during combination.
196 CareGraph
* d_careGraph
;
199 * Reference to the quantifiers engine (or NULL, if quantifiers are
200 * not supported or not enabled).
202 QuantifiersEngine
* d_quantEngine
;
206 /** extended theory */
209 // === STATISTICS ===
210 /** time spent in check calls */
211 TimerStat d_checkTime
;
212 /** time spent in theory combination */
213 TimerStat d_computeCareGraphTime
;
216 * The only method to add suff to the care graph.
218 void addCarePair(TNode t1
, TNode t2
) {
220 d_careGraph
->insert(CarePair(t1
, t2
, d_id
));
225 * The function should compute the care graph over the shared terms.
226 * The default function returns all the pairs among the shared variables.
228 virtual void computeCareGraph();
231 * A list of shared terms that the theory has.
233 context::CDList
<TNode
> d_sharedTerms
;
236 * Helper function for computeRelevantTerms
238 void collectTerms(TNode n
, std::set
<Node
>& termSet
) const;
240 * Scans the current set of assertions and shared terms top-down
241 * until a theory-leaf is reached, and adds all terms found to
242 * termSet. This is used by collectModelInfo to delimit the set of
243 * terms that should be used when constructing a model
245 void computeRelevantTerms(std::set
<Node
>& termSet
, bool includeShared
= true) const;
248 * Construct a Theory.
250 * The pair <id, instance> is assumed to uniquely identify this Theory
251 * w.r.t. the SmtEngine.
253 Theory(TheoryId id
, context::Context
* satContext
,
254 context::UserContext
* userContext
, OutputChannel
& out
,
255 Valuation valuation
, const LogicInfo
& logicInfo
,
256 std::string instance
= "") throw(); // taking : No default.
259 * This is called at shutdown time by the TheoryEngine, just before
260 * destruction. It is important because there are destruction
261 * ordering issues between PropEngine and Theory (based on what
262 * hard-links to Nodes are outstanding). As the fact queue might be
263 * nonempty, we ensure here that it's clear. If you overload this,
264 * you must make an explicit call here to this->Theory::shutdown()
267 virtual void shutdown() { }
270 * The output channel for the Theory.
272 OutputChannel
* d_out
;
275 * The valuation proxy for the Theory to communicate back with the
276 * theory engine (and other theories).
278 Valuation d_valuation
;
281 * Whether proofs are enabled
284 bool d_proofsEnabled
;
287 * Returns the next assertion in the assertFact() queue.
289 * @return the next assertion in the assertFact() queue
291 inline Assertion
get();
293 const LogicInfo
& getLogicInfo() const {
298 * The theory that owns the uninterpreted sort.
300 static TheoryId s_uninterpretedSortOwner
;
302 void printFacts(std::ostream
& os
) const;
303 void debugPrintFacts() const;
306 * Whether proofs are enabled
314 * Return the ID of the theory responsible for the given type.
316 static inline TheoryId
theoryOf(TypeNode typeNode
) {
317 Trace("theory::internal") << "theoryOf(" << typeNode
<< ")" << std::endl
;
319 while (typeNode
.isPredicateSubtype()) {
320 typeNode
= typeNode
.getSubtypeParentType();
322 if (typeNode
.getKind() == kind::TYPE_CONSTANT
) {
323 id
= typeConstantToTheoryId(typeNode
.getConst
<TypeConstant
>());
325 id
= kindToTheoryId(typeNode
.getKind());
327 if (id
== THEORY_BUILTIN
) {
328 Trace("theory::internal") << "theoryOf(" << typeNode
<< ") == " << s_uninterpretedSortOwner
<< std::endl
;
329 return s_uninterpretedSortOwner
;
335 * Returns the ID of the theory responsible for the given node.
337 static TheoryId
theoryOf(TheoryOfMode mode
, TNode node
);
340 * Returns the ID of the theory responsible for the given node.
342 static inline TheoryId
theoryOf(TNode node
) {
343 return theoryOf(options::theoryOfMode(), node
);
347 * Set the owner of the uninterpreted sort.
349 static void setUninterpretedSortOwner(TheoryId theory
) {
350 s_uninterpretedSortOwner
= theory
;
354 * Get the owner of the uninterpreted sort.
356 static TheoryId
getUninterpretedSortOwner() {
357 return s_uninterpretedSortOwner
;
361 * Checks if the node is a leaf node of this theory
363 inline bool isLeaf(TNode node
) const {
364 return node
.getNumChildren() == 0 || theoryOf(node
) != d_id
;
368 * Checks if the node is a leaf node of a theory.
370 inline static bool isLeafOf(TNode node
, TheoryId theoryId
) {
371 return node
.getNumChildren() == 0 || theoryOf(node
) != theoryId
;
375 * Returns true if the assertFact queue is empty
377 bool done() const throw() {
378 return d_factsHead
== d_facts
.size();
382 * Destructs a Theory.
387 * Subclasses of Theory may add additional efforts. DO NOT CHECK
388 * equality with one of these values (e.g. if STANDARD xxx) but
389 * rather use range checks (or use the helper functions below).
390 * Normally we call QUICK_CHECK or STANDARD; at the leaves we call
395 * Standard effort where theory need not do anything
397 EFFORT_STANDARD
= 50,
399 * Full effort requires the theory make sure its assertions are satisfiable or not
403 * Combination effort means that the individual theories are already satisfied, and
404 * it is time to put some effort into propagation of shared term equalities
406 EFFORT_COMBINATION
= 150,
408 * Last call effort, reserved for quantifiers.
410 EFFORT_LAST_CALL
= 200
413 static inline bool standardEffortOrMore(Effort e
) CVC4_CONST_FUNCTION
414 { return e
>= EFFORT_STANDARD
; }
415 static inline bool standardEffortOnly(Effort e
) CVC4_CONST_FUNCTION
416 { return e
>= EFFORT_STANDARD
&& e
< EFFORT_FULL
; }
417 static inline bool fullEffort(Effort e
) CVC4_CONST_FUNCTION
418 { return e
== EFFORT_FULL
; }
419 static inline bool combination(Effort e
) CVC4_CONST_FUNCTION
420 { return e
== EFFORT_COMBINATION
; }
423 * Get the id for this Theory.
425 TheoryId
getId() const {
430 * Returns a string that uniquely identifies this theory solver w.r.t. the
433 std::string
getFullInstanceName() const;
437 * Get the SAT context associated to this Theory.
439 context::Context
* getSatContext() const {
444 * Get the context associated to this Theory.
446 context::UserContext
* getUserContext() const {
447 return d_userContext
;
451 * Set the output channel associated to this theory.
453 void setOutputChannel(OutputChannel
& out
) {
458 * Get the output channel associated to this theory.
460 OutputChannel
& getOutputChannel() {
465 * Get the valuation associated to this theory.
467 Valuation
& getValuation() {
472 * Get the quantifiers engine associated to this theory.
474 QuantifiersEngine
* getQuantifiersEngine() {
475 return d_quantEngine
;
479 * Get the quantifiers engine associated to this theory (const version).
481 const QuantifiersEngine
* getQuantifiersEngine() const {
482 return d_quantEngine
;
486 * Finish theory initialization. At this point, options and the logic
487 * setting are final, and the master equality engine and quantifiers
488 * engine (if any) are initialized. This base class implementation
491 virtual void finishInit() { }
494 * Some theories have kinds that are effectively definitions and
495 * should be expanded before they are handled. Definitions allow
496 * a much wider range of actions than the normal forms given by the
497 * rewriter; they can enable other theories and create new terms.
498 * However no assumptions can be made about subterms having been
499 * expanded or rewritten. Where possible rewrite rules should be
500 * used, definitions should only be used when rewrites are not
501 * possible, for example in handling under-specified operations
502 * using partially defined functions.
504 virtual Node
expandDefinition(LogicRequest
&logicRequest
, Node node
) {
505 // by default, do nothing
510 * Pre-register a term. Done one time for a Node per SAT context level.
512 virtual void preRegisterTerm(TNode
) { }
515 * Assert a fact in the current context.
517 void assertFact(TNode assertion
, bool isPreregistered
) {
518 Trace("theory") << "Theory<" << getId() << ">::assertFact[" << d_satContext
->getLevel() << "](" << assertion
<< ", " << (isPreregistered
? "true" : "false") << ")" << std::endl
;
519 d_facts
.push_back(Assertion(assertion
, isPreregistered
));
523 * This method is called to notify a theory that the node n should
524 * be considered a "shared term" by this theory
526 virtual void addSharedTerm(TNode n
) { }
529 * Called to set the master equality engine.
531 virtual void setMasterEqualityEngine(eq::EqualityEngine
* eq
) { }
534 * Called to set the quantifiers engine.
536 virtual void setQuantifiersEngine(QuantifiersEngine
* qe
) {
541 * Return the current theory care graph. Theories should overload computeCareGraph to do
542 * the actual computation, and use addCarePair to add pairs to the care graph.
544 void getCareGraph(CareGraph
& careGraph
) {
545 Trace("sharing") << "Theory<" << getId() << ">::getCareGraph()" << std::endl
;
546 TimerStat::CodeTimer
computeCareGraphTime(d_computeCareGraphTime
);
547 d_careGraph
= &careGraph
;
553 * Return the status of two terms in the current context. Should be implemented in
554 * sub-theories to enable more efficient theory-combination.
556 virtual EqualityStatus
getEqualityStatus(TNode a
, TNode b
) { return EQUALITY_UNKNOWN
; }
559 * Return the model value of the give shared term (or null if not available).
561 virtual Node
getModelValue(TNode var
) { return Node::null(); }
564 * Check the current assignment's consistency.
566 * An implementation of check() is required to either:
567 * - return a conflict on the output channel,
569 * - throw an exception
570 * - or call get() until done() is true.
572 virtual void check(Effort level
= EFFORT_FULL
) { }
575 * Needs last effort check?
577 virtual bool needsCheckLastEffort() { return false; }
579 * T-propagate new literal assignments in the current context.
581 virtual void propagate(Effort level
= EFFORT_FULL
) { }
584 * Return an explanation for the literal represented by parameter n
585 * (which was previously propagated by this theory).
587 virtual Node
explain(TNode n
) {
588 Unimplemented("Theory %s propagated a node but doesn't implement the "
589 "Theory::explain() interface!", identify().c_str());
593 * Get all relevant information in this theory regarding the current
594 * model. This should be called after a call to check( FULL_EFFORT )
595 * for all theories with no conflicts and no lemmas added.
596 * If fullModel is true, then we must specify sufficient information for
597 * the model class to construct constant representatives for each equivalence
600 virtual void collectModelInfo( TheoryModel
* m
, bool fullModel
){ }
601 /** if theories want to do something with model after building, do it here */
602 virtual void postProcessModel( TheoryModel
* m
){ }
605 * Return a decision request, if the theory has one, or the NULL node
607 * If returning non-null node, hould set priority to
608 * 0 if decision is necessary for model-soundness,
609 * 1 if decision is necessary for completeness,
612 virtual Node
getNextDecisionRequest( unsigned& priority
) { return Node(); }
615 * Statically learn from assertion "in," which has been asserted
616 * true at the top level. The theory should only add (via
617 * ::operator<< or ::append()) to the "learned" builder---it should
618 * *never* clear it. It is a conjunction to add to the formula at
619 * the top-level and may contain other theories' contributions.
621 virtual void ppStaticLearn(TNode in
, NodeBuilder
<>& learned
) { }
623 enum PPAssertStatus
{
624 /** Atom has been solved */
625 PP_ASSERT_STATUS_SOLVED
,
626 /** Atom has not been solved */
627 PP_ASSERT_STATUS_UNSOLVED
,
628 /** Atom is inconsistent */
629 PP_ASSERT_STATUS_CONFLICT
633 * Given a literal, add the solved substitutions to the map, if any.
634 * The method should return true if the literal can be safely removed.
636 virtual PPAssertStatus
ppAssert(TNode in
, SubstitutionMap
& outSubstitutions
);
639 * Given an atom of the theory coming from the input formula, this
640 * method can be overridden in a theory implementation to rewrite
641 * the atom into an equivalent form. This is only called just
642 * before an input atom to the engine.
644 virtual Node
ppRewrite(TNode atom
) { return atom
; }
647 * Don't preprocess subterm of this term
649 virtual bool ppDontRewriteSubterm(TNode atom
) { return false; }
651 /** notify preprocessed assertions
652 * Called on new assertions after preprocessing before they are asserted to theory engine.
653 * Should not modify assertions.
655 virtual void ppNotifyAssertions( std::vector
< Node
>& assertions
) {}
658 * A Theory is called with presolve exactly one time per user
659 * check-sat. presolve() is called after preregistration,
660 * rewriting, and Boolean propagation, (other theories'
661 * propagation?), but the notified Theory has not yet had its
662 * check() or propagate() method called. A Theory may empty its
663 * assertFact() queue using get(). A Theory can raise conflicts,
664 * add lemmas, and propagate literals during presolve().
666 * NOTE: The presolve property must be added to the kinds file for
669 virtual void presolve() { }
672 * A Theory is called with postsolve exactly one time per user
673 * check-sat. postsolve() is called after the query has completed
674 * (regardless of whether sat, unsat, or unknown), and after any
675 * model-querying related to the query has been performed.
676 * After this call, the theory will not get another check() or
677 * propagate() call until presolve() is called again. A Theory
678 * cannot raise conflicts, add lemmas, or propagate literals during
681 virtual void postsolve() { }
684 * Notification sent to the theory wheneven the search restarts.
685 * Serves as a good time to do some clean-up work, and you can
686 * assume you're at DL 0 for the purposes of Contexts. This function
687 * should not use the output channel.
689 virtual void notifyRestart() { }
692 * Identify this theory (for debugging, dynamic configuration,
695 virtual std::string
identify() const = 0;
697 /** Set user attribute
698 * This function is called when an attribute is set by a user. In SMT-LIBv2 this is done
699 * via the syntax (! n :attr)
701 virtual void setUserAttribute(const std::string
& attr
, Node n
, std::vector
<Node
> node_values
, std::string str_value
) {
702 Unimplemented("Theory %s doesn't support Theory::setUserAttribute interface",
706 /** A set of theories */
707 typedef uint32_t Set
;
709 /** A set of all theories */
710 static const Set AllTheories
= (1 << theory::THEORY_LAST
) - 1;
712 /** Pops a first theory off the set */
713 static inline TheoryId
setPop(Set
& set
) {
714 uint32_t i
= ffs(set
); // Find First Set (bit)
715 if (i
== 0) { return THEORY_LAST
; }
716 TheoryId id
= (TheoryId
)(i
-1);
717 set
= setRemove(id
, set
);
721 /** Returns the size of a set of theories */
722 static inline size_t setSize(Set set
) {
724 while (setPop(set
) != THEORY_LAST
) {
730 /** Returns the index size of a set of theories */
731 static inline size_t setIndex(TheoryId id
, Set set
) {
732 Assert (setContains(id
, set
));
734 while (setPop(set
) != id
) {
740 /** Add the theory to the set. If no set specified, just returns a singleton set */
741 static inline Set
setInsert(TheoryId theory
, Set set
= 0) {
742 return set
| (1 << theory
);
745 /** Add the theory to the set. If no set specified, just returns a singleton set */
746 static inline Set
setRemove(TheoryId theory
, Set set
= 0) {
747 return setDifference(set
, setInsert(theory
));
750 /** Check if the set contains the theory */
751 static inline bool setContains(TheoryId theory
, Set set
) {
752 return set
& (1 << theory
);
755 static inline Set
setComplement(Set a
) {
756 return (~a
) & AllTheories
;
759 static inline Set
setIntersection(Set a
, Set b
) {
763 static inline Set
setUnion(Set a
, Set b
) {
768 static inline Set
setDifference(Set a
, Set b
) {
772 static inline std::string
setToString(theory::Theory::Set theorySet
) {
773 std::stringstream ss
;
775 for(unsigned theoryId
= 0; theoryId
< theory::THEORY_LAST
; ++theoryId
) {
776 if (theory::Theory::setContains((theory::TheoryId
)theoryId
, theorySet
)) {
777 ss
<< (theory::TheoryId
) theoryId
<< " ";
784 typedef context::CDList
<Assertion
>::const_iterator assertions_iterator
;
787 * Provides access to the facts queue, primarily intended for theory
788 * debugging purposes.
790 * @return the iterator to the beginning of the fact queue
792 assertions_iterator
facts_begin() const {
793 return d_facts
.begin();
797 * Provides access to the facts queue, primarily intended for theory
798 * debugging purposes.
800 * @return the iterator to the end of the fact queue
802 assertions_iterator
facts_end() const {
803 return d_facts
.end();
806 * Whether facts have been asserted to this theory.
808 * @return true iff facts have been asserted to this theory.
811 return !d_facts
.empty();
814 typedef context::CDList
<TNode
>::const_iterator shared_terms_iterator
;
817 * Provides access to the shared terms, primarily intended for theory
818 * debugging purposes.
820 * @return the iterator to the beginning of the shared terms list
822 shared_terms_iterator
shared_terms_begin() const {
823 return d_sharedTerms
.begin();
827 * Provides access to the facts queue, primarily intended for theory
828 * debugging purposes.
830 * @return the iterator to the end of the shared terms list
832 shared_terms_iterator
shared_terms_end() const {
833 return d_sharedTerms
.end();
838 * This is a utility function for constructing a copy of the currently shared terms
839 * in a queriable form. As this is
841 std::hash_set
<TNode
, TNodeHashFunction
> currentlySharedTerms() const;
844 * This allows the theory to be queried for whether a literal, lit, is
845 * entailed by the theory. This returns a pair of a Boolean and a node E.
847 * If the Boolean is true, then E is a formula that entails lit and E is propositionally
848 * entailed by the assertions to the theory.
850 * If the Boolean is false, it is "unknown" if lit is entailed and E may be
853 * The literal lit is either an atom a or (not a), which must belong to the theory:
854 * There is some TheoryOfMode m s.t. Theory::theoryOf(m, a) == this->getId().
856 * There are NO assumptions that a or the subterms of a have been
857 * preprocessed in any form. This includes ppRewrite, rewriting,
858 * preregistering, registering, definition expansion or ITE removal!
860 * Theories are free to limit the amount of effort they use and so may
861 * always opt to return "unknown". Both "unknown" and "not entailed",
862 * may return for E a non-boolean Node (e.g. Node::null()). (There is no explicit output
863 * for the negation of lit is entailed.)
865 * If lit is theory valid, the return result may be the Boolean constant
868 * If lit is entailed by multiple assertions on the theory's getFact()
869 * queue, a_1, a_2, ... and a_k, this may return E=(and a_1 a_2 ... a_k) or
870 * another theory entailed explanation E=(and (and a_1 a_2) (and a3 a_4) ... a_k)
872 * If lit is entailed by a single assertion on the theory's getFact()
873 * queue, say a, this may return E=a.
875 * The theory may always return false!
877 * The search is controlled by the parameter params. For default behavior,
878 * this may be left NULL.
880 * Theories that want parameters extend the virtual EntailmentCheckParameters
881 * class. Users ask the theory for an appropriate subclass from the theory
882 * and configure that. How this is implemented is on a per theory basis.
884 * The search may provide additional output to guide the user of
885 * this function. This output is stored in a EntailmentCheckSideEffects*
886 * output parameter. The implementation of this is theory specific. For
887 * no output, this is NULL.
889 * Theories may not touch their output stream during an entailment check.
891 * @param lit a literal belonging to the theory.
892 * @param params the control parameters for the entailment check.
893 * @param out a theory specific output object of the entailment search.
894 * @return a pair <b,E> s.t. if b is true, then a formula E such that
895 * E |= lit in the theory.
897 virtual std::pair
<bool, Node
> entailmentCheck(TNode lit
, const EntailmentCheckParameters
* params
= NULL
, EntailmentCheckSideEffects
* out
= NULL
);
899 /* equality engine TODO: use? */
900 virtual eq::EqualityEngine
* getEqualityEngine() { return NULL
; }
902 /* get extended theory */
903 virtual ExtTheory
* getExtTheory() { return d_extt
; }
905 /* get current substitution at an effort
908 * where ( exp[vars[i]] => vars[i] = subs[i] ) holds for all i
910 virtual bool getCurrentSubstitution( int effort
, std::vector
< Node
>& vars
, std::vector
< Node
>& subs
, std::map
< Node
, std::vector
< Node
> >& exp
) { return false; }
912 /* get reduction for node
913 if return value is not 0, then n is reduced.
914 if return value <0 then n is reduced SAT-context-independently (e.g. by a lemma that persists at this user-context level).
915 if nr is non-null, then ( n = nr ) should be added as a lemma by caller, and return value should be <0.
917 virtual int getReduction( int effort
, Node n
, Node
& nr
) { return 0; }
920 * Turn on proof-production mode.
922 void produceProofs() { d_proofsEnabled
= true; }
926 std::ostream
& operator<<(std::ostream
& os
, theory::Theory::Effort level
);
927 inline std::ostream
& operator<<(std::ostream
& out
, const theory::Assertion
& a
);
929 inline theory::Assertion
Theory::get() {
930 Assert( !done(), "Theory::get() called with assertion queue empty!" );
933 Assertion fact
= d_facts
[d_factsHead
];
934 d_factsHead
= d_factsHead
+ 1;
936 Trace("theory") << "Theory::get() => " << fact
<< " (" << d_facts
.size() - d_factsHead
<< " left)" << std::endl
;
938 if(Dump
.isOn("state")) {
939 Dump("state") << AssertCommand(fact
.assertion
.toExpr());
945 inline std::ostream
& operator<<(std::ostream
& out
, const theory::Assertion
& a
) {
946 return out
<< a
.assertion
;
949 inline std::ostream
& operator<<(std::ostream
& out
,
950 const CVC4::theory::Theory
& theory
) {
951 return out
<< theory
.identify();
954 inline std::ostream
& operator << (std::ostream
& out
, theory::Theory::PPAssertStatus status
) {
956 case theory::Theory::PP_ASSERT_STATUS_SOLVED
:
957 out
<< "SOLVE_STATUS_SOLVED"; break;
958 case theory::Theory::PP_ASSERT_STATUS_UNSOLVED
:
959 out
<< "SOLVE_STATUS_UNSOLVED"; break;
960 case theory::Theory::PP_ASSERT_STATUS_CONFLICT
:
961 out
<< "SOLVE_STATUS_CONFLICT"; break;
968 class EntailmentCheckParameters
{
972 EntailmentCheckParameters(TheoryId tid
);
974 TheoryId
getTheoryId() const;
975 virtual ~EntailmentCheckParameters();
976 };/* class EntailmentCheckParameters */
978 class EntailmentCheckSideEffects
{
982 EntailmentCheckSideEffects(TheoryId tid
);
984 TheoryId
getTheoryId() const;
985 virtual ~EntailmentCheckSideEffects();
986 };/* class EntailmentCheckSideEffects */
991 typedef context::CDHashMap
<Node
, bool, NodeHashFunction
> NodeBoolMap
;
992 typedef context::CDHashSet
<Node
, NodeHashFunction
> NodeSet
;
996 //extended string terms, map to whether they are active
997 NodeBoolMap d_ext_func_terms
;
998 //set of terms from d_ext_func_terms that are SAT-context-independently inactive
999 // (e.g. term t when a reduction lemma of the form t = t' was added)
1000 NodeSet d_ci_inactive
;
1001 //cache of all lemmas sent
1003 NodeSet d_pp_lemmas
;
1004 //watched term for checking if any non-reduced extended functions exist
1005 context::CDO
< Node
> d_has_extf
;
1007 std::map
< Kind
, bool > d_extf_kind
;
1008 //information for each term in d_ext_func_terms
1011 //all variables in this term
1012 std::vector
< Node
> d_vars
;
1014 std::map
< Node
, ExtfInfo
> d_extf_info
;
1016 void collectVars( Node n
, std::vector
< Node
>& vars
, std::map
< Node
, bool >& visited
);
1017 // is context dependent inactive
1018 bool isContextIndependentInactive( Node n
);
1019 //do inferences internal
1020 bool doInferencesInternal( int effort
, std::vector
< Node
>& terms
, std::vector
< Node
>& nred
, bool batch
, bool isRed
);
1022 bool sendLemma( Node lem
, bool preprocess
= false );
1023 //register term (recursive)
1024 void registerTermRec( Node n
, std::map
< Node
, bool >& visited
);
1026 ExtTheory( Theory
* p
);
1027 virtual ~ExtTheory(){}
1029 void addFunctionKind( Kind k
) { d_extf_kind
[k
] = true; }
1030 bool hasFunctionKind( Kind k
) { return d_extf_kind
.find( k
)!=d_extf_kind
.end(); }
1032 // adds n to d_ext_func_terms if addFunctionKind( n.getKind() ) was called
1033 void registerTerm( Node n
);
1034 void registerTermRec( Node n
);
1035 // set n as reduced/inactive
1036 // if contextDepend = false, then n remains inactive in the duration of this user-context level
1037 void markReduced( Node n
, bool contextDepend
= true );
1038 // mark that a and b are congruent terms: set b inactive, set a to inactive if b was inactive
1039 void markCongruent( Node a
, Node b
);
1041 //getSubstitutedTerms
1042 // input : effort, terms
1043 // output : sterms, exp, where ( exp[i] => terms[i] = sterms[i] ) for all i
1044 void getSubstitutedTerms( int effort
, std::vector
< Node
>& terms
, std::vector
< Node
>& sterms
, std::vector
< std::vector
< Node
> >& exp
);
1046 // * input : effort, terms, batch (whether to send one lemma or lemmas for all terms)
1047 // * sends rewriting lemmas of the form ( exp => t = c ) where t is in terms and c is a constant, c = rewrite( t*sigma ) where exp |= sigma
1048 // * output : nred (the terms that are still active)
1049 // * return : true iff lemma is sent
1050 bool doInferences( int effort
, std::vector
< Node
>& terms
, std::vector
< Node
>& nred
, bool batch
=true );
1051 bool doInferences( int effort
, std::vector
< Node
>& nred
, bool batch
=true );
1053 // same as doInferences, but will send reduction lemmas of the form ( t = t' ) where t is in terms, t' is equivalent, reduced term
1054 bool doReductions( int effort
, std::vector
< Node
>& terms
, std::vector
< Node
>& nred
, bool batch
=true );
1055 bool doReductions( int effort
, std::vector
< Node
>& nred
, bool batch
=true );
1058 bool hasActiveTerm();
1060 bool isActive( Node n
);
1061 //get the set of active terms from d_ext_func_terms
1062 void getActive( std::vector
< Node
>& active
);
1063 //get the set of active terms from d_ext_func_terms of kind k
1064 void getActive( std::vector
< Node
>& active
, Kind k
);
1067 }/* CVC4::theory namespace */
1068 }/* CVC4 namespace */
1070 #endif /* __CVC4__THEORY__THEORY_H */