1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Mathias Preiner, Tim King |
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 |
|
* Implementation of term database class. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "theory/quantifiers/term_database.h" |
17 |
|
|
18 |
|
#include "expr/skolem_manager.h" |
19 |
|
#include "options/base_options.h" |
20 |
|
#include "options/quantifiers_options.h" |
21 |
|
#include "options/smt_options.h" |
22 |
|
#include "options/theory_options.h" |
23 |
|
#include "options/uf_options.h" |
24 |
|
#include "theory/quantifiers/ematching/trigger_term_info.h" |
25 |
|
#include "theory/quantifiers/quantifiers_attributes.h" |
26 |
|
#include "theory/quantifiers/quantifiers_inference_manager.h" |
27 |
|
#include "theory/quantifiers/quantifiers_registry.h" |
28 |
|
#include "theory/quantifiers/quantifiers_state.h" |
29 |
|
#include "theory/quantifiers/term_util.h" |
30 |
|
#include "theory/rewriter.h" |
31 |
|
#include "theory/uf/equality_engine.h" |
32 |
|
|
33 |
|
using namespace cvc5::kind; |
34 |
|
using namespace cvc5::context; |
35 |
|
|
36 |
|
namespace cvc5 { |
37 |
|
namespace theory { |
38 |
|
namespace quantifiers { |
39 |
|
|
40 |
9927 |
TermDb::TermDb(QuantifiersState& qs, QuantifiersRegistry& qr) |
41 |
|
: d_qstate(qs), |
42 |
|
d_qim(nullptr), |
43 |
|
d_qreg(qr), |
44 |
|
d_termsContext(), |
45 |
9927 |
d_termsContextUse(options::termDbCd() ? qs.getSatContext() |
46 |
|
: &d_termsContext), |
47 |
|
d_processed(d_termsContextUse), |
48 |
|
d_typeMap(d_termsContextUse), |
49 |
|
d_ops(d_termsContextUse), |
50 |
|
d_opMap(d_termsContextUse), |
51 |
19854 |
d_inactive_map(qs.getSatContext()) |
52 |
|
{ |
53 |
9927 |
d_consistent_ee = true; |
54 |
9927 |
d_true = NodeManager::currentNM()->mkConst(true); |
55 |
9927 |
d_false = NodeManager::currentNM()->mkConst(false); |
56 |
9927 |
if (!options::termDbCd()) |
57 |
|
{ |
58 |
|
// when not maintaining terms in a context-dependent manner, we clear during |
59 |
|
// each presolve, which requires maintaining a single outermost level |
60 |
|
d_termsContext.push(); |
61 |
|
} |
62 |
9927 |
} |
63 |
|
|
64 |
19656 |
TermDb::~TermDb(){ |
65 |
|
|
66 |
19656 |
} |
67 |
|
|
68 |
9927 |
void TermDb::finishInit(QuantifiersInferenceManager* qim) { d_qim = qim; } |
69 |
|
|
70 |
25044 |
void TermDb::registerQuantifier( Node q ) { |
71 |
25044 |
Assert(q[0].getNumChildren() == d_qreg.getNumInstantiationConstants(q)); |
72 |
84210 |
for (size_t i = 0, nvars = q[0].getNumChildren(); i < nvars; i++) |
73 |
|
{ |
74 |
118332 |
Node ic = d_qreg.getInstantiationConstant(q, i); |
75 |
59166 |
setTermInactive( ic ); |
76 |
|
} |
77 |
25044 |
} |
78 |
|
|
79 |
915 |
size_t TermDb::getNumOperators() const { return d_ops.size(); } |
80 |
|
|
81 |
2050 |
Node TermDb::getOperator(size_t i) const |
82 |
|
{ |
83 |
2050 |
Assert(i < d_ops.size()); |
84 |
2050 |
return d_ops[i]; |
85 |
|
} |
86 |
|
|
87 |
|
/** ground terms */ |
88 |
517992 |
size_t TermDb::getNumGroundTerms(Node f) const |
89 |
|
{ |
90 |
517992 |
NodeDbListMap::const_iterator it = d_opMap.find(f); |
91 |
517992 |
if (it != d_opMap.end()) |
92 |
|
{ |
93 |
500620 |
return it->second->d_list.size(); |
94 |
|
} |
95 |
17372 |
return 0; |
96 |
|
} |
97 |
|
|
98 |
2998121 |
Node TermDb::getGroundTerm(Node f, size_t i) const |
99 |
|
{ |
100 |
2998121 |
NodeDbListMap::const_iterator it = d_opMap.find(f); |
101 |
2998121 |
if (it != d_opMap.end()) |
102 |
|
{ |
103 |
2998121 |
Assert(i < it->second->d_list.size()); |
104 |
2998121 |
return it->second->d_list[i]; |
105 |
|
} |
106 |
|
Assert(false); |
107 |
|
return Node::null(); |
108 |
|
} |
109 |
|
|
110 |
248 |
size_t TermDb::getNumTypeGroundTerms(TypeNode tn) const |
111 |
|
{ |
112 |
248 |
TypeNodeDbListMap::const_iterator it = d_typeMap.find(tn); |
113 |
248 |
if (it != d_typeMap.end()) |
114 |
|
{ |
115 |
239 |
return it->second->d_list.size(); |
116 |
|
} |
117 |
9 |
return 0; |
118 |
|
} |
119 |
|
|
120 |
10246 |
Node TermDb::getTypeGroundTerm(TypeNode tn, size_t i) const |
121 |
|
{ |
122 |
10246 |
TypeNodeDbListMap::const_iterator it = d_typeMap.find(tn); |
123 |
10246 |
if (it != d_typeMap.end()) |
124 |
|
{ |
125 |
10246 |
Assert(i < it->second->d_list.size()); |
126 |
10246 |
return it->second->d_list[i]; |
127 |
|
} |
128 |
|
Assert(false); |
129 |
|
return Node::null(); |
130 |
|
} |
131 |
|
|
132 |
2488 |
Node TermDb::getOrMakeTypeGroundTerm(TypeNode tn, bool reqVar) |
133 |
|
{ |
134 |
2488 |
TypeNodeDbListMap::const_iterator it = d_typeMap.find(tn); |
135 |
2488 |
if (it != d_typeMap.end()) |
136 |
|
{ |
137 |
519 |
Assert(!it->second->d_list.empty()); |
138 |
519 |
if (!reqVar) |
139 |
|
{ |
140 |
178 |
return it->second->d_list[0]; |
141 |
|
} |
142 |
532 |
for (const Node& v : it->second->d_list) |
143 |
|
{ |
144 |
477 |
if (v.isVar()) |
145 |
|
{ |
146 |
286 |
return v; |
147 |
|
} |
148 |
|
} |
149 |
|
} |
150 |
2024 |
return getOrMakeTypeFreshVariable(tn); |
151 |
|
} |
152 |
|
|
153 |
2024 |
Node TermDb::getOrMakeTypeFreshVariable(TypeNode tn) |
154 |
|
{ |
155 |
2024 |
std::unordered_map<TypeNode, Node>::iterator it = d_type_fv.find(tn); |
156 |
2024 |
if (it == d_type_fv.end()) |
157 |
|
{ |
158 |
240 |
SkolemManager* sm = NodeManager::currentNM()->getSkolemManager(); |
159 |
480 |
std::stringstream ss; |
160 |
240 |
ss << language::SetLanguage(options::outputLanguage()); |
161 |
240 |
ss << "e_" << tn; |
162 |
480 |
Node k = sm->mkDummySkolem(ss.str(), tn, "is a termDb fresh variable"); |
163 |
480 |
Trace("mkVar") << "TermDb:: Make variable " << k << " : " << tn |
164 |
240 |
<< std::endl; |
165 |
240 |
if (options::instMaxLevel() != -1) |
166 |
|
{ |
167 |
|
QuantAttributes::setInstantiationLevelAttr(k, 0); |
168 |
|
} |
169 |
240 |
d_type_fv[tn] = k; |
170 |
240 |
return k; |
171 |
|
} |
172 |
1784 |
return it->second; |
173 |
|
} |
174 |
|
|
175 |
4861715 |
Node TermDb::getMatchOperator( Node n ) { |
176 |
4861715 |
Kind k = n.getKind(); |
177 |
|
//datatype operators may be parametric, always assume they are |
178 |
4861715 |
if (k == SELECT || k == STORE || k == UNION || k == INTERSECTION |
179 |
4830008 |
|| k == SUBSET || k == SETMINUS || k == MEMBER || k == SINGLETON |
180 |
4801104 |
|| k == APPLY_SELECTOR_TOTAL || k == APPLY_SELECTOR || k == APPLY_TESTER |
181 |
4412494 |
|| k == SEP_PTO || k == HO_APPLY || k == SEQ_NTH) |
182 |
|
{ |
183 |
|
//since it is parametric, use a particular one as op |
184 |
938352 |
TypeNode tn = n[0].getType(); |
185 |
938352 |
Node op = n.getOperator(); |
186 |
469176 |
std::map< Node, std::map< TypeNode, Node > >::iterator ito = d_par_op_map.find( op ); |
187 |
469176 |
if( ito!=d_par_op_map.end() ){ |
188 |
460575 |
std::map< TypeNode, Node >::iterator it = ito->second.find( tn ); |
189 |
460575 |
if( it!=ito->second.end() ){ |
190 |
459905 |
return it->second; |
191 |
|
} |
192 |
|
} |
193 |
9271 |
Trace("par-op") << "Parametric operator : " << k << ", " << n.getOperator() << ", " << tn << " : " << n << std::endl; |
194 |
9271 |
d_par_op_map[op][tn] = n; |
195 |
9271 |
return n; |
196 |
|
} |
197 |
4392539 |
else if (inst::TriggerTermInfo::isAtomicTriggerKind(k)) |
198 |
|
{ |
199 |
4195056 |
return n.getOperator(); |
200 |
|
}else{ |
201 |
197483 |
return Node::null(); |
202 |
|
} |
203 |
|
} |
204 |
|
|
205 |
2460247 |
void TermDb::addTerm(Node n) |
206 |
|
{ |
207 |
2460247 |
if (d_processed.find(n) != d_processed.end()) |
208 |
|
{ |
209 |
1464534 |
return; |
210 |
|
} |
211 |
995713 |
d_processed.insert(n); |
212 |
995713 |
if (!TermUtil::hasInstConstAttr(n)) |
213 |
|
{ |
214 |
956751 |
Trace("term-db-debug") << "register term : " << n << std::endl; |
215 |
956751 |
DbList* dlt = getOrMkDbListForType(n.getType()); |
216 |
956751 |
dlt->d_list.push_back(n); |
217 |
|
// if this is an atomic trigger, consider adding it |
218 |
956751 |
if (inst::TriggerTermInfo::isAtomicTrigger(n)) |
219 |
|
{ |
220 |
406332 |
Trace("term-db") << "register term in db " << n << std::endl; |
221 |
|
|
222 |
812664 |
Node op = getMatchOperator(n); |
223 |
406332 |
Trace("term-db-debug") << " match operator is : " << op << std::endl; |
224 |
406332 |
DbList* dlo = getOrMkDbListForOp(op); |
225 |
406332 |
dlo->d_list.push_back(n); |
226 |
|
// If we are higher-order, we may need to register more terms. |
227 |
406332 |
addTermInternal(n); |
228 |
|
} |
229 |
|
} |
230 |
|
else |
231 |
|
{ |
232 |
38962 |
setTermInactive(n); |
233 |
|
} |
234 |
995713 |
if (!n.isClosure()) |
235 |
|
{ |
236 |
2559810 |
for (const Node& nc : n) |
237 |
|
{ |
238 |
1564119 |
addTerm(nc); |
239 |
|
} |
240 |
|
} |
241 |
|
} |
242 |
|
|
243 |
956751 |
DbList* TermDb::getOrMkDbListForType(TypeNode tn) |
244 |
|
{ |
245 |
956751 |
TypeNodeDbListMap::iterator it = d_typeMap.find(tn); |
246 |
956751 |
if (it != d_typeMap.end()) |
247 |
|
{ |
248 |
931920 |
return it->second.get(); |
249 |
|
} |
250 |
49662 |
std::shared_ptr<DbList> dl = std::make_shared<DbList>(d_termsContextUse); |
251 |
24831 |
d_typeMap.insert(tn, dl); |
252 |
24831 |
return dl.get(); |
253 |
|
} |
254 |
|
|
255 |
466104 |
DbList* TermDb::getOrMkDbListForOp(TNode op) |
256 |
|
{ |
257 |
466104 |
NodeDbListMap::iterator it = d_opMap.find(op); |
258 |
466104 |
if (it != d_opMap.end()) |
259 |
|
{ |
260 |
370431 |
return it->second.get(); |
261 |
|
} |
262 |
191346 |
std::shared_ptr<DbList> dl = std::make_shared<DbList>(d_termsContextUse); |
263 |
95673 |
d_opMap.insert(op, dl); |
264 |
95673 |
Assert(op.getKind() != BOUND_VARIABLE); |
265 |
95673 |
d_ops.push_back(op); |
266 |
95673 |
return dl.get(); |
267 |
|
} |
268 |
|
|
269 |
572367 |
void TermDb::computeArgReps( TNode n ) { |
270 |
572367 |
if (d_arg_reps.find(n) == d_arg_reps.end()) |
271 |
|
{ |
272 |
339714 |
eq::EqualityEngine* ee = d_qstate.getEqualityEngine(); |
273 |
1084316 |
for (const TNode& nc : n) |
274 |
|
{ |
275 |
1489204 |
TNode r = ee->hasTerm(nc) ? ee->getRepresentative(nc) : nc; |
276 |
744602 |
d_arg_reps[n].push_back( r ); |
277 |
|
} |
278 |
|
} |
279 |
572367 |
} |
280 |
|
|
281 |
1819408 |
void TermDb::computeUfEqcTerms( TNode f ) { |
282 |
1819408 |
Assert(f == getOperatorRepresentative(f)); |
283 |
1819408 |
if (d_func_map_eqc_trie.find(f) != d_func_map_eqc_trie.end()) |
284 |
|
{ |
285 |
1772957 |
return; |
286 |
|
} |
287 |
46451 |
d_func_map_eqc_trie[f].clear(); |
288 |
|
// get the matchable operators in the equivalence class of f |
289 |
92902 |
std::vector<TNode> ops; |
290 |
46451 |
getOperatorsFor(f, ops); |
291 |
46451 |
eq::EqualityEngine* ee = d_qstate.getEqualityEngine(); |
292 |
92999 |
for (TNode ff : ops) |
293 |
|
{ |
294 |
46548 |
DbList* dbl = getOrMkDbListForOp(ff); |
295 |
341616 |
for (const Node& n : dbl->d_list) |
296 |
|
{ |
297 |
295068 |
if (hasTermCurrent(n) && isTermActive(n)) |
298 |
|
{ |
299 |
279022 |
computeArgReps(n); |
300 |
558044 |
TNode r = ee->hasTerm(n) ? ee->getRepresentative(n) : TNode(n); |
301 |
279022 |
d_func_map_eqc_trie[f].d_data[r].addTerm(n, d_arg_reps[n]); |
302 |
|
} |
303 |
|
} |
304 |
|
} |
305 |
|
} |
306 |
|
|
307 |
3180107 |
void TermDb::computeUfTerms( TNode f ) { |
308 |
3180107 |
if (d_op_nonred_count.find(f) != d_op_nonred_count.end()) |
309 |
|
{ |
310 |
|
// already computed |
311 |
6278533 |
return; |
312 |
|
} |
313 |
40846 |
Assert(f == getOperatorRepresentative(f)); |
314 |
40846 |
d_op_nonred_count[f] = 0; |
315 |
|
// get the matchable operators in the equivalence class of f |
316 |
81681 |
std::vector<TNode> ops; |
317 |
40846 |
getOperatorsFor(f, ops); |
318 |
40846 |
Trace("term-db-debug") << "computeUfTerms for " << f << std::endl; |
319 |
40846 |
unsigned congruentCount = 0; |
320 |
40846 |
unsigned nonCongruentCount = 0; |
321 |
40846 |
unsigned alreadyCongruentCount = 0; |
322 |
40846 |
unsigned relevantCount = 0; |
323 |
40846 |
NodeManager* nm = NodeManager::currentNM(); |
324 |
74714 |
for (TNode ff : ops) |
325 |
|
{ |
326 |
40932 |
NodeDbListMap::iterator it = d_opMap.find(ff); |
327 |
40932 |
if (it == d_opMap.end()) |
328 |
|
{ |
329 |
|
// no terms for this operator |
330 |
7053 |
continue; |
331 |
|
} |
332 |
33879 |
Trace("term-db-debug") << "Adding terms for operator " << ff << std::endl; |
333 |
344155 |
for (const Node& n : it->second->d_list) |
334 |
|
{ |
335 |
|
// to be added to term index, term must be relevant, and exist in EE |
336 |
310287 |
if (!hasTermCurrent(n) || !d_qstate.hasTerm(n)) |
337 |
|
{ |
338 |
|
Trace("term-db-debug") << n << " is not relevant." << std::endl; |
339 |
75673 |
continue; |
340 |
|
} |
341 |
|
|
342 |
310287 |
relevantCount++; |
343 |
327229 |
if (!isTermActive(n)) |
344 |
|
{ |
345 |
16942 |
Trace("term-db-debug") << n << " is already redundant." << std::endl; |
346 |
16942 |
alreadyCongruentCount++; |
347 |
16942 |
continue; |
348 |
|
} |
349 |
|
|
350 |
293345 |
computeArgReps(n); |
351 |
293345 |
Trace("term-db-debug") << "Adding term " << n << " with arg reps : "; |
352 |
941429 |
for (unsigned i = 0, size = d_arg_reps[n].size(); i < size; i++) |
353 |
|
{ |
354 |
648084 |
Trace("term-db-debug") << d_arg_reps[n][i] << " "; |
355 |
2592336 |
if (std::find(d_func_map_rel_dom[f][i].begin(), |
356 |
1296168 |
d_func_map_rel_dom[f][i].end(), |
357 |
2592336 |
d_arg_reps[n][i]) |
358 |
1944252 |
== d_func_map_rel_dom[f][i].end()) |
359 |
|
{ |
360 |
235369 |
d_func_map_rel_dom[f][i].push_back(d_arg_reps[n][i]); |
361 |
|
} |
362 |
|
} |
363 |
293345 |
Trace("term-db-debug") << std::endl; |
364 |
293345 |
Assert(d_qstate.hasTerm(n)); |
365 |
586690 |
Trace("term-db-debug") |
366 |
293345 |
<< " and value : " << d_qstate.getRepresentative(n) << std::endl; |
367 |
527948 |
Node at = d_func_map_trie[f].addOrGetTerm(n, d_arg_reps[n]); |
368 |
293345 |
Assert(d_qstate.hasTerm(at)); |
369 |
293345 |
Trace("term-db-debug2") << "...add term returned " << at << std::endl; |
370 |
352076 |
if (at != n && d_qstate.areEqual(at, n)) |
371 |
|
{ |
372 |
58731 |
setTermInactive(n); |
373 |
58731 |
Trace("term-db-debug") << n << " is redundant." << std::endl; |
374 |
58731 |
congruentCount++; |
375 |
58731 |
continue; |
376 |
|
} |
377 |
469217 |
std::vector<Node> lits; |
378 |
234614 |
if (checkCongruentDisequal(at, n, lits)) |
379 |
|
{ |
380 |
11 |
Assert(at.getNumChildren() == n.getNumChildren()); |
381 |
41 |
for (size_t k = 0, size = at.getNumChildren(); k < size; k++) |
382 |
|
{ |
383 |
30 |
if (at[k] != n[k]) |
384 |
|
{ |
385 |
18 |
lits.push_back(nm->mkNode(EQUAL, at[k], n[k]).negate()); |
386 |
|
} |
387 |
|
} |
388 |
22 |
Node lem = nm->mkOr(lits); |
389 |
11 |
if (Trace.isOn("term-db-lemma")) |
390 |
|
{ |
391 |
|
Trace("term-db-lemma") << "Disequal congruent terms : " << at << " " |
392 |
|
<< n << "!!!!" << std::endl; |
393 |
|
if (!d_qstate.getValuation().needCheck()) |
394 |
|
{ |
395 |
|
Trace("term-db-lemma") |
396 |
|
<< " all theories passed with no lemmas." << std::endl; |
397 |
|
// we should be a full effort check, prior to theory combination |
398 |
|
} |
399 |
|
Trace("term-db-lemma") << " add lemma : " << lem << std::endl; |
400 |
|
} |
401 |
11 |
d_qim->addPendingLemma(lem, InferenceId::QUANTIFIERS_TDB_DEQ_CONG); |
402 |
11 |
d_qstate.notifyInConflict(); |
403 |
11 |
d_consistent_ee = false; |
404 |
11 |
return; |
405 |
|
} |
406 |
234603 |
nonCongruentCount++; |
407 |
234603 |
d_op_nonred_count[f]++; |
408 |
|
} |
409 |
33868 |
if (Trace.isOn("tdb")) |
410 |
|
{ |
411 |
|
Trace("tdb") << "Term db size [" << f << "] : " << nonCongruentCount |
412 |
|
<< " / "; |
413 |
|
Trace("tdb") << (nonCongruentCount + congruentCount) << " / " |
414 |
|
<< (nonCongruentCount + congruentCount |
415 |
|
+ alreadyCongruentCount) |
416 |
|
<< " / "; |
417 |
|
Trace("tdb") << relevantCount << " / " << it->second->d_list.size() |
418 |
|
<< std::endl; |
419 |
|
} |
420 |
|
} |
421 |
|
} |
422 |
|
|
423 |
6362311 |
Node TermDb::getOperatorRepresentative(TNode op) const { return op; } |
424 |
|
|
425 |
226584 |
bool TermDb::checkCongruentDisequal(TNode a, TNode b, std::vector<Node>& exp) |
426 |
|
{ |
427 |
226584 |
if (d_qstate.areDisequal(a, b)) |
428 |
|
{ |
429 |
11 |
exp.push_back(a.eqNode(b)); |
430 |
11 |
return true; |
431 |
|
} |
432 |
226573 |
return false; |
433 |
|
} |
434 |
|
|
435 |
2137827 |
bool TermDb::inRelevantDomain( TNode f, unsigned i, TNode r ) { |
436 |
|
// notice if we are not higher-order, getOperatorRepresentative is a no-op |
437 |
2137827 |
f = getOperatorRepresentative(f); |
438 |
2137827 |
computeUfTerms( f ); |
439 |
2137827 |
Assert(!d_qstate.getEqualityEngine()->hasTerm(r) |
440 |
|
|| d_qstate.getEqualityEngine()->getRepresentative(r) == r); |
441 |
2137827 |
std::map< Node, std::map< unsigned, std::vector< Node > > >::iterator it = d_func_map_rel_dom.find( f ); |
442 |
2137827 |
if( it != d_func_map_rel_dom.end() ){ |
443 |
2113341 |
std::map< unsigned, std::vector< Node > >::iterator it2 = it->second.find( i ); |
444 |
2113341 |
if( it2!=it->second.end() ){ |
445 |
2113341 |
return std::find( it2->second.begin(), it2->second.end(), r )!=it2->second.end(); |
446 |
|
}else{ |
447 |
|
return false; |
448 |
|
} |
449 |
|
}else{ |
450 |
24486 |
return false; |
451 |
|
} |
452 |
|
} |
453 |
|
|
454 |
584955 |
Node TermDb::evaluateTerm2(TNode n, |
455 |
|
std::map<TNode, Node>& visited, |
456 |
|
std::vector<Node>& exp, |
457 |
|
bool useEntailmentTests, |
458 |
|
bool computeExp, |
459 |
|
bool reqHasTerm) |
460 |
|
{ |
461 |
584955 |
std::map< TNode, Node >::iterator itv = visited.find( n ); |
462 |
584955 |
if( itv != visited.end() ){ |
463 |
44225 |
return itv->second; |
464 |
|
} |
465 |
540730 |
size_t prevSize = exp.size(); |
466 |
540730 |
Trace("term-db-eval") << "evaluate term : " << n << std::endl; |
467 |
1081460 |
Node ret = n; |
468 |
540730 |
if( n.getKind()==FORALL || n.getKind()==BOUND_VARIABLE ){ |
469 |
|
//do nothing |
470 |
|
} |
471 |
538267 |
else if (d_qstate.hasTerm(n)) |
472 |
|
{ |
473 |
252958 |
Trace("term-db-eval") << "...exists in ee, return rep" << std::endl; |
474 |
252958 |
ret = d_qstate.getRepresentative(n); |
475 |
252958 |
if (computeExp) |
476 |
|
{ |
477 |
|
if (n != ret) |
478 |
|
{ |
479 |
|
exp.push_back(n.eqNode(ret)); |
480 |
|
} |
481 |
|
} |
482 |
252958 |
reqHasTerm = false; |
483 |
|
} |
484 |
285309 |
else if (n.hasOperator()) |
485 |
|
{ |
486 |
569748 |
std::vector<TNode> args; |
487 |
284874 |
bool ret_set = false; |
488 |
284874 |
Kind k = n.getKind(); |
489 |
569748 |
std::vector<Node> tempExp; |
490 |
648429 |
for (unsigned i = 0, nchild = n.getNumChildren(); i < nchild; i++) |
491 |
|
{ |
492 |
979440 |
TNode c = evaluateTerm2(n[i], |
493 |
|
visited, |
494 |
|
tempExp, |
495 |
|
useEntailmentTests, |
496 |
|
computeExp, |
497 |
853275 |
reqHasTerm); |
498 |
489720 |
if (c.isNull()) |
499 |
|
{ |
500 |
89823 |
ret = Node::null(); |
501 |
89823 |
ret_set = true; |
502 |
89823 |
break; |
503 |
|
} |
504 |
399897 |
else if (c == d_true || c == d_false) |
505 |
|
{ |
506 |
|
// short-circuiting |
507 |
197322 |
if ((k == AND && c == d_false) || (k == OR && c == d_true)) |
508 |
|
{ |
509 |
32135 |
ret = c; |
510 |
32135 |
ret_set = true; |
511 |
32135 |
reqHasTerm = false; |
512 |
32135 |
break; |
513 |
|
} |
514 |
165187 |
else if (k == ITE && i == 0) |
515 |
|
{ |
516 |
4207 |
ret = evaluateTerm2(n[c == d_true ? 1 : 2], |
517 |
|
visited, |
518 |
|
tempExp, |
519 |
|
useEntailmentTests, |
520 |
|
computeExp, |
521 |
|
reqHasTerm); |
522 |
4207 |
ret_set = true; |
523 |
4207 |
reqHasTerm = false; |
524 |
4207 |
break; |
525 |
|
} |
526 |
|
} |
527 |
363555 |
if (computeExp) |
528 |
|
{ |
529 |
|
exp.insert(exp.end(), tempExp.begin(), tempExp.end()); |
530 |
|
} |
531 |
363555 |
Trace("term-db-eval") << " child " << i << " : " << c << std::endl; |
532 |
363555 |
args.push_back(c); |
533 |
|
} |
534 |
284874 |
if (ret_set) |
535 |
|
{ |
536 |
|
// if we short circuited |
537 |
126165 |
if (computeExp) |
538 |
|
{ |
539 |
|
exp.clear(); |
540 |
|
exp.insert(exp.end(), tempExp.begin(), tempExp.end()); |
541 |
|
} |
542 |
|
} |
543 |
|
else |
544 |
|
{ |
545 |
|
// get the (indexed) operator of n, if it exists |
546 |
317418 |
TNode f = getMatchOperator(n); |
547 |
|
// if it is an indexed term, return the congruent term |
548 |
158709 |
if (!f.isNull()) |
549 |
|
{ |
550 |
|
// if f is congruent to a term indexed by this class |
551 |
120026 |
TNode nn = getCongruentTerm(f, args); |
552 |
120026 |
Trace("term-db-eval") << " got congruent term " << nn |
553 |
60013 |
<< " from DB for " << n << std::endl; |
554 |
60013 |
if (!nn.isNull()) |
555 |
|
{ |
556 |
20243 |
if (computeExp) |
557 |
|
{ |
558 |
|
Assert(nn.getNumChildren() == n.getNumChildren()); |
559 |
|
for (unsigned i = 0, nchild = nn.getNumChildren(); i < nchild; i++) |
560 |
|
{ |
561 |
|
if (nn[i] != n[i]) |
562 |
|
{ |
563 |
|
exp.push_back(nn[i].eqNode(n[i])); |
564 |
|
} |
565 |
|
} |
566 |
|
} |
567 |
20243 |
ret = d_qstate.getRepresentative(nn); |
568 |
20243 |
Trace("term-db-eval") << "return rep" << std::endl; |
569 |
20243 |
ret_set = true; |
570 |
20243 |
reqHasTerm = false; |
571 |
20243 |
Assert(!ret.isNull()); |
572 |
20243 |
if (computeExp) |
573 |
|
{ |
574 |
|
if (n != ret) |
575 |
|
{ |
576 |
|
exp.push_back(nn.eqNode(ret)); |
577 |
|
} |
578 |
|
} |
579 |
|
} |
580 |
|
} |
581 |
158709 |
if( !ret_set ){ |
582 |
138466 |
Trace("term-db-eval") << "return rewrite" << std::endl; |
583 |
|
// a theory symbol or a new UF term |
584 |
138466 |
if (n.getMetaKind() == metakind::PARAMETERIZED) |
585 |
|
{ |
586 |
39631 |
args.insert(args.begin(), n.getOperator()); |
587 |
|
} |
588 |
138466 |
ret = NodeManager::currentNM()->mkNode(n.getKind(), args); |
589 |
138466 |
ret = Rewriter::rewrite(ret); |
590 |
138466 |
if (ret.getKind() == EQUAL) |
591 |
|
{ |
592 |
16397 |
if (d_qstate.areDisequal(ret[0], ret[1])) |
593 |
|
{ |
594 |
4706 |
ret = d_false; |
595 |
|
} |
596 |
|
} |
597 |
138466 |
if (useEntailmentTests) |
598 |
|
{ |
599 |
1359 |
if (ret.getKind() == EQUAL || ret.getKind() == GEQ) |
600 |
|
{ |
601 |
15 |
Valuation& val = d_qstate.getValuation(); |
602 |
41 |
for (unsigned j = 0; j < 2; j++) |
603 |
|
{ |
604 |
|
std::pair<bool, Node> et = val.entailmentCheck( |
605 |
|
options::TheoryOfMode::THEORY_OF_TYPE_BASED, |
606 |
56 |
j == 0 ? ret : ret.negate()); |
607 |
30 |
if (et.first) |
608 |
|
{ |
609 |
4 |
ret = j == 0 ? d_true : d_false; |
610 |
4 |
if (computeExp) |
611 |
|
{ |
612 |
|
exp.push_back(et.second); |
613 |
|
} |
614 |
4 |
break; |
615 |
|
} |
616 |
|
} |
617 |
|
} |
618 |
|
} |
619 |
|
} |
620 |
|
} |
621 |
|
} |
622 |
|
// must have the term |
623 |
540730 |
if (reqHasTerm && !ret.isNull()) |
624 |
|
{ |
625 |
136548 |
Kind k = ret.getKind(); |
626 |
136548 |
if (k != OR && k != AND && k != EQUAL && k != ITE && k != NOT |
627 |
122332 |
&& k != FORALL) |
628 |
|
{ |
629 |
122137 |
if (!d_qstate.hasTerm(ret)) |
630 |
|
{ |
631 |
37423 |
ret = Node::null(); |
632 |
|
} |
633 |
|
} |
634 |
|
} |
635 |
1081460 |
Trace("term-db-eval") << "evaluated term : " << n << ", got : " << ret |
636 |
540730 |
<< ", reqHasTerm = " << reqHasTerm << std::endl; |
637 |
|
// clear the explanation if failed |
638 |
540730 |
if (computeExp && ret.isNull()) |
639 |
|
{ |
640 |
|
exp.resize(prevSize); |
641 |
|
} |
642 |
540730 |
visited[n] = ret; |
643 |
540730 |
return ret; |
644 |
|
} |
645 |
|
|
646 |
9164589 |
TNode TermDb::getEntailedTerm2(TNode n, |
647 |
|
std::map<TNode, TNode>& subs, |
648 |
|
bool subsRep, |
649 |
|
bool hasSubs) |
650 |
|
{ |
651 |
9164589 |
Trace("term-db-entail") << "get entailed term : " << n << std::endl; |
652 |
9164589 |
if (d_qstate.hasTerm(n)) |
653 |
|
{ |
654 |
2839882 |
Trace("term-db-entail") << "...exists in ee, return rep " << std::endl; |
655 |
2839882 |
return n; |
656 |
6324707 |
}else if( n.getKind()==BOUND_VARIABLE ){ |
657 |
3612942 |
if( hasSubs ){ |
658 |
3612942 |
std::map< TNode, TNode >::iterator it = subs.find( n ); |
659 |
3612942 |
if( it!=subs.end() ){ |
660 |
2689696 |
Trace("term-db-entail") << "...substitution is : " << it->second << std::endl; |
661 |
2689696 |
if( subsRep ){ |
662 |
348105 |
Assert(d_qstate.hasTerm(it->second)); |
663 |
348105 |
Assert(d_qstate.getRepresentative(it->second) == it->second); |
664 |
3037801 |
return it->second; |
665 |
|
} |
666 |
2341591 |
return getEntailedTerm2(it->second, subs, subsRep, hasSubs); |
667 |
|
} |
668 |
|
} |
669 |
2711765 |
}else if( n.getKind()==ITE ){ |
670 |
26068 |
for( unsigned i=0; i<2; i++ ){ |
671 |
21513 |
if (isEntailed2(n[0], subs, subsRep, hasSubs, i == 0)) |
672 |
|
{ |
673 |
7716 |
return getEntailedTerm2(n[i == 0 ? 1 : 2], subs, subsRep, hasSubs); |
674 |
|
} |
675 |
|
} |
676 |
|
}else{ |
677 |
2699494 |
if( n.hasOperator() ){ |
678 |
2705443 |
TNode f = getMatchOperator( n ); |
679 |
2692618 |
if( !f.isNull() ){ |
680 |
5359586 |
std::vector< TNode > args; |
681 |
5698797 |
for( unsigned i=0; i<n.getNumChildren(); i++ ){ |
682 |
7756092 |
TNode c = getEntailedTerm2(n[i], subs, subsRep, hasSubs); |
683 |
4737088 |
if( c.isNull() ){ |
684 |
1718084 |
return TNode::null(); |
685 |
|
} |
686 |
3019004 |
c = d_qstate.getRepresentative(c); |
687 |
3019004 |
Trace("term-db-entail") << " child " << i << " : " << c << std::endl; |
688 |
3019004 |
args.push_back( c ); |
689 |
|
} |
690 |
1923418 |
TNode nn = getCongruentTerm(f, args); |
691 |
961709 |
Trace("term-db-entail") << " got congruent term " << nn << " for " << n << std::endl; |
692 |
961709 |
return nn; |
693 |
|
} |
694 |
|
} |
695 |
|
} |
696 |
947502 |
return TNode::null(); |
697 |
|
} |
698 |
|
|
699 |
91028 |
Node TermDb::evaluateTerm(TNode n, |
700 |
|
bool useEntailmentTests, |
701 |
|
bool reqHasTerm) |
702 |
|
{ |
703 |
182056 |
std::map< TNode, Node > visited; |
704 |
182056 |
std::vector<Node> exp; |
705 |
182056 |
return evaluateTerm2(n, visited, exp, useEntailmentTests, false, reqHasTerm); |
706 |
|
} |
707 |
|
|
708 |
|
Node TermDb::evaluateTerm(TNode n, |
709 |
|
std::vector<Node>& exp, |
710 |
|
bool useEntailmentTests, |
711 |
|
bool reqHasTerm) |
712 |
|
{ |
713 |
|
std::map<TNode, Node> visited; |
714 |
|
return evaluateTerm2(n, visited, exp, useEntailmentTests, true, reqHasTerm); |
715 |
|
} |
716 |
|
|
717 |
860201 |
TNode TermDb::getEntailedTerm(TNode n, |
718 |
|
std::map<TNode, TNode>& subs, |
719 |
|
bool subsRep) |
720 |
|
{ |
721 |
860201 |
return getEntailedTerm2(n, subs, subsRep, true); |
722 |
|
} |
723 |
|
|
724 |
87492 |
TNode TermDb::getEntailedTerm(TNode n) |
725 |
|
{ |
726 |
174984 |
std::map< TNode, TNode > subs; |
727 |
174984 |
return getEntailedTerm2(n, subs, false, false); |
728 |
|
} |
729 |
|
|
730 |
1789813 |
bool TermDb::isEntailed2( |
731 |
|
TNode n, std::map<TNode, TNode>& subs, bool subsRep, bool hasSubs, bool pol) |
732 |
|
{ |
733 |
1789813 |
Trace("term-db-entail") << "Check entailed : " << n << ", pol = " << pol << std::endl; |
734 |
1789813 |
Assert(n.getType().isBoolean()); |
735 |
1789813 |
if( n.getKind()==EQUAL && !n[0].getType().isBoolean() ){ |
736 |
569801 |
TNode n1 = getEntailedTerm2(n[0], subs, subsRep, hasSubs); |
737 |
414027 |
if( !n1.isNull() ){ |
738 |
498911 |
TNode n2 = getEntailedTerm2(n[1], subs, subsRep, hasSubs); |
739 |
378582 |
if( !n2.isNull() ){ |
740 |
258253 |
if( n1==n2 ){ |
741 |
22652 |
return pol; |
742 |
|
}else{ |
743 |
235601 |
Assert(d_qstate.hasTerm(n1)); |
744 |
235601 |
Assert(d_qstate.hasTerm(n2)); |
745 |
235601 |
if( pol ){ |
746 |
121361 |
return d_qstate.areEqual(n1, n2); |
747 |
|
}else{ |
748 |
114240 |
return d_qstate.areDisequal(n1, n2); |
749 |
|
} |
750 |
|
} |
751 |
|
} |
752 |
|
} |
753 |
1375786 |
}else if( n.getKind()==NOT ){ |
754 |
456263 |
return isEntailed2(n[0], subs, subsRep, hasSubs, !pol); |
755 |
919523 |
}else if( n.getKind()==OR || n.getKind()==AND ){ |
756 |
306681 |
bool simPol = ( pol && n.getKind()==OR ) || ( !pol && n.getKind()==AND ); |
757 |
1021544 |
for( unsigned i=0; i<n.getNumChildren(); i++ ){ |
758 |
860523 |
if (isEntailed2(n[i], subs, subsRep, hasSubs, pol)) |
759 |
|
{ |
760 |
177626 |
if( simPol ){ |
761 |
63415 |
return true; |
762 |
|
} |
763 |
|
}else{ |
764 |
682897 |
if( !simPol ){ |
765 |
82245 |
return false; |
766 |
|
} |
767 |
|
} |
768 |
|
} |
769 |
161021 |
return !simPol; |
770 |
|
//Boolean equality here |
771 |
612842 |
}else if( n.getKind()==EQUAL || n.getKind()==ITE ){ |
772 |
80591 |
for( unsigned i=0; i<2; i++ ){ |
773 |
67597 |
if (isEntailed2(n[0], subs, subsRep, hasSubs, i == 0)) |
774 |
|
{ |
775 |
29395 |
unsigned ch = ( n.getKind()==EQUAL || i==0 ) ? 1 : 2; |
776 |
29395 |
bool reqPol = ( n.getKind()==ITE || i==0 ) ? pol : !pol; |
777 |
29395 |
return isEntailed2(n[ch], subs, subsRep, hasSubs, reqPol); |
778 |
|
} |
779 |
|
} |
780 |
570453 |
}else if( n.getKind()==APPLY_UF ){ |
781 |
454538 |
TNode n1 = getEntailedTerm2(n, subs, subsRep, hasSubs); |
782 |
337892 |
if( !n1.isNull() ){ |
783 |
221246 |
Assert(d_qstate.hasTerm(n1)); |
784 |
221246 |
if( n1==d_true ){ |
785 |
|
return pol; |
786 |
221246 |
}else if( n1==d_false ){ |
787 |
|
return !pol; |
788 |
|
}else{ |
789 |
221246 |
return d_qstate.getRepresentative(n1) == (pol ? d_true : d_false); |
790 |
|
} |
791 |
|
} |
792 |
232561 |
}else if( n.getKind()==FORALL && !pol ){ |
793 |
4790 |
return isEntailed2(n[1], subs, subsRep, hasSubs, pol); |
794 |
|
} |
795 |
513185 |
return false; |
796 |
|
} |
797 |
|
|
798 |
1416 |
bool TermDb::isEntailed(TNode n, bool pol) |
799 |
|
{ |
800 |
1416 |
Assert(d_consistent_ee); |
801 |
2832 |
std::map< TNode, TNode > subs; |
802 |
2832 |
return isEntailed2(n, subs, false, false, pol); |
803 |
|
} |
804 |
|
|
805 |
348316 |
bool TermDb::isEntailed(TNode n, |
806 |
|
std::map<TNode, TNode>& subs, |
807 |
|
bool subsRep, |
808 |
|
bool pol) |
809 |
|
{ |
810 |
348316 |
Assert(d_consistent_ee); |
811 |
348316 |
return isEntailed2(n, subs, subsRep, true, pol); |
812 |
|
} |
813 |
|
|
814 |
4401929 |
bool TermDb::isTermActive( Node n ) { |
815 |
4401929 |
return d_inactive_map.find( n )==d_inactive_map.end(); |
816 |
|
//return !n.getAttribute(NoMatchAttribute()); |
817 |
|
} |
818 |
|
|
819 |
156859 |
void TermDb::setTermInactive( Node n ) { |
820 |
156859 |
d_inactive_map[n] = true; |
821 |
|
//Trace("term-db-debug2") << "set no match attribute" << std::endl; |
822 |
|
//NoMatchAttribute nma; |
823 |
|
//n.setAttribute(nma,true); |
824 |
156859 |
} |
825 |
|
|
826 |
4386398 |
bool TermDb::hasTermCurrent( Node n, bool useMode ) { |
827 |
4386398 |
if( !useMode ){ |
828 |
|
return d_has_map.find( n )!=d_has_map.end(); |
829 |
|
} |
830 |
|
//some assertions are not sent to EE |
831 |
4386398 |
if (options::termDbMode() == options::TermDbMode::ALL) |
832 |
|
{ |
833 |
4386398 |
return true; |
834 |
|
} |
835 |
|
else if (options::termDbMode() == options::TermDbMode::RELEVANT) |
836 |
|
{ |
837 |
|
return d_has_map.find( n )!=d_has_map.end(); |
838 |
|
} |
839 |
|
Assert(false) << "TermDb::hasTermCurrent: Unknown termDbMode : " << options::termDbMode(); |
840 |
|
return false; |
841 |
|
} |
842 |
|
|
843 |
1146 |
bool TermDb::isTermEligibleForInstantiation(TNode n, TNode f) |
844 |
|
{ |
845 |
1146 |
if( options::instMaxLevel()!=-1 ){ |
846 |
970 |
if( n.hasAttribute(InstLevelAttribute()) ){ |
847 |
|
int64_t fml = |
848 |
970 |
f.isNull() ? -1 : d_qreg.getQuantAttributes().getQuantInstLevel(f); |
849 |
970 |
unsigned ml = fml>=0 ? fml : options::instMaxLevel(); |
850 |
|
|
851 |
970 |
if( n.getAttribute(InstLevelAttribute())>ml ){ |
852 |
|
Trace("inst-add-debug") << "Term " << n << " has instantiation level " << n.getAttribute(InstLevelAttribute()); |
853 |
|
Trace("inst-add-debug") << ", which is more than maximum allowed level " << ml << " for this quantified formula." << std::endl; |
854 |
|
return false; |
855 |
|
} |
856 |
|
}else{ |
857 |
|
if( options::instLevelInputOnly() ){ |
858 |
|
Trace("inst-add-debug") << "Term " << n << " does not have an instantiation level." << std::endl; |
859 |
|
return false; |
860 |
|
} |
861 |
|
} |
862 |
|
} |
863 |
|
// it cannot have instantiation constants, which originate from |
864 |
|
// counterexample-guided instantiation strategies. |
865 |
1146 |
return !TermUtil::hasInstConstAttr(n); |
866 |
|
} |
867 |
|
|
868 |
176 |
Node TermDb::getEligibleTermInEqc( TNode r ) { |
869 |
176 |
if( isTermEligibleForInstantiation( r, TNode::null() ) ){ |
870 |
176 |
return r; |
871 |
|
}else{ |
872 |
|
std::map< Node, Node >::iterator it = d_term_elig_eqc.find( r ); |
873 |
|
if( it==d_term_elig_eqc.end() ){ |
874 |
|
Node h; |
875 |
|
eq::EqualityEngine* ee = d_qstate.getEqualityEngine(); |
876 |
|
eq::EqClassIterator eqc_i = eq::EqClassIterator(r, ee); |
877 |
|
while (!eqc_i.isFinished()) |
878 |
|
{ |
879 |
|
TNode n = (*eqc_i); |
880 |
|
++eqc_i; |
881 |
|
if (isTermEligibleForInstantiation(n, TNode::null())) |
882 |
|
{ |
883 |
|
h = n; |
884 |
|
break; |
885 |
|
} |
886 |
|
} |
887 |
|
d_term_elig_eqc[r] = h; |
888 |
|
return h; |
889 |
|
}else{ |
890 |
|
return it->second; |
891 |
|
} |
892 |
|
} |
893 |
|
} |
894 |
|
|
895 |
27559 |
bool TermDb::resetInternal(Theory::Effort e) |
896 |
|
{ |
897 |
|
// do nothing |
898 |
27559 |
return true; |
899 |
|
} |
900 |
|
|
901 |
27559 |
bool TermDb::finishResetInternal(Theory::Effort e) |
902 |
|
{ |
903 |
|
// do nothing |
904 |
27559 |
return true; |
905 |
|
} |
906 |
|
|
907 |
369679 |
void TermDb::addTermInternal(Node n) |
908 |
|
{ |
909 |
|
// do nothing |
910 |
369679 |
} |
911 |
|
|
912 |
84334 |
void TermDb::getOperatorsFor(TNode f, std::vector<TNode>& ops) |
913 |
|
{ |
914 |
84334 |
ops.push_back(f); |
915 |
84334 |
} |
916 |
|
|
917 |
|
void TermDb::setHasTerm( Node n ) { |
918 |
|
Trace("term-db-debug2") << "hasTerm : " << n << std::endl; |
919 |
|
if( d_has_map.find( n )==d_has_map.end() ){ |
920 |
|
d_has_map[n] = true; |
921 |
|
for( unsigned i=0; i<n.getNumChildren(); i++ ){ |
922 |
|
setHasTerm( n[i] ); |
923 |
|
} |
924 |
|
} |
925 |
|
} |
926 |
|
|
927 |
8213 |
void TermDb::presolve() { |
928 |
8213 |
if (options::incrementalSolving() && !options::termDbCd()) |
929 |
|
{ |
930 |
|
d_termsContext.pop(); |
931 |
|
d_termsContext.push(); |
932 |
|
} |
933 |
8213 |
} |
934 |
|
|
935 |
28475 |
bool TermDb::reset( Theory::Effort effort ){ |
936 |
28475 |
d_op_nonred_count.clear(); |
937 |
28475 |
d_arg_reps.clear(); |
938 |
28475 |
d_func_map_trie.clear(); |
939 |
28475 |
d_func_map_eqc_trie.clear(); |
940 |
28475 |
d_func_map_rel_dom.clear(); |
941 |
28475 |
d_consistent_ee = true; |
942 |
|
|
943 |
28475 |
eq::EqualityEngine* ee = d_qstate.getEqualityEngine(); |
944 |
|
|
945 |
28475 |
Assert(ee->consistent()); |
946 |
|
// if higher-order, add equalities for the purification terms now |
947 |
28475 |
if (!resetInternal(effort)) |
948 |
|
{ |
949 |
|
return false; |
950 |
|
} |
951 |
|
|
952 |
|
//compute has map |
953 |
28475 |
if (options::termDbMode() == options::TermDbMode::RELEVANT) |
954 |
|
{ |
955 |
|
d_has_map.clear(); |
956 |
|
d_term_elig_eqc.clear(); |
957 |
|
eq::EqClassesIterator eqcs_i = eq::EqClassesIterator( ee ); |
958 |
|
while( !eqcs_i.isFinished() ){ |
959 |
|
TNode r = (*eqcs_i); |
960 |
|
bool addedFirst = false; |
961 |
|
Node first; |
962 |
|
//TODO: ignoring singleton eqc isn't enough, need to ensure eqc are relevant |
963 |
|
eq::EqClassIterator eqc_i = eq::EqClassIterator(r, ee); |
964 |
|
while( !eqc_i.isFinished() ){ |
965 |
|
TNode n = (*eqc_i); |
966 |
|
if( first.isNull() ){ |
967 |
|
first = n; |
968 |
|
}else{ |
969 |
|
if( !addedFirst ){ |
970 |
|
addedFirst = true; |
971 |
|
setHasTerm( first ); |
972 |
|
} |
973 |
|
setHasTerm( n ); |
974 |
|
} |
975 |
|
++eqc_i; |
976 |
|
} |
977 |
|
++eqcs_i; |
978 |
|
} |
979 |
|
const LogicInfo& logicInfo = d_qstate.getLogicInfo(); |
980 |
|
for (TheoryId theoryId = THEORY_FIRST; theoryId < THEORY_LAST; ++theoryId) |
981 |
|
{ |
982 |
|
if (!logicInfo.isTheoryEnabled(theoryId)) |
983 |
|
{ |
984 |
|
continue; |
985 |
|
} |
986 |
|
for (context::CDList<Assertion>::const_iterator |
987 |
|
it = d_qstate.factsBegin(theoryId), |
988 |
|
it_end = d_qstate.factsEnd(theoryId); |
989 |
|
it != it_end; |
990 |
|
++it) |
991 |
|
{ |
992 |
|
setHasTerm((*it).d_assertion); |
993 |
|
} |
994 |
|
} |
995 |
|
} |
996 |
|
// finish reset |
997 |
28475 |
return finishResetInternal(effort); |
998 |
|
} |
999 |
|
|
1000 |
20558 |
TNodeTrie* TermDb::getTermArgTrie(Node f) |
1001 |
|
{ |
1002 |
20558 |
f = getOperatorRepresentative(f); |
1003 |
20558 |
computeUfTerms( f ); |
1004 |
20558 |
std::map<Node, TNodeTrie>::iterator itut = d_func_map_trie.find(f); |
1005 |
20558 |
if( itut!=d_func_map_trie.end() ){ |
1006 |
12136 |
return &itut->second; |
1007 |
|
}else{ |
1008 |
8422 |
return NULL; |
1009 |
|
} |
1010 |
|
} |
1011 |
|
|
1012 |
1819408 |
TNodeTrie* TermDb::getTermArgTrie(Node eqc, Node f) |
1013 |
|
{ |
1014 |
1819408 |
f = getOperatorRepresentative(f); |
1015 |
1819408 |
computeUfEqcTerms( f ); |
1016 |
1819408 |
std::map<Node, TNodeTrie>::iterator itut = d_func_map_eqc_trie.find(f); |
1017 |
1819408 |
if( itut==d_func_map_eqc_trie.end() ){ |
1018 |
|
return NULL; |
1019 |
|
}else{ |
1020 |
1819408 |
if( eqc.isNull() ){ |
1021 |
906990 |
return &itut->second; |
1022 |
|
}else{ |
1023 |
|
std::map<TNode, TNodeTrie>::iterator itute = |
1024 |
912418 |
itut->second.d_data.find(eqc); |
1025 |
912418 |
if( itute!=itut->second.d_data.end() ){ |
1026 |
560132 |
return &itute->second; |
1027 |
|
}else{ |
1028 |
352286 |
return NULL; |
1029 |
|
} |
1030 |
|
} |
1031 |
|
} |
1032 |
|
} |
1033 |
|
|
1034 |
|
TNode TermDb::getCongruentTerm( Node f, Node n ) { |
1035 |
|
f = getOperatorRepresentative(f); |
1036 |
|
computeUfTerms( f ); |
1037 |
|
std::map<Node, TNodeTrie>::iterator itut = d_func_map_trie.find(f); |
1038 |
|
if( itut!=d_func_map_trie.end() ){ |
1039 |
|
computeArgReps( n ); |
1040 |
|
return itut->second.existsTerm( d_arg_reps[n] ); |
1041 |
|
}else{ |
1042 |
|
return TNode::null(); |
1043 |
|
} |
1044 |
|
} |
1045 |
|
|
1046 |
1021722 |
TNode TermDb::getCongruentTerm( Node f, std::vector< TNode >& args ) { |
1047 |
1021722 |
f = getOperatorRepresentative(f); |
1048 |
1021722 |
computeUfTerms( f ); |
1049 |
1021722 |
return d_func_map_trie[f].existsTerm( args ); |
1050 |
|
} |
1051 |
|
|
1052 |
|
} // namespace quantifiers |
1053 |
|
} // namespace theory |
1054 |
29505 |
} // namespace cvc5 |