mirror of
https://github.com/Z3Prover/z3
synced 2025-04-24 17:45:32 +00:00
isolated proto_model obsolete code
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
24efe18d3f
commit
759504880a
17 changed files with 68 additions and 78 deletions
|
@ -16,8 +16,6 @@ Revision History:
|
|||
|
||||
--*/
|
||||
#include"func_interp.h"
|
||||
#include"simplifier.h"
|
||||
#include"basic_simplifier_plugin.h"
|
||||
#include"var_subst.h"
|
||||
#include"obj_hashtable.h"
|
||||
#include"ast_pp.h"
|
||||
|
@ -182,71 +180,6 @@ bool func_interp::eval_else(expr * const * args, expr_ref & result) const {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Store in r the result of applying args to this function.
|
||||
Return true in case of success.
|
||||
The function may fail if m_else == 0.
|
||||
*/
|
||||
bool func_interp::eval(simplifier & s, expr * const * args, expr_ref & result) {
|
||||
bool actuals_are_values = true;
|
||||
|
||||
if (!m_entries.empty()) {
|
||||
for (unsigned i = 0; actuals_are_values && i < m_arity; i++) {
|
||||
actuals_are_values = m_manager.is_value(args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
func_entry * entry = get_entry(args);
|
||||
if (entry != 0) {
|
||||
result = entry->get_result();
|
||||
TRACE("func_interp", tout << "found entry for: ";
|
||||
for(unsigned i = 0; i < m_arity; i++)
|
||||
tout << mk_pp(args[i], m_manager) << " ";
|
||||
tout << "\nresult: " << mk_pp(result, m_manager) << "\n";);
|
||||
return true;
|
||||
}
|
||||
|
||||
TRACE("func_interp", tout << "failed to find entry for: ";
|
||||
for(unsigned i = 0; i < m_arity; i++)
|
||||
tout << mk_pp(args[i], m_manager) << " ";
|
||||
tout << "\nis partial: " << is_partial() << "\n";);
|
||||
|
||||
if (!eval_else(args, result)) {
|
||||
TRACE("func_interp", tout << "function is partial, failed to evaluate\n";);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (actuals_are_values && m_args_are_values) {
|
||||
// cheap case... we are done
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// build symbolic result... the actuals may be equal to the args of one of the entries.
|
||||
basic_simplifier_plugin * bs = static_cast<basic_simplifier_plugin*>(s.get_plugin(m_manager.get_basic_family_id()));
|
||||
ptr_vector<func_entry>::iterator it = m_entries.begin();
|
||||
ptr_vector<func_entry>::iterator end = m_entries.end();
|
||||
for (; it != end; ++it) {
|
||||
func_entry * curr = *it;
|
||||
SASSERT(!curr->eq_args(m_arity, args));
|
||||
if (!actuals_are_values || !curr->args_are_values()) {
|
||||
expr_ref_buffer eqs(m_manager);
|
||||
unsigned i = m_arity;
|
||||
while (i > 0) {
|
||||
--i;
|
||||
expr_ref new_eq(m_manager);
|
||||
bs->mk_eq(curr->get_arg(i), args[i], new_eq);
|
||||
eqs.push_back(new_eq);
|
||||
}
|
||||
SASSERT(eqs.size() == m_arity);
|
||||
expr_ref new_cond(m_manager);
|
||||
bs->mk_and(eqs.size(), eqs.c_ptr(), new_cond);
|
||||
bs->mk_ite(new_cond, curr->get_result(), result, result);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Return the result with the maximal number of occurrencies in m_entries.
|
||||
*/
|
||||
|
|
|
@ -34,7 +34,6 @@ Revision History:
|
|||
#include"ast_translation.h"
|
||||
|
||||
class func_interp;
|
||||
class simplifier;
|
||||
|
||||
class func_entry {
|
||||
bool m_args_are_values; //!< true if is_value(m_args[i]) is true for all i in [0, arity)
|
||||
|
@ -50,10 +49,10 @@ class func_entry {
|
|||
friend class func_interp;
|
||||
|
||||
void set_result(ast_manager & m, expr * r);
|
||||
bool args_are_values() const { return m_args_are_values; }
|
||||
|
||||
public:
|
||||
static func_entry * mk(ast_manager & m, unsigned arity, expr * const * args, expr * result);
|
||||
bool args_are_values() const { return m_args_are_values; }
|
||||
void deallocate(ast_manager & m, unsigned arity);
|
||||
expr * get_result() const { return m_result; }
|
||||
expr * get_arg(unsigned idx) const { return m_args[idx]; }
|
||||
|
@ -81,6 +80,8 @@ public:
|
|||
func_interp(ast_manager & m, unsigned arity);
|
||||
~func_interp();
|
||||
|
||||
ast_manager & m () const { return m_manager; }
|
||||
|
||||
func_interp * copy() const;
|
||||
|
||||
unsigned get_arity() const { return m_arity; }
|
||||
|
@ -88,8 +89,9 @@ public:
|
|||
bool is_partial() const { return m_else == 0; }
|
||||
// A function interpretation is said to be simple if m_else is ground.
|
||||
bool is_simple() const { return is_partial() || is_ground(m_else); }
|
||||
|
||||
bool is_constant() const;
|
||||
// Return true if all arguments of the function graph are values.
|
||||
bool args_are_values() const { return m_args_are_values; }
|
||||
|
||||
expr * get_else() const { return m_else; }
|
||||
void set_else(expr * e);
|
||||
|
@ -98,7 +100,6 @@ public:
|
|||
void insert_new_entry(expr * const * args, expr * r);
|
||||
func_entry * get_entry(expr * const * args) const;
|
||||
bool eval_else(expr * const * args, expr_ref & result) const;
|
||||
bool eval(simplifier & s, expr * const * args, expr_ref & result);
|
||||
unsigned num_entries() const { return m_entries.size(); }
|
||||
func_entry const * const * get_entries() const { return m_entries.c_ptr(); }
|
||||
func_entry const * get_entry(unsigned idx) const { return m_entries[idx]; }
|
||||
|
|
|
@ -24,6 +24,7 @@ Revision History:
|
|||
#include"well_sorted.h"
|
||||
#include"used_symbols.h"
|
||||
#include"model_v2_pp.h"
|
||||
#include"basic_simplifier_plugin.h"
|
||||
|
||||
proto_model::proto_model(ast_manager & m, simplifier & s, model_params const & p):
|
||||
model_core(m),
|
||||
|
@ -115,6 +116,62 @@ expr * proto_model::mk_some_interp_for(func_decl * d) {
|
|||
return r;
|
||||
}
|
||||
|
||||
// Auxiliary function for computing fi(args[0], ..., args[fi.get_arity() - 1]).
|
||||
// The result is stored in result.
|
||||
// Return true if succeeded, and false otherwise.
|
||||
// It uses the simplifier s during the computation.
|
||||
bool eval(func_interp & fi, simplifier & s, expr * const * args, expr_ref & result) {
|
||||
bool actuals_are_values = true;
|
||||
|
||||
if (fi.num_entries() != 0) {
|
||||
for (unsigned i = 0; actuals_are_values && i < fi.get_arity(); i++) {
|
||||
actuals_are_values = fi.m().is_value(args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
func_entry * entry = fi.get_entry(args);
|
||||
if (entry != 0) {
|
||||
result = entry->get_result();
|
||||
return true;
|
||||
}
|
||||
|
||||
TRACE("func_interp", tout << "failed to find entry for: ";
|
||||
for(unsigned i = 0; i < fi.get_arity(); i++)
|
||||
tout << mk_pp(args[i], fi.m()) << " ";
|
||||
tout << "\nis partial: " << fi.is_partial() << "\n";);
|
||||
|
||||
if (!fi.eval_else(args, result)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (actuals_are_values && fi.args_are_values()) {
|
||||
// cheap case... we are done
|
||||
return true;
|
||||
}
|
||||
|
||||
// build symbolic result... the actuals may be equal to the args of one of the entries.
|
||||
basic_simplifier_plugin * bs = static_cast<basic_simplifier_plugin*>(s.get_plugin(fi.m().get_basic_family_id()));
|
||||
for (unsigned k = 0; k < fi.num_entries(); k++) {
|
||||
func_entry const * curr = fi.get_entry(k);
|
||||
SASSERT(!curr->eq_args(fi.get_arity(), args));
|
||||
if (!actuals_are_values || !curr->args_are_values()) {
|
||||
expr_ref_buffer eqs(fi.m());
|
||||
unsigned i = fi.get_arity();
|
||||
while (i > 0) {
|
||||
--i;
|
||||
expr_ref new_eq(fi.m());
|
||||
bs->mk_eq(curr->get_arg(i), args[i], new_eq);
|
||||
eqs.push_back(new_eq);
|
||||
}
|
||||
SASSERT(eqs.size() == fi.get_arity());
|
||||
expr_ref new_cond(fi.m());
|
||||
bs->mk_and(eqs.size(), eqs.c_ptr(), new_cond);
|
||||
bs->mk_ite(new_cond, curr->get_result(), result, result);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Evaluate the expression e in the current model, and store the result in \c result.
|
||||
It returns \c true if succeeded, and false otherwise. If the evaluation fails,
|
||||
|
@ -223,7 +280,7 @@ bool proto_model::eval(expr * e, expr_ref & result, bool model_completion) {
|
|||
SASSERT(fi->get_arity() == num_args);
|
||||
expr_ref r1(m_manager);
|
||||
// fi may be partial...
|
||||
if (!fi->eval(m_simplifier, args.c_ptr(), r1)) {
|
||||
if (!::eval(*fi, m_simplifier, args.c_ptr(), r1)) {
|
||||
SASSERT(fi->is_partial()); // fi->eval only fails when fi is partial.
|
||||
if (model_completion) {
|
||||
expr * r = get_some_value(f->get_range());
|
|
@ -48,8 +48,6 @@ public:
|
|||
virtual bool get_some_values(sort * s, expr_ref & v1, expr_ref & v2);
|
||||
|
||||
virtual void register_value(expr * array_value);
|
||||
|
||||
proto_model & get_model() { return m_model; }
|
||||
};
|
||||
|
||||
#endif /* _STRUCT_FACTORY_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue