35template<
typename ValueType>
127 bool empty()
const {
return m_closure_.empty(); }
276 return *
this += -rhs;
469 bool m_is_left_open_ =
false;
472 bool m_is_right_open_ =
false;
478template<
typename ValueType>
486 if((m_is_left_open_ || m_is_right_open_) &&
lower ==
upper) {
491template<
typename ValueType>
493 if(!m_closure_.contains(value)) {
return false; }
502template<
typename ValueType>
504 if(other.
empty()) {
return true; }
505 if(!m_closure_.contains(other.m_closure_)) {
return false; }
522template<
typename ValueType>
525 if(
empty()) {
return other; }
526 if(other.
empty()) {
return *
this; }
532 if(left.
upper() < right.lower()) {
return true; }
536 if(separated(*
this, other) || separated(other, *
this)) {
537 throw std::domain_error(
"Intervals do not overlap");
541 bool lower_is_open =
false;
542 bool upper_is_open =
false;
565template<
typename ValueType>
593template<
typename ValueType>
596 if(
empty()) {
return *
this = rhs; }
597 if(rhs.
empty()) {
return *
this; }
598 m_closure_ += rhs.m_closure_;
605template<
typename ValueType>
606bool GeneralInterval<ValueType>::corner_bound_open_(
607 value_t value, value_t ll, value_t lh, value_t hl, value_t hh,
617template<
typename ValueType>
619 const closure_t& result, value_t ll, value_t lh, value_t hl, value_t hh,
623 auto low = std::fmin(std::fmin(ll, lh), std::fmin(hl, hh));
624 auto high = std::fmax(std::fmax(ll, lh), std::fmax(hl, hh));
628 bool lower_is_open = !(zero_attained && result.lower() == value_t(0)) &&
629 corner_bound_open_(low, ll, lh, hl, hh, lhs, rhs);
630 bool upper_is_open = !(zero_attained && result.upper() == value_t(0)) &&
631 corner_bound_open_(high, ll, lh, hl, hh, lhs, rhs);
637template<
typename ValueType>
642 auto product = m_closure_ * rhs.m_closure_;
651 from_corners_(product, ll, lh, hl, hh, *
this, rhs, zero_attained);
654template<
typename ValueType>
658 constexpr auto inf = std::numeric_limits<value_t>::infinity();
659 const interval_t one(value_t(1));
665 a.
upper() == value_t(0) ? -inf : (one / interval_t(a.
upper())).lower();
667 a.
lower() == value_t(0) ? inf : (one / interval_t(a.
lower())).upper();
673template<
typename ValueType>
678 throw std::domain_error(
"Division by zero");
685 return *
this *= reciprocal_(rhs);
688 auto quotient = m_closure_ / rhs.m_closure_;
698 from_corners_(quotient, ll, lh, hl, hh, *
this, rhs, zero_attained);
701template<
typename ValueType>
703 if(
empty()) {
return "[∅]"; }
704 std::string left_open_str =
left_open() ?
"(" :
"[";
705 std::string right_open_str =
right_open() ?
")" :
"]";
707 return left_open_str + std::to_string(
lower()) +
", " +
708 std::to_string(
upper()) + right_open_str;
725template<
typename ValueType>
743template<
typename T1,
typename T2>
746 if constexpr(!std::is_same_v<T1, T2>)
return false;
762template<
typename T1,
typename T2>
765 return !(lhs == rhs);
840 if(point <= a.
lower()) {
857template<
typename ValueType>
858struct hash<
sigma::GeneralInterval<ValueType>> {
861 std::size_t seed = std::hash<sigma::Interval<ValueType>>()(i.
closure());
862 std::size_t openness =
864 seed ^= openness + 0x9e3779b9 + (seed << 6) + (seed >> 2);
Models an interval whose bounds may be open.
Definition general_interval.hpp:36
Interval< value_t > closure_t
Definition general_interval.hpp:42
GeneralInterval & operator/=(const GeneralInterval &rhs)
In-place division by another interval.
Definition general_interval.hpp:674
value_t width() const
Returns the distance between the interval's bounds.
Definition general_interval.hpp:103
const closure_t & closure() const
Returns the closure of the interval.
Definition general_interval.hpp:189
GeneralInterval(value_t lower, value_t upper, bool left_open=false, bool right_open=false)
Construct an interval from two bounds and their openness.
Definition general_interval.hpp:479
bool contains(value_t value) const
Whether a scalar lies in this interval.
Definition general_interval.hpp:492
GeneralInterval & operator+=(const GeneralInterval &rhs)
In-place addition of another interval.
Definition general_interval.hpp:594
bool operator!=(const GeneralInterval< T1 > &lhs, const GeneralInterval< T2 > &rhs)
Compare two intervals for inequality.
Definition general_interval.hpp:763
GeneralInterval()=default
Default constructor.
friend GeneralInterval operator+(GeneralInterval lhs, const GeneralInterval &rhs)
Addition of two intervals.
Definition general_interval.hpp:336
std::ostream & operator<<(std::ostream &os, const GeneralInterval< ValueType > &i)
Overload stream insertion to print an interval.
Definition general_interval.hpp:726
bool empty() const
Is *this the empty interval?
Definition general_interval.hpp:127
bool contains(const GeneralInterval &other) const
Is other fully contained in this interval?
Definition general_interval.hpp:503
bool left_open() const
Definition general_interval.hpp:136
bool right_closed() const
Is upper() contained in the interval?
Definition general_interval.hpp:161
bool right_open() const
Definition general_interval.hpp:153
friend GeneralInterval operator*(GeneralInterval lhs, const GeneralInterval &rhs)
Multiplication of two intervals.
Definition general_interval.hpp:368
value_t radius() const
Returns the half-width of the interval.
Definition general_interval.hpp:119
std::string print_interval_form() const
Print the interval in interval form.
Definition general_interval.hpp:702
GeneralInterval & operator-=(const GeneralInterval &rhs)
In-place subtraction of another interval.
Definition general_interval.hpp:275
float value_t
Definition general_interval.hpp:39
GeneralInterval operator-() const
Negation of an interval.
Definition general_interval.hpp:252
GeneralInterval< T > widen(const GeneralInterval< T > &a, typename GeneralInterval< T >::value_t point)
Widens an interval just enough to contain a point.
Definition general_interval.hpp:836
friend GeneralInterval operator-(GeneralInterval lhs, const GeneralInterval &rhs)
Subtraction of two intervals.
Definition general_interval.hpp:352
friend GeneralInterval operator/(GeneralInterval lhs, const GeneralInterval &rhs)
Division of two intervals.
Definition general_interval.hpp:385
GeneralInterval set_intersection(const GeneralInterval &other) const
Returns the intersection of this interval and another interval.
Definition general_interval.hpp:566
GeneralInterval & operator*=(const GeneralInterval &rhs)
In-place multiplication by another interval.
Definition general_interval.hpp:638
bool operator==(const GeneralInterval< T1 > &lhs, const GeneralInterval< T2 > &rhs)
Compare two intervals for equality.
Definition general_interval.hpp:744
GeneralInterval set_union(const GeneralInterval &other) const
Returns the union of this interval and another interval.
Definition general_interval.hpp:523
GeneralInterval(const closure_t &closed)
Construct from a closed interval.
Definition general_interval.hpp:72
bool left_closed() const
Is lower() contained in the interval?
Definition general_interval.hpp:144
bool operator<(const GeneralInterval< T > &lhs, const GeneralInterval< T > &rhs)
Orders two intervals, primarily by their median.
Definition general_interval.hpp:788
bool operator<=(const GeneralInterval< T > &lhs, const GeneralInterval< T > &rhs)
Same ordering as operator<, negated.
Definition general_interval.hpp:805
bool operator>=(const GeneralInterval< T > &lhs, const GeneralInterval< T > &rhs)
Same ordering as operator<, negated and reversed.
Definition general_interval.hpp:812
GeneralInterval(value_t value)
Construct a degenerate interval from a single value.
Definition general_interval.hpp:60
value_t median() const
Returns the midpoint of the interval.
Definition general_interval.hpp:111
bool operator>(const GeneralInterval< T > &lhs, const GeneralInterval< T > &rhs)
Same ordering as operator<, with the operands reversed.
Definition general_interval.hpp:798
value_t lower() const
Definition general_interval.hpp:169
value_t upper() const
Definition general_interval.hpp:177
Models a closed numeric interval.
Definition interval.hpp:29
value_t upper() const
Returns the upper bound of the interval.
Definition interval.hpp:127
value_t lower() const
Returns the lower bound of the interval.
Definition interval.hpp:116
bool empty() const
Is *this the empty interval?
Definition interval.hpp:108
Convenience header for general interval operations.
Defines the Interval class.
boost::numeric::interval< T, interval_policies_t< T > > boost_interval_t
The boost interval type sigma::Interval wraps.
Definition policies.hpp:485
The primary namespace for the sigma library.
Definition affine.hpp:12
GeneralInterval< double > GIDouble
Typedef for a general interval of doubles.
Definition general_interval.hpp:850
GeneralInterval< float > GIFloat
Typedef for a general interval of floats.
Definition general_interval.hpp:847
size_t operator()(const sigma::GeneralInterval< ValueType > &i) const
Hashes the closure and then folds in the openness of each bound.
Definition general_interval.hpp:860