1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Mathias Preiner, Aina Niemetz |
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 |
|
* Simple inst match generator class. |
14 |
|
*/ |
15 |
|
#include "theory/quantifiers/ematching/inst_match_generator_simple.h" |
16 |
|
|
17 |
|
#include "options/quantifiers_options.h" |
18 |
|
#include "theory/quantifiers/ematching/trigger_term_info.h" |
19 |
|
#include "theory/quantifiers/instantiate.h" |
20 |
|
#include "theory/quantifiers/quantifiers_state.h" |
21 |
|
#include "theory/quantifiers/term_database.h" |
22 |
|
#include "theory/quantifiers/term_registry.h" |
23 |
|
#include "theory/quantifiers/term_util.h" |
24 |
|
|
25 |
|
using namespace cvc5::kind; |
26 |
|
|
27 |
|
namespace cvc5 { |
28 |
|
namespace theory { |
29 |
|
namespace quantifiers { |
30 |
|
namespace inst { |
31 |
|
|
32 |
7646 |
InstMatchGeneratorSimple::InstMatchGeneratorSimple(Trigger* tparent, |
33 |
|
Node q, |
34 |
7646 |
Node pat) |
35 |
7646 |
: IMGenerator(tparent), d_quant(q), d_match_pattern(pat) |
36 |
|
{ |
37 |
7646 |
if (d_match_pattern.getKind() == NOT) |
38 |
|
{ |
39 |
1337 |
d_match_pattern = d_match_pattern[0]; |
40 |
1337 |
d_pol = false; |
41 |
|
} |
42 |
|
else |
43 |
|
{ |
44 |
6309 |
d_pol = true; |
45 |
|
} |
46 |
7646 |
if (d_match_pattern.getKind() == EQUAL) |
47 |
|
{ |
48 |
1337 |
d_eqc = d_match_pattern[1]; |
49 |
1337 |
d_match_pattern = d_match_pattern[0]; |
50 |
1337 |
Assert(!TermUtil::hasInstConstAttr(d_eqc)); |
51 |
|
} |
52 |
7646 |
Assert(TriggerTermInfo::isSimpleTrigger(d_match_pattern)); |
53 |
24592 |
for (size_t i = 0, nchild = d_match_pattern.getNumChildren(); i < nchild; i++) |
54 |
|
{ |
55 |
16946 |
if (d_match_pattern[i].getKind() == INST_CONSTANT) |
56 |
|
{ |
57 |
26752 |
if (!options::cegqi() |
58 |
26752 |
|| TermUtil::getInstConstAttr(d_match_pattern[i]) == q) |
59 |
|
{ |
60 |
13376 |
d_var_num[i] = d_match_pattern[i].getAttribute(InstVarNumAttribute()); |
61 |
|
} |
62 |
|
else |
63 |
|
{ |
64 |
|
d_var_num[i] = -1; |
65 |
|
} |
66 |
|
} |
67 |
16946 |
d_match_pattern_arg_types.push_back(d_match_pattern[i].getType()); |
68 |
|
} |
69 |
7646 |
TermDb* tdb = d_treg.getTermDatabase(); |
70 |
7646 |
d_op = tdb->getMatchOperator(d_match_pattern); |
71 |
7646 |
} |
72 |
|
|
73 |
74850 |
void InstMatchGeneratorSimple::resetInstantiationRound() {} |
74 |
25423 |
uint64_t InstMatchGeneratorSimple::addInstantiations(Node q) |
75 |
|
{ |
76 |
25423 |
uint64_t addedLemmas = 0; |
77 |
|
TNodeTrie* tat; |
78 |
25423 |
TermDb* tdb = d_treg.getTermDatabase(); |
79 |
25423 |
if (d_eqc.isNull()) |
80 |
|
{ |
81 |
20460 |
tat = tdb->getTermArgTrie(d_op); |
82 |
|
} |
83 |
|
else |
84 |
|
{ |
85 |
4963 |
if (d_pol) |
86 |
|
{ |
87 |
|
tat = tdb->getTermArgTrie(d_eqc, d_op); |
88 |
|
} |
89 |
|
else |
90 |
|
{ |
91 |
|
// iterate over all classes except r |
92 |
4963 |
tat = tdb->getTermArgTrie(Node::null(), d_op); |
93 |
4963 |
if (tat && !d_qstate.isInConflict()) |
94 |
|
{ |
95 |
9926 |
Node r = d_qstate.getRepresentative(d_eqc); |
96 |
18630 |
for (std::pair<const TNode, TNodeTrie>& t : tat->d_data) |
97 |
|
{ |
98 |
13667 |
if (t.first != r) |
99 |
|
{ |
100 |
20872 |
InstMatch m(q); |
101 |
10436 |
addInstantiations(m, addedLemmas, 0, &(t.second)); |
102 |
10436 |
if (d_qstate.isInConflict()) |
103 |
|
{ |
104 |
|
break; |
105 |
|
} |
106 |
|
} |
107 |
|
} |
108 |
|
} |
109 |
4963 |
tat = nullptr; |
110 |
|
} |
111 |
|
} |
112 |
50846 |
Debug("simple-trigger-debug") |
113 |
25423 |
<< "Adding instantiations based on " << tat << " from " << d_op << " " |
114 |
25423 |
<< d_eqc << std::endl; |
115 |
25423 |
if (tat && !d_qstate.isInConflict()) |
116 |
|
{ |
117 |
24242 |
InstMatch m(q); |
118 |
12121 |
addInstantiations(m, addedLemmas, 0, tat); |
119 |
|
} |
120 |
25423 |
return addedLemmas; |
121 |
|
} |
122 |
|
|
123 |
201700 |
void InstMatchGeneratorSimple::addInstantiations(InstMatch& m, |
124 |
|
uint64_t& addedLemmas, |
125 |
|
size_t argIndex, |
126 |
|
TNodeTrie* tat) |
127 |
|
{ |
128 |
403400 |
Debug("simple-trigger-debug") |
129 |
201700 |
<< "Add inst " << argIndex << " " << d_match_pattern << std::endl; |
130 |
201700 |
if (argIndex == d_match_pattern.getNumChildren()) |
131 |
|
{ |
132 |
49338 |
Assert(!tat->d_data.empty()); |
133 |
98676 |
TNode t = tat->getData(); |
134 |
49338 |
Debug("simple-trigger") << "Actual term is " << t << std::endl; |
135 |
|
// convert to actual used terms |
136 |
168308 |
for (const auto& v : d_var_num) |
137 |
|
{ |
138 |
118970 |
if (v.second >= 0) |
139 |
|
{ |
140 |
118970 |
Assert(v.first < t.getNumChildren()); |
141 |
237940 |
Debug("simple-trigger") |
142 |
118970 |
<< "...set " << v.second << " " << t[v.first] << std::endl; |
143 |
118970 |
m.setValue(v.second, t[v.first]); |
144 |
|
} |
145 |
|
} |
146 |
|
// we do not need the trigger parent for simple triggers (no post-processing |
147 |
|
// required) |
148 |
49338 |
if (sendInstantiation(m, InferenceId::QUANTIFIERS_INST_E_MATCHING_SIMPLE)) |
149 |
|
{ |
150 |
13481 |
addedLemmas++; |
151 |
13481 |
Debug("simple-trigger") << "-> Produced instantiation " << m << std::endl; |
152 |
|
} |
153 |
49338 |
return; |
154 |
|
} |
155 |
152362 |
if (d_match_pattern[argIndex].getKind() == INST_CONSTANT) |
156 |
|
{ |
157 |
80057 |
int v = d_var_num[argIndex]; |
158 |
80057 |
if (v != -1) |
159 |
|
{ |
160 |
253148 |
for (std::pair<const TNode, TNodeTrie>& tt : tat->d_data) |
161 |
|
{ |
162 |
346182 |
Node t = tt.first; |
163 |
346182 |
Node prev = m.get(v); |
164 |
|
// using representatives, just check if equal |
165 |
173091 |
Assert(t.getType().isComparableTo(d_match_pattern_arg_types[argIndex])); |
166 |
173091 |
if (prev.isNull() || prev == t) |
167 |
|
{ |
168 |
168847 |
m.setValue(v, t); |
169 |
168847 |
addInstantiations(m, addedLemmas, argIndex + 1, &(tt.second)); |
170 |
168847 |
m.setValue(v, prev); |
171 |
168847 |
if (d_qstate.isInConflict()) |
172 |
|
{ |
173 |
|
break; |
174 |
|
} |
175 |
|
} |
176 |
|
} |
177 |
80057 |
return; |
178 |
|
} |
179 |
|
// inst constant from another quantified formula, treat as ground term? |
180 |
|
} |
181 |
144610 |
Node r = d_qstate.getRepresentative(d_match_pattern[argIndex]); |
182 |
72305 |
std::map<TNode, TNodeTrie>::iterator it = tat->d_data.find(r); |
183 |
72305 |
if (it != tat->d_data.end()) |
184 |
|
{ |
185 |
10296 |
addInstantiations(m, addedLemmas, argIndex + 1, &(it->second)); |
186 |
|
} |
187 |
|
} |
188 |
|
|
189 |
|
int InstMatchGeneratorSimple::getActiveScore() |
190 |
|
{ |
191 |
|
TermDb* tdb = d_treg.getTermDatabase(); |
192 |
|
Node f = tdb->getMatchOperator(d_match_pattern); |
193 |
|
size_t ngt = tdb->getNumGroundTerms(f); |
194 |
|
Trace("trigger-active-sel-debug") << "Number of ground terms for (simple) " |
195 |
|
<< f << " is " << ngt << std::endl; |
196 |
|
return static_cast<int>(ngt); |
197 |
|
} |
198 |
|
|
199 |
|
} // namespace inst |
200 |
|
} // namespace quantifiers |
201 |
|
} // namespace theory |
202 |
29340 |
} // namespace cvc5 |