Skip to content

Commit

Permalink
add rewriters for and
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
  • Loading branch information
NikolajBjorner committed Dec 15, 2023
1 parent 4778f27 commit b44ab2f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/ast/rewriter/arith_rewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ br_status arith_rewriter::mk_app_core(func_decl * f, unsigned num_args, expr * c
case OP_SINH: SASSERT(num_args == 1); st = mk_sinh_core(args[0], result); break;
case OP_COSH: SASSERT(num_args == 1); st = mk_cosh_core(args[0], result); break;
case OP_TANH: SASSERT(num_args == 1); st = mk_tanh_core(args[0], result); break;
case OP_ARITH_BAND: SASSERT(num_args == 2); st = mk_band_core(f->get_parameter(0).get_int(), args[0], args[1], result); break;
default: st = BR_FAILED; break;
}
CTRACE("arith_rewriter", st != BR_FAILED, tout << st << ": " << mk_pp(f, m);
Expand Down Expand Up @@ -1349,6 +1350,34 @@ app* arith_rewriter_core::mk_power(expr* x, rational const& r, sort* s) {
return y;
}

br_status arith_rewriter::mk_band_core(unsigned sz, expr* arg1, expr* arg2, expr_ref& result) {
numeral x, y, N;
bool is_num_x = m_util.is_numeral(arg1, x);
bool is_num_y = m_util.is_numeral(arg2, y);
N = rational::power_of_two(sz);
if (is_num_x)
x = mod(x, N);
if (is_num_y)
y = mod(y, N);
if (is_num_x && x.is_zero()) {
result = m_util.mk_int(0);
return BR_DONE;
}
if (is_num_y && y.is_zero()) {
result = m_util.mk_int(0);
return BR_DONE;
}
if (is_num_x && is_num_y) {
rational r(0);
for (unsigned i = 0; i < sz; ++i)
if (x.get_bit(i) && y.get_bit(i))
r += rational::power_of_two(i);
result = m_util.mk_int(r);
return BR_DONE;
}
return BR_FAILED;
}

br_status arith_rewriter::mk_power_core(expr * arg1, expr * arg2, expr_ref & result) {
numeral x, y;
bool is_num_x = m_util.is_numeral(arg1, x);
Expand Down
1 change: 1 addition & 0 deletions src/ast/rewriter/arith_rewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class arith_rewriter : public poly_rewriter<arith_rewriter_core> {
br_status mk_mod_core(expr * arg1, expr * arg2, expr_ref & result);
br_status mk_rem_core(expr * arg1, expr * arg2, expr_ref & result);
br_status mk_power_core(expr* arg1, expr* arg2, expr_ref & result);
br_status mk_band_core(unsigned sz, expr* arg1, expr* arg2, expr_ref& result);
void mk_div(expr * arg1, expr * arg2, expr_ref & result) {
if (mk_div_core(arg1, arg2, result) == BR_FAILED)
result = m.mk_app(get_fid(), OP_DIV, arg1, arg2);
Expand Down

0 comments on commit b44ab2f

Please sign in to comment.