mirror of
https://github.com/Z3Prover/z3
synced 2025-08-15 23:35:26 +00:00
add cube mode
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
commit
ae9a6664d4
144 changed files with 6012 additions and 3174 deletions
|
@ -392,24 +392,27 @@ struct is_non_nira_functor {
|
|||
|
||||
is_non_nira_functor(ast_manager & _m, bool _int, bool _real, bool _quant, bool linear):m(_m), u(m), m_int(_int), m_real(_real), m_quant(_quant), m_linear(linear) {}
|
||||
|
||||
void throw_found() {
|
||||
void throw_found(expr* e) {
|
||||
TRACE("probe", tout << expr_ref(e, m) << ": " << sort_ref(m.get_sort(e), m) << "\n";);
|
||||
throw found();
|
||||
}
|
||||
|
||||
void operator()(var * x) {
|
||||
if (!m_quant)
|
||||
throw_found();
|
||||
throw_found(x);
|
||||
sort * s = x->get_sort();
|
||||
if (m_int && u.is_int(s))
|
||||
return;
|
||||
if (m_real && u.is_real(s))
|
||||
return;
|
||||
throw_found();
|
||||
if (m.is_bool(s))
|
||||
return;
|
||||
throw_found(x);
|
||||
}
|
||||
|
||||
void operator()(quantifier *) {
|
||||
void operator()(quantifier * q) {
|
||||
if (!m_quant)
|
||||
throw_found();
|
||||
throw_found(q);
|
||||
}
|
||||
|
||||
bool compatible_sort(app * n) const {
|
||||
|
@ -424,7 +427,7 @@ struct is_non_nira_functor {
|
|||
|
||||
void operator()(app * n) {
|
||||
if (!compatible_sort(n))
|
||||
throw_found();
|
||||
throw_found(n);
|
||||
family_id fid = n->get_family_id();
|
||||
if (fid == m.get_basic_family_id())
|
||||
return;
|
||||
|
@ -437,39 +440,39 @@ struct is_non_nira_functor {
|
|||
case OP_MUL:
|
||||
if (m_linear) {
|
||||
if (n->get_num_args() != 2)
|
||||
throw_found();
|
||||
throw_found(n);
|
||||
if (!u.is_numeral(n->get_arg(0)))
|
||||
throw_found();
|
||||
throw_found(n);
|
||||
}
|
||||
return;
|
||||
case OP_IDIV: case OP_DIV: case OP_REM: case OP_MOD:
|
||||
if (m_linear && !u.is_numeral(n->get_arg(1)))
|
||||
throw_found();
|
||||
throw_found(n);
|
||||
return;
|
||||
case OP_IS_INT:
|
||||
if (m_real)
|
||||
throw_found();
|
||||
throw_found(n);
|
||||
return;
|
||||
case OP_TO_INT:
|
||||
case OP_TO_REAL:
|
||||
return;
|
||||
case OP_POWER:
|
||||
if (m_linear)
|
||||
throw_found();
|
||||
throw_found(n);
|
||||
return;
|
||||
case OP_IRRATIONAL_ALGEBRAIC_NUM:
|
||||
if (m_linear || !m_real)
|
||||
throw_found();
|
||||
throw_found(n);
|
||||
return;
|
||||
default:
|
||||
throw_found();
|
||||
throw_found(n);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_uninterp_const(n))
|
||||
return;
|
||||
throw_found();
|
||||
throw_found(n);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -33,12 +33,29 @@ model_converter * fpa2bv_model_converter::translate(ast_translation & translator
|
|||
}
|
||||
|
||||
void fpa2bv_model_converter::convert(model_core * mc, model * float_mdl) {
|
||||
TRACE("fpa2bv_mc", tout << "BV Model: " << std::endl;
|
||||
for (unsigned i = 0; i < mc->get_num_constants(); i++)
|
||||
tout << mc->get_constant(i)->get_name() << " --> " <<
|
||||
mk_ismt2_pp(mc->get_const_interp(mc->get_constant(i)), m) << std::endl;
|
||||
for (unsigned i = 0; i < mc->get_num_functions(); i++) {
|
||||
func_decl * f = mc->get_function(i);
|
||||
tout << f->get_name() << "(...) := " << std::endl;
|
||||
func_interp * fi = mc->get_func_interp(f);
|
||||
for (unsigned j = 0; j < fi->num_entries(); j++) {
|
||||
func_entry const * fe = fi->get_entry(j);
|
||||
for (unsigned k = 0; k < f->get_arity(); k++)
|
||||
tout << mk_ismt2_pp(fe->get_arg(k), m) << " ";
|
||||
tout << "--> " << mk_ismt2_pp(fe->get_result(), m) << std::endl;
|
||||
}
|
||||
tout << "else " << mk_ismt2_pp(fi->get_else(), m) << std::endl;
|
||||
});
|
||||
|
||||
obj_hashtable<func_decl> seen;
|
||||
m_bv2fp->convert_consts(mc, float_mdl, seen);
|
||||
m_bv2fp->convert_rm_consts(mc, float_mdl, seen);
|
||||
m_bv2fp->convert_min_max_specials(mc, float_mdl, seen);
|
||||
m_bv2fp->convert_uf2bvuf(mc, float_mdl, seen);
|
||||
|
||||
|
||||
// Keep all the non-float constants.
|
||||
unsigned sz = mc->get_num_constants();
|
||||
for (unsigned i = 0; i < sz; i++) {
|
||||
|
@ -46,7 +63,7 @@ void fpa2bv_model_converter::convert(model_core * mc, model * float_mdl) {
|
|||
if (!seen.contains(c))
|
||||
float_mdl->register_decl(c, mc->get_const_interp(c));
|
||||
}
|
||||
|
||||
|
||||
// And keep everything else
|
||||
sz = mc->get_num_functions();
|
||||
for (unsigned i = 0; i < sz; i++) {
|
||||
|
@ -57,7 +74,7 @@ void fpa2bv_model_converter::convert(model_core * mc, model * float_mdl) {
|
|||
float_mdl->register_decl(f, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sz = mc->get_num_uninterpreted_sorts();
|
||||
for (unsigned i = 0; i < sz; i++) {
|
||||
sort * s = mc->get_uninterpreted_sort(i);
|
||||
|
|
|
@ -26,7 +26,7 @@ Notes:
|
|||
class fpa2bv_model_converter : public model_converter {
|
||||
ast_manager & m;
|
||||
bv2fpa_converter * m_bv2fp;
|
||||
|
||||
|
||||
public:
|
||||
fpa2bv_model_converter(ast_manager & m, fpa2bv_converter & conv):
|
||||
m(m),
|
||||
|
@ -53,10 +53,10 @@ public:
|
|||
virtual model_converter * translate(ast_translation & translator);
|
||||
|
||||
protected:
|
||||
fpa2bv_model_converter(ast_manager & m) :
|
||||
fpa2bv_model_converter(ast_manager & m) :
|
||||
m(m),
|
||||
m_bv2fp(0) {}
|
||||
|
||||
|
||||
void convert(model_core * mc, model * float_mdl);
|
||||
};
|
||||
|
||||
|
|
|
@ -2,25 +2,25 @@ def_module_params('sls',
|
|||
export=True,
|
||||
description='Experimental Stochastic Local Search Solver (for QFBV only).',
|
||||
params=(max_memory_param(),
|
||||
('max_restarts', UINT, UINT_MAX, 'maximum number of restarts'),
|
||||
('walksat', BOOL, 1, 'use walksat assertion selection (instead of gsat)'),
|
||||
('walksat_ucb', BOOL, 1, 'use bandit heuristic for walksat assertion selection (instead of random)'),
|
||||
('walksat_ucb_constant', DOUBLE, 20.0, 'the ucb constant c in the term score + c * f(touched)'),
|
||||
('walksat_ucb_init', BOOL, 0, 'initialize total ucb touched to formula size'),
|
||||
('walksat_ucb_forget', DOUBLE, 1.0, 'scale touched by this factor every base restart interval'),
|
||||
('walksat_ucb_noise', DOUBLE, 0.0002, 'add noise 0 <= 256 * ucb_noise to ucb score for assertion selection'),
|
||||
('walksat_repick', BOOL, 1, 'repick assertion if randomizing in local minima'),
|
||||
('scale_unsat', DOUBLE, 0.5, 'scale score of unsat expressions by this factor'),
|
||||
('paws_init', UINT, 40, 'initial/minimum assertion weights'),
|
||||
('paws_sp', UINT, 52, 'smooth assertion weights with probability paws_sp / 1024'),
|
||||
('wp', UINT, 100, 'random walk with probability wp / 1024'),
|
||||
('vns_mc', UINT, 0, 'in local minima, try Monte Carlo sampling vns_mc many 2-bit-flips per bit'),
|
||||
('vns_repick', BOOL, 0, 'in local minima, try picking a different assertion (only for walksat)'),
|
||||
('restart_base', UINT, 100, 'base restart interval given by moves per run'),
|
||||
('restart_init', BOOL, 0, 'initialize to 0 or random value (= 1) after restart'),
|
||||
('early_prune', BOOL, 1, 'use early pruning for score prediction'),
|
||||
('random_offset', BOOL, 1, 'use random offset for candidate evaluation'),
|
||||
('rescore', BOOL, 1, 'rescore/normalize top-level score every base restart interval'),
|
||||
('track_unsat', BOOL, 0, 'keep a list of unsat assertions as done in SAT - currently disabled internally'),
|
||||
('random_seed', UINT, 0, 'random seed')
|
||||
))
|
||||
('max_restarts', UINT, UINT_MAX, 'maximum number of restarts'),
|
||||
('walksat', BOOL, 1, 'use walksat assertion selection (instead of gsat)'),
|
||||
('walksat_ucb', BOOL, 1, 'use bandit heuristic for walksat assertion selection (instead of random)'),
|
||||
('walksat_ucb_constant', DOUBLE, 20.0, 'the ucb constant c in the term score + c * f(touched)'),
|
||||
('walksat_ucb_init', BOOL, 0, 'initialize total ucb touched to formula size'),
|
||||
('walksat_ucb_forget', DOUBLE, 1.0, 'scale touched by this factor every base restart interval'),
|
||||
('walksat_ucb_noise', DOUBLE, 0.0002, 'add noise 0 <= 256 * ucb_noise to ucb score for assertion selection'),
|
||||
('walksat_repick', BOOL, 1, 'repick assertion if randomizing in local minima'),
|
||||
('scale_unsat', DOUBLE, 0.5, 'scale score of unsat expressions by this factor'),
|
||||
('paws_init', UINT, 40, 'initial/minimum assertion weights'),
|
||||
('paws_sp', UINT, 52, 'smooth assertion weights with probability paws_sp / 1024'),
|
||||
('wp', UINT, 100, 'random walk with probability wp / 1024'),
|
||||
('vns_mc', UINT, 0, 'in local minima, try Monte Carlo sampling vns_mc many 2-bit-flips per bit'),
|
||||
('vns_repick', BOOL, 0, 'in local minima, try picking a different assertion (only for walksat)'),
|
||||
('restart_base', UINT, 100, 'base restart interval given by moves per run'),
|
||||
('restart_init', BOOL, 0, 'initialize to 0 or random value (= 1) after restart'),
|
||||
('early_prune', BOOL, 1, 'use early pruning for score prediction'),
|
||||
('random_offset', BOOL, 1, 'use random offset for candidate evaluation'),
|
||||
('rescore', BOOL, 1, 'rescore/normalize top-level score every base restart interval'),
|
||||
('track_unsat', BOOL, 0, 'keep a list of unsat assertions as done in SAT - currently disabled internally'),
|
||||
('random_seed', UINT, 0, 'random seed')
|
||||
))
|
||||
|
|
|
@ -68,7 +68,7 @@ private:
|
|||
typedef obj_map<expr, value_score> scores_type;
|
||||
typedef obj_map<expr, ptr_vector<expr> > uplinks_type;
|
||||
typedef obj_map<expr, ptr_vector<func_decl> > occ_type;
|
||||
obj_hashtable<expr> m_top_expr;
|
||||
obj_hashtable<expr> m_top_expr;
|
||||
scores_type m_scores;
|
||||
uplinks_type m_uplinks;
|
||||
entry_point_type m_entry_points;
|
||||
|
@ -85,11 +85,11 @@ private:
|
|||
unsigned m_touched;
|
||||
double m_scale_unsat;
|
||||
unsigned m_paws_init;
|
||||
obj_map<expr, unsigned> m_where_false;
|
||||
expr** m_list_false;
|
||||
obj_map<expr, unsigned> m_where_false;
|
||||
expr** m_list_false;
|
||||
unsigned m_track_unsat;
|
||||
obj_map<expr, unsigned> m_weights;
|
||||
double m_top_sum;
|
||||
double m_top_sum;
|
||||
obj_hashtable<expr> m_temp_seen;
|
||||
|
||||
public:
|
||||
|
@ -450,7 +450,7 @@ public:
|
|||
m_list_false = new expr*[sz];
|
||||
for (unsigned i = 0; i < sz; i++)
|
||||
{
|
||||
if (m_mpz_manager.eq(get_value(as[i]), m_zero))
|
||||
if (m_mpz_manager.eq(get_value(as[i]), m_zero))
|
||||
break_assertion(as[i]);
|
||||
}
|
||||
}
|
||||
|
@ -462,7 +462,7 @@ public:
|
|||
|
||||
// initialize weights
|
||||
if (!m_weights.contains(e))
|
||||
m_weights.insert(e, m_paws_init);
|
||||
m_weights.insert(e, m_paws_init);
|
||||
|
||||
// positive/negative occurrences used for early pruning
|
||||
setup_occs(as[i]);
|
||||
|
@ -1075,7 +1075,7 @@ public:
|
|||
|
||||
unsigned cnt_unsat = 0;
|
||||
for (unsigned i = 0; i < sz; i++)
|
||||
if (m_mpz_manager.neq(get_value(as[i]), m_one) && (get_random_uint(16) % ++cnt_unsat == 0)) pos = i;
|
||||
if (m_mpz_manager.neq(get_value(as[i]), m_one) && (get_random_uint(16) % ++cnt_unsat == 0)) pos = i;
|
||||
if (pos == static_cast<unsigned>(-1))
|
||||
return 0;
|
||||
}
|
||||
|
@ -1092,7 +1092,7 @@ public:
|
|||
|
||||
unsigned cnt_unsat = 0, pos = -1;
|
||||
for (unsigned i = 0; i < sz; i++)
|
||||
if ((i != m_last_pos) && m_mpz_manager.neq(get_value(as[i]), m_one) && (get_random_uint(16) % ++cnt_unsat == 0)) pos = i;
|
||||
if ((i != m_last_pos) && m_mpz_manager.neq(get_value(as[i]), m_one) && (get_random_uint(16) % ++cnt_unsat == 0)) pos = i;
|
||||
|
||||
if (pos == static_cast<unsigned>(-1))
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue