Skip to content

Commit aaba45b

Browse files
committed
Format
1 parent f322140 commit aaba45b

File tree

3 files changed

+71
-49
lines changed

3 files changed

+71
-49
lines changed

src/rewriter/basic_rewrite_rcons.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ std::ostream& operator<<(std::ostream& os, TheoryRewriteMode tm)
5959
return os;
6060
}
6161

62-
BasicRewriteRCons::BasicRewriteRCons(Env& env) : EnvObj(env),
63-
d_bvRewElab(env)
62+
BasicRewriteRCons::BasicRewriteRCons(Env& env) : EnvObj(env), d_bvRewElab(env)
6463
{
6564

6665
}

src/rewriter/basic_rewrite_rcons.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
#include "proof/proof_node_manager.h"
2727
#include "smt/env_obj.h"
2828
#include "theory/builtin/proof_checker.h"
29-
#include "theory/rewriter.h"
3029
#include "theory/bv/macro_rewrite_elaborator.h"
30+
#include "theory/rewriter.h"
3131

3232
namespace cvc5::internal {
3333
namespace rewriter {

src/theory/bv/macro_rewrite_elaborator.cpp

Lines changed: 69 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
#include "theory/bv/macro_rewrite_elaborator.h"
1717

1818
#include "expr/aci_norm.h"
19-
#include "proof/proof_checker.h"
20-
#include "proof/proof_node_algorithm.h"
2119
#include "proof/conv_proof_generator.h"
20+
#include "proof/proof_checker.h"
2221
#include "proof/proof_node.h"
22+
#include "proof/proof_node_algorithm.h"
2323
#include "proof/proof_node_manager.h"
24-
#include "theory/bv/theory_bv_rewrite_rules_core.h"
2524
#include "smt/env.h"
25+
#include "theory/bv/theory_bv_rewrite_rules_core.h"
2626

2727
namespace cvc5::internal {
2828
namespace theory {
@@ -34,7 +34,7 @@ bool MacroRewriteElaborator::ensureProofFor(CDProof* cdp,
3434
ProofRewriteRule id,
3535
const Node& eq)
3636
{
37-
Assert (eq.getKind()==Kind::EQUAL);
37+
Assert(eq.getKind() == Kind::EQUAL);
3838
Trace("bv-rew-elab") << "ensureProofFor: " << id << " " << eq << std::endl;
3939
switch (id)
4040
{
@@ -93,7 +93,7 @@ bool MacroRewriteElaborator::ensureProofForSimplify(CDProof* cdp,
9393
std::vector<Node> premises;
9494
premises.push_back(ceq);
9595
Node equiv2 = proveCong(cdp, eq0c, premises);
96-
Assert (equiv2.getKind()==Kind::EQUAL);
96+
Assert(equiv2.getKind() == Kind::EQUAL);
9797
transEq.push_back(equiv2);
9898
if (equiv2[1] != eq[1])
9999
{
@@ -112,7 +112,8 @@ bool MacroRewriteElaborator::ensureProofForSimplify(CDProof* cdp,
112112
return true;
113113
}
114114

115-
bool MacroRewriteElaborator::ensureProofForConcatMerge(CDProof* cdp, const Node& eq)
115+
bool MacroRewriteElaborator::ensureProofForConcatMerge(CDProof* cdp,
116+
const Node& eq)
116117
{
117118
// below, we group portions of the concatenation into a form in which they
118119
// can be rewritten in isolation. We prove the grouping by ACI_NORM, then
@@ -125,24 +126,29 @@ bool MacroRewriteElaborator::ensureProofForConcatMerge(CDProof* cdp, const Node&
125126
Node currRew;
126127
Kind ck = Kind::UNDEFINED_KIND;
127128
TConvProofGenerator tcpg(d_env);
128-
for (size_t i=0, nchild = concat.getNumChildren(); i<=nchild; i++)
129+
for (size_t i = 0, nchild = concat.getNumChildren(); i <= nchild; i++)
129130
{
130-
Node next = i<nchild ? concat[i] : Node::null();
131-
if (!curr.empty() && next.getKind()==ck && (ck==Kind::CONST_BITVECTOR || ck==Kind::BITVECTOR_EXTRACT))
131+
Node next = i < nchild ? concat[i] : Node::null();
132+
if (!curr.empty() && next.getKind() == ck
133+
&& (ck == Kind::CONST_BITVECTOR || ck == Kind::BITVECTOR_EXTRACT))
132134
{
133-
if (ck==Kind::BITVECTOR_EXTRACT)
135+
if (ck == Kind::BITVECTOR_EXTRACT)
134136
{
135-
Assert (curr.size()==1);
137+
Assert(curr.size() == 1);
136138
curr[0] = nm->mkNode(Kind::BITVECTOR_CONCAT, curr[0], next);
137139
currRew = nm->mkNode(Kind::BITVECTOR_CONCAT, currRew, next);
138-
Node rcr = RewriteRule<ConcatExtractMerge>::run<true>(currRew);
140+
Node rcr = RewriteRule<ConcatExtractMerge>::run<true>(currRew);
139141
// single rewrite step
140-
tcpg.addRewriteStep(currRew, rcr, nullptr, false, TrustId::MACRO_THEORY_REWRITE_RCONS_SIMPLE);
142+
tcpg.addRewriteStep(currRew,
143+
rcr,
144+
nullptr,
145+
false,
146+
TrustId::MACRO_THEORY_REWRITE_RCONS_SIMPLE);
141147
currRew = rcr;
142148
}
143149
else
144150
{
145-
Assert (ck==Kind::CONST_BITVECTOR);
151+
Assert(ck == Kind::CONST_BITVECTOR);
146152
curr.push_back(next);
147153
}
148154
}
@@ -151,11 +157,15 @@ bool MacroRewriteElaborator::ensureProofForConcatMerge(CDProof* cdp, const Node&
151157
if (!curr.empty())
152158
{
153159
Node rem;
154-
if (curr.size()>1)
160+
if (curr.size() > 1)
155161
{
156162
rem = nm->mkNode(Kind::BITVECTOR_CONCAT, curr);
157163
Node rr = evaluate(rem, {}, {});
158-
tcpg.addRewriteStep(rem, rr, nullptr, false, TrustId::MACRO_THEORY_REWRITE_RCONS_SIMPLE);
164+
tcpg.addRewriteStep(rem,
165+
rr,
166+
nullptr,
167+
false,
168+
TrustId::MACRO_THEORY_REWRITE_RCONS_SIMPLE);
159169
}
160170
else
161171
{
@@ -169,7 +179,8 @@ bool MacroRewriteElaborator::ensureProofForConcatMerge(CDProof* cdp, const Node&
169179
ck = next.getKind();
170180
}
171181
}
172-
Node gc = children.size()==1 ? children[0] : nm->mkNode(Kind::BITVECTOR_CONCAT, children);
182+
Node gc = children.size() == 1 ? children[0]
183+
: nm->mkNode(Kind::BITVECTOR_CONCAT, children);
173184
Node equiv1 = eq[0].eqNode(gc);
174185
Trace("bv-rew-elab") << "- grouped concat: " << equiv1 << std::endl;
175186
cdp->addStep(equiv1, ProofRule::ACI_NORM, {}, {equiv1});
@@ -178,27 +189,28 @@ bool MacroRewriteElaborator::ensureProofForConcatMerge(CDProof* cdp, const Node&
178189
cdp->addProof(pfn);
179190
Node equiv2 = pfn->getResult();
180191
Trace("bv-rew-elab") << "- rewritten: " << equiv2 << std::endl;
181-
if (equiv2[1]==eq[1])
192+
if (equiv2[1] == eq[1])
182193
{
183194
cdp->addStep(eq, ProofRule::TRANS, {equiv1, equiv2}, {});
184195
return true;
185196
}
186197
return false;
187198
}
188199

189-
bool MacroRewriteElaborator::ensureProofForExtractConcat(CDProof* cdp, const Node& eq)
200+
bool MacroRewriteElaborator::ensureProofForExtractConcat(CDProof* cdp,
201+
const Node& eq)
190202
{
191-
// Below, we curry the bvconcat and then apply ExtractConcat to each 2 argument
192-
// bv concat in isolation. We prove the currying via ACI_NORM and then prove
193-
// the result (which is curried) is equivalent to the right hand side with another
194-
// application of ACI_NORM.
203+
// Below, we curry the bvconcat and then apply ExtractConcat to each 2
204+
// argument bv concat in isolation. We prove the currying via ACI_NORM and
205+
// then prove the result (which is curried) is equivalent to the right hand
206+
// side with another application of ACI_NORM.
195207
NodeManager* nm = nodeManager();
196-
Assert (eq[0].getKind()==Kind::BITVECTOR_EXTRACT);
208+
Assert(eq[0].getKind() == Kind::BITVECTOR_EXTRACT);
197209
Node concat = eq[0][0];
198-
Assert (concat.getKind()==Kind::BITVECTOR_CONCAT);
210+
Assert(concat.getKind() == Kind::BITVECTOR_CONCAT);
199211
Node curr = concat[0];
200212
Trace("bv-rew-elab") << "concat is " << concat << std::endl;
201-
for (size_t i=1, nchild = concat.getNumChildren(); i<nchild; i++)
213+
for (size_t i = 1, nchild = concat.getNumChildren(); i < nchild; i++)
202214
{
203215
curr = nm->mkNode(Kind::BITVECTOR_CONCAT, curr, concat[i]);
204216
}
@@ -209,23 +221,25 @@ bool MacroRewriteElaborator::ensureProofForExtractConcat(CDProof* cdp, const Nod
209221
Node equiv1 = proveCong(cdp, eq[0], {ceq});
210222
transEq.push_back(equiv1);
211223
Trace("bv-rew-elab") << "- grouped extract-concat: " << equiv1 << std::endl;
212-
Assert (equiv1.getKind()==Kind::EQUAL);
224+
Assert(equiv1.getKind() == Kind::EQUAL);
213225
Node exc = equiv1[1];
214226
TConvProofGenerator tcpg(d_env);
215227
while (RewriteRule<ExtractConcat>::applies(exc))
216228
{
217-
Node excr = RewriteRule<ExtractConcat>::run<false>(exc);
218-
Trace("bv-rew-elab") << " - rewrite: " << exc << " -> " << excr << std::endl;
219-
Assert (exc!=excr);
229+
Node excr = RewriteRule<ExtractConcat>::run<false>(exc);
230+
Trace("bv-rew-elab") << " - rewrite: " << exc << " -> " << excr
231+
<< std::endl;
232+
Assert(exc != excr);
220233
// single rewrite step
221-
tcpg.addRewriteStep(exc, excr, nullptr, true, TrustId::MACRO_THEORY_REWRITE_RCONS_SIMPLE);
222-
if (excr.getKind()==Kind::BITVECTOR_EXTRACT)
234+
tcpg.addRewriteStep(
235+
exc, excr, nullptr, true, TrustId::MACRO_THEORY_REWRITE_RCONS_SIMPLE);
236+
if (excr.getKind() == Kind::BITVECTOR_EXTRACT)
223237
{
224238
exc = excr;
225239
}
226-
else if (excr.getKind()==Kind::BITVECTOR_CONCAT)
240+
else if (excr.getKind() == Kind::BITVECTOR_CONCAT)
227241
{
228-
Assert (excr.getNumChildren()==2);
242+
Assert(excr.getNumChildren() == 2);
229243
exc = excr[0];
230244
}
231245
else
@@ -239,7 +253,7 @@ bool MacroRewriteElaborator::ensureProofForExtractConcat(CDProof* cdp, const Nod
239253
Node equiv2 = pfn->getResult();
240254
transEq.push_back(equiv2);
241255
Trace("bv-rew-elab") << "- grouped concat: " << equiv2 << std::endl;
242-
if (equiv2[1]!=eq[1])
256+
if (equiv2[1] != eq[1])
243257
{
244258
if (expr::isACINorm(equiv2[1], eq[1]))
245259
{
@@ -263,46 +277,55 @@ bool MacroRewriteElaborator::ensureProofForMultSltMult(CDProof* cdp,
263277
// bv-mult-slt-mult-1 and bv-mult-slt-mult-2 by turning concatenation
264278
// with zero into a zero extend, and flipping multiplication if applicable.
265279
NodeManager* nm = nodeManager();
266-
Assert (eq[0].getKind()==Kind::BITVECTOR_SLT);
280+
Assert(eq[0].getKind() == Kind::BITVECTOR_SLT);
267281
TConvProofGenerator tcpg(d_env);
268-
for (size_t i=0; i<2; i++)
282+
for (size_t i = 0; i < 2; i++)
269283
{
270-
Assert (eq[0][i].getKind()==Kind::BITVECTOR_MULT);
271-
Assert (eq[0][i].getNumChildren()==2);
284+
Assert(eq[0][i].getKind() == Kind::BITVECTOR_MULT);
285+
Assert(eq[0][i].getNumChildren() == 2);
272286
std::vector<Node> ch;
273-
for (size_t j=0; j<2; j++)
287+
for (size_t j = 0; j < 2; j++)
274288
{
275289
Node n = eq[0][i][j];
276-
if (n.getKind()==Kind::BITVECTOR_CONCAT)
290+
if (n.getKind() == Kind::BITVECTOR_CONCAT)
277291
{
278292
size_t sz = utils::getSize(n[0]);
279293
if (n[0] == utils::mkZero(sz))
280294
{
281295
// turn concatenation with zero into zero extend
282296
Node zext = nm->mkConst(BitVectorZeroExtend(sz));
283297
Node nze = nm->mkNode(zext, n[1]);
284-
tcpg.addRewriteStep(n, nze, nullptr, false, TrustId::MACRO_THEORY_REWRITE_RCONS_SIMPLE);
298+
tcpg.addRewriteStep(n,
299+
nze,
300+
nullptr,
301+
false,
302+
TrustId::MACRO_THEORY_REWRITE_RCONS_SIMPLE);
285303
ch.push_back(nze);
286304
continue;
287305
}
288306
}
289307
ch.push_back(n);
290308
}
291-
if (ch[1].getKind()==Kind::BITVECTOR_ZERO_EXTEND)
309+
if (ch[1].getKind() == Kind::BITVECTOR_ZERO_EXTEND)
292310
{
293-
Assert (ch[0].getKind()!=Kind::BITVECTOR_ZERO_EXTEND);
311+
Assert(ch[0].getKind() != Kind::BITVECTOR_ZERO_EXTEND);
294312
// swap to match rule
295313
Node mul = nm->mkNode(eq[0][i].getKind(), ch[0], ch[1]);
296314
Node muls = nm->mkNode(eq[0][i].getKind(), ch[1], ch[0]);
297-
tcpg.addRewriteStep(mul, muls, nullptr, false, TrustId::MACRO_THEORY_REWRITE_RCONS_SIMPLE);
315+
tcpg.addRewriteStep(mul,
316+
muls,
317+
nullptr,
318+
false,
319+
TrustId::MACRO_THEORY_REWRITE_RCONS_SIMPLE);
298320
}
299321
}
300322
std::shared_ptr<ProofNode> pfn = tcpg.getProofForRewriting(eq[0]);
301323
cdp->addProof(pfn);
302324
Node equiv1 = pfn->getResult();
303325
Trace("bv-rew-elab") << "- cast to zero extend: " << equiv1 << std::endl;
304326
Node equiv2 = equiv1[1].eqNode(eq[1]);
305-
cdp->addTrustedStep(equiv2, TrustId::MACRO_THEORY_REWRITE_RCONS_SIMPLE, {}, {});
327+
cdp->addTrustedStep(
328+
equiv2, TrustId::MACRO_THEORY_REWRITE_RCONS_SIMPLE, {}, {});
306329
cdp->addStep(eq, ProofRule::TRANS, {equiv1, equiv2}, {});
307330
return true;
308331
}

0 commit comments

Comments
 (0)