carl  24.04
Computer ARithmetic Library
Interval.h
Go to the documentation of this file.
1 /* The class which contains the interval arithmetic including trigonometric
2  * functions. The template parameter contains the number type used for the
3  * boundaries. It is necessary to implement the rounding and checking policies
4  * for any non-primitive type such that the desired inclusion property can be
5  * maintained.
6  *
7  * Requirements for the NumberType:
8  * - Operators +,-,*,/ with the expected functionality
9  * - Operators +=,-=,*=,/= with the expected functionality
10  * - Operators <,>,<=,>=,==,!= with the expected functionality
11  * - Operations abs, min, max, log, exp, power, sqrt
12  * - Trigonometric functions sin, cos, tan, asin, acos, atan, sinh, cosh, tanh,
13  * asinh, acosh, atanh (these functions are needed for the
14  * specialization of the rounding modes.
15  * - Operator <<
16  *
17  * @file Interval.h
18  * @author Stefan Schupp <stefan.schupp@cs.rwth-aachen.de>
19  *
20  * @since 2013-12-13
21  * @version 2014-11-11
22  */
23 
24 #pragma once
25 
26 #include <carl-arith/core/Sign.h>
29 #include <carl-common/util/hash.h>
32 #include "BoundType.h"
33 #include "policies/checking.h"
34 #include "policies/rounding.h"
35 
36 CLANG_WARNING_DISABLE("-Wunused-parameter")
37 CLANG_WARNING_DISABLE("-Wunused-local-typedef")
38 #include <boost/numeric/interval.hpp>
39 #include <boost/numeric/interval/interval.hpp>
40 CLANG_WARNING_RESET
41 
42 #include "Sampling.h"
43 
44 #include <cassert>
45 #include <cmath>
46 #include <limits>
47 #include <list>
48 #include <map>
49 #include <sstream>
50 
51 #include "typetraits.h"
52 
53 
54 namespace carl
55 {
56  template<typename Number>
57  class Interval;
58 
59  template <class Number> struct is_interval_type<carl::Interval<Number>> : std::true_type {};
60  template <class Number> struct is_interval_type<const carl::Interval<Number>> : std::true_type {};
61 
62  /**
63  * Struct which holds the rounding and checking policies required for boost
64  * interval.
65  */
66  template<typename Number, typename Interval>
67  struct policies
68  {
71  static void sanitize(Interval&) {}
72  };
73 
74  /**
75  * Template specialization for rounding and checking policies for native double.
76  */
77  // TODO: Create struct specialization for all types which are already covered by the standard boost interval policies.
78  template<typename Interval>
79  struct policies<double, Interval>
80  {
81  using roundingP = boost::numeric::interval_lib::save_state<boost::numeric::interval_lib::rounded_transc_std<double> >; // TODO: change it to boost::numeric::interval_lib::rounded_transc_opp, if new boost release patches the bug with clang
82  using checkingP = boost::numeric::interval_lib::checking_no_nan<double, boost::numeric::interval_lib::checking_no_nan<double> >;
83  static void sanitize(Interval& n) {
84  if (std::isinf(n.lower())) {
86  }
87  if (std::isinf(n.upper())) {
89  }
90  assert(!std::isnan(n.lower()));
91  assert(!std::isnan(n.upper()));
92  }
93  };
94 
95  template<typename Number>
96  struct LowerBound {
97  const Number& number;
99  };
100  template<typename Number>
101  std::ostream& operator<<(std::ostream& os, const LowerBound<Number>& lb) {
102  return os << "Lower(" << lb.number << "," << lb.bound_type << ")";
103  }
104 
105  template<typename Number>
106  struct UpperBound {
107  const Number& number;
109  };
110  template<typename Number>
111  std::ostream& operator<<(std::ostream& os, const UpperBound<Number>& lb) {
112  return os << "Upper(" << lb.number << "," << lb.bound_type << ")";
113  }
114 
115  /**
116  *The class which contains the interval arithmetic including trigonometric
117  * functions. The template parameter contains the number type used for the
118  * boundaries. It is necessary to implement the rounding and checking policies
119  * for any non-primitive type such that the desired inclusion property can be
120  * maintained.
121  *
122  * Requirements for the NumberType:
123  * - Operators +,-,*,/ with the expected functionality
124  * - Operators +=,-=,*=,/= with the expected functionality
125  * - Operators <,>,<=,>=,==,!= with the expected functionality
126  * - Operations abs, min, max, log, exp, power, sqrt
127  * - Trigonometric functions sin, cos, tan, asin, acos, atan, sinh, cosh, tanh,
128  * asinh, acosh, atanh (these functions are needed for the
129  * specialization of the rounding modes.
130  * - Operator <<
131  */
132  template<typename Number>
133  class Interval : public policies<Number, Interval<Number>>
134  {
135  public:
137  /*
138  * Typedefs
139  */
140  //typedef typename policies<Number>::checking checking;
141  //typedef typename policies<Number>::rounding rounding;
142  using BoostIntervalPolicies = boost::numeric::interval_lib::policies< typename Policy::roundingP, typename Policy::checkingP >;
143  using BoostInterval = boost::numeric::interval< Number, BoostIntervalPolicies >;
144  using evalintervalmap = std::map<Variable, Interval<Number> >;
145 
146  /// Macro to perform a quick check on the passed interval bounds.
147 #define BOUNDS_OK( lower, lowerBoundType, upper, upperBoundType )\
148 (lowerBoundType == BoundType::INFTY || upperBoundType == BoundType::INFTY || lower <= upper)
149 
150  /// Macro to perform a quick check for emptiness of the interval.
151 #define IS_EMPTY(lower, lowerBoundType, upper, upperBoundType )\
152 (((lowerBoundType == BoundType::STRICT && upperBoundType != BoundType::INFTY) || (lowerBoundType != BoundType::INFTY && upperBoundType == BoundType::STRICT)) && lower == upper)
153 
154  /// Macro to perform a quick check if the interval is unbounded.
155 #define IS_UNBOUNDED(lower, lowerBoundType, upper, upperBoundType )\
156 (lowerBoundType == BoundType::INFTY && upperBoundType == BoundType::INFTY)
157 
158  protected:
159  /***********************************************************************
160  * Members
161  **********************************************************************/
162 
166 
167  public:
168 
169  /***********************************************************************
170  * Constructors & Destructor
171  **********************************************************************/
172 
173  /**
174  * Default constructor which constructs the empty interval at point 0.
175  */
177  mContent(carl::constant_zero<Number>().get())
178  { }
179 
180  /**
181  * Constructor which constructs the pointinterval at n.
182  * @param n Location of the pointinterval.
183  */
184  explicit Interval(const Number& n) :
185  mContent(n),
188  {
189  Policy::sanitize(*this);
190  }
191 
192  /**
193  * Constructor which constructs the weak-bounded interval between lower
194  * and upper. If the bounds are invalid an empty interval at point 0 is
195  * constructed.
196  * @param lower The desired lower bound.
197  * @param upper The desired upper bound.
198  */
199  explicit Interval(const Number& lower, const Number& upper):
201  {
203  {
207  }
208  else
209  {
213  }
214  Policy::sanitize(*this);
215  }
216 
217  /**
218  * Constructor which constructs the interval according to the passed boost
219  * interval with the passed bound types. Note that if the interval is a
220  * pointinterval with both strict bounds or the content is invalid the
221  * empty interval is constructed and if both bounds are infty the unbounded
222  * interval is constructed.
223  * @param content The passed boost interval.
224  * @param lowerBoundType The desired lower bound type, defaults to WEAK.
225  * @param upperBoundType The desired upper bound type, defaults to WEAK.
226  */
227  explicit Interval(const BoostInterval& content, BoundType lowerBoundType = BoundType::WEAK, BoundType upperBoundType = BoundType::WEAK):
229  {
230  if (BOUNDS_OK(content.lower(), lowerBoundType, content.upper(), upperBoundType))
231  {
232  if (IS_EMPTY(content.lower(), lowerBoundType, content.upper(), upperBoundType) )
233  {
237  }
238  if (IS_UNBOUNDED(content.lower(), lowerBoundType, content.upper(), upperBoundType))
239  {
243  }
244  else if (lowerBoundType == BoundType::INFTY || upperBoundType == BoundType::INFTY)
245  {
246  mContent = BoostInterval(lowerBoundType == BoundType::INFTY ? content.upper() : content.lower());
247  mLowerBoundType = lowerBoundType;
248  mUpperBoundType = upperBoundType;
249  }
250  else
251  {
252  mContent = content;
253  mLowerBoundType = lowerBoundType;
254  mUpperBoundType = upperBoundType;
255  }
256  }
257  else
258  {
262  }
263  Policy::sanitize(*this);
264  assert(is_consistent());
265  }
266 
267  /**
268  * Constructor which constructs the interval according to the passed bounds
269  * with the passed bound types. Note that if the interval is a
270  * pointinterval with both strict bounds or the content is invalid the
271  * empty interval is constru
272  * @param lower The desired lower bound.
273  * @param lowerBoundType The desired lower bound type.
274  * @param upper The desired upper bound.
275  * @param upperBoundType The desired upper bound type.
276  */
277  Interval(const Number& lower, BoundType lowerBoundType, const Number& upper, BoundType upperBoundType):
279  {
280  if (BOUNDS_OK(lower, lowerBoundType, upper, upperBoundType))
281  {
282  if (IS_EMPTY(lower, lowerBoundType, upper, upperBoundType))
283  {
287  }
288  else if (IS_UNBOUNDED(lower, lowerBoundType, upper, upperBoundType))
289  {
293  }
294  else if (lowerBoundType == BoundType::INFTY || upperBoundType == BoundType::INFTY)
295  {
296  mContent = BoostInterval(lowerBoundType == BoundType::INFTY ? upper : lower);
297  mLowerBoundType = lowerBoundType;
298  mUpperBoundType = upperBoundType;
299  }
300  else
301  {
303  mLowerBoundType = lowerBoundType;
304  mUpperBoundType = upperBoundType;
305  }
306  }
307  else
308  {
312  }
313  Policy::sanitize(*this);
314  }
315 
316  /**
317  * Copy constructor.
318  * @param o The original interval.
319  */
324 
325  template<typename Other, DisableIf<std::is_same<Number, Other >> = dummy >
326  explicit Interval(const Interval<Other>& o)
327  {
328  *this = Interval<Number>(carl::convert<Other,Number>(o.lower()), o.lower_bound_type(), carl::convert<Other,Number>(o.upper()), o.upper_bound_type());
329  }
330 
331  /**
332  * Constructor which constructs a pointinterval from a passed double.
333  * @param n The passed double.
334  */
335  template<typename N = Number, DisableIf<std::is_same<N, double >> = dummy, DisableIf<is_rational_type<N >> = dummy >
336  explicit Interval(const double& n) :
337  mContent(carl::Interval<Number>::BoostInterval(n, n)),
340  Policy::sanitize(*this);
341  }
342 
343  /**
344  * Constructor which constructs an interval from the passed double bounds.
345  * @param lower The desired lower bound.
346  * @param upper The desired upper bound.
347  */
348  template<typename N = Number, DisableIf<std::is_same<N, double >> = dummy, DisableIf<is_rational_type<N >> = dummy >
349  explicit Interval(double lower, double upper)
350  {
352  {
356  }
357  else
358  {
362  }
363  Policy::sanitize(*this);
364  }
365 
366  /**
367  * Constructor which constructs the interval according to the passed double
368  * bounds with the passed bound types. Note that if the interval is a
369  * pointinterval with both strict bounds or the content is invalid the
370  * empty interval is constru
371  * @param lower The desired double lower bound.
372  * @param lowerBoundType The desired lower bound type.
373  * @param upper The desired double upper bound.
374  * @param upperBoundType The desired upper bound type.
375  */
376  template<typename N = Number, DisableIf<std::is_same<N, double >> = dummy, DisableIf<is_rational_type<N >> = dummy>
377  Interval(double lower, BoundType lowerBoundType, double upper, BoundType upperBoundType)
378  {
379  if (BOUNDS_OK(lower, lowerBoundType, upper, upperBoundType))
380  {
381  if (IS_EMPTY(lower, lowerBoundType, upper, upperBoundType))
382  {
386  }
387  else if (IS_UNBOUNDED(lower, lowerBoundType, upper, upperBoundType))
388  {
392  }
393  else if (lowerBoundType == BoundType::INFTY || upperBoundType == BoundType::INFTY)
394  {
395  mContent = BoostInterval(lowerBoundType == BoundType::INFTY ? upper : lower);
396  mLowerBoundType = lowerBoundType;
397  mUpperBoundType = upperBoundType;
398  }
399  else
400  {
402  mLowerBoundType = lowerBoundType;
403  mUpperBoundType = upperBoundType;
404  }
405  }
406  else
407  {
411  }
412  Policy::sanitize(*this);
413  }
414 
415  /**
416  * Constructor which constructs a pointinterval from a passed int.
417  * @param n The passed double.
418  */
419  template<typename N = Number, DisableIf<std::is_same<N, int >> = dummy >
420  explicit Interval(const int& n) :
421  mContent(carl::Interval<Number>::BoostInterval(n, n)),
424 
425  /**
426  * Constructor which constructs an interval from the passed int bounds.
427  * @param lower The desired lower bound.
428  * @param upper The desired upper bound.
429  */
430  template<typename N = Number, DisableIf<std::is_same<N, int >> = dummy>
431  explicit Interval(int lower, int upper)
432  {
434  {
438  }
439  else
440  {
444  }
445  }
446 
447  /**
448  * Constructor which constructs the interval according to the passed int
449  * bounds with the passed bound types. Note that if the interval is a
450  * pointinterval with both strict bounds or the content is invalid the
451  * empty interval is constru
452  * @param lower The desired lower bound.
453  * @param lowerBoundType The desired lower bound type.
454  * @param upper The desired upper bound.
455  * @param upperBoundType The desired upper bound type.
456  */
457  template<typename N = Number, DisableIf<std::is_same<N, int >> = dummy>
458  Interval(int lower, BoundType lowerBoundType, int upper, BoundType upperBoundType)
459  {
460  if (BOUNDS_OK(lower, lowerBoundType, upper, upperBoundType))
461  {
462  if (IS_EMPTY(lower, lowerBoundType, upper, upperBoundType))
463  {
467  }
468  else if (IS_UNBOUNDED(lower, lowerBoundType, upper, upperBoundType))
469  {
473  }
474  else if (lowerBoundType == BoundType::INFTY || upperBoundType == BoundType::INFTY)
475  {
476  mContent = BoostInterval(lowerBoundType == BoundType::INFTY ? upper : lower);
477  mLowerBoundType = lowerBoundType;
478  mUpperBoundType = upperBoundType;
479  }
480  else
481  {
483  mLowerBoundType = lowerBoundType;
484  mUpperBoundType = upperBoundType;
485  }
486  }
487  else
488  {
492  }
493  }
494 
495  /**
496  * Constructor which constructs a pointinterval from a passed unsigned int.
497  * @param n The passed double.
498  */
499  template<typename N = Number, DisableIf<std::is_same<N, unsigned int >> = dummy >
500  explicit Interval(const unsigned int& n) :
501  mContent(carl::Interval<Number>::BoostInterval(n, n)),
504 
505  /**
506  * Constructor which constructs an interval from the passed unsigned int bounds.
507  * @param lower The desired lower bound.
508  * @param upper The desired upper bound.
509  */
510  template<typename N = Number, DisableIf<std::is_same<N, unsigned int >> = dummy>
511  explicit Interval(unsigned int lower, unsigned int upper)
512  {
514  {
518  }
519  else
520  {
524  }
525  }
526 
527  /**
528  * Constructor which constructs the interval according to the passed unsigned int
529  * bounds with the passed bound types. Note that if the interval is a
530  * pointinterval with both strict bounds or the content is invalid the
531  * empty interval is constru
532  * @param lower The desired lower bound.
533  * @param lowerBoundType The desired lower bound type.
534  * @param upper The desired upper bound.
535  * @param upperBoundType The desired upper bound type.
536  */
537  template<typename N = Number, DisableIf<std::is_same<N, unsigned int >> = dummy>
538  Interval(unsigned int lower, BoundType lowerBoundType, unsigned int upper, BoundType upperBoundType)
539  {
540  if (BOUNDS_OK(lower, lowerBoundType, upper, upperBoundType))
541  {
542  if (IS_EMPTY(lower, lowerBoundType, upper, upperBoundType))
543  {
547  }
548  else if (IS_UNBOUNDED(lower, lowerBoundType, upper, upperBoundType))
549  {
553  }
554  else if (lowerBoundType == BoundType::INFTY || upperBoundType == BoundType::INFTY)
555  {
556  mContent = BoostInterval(lowerBoundType == BoundType::INFTY ? upper : lower);
557  mLowerBoundType = lowerBoundType;
558  mUpperBoundType = upperBoundType;
559  }
560  else
561  {
563  mLowerBoundType = lowerBoundType;
564  mUpperBoundType = upperBoundType;
565  }
566  }
567  else
568  {
572  }
573  }
574 
575  /**
576  * Constructor which constructs a pointinterval from a passed general
577  * rational number.
578  * @param n The passed double.
579  */
580  template<typename Num = Number, typename Rational, EnableIf<std::is_floating_point<Num >> = dummy, DisableIf<std::is_same<Num, Rational >> = dummy>
581  explicit Interval(Rational n):
583  {
584  *this = Interval<Num>(n, n);
585  Policy::sanitize(*this);
586  }
587 
588  /**
589  * Constructor which constructs an interval from the passed general rational
590  * bounds.
591  * @param lower The desired lower bound.
592  * @param upper The desired upper bound.
593  */
594  template<typename Num = Number, typename Rational, EnableIf<std::is_floating_point<Num >> = dummy, DisableIf<std::is_same<Num, Rational >> = dummy>
597  {
599  Policy::sanitize(*this);
600  }
601 
602  /**
603  * Constructor which constructs the interval according to the passed general
604  * rational bounds with the passed bound types. Note that if the interval is a
605  * pointinterval with both strict bounds or the content is invalid the
606  * empty interval is constru
607  * @param lower The desired lower bound.
608  * @param lowerBoundType The desired lower bound type.
609  * @param upper The desired upper bound.
610  * @param upperBoundType The desired upper bound type.
611  */
612  template<typename Num = Number, typename Rational, EnableIf<std::is_floating_point<Num >> = dummy, DisableIf<std::is_same<Num, Rational >> = dummy>
613  Interval(Rational lower, BoundType lowerBoundType, Rational upper, BoundType upperBoundType)
614  {
615  mLowerBoundType = lowerBoundType;
616  mUpperBoundType = upperBoundType;
617  double dLeft = carl::roundDown(lower, false);
618  double dRight = carl::roundUp(upper, false);
619  if (dLeft == -std::numeric_limits<double>::infinity()) mLowerBoundType = BoundType::INFTY;
620  if (dRight == std::numeric_limits<double>::infinity()) mUpperBoundType = BoundType::INFTY;
622  {
624  }
625  else if (mLowerBoundType == BoundType::INFTY)
626  {
627  mContent = BoostInterval(Num(dRight));
628  }
629  else if (mUpperBoundType == BoundType::INFTY)
630  {
631  mContent = BoostInterval(Num(dLeft));
632  }
633  else if ((lower == upper && lowerBoundType != upperBoundType) || lower > upper)
634  {
638  }
639  else
640  {
641  mContent = BoostInterval(Num(dLeft), Num(dRight));
642  }
643  Policy::sanitize(*this);
644  }
645 
646  /**
647  * Constructor which constructs a pointinterval from a passed general
648  * float number (e.g. FLOAT_T).
649  * @param n The passed double.
650  */
651  template<typename Num = Number, typename Float, EnableIf<is_rational_type<Num >> = dummy, EnableIf<std::is_floating_point<Float >> = dummy, DisableIf<std::is_same<Num, Float >> = dummy>
652  explicit Interval(Float n):
654  {
655  *this = Interval<Num>(n, n);
656  Policy::sanitize(*this);
657  }
658 
659  /**
660  * Constructor which constructs an interval from the passed general float
661  * bounds (e.g. FLOAT_T).
662  * @param lower The desired lower bound.
663  * @param upper The desired upper bound.
664  */
665  template<typename Num = Number, typename Float, EnableIf<is_rational_type<Num >> = dummy, EnableIf<std::is_floating_point<Float >> = dummy, DisableIf<std::is_same<Num, Float >> = dummy>
666  explicit Interval(Float lower, Float upper):
668  {
670  Policy::sanitize(*this);
671  }
672 
673  /**
674  * Constructor which constructs the interval according to the passed general
675  * float bounds (e.g. FLOAT_T) with the passed bound types. Note that if the interval is a
676  * pointinterval with both strict bounds or the content is invalid the
677  * empty interval is constru
678  * @param lower The desired lower bound.
679  * @param lowerBoundType The desired lower bound type.
680  * @param upper The desired upper bound.
681  * @param upperBoundType The desired upper bound type.
682  */
683  template<typename Num = Number, typename Float, EnableIf<is_rational_type<Num >> = dummy, EnableIf<std::is_floating_point<Float >> = dummy, DisableIf<std::is_same<Num, Float >> = dummy, DisableIf<std::is_floating_point<Num >> = dummy>
684  Interval(Float lower, BoundType lowerBoundType, Float upper, BoundType upperBoundType):
685  mContent(), mLowerBoundType(lowerBoundType), mUpperBoundType(upperBoundType)
686  {
687  Num left = carl::rationalize<Num>(to_double(lower));
688  Num right = carl::rationalize<Num>(to_double(upper));
689  //if(left == -std::numeric_limits<double>::infinity()) mLowerBoundType = BoundType::INFTY;
690  //if(right == std::numeric_limits<double>::infinity()) mUpperBoundType = BoundType::INFTY;
692  {
694  }
695  else if (mLowerBoundType == BoundType::INFTY)
696  {
697  mContent = BoostInterval(right);
698  }
699  else if (mUpperBoundType == BoundType::INFTY)
700  {
701  mContent = BoostInterval(left);
702  }
703  else if ((lower == upper && lowerBoundType != upperBoundType) || lower > upper)
704  {
708  }
709  else
710  {
711  mContent = BoostInterval(left, right);
712  }
713  Policy::sanitize(*this);
714  }
715 
716  /**
717  * Constructor which constructs a pointinterval from a passed general
718  * float number (e.g. FLOAT_T).
719  * @param n The passed double.
720  */
721  template<typename Num = Number, typename Rational, EnableIf<is_rational_type<Num >> = dummy, EnableIf<is_rational_type<Rational >> = dummy, DisableIf<std::is_same<Num, Rational >> = dummy>
722  explicit Interval(Rational n):
724  {
725  *this = Interval<double>(n, n);
726  Policy::sanitize(*this);
727  }
728 
729  /**
730  * Constructor which constructs an interval from the passed general float
731  * bounds (e.g. FLOAT_T).
732  * @param lower The desired lower bound.
733  * @param upper The desired upper bound.
734  */
735  template<typename Num = Number, typename Rational, EnableIf<is_rational_type<Num >> = dummy, EnableIf<is_rational_type<Rational >> = dummy, DisableIf<std::is_same<Num, Rational >> = dummy>
738  {
740  Policy::sanitize(*this);
741  }
742 
743  /**
744  * Constructor which constructs the interval according to the passed general
745  * float bounds (e.g. FLOAT_T) with the passed bound types. Note that if the interval is a
746  * pointinterval with both strict bounds or the content is invalid the
747  * empty interval is constru
748  * @param lower The desired lower bound.
749  * @param lowerBoundType The desired lower bound type.
750  * @param upper The desired upper bound.
751  * @param upperBoundType The desired upper bound type.
752  */
753  template<typename Num = Number, typename Rational, EnableIf<is_rational_type<Num >> = dummy, EnableIf<is_rational_type<Rational >> = dummy, DisableIf<std::is_same<Num, Rational >> = dummy>
754  Interval(Rational lower, BoundType lowerBoundType, Rational upper, BoundType upperBoundType)
755  {
756  mLowerBoundType = lowerBoundType;
757  mUpperBoundType = upperBoundType;
758  Num left = carl::rationalize<Num>(to_double(lower));
759  Num right = carl::rationalize<Num>(to_double(upper));
761  {
763  }
764  else if (mLowerBoundType == BoundType::INFTY)
765  {
766  mContent = BoostInterval(right);
767  }
768  else if (mUpperBoundType == BoundType::INFTY)
769  {
770  mContent = BoostInterval(left);
771  }
772  else if ((lower == upper && lowerBoundType != upperBoundType) || lower > upper)
773  {
777  }
778  else
779  {
780  mContent = BoostInterval(left, right);
781  }
782  Policy::sanitize(*this);
783  }
784 
786  Interval(lb.number, lb.bound_type, ub.number, ub.bound_type)
787  {
788  }
789 
791  Interval(lb.number, lb.bound_type, ub.number, get_other_bound_type(ub.bound_type))
792  {
793  }
794 
796  Interval(lb.number, get_other_bound_type(lb.bound_type), ub.number, ub.bound_type)
797  {
798  }
799 
800  /**
801  * Method which returns the unbounded interval rooted at 0.
802  * @return Unbounded interval.
803  */
805  {
807  }
808 
809  /**
810  * Method which returns the empty interval rooted at 0.
811  * @return Empty interval.
812  */
814  {
816  }
817 
818  /**
819  * Method which returns the pointinterval rooted at 0.
820  * @return Pointinterval(0).
821  */
823  {
825  }
826 
827  /**
828  * Destructor
829  */
830  ~Interval() = default;
831 
832  /***********************************************************************
833  * Getter & Setter
834  **********************************************************************/
835 
836  /**
837  * The getter for the lower boundary of the interval.
838  * @return Lower interval boundary.
839  */
840  inline const Number& lower() const
841  {
842  return mContent.lower();
843  }
844 
845  /**
846  * The getter for the upper boundary of the interval.
847  * @return Upper interval boundary.
848  */
849  inline const Number& upper() const
850  {
851  return mContent.upper();
852  }
853 
854  auto lower_bound() const {
856  }
857  auto upper_bound() const {
859  }
860 
861  /**
862  * Returns a reference to the included boost interval.
863  * @return Boost interval reference.
864  */
865  const BoostInterval& content() const
866  {
867  return mContent;
868  }
869 
870  /**
871  * Returns a reference to the included boost interval.
872  * @return Boost interval reference.
873  */
875  {
876  return mContent;
877  }
878 
879  /**
880  * The getter for the lower bound type of the interval.
881  * @return Lower bound type.
882  */
884  {
885  return mLowerBoundType;
886  }
887 
888  /**
889  * The getter for the upper bound type of the interval.
890  * @return Upper bound type.
891  */
893  {
894  return mUpperBoundType;
895  }
896 
897  /**
898  * The setter for the lower boundary of the interval.
899  * @param n Lower boundary.
900  */
901  inline void set_lower(const Number& n)
902  {
903  this->set(n, mContent.upper());
904  }
905 
906  /**
907  * The setter for the upper boundary of the interval.
908  * @param n Upper boundary.
909  */
910  inline void set_upper(const Number& n)
911  {
912  this->set(mContent.lower(), n);
913  }
914 
915  /**
916  * The setter for the lower boundary of the interval.
917  * @param n Lower boundary.
918  */
919  inline void set_lower_bound(const Number& n, BoundType b)
920  {
921  /// TODO: Fix this.
922  if(b == BoundType::INFTY) {
923  this->set(mContent.upper(), mContent.upper());
924  mLowerBoundType = b;
925  } else {
927  this->set(n, n);
928  mLowerBoundType = b;
930  } else {
931  this->set(n, mContent.upper());
932  mLowerBoundType = b;
933  }
934  }
935  }
936 
937  /**
938  * The setter for the upper boundary of the interval.
939  * @param n Upper boundary.
940  */
941  inline void set_upper_bound(const Number& n, BoundType b)
942  {
943  /// TODO: Fix this.
944  if(b == BoundType::INFTY) {
945  this->set(mContent.lower(), mContent.lower());
946  mUpperBoundType = b;
947  } else {
949  this->set(n, n);
950  mUpperBoundType = b;
952  } else {
953  this->set(mContent.lower(), n);
954  mUpperBoundType = b;
955  }
956  }
957  }
958 
959  /**
960  * The setter for the lower bound type of the interval.
961  * @param b Lower bound type.
962  */
964  {
965  mLowerBoundType = b;
966  if (b == BoundType::INFTY) {
967  //set_lower(carl::constant_zero<Number>().get());
968  set_lower(upper());
969  }
970  }
971 
972  /**
973  * The setter for the upper bound type of the interval.
974  * @param b Upper bound type.
975  */
977  {
978  mUpperBoundType = b;
979  if (b == BoundType::INFTY) {
980  //set_upper(carl::constant_zero<Number>().get());
981  set_upper(lower());
982  }
983  }
984 
985  /**
986  * The assignment operator.
987  * @param rhs Source interval.
988  * @return
989  */
991  {
992  mContent = rhs.content();
995  return *this;
996  }
997 
998  /*
999  * Transformations and advanced getters/setters
1000  */
1001 
1002  /**
1003  * Advanced setter to modify both boundaries at once.
1004  * @param lower Lower boundary.
1005  * @param upper Upper boundary.
1006  */
1007  inline void set(const BoostInterval& content)
1008  {
1009  mContent = content;
1010  }
1011 
1012  /**
1013  * Advanced setter to modify both boundaries at once by passing a boost
1014  * interval
1015  * @param content Boost interval.
1016  */
1017  inline void set(const Number& lower, const Number& upper)
1018  {
1020  }
1021 
1022  /**
1023  * Function which determines, if the interval is (-oo,oo).
1024  * @return True if both bounds are INFTY.
1025  */
1026  inline bool is_infinite() const
1027  {
1028  assert(this->is_consistent());
1029  return mLowerBoundType == BoundType::INFTY && mUpperBoundType == BoundType::INFTY;
1030  }
1031 
1032  /**
1033  * Function which determines, if the interval is unbounded.
1034  * @return True if at least one bound is INFTY.
1035  */
1036  inline bool is_unbounded() const
1037  {
1038  assert(this->is_consistent());
1039  return mLowerBoundType == BoundType::INFTY || mUpperBoundType == BoundType::INFTY;
1040  }
1041 
1042  /**
1043  * Function which determines, if the interval is half-bounded.
1044  * @return True if exactly one bound is INFTY.
1045  */
1046  inline bool is_half_bounded() const
1047  {
1048  assert(this->is_consistent());
1049  return (mLowerBoundType == BoundType::INFTY) != (mUpperBoundType == BoundType::INFTY);
1050  }
1051 
1052  /**
1053  * Function which determines, if the interval is empty.
1054  * @return True if the interval is empty.
1055  */
1056  inline bool is_empty() const
1057  {
1058  assert(this->is_consistent());
1059  if (mContent.lower() == mContent.upper()) {
1063  }
1064  return false;
1065  }
1066 
1067  /**
1068  * Function which determines, if the interval is a pointinterval.
1069  * @return True if this is a pointinterval.
1070  */
1071  inline bool is_point_interval() const
1072  {
1073  assert(this->is_consistent());
1074  return (this->is_closed_interval() && mContent.lower() == mContent.upper());
1075  }
1076 
1077  /**
1078  * Function which determines, if the interval is open.
1079  * @return True if both bounds are STRICT.
1080  */
1081  inline bool is_open_interval() const
1082  {
1083  assert(this->is_consistent());
1084  return (mLowerBoundType == BoundType::STRICT && mUpperBoundType == BoundType::STRICT);
1085  }
1086 
1087  /**
1088  * Function which determines, if the interval is closed.
1089  * @return True if both bounds are WEAK.
1090  */
1091  inline bool is_closed_interval() const
1092  {
1093  assert(this->is_consistent());
1094  return (mLowerBoundType == BoundType::WEAK && mUpperBoundType == BoundType::WEAK);
1095  }
1096 
1097  /**
1098  * Function which determines, if the interval is the zero interval.
1099  * @return True if it is a pointinterval rooted at 0.
1100  */
1101  inline bool is_zero() const
1102  {
1103  assert(this->is_consistent());
1104  return this->is_point_interval() && (mContent.lower() == carl::constant_zero<Number>().get());
1105  }
1106 
1107  /**
1108  * Function which determines, if the interval is the one interval.
1109  * @return True if it is a pointinterval rooted at 1.
1110  */
1111  inline bool is_one() const
1112  {
1113  assert(this->is_consistent());
1114  return this->is_point_interval() && (mContent.lower() == carl::constant_one<Number>().get());
1115  }
1116 
1117  /**
1118  * @return true, if it this interval contains only positive values.
1119  */
1120  inline bool is_positive() const
1121  {
1122  assert(this->is_consistent());
1123  if( mLowerBoundType == BoundType::WEAK )
1124  return mContent.lower() > carl::constant_zero<Number>().get();
1126  return mContent.lower() >= carl::constant_zero<Number>().get();
1127  return false;
1128  }
1129 
1130  /**
1131  * @return true, if it this interval contains only negative values.
1132  */
1133  inline bool is_negative() const
1134  {
1135  assert(this->is_consistent());
1136  if( mUpperBoundType == BoundType::WEAK )
1137  return mContent.upper() < carl::constant_zero<Number>().get();
1139  return mContent.upper() <= carl::constant_zero<Number>().get();
1140  return false;
1141  }
1142 
1143  /**
1144  * @return true, if it this interval contains only positive values or 0.
1145  */
1146  inline bool is_semi_positive() const
1147  {
1148  assert(this->is_consistent());
1149  if( mLowerBoundType != BoundType::INFTY )
1150  return mContent.lower() >= carl::constant_zero<Number>().get();
1151  return false;
1152  }
1153 
1154  /**
1155  * @return true, if it this interval contains only negative values or 0.
1156  */
1157  inline bool is_semi_negative() const
1158  {
1159  assert(this->is_consistent());
1160  if( mUpperBoundType != BoundType::INFTY )
1161  return mContent.upper() <= carl::constant_zero<Number>().get();
1162  return false;
1163  }
1164 
1165  /**
1166  * Determine whether the interval lays entirely left of 0 (NEGATIVE_SIGN), right of 0 (POSITIVE_SIGN) or contains 0 (ZERO_SIGN).
1167  * @return NEGATIVE_SIGN, if the interval lays entirely left of 0; POSITIVE_SIGN, if right of 0; or ZERO_SIGN, if contains 0.
1168  */
1169  inline Sign sgn() const;
1170 
1171  /**
1172  * Computes the integral part of the given interval.
1173  * @return Interval.
1174  */
1176 
1177  /**
1178  * Computes and assigns the integral part of the given interval.
1179  * @return Interval.
1180  */
1182 
1183  /**
1184  * Checks if the interval contains at least one integer value.
1185  * @return true, if the interval contains an integer.
1186  */
1187  bool contains_integer() const;
1188 
1189  /**
1190  * Returns the diameter of the interval.
1191  * @return Diameter.
1192  */
1193  Number diameter() const;
1194 
1195  /**
1196  * Computes and assigns the diameter of the interval.
1197  */
1199 
1200  /**
1201  * Returns the ratio of the diameters of the given intervals.
1202  * @param rhs Other interval.
1203  * @return Ratio.
1204  */
1205  Number diameter_ratio(const Interval<Number>& rhs) const;
1206 
1207  /**
1208  * Computes and assigns the ratio of the diameters of the given intervals.
1209  * @param rhs Other interval.
1210  */
1212 
1213  /**
1214  * Returns the magnitude of the interval.
1215  * @return Magnitude.
1216  */
1217  Number magnitude() const;
1218 
1219  /**
1220  * Computes and assigns the magnitude of the interval.
1221  */
1223 
1224  /**
1225  * Computes and assigns the center point of the interval.
1226  */
1228 
1229  /**
1230  * Checks if the interval contains the given value.
1231  * @param val Value to be checked.
1232  * @return True if the value is contained in this.
1233  */
1234  bool contains(const Number& val) const;
1235 
1236  template<typename Num = Number, DisableIf<std::is_same<Num, int >> = dummy>
1237  bool contains(int val) const
1238  {
1239  return this->contains(Number(val));
1240  }
1241 
1242  /**
1243  * Checks if the interval contains the given interval.
1244  * @param rhs Interval to be checked.
1245  * @return True if rhs is contained in this.
1246  */
1247  bool contains(const Interval<Number>& rhs) const;
1248 
1249  /**
1250  * Checks if the interval meets the given value, that is if the given value is contained in the <b>closed</b> interval defined by the bounds.
1251  * @param val Value to be checked.
1252  * @return True if val is fully contained in this.
1253  */
1254  bool meets(const Number& n) const;
1255 
1256  /**
1257  * Bloats the interval by the given value.
1258  * @param width Width.
1259  */
1260  void bloat_by(const Number& width);
1261 
1262  /**
1263  * Bloats the interval times the factor (multiplies the overall width).
1264  * @param factor Factor.
1265  */
1266  void bloat_times(const Number& factor);
1267 
1268  /**
1269  * Shrinks the interval by the given value.
1270  * @param width Width.
1271  */
1272  void shrink_by(const Number& width);
1273 
1274  /**
1275  * Shrinks the interval by a multiple of its width.
1276  * @param factor Factor.
1277  */
1278  void shrink_times(const Number& factor);
1279 
1280  /**
1281  * Splits the interval into 2 equally sized parts (strict-weak-cut).
1282  * @return pair<interval, interval>.
1283  */
1284  std::pair<Interval<Number>, Interval<Number >> split() const;
1285 
1286  /**
1287  * Splits the interval into n equally sized parts (strict-weak-cut).
1288  * @return list<interval>.
1289  */
1290  std::list<Interval<Number >> split(unsigned n) const;
1291 
1292  /**
1293  * Creates a string representation of the interval.
1294  * @return String representation of this.
1295  */
1296  std::string toString() const;
1297 
1298  /**
1299  * Operator which passes a string representation of this to the given ostream.
1300  * @param str The ostream.
1301  * @param i The interval.
1302  * @return A reference to ostream.
1303  */
1304  friend inline std::ostream& operator <<(std::ostream& str, const Interval<Number>& i)
1305  {
1306  switch (i.mLowerBoundType)
1307  {
1308  case BoundType::INFTY:
1309  str << "]-INF, ";
1310  break;
1311  case BoundType::STRICT:
1312  str << "]" << i.mContent.lower() << ", ";
1313  break;
1314  case BoundType::WEAK:
1315  str << "[" << i.mContent.lower() << ", ";
1316  }
1317  switch (i.mUpperBoundType)
1318  {
1319  case BoundType::INFTY:
1320  str << "INF[";
1321  break;
1322  case BoundType::STRICT:
1323  str << i.mContent.upper() << "[";
1324  break;
1325  case BoundType::WEAK:
1326  str << i.mContent.upper() << "]";
1327  }
1328  return str;
1329  }
1330 
1331  /*
1332  * Arithmetic functions
1333  */
1334 
1335  /**
1336  * Adds two intervals according to natural interval arithmetic.
1337  * @param rhs Interval.
1338  * @return Result.
1339  */
1341  void add_assign(const Interval<Number>& rhs);
1342 
1343  /**
1344  * Subtracts two intervals according to natural interval arithmetic.
1345  * @param rhs Interval.
1346  * @return Result.
1347  */
1349  void sub_assign(const Interval<Number>& rhs);
1350 
1351  /**
1352  * Multiplies two intervals according to natural interval arithmetic.
1353  * @param rhs Interval.
1354  * @return Result.
1355  */
1357  void mul_assign(const Interval<Number>& rhs);
1358 
1359  /**
1360  * Divides two intervals according to natural interval arithmetic.
1361  * @param rhs Interval.
1362  * @return Result.
1363  */
1365  void div_assign(const Interval<Number>& rhs);
1366 
1367  /**
1368  * Implements extended interval division with intervals containting zero.
1369  * @param rhs Interval.
1370  * @param a Result a.
1371  * @param b Result b.
1372  * @return True if split occurred.
1373  */
1375 
1376  /**
1377  * Calculates the additive inverse of an interval with respect to natural interval arithmetic.
1378  * @return Interval.
1379  */
1381 
1382  /**
1383  * Calculates the absolute value of the interval.
1384  * @return Interval.
1385  */
1387 
1388  /**
1389  * Calculates and assigns the absolute value of the interval.
1390  */
1391  void abs_assign();
1392 
1393  /**
1394  * Calculates and assigns the additive inverse of an interval with respect
1395  * to natural interval arithmetic.
1396  */
1398 
1399  /**
1400  * Calculates the multiplicative inverse of an interval with respect to natural interval arithmetic.
1401  * @param a Result a.
1402  * @param b Result b.
1403  * @return True, if split occured.
1404  */
1406 
1407  /**
1408  * Calculates the nth root of the interval with respect to natural interval arithmetic.
1409  * @param deg Degree.
1410  * @return Result.
1411  */
1412  template<typename Num = Number, EnableIf<std::is_floating_point<Num>> = dummy>
1413  Interval<Number> root(int deg) const;
1414 
1415  /**
1416  * Calculates and assigns the nth root of the interval with respect to natural interval arithmetic.
1417  * @param deg Degree.
1418  */
1419  template<typename Num = Number, EnableIf<std::is_floating_point<Num>> = dummy>
1420  void root_assign(unsigned deg);
1421 
1422  /**
1423  * A quick check for the bound values.
1424  * @return True if the lower bound is less or equal to the upper bound.
1425  */
1426  bool is_consistent() const
1427  {
1428  return this->lower() <= this->upper();
1429  }
1430  /**
1431  * Calculates the distance between two Intervals.
1432  * @param intervalA Interval to wich we want to know the distance.
1433  * @return distance to intervalA
1434  */
1435  Number distance(const Interval<Number>& intervalA);
1436 
1438 
1439  };
1440 
1441  template<typename T>
1442  struct is_number_type<Interval<T>> : std::true_type {};
1443 
1444  template<typename Number>
1445  inline bool is_integer(const Interval<Number>& n) {
1446  return n.is_point_interval() && carl::is_integer(n.lower());
1447  }
1448 
1449 /**
1450 * Check if this interval is a point-interval containing 0.
1451 */
1452 template<typename Number>
1453 bool is_zero(const Interval<Number>& i) {
1454  assert(i.is_consistent());
1455  return i.is_point_interval() && carl::is_zero(i.lower());
1456 }
1457 
1458 /**
1459 * Check if this interval is a point-interval containing 1.
1460 */
1461 template<typename Number>
1462 bool is_one(const Interval<Number>& i) {
1463  assert(i.is_consistent());
1464  return i.is_point_interval() && carl::is_one(i.lower());
1465 }
1466 
1467 
1468 
1469  /**
1470  * Implements the division which assumes that there is no remainder.
1471  * @param _lhs
1472  * @param _rhs
1473  * @return Interval which holds the result.
1474  */
1475  template<typename Number>
1476  inline Interval<Number> div(const Interval<Number>& _lhs, const Interval<Number>& _rhs)
1477  {
1478  return _lhs.div(_rhs);
1479  }
1480 
1481  /**
1482  * Implements the division with remainder.
1483  * @param _lhs
1484  * @param _rhs
1485  * @return Interval which holds the result.
1486  */
1487  template<typename Number>
1489  {
1490  return _lhs.div(_rhs);
1491  }
1492 
1493  /**
1494  * Casts the Interval to an arbitrary integer type which has a constructor for
1495  * a native int.
1496  * @param _floatInterval
1497  * @return Integer type which holds floor(_float).
1498  */
1499  template<typename Integer, typename Number>
1500  inline Integer to_int(const Interval<Number>& _floatInterval)
1501  {
1502  return Interval<Integer>(_floatInterval.lower(), _floatInterval.lower_bound_type(), _floatInterval.upper(), _floatInterval.upper_bound_type());
1503  }
1504 
1505  /**
1506  * Method which returns the absolute value of the passed number.
1507  * @param _in Number.
1508  * @return Number which holds the result.
1509  */
1510  template<typename Number>
1512  {
1513  return _in.abs();
1514  }
1515 
1516  /**
1517  * Method which returns the next smaller integer of this number or the number
1518  * itself, if it is already an integer.
1519  * @param _in Number.
1520  * @return Number which holds the result.
1521  */
1522  template<typename Number>
1524  {
1525  return Interval<Number>(floor(_in.lower()), _in.lower_bound_type(), floor(_in.upper()), _in.upper_bound_type());
1526  }
1527 
1528  /**
1529  * Method which returns the next larger integer of the passed number or the
1530  * number itself, if it is already an integer.
1531  * @param _in Number.
1532  * @return Number which holds the result.
1533  */
1534  template<typename Number>
1536  {
1537  return Interval<Number>(ceil(_in.lower()), _in.lower_bound_type(), ceil(_in.upper()), _in.upper_bound_type());
1538  }
1539 
1540 }
1541 
1542 namespace std {
1543  /**
1544  * Specialization of `std::hash` for an interval.
1545  */
1546  template<typename Number>
1547  struct hash<carl::Interval<Number>> {
1548  /**
1549  * Calculates the hash of an interval.
1550  * @param interval An interval.
1551  * @return Hash of an interval.
1552  */
1553  std::size_t operator()(const carl::Interval<Number>& interval) const {
1554  return carl::hash_all(
1555  interval.lower_bound_type(), interval.upper_bound_type(),
1556  interval.lower(), interval.upper()
1557  );
1558  }
1559  };
1560 } // namespace std
1561 
1562 #include "operators.h"
1563 #include "Interval.tpp"
1564 #include "Conversion.h"
#define IS_EMPTY(lower, lowerBoundType, upper, upperBoundType)
Macro to perform a quick check for emptiness of the interval.
Definition: Interval.h:151
#define BOUNDS_OK(lower, lowerBoundType, upper, upperBoundType)
Macro to perform a quick check on the passed interval bounds.
Definition: Interval.h:147
#define IS_UNBOUNDED(lower, lowerBoundType, upper, upperBoundType)
Macro to perform a quick check if the interval is unbounded.
Definition: Interval.h:155
mpq_class Rational
Definition: HornerTest.cpp:12
mpz_class Integer
carl is the main namespace for the library.
Interval< Number > ceil(const Interval< Number > &_in)
Method which returns the next larger integer of the passed number or the number itself,...
Definition: Interval.h:1535
Interval< Number > abs(const Interval< Number > &_in)
Method which returns the absolute value of the passed number.
Definition: Interval.h:1511
Interval< Number > floor(const Interval< Number > &_in)
Method which returns the next smaller integer of this number or the number itself,...
Definition: Interval.h:1523
Interval< Number > quotient(const Interval< Number > &_lhs, const Interval< Number > &_rhs)
Implements the division with remainder.
Definition: Interval.h:1488
double roundDown(const Rational &o, bool overapproximate=false)
Returns a down-rounded representation of the given numeric.
Definition: generic.h:12
std::ostream & operator<<(std::ostream &os, const BasicConstraint< Poly > &c)
Prints the given constraint on the given stream.
Sign
This class represents the sign of a number .
Definition: Sign.h:20
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
Definition: Interval.h:1453
Integer to_int(const Interval< Number > &_floatInterval)
Casts the Interval to an arbitrary integer type which has a constructor for a native int.
Definition: Interval.h:1500
static BoundType get_other_bound_type(BoundType type)
Definition: BoundType.h:42
Interval< Number > div(const Interval< Number > &_lhs, const Interval< Number > &_rhs)
Implements the division which assumes that there is no remainder.
Definition: Interval.h:1476
double roundUp(const Rational &o, bool overapproximate=false)
Returns a up-rounded representation of the given numeric.
Definition: generic.h:38
bool is_integer(const Interval< Number > &n)
Definition: Interval.h:1445
double to_double(const cln::cl_RA &n)
Converts the given fraction to a double.
Definition: operations.h:113
BoundType
Definition: BoundType.h:13
@ WEAK
the given bound is compared by a weak ordering relation
@ STRICT
the given bound is compared by a strict ordering relation
@ INFTY
the given bound is interpreted as minus or plus infinity depending on whether it is the left or the r...
std::size_t hash_all(Args &&... args)
Hashes an arbitrary number of values.
Definition: hash.h:71
bool is_one(const Interval< Number > &i)
Check if this interval is a point-interval containing 1.
Definition: Interval.h:1462
auto & get(const std::string &name)
The class which contains the interval arithmetic including trigonometric functions.
Definition: Interval.h:134
Interval(const BoostInterval &content, BoundType lowerBoundType=BoundType::WEAK, BoundType upperBoundType=BoundType::WEAK)
Constructor which constructs the interval according to the passed boost interval with the passed boun...
Definition: Interval.h:227
Interval(double lower, BoundType lowerBoundType, double upper, BoundType upperBoundType)
Constructor which constructs the interval according to the passed double bounds with the passed bound...
Definition: Interval.h:377
bool is_negative() const
Definition: Interval.h:1133
void shrink_by(const Number &width)
Shrinks the interval by the given value.
bool contains(const Interval< Number > &rhs) const
Checks if the interval contains the given interval.
Interval(unsigned int lower, BoundType lowerBoundType, unsigned int upper, BoundType upperBoundType)
Constructor which constructs the interval according to the passed unsigned int bounds with the passed...
Definition: Interval.h:538
Interval(int lower, BoundType lowerBoundType, int upper, BoundType upperBoundType)
Constructor which constructs the interval according to the passed int bounds with the passed bound ty...
Definition: Interval.h:458
void bloat_by(const Number &width)
Bloats the interval by the given value.
Interval< Number > inverse() const
Calculates the additive inverse of an interval with respect to natural interval arithmetic.
void div_assign(const Interval< Number > &rhs)
void abs_assign()
Calculates and assigns the absolute value of the interval.
void set_upper_bound_type(BoundType b)
The setter for the upper bound type of the interval.
Definition: Interval.h:976
bool div_ext(const Interval< Number > &rhs, Interval< Number > &a, Interval< Number > &b) const
Implements extended interval division with intervals containting zero.
bool is_empty() const
Function which determines, if the interval is empty.
Definition: Interval.h:1056
BoundType lower_bound_type() const
The getter for the lower bound type of the interval.
Definition: Interval.h:883
const BoostInterval & content() const
Returns a reference to the included boost interval.
Definition: Interval.h:865
static Interval< Number > zero_interval()
Method which returns the pointinterval rooted at 0.
Definition: Interval.h:822
Interval(Float n)
Constructor which constructs a pointinterval from a passed general float number (e....
Definition: Interval.h:652
Interval()
Default constructor which constructs the empty interval at point 0.
Definition: Interval.h:176
void set_upper(const Number &n)
The setter for the upper boundary of the interval.
Definition: Interval.h:910
void set(const Number &lower, const Number &upper)
Advanced setter to modify both boundaries at once by passing a boost interval.
Definition: Interval.h:1017
BoostInterval mContent
Definition: Interval.h:163
void inverse_assign()
Calculates and assigns the additive inverse of an interval with respect to natural interval arithmeti...
Interval(Rational lower, BoundType lowerBoundType, Rational upper, BoundType upperBoundType)
Constructor which constructs the interval according to the passed general float bounds (e....
Definition: Interval.h:754
const Number & upper() const
The getter for the upper boundary of the interval.
Definition: Interval.h:849
Number magnitude() const
Returns the magnitude of the interval.
boost::numeric::interval_lib::policies< typename Policy::roundingP, typename Policy::checkingP > BoostIntervalPolicies
Definition: Interval.h:142
bool is_semi_positive() const
Definition: Interval.h:1146
void center_assign()
Computes and assigns the center point of the interval.
void mul_assign(const Interval< Number > &rhs)
bool reciprocal(Interval< Number > &a, Interval< Number > &b) const
Calculates the multiplicative inverse of an interval with respect to natural interval arithmetic.
Interval(const unsigned int &n)
Constructor which constructs a pointinterval from a passed unsigned int.
Definition: Interval.h:500
auto lower_bound() const
Definition: Interval.h:854
Interval(Rational lower, BoundType lowerBoundType, Rational upper, BoundType upperBoundType)
Constructor which constructs the interval according to the passed general rational bounds with the pa...
Definition: Interval.h:613
void diameter_assign()
Computes and assigns the diameter of the interval.
Interval(unsigned int lower, unsigned int upper)
Constructor which constructs an interval from the passed unsigned int bounds.
Definition: Interval.h:511
boost::numeric::interval< Number, BoostIntervalPolicies > BoostInterval
Definition: Interval.h:143
bool contains(const Number &val) const
Checks if the interval contains the given value.
Interval(const LowerBound< Number > &lb, const LowerBound< Number > &ub)
Definition: Interval.h:790
Interval(const UpperBound< Number > &lb, const UpperBound< Number > &ub)
Definition: Interval.h:795
Interval< Number > & operator=(const Interval< Number > &rhs)
The assignment operator.
Definition: Interval.h:990
Interval(Rational n)
Constructor which constructs a pointinterval from a passed general float number (e....
Definition: Interval.h:722
Interval(const Interval< Number > &o)
Copy constructor.
Definition: Interval.h:320
void add_assign(const Interval< Number > &rhs)
bool contains_integer() const
Checks if the interval contains at least one integer value.
bool is_closed_interval() const
Function which determines, if the interval is closed.
Definition: Interval.h:1091
Interval(const Number &lower, BoundType lowerBoundType, const Number &upper, BoundType upperBoundType)
Constructor which constructs the interval according to the passed bounds with the passed bound types.
Definition: Interval.h:277
void sub_assign(const Interval< Number > &rhs)
Interval< Number > root(int deg) const
Calculates the nth root of the interval with respect to natural interval arithmetic.
std::list< Interval< Number > > split(unsigned n) const
Splits the interval into n equally sized parts (strict-weak-cut).
~Interval()=default
Destructor.
Interval(Float lower, Float upper)
Constructor which constructs an interval from the passed general float bounds (e.g.
Definition: Interval.h:666
const Number & lower() const
The getter for the lower boundary of the interval.
Definition: Interval.h:840
void shrink_times(const Number &factor)
Shrinks the interval by a multiple of its width.
void diameter_ratio_assign(const Interval< Number > &rhs)
Computes and assigns the ratio of the diameters of the given intervals.
void set_upper_bound(const Number &n, BoundType b)
The setter for the upper boundary of the interval.
Definition: Interval.h:941
bool is_point_interval() const
Function which determines, if the interval is a pointinterval.
Definition: Interval.h:1071
std::pair< Interval< Number >, Interval< Number > > split() const
Splits the interval into 2 equally sized parts (strict-weak-cut).
bool meets(const Number &n) const
Checks if the interval meets the given value, that is if the given value is contained in the closed i...
Interval(const Number &n)
Constructor which constructs the pointinterval at n.
Definition: Interval.h:184
void set(const BoostInterval &content)
Advanced setter to modify both boundaries at once.
Definition: Interval.h:1007
bool is_open_interval() const
Function which determines, if the interval is open.
Definition: Interval.h:1081
Interval< Number > mul(const Interval< Number > &rhs) const
Multiplies two intervals according to natural interval arithmetic.
bool is_semi_negative() const
Definition: Interval.h:1157
bool is_consistent() const
A quick check for the bound values.
Definition: Interval.h:1426
static Interval< Number > empty_interval()
Method which returns the empty interval rooted at 0.
Definition: Interval.h:813
Interval(Float lower, BoundType lowerBoundType, Float upper, BoundType upperBoundType)
Constructor which constructs the interval according to the passed general float bounds (e....
Definition: Interval.h:684
Sign sgn() const
Determine whether the interval lays entirely left of 0 (NEGATIVE_SIGN), right of 0 (POSITIVE_SIGN) or...
Interval(const Interval< Other > &o)
Definition: Interval.h:326
void magnitude_assign()
Computes and assigns the magnitude of the interval.
void set_lower_bound_type(BoundType b)
The setter for the lower bound type of the interval.
Definition: Interval.h:963
Interval(Rational n)
Constructor which constructs a pointinterval from a passed general rational number.
Definition: Interval.h:581
Interval(const LowerBound< Number > &lb, const UpperBound< Number > &ub)
Definition: Interval.h:785
Number diameter_ratio(const Interval< Number > &rhs) const
Returns the ratio of the diameters of the given intervals.
bool is_positive() const
Definition: Interval.h:1120
bool is_unbounded() const
Function which determines, if the interval is unbounded.
Definition: Interval.h:1036
void root_assign(unsigned deg)
Calculates and assigns the nth root of the interval with respect to natural interval arithmetic.
Interval< Number > convex_hull(const Interval< Number > &interval) const
BoostInterval & content()
Returns a reference to the included boost interval.
Definition: Interval.h:874
void integralPart_assign()
Computes and assigns the integral part of the given interval.
Interval< Number > sub(const Interval< Number > &rhs) const
Subtracts two intervals according to natural interval arithmetic.
BoundType upper_bound_type() const
The getter for the upper bound type of the interval.
Definition: Interval.h:892
Interval(const int &n)
Constructor which constructs a pointinterval from a passed int.
Definition: Interval.h:420
Interval(Rational lower, Rational upper)
Constructor which constructs an interval from the passed general float bounds (e.g.
Definition: Interval.h:736
void bloat_times(const Number &factor)
Bloats the interval times the factor (multiplies the overall width).
bool is_one() const
Function which determines, if the interval is the one interval.
Definition: Interval.h:1111
static Interval< Number > unbounded_interval()
Method which returns the unbounded interval rooted at 0.
Definition: Interval.h:804
bool is_half_bounded() const
Function which determines, if the interval is half-bounded.
Definition: Interval.h:1046
BoundType mUpperBoundType
Definition: Interval.h:165
Interval(Rational lower, Rational upper)
Constructor which constructs an interval from the passed general rational bounds.
Definition: Interval.h:595
Interval< Number > abs() const
Calculates the absolute value of the interval.
std::string toString() const
Creates a string representation of the interval.
BoundType mLowerBoundType
Definition: Interval.h:164
Interval(const Number &lower, const Number &upper)
Constructor which constructs the weak-bounded interval between lower and upper.
Definition: Interval.h:199
Interval< Number > integral_part() const
Computes the integral part of the given interval.
bool is_infinite() const
Function which determines, if the interval is (-oo,oo).
Definition: Interval.h:1026
Number diameter() const
Returns the diameter of the interval.
Interval< Number > add(const Interval< Number > &rhs) const
Adds two intervals according to natural interval arithmetic.
void set_lower(const Number &n)
The setter for the lower boundary of the interval.
Definition: Interval.h:901
bool contains(int val) const
Definition: Interval.h:1237
auto upper_bound() const
Definition: Interval.h:857
bool is_zero() const
Function which determines, if the interval is the zero interval.
Definition: Interval.h:1101
Interval(const double &n)
Constructor which constructs a pointinterval from a passed double.
Definition: Interval.h:336
Number distance(const Interval< Number > &intervalA)
Calculates the distance between two Intervals.
std::map< Variable, Interval< Number > > evalintervalmap
Definition: Interval.h:144
void set_lower_bound(const Number &n, BoundType b)
The setter for the lower boundary of the interval.
Definition: Interval.h:919
Interval(double lower, double upper)
Constructor which constructs an interval from the passed double bounds.
Definition: Interval.h:349
Interval(int lower, int upper)
Constructor which constructs an interval from the passed int bounds.
Definition: Interval.h:431
Interval< Number > div(const Interval< Number > &rhs) const
Divides two intervals according to natural interval arithmetic.
friend std::ostream & operator<<(std::ostream &str, const Interval< Number > &i)
Operator which passes a string representation of this to the given ostream.
Definition: Interval.h:1304
Struct which holds the rounding and checking policies required for boost interval.
Definition: Interval.h:68
static void sanitize(Interval &)
Definition: Interval.h:71
boost::numeric::interval_lib::checking_no_nan< double, boost::numeric::interval_lib::checking_no_nan< double > > checkingP
Definition: Interval.h:82
static void sanitize(Interval &n)
Definition: Interval.h:83
boost::numeric::interval_lib::save_state< boost::numeric::interval_lib::rounded_transc_std< double > > roundingP
Definition: Interval.h:81
BoundType bound_type
Definition: Interval.h:98
const Number & number
Definition: Interval.h:97
BoundType bound_type
Definition: Interval.h:108
const Number & number
Definition: Interval.h:107
std::size_t operator()(const carl::Interval< Number > &interval) const
Calculates the hash of an interval.
Definition: Interval.h:1553
States whether a given type is an Interval.
Definition: typetraits.h:10
static const T & get()
Definition: constants.h:42
static const T & get()
Definition: constants.h:51
States if a type is a number type.
Definition: typetraits.h:237