mirror of
https://github.com/Z3Prover/z3
synced 2025-08-19 17:50:23 +00:00
add recfuns to model
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
51a0022450
commit
80acf8ed79
9 changed files with 45 additions and 15 deletions
|
@ -1360,7 +1360,8 @@ ast_manager::ast_manager(ast_manager const & src, bool disable_proofs):
|
|||
m_proof_mode(disable_proofs ? PGM_DISABLED : src.m_proof_mode),
|
||||
m_trace_stream(src.m_trace_stream),
|
||||
m_trace_stream_owner(false),
|
||||
m_rec_fun(":rec-fun") {
|
||||
m_rec_fun(":rec-fun"),
|
||||
m_lambda_def(":lambda-def") {
|
||||
SASSERT(!src.is_format_manager());
|
||||
m_format_manager = alloc(ast_manager, PGM_DISABLED, m_trace_stream, true);
|
||||
init();
|
||||
|
|
|
@ -1636,7 +1636,7 @@ public:
|
|||
bool are_distinct(expr * a, expr * b) const;
|
||||
|
||||
bool contains(ast * a) const { return m_ast_table.contains(a); }
|
||||
|
||||
|
||||
bool is_rec_fun_def(quantifier* q) const { return q->get_qid() == m_rec_fun; }
|
||||
bool is_lambda_def(quantifier* q) const { return q->get_qid() == m_lambda_def; }
|
||||
func_decl* get_rec_fun_decl(quantifier* q) const;
|
||||
|
|
|
@ -56,6 +56,7 @@ namespace recfun {
|
|||
m_domain(m, arity, domain),
|
||||
m_range(range, m), m_vars(m), m_cases(),
|
||||
m_decl(m),
|
||||
m_rhs(m),
|
||||
m_fid(fid)
|
||||
{
|
||||
SASSERT(arity == get_arity());
|
||||
|
@ -211,7 +212,7 @@ namespace recfun {
|
|||
name.append(m_name.bare_str());
|
||||
|
||||
m_vars.append(n_vars, vars);
|
||||
|
||||
m_rhs = rhs;
|
||||
|
||||
expr_ref_vector conditions(m);
|
||||
|
||||
|
|
|
@ -99,6 +99,7 @@ namespace recfun {
|
|||
vars m_vars; //<! variables of the function
|
||||
cases m_cases; //!< possible cases
|
||||
func_decl_ref m_decl; //!< generic declaration
|
||||
expr_ref m_rhs; //!< definition
|
||||
family_id m_fid;
|
||||
|
||||
def(ast_manager &m, family_id fid, symbol const & s, unsigned arity, sort *const * domain, sort* range);
|
||||
|
@ -116,13 +117,11 @@ namespace recfun {
|
|||
sort_ref_vector const & get_domain() const { return m_domain; }
|
||||
sort_ref const & get_range() const { return m_range; }
|
||||
func_decl * get_decl() const { return m_decl.get(); }
|
||||
expr * get_rhs() const { return m_rhs; }
|
||||
|
||||
bool is_fun_macro() const { return m_cases.size() == 1; }
|
||||
bool is_fun_defined() const { return !is_fun_macro(); }
|
||||
|
||||
expr * get_macro_rhs() const {
|
||||
return m_cases[0].get_rhs();
|
||||
}
|
||||
};
|
||||
|
||||
// definition to be complete (missing RHS)
|
||||
|
@ -180,7 +179,12 @@ namespace recfun {
|
|||
def& get_def(func_decl* f) { return *(m_defs[f]); }
|
||||
bool has_case_def(func_decl* f) const { return m_case_defs.contains(f); }
|
||||
case_def& get_case_def(func_decl* f) { SASSERT(has_case_def(f)); return *(m_case_defs[f]); }
|
||||
//bool is_declared(symbol const& s) const { return m_defs.contains(s); }
|
||||
|
||||
func_decl_ref_vector get_rec_funs() {
|
||||
func_decl_ref_vector result(m());
|
||||
for (auto& kv : m_defs) result.push_back(kv.m_key);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -232,6 +236,10 @@ namespace recfun {
|
|||
return mk_fun_defined(d, args.size(), args.c_ptr());
|
||||
}
|
||||
|
||||
func_decl_ref_vector get_rec_funs() {
|
||||
return m_plugin->get_rec_funs();
|
||||
}
|
||||
|
||||
app_ref mk_depth_limit_pred(unsigned d);
|
||||
|
||||
decl::plugin& get_plugin() { return *m_plugin; }
|
||||
|
|
|
@ -279,8 +279,9 @@ protected:
|
|||
return false;
|
||||
}
|
||||
|
||||
bool get_macro(func_decl * f, expr * & def, quantifier * & q, proof * & def_pr) {
|
||||
return m_cfg.get_macro(f, def, q, def_pr);
|
||||
bool get_macro(func_decl * f, expr * & def, proof * & def_pr) {
|
||||
quantifier* q = nullptr;
|
||||
return m_cfg.get_macro(f, def, q, def_pr);
|
||||
}
|
||||
|
||||
void push_frame(expr * t, bool mcache, unsigned max_depth) {
|
||||
|
|
|
@ -212,6 +212,7 @@ bool rewriter_tpl<Config>::constant_fold(app * t, frame & fr) {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
template<typename Config>
|
||||
template<bool ProofGen>
|
||||
void rewriter_tpl<Config>::process_app(app * t, frame & fr) {
|
||||
|
@ -338,15 +339,12 @@ void rewriter_tpl<Config>::process_app(app * t, frame & fr) {
|
|||
// TODO: add rewrite rules support
|
||||
expr * def = nullptr;
|
||||
proof * def_pr = nullptr;
|
||||
quantifier * def_q = nullptr;
|
||||
// When get_macro succeeds, then
|
||||
// we know that:
|
||||
// forall X. f(X) = def[X]
|
||||
// and def_pr is a proof for this quantifier.
|
||||
//
|
||||
// Remark: def_q is only used for proof generation.
|
||||
// It is the quantifier forall X. f(X) = def[X]
|
||||
if (get_macro(f, def, def_q, def_pr)) {
|
||||
if (get_macro(f, def, def_pr)) {
|
||||
SASSERT(!f->is_associative() || !flat_assoc(f));
|
||||
SASSERT(new_num_args == t->get_num_args());
|
||||
SASSERT(m().get_sort(def) == m().get_sort(t));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue