|
sigma
1.0.0
|
Models an interval whose bounds may be open. More...
#include <general_interval.hpp>
Public Types | |
| using | value_t = ValueType |
| The numeric type of the bounds. | |
| using | closure_t = Interval<value_t> |
| The type of the closure, the closed interval with the same bounds. | |
Public Member Functions | |
| GeneralInterval ()=default | |
| Default constructor. | |
| GeneralInterval (value_t value) | |
| Construct a degenerate interval from a single value. | |
| GeneralInterval (const closure_t &closed) | |
| Construct from a closed interval. | |
| GeneralInterval (value_t lower, value_t upper, bool left_open=false, bool right_open=false) | |
| Construct an interval from two bounds and their openness. | |
| value_t | width () const |
| Returns the distance between the interval's bounds. | |
| value_t | median () const |
| Returns the midpoint of the interval. | |
| value_t | radius () const |
| Returns the half-width of the interval. | |
| bool | empty () const |
| Is *this the empty interval? | |
| bool | left_open () const |
| Is lower() NOT contained in the interval? | |
| bool | left_closed () const |
| Is lower() contained in the interval? | |
| bool | right_open () const |
| Is upper() NOT contained in the interval? | |
| bool | right_closed () const |
| Is upper() contained in the interval? | |
| value_t | lower () const |
| Returns the lower bound of the interval. | |
| value_t | upper () const |
| Returns the upper bound of the interval. | |
| const closure_t & | closure () const |
| Returns the closure of the interval. | |
| bool | contains (value_t value) const |
| Whether a scalar lies in this interval. | |
| bool | contains (const GeneralInterval &other) const |
Is other fully contained in this interval? | |
| GeneralInterval | set_union (const GeneralInterval &other) const |
| Returns the union of this interval and another interval. | |
| GeneralInterval | set_intersection (const GeneralInterval &other) const |
| Returns the intersection of this interval and another interval. | |
| GeneralInterval | operator- () const |
| Negation of an interval. | |
| GeneralInterval & | operator+= (const GeneralInterval &rhs) |
| In-place addition of another interval. | |
| GeneralInterval & | operator-= (const GeneralInterval &rhs) |
| In-place subtraction of another interval. | |
| GeneralInterval & | operator*= (const GeneralInterval &rhs) |
| In-place multiplication by another interval. | |
| GeneralInterval & | operator/= (const GeneralInterval &rhs) |
| In-place division by another interval. | |
| std::string | print_interval_form () const |
| Print the interval in interval form. | |
Friends | |
| GeneralInterval | operator+ (GeneralInterval lhs, const GeneralInterval &rhs) |
| Addition of two intervals. | |
| GeneralInterval | operator- (GeneralInterval lhs, const GeneralInterval &rhs) |
| Subtraction of two intervals. | |
| GeneralInterval | operator* (GeneralInterval lhs, const GeneralInterval &rhs) |
| Multiplication of two intervals. | |
| GeneralInterval | operator/ (GeneralInterval lhs, const GeneralInterval &rhs) |
| Division of two intervals. | |
Related Symbols | |
(Note that these are not member symbols.) | |
| template<typename ValueType> | |
| std::ostream & | operator<< (std::ostream &os, const GeneralInterval< ValueType > &i) |
| Overload stream insertion to print an interval. | |
| template<typename T1, typename T2> | |
| bool | operator== (const GeneralInterval< T1 > &lhs, const GeneralInterval< T2 > &rhs) |
| Compare two intervals for equality. | |
| template<typename T1, typename T2> | |
| bool | operator!= (const GeneralInterval< T1 > &lhs, const GeneralInterval< T2 > &rhs) |
| Compare two intervals for inequality. | |
| template<typename T> | |
| bool | operator< (const GeneralInterval< T > &lhs, const GeneralInterval< T > &rhs) |
| Orders two intervals, primarily by their median. | |
| template<typename T> | |
| bool | operator> (const GeneralInterval< T > &lhs, const GeneralInterval< T > &rhs) |
| Same ordering as operator<, with the operands reversed. | |
| template<typename T> | |
| bool | operator<= (const GeneralInterval< T > &lhs, const GeneralInterval< T > &rhs) |
| Same ordering as operator<, negated. | |
| template<typename T> | |
| bool | operator>= (const GeneralInterval< T > &lhs, const GeneralInterval< T > &rhs) |
| Same ordering as operator<, negated and reversed. | |
| template<typename T> | |
| GeneralInterval< T > | widen (const GeneralInterval< T > &a, typename GeneralInterval< T >::value_t point) |
| Widens an interval just enough to contain a point. | |
Models an interval whose bounds may be open.
Interval represents closed intervals only. GeneralInterval adds the openness of each bound on top of one, so the half-open \( \lbrack a, b) \) and \( (a, b\rbrack \) and the open \( (a, b) \) are representable too. Openness decides which values are members, and nothing else: the width, median, and radius are those of the closure, the closed Interval with the same bounds. An infinite bound is never a member, so it is always open.
An Interval converts implicitly, and losslessly, to a GeneralInterval with both bounds closed (save an infinite one), so arithmetic that mixes the two types promotes to GeneralInterval. The reverse conversion discards information and is spelled out with closure().
| ValueType | The floating-point type of the bounds |
|
default |
Default constructor.
Constructs an empty interval (contains no values).
| none | No throw guarantee |
|
inline |
Construct a degenerate interval from a single value.
| value | The value to set both bounds to. Both bounds are closed, unless value is infinite, in which case the interval is empty. |
| none | No throw guarantee |
|
inline |
Construct from a closed interval.
Every closed interval is a general interval with two closed bounds, so this conversion is implicit and loses nothing. The exception is an infinite bound, which is opened, as for every other constructor.
| closed | The closed interval to convert |
| none | No throw guarantee |
| sigma::GeneralInterval< ValueType >::GeneralInterval | ( | value_t | lower, |
| value_t | upper, | ||
| bool | left_open = false, | ||
| bool | right_open = false ) |
Construct an interval from two bounds and their openness.
For convenience, the bounds are sorted so that lower() <= upper(). An infinite bound is always open, whatever is requested. A single value with an open bound contains nothing, so it constructs the empty interval; this includes a single infinite value.
| lower | The lower bound of the interval |
| upper | The upper bound of the interval |
| left_open | Is lower just outside the interval? |
| right_open | Is upper just outside the interval? |
| none | No throw guarantee |
|
inline |
| bool sigma::GeneralInterval< ValueType >::contains | ( | const GeneralInterval< ValueType > & | other | ) | const |
Is other fully contained in this interval?
| other | The interval to test. The empty interval is contained in every interval. |
other is in *this.| none | No throw guarantee |
| bool sigma::GeneralInterval< ValueType >::contains | ( | value_t | value | ) | const |
Whether a scalar lies in this interval.
Returns true if lower() <= value <= upper(). Equality to lower()/ upper() is only allowed if left_closed()/right_closed() is true, respectively.
| value | The scalar to test |
value lies in the interval represented by *this and false otherwise.| none | No throw guarantee |
|
inline |
Is *this the empty interval?
| none | No throw guarantee |
|
inline |
|
inline |
|
inline |
Returns the lower bound of the interval.
| std::domain_error | if the interval is empty |
|
inline |
Returns the midpoint of the interval.
| std::domain_error | if the interval is empty |
| GeneralInterval< ValueType > & sigma::GeneralInterval< ValueType >::operator*= | ( | const GeneralInterval< ValueType > & | rhs | ) |
In-place multiplication by another interval.
A bound of the product is closed if any of the products of operand bounds that equals it combines two closed bounds, or if it is zero and either operand contains zero.
| rhs | The interval to multiply by |
| none | No throw guarantee |
| GeneralInterval< ValueType > & sigma::GeneralInterval< ValueType >::operator+= | ( | const GeneralInterval< ValueType > & | rhs | ) |
In-place addition of another interval.
A bound of the sum is open if either bound that produced it is.
| rhs | The interval to add |
| none | No throw guarantee |
|
inline |
Negation of an interval.
Given the interval [a, b], the negation is [-b, -a]. The openness of the bounds is reversed, e.g., [a, b) becomes (-b, -a].
| none | No throw guarantee |
|
inline |
In-place subtraction of another interval.
| rhs | The interval to subtract |
| none | No throw guarantee |
| GeneralInterval< ValueType > & sigma::GeneralInterval< ValueType >::operator/= | ( | const GeneralInterval< ValueType > & | rhs | ) |
In-place division by another interval.
A divisor merely bounded by an open zero, such as \( (0, 1\rbrack \), does not contain zero and is divided by normally; the quotient is then unbounded on that side. A bound of the quotient is closed under the same rule as for multiplication, except that a zero bound is closed when the dividend contains zero.
| rhs | The interval to divide by |
| std::domain_error | if rhs contains zero. Strong throw guarantee. |
| std::string sigma::GeneralInterval< ValueType >::print_interval_form | ( | ) | const |
Print the interval in interval form.
The interval is printed in the form where closed bounds are represented by square brackets and open bounds are represented by parentheses.
| none | No throw guarantee |
|
inline |
Returns the half-width of the interval.
| std::domain_error | if the interval is empty |
|
inline |
|
inline |
| GeneralInterval< ValueType > sigma::GeneralInterval< ValueType >::set_intersection | ( | const GeneralInterval< ValueType > & | other | ) | const |
Returns the intersection of this interval and another interval.
| other | The interval to intersect with |
other | none | No throw guarantee. |
| GeneralInterval< ValueType > sigma::GeneralInterval< ValueType >::set_union | ( | const GeneralInterval< ValueType > & | other | ) | const |
Returns the union of this interval and another interval.
Because the result must be an interval, union is only defined when there is no gap between the intervals: they must overlap, or touch at a point that at least one of them contains, as in \( \lbrack 0, 1) \cup [1, 2] = [0, 2] \).
| other | The interval to union with |
other | std::domain_error | if there is a gap between the intervals. Strong throw guarantee. |
|
inline |
Returns the upper bound of the interval.
| std::domain_error | if the interval is empty |
|
inline |
Returns the distance between the interval's bounds.
The width does NOT depend on the openness of the bounds.
| std::domain_error | if the interval is empty |
|
Compare two intervals for inequality.
| T1 | The numerical type of the left-hand interval |
| T2 | The numerical type of the right-hand interval |
| lhs | The first interval |
| rhs | The second interval |
|
friend |
Multiplication of two intervals.
Either operand may also be an Interval or a scalar, which is converted.
| lhs | The left-hand interval |
| rhs | The right-hand interval |
lhs and rhs | none | No throw guarantee |
|
friend |
Addition of two intervals.
Either operand may also be an Interval or a scalar, which is converted.
| lhs | The left-hand interval |
| rhs | The right-hand interval |
lhs and rhs | none | No throw guarantee |
|
friend |
Subtraction of two intervals.
Either operand may also be an Interval or a scalar, which is converted.
| lhs | The left-hand interval |
| rhs | The right-hand interval |
lhs and rhs | none | No throw guarantee |
|
friend |
Division of two intervals.
Either operand may also be an Interval or a scalar, which is converted.
| lhs | The left-hand interval |
| rhs | The right-hand interval |
lhs and rhs | std::domain_error | if rhs contains zero. Strong throw guarantee. |
|
Orders two intervals, primarily by their median.
The same deliberately weak, total ordering as for Interval, meant only for consumers that need some consistent ordering to sort by and not a rigorous enclosure relation: the closures are compared first. Intervals with the same closure are then ordered by the openness of the lower bound and then of the upper bound, with a closed bound before an open one, so that, as for Interval, neither of two intervals precedes the other exactly when they are equal. The empty interval sorts before every non-empty one.
| T | The numerical type of the bounds |
| lhs | The first interval |
| rhs | The second interval |
lhs precedes rhs.| none | No throw guarantee |
|
Overload stream insertion to print an interval.
| ValueType | The numerical type of the bounds |
| os | The ostream to write to |
| i | The interval to write |
| std::ios_base::failure | if anything goes wrong while writing. Weak throw guarantee. |
|
Compare two intervals for equality.
Two intervals are equal if they have the same bounds and the same openness.
| T1 | The numerical type of the left-hand interval |
| T2 | The numerical type of the right-hand interval |
| lhs | The first interval |
| rhs | The second interval |
|
Widens an interval just enough to contain a point.
As for widen(const Interval<T>&, T), except that point may also lie on an open bound of a. Either way, the bound that point moves or lands on is closed.
| T | The numerical type of the bounds |
| a | The interval to widen |
| point | The value the result must contain. An infinite or NaN value is never a member of an interval, so for one of those the result cannot contain point. |
a if it already contains point. Otherwise a with the bound on the side of point moved to point and closed; the degenerate interval [point, point] if a is empty.| none | No throw guarantee |