mirror of
https://github.com/Z3Prover/z3
synced 2025-06-20 21:03:39 +00:00
hook up pdd_grobner
Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
parent
c6ea5c2263
commit
b9f74db14c
6 changed files with 79 additions and 9 deletions
|
@ -43,7 +43,7 @@ public:
|
||||||
m_dep_intervals.set_interval_for_scalar(k, p.val());
|
m_dep_intervals.set_interval_for_scalar(k, p.val());
|
||||||
return k;
|
return k;
|
||||||
}
|
}
|
||||||
bool deps = (wd == w_dep::with_deps);
|
bool deps = wd == w_dep::with_deps;
|
||||||
interval a = m_var2interval(p.var(), deps);
|
interval a = m_var2interval(p.var(), deps);
|
||||||
interval hi = get_interval<wd>(p.hi());
|
interval hi = get_interval<wd>(p.hi());
|
||||||
interval la = get_interval<wd>(p.lo());
|
interval la = get_interval<wd>(p.lo());
|
||||||
|
|
|
@ -255,12 +255,13 @@ public:
|
||||||
inline bool separated_from_zero(const interval& i) const {
|
inline bool separated_from_zero(const interval& i) const {
|
||||||
return separated_from_zero_on_upper(i) || separated_from_zero_on_lower(i);
|
return separated_from_zero_on_upper(i) || separated_from_zero_on_lower(i);
|
||||||
}
|
}
|
||||||
|
// if the separation happens then call f()
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool check_interval_for_conflict_on_zero(const interval& i, u_dependency*& dep, std::function<void (const T&)> f) {
|
bool check_interval_for_conflict_on_zero(const interval& i, u_dependency* dep, std::function<void (const T&)> f) {
|
||||||
return check_interval_for_conflict_on_zero_lower(i, dep, f) || check_interval_for_conflict_on_zero_upper(i, dep, f);
|
return check_interval_for_conflict_on_zero_lower(i, dep, f) || check_interval_for_conflict_on_zero_upper(i, dep, f);
|
||||||
}
|
}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool check_interval_for_conflict_on_zero_lower(const interval& i, u_dependency*& dep, std::function<void (const T&)> f) {
|
bool check_interval_for_conflict_on_zero_lower(const interval& i, u_dependency* dep, std::function<void (const T&)> f) {
|
||||||
if (!separated_from_zero_on_lower(i)) {
|
if (!separated_from_zero_on_lower(i)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -272,7 +273,7 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool check_interval_for_conflict_on_zero_upper(const interval& i, u_dependency*& dep, std::function<void (const T&)> f) {
|
bool check_interval_for_conflict_on_zero_upper(const interval& i, u_dependency* dep, std::function<void (const T&)> f) {
|
||||||
if (!separated_from_zero_on_upper(i))
|
if (!separated_from_zero_on_upper(i))
|
||||||
return false;
|
return false;
|
||||||
TRACE("dep_intervals", display(tout, i););
|
TRACE("dep_intervals", display(tout, i););
|
||||||
|
|
|
@ -21,6 +21,7 @@ Revision History:
|
||||||
#include "math/lp/factorization_factory_imp.h"
|
#include "math/lp/factorization_factory_imp.h"
|
||||||
#include "math/lp/nex.h"
|
#include "math/lp/nex.h"
|
||||||
#include "math/grobner/pdd_grobner.h"
|
#include "math/grobner/pdd_grobner.h"
|
||||||
|
#include "math/dd/pdd_interval.h"
|
||||||
namespace nla {
|
namespace nla {
|
||||||
|
|
||||||
core::core(lp::lar_solver& s, reslimit & lim) :
|
core::core(lp::lar_solver& s, reslimit & lim) :
|
||||||
|
@ -33,7 +34,7 @@ core::core(lp::lar_solver& s, reslimit & lim) :
|
||||||
m_intervals(this, lim),
|
m_intervals(this, lim),
|
||||||
m_horner(this, &m_intervals),
|
m_horner(this, &m_intervals),
|
||||||
m_nex_grobner(this, &m_intervals),
|
m_nex_grobner(this, &m_intervals),
|
||||||
m_pdd_manager(0),
|
m_pdd_manager(s.number_of_vars()),
|
||||||
m_pdd_grobner(lim, m_pdd_manager),
|
m_pdd_grobner(lim, m_pdd_manager),
|
||||||
m_emons(m_evars),
|
m_emons(m_evars),
|
||||||
m_reslim(lim)
|
m_reslim(lim)
|
||||||
|
@ -1410,8 +1411,15 @@ std::ostream& core::print_term( const lp::lar_term& t, std::ostream& out) const
|
||||||
out);
|
out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void core::create_vars_used_in_mrows() {
|
||||||
|
for (unsigned i : m_rows) {
|
||||||
|
add_row_vars_to_pdd_grobner(m_lar_solver.A_r().m_rows[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void core::run_pdd_grobner() {
|
void core::run_pdd_grobner() {
|
||||||
m_pdd_manager.resize(m_lar_solver.number_of_vars());
|
m_pdd_manager.resize(m_lar_solver.number_of_vars());
|
||||||
|
create_vars_used_in_mrows();
|
||||||
for (unsigned i : m_rows) {
|
for (unsigned i : m_rows) {
|
||||||
add_row_to_pdd_grobner(m_lar_solver.A_r().m_rows[i]);
|
add_row_to_pdd_grobner(m_lar_solver.A_r().m_rows[i]);
|
||||||
}
|
}
|
||||||
|
@ -1422,7 +1430,24 @@ void core::run_pdd_grobner() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void core::check_pdd_eq(const dd::grobner::equation* e) {
|
void core::check_pdd_eq(const dd::grobner::equation* e) {
|
||||||
NOT_IMPLEMENTED_YET();
|
dd::pdd_interval eval(m_pdd_manager, m_reslim);
|
||||||
|
eval.var2interval() =
|
||||||
|
[this](lpvar j, bool deps) {
|
||||||
|
intervals::interval a;
|
||||||
|
if (deps) m_intervals.set_var_interval<dd::w_dep::with_deps>(j, a);
|
||||||
|
else m_intervals.set_var_interval<dd::w_dep::without_deps>(j, a);
|
||||||
|
return a;
|
||||||
|
};
|
||||||
|
auto i = eval.get_interval<dd::w_dep::without_deps>(e->poly());
|
||||||
|
dep_intervals di(m_reslim);
|
||||||
|
if (!di.separated_from_zero(i))
|
||||||
|
return;
|
||||||
|
auto i_wd = eval.get_interval<dd::w_dep::with_deps>(e->poly());
|
||||||
|
std::function<void (const lp::explanation&)> f = [this](const lp::explanation& e) {
|
||||||
|
add_empty_lemma();
|
||||||
|
current_expl().add(e);
|
||||||
|
};
|
||||||
|
di.check_interval_for_conflict_on_zero(i_wd, e->dep(), f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void core::add_var_and_its_factors_to_q_and_collect_new_rows(lpvar j, svector<lpvar> & q) {
|
void core::add_var_and_its_factors_to_q_and_collect_new_rows(lpvar j, svector<lpvar> & q) {
|
||||||
|
@ -1454,8 +1479,47 @@ void core::add_var_and_its_factors_to_q_and_collect_new_rows(lpvar j, svector<lp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void core::add_row_vars_to_pdd_grobner(const vector<lp::row_cell<rational>> & row) {
|
||||||
|
for (const auto &p : row) {
|
||||||
|
lpvar j = p.var();
|
||||||
|
if (!is_monic_var(j)) {
|
||||||
|
m_pdd_manager.mk_var(j);
|
||||||
|
} else {
|
||||||
|
const monic& m = emons()[j];
|
||||||
|
for (lpvar k : m.vars()) {
|
||||||
|
m_pdd_manager.mk_var(k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dd::pdd core::pdd_expr(const rational& c, lpvar j) {
|
||||||
|
if (!is_monic_var(j))
|
||||||
|
return c * m_pdd_manager.mk_var(j);
|
||||||
|
|
||||||
|
// j is a monic var
|
||||||
|
dd::pdd r = m_pdd_manager.mk_val(c);
|
||||||
|
const monic& m = emons()[j];
|
||||||
|
for (lpvar k : m.vars()) {
|
||||||
|
r *= m_pdd_manager.mk_var(k);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
void core::add_row_to_pdd_grobner(const vector<lp::row_cell<rational>> & row) {
|
void core::add_row_to_pdd_grobner(const vector<lp::row_cell<rational>> & row) {
|
||||||
NOT_IMPLEMENTED_YET();
|
u_dependency *dep = nullptr;
|
||||||
|
dd::pdd sum = m_pdd_manager.mk_val(rational(0));
|
||||||
|
for (const auto &p : row) {
|
||||||
|
dd::pdd e = pdd_expr(p.coeff(), p.var());
|
||||||
|
sum += e;
|
||||||
|
unsigned lc, uc;
|
||||||
|
m_lar_solver.get_bound_constraint_witnesses_for_column(p.var(), lc, uc);
|
||||||
|
if (lc != null_lpvar)
|
||||||
|
dep = m_intervals.mk_join(dep, m_intervals.mk_leaf(lc));
|
||||||
|
if (uc != null_lpvar)
|
||||||
|
dep = m_intervals.mk_join(dep, m_intervals.mk_leaf(uc));
|
||||||
|
}
|
||||||
|
m_pdd_grobner.add(sum, dep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ typedef lp::lconstraint_kind llc;
|
||||||
typedef lp::constraint_index lpci;
|
typedef lp::constraint_index lpci;
|
||||||
typedef lp::explanation expl_set;
|
typedef lp::explanation expl_set;
|
||||||
typedef lp::var_index lpvar;
|
typedef lp::var_index lpvar;
|
||||||
|
const lpvar null_lpvar = UINT_MAX;
|
||||||
|
|
||||||
inline int rat_sign(const rational& r) { return r.is_pos()? 1 : ( r.is_neg()? -1 : 0); }
|
inline int rat_sign(const rational& r) { return r.is_pos()? 1 : ( r.is_neg()? -1 : 0); }
|
||||||
inline rational rrat_sign(const rational& r) { return rational(rat_sign(r)); }
|
inline rational rrat_sign(const rational& r) { return rational(rat_sign(r)); }
|
||||||
|
@ -122,7 +123,7 @@ public:
|
||||||
m_active_var_set.resize(m_lar_solver.number_of_vars());
|
m_active_var_set.resize(m_lar_solver.number_of_vars());
|
||||||
}
|
}
|
||||||
|
|
||||||
reslimit & reslim() { return m_reslim; }
|
reslimit& reslim() { return m_reslim; }
|
||||||
emonics& emons() { return m_emons; }
|
emonics& emons() { return m_emons; }
|
||||||
const emonics& emons() const { return m_emons; }
|
const emonics& emons() const { return m_emons; }
|
||||||
// constructor
|
// constructor
|
||||||
|
@ -401,6 +402,9 @@ public:
|
||||||
var_weight get_var_weight(lpvar) const;
|
var_weight get_var_weight(lpvar) const;
|
||||||
void add_row_to_pdd_grobner(const vector<lp::row_cell<rational>> & row);
|
void add_row_to_pdd_grobner(const vector<lp::row_cell<rational>> & row);
|
||||||
void check_pdd_eq(const dd::grobner::equation*);
|
void check_pdd_eq(const dd::grobner::equation*);
|
||||||
|
void create_vars_used_in_mrows();
|
||||||
|
void add_row_vars_to_pdd_grobner(const vector<lp::row_cell<rational>> & row);
|
||||||
|
dd::pdd pdd_expr(const rational& c, lpvar j);
|
||||||
}; // end of core
|
}; // end of core
|
||||||
|
|
||||||
struct pp_mon {
|
struct pp_mon {
|
||||||
|
|
|
@ -119,7 +119,7 @@ private:
|
||||||
equation_set m_to_superpose;
|
equation_set m_to_superpose;
|
||||||
equation_set m_to_simplify;
|
equation_set m_to_simplify;
|
||||||
region m_alloc;
|
region m_alloc;
|
||||||
mutable u_dependency_manager m_dep_manager;
|
mutable u_dependency_manager m_dep_manager;
|
||||||
nex_lt m_lt;
|
nex_lt m_lt;
|
||||||
bool m_changed_leading_term;
|
bool m_changed_leading_term;
|
||||||
params m_params;
|
params m_params;
|
||||||
|
|
|
@ -46,6 +46,7 @@ public:
|
||||||
m_dep_intervals(lim),
|
m_dep_intervals(lim),
|
||||||
m_core(c)
|
m_core(c)
|
||||||
{}
|
{}
|
||||||
|
dep_intervals& get_dep_intervals() { return m_dep_intervals; }
|
||||||
u_dependency* mk_join(u_dependency* a, u_dependency* b) { return m_dep_intervals.mk_join(a, b); }
|
u_dependency* mk_join(u_dependency* a, u_dependency* b) { return m_dep_intervals.mk_join(a, b); }
|
||||||
u_dependency* mk_leaf(lp::constraint_index ci) { return m_dep_intervals.mk_leaf(ci); }
|
u_dependency* mk_leaf(lp::constraint_index ci) { return m_dep_intervals.mk_leaf(ci); }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue