summaryrefslogtreecommitdiff
path: root/src/theory/valuation.cpp
blob: bd7a3872c6030c94457f5431cfe8f517fca44c5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/******************************************************************************
 * Top contributors (to current version):
 *   Andrew Reynolds, Dejan Jovanovic, Morgan Deters
 *
 * This file is part of the cvc5 project.
 *
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
 * in the top-level source directory and their institutional affiliations.
 * All rights reserved.  See the file COPYING in the top-level source
 * directory for licensing information.
 * ****************************************************************************
 *
 * A "valuation" proxy for TheoryEngine.
 */

#include "theory/valuation.h"

#include "expr/node.h"
#include "options/theory_options.h"
#include "prop/prop_engine.h"
#include "theory/assertion.h"
#include "theory/rewriter.h"
#include "theory/theory_engine.h"
#include "theory/theory_model.h"

namespace cvc5 {
namespace theory {

std::ostream& operator<<(std::ostream& os, EqualityStatus s)
{
  switch (s)
  {
    case EQUALITY_TRUE_AND_PROPAGATED:
      os << "EQUALITY_TRUE_AND_PROPAGATED";
      break;
    case EQUALITY_FALSE_AND_PROPAGATED:
      os << "EQUALITY_FALSE_AND_PROPAGATED";
      break;
    case EQUALITY_TRUE: os << "EQUALITY_TRUE"; break;
    case EQUALITY_FALSE: os << "EQUALITY_FALSE"; break;
    case EQUALITY_TRUE_IN_MODEL: os << "EQUALITY_TRUE_IN_MODEL"; break;
    case EQUALITY_FALSE_IN_MODEL: os << "EQUALITY_FALSE_IN_MODEL"; break;
    case EQUALITY_UNKNOWN: os << "EQUALITY_UNKNOWN"; break;
    default: Unhandled(); break;
  }
  return os;
}

bool equalityStatusCompatible(EqualityStatus s1, EqualityStatus s2) {
  switch (s1) {
  case EQUALITY_TRUE:
  case EQUALITY_TRUE_IN_MODEL:
  case EQUALITY_TRUE_AND_PROPAGATED:
    switch (s2) {
    case EQUALITY_TRUE:
    case EQUALITY_TRUE_IN_MODEL:
    case EQUALITY_TRUE_AND_PROPAGATED:
      return true;
    default:
      return false;
    }
    break;
  case EQUALITY_FALSE:
  case EQUALITY_FALSE_IN_MODEL:
  case EQUALITY_FALSE_AND_PROPAGATED:
    switch (s2) {
    case EQUALITY_FALSE:
    case EQUALITY_FALSE_IN_MODEL:
    case EQUALITY_FALSE_AND_PROPAGATED:
      return true;
    default:
      return false;
    }
    break;
  default:
    return false;
  }
}

bool Valuation::isSatLiteral(TNode n) const {
  Assert(d_engine != nullptr);
  return d_engine->getPropEngine()->isSatLiteral(n);
}

Node Valuation::getSatValue(TNode n) const {
  Assert(d_engine != nullptr);
  if(n.getKind() == kind::NOT) {
    Node atomRes = d_engine->getPropEngine()->getValue(n[0]);
    if(atomRes.getKind() == kind::CONST_BOOLEAN) {
      return NodeManager::currentNM()->mkConst(!atomRes.getConst<bool>());
    } else {
      Assert(atomRes.isNull());
      return atomRes;
    }
  } else {
    return d_engine->getPropEngine()->getValue(n);
  }
}

bool Valuation::hasSatValue(TNode n, bool& value) const {
  Assert(d_engine != nullptr);
  if (d_engine->getPropEngine()->isSatLiteral(n)) {
    return d_engine->getPropEngine()->hasValue(n, value);
  } else {
    return false;
  }
}

EqualityStatus Valuation::getEqualityStatus(TNode a, TNode b) {
  Assert(d_engine != nullptr);
  return d_engine->getEqualityStatus(a, b);
}

Node Valuation::getModelValue(TNode var) {
  Assert(d_engine != nullptr);
  return d_engine->getModelValue(var);
}

TheoryModel* Valuation::getModel() {
  if (d_engine == nullptr)
  {
    // no theory engine, thus we don't have a model object
    return nullptr;
  }
  return d_engine->getModel();
}
SortInference* Valuation::getSortInference()
{
  if (d_engine == nullptr)
  {
    // no theory engine, thus we don't have a sort inference object
    return nullptr;
  }
  return d_engine->getSortInference();
}

void Valuation::setUnevaluatedKind(Kind k)
{
  TheoryModel* m = getModel();
  if (m != nullptr)
  {
    m->setUnevaluatedKind(k);
  }
  // If no model is available, this command has no effect. This is the case
  // when e.g. calling Theory::finishInit for theories that are using a
  // Valuation with no model.
}

void Valuation::setSemiEvaluatedKind(Kind k)
{
  TheoryModel* m = getModel();
  if (m != nullptr)
  {
    m->setSemiEvaluatedKind(k);
  }
}

void Valuation::setIrrelevantKind(Kind k)
{
  TheoryModel* m = getModel();
  if (m != nullptr)
  {
    m->setIrrelevantKind(k);
  }
}

Node Valuation::ensureLiteral(TNode n) {
  Assert(d_engine != nullptr);
  return d_engine->getPropEngine()->ensureLiteral(n);
}

Node Valuation::getPreprocessedTerm(TNode n)
{
  Assert(d_engine != nullptr);
  return d_engine->getPropEngine()->getPreprocessedTerm(n);
}

Node Valuation::getPreprocessedTerm(TNode n,
                                    std::vector<Node>& skAsserts,
                                    std::vector<Node>& sks)
{
  Assert(d_engine != nullptr);
  return d_engine->getPropEngine()->getPreprocessedTerm(n, skAsserts, sks);
}

bool Valuation::isDecision(Node lit) const {
  Assert(d_engine != nullptr);
  return d_engine->getPropEngine()->isDecision(lit);
}

int32_t Valuation::getDecisionLevel(Node lit) const
{
  Assert(d_engine != nullptr);
  return d_engine->getPropEngine()->getDecisionLevel(lit);
}

int32_t Valuation::getIntroLevel(Node lit) const
{
  Assert(d_engine != nullptr);
  return d_engine->getPropEngine()->getIntroLevel(lit);
}

unsigned Valuation::getAssertionLevel() const{
  Assert(d_engine != nullptr);
  return d_engine->getPropEngine()->getAssertionLevel();
}

std::pair<bool, Node> Valuation::entailmentCheck(options::TheoryOfMode mode,
                                                 TNode lit)
{
  Assert(d_engine != nullptr);
  return d_engine->entailmentCheck(mode, lit);
}

bool Valuation::needCheck() const{
  Assert(d_engine != nullptr);
  return d_engine->needCheck();
}

bool Valuation::isRelevant(Node lit) const { return d_engine->isRelevant(lit); }

context::CDList<Assertion>::const_iterator Valuation::factsBegin(TheoryId tid)
{
  Theory* theory = d_engine->theoryOf(tid);
  Assert(theory != nullptr);
  return theory->facts_begin();
}
context::CDList<Assertion>::const_iterator Valuation::factsEnd(TheoryId tid)
{
  Theory* theory = d_engine->theoryOf(tid);
  Assert(theory != nullptr);
  return theory->facts_end();
}

}  // namespace theory
}  // namespace cvc5
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback