3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-24 17:45:32 +00:00

add special relations tactic

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2019-03-28 10:07:50 -07:00
parent ec6cf7950e
commit 7a6823aef1
7 changed files with 92 additions and 21 deletions

View file

@ -19,6 +19,7 @@ z3_add_component(core_tactics
reduce_invertible_tactic.cpp
simplify_tactic.cpp
solve_eqs_tactic.cpp
special_relations_tactic.cpp
split_clause_tactic.cpp
symmetry_reduce_tactic.cpp
tseitin_cnf_tactic.cpp
@ -46,6 +47,7 @@ z3_add_component(core_tactics
reduce_invertible_tactic.h
simplify_tactic.h
solve_eqs_tactic.h
special_relations_tactic.h
split_clause_tactic.h
symmetry_reduce_tactic.h
tseitin_cnf_tactic.h

View file

@ -17,7 +17,8 @@ Author:
Notes:
--*/
#include "tactic/core/special_relations.h"
#include "tactic/core/special_relations_tactic.h"
#include "ast/rewriter/func_decl_replace.h"
void special_relations_tactic::collect_feature(goal const& g, unsigned idx,
obj_map<func_decl, sp_axioms>& goal_features) {
@ -26,14 +27,34 @@ void special_relations_tactic::collect_feature(goal const& g, unsigned idx,
if (is_transitivity(f, p)) {
insert(goal_features, p, idx, sr_transitive);
}
else if (is_anti_symmetry(f, p)) {
insert(goal_features, p, idx, sr_antisymmetric);
}
else if (is_left_tree(f, p)) {
insert(goal_features, p, idx, sr_lefttree);
}
else if (is_right_tree(f, p)) {
insert(goal_features, p, idx, sr_righttree);
}
else if (is_reflexive(f, p)) {
insert(goal_features, p, idx, sr_reflexive);
}
else if (is_total(f, p)) {
insert(goal_features, p, idx, sr_total);
}
}
void specia_relations_tactic::insert(obj_map<func_decl, sp_axioms>& goal_features, func_decl* p, unsigned idx, sr_property p) {
void special_relations_tactic::insert(obj_map<func_decl, sp_axioms>& goal_features, func_decl* f, unsigned idx, sr_property p) {
sp_axioms ax;
goal_features.find(f, ax);
ax.m_goal_indices.push_back(idx);
ax.m_sp_features = (sr_property)(p | ax.m_sp_features);
goal_features.insert(f, ax);
}
bool special_relations_tactic::is_transitivity(expr* fml, func_decl_ref& p) {
// match Forall x, y, z . p(x,y) & p(y,z) -> p(x,z)
return false;
}
bool special_relations_tactic::is_anti_symmetry(expr* fml, func_decl_ref& p) {
@ -45,7 +66,7 @@ bool special_relations_tactic::is_left_tree(expr* fml, func_decl_ref& p) {
bool special_relations_tactic::is_right_tree(expr* fml, func_decl_ref& p) {
return false;
}
bool special_relations_tactic::is_reflexivity(expr* fml, func_decl_ref& p) {
bool special_relations_tactic::is_reflexive(expr* fml, func_decl_ref& p) {
return false;
}
bool special_relations_tactic::is_total(expr* fml, func_decl_ref& p) {
@ -57,16 +78,58 @@ bool special_relations_tactic::is_symmetric(expr* fml, func_decl_ref& p) {
void special_relations_tactic::operator()(goal_ref const & g, goal_ref_buffer & result) {
tactic_report report("special_relations", g);
tactic_report report("special_relations", *g);
obj_map<func_decl, sp_axioms> goal_features;
unsigned size = g.size();
unsigned size = g->size();
for (unsigned idx = 0; idx < size; idx++) {
collect_feature(g, idx, goal_features);
collect_feature(*g, idx, goal_features);
}
if (!goal_features.empty()) {
special_relations_util u(m);
func_decl_replace replace(m);
unsigned_vector to_delete;
for(auto const& kv : goal_features) {
func_decl* sp = nullptr;
sr_property feature = kv.m_value.m_sp_features;
switch (feature) {
case sr_po:
replace.insert(kv.m_key, u.mk_po_decl(kv.m_key));
to_delete.append(kv.m_value.m_goal_indices);
break;
case sr_to:
replace.insert(kv.m_key, u.mk_to_decl(kv.m_key));
to_delete.append(kv.m_value.m_goal_indices);
break;
case sr_plo:
replace.insert(kv.m_key, u.mk_plo_decl(kv.m_key));
to_delete.append(kv.m_value.m_goal_indices);
break;
case sr_lo:
replace.insert(kv.m_key, u.mk_lo_decl(kv.m_key));
to_delete.append(kv.m_value.m_goal_indices);
break;
default:
TRACE("special_relations", tout << "unprocessed feature " << feature << "\n";);
break;
}
}
if (!replace.empty()) {
for (unsigned idx = 0; idx < size; idx++) {
if (to_delete.contains(idx)) {
g->update(idx, m.mk_true());
}
else {
expr_ref new_f = replace(g->form(idx));
g->update(idx, new_f);
}
}
g->elim_true();
}
g->inc_depth();
result.push_back(g.get());
}
tactic * mk_special_relations_tactic(ast_manager & m, params_ref const & p) {
return alloc(special_relations_tactic, m, p);
}

View file

@ -22,29 +22,32 @@ Notes:
#include "tactic/tactic.h"
#include "tactic/tactical.h"
#include "ast/special_relations_decl_plugin.h"
class special_relations_tactic : public tactic {
ast_manager& m;
params_ref m_params;
struct sp_axioms {
unsigned_vector m_goal_indices;
unsigned m_sp_features;
sr_property m_sp_features;
sp_axioms():m_sp_features(sr_none) {}
};
void collect_feature(goal const& g, unsigned idx, obj_map<func_decl, sp_axioms>& goal_features);
void insert(obj_map<func_decl, sp_axioms>& goal_features, func_decl* p, unsigned idx, sr_property p);
void insert(obj_map<func_decl, sp_axioms>& goal_features, func_decl* f, unsigned idx, sr_property p);
bool is_transitivity(expr* fml, func_decl_ref& p);
bool is_anti_symmetry(expr* fml, func_decl_ref& p);
bool is_left_tree(expr* fml, func_decl_ref& p);
bool is_right_tree(expr* fml, func_decl_ref& p);
bool is_reflexivity(expr* fml, func_decl_ref& p);
bool is_reflexive(expr* fml, func_decl_ref& p);
bool is_total(expr* fml, func_decl_ref& p);
bool is_symmetric(expr* fml, func_decl_ref& p);
public:
special_relations_tactic(ast_manager & m, params_ref const & ref = params_ref()) {}
special_relations_tactic(ast_manager & m, params_ref const & ref = params_ref()): m(m), m_params(ref) {}
~special_relations_tactic() override {}