3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-24 01:25:31 +00:00

move out sign

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2020-01-19 09:34:22 -06:00
parent 89c91765f6
commit d3b105f9f8
15 changed files with 176 additions and 168 deletions

View file

@ -43,7 +43,7 @@ namespace nlsat {
svector<section> m_sections;
unsigned_vector m_sorted_sections; // refs to m_sections
unsigned_vector m_poly_sections; // refs to m_sections
svector<polynomial::sign> m_poly_signs;
svector<sign> m_poly_signs;
struct poly_info {
unsigned m_num_roots;
unsigned m_first_section; // idx in m_poly_sections;
@ -149,7 +149,7 @@ namespace nlsat {
\brief Add polynomial with the given roots and signs.
*/
unsigned_vector p_section_ids;
void add(anum_vector & roots, svector<polynomial::sign> & signs) {
void add(anum_vector & roots, svector<sign> & signs) {
p_section_ids.reset();
if (!roots.empty())
merge(roots, p_section_ids);
@ -169,7 +169,7 @@ namespace nlsat {
/**
\brief Add constant polynomial
*/
void add_const(polynomial::sign sign) {
void add_const(sign sign) {
unsigned first_sign = m_poly_signs.size();
unsigned first_section = m_poly_sections.size();
m_poly_signs.push_back(sign);
@ -226,12 +226,12 @@ namespace nlsat {
}
// Return the sign idx of pinfo
polynomial::sign sign(poly_info const & pinfo, unsigned i) const {
::sign sign(poly_info const & pinfo, unsigned i) const {
return m_poly_signs[pinfo.m_first_sign + i];
}
#define LINEAR_SEARCH_THRESHOLD 8
polynomial::sign sign_at(unsigned info_id, unsigned c) const {
::sign sign_at(unsigned info_id, unsigned c) const {
poly_info const & pinfo = m_info[info_id];
unsigned num_roots = pinfo.m_num_roots;
if (num_roots < LINEAR_SEARCH_THRESHOLD) {
@ -239,7 +239,7 @@ namespace nlsat {
for (; i < num_roots; i++) {
unsigned section_cell_id = cell_id(pinfo, i);
if (section_cell_id == c)
return polynomial::sign_zero;
return sign_zero;
else if (section_cell_id > c)
break;
}
@ -253,7 +253,7 @@ namespace nlsat {
if (c < root_1_cell_id)
return sign(pinfo, 0);
else if (c == root_1_cell_id || c == root_n_cell_id)
return polynomial::sign_zero;
return sign_zero;
else if (c > root_n_cell_id)
return sign(pinfo, num_roots);
int low = 0;
@ -272,7 +272,7 @@ namespace nlsat {
SASSERT(low < mid && mid < high);
unsigned mid_cell_id = cell_id(pinfo, mid);
if (mid_cell_id == c) {
return polynomial::sign_zero;
return sign_zero;
}
if (c < mid_cell_id) {
high = mid;
@ -381,7 +381,7 @@ namespace nlsat {
\pre All variables of p are assigned in the current interpretation.
*/
polynomial::sign eval_sign(poly * p) {
sign eval_sign(poly * p) {
// TODO: check if it is useful to cache results
SASSERT(m_assignment.is_assigned(max_var(p)));
return m_am.eval_sign_at(polynomial_ref(p, m_pm), m_assignment);
@ -449,7 +449,7 @@ namespace nlsat {
return a->is_ineq_atom() ? eval_ineq(to_ineq_atom(a), neg) : eval_root(to_root_atom(a), neg);
}
svector<polynomial::sign> m_add_signs_tmp;
svector<sign> m_add_signs_tmp;
void add(poly * p, var x, sign_table & t) {
SASSERT(m_pm.max_var(p) <= x);
if (m_pm.max_var(p) < x) {
@ -458,7 +458,7 @@ namespace nlsat {
else {
// isolate roots of p
scoped_anum_vector & roots = m_add_roots_tmp;
svector<polynomial::sign> & signs = m_add_signs_tmp;
svector<sign> & signs = m_add_signs_tmp;
roots.reset();
signs.reset();
TRACE("nlsat_evaluator", tout << "x: " << x << " max_var(p): " << m_pm.max_var(p) << "\n";);
@ -470,18 +470,18 @@ namespace nlsat {
}
// Evaluate the sign of p1^e1*...*pn^en (of atom a) in cell c of table t.
polynomial::sign sign_at(ineq_atom * a, sign_table const & t, unsigned c) const {
auto sign = polynomial::sign_pos;
sign sign_at(ineq_atom * a, sign_table const & t, unsigned c) const {
auto sign = sign_pos;
unsigned num_ps = a->size();
for (unsigned i = 0; i < num_ps; i++) {
polynomial::sign curr_sign = t.sign_at(i, c);
::sign curr_sign = t.sign_at(i, c);
TRACE("nlsat_evaluator_bug", tout << "sign of i: " << i << " at cell " << c << "\n";
m_pm.display(tout, a->p(i));
tout << "\nsign: " << curr_sign << "\n";);
if (a->is_even(i) && curr_sign < 0)
curr_sign = polynomial::sign_pos;
curr_sign = sign_pos;
sign = sign * curr_sign;
if (sign == polynomial::sign_zero)
if (is_zero(sign))
break;
}
return sign;

View file

@ -208,7 +208,7 @@ namespace nlsat {
\brief evaluate the given polynomial in the current interpretation.
max_var(p) must be assigned in the current interpretation.
*/
polynomial::sign sign(polynomial_ref const & p) {
::sign sign(polynomial_ref const & p) {
SASSERT(max_var(p) == null_var || m_assignment.is_assigned(max_var(p)));
auto s = m_am.eval_sign_at(p, m_assignment);
TRACE("nlsat_explain", tout << "p: " << p << " var: " << max_var(p) << " sign: " << s << "\n";);
@ -271,7 +271,7 @@ namespace nlsat {
polynomial_ref f(m_pm);
for (unsigned i = 0; i < num_factors; i++) {
f = m_factors.get(i);
if (sign(f) == polynomial::sign_zero) {
if (is_zero(sign(f))) {
m_zero_fs.push_back(m_factors.get(i));
m_is_even.push_back(false);
}
@ -338,7 +338,7 @@ namespace nlsat {
lc = m_pm.coeff(p, x, k, reduct);
TRACE("nlsat_explain", tout << "lc: " << lc << " reduct: " << reduct << "\n";);
if (!is_zero(lc)) {
if (sign(lc) != polynomial::sign_zero)
if (!::is_zero(sign(lc)))
return;
// lc is not the zero polynomial, but it vanished in the current interpretation.
// so we keep searching...
@ -653,7 +653,7 @@ namespace nlsat {
TRACE("nlsat_explain", tout << "done, psc is a constant\n";);
return;
}
if (sign(s) == polynomial::sign_zero) {
if (is_zero(sign(s))) {
TRACE("nlsat_explain", tout << "psc vanished, adding zero assumption\n";);
add_zero_assumption(s);
continue;
@ -1137,8 +1137,8 @@ namespace nlsat {
}
if (is_const(new_factor)) {
TRACE("nlsat_simplify_core", tout << "new factor is const\n";);
polynomial::sign s = sign(new_factor);
if (s == polynomial::sign_zero) {
auto s = sign(new_factor);
if (is_zero(s)) {
bool atom_val = a->get_kind() == atom::EQ;
bool lit_val = l.sign() ? !atom_val : atom_val;
new_lit = lit_val ? true_literal : false_literal;

View file

@ -78,11 +78,11 @@ namespace nlsat {
SASSERT(i.m_upper_open);
}
if (!i.m_lower_inf && !i.m_upper_inf) {
int s = am.compare(i.m_lower, i.m_upper);
auto s = am.compare(i.m_lower, i.m_upper);
TRACE("nlsat_interval", tout << "lower: "; am.display_decimal(tout, i.m_lower); tout << ", upper: "; am.display_decimal(tout, i.m_upper);
tout << "\ns: " << s << "\n";);
SASSERT(s <= 0);
if (s == 0) {
if (::is_zero(s)) {
SASSERT(!i.m_lower_open && !i.m_upper_open);
}
}