3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-22 11:07:51 +00:00

adding simplifiers layer

simplifiers layer is a common substrate for global non-incremental and incremental processing.
The first two layers are new, but others are to be ported form tactics.

- bv::slice - rewrites equations to cut-dice-slice bit-vector extractions until they align. It creates opportunities for rewriting portions of bit-vectors to common sub-expressions, including values.
- euf::completion - generalizes the KB simplifcation from asserted formulas to use the E-graph to establish a global and order-independent canonization.

The interface dependent_expr_simplifier is amenable to forming tactics. Plugins for asserted-formulas is also possible but not yet realized.
This commit is contained in:
Nikolaj Bjorner 2022-11-02 08:51:30 -07:00
parent 1646a41b2f
commit e57674490f
16 changed files with 1024 additions and 2 deletions

View file

@ -17,6 +17,7 @@ z3_add_component(tactic
COMPONENT_DEPENDENCIES
ast
model
simplifiers
TACTIC_HEADERS
probe.h
tactic.h

View file

@ -8,6 +8,7 @@ z3_add_component(bv_tactics
bv_bound_chk_tactic.cpp
bv_bounds_tactic.cpp
bv_size_reduction_tactic.cpp
bv_slice_tactic.cpp
dt2bv_tactic.cpp
elim_small_bv_tactic.cpp
max_bv_sharing_tactic.cpp
@ -21,6 +22,7 @@ z3_add_component(bv_tactics
bv_bound_chk_tactic.h
bv_bounds_tactic.h
bv_size_reduction_tactic.h
bv_slice_tactic.h
bvarray2uf_tactic.h
dt2bv_tactic.h
elim_small_bv_tactic.h

View file

@ -0,0 +1,29 @@
/*++
Copyright (c) 2011 Microsoft Corporation
Module Name:
bv_slice_tactic.h
Abstract:
Tactic for simplifying with bit-vector slices
Author:
Nikolaj Bjorner (nbjorner) 2022-10-30
--*/
#pragma once
#include "util/params.h"
class ast_manager;
class tactic;
tactic * mk_bv_slice_tactic(ast_manager & m, params_ref const & p = params_ref());
/*
ADD_TACTIC("bv-slice", "simplify using bit-vector slices.", "mk_bv_slice_tactic(m, p)")
*/

View file

@ -10,6 +10,7 @@ z3_add_component(core_tactics
dom_simplify_tactic.cpp
elim_term_ite_tactic.cpp
elim_uncnstr_tactic.cpp
euf_completion_tactic.cpp
injectivity_tactic.cpp
nnf_tactic.cpp
occf_tactic.cpp
@ -38,6 +39,7 @@ z3_add_component(core_tactics
dom_simplify_tactic.h
elim_term_ite_tactic.h
elim_uncnstr_tactic.h
euf_completion_tactic.h
injectivity_tactic.h
nnf_tactic.h
occf_tactic.h

View file

@ -0,0 +1,32 @@
/*++
Copyright (c) 2022 Microsoft Corporation
Module Name:
euf_completion_tactic.cpp
Abstract:
Tactic for simplifying with equations.
Author:
Nikolaj Bjorner (nbjorner) 2022-10-30
--*/
#include "tactic/tactic.h"
#include "tactic/dependent_expr_state_tactic.h"
#include "ast/simplifiers/euf_completion.h"
#include "tactic/core/euf_completion_tactic.h"
class euf_completion_tactic_factory : public dependent_expr_simplifier_factory {
public:
dependent_expr_simplifier* mk(ast_manager& m, params_ref const& p, dependent_expr_state& s) override {
return alloc(euf::completion, m, s);
}
};
tactic * mk_euf_completion_tactic(ast_manager& m, params_ref const& p) {
return alloc(dependent_expr_state_tactic, m, p, alloc(euf_completion_tactic_factory), "euf-completion");
}

View file

@ -0,0 +1,29 @@
/*++
Copyright (c) 2022 Microsoft Corporation
Module Name:
euf_completion_tactic.h
Abstract:
Tactic for simplifying with equations.
Author:
Nikolaj Bjorner (nbjorner) 2022-10-30
--*/
#pragma once
#include "util/params.h"
class ast_manager;
class tactic;
tactic * mk_euf_completion_tactic(ast_manager & m, params_ref const & p = params_ref());
/*
ADD_TACTIC("euf-completion", "simplify using equalities.", "mk_euf_completion_tactic(m, p)")
*/

View file

@ -0,0 +1,101 @@
/*++
Copyright (c) 2022 Microsoft Corporation
Module Name:
dependent_expr_state_tactic.h
Abstract:
The dependent_expr_state_tactic creates a tactic from a dependent_expr_simplifier.
It relies on a factory for building simplifiers.
Author:
Nikolaj Bjorner (nbjorner) 2022-11-2.
--*/
#include "tactic/tactic.h"
#include "ast/simplifiers/dependent_expr_state.h"
class dependent_expr_state_tactic : public tactic, public dependent_expr_state {
ast_manager& m;
params_ref m_params;
std::string m_name;
ref<dependent_expr_simplifier_factory> m_factory;
scoped_ptr<dependent_expr_simplifier> m_simp;
goal_ref m_goal;
dependent_expr m_dep;
void init() {
if (!m_simp)
m_simp = m_factory->mk(m, m_params, *this);
}
public:
dependent_expr_state_tactic(ast_manager& m, params_ref const& p, dependent_expr_simplifier_factory* f, char const* name):
m(m),
m_params(p),
m_name(name),
m_factory(f),
m_simp(f->mk(m, p, *this)),
m_dep(m, m.mk_true(), nullptr)
{}
/**
* size(), [](), update() and inconsisent() implement the abstract interface of dependent_expr_state
*/
unsigned size() const override { return m_goal->size(); }
dependent_expr const& operator[](unsigned i) override {
m_dep = dependent_expr(m, m_goal->form(i), m_goal->dep(i));
return m_dep;
}
void update(unsigned i, dependent_expr const& j) override {
auto [f, d] = j();
m_goal->update(i, f, nullptr, d);
}
bool inconsistent() override {
return m_goal->inconsistent();
}
char const* name() const override { return m_name.c_str(); }
void updt_params(params_ref const & p) override {
m_params.append(p);
init();
m_simp->updt_params(m_params);
}
tactic * translate(ast_manager & m) override {
return alloc(dependent_expr_state_tactic, m, m_params, m_factory.get(), name());
}
void operator()(goal_ref const & in,
goal_ref_buffer & result) override {
if (in->proofs_enabled())
throw tactic_exception("tactic does not support low level proofs");
init();
tactic_report report(name(), *in);
m_goal = in.get();
m_simp->reduce();
m_goal->inc_depth();
result.push_back(in.get());
}
void cleanup() override {
}
void collect_statistics(statistics & st) const override {
if (m_simp)
m_simp->collect_statistics(st);
}
void reset_statistics() override {
if (m_simp)
m_simp->reset_statistics();
}
};