mirror of
https://github.com/Z3Prover/z3
synced 2025-06-16 19:06:17 +00:00
add bv-size reduce #6137
- add option smt.bv.reduce_size. - it allows to apply incremental pre-processing of bit-vectors by identifying ranges that are known to be constant. This rewrite is beneficial, for instance, when bit-vectors are constrained to have many high-level bits set to 0.
This commit is contained in:
parent
45a4b810de
commit
48b13291d1
8 changed files with 78 additions and 0 deletions
|
@ -26,6 +26,7 @@ Revision History:
|
|||
#include "ast/pattern/pattern_inference.h"
|
||||
#include "ast/macros/quasi_macros.h"
|
||||
#include "ast/occurs.h"
|
||||
#include "ast/bv_decl_plugin.h"
|
||||
#include "solver/assertions/asserted_formulas.h"
|
||||
|
||||
|
||||
|
@ -54,6 +55,7 @@ asserted_formulas::asserted_formulas(ast_manager & m, smt_params & sp, params_re
|
|||
m_elim_bvs_from_quantifiers(*this),
|
||||
m_cheap_quant_fourier_motzkin(*this),
|
||||
m_apply_bit2int(*this),
|
||||
m_bv_size_reduce(*this),
|
||||
m_lift_ite(*this),
|
||||
m_ng_lift_ite(*this),
|
||||
m_find_macros(*this),
|
||||
|
@ -205,6 +207,7 @@ void asserted_formulas::push_scope_core() {
|
|||
m_elim_term_ite.push();
|
||||
m_bv_sharing.push_scope();
|
||||
m_macro_manager.push_scope();
|
||||
m_bv_size_reduce.push_scope();
|
||||
commit();
|
||||
TRACE("asserted_formulas_scopes", tout << "after push: " << m_scopes.size() << "\n");
|
||||
}
|
||||
|
@ -225,6 +228,7 @@ void asserted_formulas::pop_scope(unsigned num_scopes) {
|
|||
TRACE("asserted_formulas_scopes", tout << "before pop " << num_scopes << " of " << m_scopes.size() << "\n";);
|
||||
m_bv_sharing.pop_scope(num_scopes);
|
||||
m_macro_manager.pop_scope(num_scopes);
|
||||
m_bv_size_reduce.pop_scope(num_scopes);
|
||||
unsigned new_lvl = m_scopes.size() - num_scopes;
|
||||
scope & s = m_scopes[new_lvl];
|
||||
m_inconsistent = s.m_inconsistent_old;
|
||||
|
@ -293,6 +297,7 @@ void asserted_formulas::reduce() {
|
|||
if (!invoke(m_find_macros)) return;
|
||||
if (!invoke(m_apply_quasi_macros)) return;
|
||||
if (!invoke(m_apply_bit2int)) return;
|
||||
if (!invoke(m_bv_size_reduce)) return;
|
||||
if (!invoke(m_cheap_quant_fourier_motzkin)) return;
|
||||
if (!invoke(m_pattern_inference)) return;
|
||||
if (!invoke(m_max_bv_sharing_fn)) return;
|
||||
|
@ -717,6 +722,40 @@ void asserted_formulas::refine_inj_axiom_fn::simplify(justified_expr const& j, e
|
|||
}
|
||||
|
||||
|
||||
void asserted_formulas::bv_size_reduce_fn::simplify(justified_expr const& j, expr_ref& n, proof_ref& p) {
|
||||
bv_util bv(m);
|
||||
expr* f = j.get_fml();
|
||||
expr* a, *b, *x;
|
||||
unsigned lo, hi;
|
||||
rational r;
|
||||
expr_ref new_term(m);
|
||||
auto check_reduce = [&](expr* a, expr* b) {
|
||||
if (bv.is_extract(a, lo, hi, x) && lo > 0 && hi + 1 == bv.get_bv_size(x) && bv.is_numeral(b, r) && r == 0) {
|
||||
// insert x -> x[0,lo-1] ++ n into sub
|
||||
new_term = bv.mk_concat(bv.mk_extract(lo - 1, 0, x), b);
|
||||
m_sub.insert(x, new_term);
|
||||
n = j.get_fml();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
if (m.is_eq(f, a, b) && (check_reduce(a, b) || check_reduce(b, a))) {
|
||||
// done
|
||||
}
|
||||
else {
|
||||
n = j.get_fml();
|
||||
m_sub(n);
|
||||
}
|
||||
}
|
||||
|
||||
void asserted_formulas::bv_size_reduce_fn::push_scope() {
|
||||
m_sub.push_scope();
|
||||
}
|
||||
|
||||
void asserted_formulas::bv_size_reduce_fn::pop_scope(unsigned n) {
|
||||
m_sub.pop_scope(n);
|
||||
}
|
||||
|
||||
unsigned asserted_formulas::get_total_size() const {
|
||||
expr_mark visited;
|
||||
unsigned r = 0;
|
||||
|
|
|
@ -30,6 +30,7 @@ Revision History:
|
|||
#include "ast/rewriter/bv_elim.h"
|
||||
#include "ast/rewriter/der.h"
|
||||
#include "ast/rewriter/elim_bounds.h"
|
||||
#include "ast/rewriter/expr_safe_replace.h"
|
||||
#include "ast/macros/macro_manager.h"
|
||||
#include "ast/macros/macro_finder.h"
|
||||
#include "ast/normal_forms/defined_names.h"
|
||||
|
@ -150,6 +151,16 @@ class asserted_formulas {
|
|||
void post_op() override { af.m_reduce_asserted_formulas(); }
|
||||
};
|
||||
|
||||
class bv_size_reduce_fn : public simplify_fmls {
|
||||
expr_safe_replace m_sub;
|
||||
public:
|
||||
bv_size_reduce_fn(asserted_formulas& af): simplify_fmls(af, "bv-size-reduce"), m_sub(af.m) {}
|
||||
bool should_apply() const override { return af.m_smt_params.m_bv_size_reduce; }
|
||||
void simplify(justified_expr const& j, expr_ref& n, proof_ref& p) override;
|
||||
void push_scope();
|
||||
void pop_scope(unsigned n);
|
||||
};
|
||||
|
||||
class elim_term_ite_fn : public simplify_fmls {
|
||||
elim_term_ite_rw m_elim;
|
||||
public:
|
||||
|
@ -205,6 +216,7 @@ class asserted_formulas {
|
|||
elim_bvs_from_quantifiers m_elim_bvs_from_quantifiers;
|
||||
cheap_quant_fourier_motzkin m_cheap_quant_fourier_motzkin;
|
||||
apply_bit2int m_apply_bit2int;
|
||||
bv_size_reduce_fn m_bv_size_reduce;
|
||||
lift_ite m_lift_ite;
|
||||
ng_lift_ite m_ng_lift_ite;
|
||||
find_macros_fn m_find_macros;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue