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 |
6278 |
TermDb::TermDb(Env& env, QuantifiersState& qs, QuantifiersRegistry& qr) |
41 |
|
: QuantifiersUtil(env), |
42 |
|
d_qstate(qs), |
43 |
|
d_qim(nullptr), |
44 |
|
d_qreg(qr), |
45 |
|
d_termsContext(), |
46 |
6278 |
d_termsContextUse(options::termDbCd() ? context() : &d_termsContext), |
47 |
|
d_processed(d_termsContextUse), |
48 |
|
d_typeMap(d_termsContextUse), |
49 |
|
d_ops(d_termsContextUse), |
50 |
|
d_opMap(d_termsContextUse), |
51 |
12556 |
d_inactive_map(context()) |
52 |
|
{ |
53 |
6278 |
d_consistent_ee = true; |
54 |
6278 |
d_true = NodeManager::currentNM()->mkConst(true); |
55 |
6278 |
d_false = NodeManager::currentNM()->mkConst(false); |
56 |
6278 |
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 |
6278 |
} |
63 |
|
|
64 |
12431 |
TermDb::~TermDb(){ |
65 |
|
|
66 |
12431 |
} |
67 |
|
|
68 |
6278 |
void TermDb::finishInit(QuantifiersInferenceManager* qim) { d_qim = qim; } |
69 |
|
|
70 |
10532 |
void TermDb::registerQuantifier( Node q ) { |
71 |
10532 |
Assert(q[0].getNumChildren() == d_qreg.getNumInstantiationConstants(q)); |
72 |
34316 |
for (size_t i = 0, nvars = q[0].getNumChildren(); i < nvars; i++) |
73 |
|
{ |
74 |
47568 |
Node ic = d_qreg.getInstantiationConstant(q, i); |
75 |
23784 |
setTermInactive( ic ); |
76 |
|
} |
77 |
10532 |
} |
78 |
|
|
79 |
283 |
size_t TermDb::getNumOperators() const { return d_ops.size(); } |
80 |
|
|
81 |
878 |
Node TermDb::getOperator(size_t i) const |
82 |
|
{ |
83 |
878 |
Assert(i < d_ops.size()); |
84 |
878 |
return d_ops[i]; |
85 |
|
} |
86 |
|
|
87 |
|
/** ground terms */ |
88 |
147268 |
size_t TermDb::getNumGroundTerms(Node f) const |
89 |
|
{ |
90 |
147268 |
NodeDbListMap::const_iterator it = d_opMap.find(f); |
91 |
147268 |
if (it != d_opMap.end()) |
92 |
|
{ |
93 |
143091 |
return it->second->d_list.size(); |
94 |
|
} |
95 |
4177 |
return 0; |
96 |
|
} |
97 |
|
|
98 |
899863 |
Node TermDb::getGroundTerm(Node f, size_t i) const |
99 |
|
{ |
100 |
899863 |
NodeDbListMap::const_iterator it = d_opMap.find(f); |
101 |
899863 |
if (it != d_opMap.end()) |
102 |
|
{ |
103 |
899863 |
Assert(i < it->second->d_list.size()); |
104 |
899863 |
return it->second->d_list[i]; |
105 |
|
} |
106 |
|
Assert(false); |
107 |
|
return Node::null(); |
108 |
|
} |
109 |
|
|
110 |
193 |
size_t TermDb::getNumTypeGroundTerms(TypeNode tn) const |
111 |
|
{ |
112 |
193 |
TypeNodeDbListMap::const_iterator it = d_typeMap.find(tn); |
113 |
193 |
if (it != d_typeMap.end()) |
114 |
|
{ |
115 |
184 |
return it->second->d_list.size(); |
116 |
|
} |
117 |
9 |
return 0; |
118 |
|
} |
119 |
|
|
120 |
9874 |
Node TermDb::getTypeGroundTerm(TypeNode tn, size_t i) const |
121 |
|
{ |
122 |
9874 |
TypeNodeDbListMap::const_iterator it = d_typeMap.find(tn); |
123 |
9874 |
if (it != d_typeMap.end()) |
124 |
|
{ |
125 |
9874 |
Assert(i < it->second->d_list.size()); |
126 |
9874 |
return it->second->d_list[i]; |
127 |
|
} |
128 |
|
Assert(false); |
129 |
|
return Node::null(); |
130 |
|
} |
131 |
|
|
132 |
1035 |
Node TermDb::getOrMakeTypeGroundTerm(TypeNode tn, bool reqVar) |
133 |
|
{ |
134 |
1035 |
TypeNodeDbListMap::const_iterator it = d_typeMap.find(tn); |
135 |
1035 |
if (it != d_typeMap.end()) |
136 |
|
{ |
137 |
366 |
Assert(!it->second->d_list.empty()); |
138 |
366 |
if (!reqVar) |
139 |
|
{ |
140 |
121 |
return it->second->d_list[0]; |
141 |
|
} |
142 |
415 |
for (const Node& v : it->second->d_list) |
143 |
|
{ |
144 |
366 |
if (v.isVar()) |
145 |
|
{ |
146 |
196 |
return v; |
147 |
|
} |
148 |
|
} |
149 |
|
} |
150 |
718 |
return getOrMakeTypeFreshVariable(tn); |
151 |
|
} |
152 |
|
|
153 |
718 |
Node TermDb::getOrMakeTypeFreshVariable(TypeNode tn) |
154 |
|
{ |
155 |
718 |
std::unordered_map<TypeNode, Node>::iterator it = d_type_fv.find(tn); |
156 |
718 |
if (it == d_type_fv.end()) |
157 |
|
{ |
158 |
184 |
SkolemManager* sm = NodeManager::currentNM()->getSkolemManager(); |
159 |
368 |
std::stringstream ss; |
160 |
184 |
ss << language::SetLanguage(options::outputLanguage()); |
161 |
184 |
ss << "e_" << tn; |
162 |
368 |
Node k = sm->mkDummySkolem(ss.str(), tn, "is a termDb fresh variable"); |
163 |
368 |
Trace("mkVar") << "TermDb:: Make variable " << k << " : " << tn |
164 |
184 |
<< std::endl; |
165 |
184 |
if (options::instMaxLevel() != -1) |
166 |
|
{ |
167 |
|
QuantAttributes::setInstantiationLevelAttr(k, 0); |
168 |
|
} |
169 |
184 |
d_type_fv[tn] = k; |
170 |
184 |
return k; |
171 |
|
} |
172 |
534 |
return it->second; |
173 |
|
} |
174 |
|
|
175 |
1499681 |
Node TermDb::getMatchOperator( Node n ) { |
176 |
1499681 |
Kind k = n.getKind(); |
177 |
|
//datatype operators may be parametric, always assume they are |
178 |
1499681 |
if (k == SELECT || k == STORE || k == UNION || k == INTERSECTION |
179 |
1459232 |
|| k == SUBSET || k == SETMINUS || k == MEMBER || k == SINGLETON |
180 |
1450245 |
|| k == APPLY_SELECTOR_TOTAL || k == APPLY_SELECTOR || k == APPLY_TESTER |
181 |
1382954 |
|| k == SEP_PTO || k == HO_APPLY || k == SEQ_NTH || k == STRING_LENGTH) |
182 |
|
{ |
183 |
|
//since it is parametric, use a particular one as op |
184 |
316620 |
TypeNode tn = n[0].getType(); |
185 |
316620 |
Node op = n.getOperator(); |
186 |
158310 |
std::map< Node, std::map< TypeNode, Node > >::iterator ito = d_par_op_map.find( op ); |
187 |
158310 |
if( ito!=d_par_op_map.end() ){ |
188 |
152021 |
std::map< TypeNode, Node >::iterator it = ito->second.find( tn ); |
189 |
152021 |
if( it!=ito->second.end() ){ |
190 |
151671 |
return it->second; |
191 |
|
} |
192 |
|
} |
193 |
6639 |
Trace("par-op") << "Parametric operator : " << k << ", " << n.getOperator() << ", " << tn << " : " << n << std::endl; |
194 |
6639 |
d_par_op_map[op][tn] = n; |
195 |
6639 |
return n; |
196 |
|
} |
197 |
1341371 |
else if (inst::TriggerTermInfo::isAtomicTriggerKind(k)) |
198 |
|
{ |
199 |
1265720 |
return n.getOperator(); |
200 |
|
}else{ |
201 |
75651 |
return Node::null(); |
202 |
|
} |
203 |
|
} |
204 |
|
|
205 |
1720431 |
void TermDb::addTerm(Node n) |
206 |
|
{ |
207 |
1720431 |
if (d_processed.find(n) != d_processed.end()) |
208 |
|
{ |
209 |
1048347 |
return; |
210 |
|
} |
211 |
672084 |
d_processed.insert(n); |
212 |
672084 |
if (!TermUtil::hasInstConstAttr(n)) |
213 |
|
{ |
214 |
655734 |
Trace("term-db-debug") << "register term : " << n << std::endl; |
215 |
655734 |
DbList* dlt = getOrMkDbListForType(n.getType()); |
216 |
655734 |
dlt->d_list.push_back(n); |
217 |
|
// if this is an atomic trigger, consider adding it |
218 |
655734 |
if (inst::TriggerTermInfo::isAtomicTrigger(n)) |
219 |
|
{ |
220 |
214347 |
Trace("term-db") << "register term in db " << n << std::endl; |
221 |
|
|
222 |
428694 |
Node op = getMatchOperator(n); |
223 |
214347 |
Trace("term-db-debug") << " match operator is : " << op << std::endl; |
224 |
214347 |
DbList* dlo = getOrMkDbListForOp(op); |
225 |
214347 |
dlo->d_list.push_back(n); |
226 |
|
// If we are higher-order, we may need to register more terms. |
227 |
214347 |
addTermInternal(n); |
228 |
|
} |
229 |
|
} |
230 |
|
else |
231 |
|
{ |
232 |
16350 |
setTermInactive(n); |
233 |
|
} |
234 |
672084 |
if (!n.isClosure()) |
235 |
|
{ |
236 |
1816807 |
for (const Node& nc : n) |
237 |
|
{ |
238 |
1144730 |
addTerm(nc); |
239 |
|
} |
240 |
|
} |
241 |
|
} |
242 |
|
|
243 |
655734 |
DbList* TermDb::getOrMkDbListForType(TypeNode tn) |
244 |
|
{ |
245 |
655734 |
TypeNodeDbListMap::iterator it = d_typeMap.find(tn); |
246 |
655734 |
if (it != d_typeMap.end()) |
247 |
|
{ |
248 |
641035 |
return it->second.get(); |
249 |
|
} |
250 |
29398 |
std::shared_ptr<DbList> dl = std::make_shared<DbList>(d_termsContextUse); |
251 |
14699 |
d_typeMap.insert(tn, dl); |
252 |
14699 |
return dl.get(); |
253 |
|
} |
254 |
|
|
255 |
246367 |
DbList* TermDb::getOrMkDbListForOp(TNode op) |
256 |
|
{ |
257 |
246367 |
NodeDbListMap::iterator it = d_opMap.find(op); |
258 |
246367 |
if (it != d_opMap.end()) |
259 |
|
{ |
260 |
177801 |
return it->second.get(); |
261 |
|
} |
262 |
137132 |
std::shared_ptr<DbList> dl = std::make_shared<DbList>(d_termsContextUse); |
263 |
68566 |
d_opMap.insert(op, dl); |
264 |
68566 |
Assert(op.getKind() != BOUND_VARIABLE); |
265 |
68566 |
d_ops.push_back(op); |
266 |
68566 |
return dl.get(); |
267 |
|
} |
268 |
|
|
269 |
243247 |
void TermDb::computeArgReps( TNode n ) { |
270 |
243247 |
if (d_arg_reps.find(n) == d_arg_reps.end()) |
271 |
|
{ |
272 |
157601 |
eq::EqualityEngine* ee = d_qstate.getEqualityEngine(); |
273 |
507168 |
for (const TNode& nc : n) |
274 |
|
{ |
275 |
699134 |
TNode r = ee->hasTerm(nc) ? ee->getRepresentative(nc) : nc; |
276 |
349567 |
d_arg_reps[n].push_back( r ); |
277 |
|
} |
278 |
|
} |
279 |
243247 |
} |
280 |
|
|
281 |
545479 |
void TermDb::computeUfEqcTerms( TNode f ) { |
282 |
545479 |
Assert(f == getOperatorRepresentative(f)); |
283 |
545479 |
if (d_func_map_eqc_trie.find(f) != d_func_map_eqc_trie.end()) |
284 |
|
{ |
285 |
526134 |
return; |
286 |
|
} |
287 |
19345 |
d_func_map_eqc_trie[f].clear(); |
288 |
|
// get the matchable operators in the equivalence class of f |
289 |
38690 |
std::vector<TNode> ops; |
290 |
19345 |
getOperatorsFor(f, ops); |
291 |
19345 |
eq::EqualityEngine* ee = d_qstate.getEqualityEngine(); |
292 |
38722 |
for (TNode ff : ops) |
293 |
|
{ |
294 |
19377 |
DbList* dbl = getOrMkDbListForOp(ff); |
295 |
146152 |
for (const Node& n : dbl->d_list) |
296 |
|
{ |
297 |
126775 |
if (hasTermCurrent(n) && isTermActive(n)) |
298 |
|
{ |
299 |
119750 |
computeArgReps(n); |
300 |
239500 |
TNode r = ee->hasTerm(n) ? ee->getRepresentative(n) : TNode(n); |
301 |
119750 |
d_func_map_eqc_trie[f].d_data[r].addTerm(n, d_arg_reps[n]); |
302 |
|
} |
303 |
|
} |
304 |
|
} |
305 |
|
} |
306 |
|
|
307 |
1044351 |
void TermDb::computeUfTerms( TNode f ) { |
308 |
1044351 |
if (d_op_nonred_count.find(f) != d_op_nonred_count.end()) |
309 |
|
{ |
310 |
|
// already computed |
311 |
2052332 |
return; |
312 |
|
} |
313 |
18188 |
Assert(f == getOperatorRepresentative(f)); |
314 |
18188 |
d_op_nonred_count[f] = 0; |
315 |
|
// get the matchable operators in the equivalence class of f |
316 |
36370 |
std::vector<TNode> ops; |
317 |
18188 |
getOperatorsFor(f, ops); |
318 |
18188 |
Trace("term-db-debug") << "computeUfTerms for " << f << std::endl; |
319 |
18188 |
unsigned congruentCount = 0; |
320 |
18188 |
unsigned nonCongruentCount = 0; |
321 |
18188 |
unsigned alreadyCongruentCount = 0; |
322 |
18188 |
unsigned relevantCount = 0; |
323 |
18188 |
NodeManager* nm = NodeManager::currentNM(); |
324 |
33930 |
for (TNode ff : ops) |
325 |
|
{ |
326 |
18205 |
NodeDbListMap::iterator it = d_opMap.find(ff); |
327 |
18205 |
if (it == d_opMap.end()) |
328 |
|
{ |
329 |
|
// no terms for this operator |
330 |
2457 |
continue; |
331 |
|
} |
332 |
15748 |
Trace("term-db-debug") << "Adding terms for operator " << ff << std::endl; |
333 |
148070 |
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 |
132328 |
if (!hasTermCurrent(n) || !d_qstate.hasTerm(n)) |
337 |
|
{ |
338 |
|
Trace("term-db-debug") << n << " is not relevant." << std::endl; |
339 |
36641 |
continue; |
340 |
|
} |
341 |
|
|
342 |
132328 |
relevantCount++; |
343 |
141159 |
if (!isTermActive(n)) |
344 |
|
{ |
345 |
8831 |
Trace("term-db-debug") << n << " is already redundant." << std::endl; |
346 |
8831 |
alreadyCongruentCount++; |
347 |
8831 |
continue; |
348 |
|
} |
349 |
|
|
350 |
123497 |
computeArgReps(n); |
351 |
123497 |
Trace("term-db-debug") << "Adding term " << n << " with arg reps : "; |
352 |
390996 |
for (unsigned i = 0, size = d_arg_reps[n].size(); i < size; i++) |
353 |
|
{ |
354 |
267499 |
Trace("term-db-debug") << d_arg_reps[n][i] << " "; |
355 |
1069996 |
if (std::find(d_func_map_rel_dom[f][i].begin(), |
356 |
534998 |
d_func_map_rel_dom[f][i].end(), |
357 |
1069996 |
d_arg_reps[n][i]) |
358 |
802497 |
== d_func_map_rel_dom[f][i].end()) |
359 |
|
{ |
360 |
91725 |
d_func_map_rel_dom[f][i].push_back(d_arg_reps[n][i]); |
361 |
|
} |
362 |
|
} |
363 |
123497 |
Trace("term-db-debug") << std::endl; |
364 |
123497 |
Assert(d_qstate.hasTerm(n)); |
365 |
246994 |
Trace("term-db-debug") |
366 |
123497 |
<< " and value : " << d_qstate.getRepresentative(n) << std::endl; |
367 |
219178 |
Node at = d_func_map_trie[f].addOrGetTerm(n, d_arg_reps[n]); |
368 |
123497 |
Assert(d_qstate.hasTerm(at)); |
369 |
123497 |
Trace("term-db-debug2") << "...add term returned " << at << std::endl; |
370 |
151307 |
if (at != n && d_qstate.areEqual(at, n)) |
371 |
|
{ |
372 |
27810 |
setTermInactive(n); |
373 |
27810 |
Trace("term-db-debug") << n << " is redundant." << std::endl; |
374 |
27810 |
congruentCount++; |
375 |
27810 |
continue; |
376 |
|
} |
377 |
191368 |
std::vector<Node> lits; |
378 |
95687 |
if (checkCongruentDisequal(at, n, lits)) |
379 |
|
{ |
380 |
6 |
Assert(at.getNumChildren() == n.getNumChildren()); |
381 |
23 |
for (size_t k = 0, size = at.getNumChildren(); k < size; k++) |
382 |
|
{ |
383 |
17 |
if (at[k] != n[k]) |
384 |
|
{ |
385 |
8 |
lits.push_back(nm->mkNode(EQUAL, at[k], n[k]).negate()); |
386 |
|
} |
387 |
|
} |
388 |
12 |
Node lem = nm->mkOr(lits); |
389 |
6 |
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 |
6 |
d_qim->addPendingLemma(lem, InferenceId::QUANTIFIERS_TDB_DEQ_CONG); |
402 |
6 |
d_qstate.notifyInConflict(); |
403 |
6 |
d_consistent_ee = false; |
404 |
6 |
return; |
405 |
|
} |
406 |
95681 |
nonCongruentCount++; |
407 |
95681 |
d_op_nonred_count[f]++; |
408 |
|
} |
409 |
15742 |
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 |
1963917 |
Node TermDb::getOperatorRepresentative(TNode op) const { return op; } |
424 |
|
|
425 |
92210 |
bool TermDb::checkCongruentDisequal(TNode a, TNode b, std::vector<Node>& exp) |
426 |
|
{ |
427 |
92210 |
if (d_qstate.areDisequal(a, b)) |
428 |
|
{ |
429 |
6 |
exp.push_back(a.eqNode(b)); |
430 |
6 |
return true; |
431 |
|
} |
432 |
92204 |
return false; |
433 |
|
} |
434 |
|
|
435 |
680907 |
bool TermDb::inRelevantDomain( TNode f, unsigned i, TNode r ) { |
436 |
|
// notice if we are not higher-order, getOperatorRepresentative is a no-op |
437 |
680907 |
f = getOperatorRepresentative(f); |
438 |
680907 |
computeUfTerms( f ); |
439 |
680907 |
Assert(!d_qstate.getEqualityEngine()->hasTerm(r) |
440 |
|
|| d_qstate.getEqualityEngine()->getRepresentative(r) == r); |
441 |
680907 |
std::map< Node, std::map< unsigned, std::vector< Node > > >::iterator it = d_func_map_rel_dom.find( f ); |
442 |
680907 |
if( it != d_func_map_rel_dom.end() ){ |
443 |
672822 |
std::map< unsigned, std::vector< Node > >::iterator it2 = it->second.find( i ); |
444 |
672822 |
if( it2!=it->second.end() ){ |
445 |
672822 |
return std::find( it2->second.begin(), it2->second.end(), r )!=it2->second.end(); |
446 |
|
}else{ |
447 |
|
return false; |
448 |
|
} |
449 |
|
}else{ |
450 |
8085 |
return false; |
451 |
|
} |
452 |
|
} |
453 |
|
|
454 |
208013 |
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 |
208013 |
std::map< TNode, Node >::iterator itv = visited.find( n ); |
462 |
208013 |
if( itv != visited.end() ){ |
463 |
16187 |
return itv->second; |
464 |
|
} |
465 |
191826 |
size_t prevSize = exp.size(); |
466 |
191826 |
Trace("term-db-eval") << "evaluate term : " << n << std::endl; |
467 |
383652 |
Node ret = n; |
468 |
191826 |
if( n.getKind()==FORALL || n.getKind()==BOUND_VARIABLE ){ |
469 |
|
//do nothing |
470 |
|
} |
471 |
191072 |
else if (d_qstate.hasTerm(n)) |
472 |
|
{ |
473 |
89023 |
Trace("term-db-eval") << "...exists in ee, return rep" << std::endl; |
474 |
89023 |
ret = d_qstate.getRepresentative(n); |
475 |
89023 |
if (computeExp) |
476 |
|
{ |
477 |
|
if (n != ret) |
478 |
|
{ |
479 |
|
exp.push_back(n.eqNode(ret)); |
480 |
|
} |
481 |
|
} |
482 |
89023 |
reqHasTerm = false; |
483 |
|
} |
484 |
102049 |
else if (n.hasOperator()) |
485 |
|
{ |
486 |
203650 |
std::vector<TNode> args; |
487 |
101825 |
bool ret_set = false; |
488 |
101825 |
Kind k = n.getKind(); |
489 |
203650 |
std::vector<Node> tempExp; |
490 |
233099 |
for (unsigned i = 0, nchild = n.getNumChildren(); i < nchild; i++) |
491 |
|
{ |
492 |
349910 |
TNode c = evaluateTerm2(n[i], |
493 |
|
visited, |
494 |
|
tempExp, |
495 |
|
useEntailmentTests, |
496 |
|
computeExp, |
497 |
306229 |
reqHasTerm); |
498 |
174955 |
if (c.isNull()) |
499 |
|
{ |
500 |
31473 |
ret = Node::null(); |
501 |
31473 |
ret_set = true; |
502 |
31473 |
break; |
503 |
|
} |
504 |
143482 |
else if (c == d_true || c == d_false) |
505 |
|
{ |
506 |
|
// short-circuiting |
507 |
65163 |
if ((k == AND && c == d_false) || (k == OR && c == d_true)) |
508 |
|
{ |
509 |
11136 |
ret = c; |
510 |
11136 |
ret_set = true; |
511 |
11136 |
reqHasTerm = false; |
512 |
11136 |
break; |
513 |
|
} |
514 |
54027 |
else if (k == ITE && i == 0) |
515 |
|
{ |
516 |
1072 |
ret = evaluateTerm2(n[c == d_true ? 1 : 2], |
517 |
|
visited, |
518 |
|
tempExp, |
519 |
|
useEntailmentTests, |
520 |
|
computeExp, |
521 |
|
reqHasTerm); |
522 |
1072 |
ret_set = true; |
523 |
1072 |
reqHasTerm = false; |
524 |
1072 |
break; |
525 |
|
} |
526 |
|
} |
527 |
131274 |
if (computeExp) |
528 |
|
{ |
529 |
|
exp.insert(exp.end(), tempExp.begin(), tempExp.end()); |
530 |
|
} |
531 |
131274 |
Trace("term-db-eval") << " child " << i << " : " << c << std::endl; |
532 |
131274 |
args.push_back(c); |
533 |
|
} |
534 |
101825 |
if (ret_set) |
535 |
|
{ |
536 |
|
// if we short circuited |
537 |
43681 |
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 |
116288 |
TNode f = getMatchOperator(n); |
547 |
|
// if it is an indexed term, return the congruent term |
548 |
58144 |
if (!f.isNull()) |
549 |
|
{ |
550 |
|
// if f is congruent to a term indexed by this class |
551 |
43048 |
TNode nn = getCongruentTerm(f, args); |
552 |
43048 |
Trace("term-db-eval") << " got congruent term " << nn |
553 |
21524 |
<< " from DB for " << n << std::endl; |
554 |
21524 |
if (!nn.isNull()) |
555 |
|
{ |
556 |
8076 |
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 |
8076 |
ret = d_qstate.getRepresentative(nn); |
568 |
8076 |
Trace("term-db-eval") << "return rep" << std::endl; |
569 |
8076 |
ret_set = true; |
570 |
8076 |
reqHasTerm = false; |
571 |
8076 |
Assert(!ret.isNull()); |
572 |
8076 |
if (computeExp) |
573 |
|
{ |
574 |
|
if (n != ret) |
575 |
|
{ |
576 |
|
exp.push_back(nn.eqNode(ret)); |
577 |
|
} |
578 |
|
} |
579 |
|
} |
580 |
|
} |
581 |
58144 |
if( !ret_set ){ |
582 |
50068 |
Trace("term-db-eval") << "return rewrite" << std::endl; |
583 |
|
// a theory symbol or a new UF term |
584 |
50068 |
if (n.getMetaKind() == metakind::PARAMETERIZED) |
585 |
|
{ |
586 |
13335 |
args.insert(args.begin(), n.getOperator()); |
587 |
|
} |
588 |
50068 |
ret = NodeManager::currentNM()->mkNode(n.getKind(), args); |
589 |
50068 |
ret = Rewriter::rewrite(ret); |
590 |
50068 |
if (ret.getKind() == EQUAL) |
591 |
|
{ |
592 |
7509 |
if (d_qstate.areDisequal(ret[0], ret[1])) |
593 |
|
{ |
594 |
2165 |
ret = d_false; |
595 |
|
} |
596 |
|
} |
597 |
50068 |
if (useEntailmentTests) |
598 |
|
{ |
599 |
438 |
if (ret.getKind() == EQUAL || ret.getKind() == GEQ) |
600 |
|
{ |
601 |
4 |
Valuation& val = d_qstate.getValuation(); |
602 |
11 |
for (unsigned j = 0; j < 2; j++) |
603 |
|
{ |
604 |
|
std::pair<bool, Node> et = val.entailmentCheck( |
605 |
|
options::TheoryOfMode::THEORY_OF_TYPE_BASED, |
606 |
15 |
j == 0 ? ret : ret.negate()); |
607 |
8 |
if (et.first) |
608 |
|
{ |
609 |
1 |
ret = j == 0 ? d_true : d_false; |
610 |
1 |
if (computeExp) |
611 |
|
{ |
612 |
|
exp.push_back(et.second); |
613 |
|
} |
614 |
1 |
break; |
615 |
|
} |
616 |
|
} |
617 |
|
} |
618 |
|
} |
619 |
|
} |
620 |
|
} |
621 |
|
} |
622 |
|
// must have the term |
623 |
191826 |
if (reqHasTerm && !ret.isNull()) |
624 |
|
{ |
625 |
49641 |
Kind k = ret.getKind(); |
626 |
49641 |
if (k != OR && k != AND && k != EQUAL && k != ITE && k != NOT |
627 |
43092 |
&& k != FORALL) |
628 |
|
{ |
629 |
43015 |
if (!d_qstate.hasTerm(ret)) |
630 |
|
{ |
631 |
12926 |
ret = Node::null(); |
632 |
|
} |
633 |
|
} |
634 |
|
} |
635 |
383652 |
Trace("term-db-eval") << "evaluated term : " << n << ", got : " << ret |
636 |
191826 |
<< ", reqHasTerm = " << reqHasTerm << std::endl; |
637 |
|
// clear the explanation if failed |
638 |
191826 |
if (computeExp && ret.isNull()) |
639 |
|
{ |
640 |
|
exp.resize(prevSize); |
641 |
|
} |
642 |
191826 |
visited[n] = ret; |
643 |
191826 |
return ret; |
644 |
|
} |
645 |
|
|
646 |
2915238 |
TNode TermDb::getEntailedTerm2(TNode n, |
647 |
|
std::map<TNode, TNode>& subs, |
648 |
|
bool subsRep, |
649 |
|
bool hasSubs) |
650 |
|
{ |
651 |
2915238 |
Trace("term-db-entail") << "get entailed term : " << n << std::endl; |
652 |
2915238 |
if (d_qstate.hasTerm(n)) |
653 |
|
{ |
654 |
981173 |
Trace("term-db-entail") << "...exists in ee, return rep " << std::endl; |
655 |
981173 |
return n; |
656 |
1934065 |
}else if( n.getKind()==BOUND_VARIABLE ){ |
657 |
1173780 |
if( hasSubs ){ |
658 |
1173780 |
std::map< TNode, TNode >::iterator it = subs.find( n ); |
659 |
1173780 |
if( it!=subs.end() ){ |
660 |
913164 |
Trace("term-db-entail") << "...substitution is : " << it->second << std::endl; |
661 |
913164 |
if( subsRep ){ |
662 |
95208 |
Assert(d_qstate.hasTerm(it->second)); |
663 |
95208 |
Assert(d_qstate.getRepresentative(it->second) == it->second); |
664 |
1008372 |
return it->second; |
665 |
|
} |
666 |
817956 |
return getEntailedTerm2(it->second, subs, subsRep, hasSubs); |
667 |
|
} |
668 |
|
} |
669 |
760285 |
}else if( n.getKind()==ITE ){ |
670 |
18684 |
for( unsigned i=0; i<2; i++ ){ |
671 |
16546 |
if (isEntailed2(n[0], subs, subsRep, hasSubs, i == 0)) |
672 |
|
{ |
673 |
7647 |
return getEntailedTerm2(n[i == 0 ? 1 : 2], subs, subsRep, hasSubs); |
674 |
|
} |
675 |
|
} |
676 |
|
}else{ |
677 |
750500 |
if( n.hasOperator() ){ |
678 |
755354 |
TNode f = getMatchOperator( n ); |
679 |
747073 |
if( !f.isNull() ){ |
680 |
1477584 |
std::vector< TNode > args; |
681 |
1772122 |
for( unsigned i=0; i<n.getNumChildren(); i++ ){ |
682 |
2470717 |
TNode c = getEntailedTerm2(n[i], subs, subsRep, hasSubs); |
683 |
1437387 |
if( c.isNull() ){ |
684 |
404057 |
return TNode::null(); |
685 |
|
} |
686 |
1033330 |
c = d_qstate.getRepresentative(c); |
687 |
1033330 |
Trace("term-db-entail") << " child " << i << " : " << c << std::endl; |
688 |
1033330 |
args.push_back( c ); |
689 |
|
} |
690 |
669470 |
TNode nn = getCongruentTerm(f, args); |
691 |
334735 |
Trace("term-db-entail") << " got congruent term " << nn << " for " << n << std::endl; |
692 |
334735 |
return nn; |
693 |
|
} |
694 |
|
} |
695 |
|
} |
696 |
274462 |
return TNode::null(); |
697 |
|
} |
698 |
|
|
699 |
31986 |
Node TermDb::evaluateTerm(TNode n, |
700 |
|
bool useEntailmentTests, |
701 |
|
bool reqHasTerm) |
702 |
|
{ |
703 |
63972 |
std::map< TNode, Node > visited; |
704 |
63972 |
std::vector<Node> exp; |
705 |
63972 |
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 |
238860 |
TNode TermDb::getEntailedTerm(TNode n, |
718 |
|
std::map<TNode, TNode>& subs, |
719 |
|
bool subsRep) |
720 |
|
{ |
721 |
238860 |
return getEntailedTerm2(n, subs, subsRep, true); |
722 |
|
} |
723 |
|
|
724 |
34804 |
TNode TermDb::getEntailedTerm(TNode n) |
725 |
|
{ |
726 |
69608 |
std::map< TNode, TNode > subs; |
727 |
69608 |
return getEntailedTerm2(n, subs, false, false); |
728 |
|
} |
729 |
|
|
730 |
663740 |
bool TermDb::isEntailed2( |
731 |
|
TNode n, std::map<TNode, TNode>& subs, bool subsRep, bool hasSubs, bool pol) |
732 |
|
{ |
733 |
663740 |
Trace("term-db-entail") << "Check entailed : " << n << ", pol = " << pol << std::endl; |
734 |
663740 |
Assert(n.getType().isBoolean()); |
735 |
663740 |
if( n.getKind()==EQUAL && !n[0].getType().isBoolean() ){ |
736 |
166190 |
TNode n1 = getEntailedTerm2(n[0], subs, subsRep, hasSubs); |
737 |
138334 |
if( !n1.isNull() ){ |
738 |
134036 |
TNode n2 = getEntailedTerm2(n[1], subs, subsRep, hasSubs); |
739 |
122257 |
if( !n2.isNull() ){ |
740 |
110478 |
if( n1==n2 ){ |
741 |
14893 |
return pol; |
742 |
|
}else{ |
743 |
95585 |
Assert(d_qstate.hasTerm(n1)); |
744 |
95585 |
Assert(d_qstate.hasTerm(n2)); |
745 |
95585 |
if( pol ){ |
746 |
48865 |
return d_qstate.areEqual(n1, n2); |
747 |
|
}else{ |
748 |
46720 |
return d_qstate.areDisequal(n1, n2); |
749 |
|
} |
750 |
|
} |
751 |
|
} |
752 |
|
} |
753 |
525406 |
}else if( n.getKind()==NOT ){ |
754 |
196480 |
return isEntailed2(n[0], subs, subsRep, hasSubs, !pol); |
755 |
328926 |
}else if( n.getKind()==OR || n.getKind()==AND ){ |
756 |
97542 |
bool simPol = ( pol && n.getKind()==OR ) || ( !pol && n.getKind()==AND ); |
757 |
337311 |
for( unsigned i=0; i<n.getNumChildren(); i++ ){ |
758 |
301203 |
if (isEntailed2(n[i], subs, subsRep, hasSubs, pol)) |
759 |
|
{ |
760 |
71281 |
if( simPol ){ |
761 |
29589 |
return true; |
762 |
|
} |
763 |
|
}else{ |
764 |
229922 |
if( !simPol ){ |
765 |
31845 |
return false; |
766 |
|
} |
767 |
|
} |
768 |
|
} |
769 |
36108 |
return !simPol; |
770 |
|
//Boolean equality here |
771 |
231384 |
}else if( n.getKind()==EQUAL || n.getKind()==ITE ){ |
772 |
35432 |
for( unsigned i=0; i<2; i++ ){ |
773 |
28557 |
if (isEntailed2(n[0], subs, subsRep, hasSubs, i == 0)) |
774 |
|
{ |
775 |
9889 |
unsigned ch = ( n.getKind()==EQUAL || i==0 ) ? 1 : 2; |
776 |
9889 |
bool reqPol = ( n.getKind()==ITE || i==0 ) ? pol : !pol; |
777 |
9889 |
return isEntailed2(n[ch], subs, subsRep, hasSubs, reqPol); |
778 |
|
} |
779 |
|
} |
780 |
214620 |
}else if( n.getKind()==APPLY_UF ){ |
781 |
158595 |
TNode n1 = getEntailedTerm2(n, subs, subsRep, hasSubs); |
782 |
117993 |
if( !n1.isNull() ){ |
783 |
77391 |
Assert(d_qstate.hasTerm(n1)); |
784 |
77391 |
if( n1==d_true ){ |
785 |
|
return pol; |
786 |
77391 |
}else if( n1==d_false ){ |
787 |
|
return !pol; |
788 |
|
}else{ |
789 |
77391 |
return d_qstate.getRepresentative(n1) == (pol ? d_true : d_false); |
790 |
|
} |
791 |
|
} |
792 |
96627 |
}else if( n.getKind()==FORALL && !pol ){ |
793 |
2613 |
return isEntailed2(n[1], subs, subsRep, hasSubs, pol); |
794 |
|
} |
795 |
169347 |
return false; |
796 |
|
} |
797 |
|
|
798 |
396 |
bool TermDb::isEntailed(TNode n, bool pol) |
799 |
|
{ |
800 |
396 |
Assert(d_consistent_ee); |
801 |
792 |
std::map< TNode, TNode > subs; |
802 |
792 |
return isEntailed2(n, subs, false, false, pol); |
803 |
|
} |
804 |
|
|
805 |
108056 |
bool TermDb::isEntailed(TNode n, |
806 |
|
std::map<TNode, TNode>& subs, |
807 |
|
bool subsRep, |
808 |
|
bool pol) |
809 |
|
{ |
810 |
108056 |
Assert(d_consistent_ee); |
811 |
108056 |
return isEntailed2(n, subs, subsRep, true, pol); |
812 |
|
} |
813 |
|
|
814 |
1261294 |
bool TermDb::isTermActive( Node n ) { |
815 |
1261294 |
return d_inactive_map.find( n )==d_inactive_map.end(); |
816 |
|
//return !n.getAttribute(NoMatchAttribute()); |
817 |
|
} |
818 |
|
|
819 |
67944 |
void TermDb::setTermInactive( Node n ) { |
820 |
67944 |
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 |
67944 |
} |
825 |
|
|
826 |
1783313 |
bool TermDb::hasTermCurrent( Node n, bool useMode ) { |
827 |
1783313 |
if( !useMode ){ |
828 |
|
return d_has_map.find( n )!=d_has_map.end(); |
829 |
|
} |
830 |
|
//some assertions are not sent to EE |
831 |
1783313 |
if (options::termDbMode() == options::TermDbMode::ALL) |
832 |
|
{ |
833 |
1783313 |
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 |
313 |
bool TermDb::isTermEligibleForInstantiation(TNode n, TNode f) |
844 |
|
{ |
845 |
313 |
if( options::instMaxLevel()!=-1 ){ |
846 |
260 |
if( n.hasAttribute(InstLevelAttribute()) ){ |
847 |
|
int64_t fml = |
848 |
260 |
f.isNull() ? -1 : d_qreg.getQuantAttributes().getQuantInstLevel(f); |
849 |
260 |
unsigned ml = fml>=0 ? fml : options::instMaxLevel(); |
850 |
|
|
851 |
260 |
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 |
313 |
return !TermUtil::hasInstConstAttr(n); |
866 |
|
} |
867 |
|
|
868 |
53 |
Node TermDb::getEligibleTermInEqc( TNode r ) { |
869 |
53 |
if( isTermEligibleForInstantiation( r, TNode::null() ) ){ |
870 |
53 |
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 |
19173 |
bool TermDb::resetInternal(Theory::Effort e) |
896 |
|
{ |
897 |
|
// do nothing |
898 |
19173 |
return true; |
899 |
|
} |
900 |
|
|
901 |
19173 |
bool TermDb::finishResetInternal(Theory::Effort e) |
902 |
|
{ |
903 |
|
// do nothing |
904 |
19173 |
return true; |
905 |
|
} |
906 |
|
|
907 |
175781 |
void TermDb::addTermInternal(Node n) |
908 |
|
{ |
909 |
|
// do nothing |
910 |
175781 |
} |
911 |
|
|
912 |
35419 |
void TermDb::getOperatorsFor(TNode f, std::vector<TNode>& ops) |
913 |
|
{ |
914 |
35419 |
ops.push_back(f); |
915 |
35419 |
} |
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 |
5725 |
void TermDb::presolve() { |
928 |
5725 |
if (options::incrementalSolving() && !options::termDbCd()) |
929 |
|
{ |
930 |
|
d_termsContext.pop(); |
931 |
|
d_termsContext.push(); |
932 |
|
} |
933 |
5725 |
} |
934 |
|
|
935 |
19864 |
bool TermDb::reset( Theory::Effort effort ){ |
936 |
19864 |
d_op_nonred_count.clear(); |
937 |
19864 |
d_arg_reps.clear(); |
938 |
19864 |
d_func_map_trie.clear(); |
939 |
19864 |
d_func_map_eqc_trie.clear(); |
940 |
19864 |
d_func_map_rel_dom.clear(); |
941 |
19864 |
d_consistent_ee = true; |
942 |
|
|
943 |
19864 |
eq::EqualityEngine* ee = d_qstate.getEqualityEngine(); |
944 |
|
|
945 |
19864 |
Assert(ee->consistent()); |
946 |
|
// if higher-order, add equalities for the purification terms now |
947 |
19864 |
if (!resetInternal(effort)) |
948 |
|
{ |
949 |
|
return false; |
950 |
|
} |
951 |
|
|
952 |
|
//compute has map |
953 |
19864 |
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 |
19864 |
return finishResetInternal(effort); |
998 |
|
} |
999 |
|
|
1000 |
7185 |
TNodeTrie* TermDb::getTermArgTrie(Node f) |
1001 |
|
{ |
1002 |
7185 |
f = getOperatorRepresentative(f); |
1003 |
7185 |
computeUfTerms( f ); |
1004 |
7185 |
std::map<Node, TNodeTrie>::iterator itut = d_func_map_trie.find(f); |
1005 |
7185 |
if( itut!=d_func_map_trie.end() ){ |
1006 |
4156 |
return &itut->second; |
1007 |
|
}else{ |
1008 |
3029 |
return NULL; |
1009 |
|
} |
1010 |
|
} |
1011 |
|
|
1012 |
545479 |
TNodeTrie* TermDb::getTermArgTrie(Node eqc, Node f) |
1013 |
|
{ |
1014 |
545479 |
f = getOperatorRepresentative(f); |
1015 |
545479 |
computeUfEqcTerms( f ); |
1016 |
545479 |
std::map<Node, TNodeTrie>::iterator itut = d_func_map_eqc_trie.find(f); |
1017 |
545479 |
if( itut==d_func_map_eqc_trie.end() ){ |
1018 |
|
return NULL; |
1019 |
|
}else{ |
1020 |
545479 |
if( eqc.isNull() ){ |
1021 |
308215 |
return &itut->second; |
1022 |
|
}else{ |
1023 |
|
std::map<TNode, TNodeTrie>::iterator itute = |
1024 |
237264 |
itut->second.d_data.find(eqc); |
1025 |
237264 |
if( itute!=itut->second.d_data.end() ){ |
1026 |
134193 |
return &itute->second; |
1027 |
|
}else{ |
1028 |
103071 |
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 |
356259 |
TNode TermDb::getCongruentTerm( Node f, std::vector< TNode >& args ) { |
1047 |
356259 |
f = getOperatorRepresentative(f); |
1048 |
356259 |
computeUfTerms( f ); |
1049 |
356259 |
return d_func_map_trie[f].existsTerm( args ); |
1050 |
|
} |
1051 |
|
|
1052 |
|
} // namespace quantifiers |
1053 |
|
} // namespace theory |
1054 |
22755 |
} // namespace cvc5 |