36 CLANG_WARNING_DISABLE(
"-Wunused-parameter")
37 CLANG_WARNING_DISABLE("-Wunused-local-typedef")
38 #include <boost/numeric/interval.hpp>
39 #include <boost/numeric/interval/interval.hpp>
56 template<
typename Number>
66 template<
typename Number,
typename Interval>
78 template<
typename Interval>
81 using roundingP = boost::numeric::interval_lib::save_state<boost::numeric::interval_lib::rounded_transc_std<double> >;
82 using checkingP = boost::numeric::interval_lib::checking_no_nan<double, boost::numeric::interval_lib::checking_no_nan<double> >;
84 if (std::isinf(n.
lower())) {
87 if (std::isinf(n.
upper())) {
90 assert(!std::isnan(n.
lower()));
91 assert(!std::isnan(n.
upper()));
95 template<
typename Number>
100 template<
typename Number>
105 template<
typename Number>
110 template<
typename Number>
132 template<
typename Number>
142 using BoostIntervalPolicies = boost::numeric::interval_lib::policies< typename Policy::roundingP, typename Policy::checkingP >;
143 using BoostInterval = boost::numeric::interval< Number, BoostIntervalPolicies >;
147 #define BOUNDS_OK( lower, lowerBoundType, upper, upperBoundType )\
148 (lowerBoundType == BoundType::INFTY || upperBoundType == BoundType::INFTY || lower <= upper)
151 #define IS_EMPTY(lower, lowerBoundType, upper, upperBoundType )\
152 (((lowerBoundType == BoundType::STRICT && upperBoundType != BoundType::INFTY) || (lowerBoundType != BoundType::INFTY && upperBoundType == BoundType::STRICT)) && lower == upper)
155 #define IS_UNBOUNDED(lower, lowerBoundType, upper, upperBoundType )\
156 (lowerBoundType == BoundType::INFTY && upperBoundType == BoundType::INFTY)
325 template<
typename Other, DisableIf<std::is_same<Number, Other >> = dummy >
335 template<
typename N = Number, DisableIf<std::is_same<N,
double >> = dummy, DisableIf<is_rational_type<N >> = dummy >
348 template<
typename N = Number, DisableIf<std::is_same<N,
double >> = dummy, DisableIf<is_rational_type<N >> = dummy >
376 template<
typename N = Number, DisableIf<std::is_same<N,
double >> = dummy, DisableIf<is_rational_type<N >> = dummy>
419 template<
typename N = Number, DisableIf<std::is_same<N,
int >> = dummy >
430 template<
typename N = Number, DisableIf<std::is_same<N,
int >> = dummy>
457 template<
typename N = Number, DisableIf<std::is_same<N,
int >> = dummy>
499 template<
typename N = Number, DisableIf<std::is_same<N,
unsigned int >> = dummy >
510 template<
typename N = Number, DisableIf<std::is_same<N,
unsigned int >> = dummy>
537 template<
typename N = Number, DisableIf<std::is_same<N,
unsigned int >> = dummy>
580 template<
typename Num = Number,
typename Rational, EnableIf<std::is_
floating_po
int<Num >> = dummy, DisableIf<std::is_same<Num, Rational >> = dummy>
594 template<
typename Num = Number,
typename Rational, EnableIf<std::is_
floating_po
int<Num >> = dummy, DisableIf<std::is_same<Num, Rational >> = dummy>
612 template<
typename Num = Number,
typename Rational, EnableIf<std::is_
floating_po
int<Num >> = dummy, DisableIf<std::is_same<Num, Rational >> = dummy>
651 template<
typename Num = Number,
typename Float, EnableIf<is_rational_type<Num >> = dummy, EnableIf<std::is_
floating_po
int<Float >> = dummy, DisableIf<std::is_same<Num, Float >> = dummy>
665 template<
typename Num = Number,
typename Float, EnableIf<is_rational_type<Num >> = dummy, EnableIf<std::is_
floating_po
int<Float >> = dummy, DisableIf<std::is_same<Num, Float >> = dummy>
683 template<
typename Num = Number,
typename Float, EnableIf<is_rational_type<Num >> = dummy, EnableIf<std::is_
floating_po
int<Float >> = dummy, DisableIf<std::is_same<Num, Float >> = dummy, DisableIf<std::is_
floating_po
int<Num >> = dummy>
721 template<
typename Num = Number,
typename Rational, EnableIf<is_rational_type<Num >> = dummy, EnableIf<is_rational_type<Rational >> = dummy, DisableIf<std::is_same<Num, Rational >> = dummy>
735 template<
typename Num = Number,
typename Rational, EnableIf<is_rational_type<Num >> = dummy, EnableIf<is_rational_type<Rational >> = dummy, DisableIf<std::is_same<Num, Rational >> = dummy>
753 template<
typename Num = Number,
typename Rational, EnableIf<is_rational_type<Num >> = dummy, EnableIf<is_rational_type<Rational >> = dummy, DisableIf<std::is_same<Num, Rational >> = dummy>
786 Interval(lb.number, lb.bound_type, ub.number, ub.bound_type)
912 this->
set(mContent.lower(), n);
953 this->
set(mContent.lower(), n);
1059 if (mContent.lower() ==
mContent.upper()) {
1236 template<
typename Num = Number, DisableIf<std::is_same<Num,
int >> = dummy>
1239 return this->
contains(Number(val));
1290 std::list<Interval<Number >>
split(
unsigned n)
const;
1312 str <<
"]" << i.
mContent.lower() <<
", ";
1315 str <<
"[" << i.
mContent.lower() <<
", ";
1412 template<
typename Num = Number, EnableIf<std::is_
floating_po
int<Num>> = dummy>
1419 template<
typename Num = Number, EnableIf<std::is_
floating_po
int<Num>> = dummy>
1441 template<
typename T>
1444 template<
typename Number>
1452 template<
typename Number>
1461 template<
typename Number>
1475 template<
typename Number>
1478 return _lhs.
div(_rhs);
1487 template<
typename Number>
1490 return _lhs.
div(_rhs);
1499 template<
typename Integer,
typename Number>
1510 template<
typename Number>
1522 template<
typename Number>
1534 template<
typename Number>
1546 template<
typename Number>
1547 struct hash<
carl::Interval<Number>> {
#define IS_EMPTY(lower, lowerBoundType, upper, upperBoundType)
Macro to perform a quick check for emptiness of the interval.
#define BOUNDS_OK(lower, lowerBoundType, upper, upperBoundType)
Macro to perform a quick check on the passed interval bounds.
#define IS_UNBOUNDED(lower, lowerBoundType, upper, upperBoundType)
Macro to perform a quick check if the interval is unbounded.
carl is the main namespace for the library.
Interval< Number > ceil(const Interval< Number > &_in)
Method which returns the next larger integer of the passed number or the number itself,...
Interval< Number > abs(const Interval< Number > &_in)
Method which returns the absolute value of the passed number.
Interval< Number > floor(const Interval< Number > &_in)
Method which returns the next smaller integer of this number or the number itself,...
Interval< Number > quotient(const Interval< Number > &_lhs, const Interval< Number > &_rhs)
Implements the division with remainder.
double roundDown(const Rational &o, bool overapproximate=false)
Returns a down-rounded representation of the given numeric.
std::ostream & operator<<(std::ostream &os, const BasicConstraint< Poly > &c)
Prints the given constraint on the given stream.
Sign
This class represents the sign of a number .
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
Integer to_int(const Interval< Number > &_floatInterval)
Casts the Interval to an arbitrary integer type which has a constructor for a native int.
static BoundType get_other_bound_type(BoundType type)
Interval< Number > div(const Interval< Number > &_lhs, const Interval< Number > &_rhs)
Implements the division which assumes that there is no remainder.
double roundUp(const Rational &o, bool overapproximate=false)
Returns a up-rounded representation of the given numeric.
bool is_integer(const Interval< Number > &n)
double to_double(const cln::cl_RA &n)
Converts the given fraction to a double.
@ WEAK
the given bound is compared by a weak ordering relation
@ STRICT
the given bound is compared by a strict ordering relation
@ INFTY
the given bound is interpreted as minus or plus infinity depending on whether it is the left or the r...
std::size_t hash_all(Args &&... args)
Hashes an arbitrary number of values.
bool is_one(const Interval< Number > &i)
Check if this interval is a point-interval containing 1.
auto & get(const std::string &name)
The class which contains the interval arithmetic including trigonometric functions.
Interval(const BoostInterval &content, BoundType lowerBoundType=BoundType::WEAK, BoundType upperBoundType=BoundType::WEAK)
Constructor which constructs the interval according to the passed boost interval with the passed boun...
Interval(double lower, BoundType lowerBoundType, double upper, BoundType upperBoundType)
Constructor which constructs the interval according to the passed double bounds with the passed bound...
void shrink_by(const Number &width)
Shrinks the interval by the given value.
bool contains(const Interval< Number > &rhs) const
Checks if the interval contains the given interval.
Interval(unsigned int lower, BoundType lowerBoundType, unsigned int upper, BoundType upperBoundType)
Constructor which constructs the interval according to the passed unsigned int bounds with the passed...
Interval(int lower, BoundType lowerBoundType, int upper, BoundType upperBoundType)
Constructor which constructs the interval according to the passed int bounds with the passed bound ty...
void bloat_by(const Number &width)
Bloats the interval by the given value.
Interval< Number > inverse() const
Calculates the additive inverse of an interval with respect to natural interval arithmetic.
void div_assign(const Interval< Number > &rhs)
void abs_assign()
Calculates and assigns the absolute value of the interval.
void set_upper_bound_type(BoundType b)
The setter for the upper bound type of the interval.
bool div_ext(const Interval< Number > &rhs, Interval< Number > &a, Interval< Number > &b) const
Implements extended interval division with intervals containting zero.
bool is_empty() const
Function which determines, if the interval is empty.
BoundType lower_bound_type() const
The getter for the lower bound type of the interval.
const BoostInterval & content() const
Returns a reference to the included boost interval.
static Interval< Number > zero_interval()
Method which returns the pointinterval rooted at 0.
Interval(Float n)
Constructor which constructs a pointinterval from a passed general float number (e....
Interval()
Default constructor which constructs the empty interval at point 0.
void set_upper(const Number &n)
The setter for the upper boundary of the interval.
void set(const Number &lower, const Number &upper)
Advanced setter to modify both boundaries at once by passing a boost interval.
void inverse_assign()
Calculates and assigns the additive inverse of an interval with respect to natural interval arithmeti...
Interval(Rational lower, BoundType lowerBoundType, Rational upper, BoundType upperBoundType)
Constructor which constructs the interval according to the passed general float bounds (e....
const Number & upper() const
The getter for the upper boundary of the interval.
Number magnitude() const
Returns the magnitude of the interval.
boost::numeric::interval_lib::policies< typename Policy::roundingP, typename Policy::checkingP > BoostIntervalPolicies
bool is_semi_positive() const
void center_assign()
Computes and assigns the center point of the interval.
void mul_assign(const Interval< Number > &rhs)
bool reciprocal(Interval< Number > &a, Interval< Number > &b) const
Calculates the multiplicative inverse of an interval with respect to natural interval arithmetic.
Interval(const unsigned int &n)
Constructor which constructs a pointinterval from a passed unsigned int.
Interval(Rational lower, BoundType lowerBoundType, Rational upper, BoundType upperBoundType)
Constructor which constructs the interval according to the passed general rational bounds with the pa...
void diameter_assign()
Computes and assigns the diameter of the interval.
Interval(unsigned int lower, unsigned int upper)
Constructor which constructs an interval from the passed unsigned int bounds.
boost::numeric::interval< Number, BoostIntervalPolicies > BoostInterval
bool contains(const Number &val) const
Checks if the interval contains the given value.
Interval(const LowerBound< Number > &lb, const LowerBound< Number > &ub)
Interval(const UpperBound< Number > &lb, const UpperBound< Number > &ub)
Interval< Number > & operator=(const Interval< Number > &rhs)
The assignment operator.
Interval(Rational n)
Constructor which constructs a pointinterval from a passed general float number (e....
Interval(const Interval< Number > &o)
Copy constructor.
void add_assign(const Interval< Number > &rhs)
bool contains_integer() const
Checks if the interval contains at least one integer value.
bool is_closed_interval() const
Function which determines, if the interval is closed.
Interval(const Number &lower, BoundType lowerBoundType, const Number &upper, BoundType upperBoundType)
Constructor which constructs the interval according to the passed bounds with the passed bound types.
void sub_assign(const Interval< Number > &rhs)
Interval< Number > root(int deg) const
Calculates the nth root of the interval with respect to natural interval arithmetic.
std::list< Interval< Number > > split(unsigned n) const
Splits the interval into n equally sized parts (strict-weak-cut).
~Interval()=default
Destructor.
Interval(Float lower, Float upper)
Constructor which constructs an interval from the passed general float bounds (e.g.
const Number & lower() const
The getter for the lower boundary of the interval.
void shrink_times(const Number &factor)
Shrinks the interval by a multiple of its width.
void diameter_ratio_assign(const Interval< Number > &rhs)
Computes and assigns the ratio of the diameters of the given intervals.
void set_upper_bound(const Number &n, BoundType b)
The setter for the upper boundary of the interval.
bool is_point_interval() const
Function which determines, if the interval is a pointinterval.
std::pair< Interval< Number >, Interval< Number > > split() const
Splits the interval into 2 equally sized parts (strict-weak-cut).
bool meets(const Number &n) const
Checks if the interval meets the given value, that is if the given value is contained in the closed i...
Interval(const Number &n)
Constructor which constructs the pointinterval at n.
void set(const BoostInterval &content)
Advanced setter to modify both boundaries at once.
bool is_open_interval() const
Function which determines, if the interval is open.
Interval< Number > mul(const Interval< Number > &rhs) const
Multiplies two intervals according to natural interval arithmetic.
bool is_semi_negative() const
bool is_consistent() const
A quick check for the bound values.
static Interval< Number > empty_interval()
Method which returns the empty interval rooted at 0.
Interval(Float lower, BoundType lowerBoundType, Float upper, BoundType upperBoundType)
Constructor which constructs the interval according to the passed general float bounds (e....
Sign sgn() const
Determine whether the interval lays entirely left of 0 (NEGATIVE_SIGN), right of 0 (POSITIVE_SIGN) or...
Interval(const Interval< Other > &o)
void magnitude_assign()
Computes and assigns the magnitude of the interval.
void set_lower_bound_type(BoundType b)
The setter for the lower bound type of the interval.
Interval(Rational n)
Constructor which constructs a pointinterval from a passed general rational number.
Interval(const LowerBound< Number > &lb, const UpperBound< Number > &ub)
Number diameter_ratio(const Interval< Number > &rhs) const
Returns the ratio of the diameters of the given intervals.
bool is_unbounded() const
Function which determines, if the interval is unbounded.
void root_assign(unsigned deg)
Calculates and assigns the nth root of the interval with respect to natural interval arithmetic.
Interval< Number > convex_hull(const Interval< Number > &interval) const
BoostInterval & content()
Returns a reference to the included boost interval.
void integralPart_assign()
Computes and assigns the integral part of the given interval.
Interval< Number > sub(const Interval< Number > &rhs) const
Subtracts two intervals according to natural interval arithmetic.
BoundType upper_bound_type() const
The getter for the upper bound type of the interval.
Interval(const int &n)
Constructor which constructs a pointinterval from a passed int.
Interval(Rational lower, Rational upper)
Constructor which constructs an interval from the passed general float bounds (e.g.
void bloat_times(const Number &factor)
Bloats the interval times the factor (multiplies the overall width).
bool is_one() const
Function which determines, if the interval is the one interval.
static Interval< Number > unbounded_interval()
Method which returns the unbounded interval rooted at 0.
bool is_half_bounded() const
Function which determines, if the interval is half-bounded.
BoundType mUpperBoundType
Interval(Rational lower, Rational upper)
Constructor which constructs an interval from the passed general rational bounds.
Interval< Number > abs() const
Calculates the absolute value of the interval.
std::string toString() const
Creates a string representation of the interval.
BoundType mLowerBoundType
Interval(const Number &lower, const Number &upper)
Constructor which constructs the weak-bounded interval between lower and upper.
Interval< Number > integral_part() const
Computes the integral part of the given interval.
bool is_infinite() const
Function which determines, if the interval is (-oo,oo).
Number diameter() const
Returns the diameter of the interval.
Interval< Number > add(const Interval< Number > &rhs) const
Adds two intervals according to natural interval arithmetic.
void set_lower(const Number &n)
The setter for the lower boundary of the interval.
bool contains(int val) const
bool is_zero() const
Function which determines, if the interval is the zero interval.
Interval(const double &n)
Constructor which constructs a pointinterval from a passed double.
Number distance(const Interval< Number > &intervalA)
Calculates the distance between two Intervals.
std::map< Variable, Interval< Number > > evalintervalmap
void set_lower_bound(const Number &n, BoundType b)
The setter for the lower boundary of the interval.
Interval(double lower, double upper)
Constructor which constructs an interval from the passed double bounds.
Interval(int lower, int upper)
Constructor which constructs an interval from the passed int bounds.
Interval< Number > div(const Interval< Number > &rhs) const
Divides two intervals according to natural interval arithmetic.
friend std::ostream & operator<<(std::ostream &str, const Interval< Number > &i)
Operator which passes a string representation of this to the given ostream.
Struct which holds the rounding and checking policies required for boost interval.
static void sanitize(Interval &)
boost::numeric::interval_lib::checking_no_nan< double, boost::numeric::interval_lib::checking_no_nan< double > > checkingP
static void sanitize(Interval &n)
boost::numeric::interval_lib::save_state< boost::numeric::interval_lib::rounded_transc_std< double > > roundingP
std::size_t operator()(const carl::Interval< Number > &interval) const
Calculates the hash of an interval.
States whether a given type is an Interval.
States if a type is a number type.