codac 1.5.6
Loading...
Searching...
No Matches
codac2_Interval.h
Go to the documentation of this file.
1
14
15#pragma once
16
17#include <list>
18#include <array>
19#include <3rd/gaol/gaol_interval.h>
20#include "codac2_Index.h"
21#include "codac2_Domain.h"
22#include "codac2_assert.h"
23#include "codac2_TypeInfo.h"
24
25namespace codac2
26{
27 const double oo = []() {
28
29 // (from IBEX lib, main author: Gilles Chabert)
30 // We use Gaol not in PRESERVE_ROUNDING mode, thus
31 // assuming the rounding mode is always set upward.
32 // Calling this function in the initialization of
33 // the 'oo' constant should be enough as this constant
34 // is initialized before the first Codac function call occurs.
35 gaol::round_upward();
36
37 return std::numeric_limits<double>::infinity();
38 }();
39
40 class Interval;
41
42 template<>
43 struct is_interval_based<Interval> : std::true_type {};
44
45 template<>
46 struct is_ctc<Interval> : std::false_type {};
47
48 template<>
49 struct is_sep<Interval> : std::false_type {};
50
61 class Interval : protected gaol::interval, public DomainInterface<Interval,double>
62 {
63 public:
64
65 using DegeneratedType = double;
66
70 Interval();
71
77 Interval(double a);
78
85 Interval(double a, double b);
86
92 Interval(const Interval& x);
93
99 explicit Interval(const std::array<double,1>& array);
100
106 explicit Interval(const std::array<double,2>& array);
107
113 Interval(std::initializer_list<double> l);
114
123 Interval& init(const Interval& x);
124
133 Interval& init_from_list(const std::list<double>& l);
134
141 Interval& operator=(double x);
142
149 Interval& operator=(const Interval& x);
150
157 bool operator==(const Interval& x) const;
158
165 bool operator!=(const Interval& x) const;
166
172 double lb() const;
173
179 double ub() const;
180
196 double mid() const;
197
204 double mag() const;
205
215 double mig() const;
216
228 double rand() const;
229
235 double rad() const;
236
242 double diam() const;
243
251 double volume() const;
252
260 Index size() const;
261
265 void set_empty();
266
272 bool is_empty() const;
273
284 bool contains(const double& x) const;
285
292 bool interior_contains(const double& x) const;
293
301 bool is_unbounded() const;
302
311 bool is_degenerated() const;
312
319 bool intersects(const Interval &x) const;
320
327 bool is_disjoint(const Interval& x) const;
328
336 bool overlaps(const Interval &x) const;
337
346 bool is_subset(const Interval& x) const;
347
359 bool is_strict_subset(const Interval& x) const;
360
371 bool is_interior_subset(const Interval& x) const;
372
383 bool is_strict_interior_subset(const Interval& x) const;
384
393 bool is_superset(const Interval& x) const;
394
403 bool is_strict_superset(const Interval& x) const;
404
411 Interval& inflate(const double& rad);
412
420 bool is_bisectable() const;
421
430 std::pair<Interval,Interval> bisect(float ratio = 0.49) const;
431
438 std::vector<Interval> complementary(bool compactness = true) const;
439
447 std::vector<Interval> diff(const Interval& y, bool compactness = true) const;
448
455 Interval& operator|=(const Interval& x);
456
463 Interval& operator&=(const Interval& x);
464
471 Interval& operator+=(double x);
472
479 Interval& operator+=(const Interval& x);
480
486 Interval operator-() const;
487
494 Interval& operator-=(double x);
495
502 Interval& operator-=(const Interval& x);
503
510 Interval& operator*=(double x);
511
518 Interval& operator*=(const Interval& x);
519
526 Interval& operator/=(double x);
527
538 Interval& operator/=(const Interval& x);
539
545 static Interval empty();
546
552 static Interval zero();
553
559 static Interval one();
560
566 static Interval half_pi();
567
573 static Interval pi();
574
580 static Interval two_pi();
581
582 friend std::ostream& operator<<(std::ostream& os, const Interval& x);
583
584 // Getting 'inaccessible' operators from GAOL, required for pybind11
585
586 void* operator new(std::size_t size)
587 {
588 return ::operator new(size);
589 }
590
591 void operator delete(void* ptr)
592 {
593 ::operator delete(ptr);
594 }
595
596 protected:
597
598 Interval(const gaol::interval& x);
599
600 #define _dec_friend_interval2_arithm_op(f) \
601 friend Interval f(double, const Interval&); \
602 friend Interval f(const Interval&, double); \
603 friend Interval f(const Interval&, const Interval&); \
604
605 _dec_friend_interval2_arithm_op(operator&)
606 _dec_friend_interval2_arithm_op(operator|)
607 _dec_friend_interval2_arithm_op(operator+)
608 _dec_friend_interval2_arithm_op(operator-)
609 _dec_friend_interval2_arithm_op(operator*)
610 _dec_friend_interval2_arithm_op(operator/)
611
612 #define _dec_friend_interval2_unary_op(f) \
613 friend Interval f(const Interval&); \
614
615 _dec_friend_interval2_unary_op(sqr)
616 _dec_friend_interval2_unary_op(sqrt)
617 _dec_friend_interval2_unary_op(exp)
618 _dec_friend_interval2_unary_op(log)
619 _dec_friend_interval2_unary_op(cos)
620 _dec_friend_interval2_unary_op(sin)
621 _dec_friend_interval2_unary_op(tan)
622 _dec_friend_interval2_unary_op(acos)
623 _dec_friend_interval2_unary_op(asin)
624 _dec_friend_interval2_unary_op(atan)
625 _dec_friend_interval2_unary_op(cosh)
626 _dec_friend_interval2_unary_op(sinh)
627 _dec_friend_interval2_unary_op(tanh)
628 _dec_friend_interval2_unary_op(acosh)
629 _dec_friend_interval2_unary_op(asinh)
630 _dec_friend_interval2_unary_op(atanh)
631 _dec_friend_interval2_unary_op(abs)
632 _dec_friend_interval2_unary_op(sign)
633 _dec_friend_interval2_unary_op(integer)
634 _dec_friend_interval2_unary_op(floor)
635 _dec_friend_interval2_unary_op(ceil)
636
637 #define _dec_friend_interval2_binary_op(f) \
638 friend Interval f(const Interval&, const Interval&); \
639
640 _dec_friend_interval2_binary_op(max)
641 _dec_friend_interval2_binary_op(min)
642 _dec_friend_interval2_binary_op(atan2)
643
644 friend Interval pow(const Interval&, int);
645 friend Interval pow(const Interval&, double);
646
647 _dec_friend_interval2_binary_op(pow)
648
649 friend Interval root(const Interval&, int);
650 friend Interval chi(const Interval&, const Interval&, const Interval&);
651
652 friend struct AbsOp;
653 friend struct AcosOp;
654 friend struct AddOp;
655 friend struct ChiOp;
656 friend struct DivOp;
657 friend struct MulOp;
658 friend struct SubOp;
659 friend struct AsinOp;
660 friend struct AtanOp;
661 friend struct Atan2Op;
662 friend struct CosOp;
663 friend struct CoshOp;
664 friend struct DetOp;
665 friend struct ExpOp;
666 friend struct LogOp;
667 friend struct PowOp;
668 friend struct SinOp;
669 friend struct SinhOp;
670 friend struct SqrOp;
671 friend struct SqrtOp;
672 friend struct TanOp;
673 friend struct TanhOp;
674 };
675
683 std::ostream& operator<<(std::ostream& os, const Interval& x);
684
691 Interval operator""_i(long double x);
692
693 double previous_float(double x);
694 double next_float(double x);
695
705 Interval operator&(const Interval& x, const Interval& y);
706
716 Interval operator|(const Interval& x, const Interval& y);
717
726 const Interval& operator+(const Interval& x);
727
735 Interval operator+(const Interval& x, double y);
736
744 Interval operator+(double x, const Interval& y);
745
753 Interval operator+(const Interval& x, const Interval& y);
754
762 Interval operator-(const Interval& x, double y);
763
771 Interval operator-(double x, const Interval& y);
772
780 Interval operator-(const Interval& x, const Interval& y);
781
789 Interval operator*(const Interval& x, double y);
790
798 Interval operator*(double x, const Interval& y);
799
807 Interval operator*(const Interval& x, const Interval& y);
808
816 Interval operator/(const Interval& x, double y);
817
825 Interval operator/(double x, const Interval& y);
826
834 Interval operator/(const Interval& x, const Interval& y);
835}
836
837#include "codac2_Interval_impl.h"
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:62
Interval & init(const Interval &x)
Sets the value of this interval to x.
Definition codac2_Interval_impl.h:54
bool is_unbounded() const
Tests if one of the bounds of this is infinite.
Definition codac2_Interval_impl.h:202
Interval & operator*=(double x)
Self multiplication of this and a real x.
Definition codac2_Interval_impl.h:505
Interval & operator-=(double x)
Self substraction of this and a real x.
Definition codac2_Interval_impl.h:490
bool operator==(const Interval &x) const
Comparison (equality) between two intervals.
Definition codac2_Interval_impl.h:92
bool is_empty() const
Tests if this is empty.
Definition codac2_Interval_impl.h:187
double mig() const
Returns the mignitude of this.
Definition codac2_Interval_impl.h:124
bool is_bisectable() const
Tests if this can be bisected into two non-degenerated intervals.
Definition codac2_Interval_impl.h:266
friend Interval chi(const Interval &, const Interval &, const Interval &)
Return if , if , else.
Definition codac2_Interval_operations_impl.h:299
Interval & inflate(const double &rad)
Adds [-rad,+rad] to this.
Definition codac2_Interval_impl.h:260
static Interval one()
Provides an interval for .
Definition codac2_Interval_impl.h:545
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:60
double ub() const
Returns the upper bound of this.
Definition codac2_Interval_impl.h:107
bool intersects(const Interval &x) const
Tests if this and x intersect.
Definition codac2_Interval_impl.h:212
double volume() const
Returns the diameter of this.
Definition codac2_Interval_impl.h:172
bool interior_contains(const double &x) const
Tests if the interior of this contains x.
Definition codac2_Interval_impl.h:197
static Interval pi()
Provides an interval for .
Definition codac2_Interval_impl.h:555
double rand() const
Returns a random value inside the interval.
Definition codac2_Interval_impl.h:129
std::pair< Interval, Interval > bisect(float ratio=0.49) const
Bisects this into two subintervals.
Definition codac2_Interval_impl.h:274
friend std::ostream & operator<<(std::ostream &os, const Interval &x)
Streams out this.
Definition codac2_Interval_impl.h:565
std::vector< Interval > diff(const Interval &y, bool compactness=true) const
Computes the result of .
Definition codac2_Interval_impl.h:326
bool is_strict_subset(const Interval &x) const
Tests if this is a subset of x and not x itself.
Definition codac2_Interval_impl.h:232
bool is_interior_subset(const Interval &x) const
Tests if this is in the interior of x.
Definition codac2_Interval_impl.h:237
bool is_degenerated() const
Tests if this is degenerated, that is, in the form of .
Definition codac2_Interval_impl.h:207
std::vector< Interval > complementary(bool compactness=true) const
Computes the complementary of this.
Definition codac2_Interval_impl.h:310
Interval & operator/=(double x)
Self division of this and a real x.
Definition codac2_Interval_impl.h:520
double diam() const
Returns the diameter of this.
Definition codac2_Interval_impl.h:159
Interval & operator+=(double x)
Self addition of this and a real x.
Definition codac2_Interval_impl.h:470
bool is_disjoint(const Interval &x) const
Tests if this and x do not intersect.
Definition codac2_Interval_impl.h:217
Interval & operator&=(const Interval &x)
Self intersection of this and x.
Definition codac2_Interval_impl.h:464
static Interval zero()
Provides an interval for .
Definition codac2_Interval_impl.h:540
Index size() const
Returns the dimension of this (which is always )
Definition codac2_Interval_impl.h:177
bool is_superset(const Interval &x) const
Tests if this is a superset of x.
Definition codac2_Interval_impl.h:250
double rad() const
Returns the radius of this.
Definition codac2_Interval_impl.h:142
double mag() const
Returns the magnitude of this i.e. max(|lower bound|, |upper bound|).
Definition codac2_Interval_impl.h:119
bool overlaps(const Interval &x) const
Tests if this and x intersect and their intersection has a non-null volume.
Definition codac2_Interval_impl.h:222
void set_empty()
Sets this interval to the empty set.
Definition codac2_Interval_impl.h:182
bool is_subset(const Interval &x) const
Tests if this is a subset of x.
Definition codac2_Interval_impl.h:227
Interval & operator|=(const Interval &x)
Self union of this and x.
Definition codac2_Interval_impl.h:458
Interval & operator=(double x)
Sets this to x.
Definition codac2_Interval_impl.h:76
friend Interval pow(const Interval &, double)
Returns , .
Definition codac2_Interval_operations_impl.h:40
Interval()
Creates an interval .
Definition codac2_Interval_impl.h:21
bool contains(const double &x) const
Tests if this contains x.
Definition codac2_Interval_impl.h:192
bool operator!=(const Interval &x) const
Comparison (non equality) between two intervals.
Definition codac2_Interval_impl.h:97
double lb() const
Returns the lower bound of this.
Definition codac2_Interval_impl.h:102
static Interval two_pi()
Provides an interval for .
Definition codac2_Interval_impl.h:560
bool is_strict_interior_subset(const Interval &x) const
Tests if this is in the interior of x and different from x.
Definition codac2_Interval_impl.h:242
bool is_strict_superset(const Interval &x) const
Tests if this is a superset of x and different from x.
Definition codac2_Interval_impl.h:255
double mid() const
Returns the midpoint of this.
Definition codac2_Interval_impl.h:112
static Interval empty()
Provides an empty interval.
Definition codac2_Interval_impl.h:535
Interval operator-() const
Substraction of this.
Definition codac2_Interval_impl.h:485
static Interval half_pi()
Provides an interval for .
Definition codac2_Interval_impl.h:550
std::ostream & operator<<(std::ostream &os, const BoolInterval &x)
Streams out a BoolInterval.
Definition codac2_BoolInterval.h:45
Ellipsoid operator+(const Ellipsoid &e1, const Ellipsoid &e2)
Compute the Minkowski sum of two ellipsoids.
Interval operator*(const Interval &x, double y)
Returns with .
Definition codac2_Interval_impl.h:412
Interval operator/(const Interval &x, double y)
Returns with .
Definition codac2_Interval_impl.h:435
Interval operator-(const Interval &x, double y)
Returns with .
Definition codac2_Interval_impl.h:389
Interval ceil(const Interval &x)
Returns ceil of .
Definition codac2_Interval_operations_impl.h:294
Interval atan(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:133
Interval max(const Interval &x, const Interval &y)
Returns .
Definition codac2_Interval_operations_impl.h:274
Interval asinh(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:237
Interval atanh(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:257
Interval sqrt(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:26
Interval cosh(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:205
Interval floor(const Interval &x)
Returns floor of .
Definition codac2_Interval_operations_impl.h:289
Interval sinh(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:216
Interval acos(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:119
Interval atan2(const Interval &y, const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:140
Interval log(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:85
Interval cos(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:98
Interval exp(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:78
Interval tanh(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:223
Interval sqr(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:21
Interval root(const Interval &x, int p)
Returns the p-th root: .
Definition codac2_Interval_operations_impl.h:60
Interval abs(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:264
Interval asin(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:126
Interval integer(const Interval &x)
Returns the largest integer interval included in .
Definition codac2_Interval_operations_impl.h:284
Interval min(const Interval &x, const Interval &y)
Returns .
Definition codac2_Interval_operations_impl.h:269
Interval acosh(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:230
Interval sign(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:279
Interval sin(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:105
Interval tan(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:112