mirror of
https://github.com/Z3Prover/z3
synced 2025-04-25 01:55:32 +00:00
working on mam
This commit is contained in:
parent
f33d6f89b9
commit
4b6d7ca097
15 changed files with 807 additions and 209 deletions
|
@ -3,7 +3,6 @@ z3_add_component(euf
|
|||
euf_enode.cpp
|
||||
euf_etable.cpp
|
||||
euf_egraph.cpp
|
||||
euf_mam.cpp
|
||||
COMPONENT_DEPENDENCIES
|
||||
ast
|
||||
util
|
||||
|
|
|
@ -39,6 +39,23 @@ namespace euf {
|
|||
return n;
|
||||
}
|
||||
|
||||
enode* egraph::find(expr* e, unsigned n, enode* const* args) {
|
||||
if (m_tmp_node && m_tmp_node_capacity < n) {
|
||||
memory::deallocate(m_tmp_node);
|
||||
m_tmp_node = nullptr;
|
||||
}
|
||||
if (!m_tmp_node) {
|
||||
m_tmp_node = enode::mk_tmp(n);
|
||||
m_tmp_node_capacity = n;
|
||||
}
|
||||
for (unsigned i = 0; i < n; ++i)
|
||||
m_tmp_node->m_args[i] = args[i];
|
||||
m_tmp_node->m_num_args = n;
|
||||
m_tmp_node->m_expr = e;
|
||||
return m_table.find(m_tmp_node);
|
||||
}
|
||||
|
||||
|
||||
enode_vector const& egraph::enodes_of(func_decl* f) {
|
||||
unsigned id = f->get_decl_id();
|
||||
if (id < m_decl2enodes.size())
|
||||
|
@ -115,6 +132,8 @@ namespace euf {
|
|||
egraph::~egraph() {
|
||||
for (enode* n : m_nodes)
|
||||
n->m_parents.finalize();
|
||||
if (m_tmp_node)
|
||||
memory::deallocate(m_tmp_node);
|
||||
}
|
||||
|
||||
void egraph::add_th_eq(theory_id id, theory_var v1, theory_var v2, enode* c, enode* r) {
|
||||
|
@ -382,6 +401,8 @@ namespace euf {
|
|||
r2->inc_class_size(r1->class_size());
|
||||
merge_th_eq(r1, r2);
|
||||
reinsert_parents(r1, r2);
|
||||
if (m_on_merge)
|
||||
m_on_merge(r2, r1);
|
||||
}
|
||||
|
||||
void egraph::remove_parents(enode* r1, enode* r2) {
|
||||
|
|
|
@ -148,6 +148,8 @@ namespace euf {
|
|||
unsigned_vector m_scopes;
|
||||
enode_vector m_expr2enode;
|
||||
enode* m_tmp_eq { nullptr };
|
||||
enode* m_tmp_node { nullptr };
|
||||
unsigned m_tmp_node_capacity { 0 };
|
||||
enode_vector m_nodes;
|
||||
expr_ref_vector m_exprs;
|
||||
vector<enode_vector> m_decl2enodes;
|
||||
|
@ -165,6 +167,7 @@ namespace euf {
|
|||
enode_vector m_todo;
|
||||
stats m_stats;
|
||||
bool m_uses_congruence { false };
|
||||
std::function<void(enode*,enode*)> m_on_merge;
|
||||
std::function<void(expr*,expr*,expr*)> m_used_eq;
|
||||
std::function<void(app*,app*)> m_used_cc;
|
||||
std::function<void(std::ostream&, void*)> m_display_justification;
|
||||
|
@ -218,6 +221,7 @@ namespace euf {
|
|||
egraph(ast_manager& m);
|
||||
~egraph();
|
||||
enode* find(expr* f) const { return m_expr2enode.get(f->get_id(), nullptr); }
|
||||
enode* find(expr* f, unsigned n, enode* const* args);
|
||||
enode* mk(expr* f, unsigned generation, unsigned n, enode *const* args);
|
||||
enode_vector const& enodes_of(func_decl* f);
|
||||
void push() { ++m_num_scopes; }
|
||||
|
@ -269,6 +273,7 @@ namespace euf {
|
|||
void set_value(enode* n, lbool value);
|
||||
void set_bool_var(enode* n, unsigned v) { n->set_bool_var(v); }
|
||||
|
||||
void set_on_merge(std::function<void(enode* root,enode* other)>& on_merge) { m_on_merge = on_merge; }
|
||||
void set_used_eq(std::function<void(expr*,expr*,expr*)>& used_eq) { m_used_eq = used_eq; }
|
||||
void set_used_cc(std::function<void(app*,app*)>& used_cc) { m_used_cc = used_cc; }
|
||||
void set_display_justification(std::function<void (std::ostream&, void*)> & d) { m_display_justification = d; }
|
||||
|
|
|
@ -109,6 +109,20 @@ namespace euf {
|
|||
n->m_args[i] = nullptr;
|
||||
return n;
|
||||
}
|
||||
|
||||
static enode* mk_tmp(unsigned num_args) {
|
||||
void* mem = memory::allocate(get_enode_size(num_args));
|
||||
enode* n = new (mem) enode();
|
||||
n->m_expr = nullptr;
|
||||
n->m_next = n;
|
||||
n->m_root = n;
|
||||
n->m_commutative = true;
|
||||
n->m_num_args = 2;
|
||||
n->m_merge_enabled = true;
|
||||
for (unsigned i = 0; i < num_args; ++i)
|
||||
n->m_args[i] = nullptr;
|
||||
return n;
|
||||
}
|
||||
|
||||
void set_update_children() { m_update_children = true; }
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ namespace euf {
|
|||
|
||||
struct cg_comm_eq {
|
||||
bool & m_commutativity;
|
||||
cg_comm_eq( bool & c): m_commutativity(c) {}
|
||||
cg_comm_eq(bool & c): m_commutativity(c) {}
|
||||
bool operator()(enode * n1, enode * n2) const {
|
||||
SASSERT(n1->num_args() == 2);
|
||||
SASSERT(n2->num_args() == 2);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,66 +0,0 @@
|
|||
/*++
|
||||
Copyright (c) 2006 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
euf_mam.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Matching Abstract Machine
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo de Moura (leonardo) 2007-02-13.
|
||||
Nikolaj Bjorner (nbjorner) 2021-01-22.
|
||||
|
||||
--*/
|
||||
#pragma once
|
||||
|
||||
#include "ast/ast.h"
|
||||
#include "ast/euf/euf_egraph.h"
|
||||
#include <functional>
|
||||
|
||||
namespace euf {
|
||||
|
||||
/**
|
||||
\brief Matching Abstract Machine (MAM)
|
||||
*/
|
||||
class mam {
|
||||
friend class mam_impl;
|
||||
|
||||
mam() {}
|
||||
|
||||
public:
|
||||
|
||||
static mam * mk(egraph & ctx,
|
||||
std::function<void(quantifier*, app*, unsigned, enode* const*, unsigned)>& add_instance);
|
||||
|
||||
virtual ~mam() {}
|
||||
|
||||
virtual void add_pattern(quantifier * q, app * mp) = 0;
|
||||
|
||||
virtual void push_scope() = 0;
|
||||
|
||||
virtual void pop_scope(unsigned num_scopes) = 0;
|
||||
|
||||
virtual void match() = 0;
|
||||
|
||||
virtual void rematch(bool use_irrelevant = false) = 0;
|
||||
|
||||
virtual bool has_work() const = 0;
|
||||
|
||||
virtual void add_eq_eh(enode * r1, enode * r2) = 0;
|
||||
|
||||
virtual void reset() = 0;
|
||||
|
||||
virtual std::ostream& display(std::ostream& out) = 0;
|
||||
|
||||
virtual void on_match(quantifier * q, app * pat, unsigned num_bindings, enode * const * bindings, unsigned max_generation) = 0;
|
||||
|
||||
virtual bool is_shared(enode * n) const = 0;
|
||||
|
||||
virtual bool check_missing_instances() = 0;
|
||||
};
|
||||
};
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue