3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-05-09 08:45:47 +00:00

add demodulator tactic based on demodulator-simplifier

- some handling for commutative operators
- fix bug in demodulator_index where fwd and bwd are swapped
This commit is contained in:
Nikolaj Bjorner 2022-12-05 03:20:46 -08:00
parent 87095950cb
commit de916f50d6
5 changed files with 123 additions and 37 deletions

View file

@ -71,8 +71,20 @@ void demodulator_index::remove_bwd(expr* e, unsigned i) {
for_each_expr(p, e);
}
std::ostream& demodulator_index::display(std::ostream& out) const {
out << "forward\n";
for (auto& [k, v] : m_fwd_index)
out << mk_pp(k, m) << " : " << *v << "\n";
out << "backward\n";
for (auto& [k, v] : m_bwd_index)
out << mk_pp(k, m) << " : " << *v << "\n";
return out;
}
demodulator_simplifier::demodulator_simplifier(ast_manager& m, params_ref const& p, dependent_expr_state& st):
dependent_expr_simplifier(m, st),
m_index(m),
m_util(m),
m_match_subst(m),
m_rewriter(m),
@ -104,18 +116,19 @@ bool demodulator_simplifier::rewrite1(func_decl* f, expr_ref_vector const& args,
if (!m_index.find_fwd(f, set))
return false;
TRACE("demodulator", tout << "trying to rewrite: " << f->get_name() << " args:\n" << args << "\n";);
TRACE("demodulator", tout << "trying to rewrite: " << f->get_name() << " args:" << args << "\n"; m_index.display(tout));
for (unsigned i : *set) {
auto const& [lhs, rhs] = m_rewrites[i];
TRACE("demodulator", tout << "Matching with demodulator: " << i << " " << mk_pp(lhs, m) << "\n");
if (lhs->get_num_args() != args.size())
continue;
SASSERT(lhs->get_decl() == f);
TRACE("demodulator", tout << "Matching with demodulator: " << mk_pp(lhs, m) << "\n");
if (m_match_subst(lhs, rhs, args.data(), np)) {
TRACE("demodulator_bug", tout << "succeeded...\n" << mk_pp(rhs, m) << "\n===>\n" << np << "\n");
@ -186,6 +199,7 @@ void demodulator_simplifier::reduce() {
rewrite(i);
if (m_util.is_demodulator(fml(i), large, small)) {
func_decl* f = large->get_decl();
TRACE("demodulator", tout << i << " " << mk_pp(fml(i), m) << ": " << large << " ==> " << small << "\n");
reschedule_processed(f);
reschedule_demodulators(f, large);
m_index.insert_fwd(f, i);

View file

@ -18,19 +18,22 @@ Author:
#include "util/uint_set.h"
class demodulator_index {
ast_manager& m;
obj_map<func_decl, uint_set*> m_fwd_index, m_bwd_index;
void add(func_decl* f, unsigned i, obj_map<func_decl, uint_set*>& map);
void del(func_decl* f, unsigned i, obj_map<func_decl, uint_set*>& map);
public:
demodulator_index(ast_manager& m): m(m) {}
~demodulator_index();
void reset();
void insert_fwd(func_decl* f, unsigned i) { add(f, i, m_fwd_index); }
void remove_fwd(func_decl* f, unsigned i) { del(f, i, m_fwd_index); }
void insert_bwd(expr* e, unsigned i);
void remove_bwd(expr* e, unsigned i);
bool find_fwd(func_decl* f, uint_set*& s) { return m_bwd_index.find(f, s); }
bool find_bwd(func_decl* f, uint_set*& s) { return m_fwd_index.find(f, s); }
bool find_fwd(func_decl* f, uint_set*& s) { return m_fwd_index.find(f, s); }
bool find_bwd(func_decl* f, uint_set*& s) { return m_bwd_index.find(f, s); }
bool empty() const { return m_fwd_index.empty(); }
std::ostream& display(std::ostream& out) const;
};
class demodulator_simplifier : public dependent_expr_simplifier {
@ -56,4 +59,6 @@ class demodulator_simplifier : public dependent_expr_simplifier {
demodulator_simplifier(ast_manager& m, params_ref const& p, dependent_expr_state& st);
void reduce() override;
char const* name() const override { return "demodulator"; }
};