codac 2.0.5
Loading...
Searching...
No Matches
codac2::Interval Class Reference

Interval class, for representing closed and connected subsets of \(\mathbb{R}\). More...

#include <codac2_Interval.h>

Inheritance diagram for codac2::Interval:
codac2::TSlice

Public Member Functions

 Interval ()
 Creates an interval \([-\infty,\infty]\).
 Interval (double a)
 Creates a degenerate interval \([a,a]\), \(a\in\mathbb{R}\).
 Interval (double a, double b)
 Creates an interval \([a,b]\), \(a\in\mathbb{R}, b\in\mathbb{R}\).
 Interval (const Interval &x)
 Creates an interval from another one.
 Interval (const std::array< double, 1 > &array)
 Create an interval \([a,a]\) from a fixed-sized array of size 1.
 Interval (const std::array< double, 2 > &array)
 Create an interval \([a,b]\) from a fixed-sized array of size 2.
 Interval (std::initializer_list< double > l)
 Create an interval as the hull of a list of values.
Intervalinit ()
 Sets the value of this interval to [-oo,oo].
Intervalinit (const Interval &x)
 Sets the value of this interval to x.
Intervalinit_from_list (const std::list< double > &l)
 Sets the bounds as the hull of a list of values.
Intervaloperator= (double x)
 Sets this to x.
Intervaloperator= (const Interval &x)
 Sets this to x.
bool operator== (const Interval &x) const
 Comparison (equality) between two intervals.
bool operator!= (const Interval &x) const
 Comparison (non equality) between two intervals.
BoolInterval operator< (const Interval &x) const
 Comparison (strict less-than) between this and x.
BoolInterval operator> (const Interval &x) const
 Comparison (strict greater-than) between this and x.
double lb () const
 Returns the lower bound of this.
double ub () const
 Returns the upper bound of this.
double mid () const
 Returns the midpoint of this.
double mag () const
 Returns the magnitude of this i.e. max(|lower bound|, |upper bound|).
double mig () const
 Returns the mignitude of this.
double smag () const
 Returns the signed magnitude of this i.e. lower bound if |lower bound|>|upper bound|, upper bound otherwise.
double smig () const
 Returns the signed mignitude of this.
double rand () const
 Returns a random value inside the interval.
double rad () const
 Returns the radius of this.
double diam () const
 Returns the diameter of this.
double volume () const
 Returns the diameter of this.
Index size () const
 Returns the dimension of this (which is always ).
void set_empty ()
 Sets this interval to the empty set.
bool is_empty () const
 Tests if this is empty.
bool contains (const double &x) const
 Tests if this contains x.
bool interior_contains (const double &x) const
 Tests if the interior of this contains x.
bool is_unbounded () const
 Tests if one of the bounds of this is infinite.
bool is_degenerated () const
 Tests if this is degenerated, that is, in the form of \([a,a]\).
bool is_integer () const
 Tests if this is an integer, that is, in the form of \([n,n]\) where n is an integer.
bool has_integer_bounds () const
 Checks whether the interval has integer lower and upper bounds.
bool intersects (const Interval &x) const
 Tests if this and x intersect.
bool is_disjoint (const Interval &x) const
 Tests if this and x do not intersect.
bool overlaps (const Interval &x) const
 Tests if this and x intersect and their intersection has a non-null volume.
bool is_subset (const Interval &x) const
 Tests if this is a subset of x.
bool is_strict_subset (const Interval &x) const
 Tests if this is a subset of x and not x itself.
bool is_interior_subset (const Interval &x) const
 Tests if this is in the interior of x.
bool is_strict_interior_subset (const Interval &x) const
 Tests if this is in the interior of x and different from x.
bool is_superset (const Interval &x) const
 Tests if this is a superset of x.
bool is_strict_superset (const Interval &x) const
 Tests if this is a superset of x and different from x.
Intervalinflate (const double &rad)
 Adds [-rad,+rad] to this.
