1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Mathias Preiner |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
7 |
|
* Copyright (c) 2009-2021 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. |
11 |
|
* **************************************************************************** |
12 |
|
* |
13 |
|
* A theory state for Theory. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "theory/theory_state.h" |
17 |
|
|
18 |
|
#include "theory/uf/equality_engine.h" |
19 |
|
|
20 |
|
namespace cvc5 { |
21 |
|
namespace theory { |
22 |
|
|
23 |
119346 |
TheoryState::TheoryState(Env& env, Valuation val) |
24 |
119346 |
: EnvObj(env), d_valuation(val), d_ee(nullptr), d_conflict(context(), false) |
25 |
|
{ |
26 |
119346 |
} |
27 |
|
|
28 |
119304 |
void TheoryState::setEqualityEngine(eq::EqualityEngine* ee) { d_ee = ee; } |
29 |
|
|
30 |
28500637 |
bool TheoryState::hasTerm(TNode a) const |
31 |
|
{ |
32 |
28500637 |
Assert(d_ee != nullptr); |
33 |
28500637 |
return d_ee->hasTerm(a); |
34 |
|
} |
35 |
|
|
36 |
14957842 |
TNode TheoryState::getRepresentative(TNode t) const |
37 |
|
{ |
38 |
14957842 |
Assert(d_ee != nullptr); |
39 |
14957842 |
if (d_ee->hasTerm(t)) |
40 |
|
{ |
41 |
14800123 |
return d_ee->getRepresentative(t); |
42 |
|
} |
43 |
157719 |
return t; |
44 |
|
} |
45 |
|
|
46 |
9578437 |
bool TheoryState::areEqual(TNode a, TNode b) const |
47 |
|
{ |
48 |
9578437 |
Assert(d_ee != nullptr); |
49 |
9578437 |
if (a == b) |
50 |
|
{ |
51 |
2444760 |
return true; |
52 |
|
} |
53 |
7133677 |
else if (hasTerm(a) && hasTerm(b)) |
54 |
|
{ |
55 |
7093944 |
return d_ee->areEqual(a, b); |
56 |
|
} |
57 |
39733 |
return false; |
58 |
|
} |
59 |
|
|
60 |
568057 |
bool TheoryState::areDisequal(TNode a, TNode b) const |
61 |
|
{ |
62 |
568057 |
Assert(d_ee != nullptr); |
63 |
568057 |
if (a == b) |
64 |
|
{ |
65 |
245072 |
return false; |
66 |
|
} |
67 |
|
|
68 |
322985 |
bool isConst = true; |
69 |
322985 |
bool hasTerms = true; |
70 |
322985 |
if (hasTerm(a)) |
71 |
|
{ |
72 |
322422 |
a = d_ee->getRepresentative(a); |
73 |
322422 |
isConst = a.isConst(); |
74 |
|
} |
75 |
563 |
else if (!a.isConst()) |
76 |
|
{ |
77 |
|
// if not constant and not a term in the ee, it cannot be disequal |
78 |
321 |
return false; |
79 |
|
} |
80 |
|
else |
81 |
|
{ |
82 |
242 |
hasTerms = false; |
83 |
|
} |
84 |
|
|
85 |
322664 |
if (hasTerm(b)) |
86 |
|
{ |
87 |
322272 |
b = d_ee->getRepresentative(b); |
88 |
322272 |
isConst = isConst && b.isConst(); |
89 |
|
} |
90 |
392 |
else if (!b.isConst()) |
91 |
|
{ |
92 |
|
// same as above, it cannot be disequal |
93 |
57 |
return false; |
94 |
|
} |
95 |
|
else |
96 |
|
{ |
97 |
335 |
hasTerms = false; |
98 |
|
} |
99 |
|
|
100 |
322607 |
if (isConst) |
101 |
|
{ |
102 |
|
// distinct constants are disequal |
103 |
64216 |
return a != b; |
104 |
|
} |
105 |
258391 |
else if (!hasTerms) |
106 |
|
{ |
107 |
339 |
return false; |
108 |
|
} |
109 |
|
// otherwise there may be an explicit disequality in the equality engine |
110 |
258052 |
return d_ee->areDisequal(a, b, false); |
111 |
|
} |
112 |
|
|
113 |
8279 |
void TheoryState::getEquivalenceClass(Node a, std::vector<Node>& eqc) const |
114 |
|
{ |
115 |
8279 |
if (d_ee->hasTerm(a)) |
116 |
|
{ |
117 |
15024 |
Node rep = d_ee->getRepresentative(a); |
118 |
7512 |
eq::EqClassIterator eqc_iter(rep, d_ee); |
119 |
118834 |
while (!eqc_iter.isFinished()) |
120 |
|
{ |
121 |
55661 |
eqc.push_back(*eqc_iter); |
122 |
55661 |
eqc_iter++; |
123 |
|
} |
124 |
|
} |
125 |
|
else |
126 |
|
{ |
127 |
767 |
eqc.push_back(a); |
128 |
|
} |
129 |
|
// a should be in its equivalence class |
130 |
8279 |
Assert(std::find(eqc.begin(), eqc.end(), a) != eqc.end()); |
131 |
8279 |
} |
132 |
|
|
133 |
7247529 |
eq::EqualityEngine* TheoryState::getEqualityEngine() const { return d_ee; } |
134 |
|
|
135 |
2545416 |
void TheoryState::notifyInConflict() { d_conflict = true; } |
136 |
|
|
137 |
50603987 |
bool TheoryState::isInConflict() const { return d_conflict; } |
138 |
|
|
139 |
|
bool TheoryState::isSatLiteral(TNode lit) const |
140 |
|
{ |
141 |
|
return d_valuation.isSatLiteral(lit); |
142 |
|
} |
143 |
|
|
144 |
6928656 |
TheoryModel* TheoryState::getModel() { return d_valuation.getModel(); } |
145 |
|
|
146 |
5153 |
SortInference* TheoryState::getSortInference() |
147 |
|
{ |
148 |
5153 |
return d_valuation.getSortInference(); |
149 |
|
} |
150 |
|
|
151 |
41175 |
bool TheoryState::hasSatValue(TNode n, bool& value) const |
152 |
|
{ |
153 |
41175 |
return d_valuation.hasSatValue(n, value); |
154 |
|
} |
155 |
|
|
156 |
7639 |
context::CDList<Assertion>::const_iterator TheoryState::factsBegin(TheoryId tid) |
157 |
|
{ |
158 |
7639 |
return d_valuation.factsBegin(tid); |
159 |
|
} |
160 |
7639 |
context::CDList<Assertion>::const_iterator TheoryState::factsEnd(TheoryId tid) |
161 |
|
{ |
162 |
7639 |
return d_valuation.factsEnd(tid); |
163 |
|
} |
164 |
|
|
165 |
11630 |
bool TheoryState::isFiniteType(TypeNode tn) const |
166 |
|
{ |
167 |
11630 |
return d_valuation.isFiniteType(tn); |
168 |
|
} |
169 |
|
|
170 |
1345092 |
Valuation& TheoryState::getValuation() { return d_valuation; } |
171 |
|
|
172 |
|
} // namespace theory |
173 |
29577 |
} // namespace cvc5 |