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 |
118278 |
TheoryState::TheoryState(context::Context* c, |
24 |
|
context::UserContext* u, |
25 |
118278 |
Valuation val) |
26 |
|
: d_context(c), |
27 |
|
d_ucontext(u), |
28 |
|
d_valuation(val), |
29 |
|
d_ee(nullptr), |
30 |
118278 |
d_conflict(c, false) |
31 |
|
{ |
32 |
118278 |
} |
33 |
|
|
34 |
118236 |
void TheoryState::setEqualityEngine(eq::EqualityEngine* ee) { d_ee = ee; } |
35 |
|
|
36 |
220809 |
context::Context* TheoryState::getSatContext() const { return d_context; } |
37 |
|
|
38 |
292899 |
context::UserContext* TheoryState::getUserContext() const { return d_ucontext; } |
39 |
|
|
40 |
25031644 |
bool TheoryState::hasTerm(TNode a) const |
41 |
|
{ |
42 |
25031644 |
Assert(d_ee != nullptr); |
43 |
25031644 |
return d_ee->hasTerm(a); |
44 |
|
} |
45 |
|
|
46 |
13295333 |
TNode TheoryState::getRepresentative(TNode t) const |
47 |
|
{ |
48 |
13295333 |
Assert(d_ee != nullptr); |
49 |
13295333 |
if (d_ee->hasTerm(t)) |
50 |
|
{ |
51 |
13136672 |
return d_ee->getRepresentative(t); |
52 |
|
} |
53 |
158661 |
return t; |
54 |
|
} |
55 |
|
|
56 |
7736126 |
bool TheoryState::areEqual(TNode a, TNode b) const |
57 |
|
{ |
58 |
7736126 |
Assert(d_ee != nullptr); |
59 |
7736126 |
if (a == b) |
60 |
|
{ |
61 |
1910340 |
return true; |
62 |
|
} |
63 |
5825786 |
else if (hasTerm(a) && hasTerm(b)) |
64 |
|
{ |
65 |
5791077 |
return d_ee->areEqual(a, b); |
66 |
|
} |
67 |
34709 |
return false; |
68 |
|
} |
69 |
|
|
70 |
527994 |
bool TheoryState::areDisequal(TNode a, TNode b) const |
71 |
|
{ |
72 |
527994 |
Assert(d_ee != nullptr); |
73 |
527994 |
if (a == b) |
74 |
|
{ |
75 |
240685 |
return false; |
76 |
|
} |
77 |
|
|
78 |
287309 |
bool isConst = true; |
79 |
287309 |
bool hasTerms = true; |
80 |
287309 |
if (hasTerm(a)) |
81 |
|
{ |
82 |
286750 |
a = d_ee->getRepresentative(a); |
83 |
286750 |
isConst = a.isConst(); |
84 |
|
} |
85 |
559 |
else if (!a.isConst()) |
86 |
|
{ |
87 |
|
// if not constant and not a term in the ee, it cannot be disequal |
88 |
317 |
return false; |
89 |
|
} |
90 |
|
else |
91 |
|
{ |
92 |
242 |
hasTerms = false; |
93 |
|
} |
94 |
|
|
95 |
286992 |
if (hasTerm(b)) |
96 |
|
{ |
97 |
286602 |
b = d_ee->getRepresentative(b); |
98 |
286602 |
isConst = isConst && b.isConst(); |
99 |
|
} |
100 |
390 |
else if (!b.isConst()) |
101 |
|
{ |
102 |
|
// same as above, it cannot be disequal |
103 |
57 |
return false; |
104 |
|
} |
105 |
|
else |
106 |
|
{ |
107 |
333 |
hasTerms = false; |
108 |
|
} |
109 |
|
|
110 |
286935 |
if (isConst) |
111 |
|
{ |
112 |
|
// distinct constants are disequal |
113 |
51918 |
return a != b; |
114 |
|
} |
115 |
235017 |
else if (!hasTerms) |
116 |
|
{ |
117 |
337 |
return false; |
118 |
|
} |
119 |
|
// otherwise there may be an explicit disequality in the equality engine |
120 |
234680 |
return d_ee->areDisequal(a, b, false); |
121 |
|
} |
122 |
|
|
123 |
7691 |
void TheoryState::getEquivalenceClass(Node a, std::vector<Node>& eqc) const |
124 |
|
{ |
125 |
7691 |
if (d_ee->hasTerm(a)) |
126 |
|
{ |
127 |
13916 |
Node rep = d_ee->getRepresentative(a); |
128 |
6958 |
eq::EqClassIterator eqc_iter(rep, d_ee); |
129 |
108164 |
while (!eqc_iter.isFinished()) |
130 |
|
{ |
131 |
50603 |
eqc.push_back(*eqc_iter); |
132 |
50603 |
eqc_iter++; |
133 |
|
} |
134 |
|
} |
135 |
|
else |
136 |
|
{ |
137 |
733 |
eqc.push_back(a); |
138 |
|
} |
139 |
|
// a should be in its equivalence class |
140 |
7691 |
Assert(std::find(eqc.begin(), eqc.end(), a) != eqc.end()); |
141 |
7691 |
} |
142 |
|
|
143 |
7151580 |
eq::EqualityEngine* TheoryState::getEqualityEngine() const { return d_ee; } |
144 |
|
|
145 |
2372936 |
void TheoryState::notifyInConflict() { d_conflict = true; } |
146 |
|
|
147 |
45438438 |
bool TheoryState::isInConflict() const { return d_conflict; } |
148 |
|
|
149 |
|
bool TheoryState::isSatLiteral(TNode lit) const |
150 |
|
{ |
151 |
|
return d_valuation.isSatLiteral(lit); |
152 |
|
} |
153 |
|
|
154 |
1514 |
TheoryModel* TheoryState::getModel() { return d_valuation.getModel(); } |
155 |
|
|
156 |
5171 |
SortInference* TheoryState::getSortInference() |
157 |
|
{ |
158 |
5171 |
return d_valuation.getSortInference(); |
159 |
|
} |
160 |
|
|
161 |
42519 |
bool TheoryState::hasSatValue(TNode n, bool& value) const |
162 |
|
{ |
163 |
42519 |
return d_valuation.hasSatValue(n, value); |
164 |
|
} |
165 |
|
|
166 |
7607 |
context::CDList<Assertion>::const_iterator TheoryState::factsBegin(TheoryId tid) |
167 |
|
{ |
168 |
7607 |
return d_valuation.factsBegin(tid); |
169 |
|
} |
170 |
7607 |
context::CDList<Assertion>::const_iterator TheoryState::factsEnd(TheoryId tid) |
171 |
|
{ |
172 |
7607 |
return d_valuation.factsEnd(tid); |
173 |
|
} |
174 |
|
|
175 |
11287 |
bool TheoryState::isFiniteType(TypeNode tn) const |
176 |
|
{ |
177 |
11287 |
return d_valuation.isFiniteType(tn); |
178 |
|
} |
179 |
|
|
180 |
1346734 |
Valuation& TheoryState::getValuation() { return d_valuation; } |
181 |
|
|
182 |
|
} // namespace theory |
183 |
29340 |
} // namespace cvc5 |