|
sigma
1.0.0
|
Models an interval together with a best estimate inside it. More...
#include <triplex.hpp>
Public Types | |
| using | interval_t = IntervalType |
| The type of the bounds. | |
| using | value_t = typename interval_t::value_t |
| The numeric type of the bounds and the nominal value. | |
Public Member Functions | |
| Triplex ()=default | |
| Default constructor. | |
| Triplex (value_t value) | |
| Constructs the degenerate triplex for an exactly known value. | |
| Triplex (value_t lower, value_t nominal, value_t upper) | |
| Constructs a triplex from its bounds and its nominal value. | |
| template<typename I = interval_t, std::enable_if_t< is_general_interval_v< I >, int > = 0> | |
| 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. | |
| Triplex (interval_t interval, value_t nominal) | |
| Constructs a triplex from an interval and a nominal value. | |
| bool | empty () const |
| Is *this the empty triplex? | |
| value_t | lower () const |
| Returns the lower bound. | |
| value_t | nominal () const |
| Returns the nominal value. | |
| value_t | upper () const |
| Returns the upper bound. | |
| value_t | width () const |
| Returns the distance between the bounds. | |
| value_t | median () const |
| Returns the midpoint of the bounds. | |
| value_t | lower_radius () const |
| Returns the distance from the lower bound to the nominal value. | |
| value_t | upper_radius () const |
| Returns the distance from the nominal value to the upper bound. | |
| const interval_t & | interval () const |
| Returns the bounds, discarding the nominal value. | |
| template<typename I = interval_t, std::enable_if_t< is_general_interval_v< I >, int > = 0> | |
| bool | left_open () const |
| Is lower() NOT a member of *this? | |
| template<typename I = interval_t, std::enable_if_t< is_general_interval_v< I >, int > = 0> | |
| bool | left_closed () const |
| Is lower() a member of *this? | |
| template<typename I = interval_t, std::enable_if_t< is_general_interval_v< I >, int > = 0> | |
| bool | right_open () const |
| Is upper() NOT a member of *this? | |
| template<typename I = interval_t, std::enable_if_t< is_general_interval_v< I >, int > = 0> | |
| bool | right_closed () const |
| Is upper() a member of *this? | |
| bool | contains (value_t value) const |
| Whether a scalar lies within the bounds. | |
| bool | contains (const Triplex &other) const |
Whether the bounds of other lie within the bounds of *this. | |
| Triplex | operator- () const |
| Negation of a triplex. | |
| Triplex & | operator+= (const Triplex &rhs) |
| In-place addition of another triplex. | |
| Triplex & | operator-= (const Triplex &rhs) |
| In-place subtraction of another triplex. | |
| Triplex & | operator*= (const Triplex &rhs) |
| In-place multiplication by another triplex. | |
| Triplex & | operator/= (const Triplex &rhs) |
| In-place division by another triplex. | |
Friends | |
| Triplex | operator+ (Triplex lhs, const Triplex &rhs) |
| Addition of two triplex numbers. | |
| Triplex | operator- (Triplex lhs, const Triplex &rhs) |
| Subtraction of two triplex numbers. | |
| Triplex | operator* (Triplex lhs, const Triplex &rhs) |
| Multiplication of two triplex numbers. | |
| Triplex | operator/ (Triplex lhs, const Triplex &rhs) |
| Division of two triplex numbers. | |
| Triplex | detail_::make_triplex_ (interval_t bounds, value_t nominal) |
| Lets make_triplex_ use the unchecked constructor. | |
Related Symbols | |
(Note that these are not member symbols.) | |
| template<typename IntervalType> | |
| std::ostream & | operator<< (std::ostream &os, const Triplex< IntervalType > &t) |
| Overload stream insertion to print a triplex. | |
| template<typename I1, typename I2> | |
| bool | operator== (const Triplex< I1 > &lhs, const Triplex< I2 > &rhs) |
| Compare two triplex numbers for equality. | |
| template<typename I1, typename I2> | |
| bool | operator!= (const Triplex< I1 > &lhs, const Triplex< I2 > &rhs) |
| Compare two triplex numbers for inequality. | |
| template<typename IntervalType> | |
| bool | operator< (const Triplex< IntervalType > &lhs, const Triplex< IntervalType > &rhs) |
| Orders two triplex numbers, primarily by their nominal values. | |
| template<typename IntervalType> | |
| bool | operator> (const Triplex< IntervalType > &lhs, const Triplex< IntervalType > &rhs) |
| Same ordering as operator<, with the operands reversed. | |
| template<typename IntervalType> | |
| bool | operator<= (const Triplex< IntervalType > &lhs, const Triplex< IntervalType > &rhs) |
| Same ordering as operator<, negated. | |
| template<typename IntervalType> | |
| bool | operator>= (const Triplex< IntervalType > &lhs, const Triplex< IntervalType > &rhs) |
| Same ordering as operator<, negated and reversed. | |
Models an interval together with a best estimate inside it.
A triplex number \( \langle a, m, b \rangle \) is an interval \( [a, b] \) plus a distinguished member \( m \) of it, the nominal value. The interval is a rigorous enclosure, computed exactly as IntervalType would compute it. The nominal value is computed in ordinary, round-to-nearest floating point from the operand nominal values, so the nominal value of any triplex computation is the result of the same computation performed with plain value_t on the input nominal values. Nothing ties the nominal value to the median of the interval; in general they differ.
If the scalar computation overflows, or otherwise produces a non-finite value, the nominal value is kept anyway. Such a nominal value is not a member of the interval, and can be detected with std::isfinite(nominal()).
See the Triplex Arithmetic page of the documentation for the full design.
| IntervalType | The type of the bounds: Interval<T> for closed bounds or GeneralInterval<T> for bounds that may be open. |
|
default |
Default constructor.
Constructs the empty triplex, which contains no values and has no nominal value.
| none | No throw guarantee |
|
inline |
Constructs the degenerate triplex for an exactly known value.
| value | The value of the lower bound, the nominal value, and the upper bound. |
| std::domain_error | if value is not finite. Strong throw guarantee. |
|
inline |
Constructs a triplex from its bounds and its nominal value.
The arguments are in the order they are ordered by, and unlike for Interval nothing is reordered. Both bounds are closed.
| lower | The lower bound |
| nominal | The nominal value. Must satisfy lower <= nominal <= upper. |
| upper | The upper bound |
| std::domain_error | if nominal is not a member of the interval [lower, upper], which includes the case lower > upper. Strong throw guarantee. |
|
inline |
Constructs a triplex whose bounds may be open.
Only available when interval_t is a GeneralInterval.
| I | Used to disable this overload for closed intervals. Do not supply it. |
| lower | The lower bound |
| nominal | The nominal value. Must be a member of the interval, so it may not equal an open bound. |
| upper | The upper bound |
| left_open | Is lower just outside the interval? |
| right_open | Is upper just outside the interval? |
| std::domain_error | if nominal is not a member of the interval, which includes the case lower > upper. Strong throw guarantee. |
|
inlineexplicit |
Constructs a triplex from an interval and a nominal value.
There is deliberately no constructor from an interval alone, since it would have to make up a nominal value.
| interval | The bounds of the triplex |
| nominal | The nominal value. Must be a member of interval. |
| std::domain_error | if nominal is not a member of interval, which includes every nominal when interval is empty. Strong throw guarantee. |
|
inline |
Whether the bounds of other lie within the bounds of *this.
The nominal values play no part.
| other | The triplex to test. The empty triplex is contained in every triplex. |
other.interval().| none | No throw guarantee |
|
inline |
Whether a scalar lies within the bounds.
| value | The scalar to test |
value, false otherwise.| none | No throw guarantee |
|
inline |
Is *this the empty triplex?
| none | No throw guarantee |
|
inline |
Returns the bounds, discarding the nominal value.
| none | No throw guarantee |
|
inline |
Is lower() a member of *this?
Only available when interval_t is a GeneralInterval.
| I | Used to disable this overload for closed intervals. Do not supply it. |
| none | No throw guarantee |
|
inline |
Is lower() NOT a member of *this?
Only available when interval_t is a GeneralInterval.
| I | Used to disable this overload for closed intervals. Do not supply it. |
| none | No throw guarantee |
|
inline |
Returns the lower bound.
| std::domain_error | if *this is empty. Strong throw guarantee. |
|
inline |
|
inline |
|
inline |
Returns the nominal value.
The nominal value is the best estimate of the quantity. It is NOT, in general, the midpoint of the bounds (see median()), nor a statistical expectation.
| std::domain_error | if *this is empty. Strong throw guarantee. |
| Triplex< IntervalType > & sigma::Triplex< IntervalType >::operator*= | ( | const Triplex< IntervalType > & | rhs | ) |
In-place multiplication by another triplex.
| rhs | The triplex to multiply by |
| none | No throw guarantee |
| Triplex< IntervalType > & sigma::Triplex< IntervalType >::operator+= | ( | const Triplex< IntervalType > & | rhs | ) |
In-place addition of another triplex.
As for interval_t, the empty triplex is the identity of addition.
| rhs | The triplex to add |
| none | No throw guarantee |
|
inline |
Negation of a triplex.
Negation is exact, so \( -\langle a, m, b \rangle = \langle -b, -m, -a \rangle \), with the openness of the bounds swapped.
| none | No throw guarantee |
| Triplex< IntervalType > & sigma::Triplex< IntervalType >::operator-= | ( | const Triplex< IntervalType > & | rhs | ) |
In-place subtraction of another triplex.
As for interval_t, subtracting from the empty triplex negates rhs.
| rhs | The triplex to subtract |
| none | No throw guarantee |
| Triplex< IntervalType > & sigma::Triplex< IntervalType >::operator/= | ( | const Triplex< IntervalType > & | rhs | ) |
In-place division by another triplex.
As for interval_t, division by an interval containing zero is an error, even when the nominal value of rhs is not zero.
| rhs | The triplex to divide by |
| std::domain_error | if rhs contains zero. Strong throw guarantee. |
|
inline |
Is upper() a member of *this?
Only available when interval_t is a GeneralInterval.
| I | Used to disable this overload for closed intervals. Do not supply it. |
| none | No throw guarantee |
|
inline |
Is upper() NOT a member of *this?
Only available when interval_t is a GeneralInterval.
| I | Used to disable this overload for closed intervals. Do not supply it. |
| none | No throw guarantee |
|
inline |
Returns the upper bound.
| std::domain_error | if *this is empty. Strong throw guarantee. |
|
inline |
|
inline |
Returns the distance between the bounds.
| std::domain_error | if *this is empty. Strong throw guarantee. |
|
Compare two triplex numbers for inequality.
| I1 | The interval type of the left-hand triplex |
| I2 | The interval type of the right-hand triplex |
| lhs | The first triplex |
| rhs | The second triplex |
| none | No throw guarantee |
|
friend |
Multiplication of two triplex numbers.
Either operand may also be a value_t, which is converted.
| lhs | The left-hand triplex |
| rhs | The right-hand triplex |
lhs and rhs | none | No throw guarantee |
|
friend |
Addition of two triplex numbers.
Either operand may also be a value_t, which is converted.
| lhs | The left-hand triplex |
| rhs | The right-hand triplex |
lhs and rhs | none | No throw guarantee |
|
friend |
Subtraction of two triplex numbers.
Either operand may also be a value_t, which is converted.
| lhs | The left-hand triplex |
| rhs | The right-hand triplex |
lhs and rhs | none | No throw guarantee |
|
friend |
Division of two triplex numbers.
Either operand may also be a value_t, which is converted.
| lhs | The left-hand triplex |
| rhs | The right-hand triplex |
lhs and rhs | std::domain_error | if rhs contains zero. Strong throw guarantee. |
|
Orders two triplex numbers, primarily by their nominal values.
As for Interval's ordering by median, this is a total order meant for sorting and not an enclosure relation. Triplex numbers are compared lexicographically by nominal value, then lower bound, then upper bound, and then, for a general triplex, by the openness of the lower and upper bounds, with a closed bound before an open one. The tie-breaks make the order consistent with operator==: neither of two triplex numbers precedes the other exactly when they are equal, so they can be keys of ordered containers. The empty triplex sorts before every non-empty one.
As for plain floating point, a NaN nominal value has no place in the order.
| IntervalType | The interval type of the triplex numbers |
| lhs | The first triplex |
| rhs | The second triplex |
lhs precedes rhs.| none | No throw guarantee |
|
Overload stream insertion to print a triplex.
The triplex is printed as "[lower, nominal, upper]", with a parenthesis in place of the bracket for an open bound. The empty triplex prints as "∅".
| IntervalType | The interval type of the triplex |
| os | The ostream to write to |
| t | The triplex to write |
| std::ios_base::failure | if anything goes wrong while writing. Weak throw guarantee. |
|
Compare two triplex numbers for equality.
Two triplex numbers are equal if their intervals, including the openness of any bound, and their nominal values are equal.
| I1 | The interval type of the left-hand triplex |
| I2 | The interval type of the right-hand triplex |
| lhs | The first triplex |
| rhs | The second triplex |
| none | No throw guarantee |