mirror of
https://github.com/Z3Prover/z3
synced 2025-08-11 05:30:51 +00:00
Readded variable evaluation as fallback for variable elimination
This commit is contained in:
parent
47cb83f578
commit
c088eb4a26
1 changed files with 68 additions and 47 deletions
|
@ -316,16 +316,32 @@ namespace polysat {
|
||||||
|
|
||||||
bool is_multiple1 = is_multiple(fac_lhs, fac, new_lhs);
|
bool is_multiple1 = is_multiple(fac_lhs, fac, new_lhs);
|
||||||
bool is_multiple2 = is_multiple(fac_rhs, fac, new_rhs);
|
bool is_multiple2 = is_multiple(fac_rhs, fac, new_rhs);
|
||||||
|
bool evaluated = false;
|
||||||
|
substitution sub(m);
|
||||||
|
|
||||||
if (!is_multiple1 || !is_multiple2) {
|
if (!is_multiple1 || !is_multiple2) {
|
||||||
if (!fac.is_val() && !fac.is_var())
|
if (
|
||||||
// TODO: We could introduce a new variable "new_var = lc" and add the valuation for this new variable
|
(!fac.is_val() && !fac.is_var()) ||
|
||||||
continue;
|
(!fac_lhs.is_val() && !fac_lhs.is_var()) ||
|
||||||
if (!fac_lhs.is_val() && !fac_lhs.is_var())
|
(!fac_rhs.is_val() && !fac_rhs.is_var())) {
|
||||||
continue;
|
|
||||||
if (!fac_rhs.is_val() && !fac_rhs.is_var())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
|
// TODO: We could introduce a new variable "new_var = lc" and add the valuation for this new variable
|
||||||
|
pdd const fac_eval = eval(fac, core, sub);
|
||||||
|
LOG("lcs: " << fac_eval);
|
||||||
|
pdd fac_eval_inv = m.zero();
|
||||||
|
if (!inv(fac_eval, fac_eval_inv))
|
||||||
|
return;
|
||||||
|
|
||||||
|
pdd const rest_eval = sub.apply_to(rest);
|
||||||
|
pdd const vs = -rest_eval * fac_eval_inv; // this is the polynomial that computes v
|
||||||
|
LOG("vs: " << vs);
|
||||||
|
SASSERT(!vs.free_vars().contains(v));
|
||||||
|
|
||||||
|
new_lhs = c_target->to_ule().lhs().subst_pdd(v, vs);
|
||||||
|
new_rhs = c_target->to_ule().rhs().subst_pdd(v, vs);
|
||||||
|
evaluated = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
pv_equality = get_dyadic_valuation(fac).first;
|
pv_equality = get_dyadic_valuation(fac).first;
|
||||||
LOG("pv_equality " << pv_equality);
|
LOG("pv_equality " << pv_equality);
|
||||||
coeff_odd = get_odd(fac); // a'
|
coeff_odd = get_odd(fac); // a'
|
||||||
|
@ -335,7 +351,9 @@ namespace polysat {
|
||||||
continue; // factor is for sure not invertible
|
continue; // factor is for sure not invertible
|
||||||
LOG("coeff_odd_inv: " << *fac_odd_inv);
|
LOG("coeff_odd_inv: " << *fac_odd_inv);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!evaluated) {
|
||||||
if (!is_multiple1) { // Sometimes we can simply unify the two equations
|
if (!is_multiple1) { // Sometimes we can simply unify the two equations
|
||||||
pdd pv_lhs = get_dyadic_valuation(fac_lhs).first;
|
pdd pv_lhs = get_dyadic_valuation(fac_lhs).first;
|
||||||
pdd odd_fac_lhs = get_odd(fac_lhs);
|
pdd odd_fac_lhs = get_odd(fac_lhs);
|
||||||
|
@ -363,8 +381,9 @@ namespace polysat {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
new_rhs = -rest * new_rhs + rest_rhs;
|
new_rhs = -rest * new_rhs + rest_rhs;
|
||||||
|
}
|
||||||
|
|
||||||
signed_constraint c_new = s.ule(new_lhs , new_rhs );
|
signed_constraint c_new = s.ule(new_lhs , new_rhs);
|
||||||
|
|
||||||
if (c_target.is_negative())
|
if (c_target.is_negative())
|
||||||
c_new.negate();
|
c_new.negate();
|
||||||
|
@ -381,8 +400,10 @@ namespace polysat {
|
||||||
|
|
||||||
clause_builder cb(s);
|
clause_builder cb(s);
|
||||||
|
|
||||||
/*for (auto [w, wv] : a)
|
if (evaluated) {
|
||||||
cb.push(~s.eq(s.var(w), wv));*/
|
for (auto [w, wv] : sub)
|
||||||
|
cb.insert(~s.eq(s.var(w), wv));
|
||||||
|
}
|
||||||
cb.insert(~c);
|
cb.insert(~c);
|
||||||
cb.insert(~c_target);
|
cb.insert(~c_target);
|
||||||
cb.insert(~p1);
|
cb.insert(~p1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue