subrange_bound.h
Go to the documentation of this file.
/********************* */
#include "cvc4_public.h"
#ifndef __CVC4__SUBRANGE_BOUND_H
#define __CVC4__SUBRANGE_BOUND_H
#include "util/integer.h"
#include "util/exception.h"
#include <limits>
namespace CVC4 {
class CVC4_PUBLIC SubrangeBound {
bool d_nobound;
Integer d_bound;
public:
SubrangeBound() throw() :
d_nobound(true),
d_bound() {
}
SubrangeBound(const Integer& i) throw() :
d_nobound(false),
d_bound(i) {
}
~SubrangeBound() throw() {
}
const Integer& getBound() const throw(IllegalArgumentException) {
CheckArgument(!d_nobound, this, "SubrangeBound is infinite");
return d_bound;
}
bool hasBound() const throw() {
return !d_nobound;
}
bool operator==(const SubrangeBound& b) const throw() {
return hasBound() == b.hasBound() &&
(!hasBound() || getBound() == b.getBound());
}
bool operator!=(const SubrangeBound& b) const throw() {
return !(*this == b);
}
bool operator<(const SubrangeBound& b) const throw() {
return (!hasBound() && b.hasBound()) || (hasBound() && !b.hasBound()) ||
( hasBound() && b.hasBound() && getBound() < b.getBound() );
}
bool operator<=(const SubrangeBound& b) const throw() {
return !hasBound() || !b.hasBound() ||
( hasBound() && b.hasBound() && getBound() <= b.getBound() );
}
bool operator>(const SubrangeBound& b) const throw() {
return (!hasBound() && b.hasBound()) || (hasBound() && !b.hasBound()) ||
( hasBound() && b.hasBound() && getBound() < b.getBound() );
}
bool operator>=(const SubrangeBound& b) const throw() {
return !hasBound() || !b.hasBound() ||
( hasBound() && b.hasBound() && getBound() <= b.getBound() );
}
static SubrangeBound min(const SubrangeBound& a, const SubrangeBound& b){
if(a.hasBound() && b.hasBound()){
return SubrangeBound(Integer::min(a.getBound(), b.getBound()));
}else{
return SubrangeBound();
}
}
static SubrangeBound max(const SubrangeBound& a, const SubrangeBound& b){
if(a.hasBound() && b.hasBound()){
return SubrangeBound(Integer::max(a.getBound(), b.getBound()));
}else{
return SubrangeBound();
}
}
};/* class SubrangeBound */
class CVC4_PUBLIC SubrangeBounds {
public:
SubrangeBound lower;
SubrangeBound upper;
SubrangeBounds(const SubrangeBound& l, const SubrangeBound& u) :
lower(l),
upper(u) {
CheckArgument(!l.hasBound() || !u.hasBound() ||
l.getBound() <= u.getBound(),
l, "Bad subrange bounds specified");
}
bool operator==(const SubrangeBounds& bounds) const {
return lower == bounds.lower && upper == bounds.upper;
}
bool operator!=(const SubrangeBounds& bounds) const {
return !(*this == bounds);
}
bool operator<(const SubrangeBounds& bounds) const {
return (lower > bounds.lower && upper <= bounds.upper) ||
(lower >= bounds.lower && upper < bounds.upper);
}
bool operator<=(const SubrangeBounds& bounds) const {
return lower >= bounds.lower && upper <= bounds.upper;
}
bool operator>(const SubrangeBounds& bounds) const {
return (lower < bounds.lower && upper >= bounds.upper) ||
(lower <= bounds.lower && upper > bounds.upper);
}
bool operator>=(const SubrangeBounds& bounds) const {
return lower <= bounds.lower && upper >= bounds.upper;
}
static bool joinIsBounded(const SubrangeBounds& a, const SubrangeBounds& b){
return (a.lower.hasBound() && b.lower.hasBound()) ||
(a.upper.hasBound() && b.upper.hasBound());
}
static SubrangeBounds join(const SubrangeBounds& a, const SubrangeBounds& b){
DebugCheckArgument(joinIsBounded(a,b), a);
SubrangeBound newLower = SubrangeBound::min(a.lower, b.lower);
SubrangeBound newUpper = SubrangeBound::max(a.upper, b.upper);
return SubrangeBounds(newLower, newUpper);
}
};/* class SubrangeBounds */
struct CVC4_PUBLIC SubrangeBoundsHashFunction {
inline size_t operator()(const SubrangeBounds& bounds) const {
// We use Integer::hash() rather than Integer::getUnsignedLong()
// because the latter might overflow and throw an exception
size_t l = bounds.lower.hasBound() ? bounds.lower.getBound().hash() : std::numeric_limits<size_t>::max();
size_t u = bounds.upper.hasBound() ? bounds.upper.getBound().hash() : std::numeric_limits<size_t>::max();
return l + 0x9e3779b9 + (u << 6) + (u >> 2);
}
};/* struct SubrangeBoundsHashFunction */
inline std::ostream&
operator<<(std::ostream& out, const SubrangeBound& bound) throw() CVC4_PUBLIC;
inline std::ostream&
operator<<(std::ostream& out, const SubrangeBound& bound) throw() {
if(bound.hasBound()) {
out << bound.getBound();
} else {
out << '_';
}
return out;
}
inline std::ostream&
operator<<(std::ostream& out, const SubrangeBounds& bounds) throw() CVC4_PUBLIC;
inline std::ostream&
operator<<(std::ostream& out, const SubrangeBounds& bounds) throw() {
out << bounds.lower << ".." << bounds.upper;
return out;
}
}/* CVC4 namespace */
#endif /* __CVC4__SUBRANGE_BOUND_H */
CVC4::IllegalArgumentException
Definition exception.h:79
CVC4::Integer
Definition integer_gmp_imp.h:34
CVC4::Integer::hash
size_t hash() const
Computes the hash of the node from the first word of the numerator, the denominator.
Definition integer_cln_imp.h:450
CVC4::SubrangeBound
Representation of a subrange bound.
Definition subrange_bound.h:36
CVC4::SubrangeBound::SubrangeBound
SubrangeBound(const Integer &i)
Construct a finite SubrangeBound.
Definition subrange_bound.h:49
CVC4::SubrangeBound::operator<
bool operator<(const SubrangeBound &b) const
Is this SubrangeBound "less than" another? For two SubrangeBounds that "have bounds,...
Definition subrange_bound.h:87
CVC4::SubrangeBound::operator!=
bool operator!=(const SubrangeBound &b) const
Test two SubrangeBounds for disequality.
Definition subrange_bound.h:75
CVC4::SubrangeBound::operator<=
bool operator<=(const SubrangeBound &b) const
Is this SubrangeBound "less than or equal to" another? For two SubrangeBounds that "have bounds,...
Definition subrange_bound.h:100
CVC4::SubrangeBound::operator>=
bool operator>=(const SubrangeBound &b) const
Is this SubrangeBound "greater than or equal to" another? For two SubrangeBounds that "have bounds,...
Definition subrange_bound.h:126
CVC4::SubrangeBound::hasBound
bool hasBound() const
Returns true iff this is a finite SubrangeBound.
Definition subrange_bound.h:64
CVC4::SubrangeBound::operator==
bool operator==(const SubrangeBound &b) const
Test two SubrangeBounds for equality.
Definition subrange_bound.h:69
CVC4::SubrangeBound::getBound
const Integer & getBound() const
Get the finite SubrangeBound, failing an assertion if infinite.
Definition subrange_bound.h:58
CVC4::SubrangeBound::max
static SubrangeBound max(const SubrangeBound &a, const SubrangeBound &b)
Definition subrange_bound.h:140
CVC4::SubrangeBound::min
static SubrangeBound min(const SubrangeBound &a, const SubrangeBound &b)
Definition subrange_bound.h:132
CVC4::SubrangeBound::operator>
bool operator>(const SubrangeBound &b) const
Is this SubrangeBound "greater than" another? For two SubrangeBounds that "have bounds,...
Definition subrange_bound.h:113
CVC4::SubrangeBound::SubrangeBound
SubrangeBound()
Construct an infinite SubrangeBound.
Definition subrange_bound.h:43
CVC4::SubrangeBound::~SubrangeBound
~SubrangeBound()
Definition subrange_bound.h:54
CVC4::SubrangeBounds
Definition subrange_bound.h:150
CVC4::SubrangeBounds::joinIsBounded
static bool joinIsBounded(const SubrangeBounds &a, const SubrangeBounds &b)
Returns true if the join of two subranges is not (- infinity, + infinity).
Definition subrange_bound.h:213
CVC4::SubrangeBounds::join
static SubrangeBounds join(const SubrangeBounds &a, const SubrangeBounds &b)
Returns the join of two subranges, a and b.
Definition subrange_bound.h:222
CVC4::SubrangeBounds::operator!=
bool operator!=(const SubrangeBounds &bounds) const
Definition subrange_bound.h:168
CVC4::SubrangeBounds::SubrangeBounds
SubrangeBounds(const SubrangeBound &l, const SubrangeBound &u)
Definition subrange_bound.h:156
CVC4::SubrangeBounds::upper
SubrangeBound upper
Definition subrange_bound.h:154
CVC4::SubrangeBounds::operator>=
bool operator>=(const SubrangeBounds &bounds) const
Is this pair of SubrangeBounds "greater than" (does it contain) the given pair of SubrangeBounds?...
Definition subrange_bound.h:206
CVC4::SubrangeBounds::lower
SubrangeBound lower
Definition subrange_bound.h:153
CVC4::SubrangeBounds::operator<
bool operator<(const SubrangeBounds &bounds) const
Is this pair of SubrangeBounds "less than" (contained inside) the given pair of SubrangeBounds?...
Definition subrange_bound.h:177
CVC4::SubrangeBounds::operator==
bool operator==(const SubrangeBounds &bounds) const
Definition subrange_bound.h:164
CVC4::SubrangeBounds::operator<=
bool operator<=(const SubrangeBounds &bounds) const
Is this pair of SubrangeBounds "less than or equal" (contained inside) the given pair of SubrangeBoun...
Definition subrange_bound.h:187
CVC4::SubrangeBounds::operator>
bool operator>(const SubrangeBounds &bounds) const
Is this pair of SubrangeBounds "greater than" (does it contain) the given pair of SubrangeBounds?...
Definition subrange_bound.h:196
cvc4_public.h
Macros that should be defined everywhere during the building of the libraries and driver binary,...
CVC4_PUBLIC
#define CVC4_PUBLIC
Definition cvc4_public.h:30
exception.h
CVC4's exception base class and some associated utilities.
CVC4
Definition expr.h:106
CVC4::DebugCheckArgument
void DebugCheckArgument(bool cond, const T &arg, const char *fmt,...)
Definition exception.h:155
CVC4::operator<<
std::ostream & operator<<(std::ostream &out, const TypeCheckingException &e)
CVC4::CheckArgument
void CheckArgument(bool cond, const T &arg, const char *fmt,...)
Definition exception.h:140
CVC4::SubrangeBoundsHashFunction
Definition subrange_bound.h:231
CVC4::SubrangeBoundsHashFunction::operator()
size_t operator()(const SubrangeBounds &bounds) const
Definition subrange_bound.h:232