mirror of
https://github.com/Z3Prover/z3
synced 2025-04-29 03:45:51 +00:00
model refactor (#4723)
* refactor model fixing Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * missing cond macro Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * file Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * file Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * add macros dependency Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * deps and debug Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * add dependency to normal forms Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * na Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * build issues Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * compile Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fix leal regression * complete model fixer Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fold back private functionality to model_finder Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * avoid duplicate fixed callbacks Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
6cc52e04c3
commit
fa58a36b9f
42 changed files with 2060 additions and 1494 deletions
|
@ -2,6 +2,7 @@ z3_add_component(macros
|
|||
SOURCES
|
||||
macro_finder.cpp
|
||||
macro_manager.cpp
|
||||
quantifier_macro_info.cpp
|
||||
macro_util.cpp
|
||||
quasi_macros.cpp
|
||||
COMPONENT_DEPENDENCIES
|
||||
|
|
72
src/ast/macros/cond_macro.h
Normal file
72
src/ast/macros/cond_macro.h
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*++
|
||||
Copyright (c) 2006 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
cond_macro.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Class for maintaining conditional macros
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo de Moura (leonardo) 2010-12-17.
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
#pragma once
|
||||
#include "ast/ast_ll_pp.h"
|
||||
|
||||
class cond_macro {
|
||||
protected:
|
||||
func_decl * m_f;
|
||||
expr_ref m_def;
|
||||
expr_ref m_cond;
|
||||
bool m_ineq;
|
||||
bool m_satisfy_atom;
|
||||
bool m_hint;
|
||||
unsigned m_weight;
|
||||
public:
|
||||
cond_macro(ast_manager & m, func_decl * f, expr * def, expr * cond, bool ineq, bool satisfy_atom, bool hint, unsigned weight):
|
||||
m_f(f),
|
||||
m_def(def,m),
|
||||
m_cond(cond, m),
|
||||
m_ineq(ineq),
|
||||
m_satisfy_atom(satisfy_atom),
|
||||
m_hint(hint),
|
||||
m_weight(weight) {
|
||||
SASSERT(!m_hint || !m_cond);
|
||||
}
|
||||
|
||||
~cond_macro() {
|
||||
}
|
||||
|
||||
func_decl * get_f() const { return m_f; }
|
||||
|
||||
expr * get_def() const { return m_def; }
|
||||
|
||||
expr * get_cond() const { return m_cond; }
|
||||
|
||||
bool is_unconditional() const { return !m_cond || m_cond.m().is_true(m_cond); }
|
||||
|
||||
bool satisfy_atom() const { return m_satisfy_atom; }
|
||||
|
||||
bool is_hint() const { return m_hint; }
|
||||
|
||||
bool is_equal(cond_macro const * other) const {
|
||||
return m_f == other->m_f && m_def == other->m_def && m_cond == other->m_cond;
|
||||
}
|
||||
|
||||
std::ostream& display(std::ostream & out) const {
|
||||
out << "[" << m_f->get_name() << " -> " << mk_bounded_pp(m_def, m_def.m(), 6);
|
||||
if (m_hint)
|
||||
out << " *hint*";
|
||||
else
|
||||
out << " when " << mk_bounded_pp(m_cond, m_cond.m(), 6);
|
||||
return out << "] weight: " << m_weight;
|
||||
}
|
||||
|
||||
unsigned get_weight() const { return m_weight; }
|
||||
};
|
66
src/ast/macros/quantifier_macro_info.cpp
Normal file
66
src/ast/macros/quantifier_macro_info.cpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*++
|
||||
Copyright (c) 2006 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
quantifier_macro_info.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
Macro solving utilities
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo de Moura (leonardo) 2010-12-17.
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
#include "ast/ast_pp.h"
|
||||
#include "ast/macros/quantifier_macro_info.h"
|
||||
|
||||
quantifier_macro_info::quantifier_macro_info(ast_manager& m, quantifier* q) :
|
||||
m(m),
|
||||
m_flat_q(q, m),
|
||||
m_is_auf(true),
|
||||
m_has_x_eq_y(false),
|
||||
m_the_one(m) {
|
||||
SASSERT(is_forall(q));
|
||||
collect_macro_candidates(q);
|
||||
}
|
||||
|
||||
void quantifier_macro_info::collect_macro_candidates(quantifier* q) {
|
||||
macro_util mutil(m);
|
||||
macro_util::macro_candidates candidates(m);
|
||||
mutil.collect_macro_candidates(q, candidates);
|
||||
unsigned num_candidates = candidates.size();
|
||||
for (unsigned i = 0; i < num_candidates; i++) {
|
||||
cond_macro* mc = alloc(cond_macro, m, candidates.get_f(i), candidates.get_def(i), candidates.get_cond(i),
|
||||
candidates.ineq(i), candidates.satisfy_atom(i), candidates.hint(i), q->get_weight());
|
||||
insert_macro(mc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool quantifier_macro_info::unary_function_fragment() const {
|
||||
unsigned sz = m_ng_decls.size();
|
||||
if (sz > 1)
|
||||
return false;
|
||||
if (sz == 0)
|
||||
return true;
|
||||
func_decl* f = *(m_ng_decls.begin());
|
||||
return f->get_arity() == 1;
|
||||
}
|
||||
|
||||
std::ostream& quantifier_macro_info::display(std::ostream& out) const {
|
||||
out << "info for quantifier:\n" << mk_pp(m_flat_q, m) << "\n";
|
||||
out << "IS_AUF: " << m_is_auf << ", has x=y: " << m_has_x_eq_y << "\n";
|
||||
out << "unary function fragment: " << unary_function_fragment() << "\n";
|
||||
out << "ng decls: ";
|
||||
for (func_decl* f : m_ng_decls)
|
||||
out << f->get_name() << " ";
|
||||
out << "\nmacros:\n";
|
||||
for (cond_macro* cm : m_cond_macros)
|
||||
cm->display(out << " ") << "\n";
|
||||
return out;
|
||||
}
|
55
src/ast/macros/quantifier_macro_info.h
Normal file
55
src/ast/macros/quantifier_macro_info.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*++
|
||||
Copyright (c) 2006 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
quantifier_macro_info.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Macro solving utilities
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo de Moura (leonardo) 2010-12-17.
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
#pragma once
|
||||
#include "util/scoped_ptr_vector.h"
|
||||
#include "ast/ast_ll_pp.h"
|
||||
#include "ast/macros/cond_macro.h"
|
||||
#include "ast/macros/macro_util.h"
|
||||
#include "ast/func_decl_dependencies.h"
|
||||
|
||||
/**
|
||||
\brief Store relevant information regarding a particular universal quantifier.
|
||||
The information is used to (try to) build a model that satisfy the universal quantifier.
|
||||
*/
|
||||
class quantifier_macro_info {
|
||||
protected:
|
||||
ast_manager& m;
|
||||
quantifier_ref m_flat_q; // (flattened) quantifier
|
||||
bool m_is_auf;
|
||||
bool m_has_x_eq_y;
|
||||
func_decl_set m_ng_decls; // declarations used in non-ground applications (basic_family operators are ignored here).
|
||||
scoped_ptr_vector<cond_macro> m_cond_macros;
|
||||
func_decl_ref m_the_one; // the macro head used to satisfy the quantifier. this is useful for model checking
|
||||
void collect_macro_candidates(quantifier* q);
|
||||
public:
|
||||
quantifier_macro_info(ast_manager& m, quantifier* q);
|
||||
virtual ~quantifier_macro_info() {}
|
||||
bool is_auf() const { return m_is_auf; }
|
||||
quantifier* get_flat_q() const { return m_flat_q; }
|
||||
bool has_cond_macros() const { return !m_cond_macros.empty(); }
|
||||
scoped_ptr_vector<cond_macro> const& macros() const { return m_cond_macros; }
|
||||
void set_the_one(func_decl* f) { m_the_one = f; }
|
||||
func_decl* get_the_one() const { return m_the_one; }
|
||||
bool contains_ng_decl(func_decl* f) const { return m_ng_decls.contains(f); }
|
||||
func_decl_set const& get_ng_decls() const { return m_ng_decls; }
|
||||
virtual void reset_the_one() { m_the_one = nullptr; }
|
||||
void insert_macro(cond_macro* m) { m_cond_macros.push_back(m); }
|
||||
bool unary_function_fragment() const;
|
||||
virtual std::ostream& display(std::ostream& out) const;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue