16
16
#include " theory/bv/macro_rewrite_elaborator.h"
17
17
18
18
#include " expr/aci_norm.h"
19
- #include " proof/proof_checker.h"
20
- #include " proof/proof_node_algorithm.h"
21
19
#include " proof/conv_proof_generator.h"
20
+ #include " proof/proof_checker.h"
22
21
#include " proof/proof_node.h"
22
+ #include " proof/proof_node_algorithm.h"
23
23
#include " proof/proof_node_manager.h"
24
- #include " theory/bv/theory_bv_rewrite_rules_core.h"
25
24
#include " smt/env.h"
25
+ #include " theory/bv/theory_bv_rewrite_rules_core.h"
26
26
27
27
namespace cvc5 ::internal {
28
28
namespace theory {
@@ -34,7 +34,7 @@ bool MacroRewriteElaborator::ensureProofFor(CDProof* cdp,
34
34
ProofRewriteRule id,
35
35
const Node& eq)
36
36
{
37
- Assert (eq.getKind ()== Kind::EQUAL);
37
+ Assert (eq.getKind () == Kind::EQUAL);
38
38
Trace (" bv-rew-elab" ) << " ensureProofFor: " << id << " " << eq << std::endl;
39
39
switch (id)
40
40
{
@@ -93,7 +93,7 @@ bool MacroRewriteElaborator::ensureProofForSimplify(CDProof* cdp,
93
93
std::vector<Node> premises;
94
94
premises.push_back (ceq);
95
95
Node equiv2 = proveCong (cdp, eq0c, premises);
96
- Assert (equiv2.getKind ()== Kind::EQUAL);
96
+ Assert (equiv2.getKind () == Kind::EQUAL);
97
97
transEq.push_back (equiv2);
98
98
if (equiv2[1 ] != eq[1 ])
99
99
{
@@ -112,7 +112,8 @@ bool MacroRewriteElaborator::ensureProofForSimplify(CDProof* cdp,
112
112
return true ;
113
113
}
114
114
115
- bool MacroRewriteElaborator::ensureProofForConcatMerge (CDProof* cdp, const Node& eq)
115
+ bool MacroRewriteElaborator::ensureProofForConcatMerge (CDProof* cdp,
116
+ const Node& eq)
116
117
{
117
118
// below, we group portions of the concatenation into a form in which they
118
119
// can be rewritten in isolation. We prove the grouping by ACI_NORM, then
@@ -125,24 +126,29 @@ bool MacroRewriteElaborator::ensureProofForConcatMerge(CDProof* cdp, const Node&
125
126
Node currRew;
126
127
Kind ck = Kind::UNDEFINED_KIND;
127
128
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++)
129
130
{
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))
132
134
{
133
- if (ck== Kind::BITVECTOR_EXTRACT)
135
+ if (ck == Kind::BITVECTOR_EXTRACT)
134
136
{
135
- Assert (curr.size ()== 1 );
137
+ Assert (curr.size () == 1 );
136
138
curr[0 ] = nm->mkNode (Kind::BITVECTOR_CONCAT, curr[0 ], next);
137
139
currRew = nm->mkNode (Kind::BITVECTOR_CONCAT, currRew, next);
138
- Node rcr = RewriteRule<ConcatExtractMerge>::run<true >(currRew);
140
+ Node rcr = RewriteRule<ConcatExtractMerge>::run<true >(currRew);
139
141
// 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);
141
147
currRew = rcr;
142
148
}
143
149
else
144
150
{
145
- Assert (ck== Kind::CONST_BITVECTOR);
151
+ Assert (ck == Kind::CONST_BITVECTOR);
146
152
curr.push_back (next);
147
153
}
148
154
}
@@ -151,11 +157,15 @@ bool MacroRewriteElaborator::ensureProofForConcatMerge(CDProof* cdp, const Node&
151
157
if (!curr.empty ())
152
158
{
153
159
Node rem;
154
- if (curr.size ()> 1 )
160
+ if (curr.size () > 1 )
155
161
{
156
162
rem = nm->mkNode (Kind::BITVECTOR_CONCAT, curr);
157
163
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);
159
169
}
160
170
else
161
171
{
@@ -169,7 +179,8 @@ bool MacroRewriteElaborator::ensureProofForConcatMerge(CDProof* cdp, const Node&
169
179
ck = next.getKind ();
170
180
}
171
181
}
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);
173
184
Node equiv1 = eq[0 ].eqNode (gc);
174
185
Trace (" bv-rew-elab" ) << " - grouped concat: " << equiv1 << std::endl;
175
186
cdp->addStep (equiv1, ProofRule::ACI_NORM, {}, {equiv1});
@@ -178,27 +189,28 @@ bool MacroRewriteElaborator::ensureProofForConcatMerge(CDProof* cdp, const Node&
178
189
cdp->addProof (pfn);
179
190
Node equiv2 = pfn->getResult ();
180
191
Trace (" bv-rew-elab" ) << " - rewritten: " << equiv2 << std::endl;
181
- if (equiv2[1 ]== eq[1 ])
192
+ if (equiv2[1 ] == eq[1 ])
182
193
{
183
194
cdp->addStep (eq, ProofRule::TRANS, {equiv1, equiv2}, {});
184
195
return true ;
185
196
}
186
197
return false ;
187
198
}
188
199
189
- bool MacroRewriteElaborator::ensureProofForExtractConcat (CDProof* cdp, const Node& eq)
200
+ bool MacroRewriteElaborator::ensureProofForExtractConcat (CDProof* cdp,
201
+ const Node& eq)
190
202
{
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.
195
207
NodeManager* nm = nodeManager ();
196
- Assert (eq[0 ].getKind ()== Kind::BITVECTOR_EXTRACT);
208
+ Assert (eq[0 ].getKind () == Kind::BITVECTOR_EXTRACT);
197
209
Node concat = eq[0 ][0 ];
198
- Assert (concat.getKind ()== Kind::BITVECTOR_CONCAT);
210
+ Assert (concat.getKind () == Kind::BITVECTOR_CONCAT);
199
211
Node curr = concat[0 ];
200
212
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++)
202
214
{
203
215
curr = nm->mkNode (Kind::BITVECTOR_CONCAT, curr, concat[i]);
204
216
}
@@ -209,23 +221,25 @@ bool MacroRewriteElaborator::ensureProofForExtractConcat(CDProof* cdp, const Nod
209
221
Node equiv1 = proveCong (cdp, eq[0 ], {ceq});
210
222
transEq.push_back (equiv1);
211
223
Trace (" bv-rew-elab" ) << " - grouped extract-concat: " << equiv1 << std::endl;
212
- Assert (equiv1.getKind ()== Kind::EQUAL);
224
+ Assert (equiv1.getKind () == Kind::EQUAL);
213
225
Node exc = equiv1[1 ];
214
226
TConvProofGenerator tcpg (d_env);
215
227
while (RewriteRule<ExtractConcat>::applies (exc))
216
228
{
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);
220
233
// 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)
223
237
{
224
238
exc = excr;
225
239
}
226
- else if (excr.getKind ()== Kind::BITVECTOR_CONCAT)
240
+ else if (excr.getKind () == Kind::BITVECTOR_CONCAT)
227
241
{
228
- Assert (excr.getNumChildren ()== 2 );
242
+ Assert (excr.getNumChildren () == 2 );
229
243
exc = excr[0 ];
230
244
}
231
245
else
@@ -239,7 +253,7 @@ bool MacroRewriteElaborator::ensureProofForExtractConcat(CDProof* cdp, const Nod
239
253
Node equiv2 = pfn->getResult ();
240
254
transEq.push_back (equiv2);
241
255
Trace (" bv-rew-elab" ) << " - grouped concat: " << equiv2 << std::endl;
242
- if (equiv2[1 ]!= eq[1 ])
256
+ if (equiv2[1 ] != eq[1 ])
243
257
{
244
258
if (expr::isACINorm (equiv2[1 ], eq[1 ]))
245
259
{
@@ -263,46 +277,55 @@ bool MacroRewriteElaborator::ensureProofForMultSltMult(CDProof* cdp,
263
277
// bv-mult-slt-mult-1 and bv-mult-slt-mult-2 by turning concatenation
264
278
// with zero into a zero extend, and flipping multiplication if applicable.
265
279
NodeManager* nm = nodeManager ();
266
- Assert (eq[0 ].getKind ()== Kind::BITVECTOR_SLT);
280
+ Assert (eq[0 ].getKind () == Kind::BITVECTOR_SLT);
267
281
TConvProofGenerator tcpg (d_env);
268
- for (size_t i= 0 ; i< 2 ; i++)
282
+ for (size_t i = 0 ; i < 2 ; i++)
269
283
{
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 );
272
286
std::vector<Node> ch;
273
- for (size_t j= 0 ; j< 2 ; j++)
287
+ for (size_t j = 0 ; j < 2 ; j++)
274
288
{
275
289
Node n = eq[0 ][i][j];
276
- if (n.getKind ()== Kind::BITVECTOR_CONCAT)
290
+ if (n.getKind () == Kind::BITVECTOR_CONCAT)
277
291
{
278
292
size_t sz = utils::getSize (n[0 ]);
279
293
if (n[0 ] == utils::mkZero (sz))
280
294
{
281
295
// turn concatenation with zero into zero extend
282
296
Node zext = nm->mkConst (BitVectorZeroExtend (sz));
283
297
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);
285
303
ch.push_back (nze);
286
304
continue ;
287
305
}
288
306
}
289
307
ch.push_back (n);
290
308
}
291
- if (ch[1 ].getKind ()== Kind::BITVECTOR_ZERO_EXTEND)
309
+ if (ch[1 ].getKind () == Kind::BITVECTOR_ZERO_EXTEND)
292
310
{
293
- Assert (ch[0 ].getKind ()!= Kind::BITVECTOR_ZERO_EXTEND);
311
+ Assert (ch[0 ].getKind () != Kind::BITVECTOR_ZERO_EXTEND);
294
312
// swap to match rule
295
313
Node mul = nm->mkNode (eq[0 ][i].getKind (), ch[0 ], ch[1 ]);
296
314
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);
298
320
}
299
321
}
300
322
std::shared_ptr<ProofNode> pfn = tcpg.getProofForRewriting (eq[0 ]);
301
323
cdp->addProof (pfn);
302
324
Node equiv1 = pfn->getResult ();
303
325
Trace (" bv-rew-elab" ) << " - cast to zero extend: " << equiv1 << std::endl;
304
326
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, {}, {});
306
329
cdp->addStep (eq, ProofRule::TRANS, {equiv1, equiv2}, {});
307
330
return true ;
308
331
}
0 commit comments