bool is_bisectable () const
 Tests if this can be bisected into two non-degenerated intervals.
std::pair< Interval, Intervalbisect (float ratio=0.49) const
 Bisects this into two subintervals.
std::vector< Intervalcomplementary (bool compactness=true) const
 Computes the complementary of this.
std::vector< Intervaldiff (const Interval &y, bool compactness=true) const
 Computes the result of \([x]\backslash[y]\).
Intervaloperator|= (const Interval &x)
 Self union of this and x.
Intervaloperator&= (const Interval &x)
 Self intersection of this and x.
Intervaloperator+= (double x)
 Self addition of this and a real x.
Intervaloperator+= (const Interval &x)
 Self addition of this and x.
Interval operator- () const
 Substraction of this.
Intervaloperator-= (double x)
 Self substraction of this and a real x.
Intervaloperator-= (const Interval &x)
 Self substraction of this and x.
Intervaloperator*= (double x)
 Self multiplication of this and a real x.
Intervaloperator*= (const Interval &x)
 Self multiplication of this and x.
Intervaloperator/= (double x)
 Self division of this and a real x.
Intervaloperator/= (const Interval &x)
 Self division of this and x.

Static Public Member Functions

static Interval empty ()
 Provides an empty interval.
static Interval zero ()
 Provides an interval for \([0]\).
static Interval one ()
 Provides an interval for \([1]\).
static Interval half_pi ()
 Provides an interval for \([\frac{\pi}{2}]\).
static Interval pi ()
 Provides an interval for \([\pi]\).
static Interval two_pi ()
 Provides an interval for \([2\pi]\).

Detailed Description

Interval class, for representing closed and connected subsets of \(\mathbb{R}\).

The class also encapsulates the interval representation provided by the Gaol library.

This class reuses several functions developed for ibex::Interval. See ibex::Interval (IBEX lib, main author: Gilles Chabert) https://ibex-lib.readthedocs.io

Constructor & Destructor Documentation

◆ Interval() [1/6]

codac2::Interval::Interval ( double a)
inline

Creates a degenerate interval \([a,a]\), \(a\in\mathbb{R}\).

Parameters
asingle value contained in the resulting interval
28 : gaol::interval(a)
29 {
30 if(a == -oo || a == oo)
31 set_empty();
32 }
void set_empty()
Sets this interval to the empty set.
Definition codac2_Interval_impl.h:216

◆ Interval() [2/6]

codac2::Interval::Interval ( double a,
double b )
inline

Creates an interval \([a,b]\), \(a\in\mathbb{R}, b\in\mathbb{R}\).

Parameters
alower bound of the interval
bupper bound of the interval
35 : gaol::interval(a,b)
36 { }

◆ Interval() [3/6]

codac2::Interval::Interval ( const Interval & x)
inline

Creates an interval from another one.

Parameters
xthe interval to be copied
39 : gaol::interval(x)
40 { }

◆ Interval() [4/6]

codac2::Interval::Interval ( const std::array< double, 1 > & array)
inlineexplicit

Create an interval \([a,a]\) from a fixed-sized array of size 1.

Parameters
arraythe array of doubles
43 : Interval(array[0])
44 { }
Interval()
Creates an interval .
Definition codac2_Interval_impl.h:23

◆ Interval() [5/6]

codac2::Interval::Interval ( const std::array< double, 2 > & array)
inlineexplicit

Create an interval \([a,b]\) from a fixed-sized array of size 2.

Parameters
arraythe array of doubles
47 : Interval(array[0],array[1])
48 { }

◆ Interval() [6/6]

codac2::Interval::Interval ( std::initializer_list< double > l)
inline

Create an interval as the hull of a list of values.

Parameters
llist of values contained in the resulting interval
51 : Interval()
52 {
54 }
Interval & init_from_list(const std::list< double > &l)
Sets the bounds as the hull of a list of values.
Definition codac2_Interval_impl.h:68

