1 /********************* */
4 ** Top contributors (to current version):
5 ** Andrew Reynolds, Morgan Deters, Dejan Jovanovic
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"
33 #include "options/options.h"
34 #include "options/theory_options.h"
35 #include "smt/logic_request.h"
36 #include "theory/assertion.h"
37 #include "theory/care_graph.h"
38 #include "theory/decision_manager.h"
39 #include "theory/ee_setup_info.h"
40 #include "theory/logic_info.h"
41 #include "theory/output_channel.h"
42 #include "theory/theory_id.h"
43 #include "theory/theory_inference_manager.h"
44 #include "theory/theory_rewriter.h"
45 #include "theory/theory_state.h"
46 #include "theory/trust_node.h"
47 #include "theory/trust_substitutions.h"
48 #include "theory/valuation.h"
49 #include "util/statistics_registry.h"
54 class ProofNodeManager
;
58 class QuantifiersEngine
;
60 class SubstitutionMap
;
64 class CandidateGenerator
;
65 }/* CVC4::theory::rrinst namespace */
69 }/* CVC4::theory::eq namespace */
72 * Base class for T-solvers. Abstract DPLL(T).
74 * This is essentially an interface class. The TheoryEngine has
75 * pointers to Theory. Note that only one specific Theory type (e.g.,
76 * TheoryUF) can exist per NodeManager, because of how the
77 * RegisteredAttr works. (If you need multiple instances of the same
78 * theory, you'll have to write a multiplexed theory that dispatches
81 * NOTE: A Theory has a special way of being initialized. The owner of a Theory
84 * (A) Using Theory as a standalone object, not associated with a TheoryEngine.
85 * In this case, simply call the public initialization method
86 * (Theory::finishInitStandalone).
88 * (B) TheoryEngine, which determines how the Theory acts in accordance with
89 * its theory combination policy. We require the following steps in order:
90 * (B.1) Get information about whether the theory wishes to use an equality
91 * eninge, and more specifically which equality engine notifications the Theory
92 * would like to be notified of (Theory::needsEqualityEngine).
93 * (B.2) Set the equality engine of the theory (Theory::setEqualityEngine),
94 * which we refer to as the "official equality engine" of this Theory. The
95 * equality engine passed to the theory must respect the contract(s) specified
96 * by the equality engine setup information (EeSetupInfo) returned in the
98 * (B.3) Set the other required utilities including setQuantifiersEngine and
100 * (B.4) Call the private initialization method (Theory::finishInit).
102 * Initialization of the second form happens during TheoryEngine::finishInit,
103 * after the quantifiers engine and model objects have been set up.
106 friend class ::CVC4::TheoryEngine
;
109 // Disallow default construction, copy, assignment.
111 Theory(const Theory
&) = delete;
112 Theory
& operator=(const Theory
&) = delete;
114 /** An integer identifying the type of the theory. */
117 /** The SAT search context for the Theory. */
118 context::Context
* d_satContext
;
120 /** The user level assertion context for the Theory. */
121 context::UserContext
* d_userContext
;
123 /** Information about the logic we're operating within. */
124 const LogicInfo
& d_logicInfo
;
127 * The assertFact() queue.
129 * These can not be TNodes as some atoms (such as equalities) are sent
130 * across theories without being stored in a global map.
132 context::CDList
<Assertion
> d_facts
;
134 /** Index into the head of the facts list */
135 context::CDO
<unsigned> d_factsHead
;
137 /** Indices for splitting on the shared terms. */
138 context::CDO
<unsigned> d_sharedTermsIndex
;
140 /** The care graph the theory will use during combination. */
141 CareGraph
* d_careGraph
;
144 * Pointer to the quantifiers engine (or NULL, if quantifiers are not
145 * supported or not enabled). Not owned by the theory.
147 QuantifiersEngine
* d_quantEngine
;
149 /** Pointer to the decision manager. */
150 DecisionManager
* d_decManager
;
153 /** Name of this theory instance. Along with the TheoryId this should provide
154 * an unique string identifier for each instance of a Theory class. We need
155 * this to ensure unique statistics names over multiple theory instances. */
156 std::string d_instanceName
;
158 // === STATISTICS ===
159 /** time spent in check calls */
160 TimerStat d_checkTime
;
161 /** time spent in theory combination */
162 TimerStat d_computeCareGraphTime
;
165 * The only method to add suff to the care graph.
167 void addCarePair(TNode t1
, TNode t2
);
170 * The function should compute the care graph over the shared terms.
171 * The default function returns all the pairs among the shared variables.
173 virtual void computeCareGraph();
176 * A list of shared terms that the theory has.
178 context::CDList
<TNode
> d_sharedTerms
;
181 * Construct a Theory.
183 * The pair <id, instance> is assumed to uniquely identify this Theory
184 * w.r.t. the SmtEngine.
187 context::Context
* satContext
,
188 context::UserContext
* userContext
,
191 const LogicInfo
& logicInfo
,
192 ProofNodeManager
* pnm
,
193 std::string instance
= ""); // taking : No default.
196 * This is called at shutdown time by the TheoryEngine, just before
197 * destruction. It is important because there are destruction
198 * ordering issues between PropEngine and Theory (based on what
199 * hard-links to Nodes are outstanding). As the fact queue might be
200 * nonempty, we ensure here that it's clear. If you overload this,
201 * you must make an explicit call here to this->Theory::shutdown()
204 virtual void shutdown() { }
207 * The output channel for the Theory.
209 OutputChannel
* d_out
;
212 * The valuation proxy for the Theory to communicate back with the
213 * theory engine (and other theories).
215 Valuation d_valuation
;
217 * Pointer to the official equality engine of this theory, which is owned by
218 * the equality engine manager of TheoryEngine.
220 eq::EqualityEngine
* d_equalityEngine
;
222 * The official equality engine, if we allocated it.
224 std::unique_ptr
<eq::EqualityEngine
> d_allocEqualityEngine
;
226 * The theory state, which contains contexts, valuation, and equality engine.
227 * Notice the theory is responsible for memory management of this class.
229 TheoryState
* d_theoryState
;
231 * The theory inference manager. This is a wrapper around the equality
232 * engine and the output channel. It ensures that the output channel and
233 * the equality engine are used properly.
235 TheoryInferenceManager
* d_inferManager
;
237 /** Pointer to proof node manager */
238 ProofNodeManager
* d_pnm
;
241 * Are proofs enabled?
243 * They are considered enabled if the ProofNodeManager is non-null.
245 bool proofsEnabled() const;
248 * Returns the next assertion in the assertFact() queue.
250 * @return the next assertion in the assertFact() queue
252 inline Assertion
get();
254 const LogicInfo
& getLogicInfo() const {
259 * Set separation logic heap. This is called when the location and data
260 * types for separation logic are determined. This should be called at
261 * most once, before solving.
263 * This currently should be overridden by the separation logic theory only.
265 virtual void declareSepHeap(TypeNode locT
, TypeNode dataT
) {}
268 * The theory that owns the uninterpreted sort.
270 static TheoryId s_uninterpretedSortOwner
;
272 void printFacts(std::ostream
& os
) const;
273 void debugPrintFacts() const;
275 /** is legal elimination
277 * Returns true if x -> val is a legal elimination of variable x. This is
278 * useful for ppAssert, when x = val is an entailed equality. This function
279 * determines whether indeed x can be eliminated from the problem via the
280 * substituion x -> val.
282 * The following criteria imply that x -> val is *not* a legal elimination:
283 * (1) If x is contained in val,
284 * (2) If the type of val is not a subtype of the type of x,
285 * (3) If val contains an operator that cannot be evaluated, and produceModels
286 * is true. For example, x -> sqrt(2) is not a legal elimination if we
287 * are producing models. This is because we care about the value of x, and
288 * its value must be computed (approximated) by the non-linear solver.
290 bool isLegalElimination(TNode x
, TNode val
);
291 //--------------------------------- private initialization
293 * Called to set the official equality engine. This should be done by
296 void setEqualityEngine(eq::EqualityEngine
* ee
);
297 /** Called to set the quantifiers engine. */
298 void setQuantifiersEngine(QuantifiersEngine
* qe
);
299 /** Called to set the decision manager. */
300 void setDecisionManager(DecisionManager
* dm
);
302 * Finish theory initialization. At this point, options and the logic
303 * setting are final, the master equality engine and quantifiers
304 * engine (if any) are initialized, and the official equality engine of this
305 * theory has been assigned. This base class implementation
306 * does nothing. This should be called by TheoryEngine only.
308 virtual void finishInit() {}
309 //--------------------------------- end private initialization
312 * This method is called to notify a theory that the node n should
313 * be considered a "shared term" by this theory. This does anything
314 * theory-specific concerning the fact that n is now marked as a shared
315 * term, which is done in addition to explicitly storing n as a shared
316 * term and adding it as a trigger term in the equality engine of this
317 * class (see addSharedTerm).
319 virtual void notifySharedTerm(TNode n
);
322 //--------------------------------- initialization
324 * @return The theory rewriter associated with this theory.
326 virtual TheoryRewriter
* getTheoryRewriter() = 0;
328 * Returns true if this theory needs an equality engine for checking
331 * If this method returns true, then the equality engine manager will
332 * initialize its equality engine field via setEqualityEngine above during
333 * TheoryEngine::finishInit, prior to calling finishInit for this theory.
335 * Additionally, if this method returns true, then this method is required to
336 * update the argument esi with instructions for initializing and setting up
337 * notifications from its equality engine, which is commonly done with
338 * a notifications class (eq::EqualityEngineNotify).
340 virtual bool needsEqualityEngine(EeSetupInfo
& esi
);
342 * Finish theory initialization, standalone version. This is used to
343 * initialize this class if it is not associated with a theory engine.
344 * This allocates the official equality engine of this Theory and then
345 * calls the finishInit method above.
347 void finishInitStandalone();
348 //--------------------------------- end initialization
351 * Return the ID of the theory responsible for the given type.
353 static inline TheoryId
theoryOf(TypeNode typeNode
) {
354 Trace("theory::internal") << "theoryOf(" << typeNode
<< ")" << std::endl
;
356 if (typeNode
.getKind() == kind::TYPE_CONSTANT
) {
357 id
= typeConstantToTheoryId(typeNode
.getConst
<TypeConstant
>());
359 id
= kindToTheoryId(typeNode
.getKind());
361 if (id
== THEORY_BUILTIN
) {
362 Trace("theory::internal") << "theoryOf(" << typeNode
<< ") == " << s_uninterpretedSortOwner
<< std::endl
;
363 return s_uninterpretedSortOwner
;
369 * Returns the ID of the theory responsible for the given node.
371 static TheoryId
theoryOf(options::TheoryOfMode mode
, TNode node
);
374 * Returns the ID of the theory responsible for the given node.
376 static inline TheoryId
theoryOf(TNode node
) {
377 return theoryOf(options::theoryOfMode(), node
);
381 * Set the owner of the uninterpreted sort.
383 static void setUninterpretedSortOwner(TheoryId theory
) {
384 s_uninterpretedSortOwner
= theory
;
388 * Get the owner of the uninterpreted sort.
390 static TheoryId
getUninterpretedSortOwner() {
391 return s_uninterpretedSortOwner
;
395 * Checks if the node is a leaf node of this theory
397 inline bool isLeaf(TNode node
) const {
398 return node
.getNumChildren() == 0 || theoryOf(node
) != d_id
;
402 * Checks if the node is a leaf node of a theory.
404 inline static bool isLeafOf(TNode node
, TheoryId theoryId
) {
405 return node
.getNumChildren() == 0 || theoryOf(node
) != theoryId
;
408 /** Returns true if the assertFact queue is empty*/
409 bool done() const { return d_factsHead
== d_facts
.size(); }
411 * Destructs a Theory.
416 * Subclasses of Theory may add additional efforts. DO NOT CHECK
417 * equality with one of these values (e.g. if STANDARD xxx) but
418 * rather use range checks (or use the helper functions below).
419 * Normally we call QUICK_CHECK or STANDARD; at the leaves we call
425 * Standard effort where theory need not do anything
427 EFFORT_STANDARD
= 50,
429 * Full effort requires the theory make sure its assertions are satisfiable
434 * Last call effort, called after theory combination has completed with
435 * no lemmas and a model is available.
437 EFFORT_LAST_CALL
= 200
440 static inline bool standardEffortOrMore(Effort e
) CVC4_CONST_FUNCTION
441 { return e
>= EFFORT_STANDARD
; }
442 static inline bool standardEffortOnly(Effort e
) CVC4_CONST_FUNCTION
443 { return e
>= EFFORT_STANDARD
&& e
< EFFORT_FULL
; }
444 static inline bool fullEffort(Effort e
) CVC4_CONST_FUNCTION
445 { return e
== EFFORT_FULL
; }
448 * Get the id for this Theory.
450 TheoryId
getId() const {
455 * Get the SAT context associated to this Theory.
457 context::Context
* getSatContext() const {
462 * Get the context associated to this Theory.
464 context::UserContext
* getUserContext() const {
465 return d_userContext
;
469 * Set the output channel associated to this theory.
471 void setOutputChannel(OutputChannel
& out
) {
476 * Get the output channel associated to this theory.
478 OutputChannel
& getOutputChannel() {
483 * Get the valuation associated to this theory.
485 Valuation
& getValuation() {
489 /** Get the equality engine being used by this theory. */
490 eq::EqualityEngine
* getEqualityEngine();
493 * Get the quantifiers engine associated to this theory.
495 QuantifiersEngine
* getQuantifiersEngine() {
496 return d_quantEngine
;
499 /** Get the decision manager associated to this theory. */
500 DecisionManager
* getDecisionManager() { return d_decManager
; }
503 * @return The theory state associated with this theory.
505 TheoryState
* getTheoryState() { return d_theoryState
; }
508 * @return The theory inference manager associated with this theory.
510 TheoryInferenceManager
* getInferenceManager() { return d_inferManager
; }
513 * Expand definitions in the term node. This returns a term that is
514 * equivalent to node. It wraps this term in a TrustNode of kind
515 * TrustNodeKind::REWRITE. If node is unchanged by this method, the
516 * null TrustNode may be returned. This is an optimization to avoid
517 * constructing the trivial equality (= node node) internally within
520 * The purpose of this method is typically to eliminate the operators in node
521 * that are syntax sugar that cannot otherwise be eliminated during rewriting.
522 * For example, division relies on the introduction of an uninterpreted
523 * function for the divide-by-zero case, which we do not introduce with
524 * the rewriter, since this function may be cached in a non-global fashion.
526 * Some theories have kinds that are effectively definitions and should be
527 * expanded before they are handled. Definitions allow a much wider range of
528 * actions than the normal forms given by the rewriter. However no
529 * assumptions can be made about subterms having been expanded or rewritten.
530 * Where possible rewrite rules should be used, definitions should only be
531 * used when rewrites are not possible, for example in handling
532 * under-specified operations using partially defined functions.
534 * Some theories like sets use expandDefinition as a "context
535 * independent preRegisterTerm". This is required for cases where
536 * a theory wants to be notified about a term before preprocessing
537 * and simplification but doesn't necessarily want to rewrite it.
539 virtual TrustNode
expandDefinition(Node node
)
541 // by default, do nothing
542 return TrustNode::null();
546 * Pre-register a term. Done one time for a Node per SAT context level.
548 virtual void preRegisterTerm(TNode
);
551 * Assert a fact in the current context.
553 void assertFact(TNode assertion
, bool isPreregistered
) {
554 Trace("theory") << "Theory<" << getId() << ">::assertFact["
555 << d_satContext
->getLevel() << "](" << assertion
<< ", "
556 << (isPreregistered
? "true" : "false") << ")" << std::endl
;
557 d_facts
.push_back(Assertion(assertion
, isPreregistered
));
560 /** Add shared term to the theory. */
561 void addSharedTerm(TNode node
);
564 * Return the current theory care graph. Theories should overload
565 * computeCareGraph to do the actual computation, and use addCarePair to add
566 * pairs to the care graph.
568 void getCareGraph(CareGraph
* careGraph
);
571 * Return the status of two terms in the current context. Should be
572 * implemented in sub-theories to enable more efficient theory-combination.
574 virtual EqualityStatus
getEqualityStatus(TNode a
, TNode b
);
577 * Return the model value of the give shared term (or null if not available).
579 * TODO (project #39): this method is likely to become deprecated.
581 virtual Node
getModelValue(TNode var
) { return Node::null(); }
583 /** T-propagate new literal assignments in the current context. */
584 virtual void propagate(Effort level
= EFFORT_FULL
) {}
587 * Return an explanation for the literal represented by parameter n
588 * (which was previously propagated by this theory).
590 virtual TrustNode
explain(TNode n
)
592 Unimplemented() << "Theory " << identify()
593 << " propagated a node but doesn't implement the "
594 "Theory::explain() interface!";
595 return TrustNode::null();
598 //--------------------------------- check
600 * Does this theory wish to be called to check at last call effort? This is
601 * the case for any theory that wishes to run when a model is available.
603 virtual bool needsCheckLastEffort() { return false; }
605 * Check the current assignment's consistency.
607 * An implementation of check() is required to either:
608 * - return a conflict on the output channel,
610 * - throw an exception
611 * - or call get() until done() is true.
613 * The standard method for check consists of a loop that processes the entire
614 * fact queue when preCheck returns false. It makes four theory-specific
615 * callbacks, (preCheck, postCheck, preNotifyFact, notifyFact) as described
616 * below. It asserts each fact to the official equality engine when
617 * preNotifyFact returns false.
619 * Theories that use this check method must use an official theory
620 * state object (d_theoryState).
622 void check(Effort level
= EFFORT_FULL
);
624 * Pre-check, called before the fact queue of the theory is processed.
625 * If this method returns false, then the theory will process its fact
626 * queue. If this method returns true, then the theory has indicated
627 * its check method should finish immediately.
629 virtual bool preCheck(Effort level
= EFFORT_FULL
);
631 * Post-check, called after the fact queue of the theory is processed.
633 virtual void postCheck(Effort level
= EFFORT_FULL
);
635 * Pre-notify fact, return true if the theory processed it. If this
636 * method returns false, then the atom will be added to the equality engine
637 * of the theory and notifyFact will be called with isInternal=false.
639 * Theories that implement check but do not use official equality
640 * engines should always return true for this method.
642 * @param atom The atom
643 * @param polarity Its polarity
644 * @param fact The original literal that was asserted
645 * @param isPrereg Whether the assertion is preregistered
646 * @param isInternal Whether the origin of the fact was internal. If this
647 * is false, the fact was asserted via the fact queue of the theory.
648 * @return true if the theory completely processed this fact, i.e. it does
649 * not need to assert the fact to its equality engine.
651 virtual bool preNotifyFact(
652 TNode atom
, bool pol
, TNode fact
, bool isPrereg
, bool isInternal
);
654 * Notify fact, called immediately after the fact was pushed into the
657 * @param atom The atom
658 * @param polarity Its polarity
659 * @param fact The original literal that was asserted.
660 * @param isInternal Whether the origin of the fact was internal. If this
661 * is false, the fact was asserted via the fact queue of the theory.
663 virtual void notifyFact(TNode atom
, bool pol
, TNode fact
, bool isInternal
);
664 //--------------------------------- end check
666 //--------------------------------- collect model info
668 * Get all relevant information in this theory regarding the current
669 * model. This should be called after a call to check( FULL_EFFORT )
670 * for all theories with no conflicts and no lemmas added.
672 * This method returns true if and only if the equality engine of m is
673 * consistent as a result of this call.
675 * The standard method for collectModelInfo computes the relevant terms,
676 * asserts the theory's equality engine to the model (if necessary) and
677 * then calls computeModelValues.
679 * TODO (project #39): this method should be non-virtual, once all theories
680 * conform to the new standard, delete, move to model manager distributed.
682 virtual bool collectModelInfo(TheoryModel
* m
, const std::set
<Node
>& termSet
);
684 * Compute terms that are not necessarily part of the assertions or
685 * shared terms that should be considered relevant, add them to termSet.
687 virtual void computeRelevantTerms(std::set
<Node
>& termSet
);
689 * Collect model values, after equality information is added to the model.
690 * The argument termSet is the set of relevant terms returned by
691 * computeRelevantTerms.
693 virtual bool collectModelValues(TheoryModel
* m
,
694 const std::set
<Node
>& termSet
);
695 /** if theories want to do something with model after building, do it here */
696 virtual void postProcessModel( TheoryModel
* m
){ }
697 //--------------------------------- end collect model info
699 //--------------------------------- preprocessing
701 * Statically learn from assertion "in," which has been asserted
702 * true at the top level. The theory should only add (via
703 * ::operator<< or ::append()) to the "learned" builder---it should
704 * *never* clear it. It is a conjunction to add to the formula at
705 * the top-level and may contain other theories' contributions.
707 virtual void ppStaticLearn(TNode in
, NodeBuilder
<>& learned
) { }
709 enum PPAssertStatus
{
710 /** Atom has been solved */
711 PP_ASSERT_STATUS_SOLVED
,
712 /** Atom has not been solved */
713 PP_ASSERT_STATUS_UNSOLVED
,
714 /** Atom is inconsistent */
715 PP_ASSERT_STATUS_CONFLICT
719 * Given a literal and its proof generator (encapsulated by trust node tin),
720 * add the solved substitutions to the map, if any. The method should return
721 * true if the literal can be safely removed from the input problem.
723 * Note that tin has trude node kind LEMMA. Its proof generator should be
724 * take into account when adding a substitution to outSubstitutions when
725 * proofs are enabled.
727 virtual PPAssertStatus
ppAssert(TrustNode tin
,
728 TrustSubstitutionMap
& outSubstitutions
);
731 * Given a term of the theory coming from the input formula or
732 * from a lemma generated during solving, this method can be overridden in a
733 * theory implementation to rewrite the term into an equivalent form.
735 * This method returns a TrustNode of kind TrustNodeKind::REWRITE, which
736 * carries information about the proof generator for the rewrite, which can
737 * be the null TrustNode if n is unchanged.
739 * Notice this method is used both in the "theory rewrite equalities"
740 * preprocessing pass, where n is an equality from the input formula,
741 * and in theory preprocessing, where n is a (non-equality) term occurring
742 * in the input or generated in a lemma.
744 virtual TrustNode
ppRewrite(TNode n
) { return TrustNode::null(); }
747 * Notify preprocessed assertions. Called on new assertions after
748 * preprocessing before they are asserted to theory engine.
750 virtual void ppNotifyAssertions(const std::vector
<Node
>& assertions
) {}
751 //--------------------------------- end preprocessing
754 * A Theory is called with presolve exactly one time per user
755 * check-sat. presolve() is called after preregistration,
756 * rewriting, and Boolean propagation, (other theories'
757 * propagation?), but the notified Theory has not yet had its
758 * check() or propagate() method called. A Theory may empty its
759 * assertFact() queue using get(). A Theory can raise conflicts,
760 * add lemmas, and propagate literals during presolve().
762 * NOTE: The presolve property must be added to the kinds file for
765 virtual void presolve() { }
768 * A Theory is called with postsolve exactly one time per user
769 * check-sat. postsolve() is called after the query has completed
770 * (regardless of whether sat, unsat, or unknown), and after any
771 * model-querying related to the query has been performed.
772 * After this call, the theory will not get another check() or
773 * propagate() call until presolve() is called again. A Theory
774 * cannot raise conflicts, add lemmas, or propagate literals during
777 virtual void postsolve() { }
780 * Notification sent to the theory wheneven the search restarts.
781 * Serves as a good time to do some clean-up work, and you can
782 * assume you're at DL 0 for the purposes of Contexts. This function
783 * should not use the output channel.
785 virtual void notifyRestart() { }
788 * Identify this theory (for debugging, dynamic configuration,
791 virtual std::string
identify() const = 0;
793 /** Set user attribute
794 * This function is called when an attribute is set by a user. In SMT-LIBv2 this is done
795 * via the syntax (! n :attr)
797 virtual void setUserAttribute(const std::string
& attr
, Node n
, std::vector
<Node
> node_values
, std::string str_value
) {
798 Unimplemented() << "Theory " << identify()
799 << " doesn't support Theory::setUserAttribute interface";
802 typedef context::CDList
<Assertion
>::const_iterator assertions_iterator
;
805 * Provides access to the facts queue, primarily intended for theory
806 * debugging purposes.
808 * @return the iterator to the beginning of the fact queue
810 assertions_iterator
facts_begin() const {
811 return d_facts
.begin();
815 * Provides access to the facts queue, primarily intended for theory
816 * debugging purposes.
818 * @return the iterator to the end of the fact queue
820 assertions_iterator
facts_end() const {
821 return d_facts
.end();
824 * Whether facts have been asserted to this theory.
826 * @return true iff facts have been asserted to this theory.
828 bool hasFacts() { return !d_facts
.empty(); }
830 /** Return total number of facts asserted to this theory */
831 size_t numAssertions() {
832 return d_facts
.size();
835 typedef context::CDList
<TNode
>::const_iterator shared_terms_iterator
;
838 * Provides access to the shared terms, primarily intended for theory
839 * debugging purposes.
841 * @return the iterator to the beginning of the shared terms list
843 shared_terms_iterator
shared_terms_begin() const {
844 return d_sharedTerms
.begin();
848 * Provides access to the facts queue, primarily intended for theory
849 * debugging purposes.
851 * @return the iterator to the end of the shared terms list
853 shared_terms_iterator
shared_terms_end() const {
854 return d_sharedTerms
.end();
859 * This is a utility function for constructing a copy of the currently shared terms
860 * in a queriable form. As this is
862 std::unordered_set
<TNode
, TNodeHashFunction
> currentlySharedTerms() const;
865 * This allows the theory to be queried for whether a literal, lit, is
866 * entailed by the theory. This returns a pair of a Boolean and a node E.
868 * If the Boolean is true, then E is a formula that entails lit and E is propositionally
869 * entailed by the assertions to the theory.
871 * If the Boolean is false, it is "unknown" if lit is entailed and E may be
874 * The literal lit is either an atom a or (not a), which must belong to the theory:
875 * There is some TheoryOfMode m s.t. Theory::theoryOf(m, a) == this->getId().
877 * There are NO assumptions that a or the subterms of a have been
878 * preprocessed in any form. This includes ppRewrite, rewriting,
879 * preregistering, registering, definition expansion or ITE removal!
881 * Theories are free to limit the amount of effort they use and so may
882 * always opt to return "unknown". Both "unknown" and "not entailed",
883 * may return for E a non-boolean Node (e.g. Node::null()). (There is no explicit output
884 * for the negation of lit is entailed.)
886 * If lit is theory valid, the return result may be the Boolean constant
889 * If lit is entailed by multiple assertions on the theory's getFact()
890 * queue, a_1, a_2, ... and a_k, this may return E=(and a_1 a_2 ... a_k) or
891 * another theory entailed explanation E=(and (and a_1 a_2) (and a3 a_4) ... a_k)
893 * If lit is entailed by a single assertion on the theory's getFact()
894 * queue, say a, this may return E=a.
896 * The theory may always return false!
898 * Theories may not touch their output stream during an entailment check.
900 * @param lit a literal belonging to the theory.
901 * @return a pair <b,E> s.t. if b is true, then a formula E such that
902 * E |= lit in the theory.
904 virtual std::pair
<bool, Node
> entailmentCheck(TNode lit
);
907 std::ostream
& operator<<(std::ostream
& os
, theory::Theory::Effort level
);
910 inline theory::Assertion
Theory::get() {
911 Assert(!done()) << "Theory::get() called with assertion queue empty!";
914 Assertion fact
= d_facts
[d_factsHead
];
915 d_factsHead
= d_factsHead
+ 1;
917 Trace("theory") << "Theory::get() => " << fact
<< " (" << d_facts
.size() - d_factsHead
<< " left)" << std::endl
;
922 inline std::ostream
& operator<<(std::ostream
& out
,
923 const CVC4::theory::Theory
& theory
) {
924 return out
<< theory
.identify();
927 inline std::ostream
& operator << (std::ostream
& out
, theory::Theory::PPAssertStatus status
) {
929 case theory::Theory::PP_ASSERT_STATUS_SOLVED
:
930 out
<< "SOLVE_STATUS_SOLVED"; break;
931 case theory::Theory::PP_ASSERT_STATUS_UNSOLVED
:
932 out
<< "SOLVE_STATUS_UNSOLVED"; break;
933 case theory::Theory::PP_ASSERT_STATUS_CONFLICT
:
934 out
<< "SOLVE_STATUS_CONFLICT"; break;
941 }/* CVC4::theory namespace */
942 }/* CVC4 namespace */
944 #endif /* CVC4__THEORY__THEORY_H */