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 |
|
* Term registry class. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "theory/quantifiers/term_registry.h" |
17 |
|
|
18 |
|
#include "options/base_options.h" |
19 |
|
#include "options/quantifiers_options.h" |
20 |
|
#include "options/smt_options.h" |
21 |
|
#include "theory/quantifiers/first_order_model.h" |
22 |
|
#include "theory/quantifiers/fmf/first_order_model_fmc.h" |
23 |
|
#include "theory/quantifiers/ho_term_database.h" |
24 |
|
#include "theory/quantifiers/quantifiers_attributes.h" |
25 |
|
#include "theory/quantifiers/quantifiers_state.h" |
26 |
|
#include "theory/quantifiers/term_util.h" |
27 |
|
|
28 |
|
namespace cvc5 { |
29 |
|
namespace theory { |
30 |
|
namespace quantifiers { |
31 |
|
|
32 |
9926 |
TermRegistry::TermRegistry(QuantifiersState& qs, QuantifiersRegistry& qr) |
33 |
9926 |
: d_presolve(qs.getUserContext(), true), |
34 |
9926 |
d_presolveCache(qs.getUserContext()), |
35 |
9926 |
d_termEnum(new TermEnumeration), |
36 |
9926 |
d_termPools(new TermPools(qs)), |
37 |
10119 |
d_termDb(qs.getEnv().getLogicInfo().isHigherOrder() ? new HoTermDb(qs, qr) |
38 |
9733 |
: new TermDb(qs, qr)), |
39 |
|
d_sygusTdb(nullptr), |
40 |
69482 |
d_qmodel(nullptr) |
41 |
|
{ |
42 |
9926 |
if (options::sygus() || options::sygusInst()) |
43 |
|
{ |
44 |
|
// must be constructed here since it is required for datatypes finistInit |
45 |
1191 |
d_sygusTdb.reset(new TermDbSygus(qs)); |
46 |
|
} |
47 |
9926 |
Trace("quant-engine-debug") << "Initialize quantifiers engine." << std::endl; |
48 |
19852 |
Trace("quant-engine-debug") |
49 |
9926 |
<< "Initialize model, mbqi : " << options::mbqiMode() << std::endl; |
50 |
9926 |
} |
51 |
|
|
52 |
9926 |
void TermRegistry::finishInit(FirstOrderModel* fm, |
53 |
|
QuantifiersInferenceManager* qim) |
54 |
|
{ |
55 |
9926 |
d_qmodel = fm; |
56 |
9926 |
d_termDb->finishInit(qim); |
57 |
9926 |
if (d_sygusTdb.get()) |
58 |
|
{ |
59 |
1191 |
d_sygusTdb->finishInit(qim); |
60 |
|
} |
61 |
9926 |
} |
62 |
|
|
63 |
8209 |
void TermRegistry::presolve() |
64 |
|
{ |
65 |
8209 |
d_presolve = false; |
66 |
|
// add all terms to database |
67 |
8209 |
if (options::incrementalSolving() && !options::termDbCd()) |
68 |
|
{ |
69 |
|
Trace("quant-engine-proc") |
70 |
|
<< "Add presolve cache " << d_presolveCache.size() << std::endl; |
71 |
|
for (const Node& t : d_presolveCache) |
72 |
|
{ |
73 |
|
addTerm(t); |
74 |
|
} |
75 |
|
Trace("quant-engine-proc") << "Done add presolve cache " << std::endl; |
76 |
|
} |
77 |
8209 |
} |
78 |
|
|
79 |
952485 |
void TermRegistry::addTerm(Node n, bool withinQuant) |
80 |
|
{ |
81 |
|
// don't add terms in quantifier bodies |
82 |
952485 |
if (withinQuant && !options::registerQuantBodyTerms()) |
83 |
|
{ |
84 |
69004 |
return; |
85 |
|
} |
86 |
883481 |
if (options::incrementalSolving() && !options::termDbCd()) |
87 |
|
{ |
88 |
|
d_presolveCache.insert(n); |
89 |
|
} |
90 |
|
// only wait if we are doing incremental solving |
91 |
883481 |
if (!d_presolve || !options::incrementalSolving() || options::termDbCd()) |
92 |
|
{ |
93 |
883481 |
d_termDb->addTerm(n); |
94 |
883481 |
if (d_sygusTdb.get() && options::sygusEvalUnfold()) |
95 |
|
{ |
96 |
173445 |
d_sygusTdb->getEvalUnfold()->registerEvalTerm(n); |
97 |
|
} |
98 |
|
} |
99 |
|
} |
100 |
|
|
101 |
2070 |
Node TermRegistry::getTermForType(TypeNode tn) |
102 |
|
{ |
103 |
2070 |
if (tn.isClosedEnumerable()) |
104 |
|
{ |
105 |
100 |
return d_termEnum->getEnumerateTerm(tn, 0); |
106 |
|
} |
107 |
1970 |
return d_termDb->getOrMakeTypeGroundTerm(tn); |
108 |
|
} |
109 |
|
|
110 |
5 |
void TermRegistry::declarePool(Node p, const std::vector<Node>& initValue) |
111 |
|
{ |
112 |
5 |
d_termPools->registerPool(p, initValue); |
113 |
5 |
} |
114 |
|
|
115 |
37635 |
void TermRegistry::processInstantiation(Node q, const std::vector<Node>& terms) |
116 |
|
{ |
117 |
37635 |
d_termPools->processInstantiation(q, terms); |
118 |
37635 |
} |
119 |
2386 |
void TermRegistry::processSkolemization(Node q, |
120 |
|
const std::vector<Node>& skolems) |
121 |
|
{ |
122 |
2386 |
d_termPools->processSkolemization(q, skolems); |
123 |
2386 |
} |
124 |
|
|
125 |
17002791 |
TermDb* TermRegistry::getTermDatabase() const { return d_termDb.get(); } |
126 |
|
|
127 |
4492 |
TermDbSygus* TermRegistry::getTermDatabaseSygus() const |
128 |
|
{ |
129 |
4492 |
return d_sygusTdb.get(); |
130 |
|
} |
131 |
|
|
132 |
582 |
TermEnumeration* TermRegistry::getTermEnumeration() const |
133 |
|
{ |
134 |
582 |
return d_termEnum.get(); |
135 |
|
} |
136 |
|
|
137 |
9930 |
TermPools* TermRegistry::getTermPools() const { return d_termPools.get(); } |
138 |
|
|
139 |
328753 |
FirstOrderModel* TermRegistry::getModel() const { return d_qmodel; } |
140 |
|
|
141 |
|
} // namespace quantifiers |
142 |
|
} // namespace theory |
143 |
29502 |
} // namespace cvc5 |