Member Function Documentation

◆ init() [1/2]

Interval & codac2::Interval::init ( )
inline

Sets the value of this interval to [-oo,oo].

Note
This function is used for template purposes.
Returns
a reference to this
57 {
58 *this = Interval(-oo,oo);
59 return *this;
60 }

◆ init() [2/2]

Interval & codac2::Interval::init ( const Interval & x)
inline

Sets the value of this interval to x.

Note
This function is used for template purposes.
Parameters
xthe value for re-initialization
Returns
a reference to this
63 {
64 *this = x;
65 return *this;
66 }

◆ init_from_list()

Interval & codac2::Interval::init_from_list ( const std::list< double > & l)
inline

Sets the bounds as the hull of a list of values.

Note
This function is separated from the constructor for py binding purposes.
Parameters
llist of values contained in the resulting interval
Returns
a reference to this
69 {
70 if(l.size() == 1)
71 *this = Interval(*l.begin());
72
73 else if(l.size() == 2)
74 *this = Interval(*l.begin(),*std::prev(l.end()));
75
76 else
77 {
78 assert_release("'Interval' can only be defined by one or two 'double' values.");
79 }
80
81 return *this;
82 }

◆ operator=() [1/2]

Interval & codac2::Interval::operator= ( double x)
inline

Sets this to x.

Parameters
xreal to be intervalized
Returns
a reference to this
85 {
86 if(x == -oo || x == oo)
87 set_empty();
88 else
89 gaol::interval::operator=(x);
90
91 return *this;
92 }

◆ operator=() [2/2]

Interval & codac2::Interval::operator= ( const Interval & x)
inline

Sets this to x.

Parameters
xinterval to be copied
Returns
a reference to this
95 {
96 gaol::interval::operator=(x);
97 return *this;
98 }

◆ operator==()

bool codac2::Interval::operator== ( const Interval & x) const
inline

Comparison (equality) between two intervals.

Parameters
xinterval to be compared with
Returns
true iff this and x are exactly the same intervals
101 {
102 return (is_empty() && x.is_empty()) || (lb() == x.lb() && ub() == x.ub());
103 }
bool is_empty() const
Tests if this is empty.
Definition codac2_Interval_impl.h:221
double ub() const
Returns the upper bound of this.
Definition codac2_Interval_impl.h:131
double lb() const
Returns the lower bound of this.
Definition codac2_Interval_impl.h:126

◆ operator!=()

bool codac2::Interval::operator!= ( const Interval & x) const
inline

Comparison (non equality) between two intervals.

Parameters
xinterval to be compared with
Returns
true iff this and x are not exactly the same intervals
106 {
107 return !(*this == x);
108 }

◆ operator<()

BoolInterval codac2::Interval::operator< ( const Interval & x) const
inline

Comparison (strict less-than) between this and x.

The returned BoolInterval encloses the truth value of \(t<s\) for \(t\in[\mathrm{this}]\) and \(s\in[x]\).

Note
Returns:
  • BoolInterval::EMPTY if this or x is empty
  • BoolInterval::TRUE iff \(\mathrm{ub}([\mathrm{this}])<\mathrm{lb}([x])\)
  • BoolInterval::FALSE iff \(\mathrm{ub}([x])\leq\mathrm{lb}([\mathrm{this}])\)
  • BoolInterval::UNKNOWN otherwise
Parameters
xinterval to be compared with
Returns
interval Boolean result
111 {
112 if(is_empty() || x.is_empty())
113 return BoolInterval::EMPTY;
114 if(this->ub() < x.lb())
115 return BoolInterval::TRUE;
116 if(x.ub() <= this->lb())
117 return BoolInterval::FALSE;
119 }
@ UNKNOWN
Definition codac2_BoolInterval.h:32
@ EMPTY
Definition codac2_BoolInterval.h:30

◆ operator>()

BoolInterval codac2::Interval::operator> ( const Interval & x) const
inline

