1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Aina Niemetz, 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 |
|
* A bit-blaster wrapper around BBSimple for proof logging. |
14 |
|
*/ |
15 |
|
#include "theory/bv/bitblast/proof_bitblaster.h" |
16 |
|
|
17 |
|
#include <unordered_set> |
18 |
|
|
19 |
|
#include "proof/conv_proof_generator.h" |
20 |
|
#include "theory/theory_model.h" |
21 |
|
|
22 |
|
namespace cvc5 { |
23 |
|
namespace theory { |
24 |
|
namespace bv { |
25 |
|
|
26 |
5330 |
BBProof::BBProof(TheoryState* state, ProofNodeManager* pnm, bool fineGrained) |
27 |
5330 |
: d_bb(new NodeBitblaster(state)), |
28 |
|
d_pnm(pnm), |
29 |
5330 |
d_tcontext(new TheoryLeafTermContext(theory::THEORY_BV)), |
30 |
|
d_tcpg(pnm ? new TConvProofGenerator( |
31 |
|
pnm, |
32 |
|
nullptr, |
33 |
|
/* ONCE to visit each term only once, post-order. FIXPOINT |
34 |
|
* could lead to infinite loops due to terms being rewritten |
35 |
|
* to terms that contain themselves */ |
36 |
|
TConvPolicy::ONCE, |
37 |
|
/* STATIC to get the same ProofNode for a shared subterm. */ |
38 |
|
TConvCachePolicy::STATIC, |
39 |
|
"BBProof::TConvProofGenerator", |
40 |
2796 |
d_tcontext.get(), |
41 |
2796 |
false) |
42 |
|
: nullptr), |
43 |
18786 |
d_recordFineGrainedProofs(fineGrained) |
44 |
|
{ |
45 |
5330 |
} |
46 |
|
|
47 |
5330 |
BBProof::~BBProof() {} |
48 |
|
|
49 |
15372 |
void BBProof::bbAtom(TNode node) |
50 |
|
{ |
51 |
30744 |
std::vector<TNode> visit; |
52 |
15372 |
visit.push_back(node); |
53 |
30744 |
std::unordered_set<TNode> visited; |
54 |
|
|
55 |
15372 |
bool fpenabled = isProofsEnabled() && d_recordFineGrainedProofs; |
56 |
|
|
57 |
15372 |
NodeManager* nm = NodeManager::currentNM(); |
58 |
|
|
59 |
340842 |
while (!visit.empty()) |
60 |
|
{ |
61 |
265683 |
TNode n = visit.back(); |
62 |
222522 |
if (hasBBAtom(n) || hasBBTerm(n)) |
63 |
|
{ |
64 |
59787 |
visit.pop_back(); |
65 |
59787 |
continue; |
66 |
|
} |
67 |
|
|
68 |
102948 |
if (visited.find(n) == visited.end()) |
69 |
|
{ |
70 |
51350 |
visited.insert(n); |
71 |
51350 |
if (!Theory::isLeafOf(n, theory::THEORY_BV)) |
72 |
|
{ |
73 |
38768 |
visit.insert(visit.end(), n.begin(), n.end()); |
74 |
|
} |
75 |
|
} |
76 |
|
else |
77 |
|
{ |
78 |
51598 |
if (Theory::isLeafOf(n, theory::THEORY_BV) && !n.isConst()) |
79 |
|
{ |
80 |
16494 |
Bits bits; |
81 |
8247 |
d_bb->makeVariable(n, bits); |
82 |
8247 |
if (fpenabled) |
83 |
|
{ |
84 |
6592 |
Node n_tobv = nm->mkNode(kind::BITVECTOR_BB_TERM, bits); |
85 |
3296 |
d_bbMap.emplace(n, n_tobv); |
86 |
6592 |
d_tcpg->addRewriteStep(n, |
87 |
|
n_tobv, |
88 |
|
PfRule::BV_BITBLAST_STEP, |
89 |
|
{}, |
90 |
|
{n.eqNode(n_tobv)}, |
91 |
3296 |
false); |
92 |
|
} |
93 |
|
} |
94 |
43351 |
else if (n.getType().isBitVector()) |
95 |
|
{ |
96 |
55958 |
Bits bits; |
97 |
27979 |
d_bb->bbTerm(n, bits); |
98 |
27979 |
Kind kind = n.getKind(); |
99 |
27979 |
if (fpenabled) |
100 |
|
{ |
101 |
12906 |
Node n_tobv = nm->mkNode(kind::BITVECTOR_BB_TERM, bits); |
102 |
6453 |
d_bbMap.emplace(n, n_tobv); |
103 |
12906 |
Node c_tobv; |
104 |
6453 |
if (n.isConst()) |
105 |
|
{ |
106 |
1752 |
c_tobv = n; |
107 |
|
} |
108 |
|
else |
109 |
|
{ |
110 |
9402 |
std::vector<Node> children_tobv; |
111 |
4701 |
if (n.getMetaKind() == kind::metakind::PARAMETERIZED) |
112 |
|
{ |
113 |
1419 |
children_tobv.push_back(n.getOperator()); |
114 |
|
} |
115 |
|
|
116 |
12750 |
for (const auto& child : n) |
117 |
|
{ |
118 |
8049 |
children_tobv.push_back(d_bbMap.at(child)); |
119 |
|
} |
120 |
4701 |
c_tobv = nm->mkNode(kind, children_tobv); |
121 |
|
} |
122 |
12906 |
d_tcpg->addRewriteStep(c_tobv, |
123 |
|
n_tobv, |
124 |
|
PfRule::BV_BITBLAST_STEP, |
125 |
|
{}, |
126 |
|
{c_tobv.eqNode(n_tobv)}, |
127 |
6453 |
false); |
128 |
|
} |
129 |
|
} |
130 |
|
else |
131 |
|
{ |
132 |
15372 |
d_bb->bbAtom(n); |
133 |
15372 |
if (fpenabled) |
134 |
|
{ |
135 |
3132 |
Node n_tobv = getStoredBBAtom(n); |
136 |
3132 |
std::vector<Node> children_tobv; |
137 |
4698 |
for (const auto& child : n) |
138 |
|
{ |
139 |
3132 |
children_tobv.push_back(d_bbMap.at(child)); |
140 |
|
} |
141 |
3132 |
Node c_tobv = nm->mkNode(n.getKind(), children_tobv); |
142 |
3132 |
d_tcpg->addRewriteStep(c_tobv, |
143 |
|
n_tobv, |
144 |
|
PfRule::BV_BITBLAST_STEP, |
145 |
|
{}, |
146 |
|
{c_tobv.eqNode(n_tobv)}, |
147 |
1566 |
false); |
148 |
|
} |
149 |
|
} |
150 |
51598 |
visit.pop_back(); |
151 |
|
} |
152 |
|
} |
153 |
|
/* Record coarse-grain bit-blast proof step. */ |
154 |
15372 |
if (isProofsEnabled() && !d_recordFineGrainedProofs) |
155 |
|
{ |
156 |
7934 |
Node node_tobv = getStoredBBAtom(node); |
157 |
7934 |
d_tcpg->addRewriteStep(node, |
158 |
|
node_tobv, |
159 |
|
PfRule::BV_BITBLAST, |
160 |
|
{}, |
161 |
|
{node.eqNode(node_tobv)}, |
162 |
3967 |
false); |
163 |
|
} |
164 |
15372 |
} |
165 |
|
|
166 |
1053999 |
bool BBProof::hasBBAtom(TNode atom) const { return d_bb->hasBBAtom(atom); } |
167 |
|
|
168 |
163044 |
bool BBProof::hasBBTerm(TNode atom) const { return d_bb->hasBBTerm(atom); } |
169 |
|
|
170 |
898363 |
Node BBProof::getStoredBBAtom(TNode node) |
171 |
|
{ |
172 |
898363 |
return d_bb->getStoredBBAtom(node); |
173 |
|
} |
174 |
|
|
175 |
123 |
void BBProof::getBBTerm(TNode node, Bits& bits) const |
176 |
|
{ |
177 |
123 |
d_bb->getBBTerm(node, bits); |
178 |
123 |
} |
179 |
|
|
180 |
1620 |
bool BBProof::collectModelValues(TheoryModel* m, |
181 |
|
const std::set<Node>& relevantTerms) |
182 |
|
{ |
183 |
1620 |
return d_bb->collectModelValues(m, relevantTerms); |
184 |
|
} |
185 |
|
|
186 |
99865 |
TConvProofGenerator* BBProof::getProofGenerator() { return d_tcpg.get(); } |
187 |
|
|
188 |
30744 |
bool BBProof::isProofsEnabled() const { return d_pnm != nullptr; } |
189 |
|
|
190 |
|
} // namespace bv |
191 |
|
} // namespace theory |
192 |
29502 |
} // namespace cvc5 |