cardinality.h
Go to the documentation of this file.
/********************* */
#include "cvc4_public.h"
#ifndef __CVC4__CARDINALITY_H
#define __CVC4__CARDINALITY_H
#include <iostream>
#include <utility>
#include "util/integer.h"
#include "util/exception.h"
namespace CVC4 {
class CVC4_PUBLIC CardinalityBeth {
Integer d_index;
public:
CardinalityBeth(const Integer& beth) : d_index(beth) {
CheckArgument(beth >= 0, beth,
"Beth index must be a nonnegative integer, not %s.",
beth.toString().c_str());
}
const Integer& getNumber() const throw() {
return d_index;
}
};/* class CardinalityBeth */
class CVC4_PUBLIC CardinalityUnknown {
public:
CardinalityUnknown() throw() {}
~CardinalityUnknown() throw() {}
};/* class CardinalityUnknown */
class CVC4_PUBLIC Cardinality {
static const Integer s_intCard;
static const Integer s_realCard;
static const Integer s_unknownCard;
static const Integer s_largeFiniteCard;
Integer d_card;
public:
static const Cardinality INTEGERS;
static const Cardinality REALS;
static const Cardinality UNKNOWN_CARD;
enum CVC4_PUBLIC CardinalityComparison {
LESS,
EQUAL,
GREATER,
UNKNOWN
};/* enum CardinalityComparison */
Cardinality(long card) : d_card(card) {
CheckArgument(card >= 0, card,
"Cardinality must be a nonnegative integer, not %ld.", card);
d_card += 1;
}
Cardinality(const Integer& card) : d_card(card) {
CheckArgument(card >= 0, card,
"Cardinality must be a nonnegative integer, not %s.",
card.toString().c_str());
d_card += 1;
}
Cardinality(CardinalityBeth beth) : d_card(-beth.getNumber() - 1) {
}
Cardinality(CardinalityUnknown) : d_card(0) {
}
bool isUnknown() const throw() {
return d_card == 0;
}
bool isFinite() const throw() {
return d_card > 0;
}
bool isLargeFinite() const throw() {
return d_card >= s_largeFiniteCard;
}
bool isInfinite() const throw() {
return d_card < 0;
}
bool isCountable() const throw() {
return isFinite() || d_card == s_intCard;
}
Integer getFiniteCardinality() const throw(IllegalArgumentException) {
CheckArgument(isFinite(), *this, "This cardinality is not finite.");
CheckArgument(!isLargeFinite(), *this, "This cardinality is finite, but too large to represent.");
return d_card - 1;
}
Integer getBethNumber() const throw(IllegalArgumentException) {
CheckArgument(!isFinite() && !isUnknown(), *this,
"This cardinality is not infinite (or is unknown).");
return -d_card - 1;
}
Cardinality& operator+=(const Cardinality& c) throw();
Cardinality& operator*=(const Cardinality& c) throw();
Cardinality& operator^=(const Cardinality& c) throw();
Cardinality operator+(const Cardinality& c) const throw() {
Cardinality card(*this);
card += c;
return card;
}
Cardinality operator*(const Cardinality& c) const throw() {
Cardinality card(*this);
card *= c;
return card;
}
Cardinality operator^(const Cardinality& c) const throw() {
Cardinality card(*this);
card ^= c;
return card;
}
Cardinality::CardinalityComparison compare(const Cardinality& c) const throw();
std::string toString() const throw();
bool knownLessThanOrEqual(const Cardinality& c) const throw();
};/* class Cardinality */
std::ostream& operator<<(std::ostream& out, CardinalityBeth b)
throw() CVC4_PUBLIC;
std::ostream& operator<<(std::ostream& out, const Cardinality& c)
throw() CVC4_PUBLIC;
}/* CVC4 namespace */
#endif /* __CVC4__CARDINALITY_H */
CVC4::CardinalityBeth
Representation for a Beth number, used only to construct Cardinality objects.
Definition cardinality.h:35
CVC4::CardinalityBeth::CardinalityBeth
CardinalityBeth(const Integer &beth)
Definition cardinality.h:39
CVC4::CardinalityBeth::getNumber
const Integer & getNumber() const
Definition cardinality.h:45
CVC4::CardinalityUnknown
Representation for an unknown cardinality.
Definition cardinality.h:54
CVC4::CardinalityUnknown::~CardinalityUnknown
~CardinalityUnknown()
Definition cardinality.h:57
CVC4::CardinalityUnknown::CardinalityUnknown
CardinalityUnknown()
Definition cardinality.h:56
CVC4::Cardinality
A simple representation of a cardinality.
Definition cardinality.h:65
CVC4::Cardinality::getFiniteCardinality
Integer getFiniteCardinality() const
In the case that this cardinality is finite, return its cardinality.
Definition cardinality.h:186
CVC4::Cardinality::getBethNumber
Integer getBethNumber() const
In the case that this cardinality is infinite, return its Beth number.
Definition cardinality.h:197
CVC4::Cardinality::operator+=
Cardinality & operator+=(const Cardinality &c)
Assigning addition of this cardinality with another.
CVC4::Cardinality::toString
std::string toString() const
Return a string representation of this cardinality.
CVC4::Cardinality::Cardinality
Cardinality(long card)
Construct a finite cardinality equal to the integer argument.
Definition cardinality.h:115
CVC4::Cardinality::isFinite
bool isFinite() const
Returns true iff this cardinality is finite.
Definition cardinality.h:156
CVC4::Cardinality::operator*=
Cardinality & operator*=(const Cardinality &c)
Assigning multiplication of this cardinality with another.
CVC4::Cardinality::REALS
static const Cardinality REALS
The cardinality of the set of real numbers.
Definition cardinality.h:96
CVC4::Cardinality::isInfinite
bool isInfinite() const
Returns true iff this cardinality is infinite.
Definition cardinality.h:169
CVC4::Cardinality::UNKNOWN_CARD
static const Cardinality UNKNOWN_CARD
The unknown cardinality.
Definition cardinality.h:99
CVC4::Cardinality::Cardinality
Cardinality(CardinalityUnknown)
Construct an unknown cardinality.
Definition cardinality.h:141
CVC4::Cardinality::isUnknown
bool isUnknown() const
Returns true iff this cardinality is unknown.
Definition cardinality.h:151
CVC4::Cardinality::isLargeFinite
bool isLargeFinite() const
Returns true iff this cardinality is finite and large (i.e., at the ceiling of representable finite c...
Definition cardinality.h:164
CVC4::Cardinality::Cardinality
Cardinality(const Integer &card)
Construct a finite cardinality equal to the integer argument.
Definition cardinality.h:125
CVC4::Cardinality::operator^
Cardinality operator^(const Cardinality &c) const
Exponentiation of two cardinalities.
Definition cardinality.h:229
CVC4::Cardinality::Cardinality
Cardinality(CardinalityBeth beth)
Construct an infinite cardinality equal to the given Beth number.
Definition cardinality.h:135
CVC4::Cardinality::INTEGERS
static const Cardinality INTEGERS
The cardinality of the set of integers.
Definition cardinality.h:93
CVC4::Cardinality::operator^=
Cardinality & operator^=(const Cardinality &c)
Assigning exponentiation of this cardinality with another.
CVC4::Cardinality::operator+
Cardinality operator+(const Cardinality &c) const
Add two cardinalities.
Definition cardinality.h:213
CVC4::Cardinality::isCountable
bool isCountable() const
Returns true iff this cardinality is finite or countably infinite.
Definition cardinality.h:177
CVC4::Cardinality::CardinalityComparison
CardinalityComparison
Used as a result code for Cardinality::compare().
Definition cardinality.h:102
CVC4::Cardinality::EQUAL
@ EQUAL
Definition cardinality.h:104
CVC4::Cardinality::GREATER
@ GREATER
Definition cardinality.h:105
CVC4::Cardinality::LESS
@ LESS
Definition cardinality.h:103
CVC4::Cardinality::operator*
Cardinality operator*(const Cardinality &c) const
Multiply two cardinalities.
Definition cardinality.h:220
CVC4::Cardinality::compare
Cardinality::CardinalityComparison compare(const Cardinality &c) const
Compare two cardinalities.
CVC4::IllegalArgumentException
Definition exception.h:79
CVC4::Integer
Definition integer_gmp_imp.h:34
CVC4::Integer::toString
std::string toString(int base=10) const
Definition integer_cln_imp.h:364
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::CheckArgument
void CheckArgument(bool cond, const T &arg, const char *fmt,...)
Definition exception.h:140
std
STL namespace.