41template<
typename IntervalType>
105 std::enable_if_t<is_general_interval_v<I>,
int> = 0>
125 if(!m_interval_.contains(m_nominal_)) {
126 throw std::domain_error(
"The nominal value of a triplex must be a "
127 "member of its interval");
139 bool empty()
const {
return m_interval_.empty(); }
149 return m_interval_.lower();
176 return m_interval_.upper();
187 return m_interval_.width();
200 return m_interval_.median();
239 std::enable_if_t<is_general_interval_v<I>,
int> = 0>
241 return m_interval_.left_open();
256 std::enable_if_t<is_general_interval_v<I>,
int> = 0>
258 return m_interval_.left_closed();
273 std::enable_if_t<is_general_interval_v<I>,
int> = 0>
275 return m_interval_.right_open();
290 std::enable_if_t<is_general_interval_v<I>,
int> = 0>
292 return m_interval_.right_closed();
319 return m_interval_.contains(other.m_interval_);
458 struct unchecked_tag_ {};
485 template<
typename... Args>
489 throw std::domain_error(
490 "A triplex requires lower <= nominal <= upper");
496 void assert_not_empty_()
const {
497 if(
empty()) {
throw std::domain_error(
"Triplex is empty"); }
514template<
typename IntervalType>
516 if(
empty()) {
return *
this = rhs; }
517 if(rhs.
empty()) {
return *
this; }
518 auto bounds = m_interval_ + rhs.m_interval_;
523template<
typename IntervalType>
525 if(
empty()) {
return *
this = -rhs; }
526 if(rhs.
empty()) {
return *
this; }
527 auto bounds = m_interval_ - rhs.m_interval_;
532template<
typename IntervalType>
535 auto bounds = m_interval_ * rhs.m_interval_;
540template<
typename IntervalType>
543 auto bounds = m_interval_ / rhs.m_interval_;
565template<
typename IntervalType>
567 if(t.
empty()) {
return os <<
"∅"; }
568 bool is_left_open =
false;
569 bool is_right_open =
false;
574 return os << (is_left_open ?
"(" :
"[") << t.
lower() <<
", " << t.
nominal()
575 <<
", " << t.
upper() << (is_right_open ?
")" :
"]");
593template<
typename I1,
typename I2>
595 if constexpr(!std::is_same_v<I1, I2>) {
616template<
typename I1,
typename I2>
618 return !(lhs == rhs);
643template<
typename IntervalType>
646 if(rhs.
empty()) {
return false; }
647 if(lhs.
empty()) {
return true; }
649 bool is_left_open =
false;
650 bool is_right_open =
false;
652 is_left_open = t.left_open();
653 is_right_open = t.right_open();
655 return std::make_tuple(t.nominal(), t.lower(), t.upper(), is_left_open,
658 return key(lhs) < key(rhs);
663template<
typename IntervalType>
671template<
typename IntervalType>
679template<
typename IntervalType>
696template<
typename IntervalType>
697struct hash<
sigma::Triplex<IntervalType>> {
701 using value_t =
typename IntervalType::value_t;
702 if(t.
empty()) {
return 0; }
703 std::size_t seed = std::hash<IntervalType>()(t.
interval());
704 std::size_t hash_nominal = std::hash<value_t>()(t.
nominal());
705 seed ^= hash_nominal + 0x9e3779b9 + (seed << 6) + (seed >> 2);
float value_t
Definition interval.hpp:32
Models an interval together with a best estimate inside it.
Definition triplex.hpp:42
Triplex(interval_t interval, value_t nominal)
Constructs a triplex from an interval and a nominal value.
Definition triplex.hpp:123
sigma::Interval< float > interval_t
Definition triplex.hpp:45
bool right_open() const
Definition triplex.hpp:274
value_t lower_radius() const
Returns the distance from the lower bound to the nominal value.
Definition triplex.hpp:209
Triplex & operator/=(const Triplex &rhs)
In-place division by another triplex.
Definition triplex.hpp:541
value_t upper() const
Definition triplex.hpp:174
bool right_closed() const
Is upper() a member of *this?
Definition triplex.hpp:291
Triplex(value_t lower, value_t nominal, value_t upper)
Constructs a triplex from its bounds and its nominal value.
Definition triplex.hpp:83
value_t median() const
Returns the midpoint of the bounds.
Definition triplex.hpp:198
bool contains(const Triplex &other) const
Whether the bounds of other lie within the bounds of *this.
Definition triplex.hpp:318
Triplex(value_t value)
Constructs the degenerate triplex for an exactly known value.
Definition triplex.hpp:67
Triplex()=default
Default constructor.
std::ostream & operator<<(std::ostream &os, const Triplex< IntervalType > &t)
Overload stream insertion to print a triplex.
Definition triplex.hpp:566
Triplex & operator*=(const Triplex &rhs)
In-place multiplication by another triplex.
Definition triplex.hpp:533
bool empty() const
Is *this the empty triplex?
Definition triplex.hpp:139
bool contains(value_t value) const
Whether a scalar lies within the bounds.
Definition triplex.hpp:305
friend Triplex operator+(Triplex lhs, const Triplex &rhs)
Addition of two triplex numbers.
Definition triplex.hpp:403
bool operator>(const Triplex< IntervalType > &lhs, const Triplex< IntervalType > &rhs)
Same ordering as operator<, with the operands reversed.
Definition triplex.hpp:664
bool operator!=(const Triplex< I1 > &lhs, const Triplex< I2 > &rhs)
Compare two triplex numbers for inequality.
Definition triplex.hpp:617
Triplex & operator-=(const Triplex &rhs)
In-place subtraction of another triplex.
Definition triplex.hpp:524
const interval_t & interval() const
Definition triplex.hpp:225
friend Triplex operator*(Triplex lhs, const Triplex &rhs)
Multiplication of two triplex numbers.
Definition triplex.hpp:433
friend Triplex operator/(Triplex lhs, const Triplex &rhs)
Division of two triplex numbers.
Definition triplex.hpp:449
value_t upper_radius() const
Returns the distance from the nominal value to the upper bound.
Definition triplex.hpp:217
value_t lower() const
Definition triplex.hpp:147
value_t nominal() const
Definition triplex.hpp:163
Triplex & operator+=(const Triplex &rhs)
In-place addition of another triplex.
Definition triplex.hpp:515
typename interval_t::value_t value_t
Definition triplex.hpp:48
bool left_open() const
Definition triplex.hpp:240
bool left_closed() const
Is lower() a member of *this?
Definition triplex.hpp:257
Triplex operator-() const
Negation of a triplex.
Definition triplex.hpp:336
friend Triplex operator-(Triplex lhs, const Triplex &rhs)
Subtraction of two triplex numbers.
Definition triplex.hpp:418
value_t width() const
Returns the distance between the bounds.
Definition triplex.hpp:185
bool operator<=(const Triplex< IntervalType > &lhs, const Triplex< IntervalType > &rhs)
Same ordering as operator<, negated.
Definition triplex.hpp:672
bool operator>=(const Triplex< IntervalType > &lhs, const Triplex< IntervalType > &rhs)
Same ordering as operator<, negated and reversed.
Definition triplex.hpp:680
bool operator<(const Triplex< IntervalType > &lhs, const Triplex< IntervalType > &rhs)
Orders two triplex numbers, primarily by their nominal values.
Definition triplex.hpp:644
Triplex(value_t lower, value_t nominal, value_t upper, bool left_open, bool right_open=false)
Constructs a triplex whose bounds may be open.
Definition triplex.hpp:106
bool operator==(const Triplex< I1 > &lhs, const Triplex< I2 > &rhs)
Compare two triplex numbers for equality.
Definition triplex.hpp:594
Defines the GeneralInterval class.
Defines the Interval class.
Defines the function every triplex operation uses to build its result.
Triplex< IntervalType > make_triplex_(IntervalType bounds, typename IntervalType::value_t nominal)
Assembles a triplex from the result of an operation.
Definition make_triplex.hpp:44
The primary namespace for the sigma library.
Definition affine.hpp:12
Triplex< Interval< double > > TPDouble
Typedef for a triplex with closed double bounds.
Definition triplex.hpp:689
constexpr bool is_general_interval_v
Convenience variable for the value of is_general_interval.
Definition traits.hpp:24
Triplex< Interval< float > > TPFloat
Typedef for a triplex with closed float bounds.
Definition triplex.hpp:686
size_t operator()(const sigma::Triplex< IntervalType > &t) const
Definition triplex.hpp:700
Type traits for the interval types.
Components for compatibility with Eigen.
Convenience header for triplex operations.