Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * This file is part of the cvc5 project. 3 : : * 4 : : * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS 5 : : * in the top-level source directory and their institutional affiliations. 6 : : * All rights reserved. See the file COPYING in the top-level source 7 : : * directory for licensing information. 8 : : * **************************************************************************** 9 : : * 10 : : * A theory state for Theory. 11 : : */ 12 : : 13 : : #include "cvc5_private.h" 14 : : 15 : : #ifndef CVC5__THEORY__THEORY_STATE_H 16 : : #define CVC5__THEORY__THEORY_STATE_H 17 : : 18 : : #include "context/cdo.h" 19 : : #include "expr/node.h" 20 : : #include "smt/env.h" 21 : : #include "smt/env_obj.h" 22 : : #include "theory/valuation.h" 23 : : 24 : : namespace cvc5::internal { 25 : : namespace theory { 26 : : 27 : : namespace eq { 28 : : class EqualityEngine; 29 : : } 30 : : 31 : : class TheoryState : protected EnvObj 32 : : { 33 : : public: 34 : : TheoryState(Env& env, Valuation val); 35 : 662774 : virtual ~TheoryState() {} 36 : : /** 37 : : * Set equality engine, where ee is a pointer to the official equality engine 38 : : * of theory. 39 : : */ 40 : : void setEqualityEngine(eq::EqualityEngine* ee); 41 : : //-------------------------------------- equality information 42 : : /** Is t registered as a term in the equality engine of this class? */ 43 : : virtual bool hasTerm(TNode t) const; 44 : : /** Add term t to the equality engine if it is not registered */ 45 : : virtual void addTerm(TNode t); 46 : : /** 47 : : * Get the representative of t in the equality engine of this class, or t 48 : : * itself if it is not registered as a term. 49 : : */ 50 : : virtual TNode getRepresentative(TNode t) const; 51 : : /** 52 : : * Are a and b equal according to the equality engine of this class? Also 53 : : * returns true if a and b are identical. 54 : : */ 55 : : virtual bool areEqual(TNode a, TNode b) const; 56 : : /** 57 : : * Are a and b disequal according to the equality engine of this class? Also 58 : : * returns true if the representative of a and b are distinct constants. 59 : : */ 60 : : virtual bool areDisequal(TNode a, TNode b) const; 61 : : /** 62 : : * Get the explanation for why a and b are disequal, store it in exp. This 63 : : * assumes that areDisequal(a,b) returns true in the current context and 64 : : * ensures the equality engine has a proof of what it is in exp. 65 : : */ 66 : : void explainDisequal(TNode a, TNode b, std::vector<Node>& exp); 67 : : /** get list of members in the equivalence class of a */ 68 : : virtual void getEquivalenceClass(Node a, std::vector<Node>& eqc) const; 69 : : /** 70 : : * Add pred as a trigger predicate to the equality engine of the theory 71 : : * that owns this state. If the option prereg-check-sat-assert is true, 72 : : * this first checks whether pred has already been asserted. If so, then 73 : : * the trigger is not added. In this care, pred is added as a non-trigger 74 : : * term to the equality engine instead. 75 : : */ 76 : : void addEqualityEngineTriggerPredicate(TNode pred); 77 : : /** get equality engine */ 78 : : eq::EqualityEngine* getEqualityEngine() const; 79 : : //-------------------------------------- end equality information 80 : : /** 81 : : * Set that the current state of the solver is in conflict. This should be 82 : : * called immediately after a call to conflict(...) on the output channel of 83 : : * the theory. 84 : : */ 85 : : virtual void notifyInConflict(); 86 : : /** Are we currently in conflict? */ 87 : : virtual bool isInConflict() const; 88 : : 89 : : /** Returns true if lit is a SAT literal. */ 90 : : virtual bool isSatLiteral(TNode lit) const; 91 : : /** 92 : : * Returns pointer to model. This model is only valid during last call effort 93 : : * check. 94 : : */ 95 : : TheoryModel* getModel(); 96 : : /** 97 : : * Returns a pointer to the sort inference module, which lives in TheoryEngine 98 : : * and is non-null when options::sortInference is true. 99 : : */ 100 : : SortInference* getSortInference(); 101 : : 102 : : /** Returns true if n has a current SAT assignment and stores it in value. */ 103 : : virtual bool hasSatValue(TNode n, bool& value) const; 104 : : 105 : : //------------------------------------------- access methods for assertions 106 : : /** 107 : : * The following methods are intended only to be used in limited use cases, 108 : : * for cases where a theory (e.g. quantifiers) requires knowing about the 109 : : * assertions from other theories. 110 : : */ 111 : : /** The beginning iterator of facts for theory tid.*/ 112 : : context::CDList<Assertion>::const_iterator factsBegin(TheoryId tid); 113 : : /** The beginning iterator of facts for theory tid.*/ 114 : : context::CDList<Assertion>::const_iterator factsEnd(TheoryId tid); 115 : : 116 : : /** Get the underlying valuation class */ 117 : : Valuation& getValuation(); 118 : : 119 : : //------------------------------------------- access methods for shared terms 120 : : /** Add shared term, called by Theory. */ 121 : : void addSharedTerm(TNode node); 122 : : 123 : : using shared_terms_iterator = context::CDList<TNode>::const_iterator; 124 : : /** 125 : : * Provides access to the shared terms, primarily intended for theory 126 : : * debugging purposes. 127 : : * 128 : : * @return the iterator to the beginning of the shared terms list 129 : : */ 130 : 797235 : shared_terms_iterator shared_terms_begin() const 131 : : { 132 : 797235 : return d_sharedTerms.begin(); 133 : : } 134 : : 135 : : /** 136 : : * Provides access to the facts queue, primarily intended for theory 137 : : * debugging purposes. 138 : : * 139 : : * @return the iterator to the end of the shared terms list 140 : : */ 141 : 797235 : shared_terms_iterator shared_terms_end() const { return d_sharedTerms.end(); } 142 : : /** Get shared terms */ 143 : 140861 : const context::CDList<TNode>& getSharedTerms() const { return d_sharedTerms; } 144 : : 145 : : protected: 146 : : /** 147 : : * The valuation proxy for the Theory to communicate back with the 148 : : * theory engine (and other theories). 149 : : */ 150 : : Valuation d_valuation; 151 : : /** Pointer to equality engine of the theory. */ 152 : : eq::EqualityEngine* d_ee; 153 : : /** Are we in conflict? */ 154 : : context::CDO<bool> d_conflict; 155 : : /** 156 : : * A list of shared terms that the theory has. 157 : : */ 158 : : context::CDList<TNode> d_sharedTerms; 159 : : }; 160 : : 161 : : } // namespace theory 162 : : } // namespace cvc5::internal 163 : : 164 : : #endif /* CVC5__THEORY__SOLVER_STATE_H */