00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00028 #ifndef _INTERVAL_PROFIL_H_
00029 #define _INTERVAL_PROFIL_H_
00030
00031 #include <iostream>
00032 #include <Interval.h>
00033
00034 namespace coco
00035 {
00036
00037 #define coconut_init_interval()
00038
00039
00040 class interval;
00041
00043
00047 struct interval_st
00048 {
00049 double l, u;
00050
00051 interval_st& operator=(const interval& __i);
00052 };
00053
00055
00060 class interval : public INTERVAL
00061 {
00062 private:
00064 typedef INTERVAL __Base;
00065
00066 public:
00068 interval(double lo, double up) : __Base(lo, up) {}
00070 interval(double d = 0) : __Base(d) {}
00072 interval(int d) : __Base((double) d) {}
00074 interval(unsigned d) : __Base((double) d) {}
00076 interval(long d) : __Base((double) d) {}
00078 interval(unsigned long d) : __Base((double) d) {}
00080 explicit interval(const __Base& x) : __Base(x) {}
00082 interval(const interval& x) : __Base(x) {}
00084 interval(const interval_st& x) : __Base(x.l, x.u) {}
00085
00087 void set(double lo, double up)
00088 {
00089 *this = interval(lo, up);
00090 }
00091
00093 __Base base() const {return *this;}
00094
00095
00097 static interval EMPTY() {return interval(__Base::EMPTY());}
00098
00100 bool empty() const {return __Base::isEmpty();}
00102 bool is_empty() const {return __Base::isEmpty();}
00103
00106 bool is_thin() const {return Sup(__Base) == Inf(__Base);}
00107
00108
00111 bool is_unbounded_below() const {return Inf(__Base) == BiasNegInf;}
00114 bool is_unbounded_above() const {return Sup(__Base) == BiasPosInf;}
00116 bool is_entire() const {return Inf(__Base) == BiasNegInf && sup() == BiasPosInf;}
00118 bool is_bounded() const
00119 {return !is_unbounded_below() && !is_unbounded_above();}
00121 bool subset (const interval& x) const
00122 {return __Base <= x;}
00124 bool superset (const interval& x) const
00125 {return x <= __Base;}
00127 bool proper_subset (const interval& x) const
00128 {return __Base < x;}
00130 bool proper_superset (const interval& x) const
00131 {return x < __Base;}
00133 bool disjoint (const interval& x) const
00134 {INTERVAL dummy;
00135 return Intersection(dummy, __Base, x) == 0;}
00136
00137
00139 double rel_width() const;
00140
00142 interval& intersect(const interval& x)
00143 {
00144 INTERVAL t;
00145 Intersection(t, __Base, x);
00146 return *this = t;
00147 }
00148
00150 interval& hull(const interval& x)
00151 {
00152 return *this = __Base::hull(x);
00153 }
00154
00157 interval& hulldiff(const interval& x)
00158 {
00159 if(subset(x))
00160 *this = EMPTY();
00161 else if(!superset(x))
00162 {
00163 if(x.contains(inf()))
00164 *this = interval(x.sup(), sup());
00165 else
00166 *this = interval(inf(), x.inf());
00167 }
00168 return *this;
00169 }
00170
00172 bool contains(const interval& x) const
00173 {
00174 if(inf() <= x.inf() && sup() >= x.sup())
00175 return true;
00176 else
00177 return false;
00178 }
00179
00181 void setpair(double& lo, double& up) const {lo = inf(); up = sup();}
00183 void get_bounds(double& a, double& b) const {a = inf(); b = sup();}
00185 void set_bounds(double a, double b) {INF = a; SUP = b;}
00187 void set_lb(double d) {INF = d;}
00189 void set_ub(double d) {SUP = d;}
00190
00192
00193 interval& operator=(double d) {INF = SUP = d; return *this;}
00194 interval& operator=(int d) {INF = SUP = d; return *this;}
00195 interval& operator=(unsigned d) {INF = SUP = d; return *this;}
00196 interval& operator=(long d) {INF = SUP = d; return *this;}
00197 interval& operator=(unsigned long d) {INF = SUP = d; return *this;}
00199
00200 interval& operator=(const __Base& _x)
00201 {INF = _x.inf(); SUP = _x.sup(); return *this;}
00202
00204 interval operator-() const {return interval(__Base::operator-());}
00205
00207 interval& ipow(int n);
00209 interval& imin(const interval& x);
00211 interval& imax(const interval& x);
00212
00215 interval& intersect_div(const interval& __i, const interval& __j);
00218 interval& intersect_power(const interval& __i, int __n);
00222 interval& intersect_invsqr_wc(const interval& __i, double __l, double __d);
00226 interval& intersect_invpower_wc(const interval& __i, double __l, int __n);
00230 interval& intersect_invsin_wc(const interval& __i, double __l, double __d);
00234 interval& intersect_invcos_wc(const interval& __i, double __l, double __d);
00238 interval& intersect_invgauss_wc(const interval& __i, double __l, double __m,
00239 double __s);
00240
00243 double project(double __d) const;
00244
00245
00246
00247
00248
00252 interval& operator+=(const interval& a);
00253
00257 interval& operator+=(double a);
00258
00262 interval& operator-=(const interval& a);
00263
00267 interval& operator-=(double a);
00268
00272 interval& operator*=(const interval& a);
00273
00277 interval& operator*=(double a);
00278
00282 interval& operator/=(const interval& a);
00283
00287 interval& operator/=(double a);
00288
00302 double mid() const;
00303
00305
00316 double diam() const;
00317 double width() const;
00319
00335 double relDiam() const;
00336
00348 double rad() const;
00349
00360 double mig() const;
00361
00373 double mag() const;
00374
00386 double dist(const interval& x) const;
00387
00401 double safeguarded_mid() const;
00402
00405 static int const & precision();
00407 static int precision(int const & p);
00408 };
00409
00410
00411
00412
00413
00414
00415
00417 inline double safeguarded_mid(const interval& __i)
00418 {return __i.safeguarded_mid();}
00421 interval ipow(const interval& x, int n);
00423 interval gauss(const interval& x);
00426 interval atan2(const interval& y, const interval& x);
00428 double absmin(const interval& __i);
00431 double gainfactor(const interval& _old, const interval& _new);
00432
00434
00435 bool operator==(const interval& __i, const interval& __d);
00436 template <class _TC>
00437 bool operator==(const interval& __i, const _TC& __d);
00439
00441
00442 bool operator!=(const interval& __i, const interval& __d);
00443 template <class _TC>
00444 bool operator!=(const interval& __i, const _TC& __d);
00446
00447
00448
00449
00450
00451
00453 double downward_plus(const double& a, const double& b);
00455 double upward_plus(const double& a, const double& b);
00457 double downward_minus(const double& a, const double& b);
00459 double upward_minus(const double& a, const double& b);
00461 double downward_multiplies(const double& a, const double& b);
00463 double upward_multiplies(const double& a, const double& b);
00465 double downward_divides(const double& a, const double& b);
00467 double upward_divides(const double& a, const double& b);
00468
00470
00473 inline bool operator<(const interval& a, const interval& b){return a.sup() < b.inf();}
00474 inline bool operator<(const interval& a, double b){return a.sup() < b;}
00475 inline bool operator<(double a, const interval& b){return a < b.inf();}
00477
00479
00480 interval operator+(const interval& a, const interval& b);
00481 interval operator+(const interval& a, double b);
00482 interval operator+(double b, const interval& a);
00484
00485
00486 interval operator-(const interval& a, const interval& b);
00487 interval operator-(const interval& a, double b);
00488 interval operator-(double a, const interval& b);
00490 interval cancel(const interval& a, const interval& b);
00492
00493 interval operator*(const interval& a, const interval& b);
00494 interval operator*(const interval& a, double b);
00495 interval operator*(double a, const interval& b);
00497
00498
00499 interval operator/(const interval& a, const interval& b);
00500 interval operator/(const interval& a, double b);
00501 interval operator/(double a, const interval& b);
00503
00505
00520 interval division_part1(const interval& x, const interval& y, bool& b);
00521
00522 interval division_part2(const interval& x, const interval& y, bool b = true);
00524
00528 double mid(const interval&);
00532 double diam(const interval&);
00533 double width(const interval&);
00537 double relDiam(const interval&);
00541 double rad(const interval&);
00545 double mig(const interval&);
00549 double mag(const interval&);
00553 double dist(const interval& x, const interval& y);
00554
00558 interval acos(const interval& x);
00559
00563 interval abs(const interval& x);
00564
00569 interval acosh(const interval& x);
00570
00575 interval acot(const interval& x);
00576
00581 interval acoth(const interval& x);
00582
00586 interval asin(const interval& x);
00587
00592 interval asinh(const interval& x);
00593
00597 interval atan(const interval& x);
00598
00603 interval atanh(const interval& x);
00604
00608 interval cos(const interval& x);
00609
00613 interval cosh(const interval& x);
00614
00618 interval cot(const interval& x);
00619
00624 interval coth(const interval& x);
00625
00629 interval exp(const interval& x);
00630
00635 interval exp10(const interval& x);
00636
00641 interval exp2(const interval& x);
00642
00646 interval expm1(const interval& x);
00647
00652 interval log(const interval& x);
00653
00658 interval log10(const interval& x);
00659
00663 interval log1p(const interval& x);
00664
00669 interval log2(const interval& x);
00670
00674 interval power(const interval& x, int n);
00675
00679 interval pow(const interval& x, const interval& y);
00680
00684 interval sin(const interval& x);
00685
00689 interval sinh(const interval& x);
00690
00694 interval sqr(const interval& x);
00695
00699 interval sqrt(const interval& x);
00700
00704 interval tan(const interval& x);
00705
00710 interval tanh(const interval& x);
00711
00716 interval imax(const interval& x, const interval& y);
00717
00722 interval imin(const interval& x, const interval& y);
00723
00724
00725
00726
00727
00728
00729 inline
00730 interval_st& interval_st::operator=(const interval& x)
00731 {
00732 l = x.inf();
00733 u = x.sup();
00734 return *this;
00735 }
00736
00737
00738
00739 inline
00740 interval ipow(const interval& x, int n)
00741 {
00742 return power(x, n);
00743 }
00744
00745
00746 inline
00747 interval gauss(const interval& x)
00748 {
00749 return exp(-sqr(x));
00750 }
00751
00752
00753 inline
00754 interval atan2(const interval& y, const interval& x)
00755 {
00756 return atan(y/x);
00757 }
00758
00759
00760 inline
00761 double absmin(const interval& __i)
00762 {
00763 if(__i.contains(0.))
00764 return 0.;
00765 else if(__i.inf() > 0)
00766 return __i.inf();
00767 else
00768 return __i.sup();
00769 }
00770
00771
00772 inline
00773 double gainfactor(const interval& _old, const interval& _new)
00774 {
00775 if(_old.is_thin())
00776 return 1.;
00777 if(_old.is_bounded() && _new.is_bounded())
00778 return _new.width()/_old.width();
00779 if((_new.sup() != COCO_INF && _old.sup() == COCO_INF) ||
00780 (_new.inf() != -COCO_INF && _old.inf() == -COCO_INF))
00781 return 0.;
00782 return 1.;
00783 }
00784
00785 inline
00786 bool operator==(const interval& __i, const interval& __d)
00787 {
00788 return filib::operator==(__i, __d);
00789 }
00790
00791 template <class _TC>
00792 inline
00793 bool operator==(const interval& __i, const _TC& __d)
00794 {
00795 return filib::operator==(__i, interval(__d));
00796 }
00797
00798 inline
00799 bool operator!=(const interval& __i, const interval& __d)
00800 {
00801 return filib::operator!=(__i, __d);
00802 }
00803
00804
00805 template <class _TC>
00806 inline
00807 bool operator!=(const interval& __i, const _TC& __d)
00808 {
00809 return filib::operator!=(__i, interval(__d));
00810 }
00811
00812
00813
00814 inline
00815 double interval::project(double __d) const
00816 {
00817 if(__d < inf())
00818 return inf();
00819 else if(__d > sup())
00820 return sup();
00821 else
00822 return __d;
00823 }
00824
00825
00826 }
00827
00828
00829 #endif // _COCONUT_INTERVAL_H_