Skip to content

Commit b9528b1

Browse files
update self-validator to handle root expressions
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
1 parent 548b9d0 commit b9528b1

File tree

1 file changed

+52
-8
lines changed

1 file changed

+52
-8
lines changed

src/nlsat/nlsat_solver.cpp

+52-8
Original file line numberDiff line numberDiff line change
@@ -3073,6 +3073,11 @@ namespace nlsat {
30733073
return out;
30743074
}
30753075

3076+
std::ostream& display_polynomial_smt2(std::ostream & out, poly const* p, display_var_proc const & proc) const {
3077+
m_pm.display_smt2(out, p, proc);
3078+
return out;
3079+
}
3080+
30763081
std::ostream& display_ineq_smt2(std::ostream & out, ineq_atom const & a, display_var_proc const & proc) const {
30773082
switch (a.get_kind()) {
30783083
case atom::LT: out << "(< "; break;
@@ -3087,13 +3092,13 @@ namespace nlsat {
30873092
if (i > 0) out << " ";
30883093
if (a.is_even(i)) {
30893094
out << "(* ";
3090-
m_pm.display_smt2(out, a.p(i), proc);
3095+
display_polynomial_smt2(out, a.p(i), proc);
30913096
out << " ";
3092-
m_pm.display_smt2(out, a.p(i), proc);
3097+
display_polynomial_smt2(out, a.p(i), proc);
30933098
out << ")";
30943099
}
30953100
else {
3096-
m_pm.display_smt2(out, a.p(i), proc);
3101+
display_polynomial_smt2(out, a.p(i), proc);
30973102
}
30983103
}
30993104
if (sz > 1)
@@ -3102,12 +3107,21 @@ namespace nlsat {
31023107
return out;
31033108
}
31043109

3110+
std::ostream& display_poly_root(std::ostream& out, char const* y, root_atom const& a, display_var_proc const& proc) const {
3111+
out << "(exists (("; proc(out,a.x()); out << " Real))\n";
3112+
out << "(and (= " << y << " ";
3113+
proc(out, a.x());
3114+
out << ") (= 0 ";
3115+
display_polynomial_smt2(out, a.p(), proc);
3116+
out << ")))\n";
3117+
return out;
3118+
}
31053119

31063120
std::ostream& display_binary_smt2(std::ostream& out, poly const* p1, char const* rel, poly const* p2, display_var_proc const& proc) const {
31073121
out << "(" << rel << " ";
3108-
m_pm.display_smt2(out, p1, proc);
3122+
display_polynomial_smt2(out, p1, proc);
31093123
out << " ";
3110-
m_pm.display_smt2(out, p2, proc);
3124+
display_polynomial_smt2(out, p2, proc);
31113125
out << ")";
31123126
return out;
31133127
}
@@ -3147,9 +3161,39 @@ namespace nlsat {
31473161

31483162
std::ostream& display_root_smt2(std::ostream& out, root_atom const& a, display_var_proc const& proc) const {
31493163
if (a.i() == 1 && m_pm.degree(a.p(), a.x()) == 1)
3150-
return display_linear_root_smt2(out, a, proc);
3151-
else
3152-
return display_root(out, a, proc);
3164+
return display_linear_root_smt2(out, a, proc);
3165+
#if 1
3166+
out << "(exists (";
3167+
for (unsigned j = 0; j < a.i(); ++j) {
3168+
std::string y = std::string("y") + std::to_string(j);
3169+
out << "(" << y << " Real) ";
3170+
}
3171+
out << ")\n";
3172+
out << "(and\n";
3173+
for (unsigned j = 0; j < a.i(); ++j) {
3174+
std::string y = std::string("y") + std::to_string(j);
3175+
display_poly_root(out, y.c_str(), a, proc);
3176+
}
3177+
for (unsigned j = 0; j + 1 < a.i(); ++j) {
3178+
std::string y1 = std::string("y") + std::to_string(j);
3179+
std::string y2 = std::string("y") + std::to_string(j+1);
3180+
out << "(< " << y1 << " " << y2 << ")\n";
3181+
}
3182+
std::string y0 = "y0";
3183+
std::string yn = "y" + std::to_string(a.i() - 1);
3184+
switch (a.get_kind()) {
3185+
case atom::ROOT_LT: out << "(< "; proc(out, a.x()); out << " " << y0 << ")"; break;
3186+
case atom::ROOT_GT: out << "(> "; proc(out, a.x()); out << " " << yn << ")"; break;
3187+
case atom::ROOT_LE: out << "(<= "; proc(out, a.x()); out << " " << y0 << ")"; break;
3188+
case atom::ROOT_GE: out << "(>= "; proc(out, a.x()); out << " " << yn << ")"; break;
3189+
case atom::ROOT_EQ: out << "(= "; proc(out, a.x()); out << " " << y0 << ")"; NOT_IMPLEMENTED_YET(); break;
3190+
}
3191+
out << "))";
3192+
return out;
3193+
#endif
3194+
3195+
3196+
return display_root(out, a, proc);
31533197
}
31543198

31553199
std::ostream& display_root(std::ostream & out, root_atom const & a, display_var_proc const & proc) const {

0 commit comments

Comments
 (0)