Comparison (strict greater-than) between this and x.

The returned BoolInterval encloses the truth value of \(t>s\) for \(t\in[\mathrm{this}]\) and \(s\in[x]\).

Note
Returns:
  • BoolInterval::EMPTY if this or x is empty
  • BoolInterval::TRUE iff \(\mathrm{lb}([\mathrm{this}])>\mathrm{ub}([x])\)
  • BoolInterval::FALSE iff \(\mathrm{lb}([x])\geq\mathrm{ub}([\mathrm{this}])\)
  • BoolInterval::UNKNOWN otherwise
Parameters
xinterval to be compared with
Returns
interval Boolean result
122 {
123 return x < *this;
124 }

◆ lb()

double codac2::Interval::lb ( ) const
inline

Returns the lower bound of this.

Returns
lower bound
127 {
128 return gaol::interval::left();
129 }

◆ ub()

double codac2::Interval::ub ( ) const
inline

Returns the upper bound of this.

Returns
upper bound
132 {
133 return gaol::interval::right();
134 }

◆ mid()

double codac2::Interval::mid ( ) const
inline

Returns the midpoint of this.

Note
The return point is guaranteed to be included in this but not necessarily to be the closest floating point from the real midpoint. In particular, cases are:
  • [empty] -> Quiet NaN
  • [-oo,+oo] -> mid = 0.0
  • [-oo,b] -> mid = -MAXREAL
  • [a,+oo] -> mid = MAXREAL
  • [a,b] -> mid ~ a + .5*(b-a)
Returns
midpoint
137 {
138 double m = gaol::interval::midpoint();
139 gaol::round_upward();
140 return m;
141 }

◆ mag()

double codac2::Interval::mag ( ) const
inline

Returns the magnitude of this i.e. max(|lower bound|, |upper bound|).

Returns
the magnitude of the interval
144 {
145 return gaol::interval::mag();
146 }

◆ mig()

double codac2::Interval::mig ( ) const
inline

Returns the mignitude of this.

+(lower bound) if lower_bound > 0 -(upper bound) if upper_bound < 0 0 otherwise.

Returns
the mignitude of the interval
149 {
150 return gaol::interval::mig();
151 }

◆ smag()

double codac2::Interval::smag ( ) const
inline

Returns the signed magnitude of this i.e. lower bound if |lower bound|>|upper bound|, upper bound otherwise.

