mirror of
https://github.com/Z3Prover/z3
synced 2025-04-24 01:25:31 +00:00
Add simplification customization for SMTLIB2
Add the ability to customize incremental pre-processing simplification for the SMTLIB2 front-end. The main new capability is to use pre-processing tactics in incremental mode that were previously not available. The main new capabilities are - solve-eqs - reduce-args - elim-unconstrained There are several more. Documentation and exposed simplifiers are populated incrementally. The current set of supported simplifiers can be inspected by using z3 with the --simplifiers flag or referring to https://microsoft.github.io/z3guide/docs/strategies/simplifiers Some pending features are: - add the ability to update parameters to simplifiers similar to how tactics can be controlled using parameters. - expose simplification solvers over the binary API.
This commit is contained in:
parent
dd0decfe5d
commit
6022c17131
32 changed files with 370 additions and 69 deletions
|
@ -29,4 +29,8 @@ z3_add_component(simplifiers
|
|||
normal_forms
|
||||
rewriter
|
||||
substitution
|
||||
TACTIC_HEADERS
|
||||
bit_blaster.h
|
||||
rewriter_simplifier.h
|
||||
|
||||
)
|
||||
|
|
|
@ -49,3 +49,6 @@ public:
|
|||
|
||||
};
|
||||
|
||||
/*
|
||||
ADD_SIMPLIFIER("bit-blaster", "reduce bit-vector expressions into SAT.", "[](auto& m, auto& p, auto &s) -> dependent_expr_simplifier* { return alloc(bit_blaster_simplifier, m, p, s); }")
|
||||
*/
|
||||
|
|
|
@ -32,6 +32,7 @@ Author:
|
|||
#include "util/trail.h"
|
||||
#include "util/statistics.h"
|
||||
#include "util/params.h"
|
||||
#include "util/z3_exception.h"
|
||||
#include "ast/converters/model_converter.h"
|
||||
#include "ast/simplifiers/dependent_expr.h"
|
||||
#include "ast/simplifiers/model_reconstruction_trail.h"
|
||||
|
@ -98,6 +99,17 @@ public:
|
|||
bool has_quantifiers();
|
||||
};
|
||||
|
||||
class default_dependent_expr_state : public dependent_expr_state {
|
||||
public:
|
||||
default_dependent_expr_state(ast_manager& m): dependent_expr_state(m) {}
|
||||
virtual unsigned qtail() const { return 0; }
|
||||
virtual dependent_expr const& operator[](unsigned i) { throw default_exception("unexpected access"); }
|
||||
virtual void update(unsigned i, dependent_expr const& j) { throw default_exception("unexpected update"); }
|
||||
virtual void add(dependent_expr const& j) { throw default_exception("unexpected addition"); }
|
||||
virtual bool inconsistent() { return false; }
|
||||
virtual model_reconstruction_trail& model_trail() { throw default_exception("unexpected access to model reconstruction"); }
|
||||
};
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& out, dependent_expr_state& st) {
|
||||
return st.display(out);
|
||||
}
|
||||
|
@ -150,3 +162,5 @@ public:
|
|||
ast_manager& get_manager() { return m; }
|
||||
dependent_expr_state& get_fmls() { return m_fmls; }
|
||||
};
|
||||
|
||||
typedef std::function<dependent_expr_simplifier*(ast_manager&, const params_ref&, dependent_expr_state& s)> simplifier_factory;
|
||||
|
|
|
@ -139,18 +139,15 @@ void model_reconstruction_trail::replay(unsigned qhead, expr_ref_vector& assumpt
|
|||
*/
|
||||
model_converter_ref model_reconstruction_trail::get_model_converter() {
|
||||
generic_model_converter_ref mc = alloc(generic_model_converter, m, "dependent-expr-model");
|
||||
unsigned i = 0;
|
||||
append(*mc, i);
|
||||
append(*mc);
|
||||
return model_converter_ref(mc.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Append model conversions starting at index i
|
||||
*/
|
||||
void model_reconstruction_trail::append(generic_model_converter& mc, unsigned& i) {
|
||||
TRACE("simplifier", display(tout));
|
||||
for (; i < m_trail.size(); ++i) {
|
||||
auto* t = m_trail[i];
|
||||
void model_reconstruction_trail::append(generic_model_converter& mc) {
|
||||
for (auto* t : m_trail) {
|
||||
if (!t->m_active)
|
||||
continue;
|
||||
else if (t->is_hide())
|
||||
|
@ -163,13 +160,10 @@ void model_reconstruction_trail::append(generic_model_converter& mc, unsigned& i
|
|||
mc.add(v, def);
|
||||
}
|
||||
}
|
||||
TRACE("simplifier", display(tout); mc.display(tout));
|
||||
}
|
||||
|
||||
|
||||
void model_reconstruction_trail::append(generic_model_converter& mc) {
|
||||
m_trail_stack.push(value_trail(m_trail_index));
|
||||
append(mc, m_trail_index);
|
||||
}
|
||||
|
||||
std::ostream& model_reconstruction_trail::display(std::ostream& out) const {
|
||||
for (auto* t : m_trail) {
|
||||
|
|
|
@ -84,7 +84,6 @@ class model_reconstruction_trail {
|
|||
ast_manager& m;
|
||||
trail_stack& m_trail_stack;
|
||||
scoped_ptr_vector<entry> m_trail;
|
||||
unsigned m_trail_index = 0;
|
||||
|
||||
void add_vars(expr* e, ast_mark& free_vars) {
|
||||
for (expr* t : subterms::all(expr_ref(e, m)))
|
||||
|
@ -108,10 +107,6 @@ class model_reconstruction_trail {
|
|||
return any_of(added, [&](dependent_expr const& d) { return intersects(free_vars, d); });
|
||||
}
|
||||
|
||||
/**
|
||||
* Append new updates to model converter, update the current index into the trail in the process.
|
||||
*/
|
||||
void append(generic_model_converter& mc, unsigned& index);
|
||||
public:
|
||||
|
||||
model_reconstruction_trail(ast_manager& m, trail_stack& tr):
|
||||
|
|
|
@ -53,3 +53,7 @@ public:
|
|||
void updt_params(params_ref const& p) override { m_params.append(p); m_rewriter.updt_params(m_params); }
|
||||
void collect_param_descrs(param_descrs& r) override { th_rewriter::get_param_descrs(r); }
|
||||
};
|
||||
|
||||
/*
|
||||
ADD_SIMPLIFIER("simplify", "apply simplification rules.", "[](auto& m, auto& p, auto &s) -> dependent_expr_simplifier* { return alloc(rewriter_simplifier, m, p, s); }")
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue