mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 09:05:31 +00:00
add EUF plugin framework.
plugin setting allows adding equality saturation within the E-graph propagation without involving externalizing theory solver dispatch. It makes equality saturation independent of SAT integration. Add a special relation operator to support ad-hoc AC symbols.
This commit is contained in:
parent
5784c2da79
commit
b52fd8d954
28 changed files with 3063 additions and 68 deletions
|
@ -44,6 +44,7 @@ z3_add_component(sat_smt
|
|||
q_solver.cpp
|
||||
recfun_solver.cpp
|
||||
sat_th.cpp
|
||||
specrel_solver.cpp
|
||||
tseitin_theory_checker.cpp
|
||||
user_solver.cpp
|
||||
COMPONENT_DEPENDENCIES
|
||||
|
|
|
@ -28,6 +28,7 @@ Author:
|
|||
#include "sat/smt/fpa_solver.h"
|
||||
#include "sat/smt/dt_solver.h"
|
||||
#include "sat/smt/recfun_solver.h"
|
||||
#include "sat/smt/specrel_solver.h"
|
||||
|
||||
namespace euf {
|
||||
|
||||
|
@ -130,6 +131,7 @@ namespace euf {
|
|||
arith_util arith(m);
|
||||
datatype_util dt(m);
|
||||
recfun::util rf(m);
|
||||
special_relations_util sp(m);
|
||||
if (pb.get_family_id() == fid)
|
||||
ext = alloc(pb::solver, *this, fid);
|
||||
else if (bvu.get_family_id() == fid)
|
||||
|
@ -144,6 +146,8 @@ namespace euf {
|
|||
ext = alloc(dt::solver, *this, fid);
|
||||
else if (rf.get_family_id() == fid)
|
||||
ext = alloc(recfun::solver, *this);
|
||||
else if (sp.get_family_id() == fid)
|
||||
ext = alloc(specrel::solver, *this, fid);
|
||||
|
||||
if (ext)
|
||||
add_solver(ext);
|
||||
|
|
120
src/sat/smt/specrel_solver.cpp
Normal file
120
src/sat/smt/specrel_solver.cpp
Normal file
|
@ -0,0 +1,120 @@
|
|||
/*++
|
||||
Copyright (c) 2020 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
specrel_solver.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Theory plugin for special relations
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2020-09-08
|
||||
|
||||
--*/
|
||||
|
||||
#include "sat/smt/specrel_solver.h"
|
||||
#include "sat/smt/euf_solver.h"
|
||||
#include "ast/euf/euf_specrel_plugin.h"
|
||||
|
||||
namespace euf {
|
||||
class solver;
|
||||
}
|
||||
|
||||
namespace specrel {
|
||||
|
||||
solver::solver(euf::solver& ctx, theory_id id) :
|
||||
th_euf_solver(ctx, ctx.get_manager().get_family_name(id), id),
|
||||
sp(m)
|
||||
{
|
||||
ctx.get_egraph().add_plugin(alloc(euf::specrel_plugin, ctx.get_egraph()));
|
||||
}
|
||||
|
||||
solver::~solver() {
|
||||
}
|
||||
|
||||
void solver::asserted(sat::literal l) {
|
||||
|
||||
}
|
||||
|
||||
sat::check_result solver::check() {
|
||||
return sat::check_result::CR_DONE;
|
||||
}
|
||||
|
||||
std::ostream& solver::display(std::ostream& out) const {
|
||||
return out;
|
||||
}
|
||||
|
||||
void solver::collect_statistics(statistics& st) const {
|
||||
}
|
||||
|
||||
euf::th_solver* solver::clone(euf::solver& ctx) {
|
||||
return alloc(solver, ctx, get_id());
|
||||
}
|
||||
|
||||
void solver::new_eq_eh(euf::th_eq const& eq) {
|
||||
TRACE("specrel", tout << "new-eq\n");
|
||||
if (eq.is_eq()) {
|
||||
auto* p = ctx.get_egraph().get_plugin(sp.get_family_id());
|
||||
p->merge_eh(var2enode(eq.v1()), var2enode(eq.v2()));
|
||||
TRACE("specrel", tout << eq.v1() << " " << eq.v2() << "\n");
|
||||
}
|
||||
}
|
||||
|
||||
void solver::add_value(euf::enode* n, model& mdl, expr_ref_vector& values) {
|
||||
}
|
||||
|
||||
bool solver::add_dep(euf::enode* n, top_sort<euf::enode>& dep) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool solver::include_func_interp(func_decl* f) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
sat::literal solver::internalize(expr* e, bool sign, bool root) {
|
||||
if (!visit_rec(m, e, sign, root))
|
||||
return sat::null_literal;
|
||||
auto lit = ctx.expr2literal(e);
|
||||
if (sign)
|
||||
lit.neg();
|
||||
return lit;
|
||||
}
|
||||
|
||||
void solver::internalize(expr* e) {
|
||||
visit_rec(m, e, false, false);
|
||||
}
|
||||
|
||||
bool solver::visit(expr* e) {
|
||||
if (visited(e))
|
||||
return true;
|
||||
m_stack.push_back(sat::eframe(e));
|
||||
return false;
|
||||
}
|
||||
|
||||
bool solver::visited(expr* e) {
|
||||
euf::enode* n = expr2enode(e);
|
||||
return n && n->is_attached_to(get_id());
|
||||
}
|
||||
|
||||
bool solver::post_visit(expr* term, bool sign, bool root) {
|
||||
euf::enode* n = expr2enode(term);
|
||||
SASSERT(!n || !n->is_attached_to(get_id()));
|
||||
if (!n)
|
||||
n = mk_enode(term);
|
||||
SASSERT(!n->is_attached_to(get_id()));
|
||||
mk_var(n);
|
||||
TRACE("specrel", tout << ctx.bpp(n) << "\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
euf::theory_var solver::mk_var(euf::enode* n) {
|
||||
if (is_attached_to_var(n))
|
||||
return n->get_th_var(get_id());
|
||||
euf::theory_var r = th_euf_solver::mk_var(n);
|
||||
ctx.attach_th_var(n, this, r);
|
||||
return r;
|
||||
}
|
||||
}
|
75
src/sat/smt/specrel_solver.h
Normal file
75
src/sat/smt/specrel_solver.h
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*++
|
||||
Copyright (c) 2020 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
specrel_solver.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Theory plugin for special relations
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2020-09-08
|
||||
|
||||
--*/
|
||||
#pragma once
|
||||
|
||||
#include "sat/smt/sat_th.h"
|
||||
#include "ast/special_relations_decl_plugin.h"
|
||||
|
||||
namespace euf {
|
||||
class solver;
|
||||
}
|
||||
|
||||
namespace specrel {
|
||||
|
||||
class solver : public euf::th_euf_solver {
|
||||
typedef euf::theory_var theory_var;
|
||||
typedef euf::theory_id theory_id;
|
||||
typedef euf::enode enode;
|
||||
typedef euf::enode_pair enode_pair;
|
||||
typedef euf::enode_pair_vector enode_pair_vector;
|
||||
typedef sat::bool_var bool_var;
|
||||
typedef sat::literal literal;
|
||||
typedef sat::literal_vector literal_vector;
|
||||
|
||||
special_relations_util sp;
|
||||
|
||||
public:
|
||||
solver(euf::solver& ctx, theory_id id);
|
||||
~solver() override;
|
||||
|
||||
bool is_external(bool_var v) override { return false; }
|
||||
void get_antecedents(literal l, sat::ext_justification_idx idx, literal_vector& r, bool probing) override {}
|
||||
void asserted(literal l) override;
|
||||
sat::check_result check() override;
|
||||
|
||||
std::ostream& display(std::ostream& out) const override;
|
||||
std::ostream& display_justification(std::ostream& out, sat::ext_justification_idx idx) const override { return euf::th_explain::from_index(idx).display(out); }
|
||||
std::ostream& display_constraint(std::ostream& out, sat::ext_constraint_idx idx) const override { return display_justification(out, idx); }
|
||||
void collect_statistics(statistics& st) const override;
|
||||
euf::th_solver* clone(euf::solver& ctx) override;
|
||||
void new_eq_eh(euf::th_eq const& eq) override;
|
||||
bool unit_propagate() override { return false; }
|
||||
void add_value(euf::enode* n, model& mdl, expr_ref_vector& values) override;
|
||||
bool add_dep(euf::enode* n, top_sort<euf::enode>& dep) override;
|
||||
bool include_func_interp(func_decl* f) const override;
|
||||
sat::literal internalize(expr* e, bool sign, bool root) override;
|
||||
void internalize(expr* e) override;
|
||||
bool visit(expr* e) override;
|
||||
bool visited(expr* e) override;
|
||||
bool post_visit(expr* e, bool sign, bool root) override;
|
||||
|
||||
euf::theory_var mk_var(euf::enode* n) override;
|
||||
void apply_sort_cnstr(euf::enode* n, sort* s) override {}
|
||||
bool is_shared(theory_var v) const override { return false; }
|
||||
lbool get_phase(bool_var v) override { return l_true; }
|
||||
bool enable_self_propagate() const override { return true; }
|
||||
|
||||
void merge_eh(theory_var, theory_var, theory_var v1, theory_var v2);
|
||||
void after_merge_eh(theory_var r1, theory_var r2, theory_var v1, theory_var v2) {}
|
||||
void unmerge_eh(theory_var v1, theory_var v2) {}
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue