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
219 double smag() const;
220
230 double smig() const;
231
243 double rand() const;
244
250 double rad() const;
251
257 double diam() const;
258
266 double volume() const;
267
275 Index size() const;
276
280 void set_empty();
281
287 bool is_empty() const;
288
299 bool contains(const double& x) const;
300
307 bool interior_contains(const double& x) const;
308
316 bool is_unbounded() const;
317
326 bool is_degenerated() const;
327
334 bool is_integer() const;
335
341 bool has_integer_bounds() const;
342
349 bool intersects(const Interval &x) const;
350
357 bool is_disjoint(const Interval& x) const;
358
366 bool overlaps(const Interval &x) const;
367
376 bool is_subset(const Interval& x) const;
377
389 bool is_strict_subset(const Interval& x) const;
390
401 bool is_interior_subset(const Interval& x) const;
402
413 bool is_strict_interior_subset(const Interval& x) const;
414
423 bool is_superset(const Interval& x) const;
424
433 bool is_strict_superset(const Interval& x) const;
434
441 Interval& inflate(const double& rad);
442
450 bool is_bisectable() const;
451
460 std::pair<Interval,Interval> bisect(float ratio = 0.49) const;
461
468 std::vector<Interval> complementary(bool compactness = true) const;
469
477 std::vector<Interval> diff(const Interval& y, bool compactness = true) const;
478
485 Interval& operator|=(const Interval& x);
486
493 Interval& operator&=(const Interval& x);
494
501 Interval& operator+=(double x);
502
509 Interval& operator+=(const Interval& x);
510
516 Interval operator-() const;
517
524 Interval& operator-=(double x);
525
532 Interval& operator-=(const Interval& x);
533
540 Interval& operator*=(double x);
541
548 Interval& operator*=(const Interval& x);
549
556 Interval& operator/=(double x);
557
568 Interval& operator/=(const Interval& x);
569
575 static Interval empty();
576
582 static Interval zero();
583
589 static Interval one();
590
596 static Interval half_pi();
597
603 static Interval pi();
604
610 static Interval two_pi();
611
612 friend std::ostream& operator<<(std::ostream& os, const Interval& x);
613
614 // Getting 'inaccessible' operators from GAOL, required for pybind11
615
616 void* operator new(std::size_t size)
617 {
618 return ::operator new(size);
619 }
620
621 void operator delete(void* ptr)
622 {
623 ::operator delete(ptr);
624 }
625
626 protected:
627
628 Interval(const gaol::interval& x);
629
630 #define _dec_friend_interval2_arithm_op(f) \
631 friend Interval f(double, const Interval&); \
632 friend Interval f(const Interval&, double); \
633 friend Interval f(const Interval&, const Interval&); \
634
635 _dec_friend_interval2_arithm_op(operator&)
636 _dec_friend_interval2_arithm_op(operator|)
637 _dec_friend_interval2_arithm_op(operator+)
638 _dec_friend_interval2_arithm_op(operator-)
639 _dec_friend_interval2_arithm_op(operator*)
640 _dec_friend_interval2_arithm_op(operator/)
641
642 #define _dec_friend_interval2_unary_op(f) \
643 friend Interval f(const Interval&); \
644
645 _dec_friend_interval2_unary_op(sqr)
646 _dec_friend_interval2_unary_op(sqrt)
647 _dec_friend_interval2_unary_op(exp)
648 _dec_friend_interval2_unary_op(log)
649 _dec_friend_interval2_unary_op(cos)
650 _dec_friend_interval2_unary_op(sin)
651 _dec_friend_interval2_unary_op(tan)
652 _dec_friend_interval2_unary_op(acos)
653 _dec_friend_interval2_unary_op(asin)
654 _dec_friend_interval2_unary_op(atan)
655 _dec_friend_interval2_unary_op(cosh)
656 _dec_friend_interval2_unary_op(sinh)
657 _dec_friend_interval2_unary_op(tanh)
658 _dec_friend_interval2_unary_op(acosh)
659 _dec_friend_interval2_unary_op(asinh)
660 _dec_friend_interval2_unary_op(atanh)
661 _dec_friend_interval2_unary_op(abs)
662 _dec_friend_interval2_unary_op(sign)
663 _dec_friend_interval2_unary_op(integer)
664 _dec_friend_interval2_unary_op(floor)
665 _dec_friend_interval2_unary_op(ceil)
666
667 #define _dec_friend_interval2_binary_op(f) \
668 friend Interval f(const Interval&, const Interval&); \
669
670 _dec_friend_interval2_binary_op(max)
671 _dec_friend_interval2_binary_op(min)
672 _dec_friend_interval2_binary_op(atan2)
673
674 friend Interval pow(const Interval&, int);
675 friend Interval pow(const Interval&, double);
676
677 _dec_friend_interval2_binary_op(pow)
678
679 friend Interval root(const Interval&, int);
680 friend Interval chi(const Interval&, const Interval&, const Interval&);
681
682 friend struct AbsOp;
683 friend struct AcosOp;
684 friend struct AddOp;
685 friend struct ChiOp;
686 friend struct DivOp;
687 friend struct MulOp;
688 friend struct SubOp;
689 friend struct AsinOp;
690 friend struct AtanOp;
691 friend struct Atan2Op;
692 friend struct CosOp;
693 friend struct CoshOp;
694 friend struct DetOp;
695 friend struct ExpOp;
696 friend struct LogOp;
697 friend struct PowOp;
698 friend struct SinOp;
699 friend struct SinhOp;
700 friend struct SqrOp;
701 friend struct SqrtOp;
702 friend struct TanOp;
703 friend struct TanhOp;
704 };
705
713 std::ostream& operator<<(std::ostream& os, const Interval& x);
714
721 Interval operator""_i(long double x);
722
734 double prev_float(double x);
735
747 double next_float(double x);
748
758 Interval operator&(const Interval& x, const Interval& y);
759
769 Interval operator|(const Interval& x, double y);
770
780 Interval operator|(const Interval& x, const Interval& y);
781
790 const Interval& operator+(const Interval& x);
791
799 Interval operator+(const Interval& x, double y);
800
808 Interval operator+(double x, const Interval& y);
809
817 Interval operator+(const Interval& x, const Interval& y);
818
826 Interval operator-(const Interval& x, double y);
827
835 Interval operator-(double x, const Interval& y);
836
844 Interval operator-(const Interval& x, const Interval& y);
845
853 Interval operator*(const Interval& x, double y);
854
862 Interval operator*(double x, const Interval& y);
863
871 Interval operator*(const Interval& x, const Interval& y);
872
880 Interval operator/(const Interval& x, double y);
881
889 Interval operator/(double x, const Interval& y);
890
898 Interval operator/(const Interval& x, const Interval& y);
899}
900
901#include "codac2_Interval_impl.h"
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:49
double smig() const
Returns the signed mignitude of this.
Definition codac2_Interval_impl.h:142
bool is_unbounded() const
Tests if one of the bounds of this is infinite.
Definition codac2_Interval_impl.h:220
Interval & operator*=(double x)
Self multiplication of this and a real x.
Definition codac2_Interval_impl.h:538
Interval & operator-=(double x)
Self substraction of this and a real x.
Definition codac2_Interval_impl.h:523
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:205
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:294
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:288
static Interval one()
Provides an interval for .
Definition codac2_Interval_impl.h:578
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:240
double volume() const
Returns the diameter of this.
Definition codac2_Interval_impl.h:190
bool interior_contains(const double &x) const
Tests if the interior of this contains x.
Definition codac2_Interval_impl.h:215
static Interval pi()
Provides an interval for .
Definition codac2_Interval_impl.h:588
double rand() const
Returns a random value inside the interval.
Definition codac2_Interval_impl.h:147
std::pair< Interval, Interval > bisect(float ratio=0.49) const
Bisects this into two subintervals.
Definition codac2_Interval_impl.h:302
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:230
friend std::ostream & operator<<(std::ostream &os, const Interval &x)
Streams out this.
Definition codac2_Interval_impl.h:598
std::vector< Interval > diff(const Interval &y, bool compactness=true) const
Computes the result of .
Definition codac2_Interval_impl.h:354
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:260
bool is_interior_subset(const Interval &x) const
Tests if this is in the interior of x.
Definition codac2_Interval_impl.h:265
bool is_degenerated() const
Tests if this is degenerated, that is, in the form of .
Definition codac2_Interval_impl.h:225
Interval & operator/=(double x)
Self division of this and a real x.
Definition codac2_Interval_impl.h:553
double diam() const
Returns the diameter of this.
Definition codac2_Interval_impl.h:177
Interval & operator+=(double x)
Self addition of this and a real x.
Definition codac2_Interval_impl.h:503
bool is_disjoint(const Interval &x) const
Tests if this and x do not intersect.
Definition codac2_Interval_impl.h:245
Interval & operator&=(const Interval &x)
Self intersection of this and x.
Definition codac2_Interval_impl.h:497
static Interval zero()
Provides an interval for .
Definition codac2_Interval_impl.h:573
Index size() const
Returns the dimension of this (which is always )
Definition codac2_Interval_impl.h:195
bool is_superset(const Interval &x) const
Tests if this is a superset of x.
Definition codac2_Interval_impl.h:278
double rad() const
Returns the radius of this.
Definition codac2_Interval_impl.h:160
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:250
void set_empty()
Sets this interval to the empty set.
Definition codac2_Interval_impl.h:200
bool is_subset(const Interval &x) const
Tests if this is a subset of x.
Definition codac2_Interval_impl.h:255
Interval & operator|=(const Interval &x)
Self union of this and x.
Definition codac2_Interval_impl.h:491
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:210
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:235
static Interval two_pi()
Provides an interval for .
Definition codac2_Interval_impl.h:593
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:270
Interval & init()
Sets the value of this interval to [-oo,oo].
Definition codac2_Interval_impl.h:56
double smag() const
Returns the signed magnitude of this i.e. lower bound if |lower bound|>|upper bound|,...
Definition codac2_Interval_impl.h:137
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:283
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:568
Interval operator-() const
Substraction of this.
Definition codac2_Interval_impl.h:518
static Interval half_pi()
Provides an interval for .
Definition codac2_Interval_impl.h:583
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
double prev_float(double x)
Returns the previous representable double-precision floating-point value before x.
Definition codac2_Interval_impl.h:614
Interval operator*(const Interval &x, double y)
Returns with .
Definition codac2_Interval_impl.h:445
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:468
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:422
double next_float(double x)
Returns the next representable double-precision floating-point value after x.
Definition codac2_Interval_impl.h:619
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