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 "valuation" proxy for TheoryEngine. 11 : : */ 12 : : 13 : : #include "theory/valuation.h" 14 : : 15 : : #include "expr/node.h" 16 : : #include "options/theory_options.h" 17 : : #include "prop/prop_engine.h" 18 : : #include "theory/assertion.h" 19 : : #include "theory/rewriter.h" 20 : : #include "theory/theory_engine.h" 21 : : #include "theory/theory_model.h" 22 : : 23 : : namespace cvc5::internal { 24 : : namespace theory { 25 : : 26 : 0 : std::ostream& operator<<(std::ostream& os, EqualityStatus s) 27 : : { 28 [ - - ][ - - ]: 0 : switch (s) [ - - ][ - - ] 29 : : { 30 : 0 : case EQUALITY_TRUE_AND_PROPAGATED: 31 : 0 : os << "EQUALITY_TRUE_AND_PROPAGATED"; 32 : 0 : break; 33 : 0 : case EQUALITY_FALSE_AND_PROPAGATED: 34 : 0 : os << "EQUALITY_FALSE_AND_PROPAGATED"; 35 : 0 : break; 36 : 0 : case EQUALITY_TRUE: os << "EQUALITY_TRUE"; break; 37 : 0 : case EQUALITY_FALSE: os << "EQUALITY_FALSE"; break; 38 : 0 : case EQUALITY_TRUE_IN_MODEL: os << "EQUALITY_TRUE_IN_MODEL"; break; 39 : 0 : case EQUALITY_FALSE_IN_MODEL: os << "EQUALITY_FALSE_IN_MODEL"; break; 40 : 0 : case EQUALITY_UNKNOWN: os << "EQUALITY_UNKNOWN"; break; 41 : 0 : default: Unhandled(); break; 42 : : } 43 : 0 : return os; 44 : : } 45 : : 46 : 0 : bool equalityStatusCompatible(EqualityStatus s1, EqualityStatus s2) 47 : : { 48 [ - - ][ - ]: 0 : switch (s1) 49 : : { 50 : 0 : case EQUALITY_TRUE: 51 : : case EQUALITY_TRUE_IN_MODEL: 52 : : case EQUALITY_TRUE_AND_PROPAGATED: 53 [ - - ]: 0 : switch (s2) 54 : : { 55 : 0 : case EQUALITY_TRUE: 56 : : case EQUALITY_TRUE_IN_MODEL: 57 : 0 : case EQUALITY_TRUE_AND_PROPAGATED: return true; 58 : 0 : default: return false; 59 : : } 60 : : break; 61 : 0 : case EQUALITY_FALSE: 62 : : case EQUALITY_FALSE_IN_MODEL: 63 : : case EQUALITY_FALSE_AND_PROPAGATED: 64 [ - - ]: 0 : switch (s2) 65 : : { 66 : 0 : case EQUALITY_FALSE: 67 : : case EQUALITY_FALSE_IN_MODEL: 68 : 0 : case EQUALITY_FALSE_AND_PROPAGATED: return true; 69 : 0 : default: return false; 70 : : } 71 : : break; 72 : 0 : default: return false; 73 : : } 74 : : } 75 : : 76 : 254447 : bool Valuation::isSatLiteral(TNode n) const 77 : : { 78 [ - + ][ - + ]: 254447 : Assert(d_engine != nullptr); [ - - ] 79 : 254447 : return d_engine->getPropEngine()->isSatLiteral(n); 80 : : } 81 : : 82 : 107300 : Node Valuation::getSatValue(TNode n) const 83 : : { 84 [ - + ][ - + ]: 107300 : Assert(d_engine != nullptr); [ - - ] 85 [ - + ]: 107300 : if (n.getKind() == Kind::NOT) 86 : : { 87 : 0 : Node atomRes = d_engine->getPropEngine()->getValue(n[0]); 88 [ - - ]: 0 : if (atomRes.getKind() == Kind::CONST_BOOLEAN) 89 : : { 90 : 0 : return n.getNodeManager()->mkConst(!atomRes.getConst<bool>()); 91 : : } 92 : : else 93 : : { 94 : 0 : Assert(atomRes.isNull()); 95 : 0 : return atomRes; 96 : : } 97 : 0 : } 98 : : else 99 : : { 100 : 107300 : return d_engine->getPropEngine()->getValue(n); 101 : : } 102 : : } 103 : : 104 : 321315 : bool Valuation::hasSatValue(TNode n, bool& value) const 105 : : { 106 [ - + ][ - + ]: 321315 : Assert(d_engine != nullptr); [ - - ] 107 : 321315 : return d_engine->hasSatValue(n, value); 108 : : } 109 : : 110 : 935965 : bool Valuation::hasSatValue(TNode n) const 111 : : { 112 [ - + ][ - + ]: 935965 : Assert(d_engine != nullptr); [ - - ] 113 : 935965 : return d_engine->hasSatValue(n); 114 : : } 115 : : 116 : 2160159 : EqualityStatus Valuation::getEqualityStatus(TNode a, TNode b) 117 : : { 118 [ - + ][ - + ]: 2160159 : Assert(d_engine != nullptr); [ - - ] 119 : 2160159 : return d_engine->getEqualityStatus(a, b); 120 : : } 121 : : 122 : 12462 : Node Valuation::getCandidateModelValue(TNode var) 123 : : { 124 [ - + ][ - + ]: 12462 : Assert(d_engine != nullptr); [ - - ] 125 : 12462 : return d_engine->getCandidateModelValue(var); 126 : : } 127 : : 128 : 1806615 : TheoryModel* Valuation::getModel() 129 : : { 130 [ - + ]: 1806615 : if (d_engine == nullptr) 131 : : { 132 : : // no theory engine, thus we don't have a model object 133 : 0 : return nullptr; 134 : : } 135 : 1806615 : return d_engine->getModel(); 136 : : } 137 : 8118 : SortInference* Valuation::getSortInference() 138 : : { 139 [ - + ]: 8118 : if (d_engine == nullptr) 140 : : { 141 : : // no theory engine, thus we don't have a sort inference object 142 : 0 : return nullptr; 143 : : } 144 : 8118 : return d_engine->getSortInference(); 145 : : } 146 : : 147 : 586836 : void Valuation::setUnevaluatedKind(Kind k) 148 : : { 149 : 586836 : TheoryModel* m = getModel(); 150 [ + - ]: 586836 : if (m != nullptr) 151 : : { 152 : 586836 : m->setUnevaluatedKind(k); 153 : : } 154 : : // If no model is available, this command has no effect. This is the case 155 : : // when e.g. calling Theory::finishInit for theories that are using a 156 : : // Valuation with no model. 157 : 586836 : } 158 : : 159 : 204384 : void Valuation::setSemiEvaluatedKind(Kind k) 160 : : { 161 : 204384 : TheoryModel* m = getModel(); 162 [ + - ]: 204384 : if (m != nullptr) 163 : : { 164 : 204384 : m->setSemiEvaluatedKind(k); 165 : : } 166 : 204384 : } 167 : : 168 : 562056 : void Valuation::setIrrelevantKind(Kind k) 169 : : { 170 : 562056 : TheoryModel* m = getModel(); 171 [ + - ]: 562056 : if (m != nullptr) 172 : : { 173 : 562056 : m->setIrrelevantKind(k); 174 : : } 175 : 562056 : } 176 : : 177 : 424571 : Node Valuation::ensureLiteral(TNode n) 178 : : { 179 [ - + ][ - + ]: 424571 : Assert(d_engine != nullptr); [ - - ] 180 : 424571 : return d_engine->getPropEngine()->ensureLiteral(n); 181 : : } 182 : : 183 : 4105 : Node Valuation::getPreprocessedTerm(TNode n) 184 : : { 185 [ - + ][ - + ]: 4105 : Assert(d_engine != nullptr); [ - - ] 186 : 4105 : return d_engine->getPropEngine()->getPreprocessedTerm(n); 187 : : } 188 : : 189 : 3544 : Node Valuation::getPreprocessedTerm(TNode n, 190 : : std::vector<Node>& skAsserts, 191 : : std::vector<Node>& sks) 192 : : { 193 [ - + ][ - + ]: 3544 : Assert(d_engine != nullptr); [ - - ] 194 : 3544 : return d_engine->getPropEngine()->getPreprocessedTerm(n, skAsserts, sks); 195 : : } 196 : : 197 : 206693 : bool Valuation::isDecision(Node lit) const 198 : : { 199 [ - + ][ - + ]: 206693 : Assert(d_engine != nullptr); [ - - ] 200 : 206693 : return d_engine->getPropEngine()->isDecision(lit); 201 : : } 202 : : 203 : 16 : bool Valuation::isFixed(TNode lit) const 204 : : { 205 [ - + ][ - + ]: 16 : Assert(d_engine != nullptr); [ - - ] 206 : 16 : return d_engine->getPropEngine()->isFixed(lit); 207 : : } 208 : : 209 : 0 : unsigned Valuation::getAssertionLevel() const 210 : : { 211 : 0 : Assert(d_engine != nullptr); 212 : 0 : return d_engine->getPropEngine()->getAssertionLevel(); 213 : : } 214 : : 215 : 11499 : std::pair<bool, Node> Valuation::entailmentCheck(options::TheoryOfMode mode, 216 : : TNode lit) 217 : : { 218 [ - + ][ - + ]: 11499 : Assert(d_engine != nullptr); [ - - ] 219 : 11499 : return d_engine->entailmentCheck(mode, lit); 220 : : } 221 : : 222 : 1319387 : bool Valuation::needCheck() const 223 : : { 224 [ - + ][ - + ]: 1319387 : Assert(d_engine != nullptr); [ - - ] 225 : 1319387 : return d_engine->needCheck(); 226 : : } 227 : : 228 : 1726 : bool Valuation::isRelevant(Node lit) const { return d_engine->isRelevant(lit); } 229 : : 230 : 53414 : bool Valuation::isLegalElimination(TNode x, TNode val) 231 : : { 232 : 53414 : return d_engine->isLegalElimination(x, val); 233 : : } 234 : : 235 : 655998 : context::CDList<Assertion>::const_iterator Valuation::factsBegin(TheoryId tid) 236 : : { 237 : 655998 : Theory* theory = d_engine->theoryOf(tid); 238 [ - + ][ - + ]: 655998 : Assert(theory != nullptr); [ - - ] 239 : 655998 : return theory->facts_begin(); 240 : : } 241 : 655998 : context::CDList<Assertion>::const_iterator Valuation::factsEnd(TheoryId tid) 242 : : { 243 : 655998 : Theory* theory = d_engine->theoryOf(tid); 244 [ - + ][ - + ]: 655998 : Assert(theory != nullptr); [ - - ] 245 : 655998 : return theory->facts_end(); 246 : : } 247 : : 248 : : } // namespace theory 249 : : } // namespace cvc5::internal