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/quantifiers_attributes.h" |
24 |
|
#include "theory/quantifiers/quantifiers_state.h" |
25 |
|
#include "theory/quantifiers/term_util.h" |
26 |
|
|
27 |
|
namespace cvc5 { |
28 |
|
namespace theory { |
29 |
|
namespace quantifiers { |
30 |
|
|
31 |
9841 |
TermRegistry::TermRegistry(QuantifiersState& qs, QuantifiersRegistry& qr) |
32 |
9841 |
: d_presolve(qs.getUserContext(), true), |
33 |
9841 |
d_presolveCache(qs.getUserContext()), |
34 |
9841 |
d_termEnum(new TermEnumeration), |
35 |
9841 |
d_termPools(new TermPools(qs)), |
36 |
9841 |
d_termDb(new TermDb(qs, qr)), |
37 |
|
d_sygusTdb(nullptr), |
38 |
59046 |
d_qmodel(nullptr) |
39 |
|
{ |
40 |
9841 |
if (options::sygus() || options::sygusInst()) |
41 |
|
{ |
42 |
|
// must be constructed here since it is required for datatypes finistInit |
43 |
1151 |
d_sygusTdb.reset(new TermDbSygus(qs)); |
44 |
|
} |
45 |
9841 |
Trace("quant-engine-debug") << "Initialize quantifiers engine." << std::endl; |
46 |
19682 |
Trace("quant-engine-debug") |
47 |
9841 |
<< "Initialize model, mbqi : " << options::mbqiMode() << std::endl; |
48 |
9841 |
} |
49 |
|
|
50 |
9841 |
void TermRegistry::finishInit(FirstOrderModel* fm, |
51 |
|
QuantifiersInferenceManager* qim) |
52 |
|
{ |
53 |
9841 |
d_qmodel = fm; |
54 |
9841 |
d_termDb->finishInit(qim); |
55 |
9841 |
if (d_sygusTdb.get()) |
56 |
|
{ |
57 |
1151 |
d_sygusTdb->finishInit(qim); |
58 |
|
} |
59 |
9841 |
} |
60 |
|
|
61 |
8153 |
void TermRegistry::presolve() |
62 |
|
{ |
63 |
8153 |
d_presolve = false; |
64 |
|
// add all terms to database |
65 |
8153 |
if (options::incrementalSolving() && !options::termDbCd()) |
66 |
|
{ |
67 |
|
Trace("quant-engine-proc") |
68 |
|
<< "Add presolve cache " << d_presolveCache.size() << std::endl; |
69 |
|
for (const Node& t : d_presolveCache) |
70 |
|
{ |
71 |
|
addTerm(t); |
72 |
|
} |
73 |
|
Trace("quant-engine-proc") << "Done add presolve cache " << std::endl; |
74 |
|
} |
75 |
8153 |
} |
76 |
|
|
77 |
940279 |
void TermRegistry::addTerm(Node n, bool withinQuant) |
78 |
|
{ |
79 |
|
// don't add terms in quantifier bodies |
80 |
1008111 |
if (withinQuant && !options::registerQuantBodyTerms()) |
81 |
|
{ |
82 |
67832 |
return; |
83 |
|
} |
84 |
872447 |
if (options::incrementalSolving() && !options::termDbCd()) |
85 |
|
{ |
86 |
|
d_presolveCache.insert(n); |
87 |
|
} |
88 |
|
// only wait if we are doing incremental solving |
89 |
872447 |
if (!d_presolve || !options::incrementalSolving() || options::termDbCd()) |
90 |
|
{ |
91 |
872447 |
d_termDb->addTerm(n); |
92 |
872447 |
if (d_sygusTdb.get() && options::sygusEvalUnfold()) |
93 |
|
{ |
94 |
180041 |
d_sygusTdb->getEvalUnfold()->registerEvalTerm(n); |
95 |
|
} |
96 |
|
} |
97 |
|
} |
98 |
|
|
99 |
2069 |
Node TermRegistry::getTermForType(TypeNode tn) |
100 |
|
{ |
101 |
2069 |
if (tn.isClosedEnumerable()) |
102 |
|
{ |
103 |
100 |
return d_termEnum->getEnumerateTerm(tn, 0); |
104 |
|
} |
105 |
1969 |
return d_termDb->getOrMakeTypeGroundTerm(tn); |
106 |
|
} |
107 |
|
|
108 |
5 |
void TermRegistry::declarePool(Node p, const std::vector<Node>& initValue) |
109 |
|
{ |
110 |
5 |
d_termPools->registerPool(p, initValue); |
111 |
5 |
} |
112 |
|
|
113 |
37127 |
void TermRegistry::processInstantiation(Node q, const std::vector<Node>& terms) |
114 |
|
{ |
115 |
37127 |
d_termPools->processInstantiation(q, terms); |
116 |
37127 |
} |
117 |
2411 |
void TermRegistry::processSkolemization(Node q, |
118 |
|
const std::vector<Node>& skolems) |
119 |
|
{ |
120 |
2411 |
d_termPools->processSkolemization(q, skolems); |
121 |
2411 |
} |
122 |
|
|
123 |
16288735 |
TermDb* TermRegistry::getTermDatabase() const { return d_termDb.get(); } |
124 |
|
|
125 |
3915 |
TermDbSygus* TermRegistry::getTermDatabaseSygus() const |
126 |
|
{ |
127 |
3915 |
return d_sygusTdb.get(); |
128 |
|
} |
129 |
|
|
130 |
576 |
TermEnumeration* TermRegistry::getTermEnumeration() const |
131 |
|
{ |
132 |
576 |
return d_termEnum.get(); |
133 |
|
} |
134 |
|
|
135 |
9845 |
TermPools* TermRegistry::getTermPools() const { return d_termPools.get(); } |
136 |
|
|
137 |
317951 |
FirstOrderModel* TermRegistry::getModel() const { return d_qmodel; } |
138 |
|
|
139 |
|
} // namespace quantifiers |
140 |
|
} // namespace theory |
141 |
97118 |
} // namespace cvc5 |