mirror of
https://github.com/Z3Prover/z3
synced 2025-04-15 13:28:47 +00:00
try the lemma scheme
This commit is contained in:
parent
e31cecf5db
commit
f423642e9b
|
@ -1844,7 +1844,7 @@ bool core::is_linear(const svector<lpvar>& m, lpvar& zero_var, lpvar& non_fixed)
|
||||||
zero_var = non_fixed = null_lpvar;
|
zero_var = non_fixed = null_lpvar;
|
||||||
unsigned n_of_non_fixed = 0;
|
unsigned n_of_non_fixed = 0;
|
||||||
for (lpvar v : m) {
|
for (lpvar v : m) {
|
||||||
if (!this->var_is_fixed(v)) {
|
if (!var_is_fixed(v)) {
|
||||||
n_of_non_fixed++;
|
n_of_non_fixed++;
|
||||||
non_fixed = v;
|
non_fixed = v;
|
||||||
continue;
|
continue;
|
||||||
|
@ -1920,88 +1920,34 @@ bool core::lower_bound_is_available(unsigned j) const
|
||||||
void core::propagate_monic_with_non_fixed(lpvar monic_var, const svector<lpvar>& vars, lpvar non_fixed, const rational& k)
|
void core::propagate_monic_with_non_fixed(lpvar monic_var, const svector<lpvar>& vars, lpvar non_fixed, const rational& k)
|
||||||
{
|
{
|
||||||
lp::impq bound_value;
|
lp::impq bound_value;
|
||||||
bool is_strict;
|
new_lemma lemma(*this, "propagate monic with non fixed");
|
||||||
auto& lps = lra;
|
// using += to not assert thath the inequality does not hold
|
||||||
|
lemma += ineq(term(rational(1), monic_var, -k, non_fixed), llc::EQ, 0);
|
||||||
if (lower_bound_is_available(non_fixed)) {
|
lp::explanation exp;
|
||||||
bound_value = lra.column_lower_bound(non_fixed);
|
for (auto v : m_emons[monic_var].vars()) {
|
||||||
is_strict = !bound_value.y.is_zero();
|
if (v == non_fixed) continue;
|
||||||
auto lambda = [vars, non_fixed, &lps]() {
|
u_dependency* dep = lra.get_column_lower_bound_witness(v);
|
||||||
u_dependency* dep = lps.get_column_lower_bound_witness(non_fixed);
|
for (auto ci : lra.flatten(dep)) {
|
||||||
for (auto v : vars)
|
exp.push_back(ci);
|
||||||
if (v != non_fixed)
|
|
||||||
dep = lps.join_deps(dep, lps.get_bound_constraint_witnesses_for_column(v));
|
|
||||||
return dep;
|
|
||||||
};
|
|
||||||
if (k.is_pos())
|
|
||||||
add_lower_bound_monic(monic_var, k * bound_value.x, is_strict, lambda);
|
|
||||||
else
|
|
||||||
add_upper_bound_monic(monic_var, k * bound_value.x, is_strict, lambda);
|
|
||||||
}
|
}
|
||||||
|
dep = lra.get_column_upper_bound_witness(v);
|
||||||
if (upper_bound_is_available(non_fixed)) {
|
for (auto ci : lra.flatten(dep)) {
|
||||||
bound_value = lra.column_upper_bound(non_fixed);
|
exp.push_back(ci);
|
||||||
is_strict = !bound_value.y.is_zero();
|
|
||||||
auto lambda = [vars, non_fixed, &lps]() {
|
|
||||||
u_dependency* dep = lps.get_column_upper_bound_witness(non_fixed);
|
|
||||||
for (auto v : vars)
|
|
||||||
if (v != non_fixed)
|
|
||||||
dep = lps.join_deps(dep, lps.get_bound_constraint_witnesses_for_column(v));
|
|
||||||
return dep;
|
|
||||||
};
|
|
||||||
if (k.is_neg())
|
|
||||||
add_lower_bound_monic(monic_var, k * bound_value.x, is_strict, lambda);
|
|
||||||
else
|
|
||||||
add_upper_bound_monic(monic_var, k * bound_value.x, is_strict, lambda);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lower_bound_is_available(monic_var)) {
|
|
||||||
auto lambda = [vars, monic_var, non_fixed, &lps]() {
|
|
||||||
u_dependency* dep = lps.get_column_lower_bound_witness(monic_var);
|
|
||||||
for (auto v : vars) {
|
|
||||||
if (v != non_fixed) {
|
|
||||||
dep = lps.join_deps(dep, lps.get_bound_constraint_witnesses_for_column(v));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dep;
|
lemma &= exp;
|
||||||
};
|
|
||||||
bound_value = lra.column_lower_bound(monic_var);
|
|
||||||
is_strict = !bound_value.y.is_zero();
|
|
||||||
if (k.is_pos())
|
|
||||||
add_lower_bound_monic(non_fixed, bound_value.x / k, is_strict, lambda);
|
|
||||||
else
|
|
||||||
add_upper_bound_monic(non_fixed, bound_value.x / k, is_strict, lambda);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (upper_bound_is_available(monic_var)) {
|
|
||||||
bound_value = lra.column_upper_bound(monic_var);
|
|
||||||
is_strict = !bound_value.y.is_zero();
|
|
||||||
auto lambda = [vars, monic_var, non_fixed, &lps]() {
|
|
||||||
u_dependency* dep = lps.get_column_upper_bound_witness(monic_var);
|
|
||||||
for (auto v : vars) {
|
|
||||||
if (v != non_fixed) {
|
|
||||||
dep = lps.join_deps(dep, lps.get_bound_constraint_witnesses_for_column(v));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dep;
|
|
||||||
};
|
|
||||||
if (k.is_neg())
|
|
||||||
add_lower_bound_monic(non_fixed, bound_value.x / k, is_strict, lambda);
|
|
||||||
else
|
|
||||||
add_upper_bound_monic(non_fixed, bound_value.x / k, is_strict, lambda);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void core::propagate_monic_with_all_fixed(lpvar monic_var, const svector<lpvar>& vars, const rational& k)
|
void core::propagate_monic_with_all_fixed(lpvar monic_var, const svector<lpvar>& vars, const rational& k)
|
||||||
{
|
{
|
||||||
auto* lps = &lra;
|
auto* lps = &lra;
|
||||||
auto lambda = [vars, lps]() { return lps->get_bound_constraint_witnesses_for_columns(vars); };
|
auto lambda = [vars, lps]() { return lps->get_bound_constraint_witnesses_for_columns(vars); };
|
||||||
add_lower_bound_monic(monic_var, k, false, lambda);
|
add_lower_bound_monic(monic_var, k, false, lambda);
|
||||||
add_upper_bound_monic(monic_var, k, false, lambda);
|
add_upper_bound_monic(monic_var, k, false, lambda);
|
||||||
}
|
}
|
||||||
|
|
||||||
void core::add_bounds_for_zero_var(lpvar monic_var, lpvar zero_var)
|
void core::add_bounds_for_zero_var(lpvar monic_var, lpvar zero_var)
|
||||||
{
|
{
|
||||||
auto* lps = &lra;
|
auto* lps = &lra;
|
||||||
auto lambda = [zero_var, lps]() {
|
auto lambda = [zero_var, lps]() {
|
||||||
return lps->get_bound_constraint_witnesses_for_column(zero_var);
|
return lps->get_bound_constraint_witnesses_for_column(zero_var);
|
||||||
|
@ -2009,10 +1955,10 @@ void core::add_bounds_for_zero_var(lpvar monic_var, lpvar zero_var)
|
||||||
TRACE("add_bound", lra.print_column_info(zero_var, tout) << std::endl;);
|
TRACE("add_bound", lra.print_column_info(zero_var, tout) << std::endl;);
|
||||||
add_lower_bound_monic(monic_var, lp::mpq(0), false, lambda);
|
add_lower_bound_monic(monic_var, lp::mpq(0), false, lambda);
|
||||||
add_upper_bound_monic(monic_var, lp::mpq(0), false, lambda);
|
add_upper_bound_monic(monic_var, lp::mpq(0), false, lambda);
|
||||||
}
|
}
|
||||||
|
|
||||||
void core::calculate_implied_bounds_for_monic(lp::lpvar monic_var)
|
void core::calculate_implied_bounds_for_monic(lp::lpvar monic_var)
|
||||||
{
|
{
|
||||||
lpvar non_fixed, zero_var;
|
lpvar non_fixed, zero_var;
|
||||||
const auto& vars = m_emons[monic_var].vars();
|
const auto& vars = m_emons[monic_var].vars();
|
||||||
if (!is_linear(vars, zero_var, non_fixed))
|
if (!is_linear(vars, zero_var, non_fixed))
|
||||||
|
@ -2033,16 +1979,16 @@ void core::calculate_implied_bounds_for_monic(lp::lpvar monic_var)
|
||||||
else // all variables are fixed
|
else // all variables are fixed
|
||||||
propagate_monic_with_all_fixed(monic_var, vars, k);
|
propagate_monic_with_all_fixed(monic_var, vars, k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void core::init_bound_propagation()
|
void core::init_bound_propagation(vector<lemma> & l_vec)
|
||||||
{
|
{
|
||||||
this->m_implied_bounds.clear();
|
m_implied_bounds.clear();
|
||||||
this->m_improved_lower_bounds.reset();
|
m_improved_lower_bounds.reset();
|
||||||
this->m_improved_upper_bounds.reset();
|
m_improved_upper_bounds.reset();
|
||||||
this->m_column_types = &lra.get_column_types();
|
m_column_types = &lra.get_column_types();
|
||||||
}
|
m_lemma_vec = &l_vec;
|
||||||
|
m_lemma_vec->clear();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace nla
|
} // namespace nla
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -451,7 +451,7 @@ private:
|
||||||
void save_tableau();
|
void save_tableau();
|
||||||
bool integrality_holds();
|
bool integrality_holds();
|
||||||
void calculate_implied_bounds_for_monic(lp::lpvar v);
|
void calculate_implied_bounds_for_monic(lp::lpvar v);
|
||||||
void init_bound_propagation();
|
void init_bound_propagation(vector<lemma>&);
|
||||||
}; // end of core
|
}; // end of core
|
||||||
|
|
||||||
struct pp_mon {
|
struct pp_mon {
|
||||||
|
|
|
@ -100,8 +100,8 @@ namespace nla {
|
||||||
m_core->check_bounded_divisions(lemmas);
|
m_core->check_bounded_divisions(lemmas);
|
||||||
}
|
}
|
||||||
|
|
||||||
void solver::init_bound_propagation() {
|
void solver::init_bound_propagation(vector<lemma>& lemmas) {
|
||||||
m_core->init_bound_propagation();
|
m_core->init_bound_propagation(lemmas);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,6 @@ namespace nla {
|
||||||
nlsat::anum const& am_value(lp::var_index v) const;
|
nlsat::anum const& am_value(lp::var_index v) const;
|
||||||
void collect_statistics(::statistics & st);
|
void collect_statistics(::statistics & st);
|
||||||
void calculate_implied_bounds_for_monic(lp::lpvar v);
|
void calculate_implied_bounds_for_monic(lp::lpvar v);
|
||||||
void init_bound_propagation();
|
void init_bound_propagation(vector<lemma>&);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -2199,11 +2199,14 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void propagate_bounds_for_touched_monomials() {
|
void propagate_bounds_for_touched_monomials() {
|
||||||
m_nla->init_bound_propagation();
|
m_nla->init_bound_propagation(m_nla_lemma_vector);
|
||||||
for (unsigned v : m_nla->monics_with_changed_bounds()) {
|
for (unsigned v : m_nla->monics_with_changed_bounds()) {
|
||||||
m_nla->calculate_implied_bounds_for_monic(v);
|
m_nla->calculate_implied_bounds_for_monic(v);
|
||||||
}
|
}
|
||||||
m_nla->reset_monics_with_changed_bounds();
|
m_nla->reset_monics_with_changed_bounds();
|
||||||
|
for (const auto & l:m_nla_lemma_vector) {
|
||||||
|
false_case_of_check_nla(l);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void propagate_bounds_with_nlp() {
|
void propagate_bounds_with_nlp() {
|
||||||
|
|
Loading…
Reference in a new issue