mirror of
https://github.com/Z3Prover/z3
synced 2025-04-24 17:45:32 +00:00
add sample bdd vector operations
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
af2376e9e4
commit
c7868579c0
4 changed files with 73 additions and 7 deletions
|
@ -972,4 +972,44 @@ namespace dd {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
bdd bdd_manager::mk_eq(bddv const& a, bddv const& b) {
|
||||
bdd eq = mk_true();
|
||||
for (unsigned i = a.size(); i-- > 0; ) {
|
||||
eq &= !(a[i] ^ b[i]);
|
||||
}
|
||||
return eq;
|
||||
}
|
||||
|
||||
bdd bdd_manager::mk_ule(bddv const& a, bddv const& b) {
|
||||
SASSERT(a.size() == b.size());
|
||||
bdd lt = mk_false();
|
||||
bdd eq = mk_true();
|
||||
for (unsigned i = a.size(); i-- > 0; ) {
|
||||
lt |= eq && (!a[i] && b[i]);
|
||||
eq &= !(a[i] ^ b[i]);
|
||||
}
|
||||
return lt || eq;
|
||||
}
|
||||
bdd bdd_manager::mk_uge(bddv const& a, bddv const& b) { return mk_ule(b, a); }
|
||||
bdd bdd_manager::mk_ult(bddv const& a, bddv const& b) { return mk_ule(a, b) && !mk_eq(a, b); }
|
||||
bdd bdd_manager::mk_ugt(bddv const& a, bddv const& b) { return mk_ult(b, a); }
|
||||
#if 0
|
||||
bdd bdd_manager::mk_sle(bddv const& a, bddv const& b);
|
||||
bdd bdd_manager::mk_sge(bddv const& a, bddv const& b) { return mk_sle(b, a); }
|
||||
bdd bdd_manager::mk_slt(bddv const& a, bddv const& b) { return mk_sle(a, b) && !mk_eq(a, b); }
|
||||
bdd bdd_manager::mk_sgt(bddv const& a, bddv const& b) { return mk_slt(b, a); }
|
||||
bdd_manager::bddv bdd_manager::mk_num(rational const& n, unsigned num_bits);
|
||||
bdd_manager::bddv bdd_manager::mk_ones(unsigned num_bits);
|
||||
bdd_manager::bddv bdd_manager::mk_zero(unsigned num_bits);
|
||||
bdd_manager::bddv bdd_manager::mk_var(unsigned num_bits, unsigned const* vars);
|
||||
bdd_manager::bddv bdd_manager::mk_var(unsigned_vector const& vars);
|
||||
bdd_manager::bddv bdd_manager::mk_add(bddv const& a, bddv const& b);
|
||||
bdd_manager::bddv bdd_manager::mk_sub(bddv const& a, bddv const& b);
|
||||
bdd_manager::bddv bdd_manager::mk_mul(bddv const& a, bddv const& b);
|
||||
bdd_manager::bddv bdd_manager::mk_mul(bddv const& a, bool_vector const& b);
|
||||
void bdd_manager::mk_quot_rem(bddv const& a, bddv const& b, bddv& quot, bddv& rem);
|
||||
rational bdd_manager::to_val(bddv const& a);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
|
@ -225,6 +225,30 @@ namespace dd {
|
|||
bdd mk_forall(unsigned v, bdd const& b);
|
||||
bdd mk_ite(bdd const& c, bdd const& t, bdd const& e);
|
||||
|
||||
/* BDD vector operations */
|
||||
typedef vector<bdd> bddv;
|
||||
bdd mk_ule(bddv const& a, bddv const& b);
|
||||
bdd mk_uge(bddv const& a, bddv const& b); // { return mk_ule(b, a); }
|
||||
bdd mk_ult(bddv const& a, bddv const& b); // { return mk_ule(a, b) && !mk_eq(a, b); }
|
||||
bdd mk_ugt(bddv const& a, bddv const& b); // { return mk_ult(b, a); }
|
||||
bdd mk_sle(bddv const& a, bddv const& b);
|
||||
bdd mk_sge(bddv const& a, bddv const& b); // { return mk_sle(b, a); }
|
||||
bdd mk_slt(bddv const& a, bddv const& b); // { return mk_sle(a, b) && !mk_eq(a, b); }
|
||||
bdd mk_sgt(bddv const& a, bddv const& b); // { return mk_slt(b, a); }
|
||||
bdd mk_eq(bddv const& a, bddv const& b);
|
||||
bddv mk_num(rational const& n, unsigned num_bits);
|
||||
bddv mk_ones(unsigned num_bits);
|
||||
bddv mk_zero(unsigned num_bits);
|
||||
bddv mk_var(unsigned num_bits, unsigned const* vars);
|
||||
bddv mk_var(unsigned_vector const& vars);
|
||||
bddv mk_add(bddv const& a, bddv const& b);
|
||||
bddv mk_sub(bddv const& a, bddv const& b);
|
||||
bddv mk_mul(bddv const& a, bddv const& b);
|
||||
bddv mk_mul(bddv const& a, bool_vector const& b);
|
||||
void mk_quot_rem(bddv const& a, bddv const& b, bddv& quot, bddv& rem);
|
||||
rational to_val(bddv const& a);
|
||||
|
||||
|
||||
/** Encodes the lower w bits of val as BDD, using variable indices 0 to w-1.
|
||||
* The least-significant bit is encoded as variable 0.
|
||||
* val must be an integer.
|
||||
|
@ -264,10 +288,10 @@ namespace dd {
|
|||
bool is_true() const { return root == bdd_manager::true_bdd; }
|
||||
bool is_false() const { return root == bdd_manager::false_bdd; }
|
||||
|
||||
bdd operator!() { return m->mk_not(*this); }
|
||||
bdd operator&&(bdd const& other) { return m->mk_and(*this, other); }
|
||||
bdd operator||(bdd const& other) { return m->mk_or(*this, other); }
|
||||
bdd operator^(bdd const& other) { return m->mk_xor(*this, other); }
|
||||
bdd operator!() const { return m->mk_not(*this); }
|
||||
bdd operator&&(bdd const& other) const { return m->mk_and(*this, other); }
|
||||
bdd operator||(bdd const& other) const { return m->mk_or(*this, other); }
|
||||
bdd operator^(bdd const& other) const { return m->mk_xor(*this, other); }
|
||||
bdd operator|=(bdd const& other) { return *this = *this || other; }
|
||||
bdd operator&=(bdd const& other) { return *this = *this && other; }
|
||||
std::ostream& display(std::ostream& out) const { return m->display(out, *this); }
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace polysat {
|
|||
}
|
||||
|
||||
bool bit_constraint::is_currently_false(solver& s) {
|
||||
return m_viable[m_var].is_false();
|
||||
return s.m_viable[m_var].is_false();
|
||||
}
|
||||
|
||||
void bit_constraint::narrow(solver& s) {
|
||||
|
|
|
@ -21,10 +21,12 @@ namespace polysat {
|
|||
case justification_k::unassigned:
|
||||
return out << "unassigned";
|
||||
case justification_k::decision:
|
||||
return out << "decision (level " << level() << ")";
|
||||
return out << "decision @ " << level();
|
||||
case justification_k::propagation:
|
||||
return out << "propagation (level " << level() << ")";
|
||||
return out << "propagation @ " << level();
|
||||
}
|
||||
UNREACHABLE();
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue