33#ifndef Z3_EXAMPLE_IntervalValue_H
34#define Z3_EXAMPLE_IntervalValue_H
222 assert(!this->
isBottom() &&
"bottom interval does not have lower bound");
229 assert(!this->
isBottom() &&
"bottom interval does not have upper bound");
381 else if (
other.isBottom())
411 assert(
false &&
"not implemented");
429 else if (
other.isBottom())
444 this->_lb =
other._lb;
445 this->_ub =
other._ub;
447 else if (
other.isBottom())
483 if (!(max(this->_lb,
other.lb()).leq(min(this->_ub,
other.ub()))))
497 return this->_lb.
leq(
n) && this->_ub.
geq(
n);
508 o <<
"[" << this->_lb <<
", " << this->_ub <<
"]";
550 if (
lhs.isBottom() ||
rhs.isBottom())
554 else if (
lhs.isTop() ||
rhs.isTop())
568 if (
lhs.isBottom() ||
rhs.isBottom())
572 else if (
lhs.isTop() ||
rhs.isTop())
586 if (
lhs.isBottom() ||
rhs.isBottom())
606 if (
lhs.isBottom() ||
rhs.isBottom())
610 else if (
rhs.contains(0))
619 else if (
lhs.contains(0))
648 if (
lhs.isBottom() ||
rhs.isBottom())
652 else if (
rhs.contains(0))
656 else if (
lhs.is_numeral() &&
rhs.is_numeral())
666 if (
lhs.lb().getNumeral() < 0)
668 if (
lhs.ub().getNumeral() > 0)
688 if (
lhs.isBottom() ||
rhs.isBottom())
693 else if (
lhs.isTop() ||
rhs.isTop())
700 if (
lhs.is_numeral() &&
rhs.is_numeral())
711 if (!
lhs.lb().leq(
rhs.ub()))
719 else if (
lhs.ub().leq(
rhs.lb()))
739 if (
lhs.isBottom() ||
rhs.isBottom())
744 else if (
lhs.isTop() ||
rhs.isTop())
751 if (
lhs.is_numeral() &&
rhs.is_numeral())
762 if (!
lhs.ub().geq(
rhs.lb()))
770 else if (
lhs.lb().geq(
rhs.ub()))
791 if (
lhs.isBottom() ||
rhs.isBottom())
796 else if (
lhs.isTop() ||
rhs.isTop())
803 if (
lhs.is_numeral() &&
rhs.is_numeral())
812 if (
lhs.lb().geq(
rhs.ub()))
821 else if (!
lhs.ub().geq(
rhs.lb()))
841 if (
lhs.isBottom() ||
rhs.isBottom())
846 else if (
lhs.isTop() ||
rhs.isTop())
853 if (
lhs.is_numeral() &&
rhs.is_numeral())
862 if (
lhs.ub().leq(
rhs.lb()))
871 else if (!
lhs.lb().leq(
rhs.ub()))
891 if (
lhs.isBottom() ||
rhs.isBottom())
893 if (
lhs.isTop() &&
rhs.isTop())
899 if (
shift.isBottom())
912 if (
shift.ub().is_infinity())
929 if (
lhs.isBottom() ||
rhs.isBottom())
931 else if (
lhs.isTop() &&
rhs.isTop())
937 if (
shift.isBottom())
964 if (
lhs.isBottom() ||
rhs.isBottom())
966 else if (
lhs.is_numeral() &&
rhs.is_numeral())
970 else if (
lhs.lb().getNumeral() >= 0 &&
rhs.lb().getNumeral() >= 0)
974 else if (
lhs.lb().getNumeral() >= 0)
978 else if (
rhs.lb().getNumeral() >= 0)
994 while ((
num >>
i) != 0)
1000 if (
lhs.isBottom() ||
rhs.isBottom())
1002 else if (
lhs.is_numeral() &&
rhs.is_numeral())
1004 else if (
lhs.lb().getNumeral() >= 0 && !
lhs.ub().is_infinity() &&
1005 rhs.lb().getNumeral() >= 0 && !
rhs.ub().is_infinity())
1007 s64_t m = std::max(
lhs.ub().getNumeral(),
rhs.ub().getNumeral());
1023 while ((
num >>
i) != 0)
1029 if (
lhs.isBottom() ||
rhs.isBottom())
1031 else if (
lhs.is_numeral() &&
rhs.is_numeral())
1033 else if (
lhs.lb().getNumeral() >= 0 && !
lhs.ub().is_infinity() &&
1034 rhs.lb().getNumeral() >= 0 && !
rhs.ub().is_infinity())
1036 s64_t m = std::max(
lhs.ub().getNumeral(),
rhs.ub().getNumeral());
A class representing a bounded 64-bit integer.
static BoundedInt plus_infinity()
bool is_minus_infinity() const
s64_t getNumeral() const
Retrieves the numeral value of the BoundedInt object.
bool is_plus_infinity() const
friend BoundedInt max(const BoundedInt &lhs, const BoundedInt &rhs)
s64_t getIntNumeral() const
static BoundedInt minus_infinity()
friend BoundedInt min(const BoundedInt &lhs, const BoundedInt &rhs)
bool geq(const BoundedInt &rhs) const
bool equal(const BoundedInt &rhs) const
bool leq(const BoundedInt &rhs) const
double getRealNumeral() const
virtual const std::string to_string() const
IntervalValue & operator=(const IntervalValue &a)=default
Copy assignment operator.
void meet_with(const IntervalValue &other)
Return a intersected IntervalValue.
IntervalValue operator!=(const IntervalValue &other) const
Equality comparison.
friend IntervalValue operator/(const IntervalValue &lhs, const IntervalValue &rhs)
Divide IntervalValues.
static BoundedInt minus_infinity()
Get minus infinity -inf.
IntervalValue(s64_t n)
Create the IntervalValue [n, n].
bool leq(const IntervalValue &other) const
IntervalValue(u32_t lb, u32_t ub)
bool geq(const IntervalValue &other) const
const BoundedInt & ub() const
Return the upper bound.
IntervalValue(u64_t lb, u64_t ub)
void join_with(const IntervalValue &other)
Current IntervalValue joins with another IntervalValue.
IntervalValue & operator=(IntervalValue &&)=default
Move assignment operator.
IntervalValue operator==(const IntervalValue &other) const
Equality comparison.
friend IntervalValue operator&(const IntervalValue &lhs, const IntervalValue &rhs)
Bitwise AND of IntervalValues.
s64_t getIntNumeral() const
IntervalValue(double lb, double ub)
bool is_numeral() const
Return true if the IntervalValue is a number [num, num].
friend IntervalValue operator>>(const IntervalValue &lhs, const IntervalValue &rhs)
Left binary shift of IntervalValues.
const std::string toString() const
friend IntervalValue operator^(const IntervalValue &lhs, const IntervalValue &rhs)
Bitwise XOR of IntervalValues.
void narrow_with(const IntervalValue &other)
Current IntervalValue narrow with another IntervalValue.
IntervalValue(s64_t lb, s64_t ub)
bool is_infinite() const
Return true if the IntervalValue is infinite IntervalValue.
IntervalValue(BoundedInt n)
void set_to_top()
Set current IntervalValue as top.
friend IntervalValue operator|(const IntervalValue &lhs, const IntervalValue &rhs)
Bitwise OR of IntervalValues.
~IntervalValue()=default
Destructor.
friend IntervalValue operator*(const IntervalValue &lhs, const IntervalValue &rhs)
Multiply IntervalValues.
friend IntervalValue operator<<(const IntervalValue &lhs, const IntervalValue &rhs)
Left binary shift of IntervalValues.
bool is_zero() const
Return true if the IntervalValue is [0, 0].
static IntervalValue bottom()
Create the bottom IntervalValue [+inf, -inf].
double getRealNumeral() const
bool contain(const IntervalValue &other) const
friend IntervalValue operator-(const IntervalValue &lhs, const IntervalValue &rhs)
Subtract IntervalValues.
static BoundedInt plus_infinity()
Get plus infinity +inf.
void widen_with(const IntervalValue &other)
Current IntervalValue widen with another IntervalValue.
IntervalValue(float lb, float ub)
static IntervalValue create(const BoundedInt &lb, const BoundedInt &ub)
bool containedWithin(const IntervalValue &other) const
bool equals(const IntervalValue &other) const
Equality comparison.
IntervalValue(s32_t lb, s32_t ub)
void dump(std::ostream &o) const
void set_to_bottom()
Set current IntervalValue as bottom.
void setValue(const BoundedInt &lb, const BoundedInt &ub)
Set the lower bound.
IntervalValue()
Create default IntervalValue.
IntervalValue(BoundedInt lb, BoundedInt ub)
Create the IntervalValue [lb, ub].
static IntervalValue top()
Create the IntervalValue [-inf, +inf].
s64_t getNumeral() const
Return.
IntervalValue(IntervalValue &&)=default
Move constructor.
friend IntervalValue operator+(const IntervalValue &lhs, const IntervalValue &rhs)
Add IntervalValues.
static bool is_infinite(const BoundedInt &e)
const BoundedInt & lb() const
Return the lower bound.
IntervalValue(const IntervalValue &)=default
Copy constructor.
bool contains(int n) const
Return true if the IntervalValue contains n.
IntervalValue operator>=(const IntervalValue &lhs, const IntervalValue &rhs)
IntervalValue operator<=(const IntervalValue &lhs, const IntervalValue &rhs)
IntervalValue operator/(const IntervalValue &lhs, const IntervalValue &rhs)
Divide IntervalValues.
IntervalValue operator%(const IntervalValue &lhs, const IntervalValue &rhs)
Divide IntervalValues.
IntervalValue operator>>(const IntervalValue &lhs, const IntervalValue &rhs)
Left binary shift of IntervalValues.
IntervalValue operator-(const IntervalValue &lhs, const IntervalValue &rhs)
Subtract IntervalValues.
IntervalValue operator^(const IntervalValue &lhs, const IntervalValue &rhs)
Bitwise XOR of IntervalValues.
IntervalValue operator&(const IntervalValue &lhs, const IntervalValue &rhs)
Bitwise AND of IntervalValues.
llvm::IRBuilder IRBuilder
IntervalValue operator|(const IntervalValue &lhs, const IntervalValue &rhs)
Bitwise OR of IntervalValues.
IntervalValue operator*(const IntervalValue &lhs, const IntervalValue &rhs)
Multiply IntervalValues.
IntervalValue operator+(const IntervalValue &lhs, const IntervalValue &rhs)
Add IntervalValues.
IntervalValue operator<(const IntervalValue &lhs, const IntervalValue &rhs)
IntervalValue operator>(const IntervalValue &lhs, const IntervalValue &rhs)
IntervalValue operator<<(const IntervalValue &lhs, const IntervalValue &rhs)
Left binary shift of IntervalValues.