3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-10 13:10:50 +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:
Nikolaj Bjorner 2023-11-30 13:58:24 -08:00
parent 5784c2da79
commit b52fd8d954
28 changed files with 3063 additions and 68 deletions

View file

@ -26,7 +26,8 @@ special_relations_decl_plugin::special_relations_decl_plugin():
m_po("partial-order"),
m_plo("piecewise-linear-order"),
m_to("tree-order"),
m_tc("transitive-closure")
m_tc("transitive-closure"),
m_ac("ac-op")
{}
func_decl * special_relations_decl_plugin::mk_func_decl(
@ -41,24 +42,53 @@ func_decl * special_relations_decl_plugin::mk_func_decl(
m_manager->raise_exception("argument sort missmatch. The two arguments should have the same sort");
return nullptr;
}
if (!range && k == OP_SPECIAL_RELATION_AC)
range = domain[0];
if (!range) {
range = m_manager->mk_bool_sort();
}
if (!m_manager->is_bool(range)) {
m_manager->raise_exception("range type is expected to be Boolean for special relations");
}
auto check_bool_range = [&]() {
if (!m_manager->is_bool(range))
m_manager->raise_exception("range type is expected to be Boolean for special relations");
};
m_has_special_relation = true;
func_decl_info info(m_family_id, k, num_parameters, parameters);
symbol name;
switch(k) {
case OP_SPECIAL_RELATION_PO: name = m_po; break;
case OP_SPECIAL_RELATION_LO: name = m_lo; break;
case OP_SPECIAL_RELATION_PLO: name = m_plo; break;
case OP_SPECIAL_RELATION_TO: name = m_to; break;
case OP_SPECIAL_RELATION_PO: check_bool_range(); name = m_po; break;
case OP_SPECIAL_RELATION_LO: check_bool_range(); name = m_lo; break;
case OP_SPECIAL_RELATION_PLO: check_bool_range(); name = m_plo; break;
case OP_SPECIAL_RELATION_TO: check_bool_range(); name = m_to; break;
case OP_SPECIAL_RELATION_AC: {
if (range != domain[0])
m_manager->raise_exception("AC operation should have the same range as domain type");
name = m_ac;
if (num_parameters != 1 || !parameters[0].is_ast() || !is_func_decl(parameters[0].get_ast()))
m_manager->raise_exception("parameter to transitive closure should be a function declaration");
func_decl* f = to_func_decl(parameters[0].get_ast());
if (f->get_arity() != 2)
m_manager->raise_exception("ac function should be binary");
if (f->get_domain(0) != f->get_domain(1))
m_manager->raise_exception("ac function should have same domain");
if (f->get_domain(0) != f->get_range())
m_manager->raise_exception("ac function should have same domain and range");
break;
}
case OP_SPECIAL_RELATION_TC:
check_bool_range();
name = m_tc;
if (num_parameters != 1 || !parameters[0].is_ast() || !is_func_decl(parameters[0].get_ast()))
m_manager->raise_exception("parameter to transitive closure should be a function declaration");
func_decl* f = to_func_decl(parameters[0].get_ast());
if (f->get_arity() != 2)
m_manager->raise_exception("tc relation should be binary");
if (f->get_domain(0) != f->get_domain(1))
m_manager->raise_exception("tc relation should have same domain");
if (!m_manager->is_bool(f->get_range()))
m_manager->raise_exception("tc relation should be Boolean");
break;
}
return m_manager->mk_func_decl(name, arity, domain, range, info);
@ -71,6 +101,7 @@ void special_relations_decl_plugin::get_op_names(svector<builtin_name> & op_name
op_names.push_back(builtin_name(m_plo.str(), OP_SPECIAL_RELATION_PLO));
op_names.push_back(builtin_name(m_to.str(), OP_SPECIAL_RELATION_TO));
op_names.push_back(builtin_name(m_tc.str(), OP_SPECIAL_RELATION_TC));
op_names.push_back(builtin_name(m_ac.str(), OP_SPECIAL_RELATION_AC));
}
}
@ -81,6 +112,7 @@ sr_property special_relations_util::get_property(func_decl* f) const {
case OP_SPECIAL_RELATION_PLO: return sr_plo;
case OP_SPECIAL_RELATION_TO: return sr_to;
case OP_SPECIAL_RELATION_TC: return sr_tc;
case OP_SPECIAL_RELATION_AC: return sr_none;
default:
UNREACHABLE();
return sr_po;