3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-11-22 05:36:41 +00:00
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2025-11-19 14:02:27 -08:00
parent 5d316a51d1
commit 823800541e
3 changed files with 24 additions and 15 deletions

View file

@ -24,6 +24,8 @@ void order::order_lemma() {
TRACE(nla_solver, tout << "not generating order lemmas\n";); TRACE(nla_solver, tout << "not generating order lemmas\n";);
return; return;
} }
if (!c().params().arith_nl_linearize())
return;
for (auto j : c().m_to_refine) { for (auto j : c().m_to_refine) {
if (done()) break; if (done()) break;

View file

@ -129,6 +129,7 @@ struct solver::imp {
} }
auto lit = add_constraint(p, ci, k); auto lit = add_constraint(p, ci, k);
} }
definitions.reset();
} }
void setup_solver_terms() { void setup_solver_terms() {
@ -153,10 +154,10 @@ struct solver::imp {
continue; continue;
auto value = m_nla_core.val(v); auto value = m_nla_core.val(v);
SASSERT(value.is_int()); SASSERT(value.is_int());
unsigned sz = m_model_bounds.size(); unsigned offset = m_model_bounds.size() + m_max_constraint_index;
m_model_bounds.push_back({v, value, true}); m_model_bounds.push_back({v, value, true});
m_model_bounds.push_back({v, value, false}); m_model_bounds.push_back({v, value, false});
m_nlsat->track_model_value(lp2nl(v), value, this + sz, this + sz + 1); m_nlsat->track_model_value(lp2nl(v), value, this + offset, this + offset + 1);
} }
} }
@ -174,7 +175,7 @@ struct solver::imp {
lbool check() { lbool check() {
SASSERT(need_check()); SASSERT(need_check());
reset(); reset();
vector<nlsat::assumption, false> core; vector<nlsat::assumption, false> core;
smt_params_helper p(m_params); smt_params_helper p(m_params);
@ -250,6 +251,7 @@ struct solver::imp {
nla::lemma_builder lemma(m_nla_core, __FUNCTION__); nla::lemma_builder lemma(m_nla_core, __FUNCTION__);
for (auto c : core) { for (auto c : core) {
unsigned idx = static_cast<unsigned>(static_cast<imp*>(c) - this); unsigned idx = static_cast<unsigned>(static_cast<imp*>(c) - this);
TRACE(nra, tout << "core index " << idx << " " << m_max_constraint_index << "\n");
if (idx <= m_max_constraint_index) if (idx <= m_max_constraint_index)
ex.push_back(idx); ex.push_back(idx);
else { else {
@ -360,6 +362,7 @@ struct solver::imp {
} }
nlsat::literal add_constraint(polynomial::polynomial *p, unsigned idx, lp::lconstraint_kind k) { nlsat::literal add_constraint(polynomial::polynomial *p, unsigned idx, lp::lconstraint_kind k) {
m_max_constraint_index = std::max(m_max_constraint_index, idx);
polynomial::polynomial *ps[1] = {p}; polynomial::polynomial *ps[1] = {p};
bool is_even[1] = {false}; bool is_even[1] = {false};
nlsat::literal lit; nlsat::literal lit;

View file

@ -1871,6 +1871,7 @@ namespace nlsat {
lbool search_check() { lbool search_check() {
verbose_stream() << "search check\n";
lbool r = l_undef; lbool r = l_undef;
m_stats.m_conflicts = 0; m_stats.m_conflicts = 0;
m_stats.m_restarts = 0; m_stats.m_restarts = 0;
@ -1880,8 +1881,15 @@ namespace nlsat {
if (r != l_true) if (r != l_true)
break; break;
++m_stats.m_restarts; ++m_stats.m_restarts;
vector<std::pair<var, rational>> bounds;
gc();
if (m_stats.m_restarts % 10 == 0) {
if (m_reordered)
restore_order();
apply_reorder();
}
vector<std::pair<var, rational>> bounds;
for (var x = 0; x < num_vars(); x++) { for (var x = 0; x < num_vars(); x++) {
if (is_int(x) && m_assignment.is_assigned(x) && !m_am.is_int(m_assignment.value(x))) { if (is_int(x) && m_assignment.is_assigned(x) && !m_am.is_int(m_assignment.value(x))) {
scoped_anum v(m_am), vlo(m_am); scoped_anum v(m_am), vlo(m_am);
@ -1905,13 +1913,6 @@ namespace nlsat {
if (bounds.empty()) if (bounds.empty())
break; break;
gc();
if (m_stats.m_restarts % 10 == 0) {
if (m_reordered)
restore_order();
apply_reorder();
}
init_search(); init_search();
IF_VERBOSE(2, verbose_stream() << "(nlsat-b&b :conflicts " << m_stats.m_conflicts IF_VERBOSE(2, verbose_stream() << "(nlsat-b&b :conflicts " << m_stats.m_conflicts
<< " :decisions " << m_stats.m_decisions << " :decisions " << m_stats.m_decisions
@ -1925,15 +1926,18 @@ namespace nlsat {
if (!m_model_values.empty()) { if (!m_model_values.empty()) {
bool found = false; bool found = false;
random_gen r(++m_random_seed); random_gen r(++m_random_seed);
auto const &[x, bound] = bounds[r(bounds.size())]; auto const &[x, value] = bounds[r(bounds.size())];
for (auto const &[mx, mvalue, lo, hi] : m_model_values) { for (auto const &[ext_x, mvalue, lo, hi] : m_model_values) {
if (mx == x) { if (ext_x == m_perm[x]) {
verbose_stream() << x << " " << ext_x << " bound: " << mvalue << " value " << value
<< "\n ";
TRACE(nla_solver, tout << "x" << ext_x << " bound " << mvalue << "\n");
polynomial_ref p(m_pm); polynomial_ref p(m_pm);
rational one(1); rational one(1);
bool is_even = false; bool is_even = false;
p = m_pm.mk_linear(1, &one, &x, -mvalue); // x - mvalue p = m_pm.mk_linear(1, &one, &x, -mvalue); // x - mvalue
auto *p1 = p.get(); auto *p1 = p.get();
if (mvalue < bound) { if (mvalue < value) {
// assert x <= mvalue // assert x <= mvalue
// <=> // <=>
// ~ (x > mvalue) // ~ (x > mvalue)