Returns
the signed magnitude of the interval
154 {
155 return (abs(lb()) > abs(ub())) ? lb() : ub();
156 }
Interval abs(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:264

◆ smig()

double codac2::Interval::smig ( ) const
inline

Returns the signed mignitude of this.

lower bound if lower_bound > 0, upper bound if upper_bound < 0, 0 otherwise.

Returns
the signed mignitude of the interval
159 {
160 return gaol::interval::smig();
161 }

◆ rand()

double codac2::Interval::rand ( ) const
inline

Returns a random value inside the interval.

Note
The seed of the pseudo-random number generator is voluntarily initialized outside this function, on demand.
In case of infinite bounds, only floating point values can be returned.
Returns
random value
164 {
165 if(is_empty())
166 return std::numeric_limits<double>::quiet_NaN();
167
168 double a = std::max<double>(next_float(-oo),lb());
169 double b = std::min<double>(prev_float(oo),ub());
170 double r = a + (((double)std::rand())/(double)RAND_MAX)*(b-a);
171 // The above operation may result in a floating point outside the bounds,
172 // due to floating-point errors. Such possible error is corrected below:
173 return std::max<double>(lb(),std::min<double>(r,ub()));
174 }
double prev_float(double x)
Returns the previous representable double-precision floating-point value before x.
Definition codac2_Interval_impl.h:630
double next_float(double x)
Returns the next representable double-precision floating-point value after x.
Definition codac2_Interval_impl.h:635

◆ rad()

double codac2::Interval::rad ( ) const
inline

Returns the radius of this.

Returns
the radius, or 0 if this is empty
177 {
178 if(is_empty())
179 return std::numeric_limits<double>::quiet_NaN();
180
181 else if(is_unbounded())
182 return oo;
183
184 else
185 {
186 double t = mid();
187 double t1 = (t-*this).ub();
188 double t2 = (*this-t).ub();
189 return (t1>t2) ? t1 : t2;
190 }
191 }
bool is_unbounded() const
Tests if one of the bounds of this is infinite.
Definition codac2_Interval_impl.h:236
double mid() const
Returns the midpoint of this.
Definition codac2_Interval_impl.h:136

◆ diam()

double codac2::Interval::diam ( ) const
inline

Returns the diameter of this.

Returns
the diameter, or 0 if this is empty
194 {
195 if(is_empty())
196 return std::numeric_limits<double>::quiet_NaN();
197
198 else
199 {
200 double d = gaol::interval::width();
201 gaol::round_upward();
202 return d;
203 }
204 }

◆ volume()

double codac2::Interval::volume ( ) const
inline

Returns the diameter of this.

Note
This function is used for template purposes. See diam()
Returns
the diameter, or 0 if this is empty
207 {
208 return diam();
209 }
double diam() const
Returns the diameter of this.
Definition codac2_Interval_impl.h:193

◆ size()

Index codac2::Interval::size ( ) const
inline

Returns the dimension of this (which is always ).

Note
This function is used for template purposes.
Returns
1
212 {
213 return 1;
214 }

◆ is_empty()

bool codac2::Interval::is_empty ( ) const
inline

Tests if this is empty.

Returns
true in case of empty set
222 {
223 return gaol::interval::is_empty();
224 }

◆ contains()

bool codac2::Interval::contains ( const double & x) const
inline

Tests if this contains x.

Note
x can also be an "open bound", i.e., infinity. So this function is not restricted to a set-membership interpretation.
Parameters
xreal value
Returns
true if this contains x
227 {
228 return gaol::interval::set_contains(x);
229 }

◆ interior_contains()

bool codac2::Interval::interior_contains ( const double & x) const
inline

Tests if the interior of this contains x.

Parameters
xreal value
Returns
true if the interior of this contains x
232 {
233 return !is_empty() && x > lb() && x < ub();
234 }

◆ is_unbounded()

bool codac2::Interval::is_unbounded ( ) const
inline

Tests if one of the bounds of this is infinite.

Note
An empty interval is always bounded
Returns
true if of the bounds of this is infinite
237 {
238 return !gaol::interval::is_finite();
239 }

◆ is_degenerated()

bool codac2::Interval::is_degenerated ( ) const
inline

Tests if this is degenerated, that is, in the form of \([a,a]\).

Note
An empty interval is considered here as degenerated
Returns
true if this is degenerated
242 {
243 return is_empty() || gaol::interval::is_a_double();
244 }

◆ is_integer()

bool codac2::Interval::is_integer ( ) const
inline

Tests if this is an integer, that is, in the form of \([n,n]\) where n is an integer.

Returns
true if this is an integer singleton
247 {
248 return gaol::interval::is_an_int();
249 }

◆ has_integer_bounds()

bool codac2::Interval::has_integer_bounds ( ) const
inline

Checks whether the interval has integer lower and upper bounds.

Returns
true if this has integer lower and upper bounds; false otherwise.
252 {
253 return trunc(lb()) == lb() && trunc(ub()) == ub();
254 }

◆ intersects()

bool codac2::Interval::intersects ( const Interval & x) const
inline

Tests if this and x intersect.

Parameters
xthe other interval
Returns
true if the intervals intersect
257 {
258 return !is_empty() && !x.is_empty() && lb() <= x.ub() && ub() >= x.lb();
259 }

◆ is_disjoint()

bool codac2::Interval::is_disjoint ( const Interval & x) const
inline

Tests if this and x do not intersect.

Parameters
xthe other interval
Returns
true if the intervals are disjoint
262 {
263 return is_empty() || x.is_empty() || lb() > x.ub() || ub() < x.lb();
264 }

◆ overlaps()

bool codac2::Interval::overlaps ( const Interval & x) const
inline

Tests if this and x intersect and their intersection has a non-null volume.

Parameters
xthe other interval
Returns
true if some interior points (of this or x) belong to their intersection
267 {
268 return !is_empty() && !x.is_empty() && ub() > x.lb() && x.ub() > lb();
269 }

◆ is_subset()

bool codac2::Interval::is_subset ( const Interval & x) const
inline

Tests if this is a subset of x.

Note
If this is empty, always returns true
Parameters
xthe other interval
Returns
true iff this interval is a subset of x
272 {
273 return is_empty() || (!x.is_empty() && x.lb() <= lb() && x.ub() >= ub());
274 }

◆ is_strict_subset()

bool codac2::Interval::is_strict_subset ( const Interval & x) const
inline

Tests if this is a subset of x and not x itself.

Note
In particular, \([-\infty,\infty]\) is not a strict subset of \([-\infty,\infty]\) and \(\varnothing\) is not a strict subset of \(\varnothing\), although in both cases, the first is inside the interior of the second.
Parameters
xthe other interval
Returns
true iff this interval is a strict subset of x
277 {
278 return !x.is_empty() && (is_empty() || (x.lb() < lb() && x.ub() >= ub()) || (x.ub() > ub() && x.lb() <= lb()));
279 }

◆ is_interior_subset()

bool codac2::Interval::is_interior_subset ( const Interval & x) const
inline

Tests if this is in the interior of x.

Note
In particular, \([-\infty,\infty]\) is in the interior of \([-\infty,\infty]\) and \(\varnothing\) is in the interior of \(\varnothing\).
Parameters
xthe other interval
Returns
true iff this interval is in the interior of x
282 {
283 return is_empty() || (!x.is_empty() && (x.lb() == -oo || x.lb() < lb()) && (x.ub() == oo || x.ub() > ub()));
284 }

◆ is_strict_interior_subset()

bool codac2::Interval::is_strict_interior_subset ( const Interval & x) const
inline

Tests if this is in the interior of x and different from x.

Note
In particular, \([-\infty,\infty]\) is not strictly in the interior of \([-\infty,\infty]\) and \(\varnothing\) is not strictly in the interior of \(\varnothing\).
Parameters
xthe other interval
Returns
true iff this interval is a strict interior subset of x
287 {
288 return !x.is_empty() && (is_empty() || (
289 (x.lb() < lb() && (x.ub() == oo || x.ub() > ub()))
290 || (x.ub() > ub() && (x.lb() == -oo || x.lb() < lb()))
291 ));
292 }

◆ is_superset()

bool codac2::Interval::is_superset ( const Interval & x) const
inline

Tests if this is a superset of x.

Note
If this is empty, always returns true
Parameters
xthe other interval
Returns
true iff this interval is a superset of x
295 {
296 return x.is_subset(*this);
297 }

◆ is_strict_superset()

bool codac2::Interval::is_strict_superset ( const Interval & x) const
inline

Tests if this is a superset of x and different from x.

See also
is_strict_subset()
Parameters
xthe other interval
Returns
true iff this interval is a strict superset of x
300 {
301 return x.is_strict_subset(*this);
302 }

◆ inflate()

Interval & codac2::Interval::inflate ( const double & rad)
inline

Adds [-rad,+rad] to this.

Parameters
radthe radius of the inflation
Returns
a reference to this
305 {
306 (*this) += Interval(-rad,rad);
307 return *this;
308 }
double rad() const
Returns the radius of this.
Definition codac2_Interval_impl.h:176

◆ is_bisectable()

bool codac2::Interval::is_bisectable ( ) const
inline

Tests if this can be bisected into two non-degenerated intervals.

Note
Examples of non bisectable intervals are [0,next_float(0)] or [DBL_MAX,+oo).
Returns
true iff this can be bisected
311 {
312 if(is_empty())
313 return false;
314 double m = mid();
315 return lb() < m && m < ub();
316 }

◆ bisect()

std::pair< Interval, Interval > codac2::Interval::bisect ( float ratio = 0.49) const
inline

Bisects this into two subintervals.

Precondition
is_bisectable() must be true
0 < ratio < 1
Parameters
ratiooptional proportion of split (0.5 corresponds to middle)
Returns
a pair of resulting subintervals
319 {
320 assert_release(is_bisectable());
321 assert_release(Interval(0,1).interior_contains(ratio));
322
323 if(lb() == -oo)
324 {
325 if(ub() == oo)
326 return { Interval(-oo,0), Interval(0,oo) };
327 else
328 return { Interval(-oo,-std::numeric_limits<double>::max()), Interval(-std::numeric_limits<double>::max(),ub()) };
329 }
330
331 else if(ub() == oo)
332 return { Interval(lb(),std::numeric_limits<double>::max()), Interval(std::numeric_limits<double>::max(),oo) };
333
334 else
335 {
336 double m;
337
338 if(ratio == 0.5)
339 m = mid();
340
341 else
342 {
343 m = lb() + ratio*diam();
344 if(m >= ub())
345 m = next_float(lb());
346
347 assert(m < ub());
348 }
349
350 return { Interval(lb(),m), Interval(m,ub()) };
351 }
352 }
bool is_bisectable() const
Tests if this can be bisected into two non-degenerated intervals.
Definition codac2_Interval_impl.h:310
bool interior_contains(const double &x) const
Tests if the interior of this contains x.
Definition codac2_Interval_impl.h:231

◆ complementary()

std::vector< Interval > codac2::Interval::complementary ( bool compactness = true) const
inline

Computes the complementary of this.

Parameters
compactnessoptional boolean to obtain or not disjoint intervals
Returns
a vector of complementary intervals
355 {
356 if(is_empty() || (compactness && is_degenerated()))
357 return { {-oo,oo} };
358
359 std::vector<Interval> l;
360
361 if(lb() > -oo)
362 l.push_back({-oo,lb()});
363
364 if(ub() < oo)
365 l.push_back({ub(),oo});
366
367 return l;
368 }
bool is_degenerated() const
Tests if this is degenerated, that is, in the form of .
Definition codac2_Interval_impl.h:241

◆ diff()

std::vector< Interval > codac2::Interval::diff ( const Interval & y,
bool compactness = true ) const
inline

Computes the result of \([x]\backslash[y]\).

Parameters
yinterval to remove from this
compactnessoptional boolean to obtain or not disjoint intervals
Returns
a vector of resulting diff intervals
371 {
372 if(compactness && is_degenerated())
373 {
374 if(is_empty() || y.contains(lb()))
375 return {};
376 else
377 return { *this };
378 }
379
380 std::vector<Interval> l;
381 for(const auto& li : y.complementary(compactness))
382 {
383 Interval inter = li & *this;
384 if(!inter.is_degenerated())
385 l.push_back(inter);
386 }
387
388 return l;
389 }

◆ operator|=()

Interval & codac2::Interval::operator|= ( const Interval & x)
inline

Self union of this and x.

Parameters
xthe other interval
Returns
a reference to this
508 {
509 gaol::interval::operator|=(x);
510 return *this;
511 }

◆ operator&=()

Interval & codac2::Interval::operator&= ( const Interval & x)
inline

Self intersection of this and x.

Parameters
xthe other interval
Returns
a reference to this
514 {
515 gaol::interval::operator&=(x);
516 return *this;
517 }

◆ operator+=() [1/2]

Interval & codac2::Interval::operator+= ( double x)
inline

Self addition of this and a real x.

Parameters
xthe real to add
Returns
a reference to this
520 {
521 if(x == -oo || x == oo)
522 set_empty();
523 else
524 gaol::interval::operator+=(x);
525 return *this;
526 }

◆ operator+=() [2/2]

Interval & codac2::Interval::operator+= ( const Interval & x)
inline

Self addition of this and x.

Parameters
xthe other interval
Returns
a reference to this
529 {
530 gaol::interval::operator+=(x);
531 return *this;
532 }

◆ operator-()

Interval codac2::Interval::operator- ( ) const
inline

Substraction of this.

Returns
(- this)
535 {
536 return 0.-*this;
537 }

◆ operator-=() [1/2]

Interval & codac2::Interval::operator-= ( double x)
inline

Self substraction of this and a real x.

Parameters
xthe real to substract
Returns
a reference to this
540 {
541 if(x == -oo || x == oo)
542 set_empty();
543 else
544 gaol::interval::operator-=(x);
545 return *this;
546 }

◆ operator-=() [2/2]

Interval & codac2::Interval::operator-= ( const Interval & x)
inline

Self substraction of this and x.

Parameters
xthe other interval
Returns
a reference to this
549 {
550 gaol::interval::operator-=(x);
551 return *this;
552 }

◆ operator*=() [1/2]

Interval & codac2::Interval::operator*= ( double x)
inline

Self multiplication of this and a real x.

Parameters
xthe real to multiply
Returns
a reference to this
555 {
556 if(x == -oo || x == oo)
557 set_empty();
558 else
559 gaol::interval::operator*=(x);
560 return *this;
561 }

◆ operator*=() [2/2]

Interval & codac2::Interval::operator*= ( const Interval & x)
inline

Self multiplication of this and x.

Parameters
xthe other interval
Returns
a reference to this
564 {
565 gaol::interval::operator*=(x);
566 return *this;
567 }

◆ operator/=() [1/2]

Interval & codac2::Interval::operator/= ( double x)
inline

Self division of this and a real x.

Parameters
xthe real to divide
Returns
a reference to this
570 {
571 if(x == -oo || x == oo)
572 set_empty();
573 else
574 gaol::interval::operator/=(x);
575 return *this;
576 }

◆ operator/=() [2/2]

Interval & codac2::Interval::operator/= ( const Interval & x)
inline

Self division of this and x.

Note
This computation is more efficient than the non-self div operator, because it calculates the union of this/x as intermediate result.
Parameters
xthe other interval
Returns
a reference to this
579 {
580 gaol::interval::operator/=(x);
581 return *this;
582 }

◆ empty()

Interval codac2::Interval::empty ( )
inlinestatic

Provides an empty interval.

Returns
an empty set
585 {
586 return std::numeric_limits<double>::quiet_NaN();
587 }

◆ zero()

Interval codac2::Interval::zero ( )
inlinestatic

Provides an interval for \([0]\).

Returns
an interval containing \(0\)
590 {
591 return gaol::interval::zero();
592 }

◆ one()

Interval codac2::Interval::one ( )
inlinestatic

Provides an interval for \([1]\).

Returns
an interval containing \(1\)
595 {
596 return gaol::interval::one();
597 }

◆ half_pi()

Interval codac2::Interval::half_pi ( )
inlinestatic

Provides an interval for \([\frac{\pi}{2}]\).

Returns
an interval containing \(\frac{\pi}{2}\)
600 {
601 return gaol::interval::half_pi();
602 }

◆ pi()

Interval codac2::Interval::pi ( )
inlinestatic

Provides an interval for \([\pi]\).

Returns
an interval containing \(\pi\)
605 {
606 return gaol::interval::pi();
607 }

◆ two_pi()

Interval codac2::Interval::two_pi ( )
inlinestatic

Provides an interval for \([2\pi]\).

Returns
an interval containing \(2\pi\)
610 {
611 return gaol::interval::two_pi();
612 }

The documentation for this class was generated from the following files: