3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-13 04:28:17 +00:00

address the review

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
Lev Nachmanson 2025-02-10 10:00:20 -10:00 committed by Lev Nachmanson
parent 8a9edd1aa7
commit 5ec10e0250

View file

@ -289,9 +289,11 @@ namespace lp {
for (auto& [val, j] : sorted_term) { for (auto& [val, j] : sorted_term) {
if (first) { if (first) {
first = false; first = false;
} else if (is_pos(val)) { }
else if (is_pos(val)) {
out << " + "; out << " + ";
} else { }
else {
out << " - "; out << " - ";
val = -val; val = -val;
} }
@ -384,7 +386,8 @@ namespace lp {
// Insert a new monomial { a, j } into m_data // Insert a new monomial { a, j } into m_data
m_data.push_back({a, j}); m_data.push_back({a, j});
m_index[j] = static_cast<int>(m_data.size() - 1); m_index[j] = static_cast<int>(m_data.size() - 1);
} else { }
else {
// Accumulate the coefficient // Accumulate the coefficient
m_data[idx].coeff() += a; m_data[idx].coeff() += a;
// If the coefficient becomes zero, remove the entry // If the coefficient becomes zero, remove the entry
@ -415,7 +418,8 @@ namespace lp {
return false; return false;
} }
} }
} else { }
else {
// Check that var() in m_data[idx] matches j // Check that var() in m_data[idx] matches j
if (idx < 0 || static_cast<unsigned>(idx) >= m_data.size()) { if (idx < 0 || static_cast<unsigned>(idx) >= m_data.size()) {
return false; return false;
@ -757,7 +761,8 @@ namespace lp {
if (it != m_columns_to_terms.end()) { if (it != m_columns_to_terms.end()) {
it->second.insert(t.j()); it->second.insert(t.j());
} else { }
else {
std::unordered_set<unsigned> s; std::unordered_set<unsigned> s;
s.insert(t.j()); s.insert(t.j());
m_columns_to_terms[p.var()] = s; m_columns_to_terms[p.var()] = s;
@ -840,7 +845,8 @@ namespace lp {
if (alpha.is_zero()) continue; if (alpha.is_zero()) continue;
if (m_k2s.has_key(j)) { if (m_k2s.has_key(j)) {
substitute_on_q_with_entry_in_S(q, ei, j, alpha); substitute_on_q_with_entry_in_S(q, ei, j, alpha);
} else { }
else {
substitute_with_fresh_def(q, ei, j, alpha); substitute_with_fresh_def(q, ei, j, alpha);
} }
} }
@ -1281,7 +1287,8 @@ namespace lp {
SASSERT(can_substitute(k)); SASSERT(can_substitute(k));
if (is_substituted_by_fresh(k)) { if (is_substituted_by_fresh(k)) {
subs_front_in_indexed_vector_by_fresh(k, q); subs_front_in_indexed_vector_by_fresh(k, q);
} else { }
else {
subs_front_in_indexed_vector_by_S(k, q); subs_front_in_indexed_vector_by_S(k, q);
} }
} }
@ -1316,7 +1323,8 @@ namespace lp {
for (const auto& p : t) { for (const auto& p : t) {
if (is_fixed(p.var())) { if (is_fixed(p.var())) {
ret.c() += p.coeff() * this->lra.get_lower_bound(p.var()).x; ret.c() += p.coeff() * this->lra.get_lower_bound(p.var()).x;
} else { }
else {
ret.add_monomial(p.coeff(), p.var()); ret.add_monomial(p.coeff(), p.var());
} }
} }
@ -1608,7 +1616,8 @@ namespace lp {
if (m_e_matrix.m_rows[ei].size() == 0) { if (m_e_matrix.m_rows[ei].size() == 0) {
if (m_sum_of_fixed[ei].is_zero()) { if (m_sum_of_fixed[ei].is_zero()) {
continue; continue;
} else { }
else {
m_conflict_index = ei; m_conflict_index = ei;
return; return;
} }
@ -1679,7 +1688,8 @@ namespace lp {
} }
if (g.is_zero()) { if (g.is_zero()) {
g = abs(p.coeff()); g = abs(p.coeff());
} else { }
else {
g = gcd(g, p.coeff()); g = gcd(g, p.coeff());
} }
if (g.is_one()) return lia_move::undef; if (g.is_one()) return lia_move::undef;
@ -1730,7 +1740,8 @@ namespace lp {
lia_move add_var_bound_for_branch(const branch& b) { lia_move add_var_bound_for_branch(const branch& b) {
if (b.m_left) { if (b.m_left) {
lra.add_var_bound(b.m_j, lconstraint_kind::LE, b.m_rs); lra.add_var_bound(b.m_j, lconstraint_kind::LE, b.m_rs);
} else { }
else {
lra.add_var_bound(b.m_j, lconstraint_kind::GE, b.m_rs + mpq(1)); lra.add_var_bound(b.m_j, lconstraint_kind::GE, b.m_rs + mpq(1));
} }
TRACE("dio_br", lra.print_column_info(b.m_j, tout) << "add bound" << std::endl;); TRACE("dio_br", lra.print_column_info(b.m_j, tout) << "add bound" << std::endl;);
@ -1812,7 +1823,8 @@ namespace lp {
// got to create a new branch // got to create a new branch
update_branch_stats(m_branch_stack.back(), n_of_ii); update_branch_stats(m_branch_stack.back(), n_of_ii);
need_create_branch = true; need_create_branch = true;
} else { }
else {
if (st == lp_status::CANCELLED) return lia_move::undef; if (st == lp_status::CANCELLED) return lia_move::undef;
collect_evidence(); collect_evidence();
undo_explored_branches(); undo_explored_branches();
@ -1856,7 +1868,8 @@ namespace lp {
if (b.m_left) { if (b.m_left) {
m_branch_stats[b.m_j].m_ii_after_left.push_back(n_of_ii); m_branch_stats[b.m_j].m_ii_after_left.push_back(n_of_ii);
} else { }
else {
m_branch_stats[b.m_j].m_ii_after_right.push_back(n_of_ii); m_branch_stats[b.m_j].m_ii_after_right.push_back(n_of_ii);
} }
} }
@ -1913,7 +1926,8 @@ namespace lp {
std::unordered_set<unsigned> s; std::unordered_set<unsigned> s;
s.insert(t->j()); s.insert(t->j());
c2t[j] = s; c2t[j] = s;
} else { }
else {
it->second.insert(t->j()); it->second.insert(t->j());
} }
} }
@ -2137,11 +2151,8 @@ namespace lp {
for (unsigned ei = 0; ei < m_e_matrix.row_count(); ei++) { for (unsigned ei = 0; ei < m_e_matrix.row_count(); ei++) {
if (!belongs_to_f(ei)) continue; if (!belongs_to_f(ei)) continue;
const auto& row = m_e_matrix.m_rows[ei]; const auto& row = m_e_matrix.m_rows[ei];
for (const auto& p : row) { bool eliminated_in_row = all_of(row, [j](auto & p) { return p.var() != j; });
if (p.var() == j) { if (!eliminated_in_row) return false;
return false;
}
}
} }
return true; return true;
} }
@ -2243,7 +2254,8 @@ namespace lp {
for (const auto& q : t.ext_coeffs()) { for (const auto& q : t.ext_coeffs()) {
if (is_fixed(q.var())) { if (is_fixed(q.var())) {
c += p.coeff() * q.coeff() * lia.lower_bound(q.var()).x; c += p.coeff() * q.coeff() * lia.lower_bound(q.var()).x;
} else { }
else {
m_substitution_workspace.add(p.coeff() * q.coeff(), q.var()); m_substitution_workspace.add(p.coeff() * q.coeff(), q.var());
} }
} }
@ -2266,7 +2278,8 @@ namespace lp {
auto it = m_row2fresh_defs.find(h); auto it = m_row2fresh_defs.find(h);
if (it == m_row2fresh_defs.end()) { if (it == m_row2fresh_defs.end()) {
m_row2fresh_defs[h].push_back(fr_j); m_row2fresh_defs[h].push_back(fr_j);
} else { }
else {
it->second.push_back(fr_j); it->second.push_back(fr_j);
} }
} }
@ -2321,11 +2334,13 @@ namespace lp {
} }
if (belongs_to_f(i)) { if (belongs_to_f(i)) {
out << "in F\n"; out << "in F\n";
} else { }
else {
unsigned j = m_k2s.get_key(i); unsigned j = m_k2s.get_key(i);
if (local_to_lar_solver(j) == UINT_MAX) { if (local_to_lar_solver(j) == UINT_MAX) {
out << "FRESH\n"; out << "FRESH\n";
} else { }
else {
out << "in S\n"; out << "in S\n";
} }
} }
@ -2352,12 +2367,11 @@ namespace lp {
bool rewrite_eqs(std_vector<unsigned>& f_vector) { bool rewrite_eqs(std_vector<unsigned>& f_vector) {
if (f_vector.size() == 0) if (f_vector.size() == 0)
return false; return false;
unsigned h = -1; unsigned h = -1, kh = 0; // the initial value of kh does not matter, assign to remove the warning
unsigned n = 0; // number of choices for a fresh variable unsigned n = 0; // number of choices for a fresh variable
mpq min_ahk; mpq min_ahk;
unsigned kh; int kh_sign = 0; // the initial values of kh_sign and h_markovich_number do not matter, assign to remove the warning
int kh_sign; unsigned h_markovich_number = 0;
unsigned h_markovich_number;
unsigned ih; // f_vector[ih] = h unsigned ih; // f_vector[ih] = h
for (unsigned i = 0; i < f_vector.size(); i++) { for (unsigned i = 0; i < f_vector.size(); i++) {
unsigned ei = f_vector[i]; unsigned ei = f_vector[i];
@ -2365,7 +2379,8 @@ namespace lp {
if (m_e_matrix.m_rows[ei].size() == 0) { if (m_e_matrix.m_rows[ei].size() == 0) {
if (m_sum_of_fixed[ei].is_zero()) { if (m_sum_of_fixed[ei].is_zero()) {
continue; continue;
} else { }
else {
m_conflict_index = ei; m_conflict_index = ei;
return false; return false;
} }
@ -2410,7 +2425,8 @@ namespace lp {
f_vector[ih] = f_vector.back(); f_vector[ih] = f_vector.back();
} }
f_vector.pop_back(); f_vector.pop_back();
} else }
else
fresh_var_step(h, kh, min_ahk * mpq(kh_sign)); fresh_var_step(h, kh, min_ahk * mpq(kh_sign));
return true; return true;
} }