codac 2.0.0
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 <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 class Interval;
28
29 template<>
30 struct is_interval_based<Interval> : std::true_type {};
31
32 template<>
33 struct is_ctc<Interval> : std::false_type {};
34
35 template<>
36 struct is_sep<Interval> : std::false_type {};
37
48 class Interval : protected gaol::interval, public DomainInterface<Interval,double>
49 {
50 public:
51
52 using DegeneratedType = double;
53
57 Interval();
58
64 Interval(double a);
65
72 Interval(double a, double b);
73
79 Interval(const Interval& x);
80
86 explicit Interval(const std::array<double,1>& array);
87
93 explicit Interval(const std::array<double,2>& array);
94
100 Interval(std::initializer_list<double> l);
101
109 Interval& init();
110
119 Interval& init(const Interval& x);
120
129 Interval& init_from_list(const std::list<double>& l);
130
137 Interval& operator=(double x);
138
145 Interval& operator=(const Interval& x);
146
153 bool operator==(const Interval& x) const;
154
161 bool operator!=(const Interval& x) const;
162
168 double lb() const;
169
175 double ub() const;
176
192 double mid() const;
193
200 double mag() const;
201
211 double mig() const;
212
224 double rand() const;
225
231 double rad() const;
232
238 double diam() const;
239
247 double volume() const;
248
256 Index size() const;
257
261 void set_empty();
262
268 bool is_empty() const;
269
280 bool contains(const double& x) const;
281
288 bool interior_contains(const double& x) const;
289
297 bool is_unbounded() const;
298
307 bool is_degenerated() const;
308
315 bool is_integer() const;
316
322 bool has_integer_bounds() const;
323
330 bool intersects(const Interval &x) const;
331
338 bool is_disjoint(const Interval& x) const;
339
347 bool overlaps(const Interval &x) const;
348
357 bool is_subset(const Interval& x) const;
358
370 bool is_strict_subset(const Interval& x) const;
371
382 bool is_interior_subset(const Interval& x) const;
383
394 bool is_strict_interior_subset(const Interval& x) const;
395
404 bool is_superset(const Interval& x) const;
405
414 bool is_strict_superset(const Interval& x) const;
415
422 Interval& inflate(const double& rad);
423
431 bool is_bisectable() const;
432
441 std::pair<Interval,Interval> bisect(float ratio = 0.49) const;
442
449 std::vector<Interval> complementary(bool compactness = true) const;
450
458 std::vector<Interval> diff(const Interval& y, bool compactness = true) const;
459
466 Interval& operator|=(const Interval& x);
467
474 Interval& operator&=(const Interval& x);
475
482 Interval& operator+=(double x);
483
490 Interval& operator+=(const Interval& x);
491
497 Interval operator-() const;
498
505 Interval& operator-=(double x);
506
513 Interval& operator-=(const Interval& x);
514
521 Interval& operator*=(double x);
522
529 Interval& operator*=(const Interval& x);
530
537 Interval& operator/=(double x);
538
549 Interval& operator/=(const Interval& x);
550
556 static Interval empty();
557
563 static Interval zero();
564
570 static Interval one();
571
577 static Interval half_pi();
578
584 static Interval pi();
585
591 static Interval two_pi();
592
593 friend std::ostream& operator<<(std::ostream& os, const Interval& x);
594
595 // Getting 'inaccessible' operators from GAOL, required for pybind11
596
597 void* operator new(std::size_t size)
598 {
599 return ::operator new(size);
600 }
601
602 void operator delete(void* ptr)
603 {
604 ::operator delete(ptr);
605 }
606
607 protected:
608
609 Interval(const gaol::interval& x);
610
611 #define _dec_friend_interval2_arithm_op(f) \
612 friend Interval f(double, const Interval&); \
613 friend Interval f(const Interval&, double); \
614 friend Interval f(const Interval&, const Interval&); \
615
616 _dec_friend_interval2_arithm_op(operator&)
617 _dec_friend_interval2_arithm_op(operator|)
618 _dec_friend_interval2_arithm_op(operator+)
619 _dec_friend_interval2_arithm_op(operator-)
620 _dec_friend_interval2_arithm_op(operator*)
621 _dec_friend_interval2_arithm_op(operator/)
622
623 #define _dec_friend_interval2_unary_op(f) \
624 friend Interval f(const Interval&); \
625
626 _dec_friend_interval2_unary_op(sqr)
627 _dec_friend_interval2_unary_op(sqrt)
628 _dec_friend_interval2_unary_op(exp)
629 _dec_friend_interval2_unary_op(log)
630 _dec_friend_interval2_unary_op(cos)
631 _dec_friend_interval2_unary_op(sin)
632 _dec_friend_interval2_unary_op(tan)
633 _dec_friend_interval2_unary_op(acos)
634 _dec_friend_interval2_unary_op(asin)
635 _dec_friend_interval2_unary_op(atan)
636 _dec_friend_interval2_unary_op(cosh)
637 _dec_friend_interval2_unary_op(sinh)
638 _dec_friend_interval2_unary_op(tanh)
639 _dec_friend_interval2_unary_op(acosh)
640 _dec_friend_interval2_unary_op(asinh)
641 _dec_friend_interval2_unary_op(atanh)
642 _dec_friend_interval2_unary_op(abs)
643 _dec_friend_interval2_unary_op(sign)
644 _dec_friend_interval2_unary_op(integer)
645 _dec_friend_interval2_unary_op(floor)
646 _dec_friend_interval2_unary_op(ceil)
647
648 #define _dec_friend_interval2_binary_op(f) \
649 friend Interval f(const Interval&, const Interval&); \
650
651 _dec_friend_interval2_binary_op(max)
652 _dec_friend_interval2_binary_op(min)
653 _dec_friend_interval2_binary_op(atan2)
654
655 friend Interval pow(const Interval&, int);
656 friend Interval pow(const Interval&, double);
657
658 _dec_friend_interval2_binary_op(pow)
659
660 friend Interval root(const Interval&, int);
661 friend Interval chi(const Interval&, const Interval&, const Interval&);
662
663 friend struct AbsOp;
664 friend struct AcosOp;
665 friend struct AddOp;
666 friend struct ChiOp;
667 friend struct DivOp;
668 friend struct MulOp;
669 friend struct SubOp;
670 friend struct AsinOp;
671 friend struct AtanOp;
672 friend struct Atan2Op;
673 friend struct CosOp;
674 friend struct CoshOp;
675 friend struct DetOp;
676 friend struct ExpOp;
677 friend struct LogOp;
678 friend struct PowOp;
679 friend struct SinOp;
680 friend struct SinhOp;
681 friend struct SqrOp;
682 friend struct SqrtOp;
683 friend struct TanOp;
684 friend struct TanhOp;
685 };
686
694 std::ostream& operator<<(std::ostream& os, const Interval& x);
695
702 Interval operator""_i(long double x);
703
715 double previous_float(double x);
716
728 double next_float(double x);
729
739 Interval operator&(const Interval& x, const Interval& y);
740
750 Interval operator|(const Interval& x, double y);
751
761 Interval operator|(const Interval& x, const Interval& y);
762
771 const Interval& operator+(const Interval& x);
772
780 Interval operator+(const Interval& x, double y);
781
789 Interval operator+(double x, const Interval& y);
790
798 Interval operator+(const Interval& x, const Interval& y);
799
807 Interval operator-(const Interval& x, double y);
808
816 Interval operator-(double x, const Interval& y);
817
825 Interval operator-(const Interval& x, const Interval& y);
826
834 Interval operator*(const Interval& x, double y);
835
843 Interval operator*(double x, const Interval& y);
844
852 Interval operator*(const Interval& x, const Interval& y);
853
861 Interval operator/(const Interval& x, double y);
862
870 Interval operator/(double x, const Interval& y);
871
879 Interval operator/(const Interval& x, const Interval& y);
880}
881
882#include "codac2_Interval_impl.h"
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:49
bool is_unbounded() const
Tests if one of the bounds of this is infinite.
Definition codac2_Interval_impl.h:210
Interval & operator*=(double x)
Self multiplication of this and a real x.
Definition codac2_Interval_impl.h:528
Interval & operator-=(double x)
Self substraction of this and a real x.
Definition codac2_Interval_impl.h:513
bool operator==(const Interval &x) const
Comparison (equality) between two intervals.
Definition codac2_Interval_impl.h:100
bool is_empty() const
Tests if this is empty.
Definition codac2_Interval_impl.h:195
double mig() const
Returns the mignitude of this.
Definition codac2_Interval_impl.h:132
bool is_bisectable() const
Tests if this can be bisected into two non-degenerated intervals.
Definition codac2_Interval_impl.h:284
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:278
static Interval one()
Provides an interval for .
Definition codac2_Interval_impl.h:568
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
double ub() const
Returns the upper bound of this.
Definition codac2_Interval_impl.h:115
bool intersects(const Interval &x) const
Tests if this and x intersect.
Definition codac2_Interval_impl.h:230
double volume() const
Returns the diameter of this.
Definition codac2_Interval_impl.h:180
bool interior_contains(const double &x) const
Tests if the interior of this contains x.
Definition codac2_Interval_impl.h:205
static Interval pi()
Provides an interval for .
Definition codac2_Interval_impl.h:578
double rand() const
Returns a random value inside the interval.
Definition codac2_Interval_impl.h:137
std::pair< Interval, Interval > bisect(float ratio=0.49) const
Bisects this into two subintervals.
Definition codac2_Interval_impl.h:292
bool is_integer() const
Tests if this is an integer, that is, in the form of where n is an integer.
Definition codac2_Interval_impl.h:220
friend std::ostream & operator<<(std::ostream &os, const Interval &x)
Streams out this.
Definition codac2_Interval_impl.h:588
std::vector< Interval > diff(const Interval &y, bool compactness=true) const
Computes the result of .
Definition codac2_Interval_impl.h:344
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:250
bool is_interior_subset(const Interval &x) const
Tests if this is in the interior of x.
Definition codac2_Interval_impl.h:255
bool is_degenerated() const
Tests if this is degenerated, that is, in the form of .
Definition codac2_Interval_impl.h:215
Interval & operator/=(double x)
Self division of this and a real x.
Definition codac2_Interval_impl.h:543
double diam() const
Returns the diameter of this.
Definition codac2_Interval_impl.h:167
Interval & operator+=(double x)
Self addition of this and a real x.
Definition codac2_Interval_impl.h:493
bool is_disjoint(const Interval &x) const
Tests if this and x do not intersect.
Definition codac2_Interval_impl.h:235
Interval & operator&=(const Interval &x)
Self intersection of this and x.
Definition codac2_Interval_impl.h:487
static Interval zero()
Provides an interval for .
Definition codac2_Interval_impl.h:563
Index size() const
Returns the dimension of this (which is always )
Definition codac2_Interval_impl.h:185
bool is_superset(const Interval &x) const
Tests if this is a superset of x.
Definition codac2_Interval_impl.h:268
double rad() const
Returns the radius of this.
Definition codac2_Interval_impl.h:150
double mag() const
Returns the magnitude of this i.e. max(|lower bound|, |upper bound|).
Definition codac2_Interval_impl.h:127
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:240
void set_empty()
Sets this interval to the empty set.
Definition codac2_Interval_impl.h:190
bool is_subset(const Interval &x) const
Tests if this is a subset of x.
Definition codac2_Interval_impl.h:245
Interval & operator|=(const Interval &x)
Self union of this and x.
Definition codac2_Interval_impl.h:481
Interval & operator=(double x)
Sets this to x.
Definition codac2_Interval_impl.h:84
friend Interval pow(const Interval &, double)
Returns , .
Definition codac2_Interval_operations_impl.h:40
Interval()
Creates an interval .
Definition codac2_Interval_impl.h:23
bool contains(const double &x) const
Tests if this contains x.
Definition codac2_Interval_impl.h:200
bool operator!=(const Interval &x) const
Comparison (non equality) between two intervals.
Definition codac2_Interval_impl.h:105
double lb() const
Returns the lower bound of this.
Definition codac2_Interval_impl.h:110
bool has_integer_bounds() const
Checks whether the interval has integer lower and upper bounds.
Definition codac2_Interval_impl.h:225
static Interval two_pi()
Provides an interval for .
Definition codac2_Interval_impl.h:583
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:260
Interval & init()
Sets the value of this interval to [-oo,oo].
Definition codac2_Interval_impl.h:56
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:273
double mid() const
Returns the midpoint of this.
Definition codac2_Interval_impl.h:120
static Interval empty()
Provides an empty interval.
Definition codac2_Interval_impl.h:558
Interval operator-() const
Substraction of this.
Definition codac2_Interval_impl.h:508
static Interval half_pi()
Provides an interval for .
Definition codac2_Interval_impl.h:573
auto operator&(const MatrixBase< OtherDerived > &x) const
Returns the element-wise intersection of this matrix with another.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:422
auto operator|(const MatrixBase< OtherDerived > &x) const
Returns the element-wise union of this matrix with another.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:438
auto complementary() const
Computes the complementary set of this interval vector (or interval row).
Definition codac2_MatrixBase_addons_IntervalVector.h:31
Definition codac2_OctaSym.h:21
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 operator*(const Interval &x, double y)
Returns with .
Definition codac2_Interval_impl.h:435
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 operator/(const Interval &x, double y)
Returns with .
Definition codac2_Interval_impl.h:458
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
Ellipsoid operator+(const Ellipsoid &e1, const Ellipsoid &e2)
Compute the Minkowski sum of two ellipsoids.
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
std::ostream & operator<<(std::ostream &os, const BoolInterval &x)
Streams out a BoolInterval.
Definition codac2_BoolInterval.h:64
Interval operator-(const Interval &x, double y)
Returns with .
Definition codac2_Interval_impl.h:412
double next_float(double x)
Returns the next representable double-precision floating-point value after x.
Definition codac2_Interval_impl.h:609
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
double previous_float(double x)
Returns the previous representable double-precision floating-point value before x.
Definition codac2_Interval_impl.h:604
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