mirror of
https://github.com/Z3Prover/z3
synced 2025-08-22 11:07:51 +00:00
adding band
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
45b0be3b37
commit
bbec72f0b3
9 changed files with 55 additions and 45 deletions
|
@ -5,6 +5,7 @@ z3_add_component(polysat
|
|||
core.cpp
|
||||
fixed_bits.cpp
|
||||
forbidden_intervals.cpp
|
||||
op_constraint.cpp
|
||||
ule_constraint.cpp
|
||||
umul_ovfl_constraint.cpp
|
||||
viable.cpp
|
||||
|
|
|
@ -17,6 +17,7 @@ Author:
|
|||
#include "sat/smt/polysat/constraints.h"
|
||||
#include "sat/smt/polysat/ule_constraint.h"
|
||||
#include "sat/smt/polysat/umul_ovfl_constraint.h"
|
||||
#include "sat/smt/polysat/op_constraint.h"
|
||||
|
||||
namespace polysat {
|
||||
|
||||
|
@ -36,6 +37,30 @@ namespace polysat {
|
|||
return signed_constraint(ckind_t::umul_ovfl_t, cnstr);
|
||||
}
|
||||
|
||||
signed_constraint constraints::lshr(pdd const& a, pdd const& b, pdd const& r) {
|
||||
auto* cnstr = alloc(op_constraint, op_constraint::code::lshr_op, a, b, r);
|
||||
c.trail().push(new_obj_trail(cnstr));
|
||||
return signed_constraint(ckind_t::op_t, cnstr);
|
||||
}
|
||||
|
||||
signed_constraint constraints::ashr(pdd const& a, pdd const& b, pdd const& r) {
|
||||
auto* cnstr = alloc(op_constraint, op_constraint::code::ashr_op, a, b, r);
|
||||
c.trail().push(new_obj_trail(cnstr));
|
||||
return signed_constraint(ckind_t::op_t, cnstr);
|
||||
}
|
||||
|
||||
signed_constraint constraints::shl(pdd const& a, pdd const& b, pdd const& r) {
|
||||
auto* cnstr = alloc(op_constraint, op_constraint::code::shl_op, a, b, r);
|
||||
c.trail().push(new_obj_trail(cnstr));
|
||||
return signed_constraint(ckind_t::op_t, cnstr);
|
||||
}
|
||||
|
||||
signed_constraint constraints::band(pdd const& a, pdd const& b, pdd const& r) {
|
||||
auto* cnstr = alloc(op_constraint, op_constraint::code::and_op, a, b, r);
|
||||
c.trail().push(new_obj_trail(cnstr));
|
||||
return signed_constraint(ckind_t::op_t, cnstr);
|
||||
}
|
||||
|
||||
bool signed_constraint::is_eq(pvar& v, rational& val) {
|
||||
if (m_sign)
|
||||
return false;
|
||||
|
@ -64,10 +89,4 @@ namespace polysat {
|
|||
return out << *m_constraint;
|
||||
}
|
||||
|
||||
bool signed_constraint::is_always_true() const {
|
||||
return m_sign ? m_constraint->is_always_false() : m_constraint->is_always_true();
|
||||
}
|
||||
bool signed_constraint::is_always_false() const {
|
||||
return m_sign ? m_constraint->is_always_true() : m_constraint->is_always_false();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,8 +41,6 @@ namespace polysat {
|
|||
virtual std::ostream& display(std::ostream& out) const = 0;
|
||||
virtual lbool eval() const = 0;
|
||||
virtual lbool eval(assignment const& a) const = 0;
|
||||
virtual bool is_always_true() const = 0;
|
||||
virtual bool is_always_false() const = 0;
|
||||
};
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& out, constraint const& c) { return c.display(out); }
|
||||
|
@ -63,9 +61,10 @@ namespace polysat {
|
|||
unsigned_vector const& vars() const { return m_constraint->vars(); }
|
||||
unsigned var(unsigned idx) const { return m_constraint->var(idx); }
|
||||
bool contains_var(pvar v) const { return m_constraint->contains_var(v); }
|
||||
bool is_always_true() const;
|
||||
bool is_always_false() const;
|
||||
bool is_always_true() const { return eval() == l_true; }
|
||||
bool is_always_false() const { return eval() == l_false; }
|
||||
lbool eval(assignment& a) const;
|
||||
lbool eval() const { return m_sign ? ~m_constraint->eval() : m_constraint->eval();}
|
||||
ckind_t op() const { return m_op; }
|
||||
bool is_ule() const { return m_op == ule_t; }
|
||||
bool is_umul_ovfl() const { return m_op == umul_ovfl_t; }
|
||||
|
@ -138,6 +137,10 @@ namespace polysat {
|
|||
signed_constraint umul_ovfl(int p, pdd const& q) { return umul_ovfl(rational(p), q); }
|
||||
signed_constraint umul_ovfl(unsigned p, pdd const& q) { return umul_ovfl(rational(p), q); }
|
||||
|
||||
signed_constraint lshr(pdd const& a, pdd const& b, pdd const& r);
|
||||
signed_constraint ashr(pdd const& a, pdd const& b, pdd const& r);
|
||||
signed_constraint shl(pdd const& a, pdd const& b, pdd const& r);
|
||||
signed_constraint band(pdd const& a, pdd const& b, pdd const& r);
|
||||
|
||||
//signed_constraint even(pdd const& p) { return parity_at_least(p, 1); }
|
||||
//signed_constraint odd(pdd const& p) { return ~even(p); }
|
||||
|
|
|
@ -115,10 +115,10 @@ namespace polysat {
|
|||
signed_constraint bit(pdd const& p, unsigned i) { return m_constraints.bit(p, i); }
|
||||
|
||||
|
||||
void lshr(pdd r, pdd a, pdd b) { NOT_IMPLEMENTED_YET(); throw default_exception("lshr nyi"); }
|
||||
void ashr(pdd r, pdd a, pdd b) { NOT_IMPLEMENTED_YET(); throw default_exception("ashr nyi"); }
|
||||
void shl(pdd r, pdd a, pdd b) { NOT_IMPLEMENTED_YET(); throw default_exception("shlh nyi"); }
|
||||
void band(pdd r, pdd a, pdd b) { NOT_IMPLEMENTED_YET(); throw default_exception("band nyi"); }
|
||||
signed_constraint lshr(pdd const& a, pdd const& b, pdd const& r) { return m_constraints.lshr(a, b, r); }
|
||||
signed_constraint ashr(pdd const& a, pdd const& b, pdd const& r) { return m_constraints.ashr(a, b, r); }
|
||||
signed_constraint shl(pdd const& a, pdd const& b, pdd const& r) { return m_constraints.shl(a, b, r); }
|
||||
signed_constraint band(pdd const& a, pdd const& b, pdd const& r) { return m_constraints.band(a, b, r); }
|
||||
|
||||
pdd bnot(pdd p) { return -p - 1; }
|
||||
|
||||
|
|
|
@ -343,22 +343,4 @@ namespace polysat {
|
|||
return eval(a.apply_to(lhs()), a.apply_to(rhs()));
|
||||
}
|
||||
|
||||
bool ule_constraint::is_always_true() const {
|
||||
if (lhs().is_zero())
|
||||
return true; // 0 <= p
|
||||
if (rhs().is_max())
|
||||
return true; // p <= -1
|
||||
if (lhs().is_val() && rhs().is_val())
|
||||
return lhs().val() <= rhs().val();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ule_constraint::is_always_false() const {
|
||||
if (lhs().is_never_zero() && rhs().is_zero())
|
||||
return true; // p > 0, q = 0
|
||||
if (lhs().is_val() && rhs().is_val())
|
||||
return lhs().val() > rhs().val();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,8 +35,6 @@ namespace polysat {
|
|||
std::ostream& display(std::ostream& out) const override;
|
||||
lbool eval() const override;
|
||||
lbool eval(assignment const& a) const override;
|
||||
bool is_always_true() const override;
|
||||
bool is_always_false() const override;
|
||||
bool is_eq() const { return m_rhs.is_zero(); }
|
||||
unsigned power_of_2() const { return m_lhs.power_of_2(); }
|
||||
|
||||
|
|
|
@ -34,8 +34,6 @@ namespace polysat {
|
|||
std::ostream& display(std::ostream& out) const override;
|
||||
lbool eval() const override;
|
||||
lbool eval(assignment const& a) const override;
|
||||
bool is_always_true() const override { return false; } // todo port
|
||||
bool is_always_false() const override { return false; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue