Skip to content

Commit

Permalink
fix #2548 fix #2530
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
  • Loading branch information
NikolajBjorner committed Sep 13, 2019
1 parent 5d9ed5b commit 67c4777
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 126 deletions.
2 changes: 1 addition & 1 deletion src/ast/rewriter/seq_rewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,7 @@ br_status seq_rewriter::mk_re_opt(expr* a, expr_ref& result) {
}

br_status seq_rewriter::mk_eq_core(expr * l, expr * r, expr_ref & result) {
TRACE("seq", tout << mk_pp(l, m()) << " = " << mk_pp(r, m()) << "\n";);
TRACE("seq", tout << mk_bounded_pp(l, m(), 2) << " = " << mk_bounded_pp(r, m(), 2) << "\n";);
expr_ref_vector lhs(m()), rhs(m()), res(m());
bool changed = false;
if (!reduce_eq(l, r, lhs, rhs, changed)) {
Expand Down
14 changes: 11 additions & 3 deletions src/math/polynomial/polynomial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ namespace polynomial {
proc(out, x);
}
}
out << ")";
}
out << ")";
}

bool is_unit() const { return m_size == 0; }
Expand Down Expand Up @@ -1576,12 +1576,20 @@ namespace polynomial {
display_num_smt2(out, nm, a_i);
}
else if (nm.is_one(a_i)) {
m_i->display(out, proc);
if (m_i->size() == 1) {
m_i->display_smt2(out, proc);
}
else {
out << "(* ";
m_i->display_smt2(out, proc);
out << ")";
}
}
else {
out << "(* ";
display_num_smt2(out, nm, a_i);
m_i->display(out, proc);
out << " ";
m_i->display_smt2(out, proc);
out << ")";
}
}
Expand Down
43 changes: 1 addition & 42 deletions src/muz/spacer/spacer_arith_generalizers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,48 +45,7 @@ struct limit_denominator_rewriter_cfg : public default_rewriter_cfg {
}

bool limit_denominator(rational &num) {
rational n, d;
n = numerator(num);
d = denominator(num);
if (d < m_limit) return false;

/*
Iteratively computes approximation using continuous fraction
decomposition

p(-1) = 0, p(0) = 1
p(j) = t(j)*p(j-1) + p(j-2)

q(-1) = 1, q(0) = 0
q(j) = t(j)*q(j-1) + q(j-2)

cf[t1; t2, ..., tr] = p(r) / q(r) for r >= 1
reference: https://www.math.u-bordeaux.fr/~pjaming/M1/exposes/MA2.pdf
*/

rational p0(0), p1(1);
rational q0(1), q1(0);

while (d != rational(0)) {
rational tj(0), rem(0);
rational p2(0), q2(0);
tj = div(n, d);

q2 = tj * q1 + q0;
p2 = tj * p1 + p0;
if (q2 >= m_limit) {
num = p2 / q2;
return true;
}
rem = n - tj * d;
p0 = p1;
p1 = p2;
q0 = q1;
q1 = q2;
n = d;
d = rem;
}
return false;
return rational::limit_denominator(num, m_limit);
}

br_status reduce_app(func_decl *f, unsigned num, expr *const *args,
Expand Down
42 changes: 21 additions & 21 deletions src/nlsat/nlsat_explain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1162,18 +1162,21 @@ namespace nlsat {
new_lit = m_solver.mk_ineq_literal(new_k, new_factors.size(), new_factors.c_ptr(), new_factors_even.c_ptr());
if (l.sign())
new_lit.neg();
TRACE("nlsat_simplify_core", tout << "simplified literal:\n"; display(tout, new_lit); tout << "\n";);
TRACE("nlsat_simplify_core", tout << "simplified literal:\n"; display(tout, new_lit); tout << " " << m_solver.value(new_lit) << "\n";);

if (max_var(new_lit) < max) {
// The conflicting core may have redundant literals.
// We should check whether new_lit is true in the current model, and discard it if that is the case
VERIFY(m_solver.value(new_lit) != l_undef);
if (m_solver.value(new_lit) == l_false)
if (m_solver.value(new_lit) == l_true) {
new_lit = l;
}
else {
add_literal(new_lit);
new_lit = true_literal;
return;
new_lit = true_literal;
}
}
else {
new_lit = normalize(new_lit, max);
TRACE("nlsat_simplify_core", tout << "simplified literal after normalization:\n"; display(tout, new_lit); tout << " " << m_solver.value(new_lit) << "\n";);
}
new_lit = normalize(new_lit, max);
TRACE("nlsat_simplify_core", tout << "simplified literal after normalization:\n"; display(tout, new_lit); tout << "\n";);
}
else {
new_lit = l;
Expand Down Expand Up @@ -1333,6 +1336,7 @@ namespace nlsat {
poly * eq_p = eq->p(0);
VERIFY(simplify(C, eq_p, max));
// add equation as an assumption
TRACE("nlsat_simpilfy_core", display(tout << "adding equality as assumption ", literal(eq->bvar(), true)); tout << "\n";);
add_literal(literal(eq->bvar(), true));
}
}
Expand Down Expand Up @@ -1511,7 +1515,7 @@ namespace nlsat {
result.set(i, ~result[i]);
}
DEBUG_CODE(
TRACE("nlsat", m_solver.display(tout, result.size(), result.c_ptr()); );
TRACE("nlsat", m_solver.display(tout, result.size(), result.c_ptr()) << "\n"; );
for (literal l : result) {
CTRACE("nlsat", l_true != m_solver.value(l), m_solver.display(tout, l) << " " << m_solver.value(l) << "\n";);
SASSERT(l_true == m_solver.value(l));
Expand Down Expand Up @@ -1619,36 +1623,32 @@ namespace nlsat {
unsigned glb_index = 0, lub_index = 0;
scoped_anum lub(m_am), glb(m_am), x_val(m_am);
x_val = m_assignment.value(x);
bool glb_valid = false, lub_valid = false;
for (unsigned i = 0; i < ps.size(); ++i) {
p = ps.get(i);
scoped_anum_vector & roots = m_roots_tmp;
roots.reset();
m_am.isolate_roots(p, undef_var_assignment(m_assignment, x), roots);
bool glb_valid = false, lub_valid = false;
for (auto const& r : roots) {
int s = m_am.compare(x_val, r);
SASSERT(s != 0);

if (s < 0 && (!lub_valid || m_am.lt(r, lub))) {
lub_index = i;
m_am.set(lub, r);
lub_valid = true;
}

if (s > 0 && (!glb_valid || m_am.lt(glb, r))) {
glb_index = i;
m_am.set(glb, r);
m_am.set(glb, r);
glb_valid = true;
}
lub_valid |= s < 0;
glb_valid |= s > 0;
}
if (glb_valid) {
++num_glb;
}
if (lub_valid) {
++num_lub;
if (s < 0) ++num_lub;
if (s > 0) ++num_glb;
}
}
TRACE("nlsat_explain", tout << ps << "\n";);
TRACE("nlsat_explain", tout << "glb: " << num_glb << " lub: " << num_lub << "\n" << lub_index << "\n" << glb_index << "\n" << ps << "\n";);

if (num_lub == 0) {
project_plus_infinity(x, ps);
Expand Down
1 change: 1 addition & 0 deletions src/nlsat/nlsat_params.pyg
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def_module_params('nlsat',
params=(max_memory_param(),
('lazy', UINT, 0, "how lazy the solver is."),
('reorder', BOOL, True, "reorder variables."),
('log_lemmas', BOOL, False, "display lemmas as self-contained SMT formulas"),
('simplify_conflicts', BOOL, True, "simplify conflicts using equalities before resolving them in nlsat solver."),
('minimize_conflicts', BOOL, False, "minimize conflicts"),
('randomize', BOOL, True, "randomize selection of a witness in nlsat."),
Expand Down
Loading

0 comments on commit 67c4777

Please sign in to comment.