mirror of
https://github.com/Z3Prover/z3
synced 2025-07-19 10:52:02 +00:00
Encode 2^k*x as (bvshl x k) in the fallback solver
This commit is contained in:
parent
06a999e219
commit
37536425f4
2 changed files with 36 additions and 2 deletions
|
@ -64,7 +64,8 @@ namespace polysat {
|
||||||
return bv->mk_numeral(r, bit_width);
|
return bv->mk_numeral(r, bit_width);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [d,c,b,a] ==> ((a*x + b)*x + c)*x + d
|
#if 0
|
||||||
|
// [d,c,b,a] --> ((a*x + b)*x + c)*x + d
|
||||||
expr* mk_poly(univariate const& p) const {
|
expr* mk_poly(univariate const& p) const {
|
||||||
if (p.empty()) {
|
if (p.empty()) {
|
||||||
return mk_numeral(rational::zero());
|
return mk_numeral(rational::zero());
|
||||||
|
@ -79,6 +80,38 @@ namespace polysat {
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
// TODO: shouldn't the simplification step of the underlying solver already support this transformation? how to enable?
|
||||||
|
// 2^k*x --> x << k
|
||||||
|
// n*x --> n * x
|
||||||
|
expr* mk_poly_term(rational const& coeff, expr* xpow) const {
|
||||||
|
unsigned pow;
|
||||||
|
if (coeff.is_power_of_two(pow))
|
||||||
|
return bv->mk_bv_shl(xpow, mk_numeral(rational(pow)));
|
||||||
|
else
|
||||||
|
return bv->mk_bv_mul(mk_numeral(coeff), xpow);
|
||||||
|
}
|
||||||
|
|
||||||
|
// [d,c,b,a] --> d + c*x + b*(x*x) + a*(x*x*x)
|
||||||
|
expr* mk_poly(univariate const& p) const {
|
||||||
|
if (p.empty()) {
|
||||||
|
return mk_numeral(rational::zero());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
expr* e = mk_numeral(p.back());
|
||||||
|
expr* xpow = x;
|
||||||
|
for (unsigned i = p.size() - 1; i-- > 0; ) {
|
||||||
|
if (!p[i].is_zero()) {
|
||||||
|
expr* t = mk_poly_term(p[i], xpow);
|
||||||
|
e = bv->mk_bv_add(e, t);
|
||||||
|
}
|
||||||
|
if (i)
|
||||||
|
xpow = bv->mk_bv_mul(xpow, x);
|
||||||
|
}
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void add(expr* e, bool sign, dep_t dep) {
|
void add(expr* e, bool sign, dep_t dep) {
|
||||||
if (sign)
|
if (sign)
|
||||||
|
|
|
@ -1661,7 +1661,8 @@ void tst_polysat() {
|
||||||
// test_polysat::test_parity1b();
|
// test_polysat::test_parity1b();
|
||||||
// test_polysat::test_parity2();
|
// test_polysat::test_parity2();
|
||||||
// test_polysat::test_parity3();
|
// test_polysat::test_parity3();
|
||||||
test_polysat::test_parity4();
|
// test_polysat::test_parity4();
|
||||||
|
// test_polysat::test_parity4(32);
|
||||||
test_polysat::test_parity4(256);
|
test_polysat::test_parity4(256);
|
||||||
// test_polysat::test_ineq2();
|
// test_polysat::test_ineq2();
|
||||||
// test_polysat::test_ineq_non_axiom4(32, 3); // stuck in viable refinement loop
|
// test_polysat::test_ineq_non_axiom4(32, 3); // stuck in viable refinement loop
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue