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 |
183318 |
TheoryState::TheoryState(Env& env, Valuation val) |
24 |
183318 |
: EnvObj(env), d_valuation(val), d_ee(nullptr), d_conflict(context(), false) |
25 |
|
{ |
26 |
183318 |
} |
27 |
|
|
28 |
183276 |
void TheoryState::setEqualityEngine(eq::EqualityEngine* ee) { d_ee = ee; } |
29 |
|
|
30 |
39845947 |
bool TheoryState::hasTerm(TNode a) const |
31 |
|
{ |
32 |
39845947 |
Assert(d_ee != nullptr); |
33 |
39845947 |
return d_ee->hasTerm(a); |
34 |
|
} |
35 |
|
|
36 |
16313191 |
TNode TheoryState::getRepresentative(TNode t) const |
37 |
|
{ |
38 |
16313191 |
Assert(d_ee != nullptr); |
39 |
16313191 |
if (d_ee->hasTerm(t)) |
40 |
|
{ |
41 |
16152376 |
return d_ee->getRepresentative(t); |
42 |
|
} |
43 |
160815 |
return t; |
44 |
|
} |
45 |
|
|
46 |
11254687 |
bool TheoryState::areEqual(TNode a, TNode b) const |
47 |
|
{ |
48 |
11254687 |
Assert(d_ee != nullptr); |
49 |
11254687 |
if (a == b) |
50 |
|
{ |
51 |
2738732 |
return true; |
52 |
|
} |
53 |
8515955 |
else if (hasTerm(a) && hasTerm(b)) |
54 |
|
{ |
55 |
8460286 |
return d_ee->areEqual(a, b); |
56 |
|
} |
57 |
55669 |
return false; |
58 |
|
} |
59 |
|
|
60 |
3814718 |
bool TheoryState::areDisequal(TNode a, TNode b) const |
61 |
|
{ |
62 |
3814718 |
Assert(d_ee != nullptr); |
63 |
3814718 |
if (a == b) |
64 |
|
{ |
65 |
416541 |
return false; |
66 |
|
} |
67 |
|
|
68 |
3398177 |
bool isConst = true; |
69 |
3398177 |
bool hasTerms = true; |
70 |
3398177 |
if (hasTerm(a)) |
71 |
|
{ |
72 |
3397490 |
a = d_ee->getRepresentative(a); |
73 |
3397490 |
isConst = a.isConst(); |
74 |
|
} |
75 |
687 |
else if (!a.isConst()) |
76 |
|
{ |
77 |
|
// if not constant and not a term in the ee, it cannot be disequal |
78 |
445 |
return false; |
79 |
|
} |
80 |
|
else |
81 |
|
{ |
82 |
242 |
hasTerms = false; |
83 |
|
} |
84 |
|
|
85 |
3397732 |
if (hasTerm(b)) |
86 |
|
{ |
87 |
3397276 |
b = d_ee->getRepresentative(b); |
88 |
3397276 |
isConst = isConst && b.isConst(); |
89 |
|
} |
90 |
456 |
else if (!b.isConst()) |
91 |
|
{ |
92 |
|
// same as above, it cannot be disequal |
93 |
102 |
return false; |
94 |
|
} |
95 |
|
else |
96 |
|
{ |
97 |
354 |
hasTerms = false; |
98 |
|
} |
99 |
|
|
100 |
3397630 |
if (isConst) |
101 |
|
{ |
102 |
|
// distinct constants are disequal |
103 |
1712002 |
return a != b; |
104 |
|
} |
105 |
1685628 |
else if (!hasTerms) |
106 |
|
{ |
107 |
356 |
return false; |
108 |
|
} |
109 |
|
// otherwise there may be an explicit disequality in the equality engine |
110 |
1685272 |
return d_ee->areDisequal(a, b, false); |
111 |
|
} |
112 |
|
|
113 |
8377 |
void TheoryState::getEquivalenceClass(Node a, std::vector<Node>& eqc) const |
114 |
|
{ |
115 |
8377 |
if (d_ee->hasTerm(a)) |
116 |
|
{ |
117 |
15028 |
Node rep = d_ee->getRepresentative(a); |
118 |
7514 |
eq::EqClassIterator eqc_iter(rep, d_ee); |
119 |
119246 |
while (!eqc_iter.isFinished()) |
120 |
|
{ |
121 |
55866 |
eqc.push_back(*eqc_iter); |
122 |
55866 |
eqc_iter++; |
123 |
|
} |
124 |
|
} |
125 |
|
else |
126 |
|
{ |
127 |
863 |
eqc.push_back(a); |
128 |
|
} |
129 |
|
// a should be in its equivalence class |
130 |
8377 |
Assert(std::find(eqc.begin(), eqc.end(), a) != eqc.end()); |
131 |
8377 |
} |
132 |
|
|
133 |
7576175 |
eq::EqualityEngine* TheoryState::getEqualityEngine() const { return d_ee; } |
134 |
|
|
135 |
2722883 |
void TheoryState::notifyInConflict() { d_conflict = true; } |
136 |
|
|
137 |
63599215 |
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 |
17808212 |
TheoryModel* TheoryState::getModel() { return d_valuation.getModel(); } |
145 |
|
|
146 |
5313 |
SortInference* TheoryState::getSortInference() |
147 |
|
{ |
148 |
5313 |
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 |
8017 |
context::CDList<Assertion>::const_iterator TheoryState::factsBegin(TheoryId tid) |
157 |
|
{ |
158 |
8017 |
return d_valuation.factsBegin(tid); |
159 |
|
} |
160 |
8017 |
context::CDList<Assertion>::const_iterator TheoryState::factsEnd(TheoryId tid) |
161 |
|
{ |
162 |
8017 |
return d_valuation.factsEnd(tid); |
163 |
|
} |
164 |
|
|
165 |
1512740 |
Valuation& TheoryState::getValuation() { return d_valuation; } |
166 |
|
|
167 |
|
} // namespace theory |
168 |
31137 |
} // namespace cvc5 |