3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-27 19:05:51 +00:00

Add basic support for not, or, xor, nand, nor via rewriting

This commit is contained in:
Jakob Rath 2022-09-30 12:59:23 +02:00
parent 9b907d709f
commit 5e54cd3e44
4 changed files with 81 additions and 36 deletions

View file

@ -166,6 +166,10 @@ namespace polysat {
return r;
}
pdd solver::bnot(pdd const& p) {
return -p - 1;
}
pdd solver::band(pdd const& p, pdd const& q) {
auto& m = p.manager();
unsigned sz = m.power_of_2();
@ -174,6 +178,28 @@ namespace polysat {
return r;
}
pdd solver::bor(pdd const& p, pdd const& q) {
// From "Hacker's Delight", section 2-2. Addition Combined with Logical Operations;
// found via Int-Blasting paper; see https://doi.org/10.1007/978-3-030-94583-1_24
// TODO: switch to op_constraint once supported
return (p + q) - band(p, q);
}
pdd solver::bxor(pdd const& p, pdd const& q) {
// From "Hacker's Delight", section 2-2. Addition Combined with Logical Operations;
// found via Int-Blasting paper; see https://doi.org/10.1007/978-3-030-94583-1_24
// TODO: switch to op_constraint once supported
return bor(p, q) - band(p, q);
// return (p + q) - 2*band(p, q);
}
pdd solver::bnand(pdd const& p, pdd const& q) {
return bnot(band(p, q));
}
pdd solver::bnor(pdd const& p, pdd const& q) {
return bnot(bor(p, q));
}
void solver::assign_eh(signed_constraint c, dependency dep) {
backjump(base_level());

View file

@ -294,15 +294,40 @@ namespace polysat {
std::tuple<pdd, pdd> quot_rem(pdd const& a, pdd const& b);
/**
* Create expression for the logical right shift of p by q.
*/
* Create expression for the logical right shift of p by q.
*/
pdd lshr(pdd const& p, pdd const& q);
/**
* Create expression for bit-wise and of p by q.
* Create expression for the bit-wise negation of p.
*/
pdd bnot(pdd const& p);
/**
* Create expression for bit-wise and of p, q.
*/
pdd band(pdd const& p, pdd const& q);
/**
* Create expression for bit-wise or of p, q.
*/
pdd bor(pdd const& p, pdd const& q);
/**
* Create expression for bit-wise xor of p, q.
*/
pdd bxor(pdd const& p, pdd const& q);
/**
* Create expression for bit-wise nand of p, q.
*/
pdd bnand(pdd const& p, pdd const& q);
/**
* Create expression for bit-wise nor of p, q.
*/
pdd bnor(pdd const& p, pdd const& q);
/**
* Create polynomial constant.
*/