Skip to content

Commit 67c4777

Browse files
fix #2548 fix #2530
Signed-off-by: Nikolaj Bjorner <[email protected]>
1 parent 5d9ed5b commit 67c4777

File tree

11 files changed

+251
-126
lines changed

11 files changed

+251
-126
lines changed

src/ast/rewriter/seq_rewriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,7 @@ br_status seq_rewriter::mk_re_opt(expr* a, expr_ref& result) {
19021902
}
19031903

19041904
br_status seq_rewriter::mk_eq_core(expr * l, expr * r, expr_ref & result) {
1905-
TRACE("seq", tout << mk_pp(l, m()) << " = " << mk_pp(r, m()) << "\n";);
1905+
TRACE("seq", tout << mk_bounded_pp(l, m(), 2) << " = " << mk_bounded_pp(r, m(), 2) << "\n";);
19061906
expr_ref_vector lhs(m()), rhs(m()), res(m());
19071907
bool changed = false;
19081908
if (!reduce_eq(l, r, lhs, rhs, changed)) {

src/math/polynomial/polynomial.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,8 @@ namespace polynomial {
410410
proc(out, x);
411411
}
412412
}
413+
out << ")";
413414
}
414-
out << ")";
415415
}
416416

417417
bool is_unit() const { return m_size == 0; }
@@ -1576,12 +1576,20 @@ namespace polynomial {
15761576
display_num_smt2(out, nm, a_i);
15771577
}
15781578
else if (nm.is_one(a_i)) {
1579-
m_i->display(out, proc);
1579+
if (m_i->size() == 1) {
1580+
m_i->display_smt2(out, proc);
1581+
}
1582+
else {
1583+
out << "(* ";
1584+
m_i->display_smt2(out, proc);
1585+
out << ")";
1586+
}
15801587
}
15811588
else {
15821589
out << "(* ";
15831590
display_num_smt2(out, nm, a_i);
1584-
m_i->display(out, proc);
1591+
out << " ";
1592+
m_i->display_smt2(out, proc);
15851593
out << ")";
15861594
}
15871595
}

src/muz/spacer/spacer_arith_generalizers.cpp

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -45,48 +45,7 @@ struct limit_denominator_rewriter_cfg : public default_rewriter_cfg {
4545
}
4646

4747
bool limit_denominator(rational &num) {
48-
rational n, d;
49-
n = numerator(num);
50-
d = denominator(num);
51-
if (d < m_limit) return false;
52-
53-
/*
54-
Iteratively computes approximation using continuous fraction
55-
decomposition
56-
57-
p(-1) = 0, p(0) = 1
58-
p(j) = t(j)*p(j-1) + p(j-2)
59-
60-
q(-1) = 1, q(0) = 0
61-
q(j) = t(j)*q(j-1) + q(j-2)
62-
63-
cf[t1; t2, ..., tr] = p(r) / q(r) for r >= 1
64-
reference: https://www.math.u-bordeaux.fr/~pjaming/M1/exposes/MA2.pdf
65-
*/
66-
67-
rational p0(0), p1(1);
68-
rational q0(1), q1(0);
69-
70-
while (d != rational(0)) {
71-
rational tj(0), rem(0);
72-
rational p2(0), q2(0);
73-
tj = div(n, d);
74-
75-
q2 = tj * q1 + q0;
76-
p2 = tj * p1 + p0;
77-
if (q2 >= m_limit) {
78-
num = p2 / q2;
79-
return true;
80-
}
81-
rem = n - tj * d;
82-
p0 = p1;
83-
p1 = p2;
84-
q0 = q1;
85-
q1 = q2;
86-
n = d;
87-
d = rem;
88-
}
89-
return false;
48+
return rational::limit_denominator(num, m_limit);
9049
}
9150

9251
br_status reduce_app(func_decl *f, unsigned num, expr *const *args,

src/nlsat/nlsat_explain.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,18 +1162,21 @@ namespace nlsat {
11621162
new_lit = m_solver.mk_ineq_literal(new_k, new_factors.size(), new_factors.c_ptr(), new_factors_even.c_ptr());
11631163
if (l.sign())
11641164
new_lit.neg();
1165-
TRACE("nlsat_simplify_core", tout << "simplified literal:\n"; display(tout, new_lit); tout << "\n";);
1165+
TRACE("nlsat_simplify_core", tout << "simplified literal:\n"; display(tout, new_lit); tout << " " << m_solver.value(new_lit) << "\n";);
1166+
11661167
if (max_var(new_lit) < max) {
1167-
// The conflicting core may have redundant literals.
1168-
// We should check whether new_lit is true in the current model, and discard it if that is the case
1169-
VERIFY(m_solver.value(new_lit) != l_undef);
1170-
if (m_solver.value(new_lit) == l_false)
1168+
if (m_solver.value(new_lit) == l_true) {
1169+
new_lit = l;
1170+
}
1171+
else {
11711172
add_literal(new_lit);
1172-
new_lit = true_literal;
1173-
return;
1173+
new_lit = true_literal;
1174+
}
1175+
}
1176+
else {
1177+
new_lit = normalize(new_lit, max);
1178+
TRACE("nlsat_simplify_core", tout << "simplified literal after normalization:\n"; display(tout, new_lit); tout << " " << m_solver.value(new_lit) << "\n";);
11741179
}
1175-
new_lit = normalize(new_lit, max);
1176-
TRACE("nlsat_simplify_core", tout << "simplified literal after normalization:\n"; display(tout, new_lit); tout << "\n";);
11771180
}
11781181
else {
11791182
new_lit = l;
@@ -1333,6 +1336,7 @@ namespace nlsat {
13331336
poly * eq_p = eq->p(0);
13341337
VERIFY(simplify(C, eq_p, max));
13351338
// add equation as an assumption
1339+
TRACE("nlsat_simpilfy_core", display(tout << "adding equality as assumption ", literal(eq->bvar(), true)); tout << "\n";);
13361340
add_literal(literal(eq->bvar(), true));
13371341
}
13381342
}
@@ -1511,7 +1515,7 @@ namespace nlsat {
15111515
result.set(i, ~result[i]);
15121516
}
15131517
DEBUG_CODE(
1514-
TRACE("nlsat", m_solver.display(tout, result.size(), result.c_ptr()); );
1518+
TRACE("nlsat", m_solver.display(tout, result.size(), result.c_ptr()) << "\n"; );
15151519
for (literal l : result) {
15161520
CTRACE("nlsat", l_true != m_solver.value(l), m_solver.display(tout, l) << " " << m_solver.value(l) << "\n";);
15171521
SASSERT(l_true == m_solver.value(l));
@@ -1619,36 +1623,32 @@ namespace nlsat {
16191623
unsigned glb_index = 0, lub_index = 0;
16201624
scoped_anum lub(m_am), glb(m_am), x_val(m_am);
16211625
x_val = m_assignment.value(x);
1626+
bool glb_valid = false, lub_valid = false;
16221627
for (unsigned i = 0; i < ps.size(); ++i) {
16231628
p = ps.get(i);
16241629
scoped_anum_vector & roots = m_roots_tmp;
16251630
roots.reset();
16261631
m_am.isolate_roots(p, undef_var_assignment(m_assignment, x), roots);
1627-
bool glb_valid = false, lub_valid = false;
16281632
for (auto const& r : roots) {
16291633
int s = m_am.compare(x_val, r);
16301634
SASSERT(s != 0);
16311635

16321636
if (s < 0 && (!lub_valid || m_am.lt(r, lub))) {
16331637
lub_index = i;
16341638
m_am.set(lub, r);
1639+
lub_valid = true;
16351640
}
16361641

16371642
if (s > 0 && (!glb_valid || m_am.lt(glb, r))) {
16381643
glb_index = i;
1639-
m_am.set(glb, r);
1644+
m_am.set(glb, r);
1645+
glb_valid = true;
16401646
}
1641-
lub_valid |= s < 0;
1642-
glb_valid |= s > 0;
1643-
}
1644-
if (glb_valid) {
1645-
++num_glb;
1646-
}
1647-
if (lub_valid) {
1648-
++num_lub;
1647+
if (s < 0) ++num_lub;
1648+
if (s > 0) ++num_glb;
16491649
}
16501650
}
1651-
TRACE("nlsat_explain", tout << ps << "\n";);
1651+
TRACE("nlsat_explain", tout << "glb: " << num_glb << " lub: " << num_lub << "\n" << lub_index << "\n" << glb_index << "\n" << ps << "\n";);
16521652

16531653
if (num_lub == 0) {
16541654
project_plus_infinity(x, ps);

src/nlsat/nlsat_params.pyg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ def_module_params('nlsat',
55
params=(max_memory_param(),
66
('lazy', UINT, 0, "how lazy the solver is."),
77
('reorder', BOOL, True, "reorder variables."),
8+
('log_lemmas', BOOL, False, "display lemmas as self-contained SMT formulas"),
89
('simplify_conflicts', BOOL, True, "simplify conflicts using equalities before resolving them in nlsat solver."),
910
('minimize_conflicts', BOOL, False, "minimize conflicts"),
1011
('randomize', BOOL, True, "randomize selection of a witness in nlsat."),

0 commit comments

Comments
 (0)