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

integrating Nikolaj's changes

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
Lev Nachmanson 2018-11-01 11:36:04 -07:00
parent 7a5666f1df
commit c1e0c79a69
3 changed files with 44 additions and 9 deletions

View file

@ -1568,7 +1568,8 @@ public:
} }
enode* n2 = get_enode(other); enode* n2 = get_enode(other);
if (n1->get_root() != n2->get_root()) { if (n1->get_root() != n2->get_root()) {
TRACE("arith", tout << enode_eq_pp(enode_pair(n1, n2), ctx()); TRACE("arith", tout << mk_pp(n1->get_owner(), m) << " = " << mk_pp(n2->get_owner(), m) << "\n";
tout << mk_pp(n1->get_owner(), m) << " = " << mk_pp(n2->get_owner(), m) << "\n";
tout << "v" << v << " = " << "v" << other << "\n";); tout << "v" << v << " = " << "v" << other << "\n";);
m_assume_eq_candidates.push_back(std::make_pair(v, other)); m_assume_eq_candidates.push_back(std::make_pair(v, other));
result = true; result = true;
@ -2073,6 +2074,32 @@ public:
nla::lemma m_lemma; nla::lemma m_lemma;
lp::lar_term mk_term(nla::polynomial const& poly) {
lp::lar_term term;
for (auto const& mon : poly) {
SASSERT(!mon.empty());
if (mon.size() == 1) {
term.add_coeff_var(mon.get_coeff(), mon[0]);
}
else {
// create the expression corresponding to the product.
// internalize it.
// extract the theory var representing the product.
// convert the theory var back to lp::var_index
expr_ref_vector mul(m);
for (lp::var_index v : mon) {
theory_var w = m_var_index2theory_var[v];
mul.push_back(get_enode(w)->get_owner());
}
app_ref t(a.mk_mul(mul.size(), mul.c_ptr()), m);
VERIFY(internalize_term(t));
theory_var w = ctx().get_enode(t)->get_th_var(get_id());
term.add_coeff_var(mon.get_coeff(), m_theory_var2var_index[w]);
}
}
return term;
}
lbool check_aftermath_nla(lbool r) { lbool check_aftermath_nla(lbool r) {
switch (r) { switch (r) {
case l_false: { case l_false: {
@ -2091,6 +2118,8 @@ public:
} }
TRACE("arith", tout << "is_lower: " << is_lower << " pos " << pos << "\n";); TRACE("arith", tout << "is_lower: " << is_lower << " pos " << pos << "\n";);
app_ref atom(m); app_ref atom(m);
// TBD utility: lp::lar_term term = mk_term(ineq.m_poly);
// then term is used instead of ineq.m_term
if (is_eq) { if (is_eq) {
atom = mk_eq(ineq.m_term, ineq.m_rs); atom = mk_eq(ineq.m_term, ineq.m_rs);
} }
@ -3081,15 +3110,15 @@ public:
get_id(), ctx().get_region(), m_core.size(), m_core.c_ptr(), m_eqs.size(), m_eqs.c_ptr(), x, y, 0, nullptr)); get_id(), ctx().get_region(), m_core.size(), m_core.c_ptr(), m_eqs.size(), m_eqs.c_ptr(), x, y, 0, nullptr));
TRACE("arith", TRACE("arith",
for (literal c : m_core) { for (unsigned i = 0; i < m_core.size(); ++i) {
ctx().display_detailed_literal(tout, c); ctx().display_detailed_literal(tout, m_core[i]);
tout << "\n"; tout << "\n";
} }
for (enode_pair const& p : m_eqs) { for (unsigned i = 0; i < m_eqs.size(); ++i) {
tout << enode_eq_pp(p, ctx()); tout << mk_pp(m_eqs[i].first->get_owner(), m) << " = " << mk_pp(m_eqs[i].second->get_owner(), m) << "\n";
} }
tout << " ==> "; tout << " ==> ";
tout << enode_pp(x, ctx()) << " = " << enode_pp(y, ctx()) << "\n"; tout << mk_pp(x->get_owner(), m) << " = " << mk_pp(y->get_owner(), m) << "\n";
); );
// parameters are TBD. // parameters are TBD.
@ -3675,7 +3704,8 @@ public:
break; break;
} }
case equality_source: case equality_source:
out << enode_eq_pp(m_equalities[idx], ctx()); out << mk_pp(m_equalities[idx].first->get_owner(), m) << " = "
<< mk_pp(m_equalities[idx].second->get_owner(), m) << "\n";
break; break;
case definition_source: { case definition_source: {
theory_var v = m_definitions[idx]; theory_var v = m_definitions[idx];

View file

@ -16,6 +16,7 @@ namespace nla {
// fields // fields
lp::var_index m_v; lp::var_index m_v;
svector<lp::var_index> m_vs; svector<lp::var_index> m_vs;
rational m_coeff;
public: public:
// constructors // constructors
monomial(lp::var_index v, unsigned sz, lp::var_index const* vs): monomial(lp::var_index v, unsigned sz, lp::var_index const* vs):
@ -30,6 +31,8 @@ namespace nla {
svector<lp::var_index>::const_iterator begin() const { return m_vs.begin(); } svector<lp::var_index>::const_iterator begin() const { return m_vs.begin(); }
svector<lp::var_index>::const_iterator end() const { return m_vs.end(); } svector<lp::var_index>::const_iterator end() const { return m_vs.end(); }
const svector<lp::var_index> vars() const { return m_vs; } const svector<lp::var_index> vars() const { return m_vs; }
bool empty() const { return m_vs.empty(); }
const rational& get_coeff() const { return m_coeff; }
}; };
typedef std::unordered_map<lp::var_index, rational> variable_map_type; typedef std::unordered_map<lp::var_index, rational> variable_map_type;
@ -56,7 +59,7 @@ namespace nla {
monomial(v, vs), monomial(v, vs),
m_coeff(coeff) {} m_coeff(coeff) {}
rational const& coeff() const { return m_coeff; } rational const& coeff() const { return m_coeff; }
}; };
} }

View file

@ -24,6 +24,8 @@ Revision History:
#include "util/params.h" #include "util/params.h"
#include "nlsat/nlsat_solver.h" #include "nlsat/nlsat_solver.h"
#include "util/lp/lar_solver.h" #include "util/lp/lar_solver.h"
#include "util/lp/monomial.h"
namespace nla { namespace nla {
struct ineq { struct ineq {
lp::lconstraint_kind m_cmp; lp::lconstraint_kind m_cmp;
@ -36,7 +38,7 @@ struct ineq {
}; };
typedef vector<ineq> lemma; typedef vector<ineq> lemma;
typedef vector<monomial> polynomial;
// nonlinear integer incremental linear solver // nonlinear integer incremental linear solver
class solver { class solver {
struct imp; struct imp;