Skip to content

Commit b44ab2f

Browse files
add rewriters for and
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
1 parent 4778f27 commit b44ab2f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/ast/rewriter/arith_rewriter.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ br_status arith_rewriter::mk_app_core(func_decl * f, unsigned num_args, expr * c
9191
case OP_SINH: SASSERT(num_args == 1); st = mk_sinh_core(args[0], result); break;
9292
case OP_COSH: SASSERT(num_args == 1); st = mk_cosh_core(args[0], result); break;
9393
case OP_TANH: SASSERT(num_args == 1); st = mk_tanh_core(args[0], result); break;
94+
case OP_ARITH_BAND: SASSERT(num_args == 2); st = mk_band_core(f->get_parameter(0).get_int(), args[0], args[1], result); break;
9495
default: st = BR_FAILED; break;
9596
}
9697
CTRACE("arith_rewriter", st != BR_FAILED, tout << st << ": " << mk_pp(f, m);
@@ -1349,6 +1350,34 @@ app* arith_rewriter_core::mk_power(expr* x, rational const& r, sort* s) {
13491350
return y;
13501351
}
13511352

1353+
br_status arith_rewriter::mk_band_core(unsigned sz, expr* arg1, expr* arg2, expr_ref& result) {
1354+
numeral x, y, N;
1355+
bool is_num_x = m_util.is_numeral(arg1, x);
1356+
bool is_num_y = m_util.is_numeral(arg2, y);
1357+
N = rational::power_of_two(sz);
1358+
if (is_num_x)
1359+
x = mod(x, N);
1360+
if (is_num_y)
1361+
y = mod(y, N);
1362+
if (is_num_x && x.is_zero()) {
1363+
result = m_util.mk_int(0);
1364+
return BR_DONE;
1365+
}
1366+
if (is_num_y && y.is_zero()) {
1367+
result = m_util.mk_int(0);
1368+
return BR_DONE;
1369+
}
1370+
if (is_num_x && is_num_y) {
1371+
rational r(0);
1372+
for (unsigned i = 0; i < sz; ++i)
1373+
if (x.get_bit(i) && y.get_bit(i))
1374+
r += rational::power_of_two(i);
1375+
result = m_util.mk_int(r);
1376+
return BR_DONE;
1377+
}
1378+
return BR_FAILED;
1379+
}
1380+
13521381
br_status arith_rewriter::mk_power_core(expr * arg1, expr * arg2, expr_ref & result) {
13531382
numeral x, y;
13541383
bool is_num_x = m_util.is_numeral(arg1, x);

src/ast/rewriter/arith_rewriter.h

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class arith_rewriter : public poly_rewriter<arith_rewriter_core> {
159159
br_status mk_mod_core(expr * arg1, expr * arg2, expr_ref & result);
160160
br_status mk_rem_core(expr * arg1, expr * arg2, expr_ref & result);
161161
br_status mk_power_core(expr* arg1, expr* arg2, expr_ref & result);
162+
br_status mk_band_core(unsigned sz, expr* arg1, expr* arg2, expr_ref& result);
162163
void mk_div(expr * arg1, expr * arg2, expr_ref & result) {
163164
if (mk_div_core(arg1, arg2, result) == BR_FAILED)
164165
result = m.mk_app(get_fid(), OP_DIV, arg1, arg2);

0 commit comments

Comments
 (0)