carl  24.04
Computer ARithmetic Library
Power.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Interval.h"
4 
5 #include <cassert>
6 
7 
8 namespace carl {
9 
10 template<typename Number, typename Integer>
12  assert(i.is_consistent());
13  if (exp % 2 == 0) {
14  if (i.is_infinite()) {
16  } else if (i.lower_bound_type() == BoundType::INFTY) {
19  } else {
21  }
22  } else if (i.upper_bound_type() == BoundType::INFTY) {
25  } else {
27  }
28  } else {
29  BoundType rType = i.upper_bound_type();
30  BoundType lType = i.lower_bound_type();
31  if (carl::abs(i.lower()) > carl::abs(i.upper())) {
32  std::swap(lType, rType);
33  }
36  } else {
37  return Interval<Number>(boost::numeric::pow(i.content(), int(exp)), lType, rType);
38  }
39  }
40  } else {
42  }
43 }
44 
45 template<typename Number, typename Integer>
47  i = pow(i, exp);
48 }
49 
50 template<typename Number, EnableIf<std::is_floating_point<Number>> = dummy>
52  assert(i.is_consistent());
53  Interval<Number> res;
56  }
60  } else {
62  }
63  } else {
65  }
66  CARL_LOG_DEBUG("carl.interval", "sqrt(" << i << ") = " << res);
67  return res;
68 }
69 
70 template<typename Number, EnableIf<std::is_floating_point<Number>> = dummy>
72  i = sqrt(i, exp);
73 }
74 
75 }
#define CARL_LOG_DEBUG(channel, msg)
Definition: carl-logging.h:43
mpz_class Integer
carl is the main namespace for the library.
UnivariatePolynomial< Coeff > pow(const UnivariatePolynomial< Coeff > &p, std::size_t exp)
Returns a polynomial to the given power.
Definition: Power.h:77
void swap(Variable &lhs, Variable &rhs)
Definition: Variables.h:202
Interval< Number > abs(const Interval< Number > &_in)
Method which returns the absolute value of the passed number.
Definition: Interval.h:1511
void pow_assign(Interval< Number > &i, Integer exp)
Definition: Power.h:46
Interval< Number > exp(const Interval< Number > &i)
Definition: Exponential.h:10
Interval< Number > sqrt(const Interval< Number > &i)
Definition: Power.h:51
void sqrt_assign(Interval< Number > &i)
Definition: Power.h:71
BoundType
Definition: BoundType.h:13
@ WEAK
the given bound is compared by a weak ordering relation
@ INFTY
the given bound is interpreted as minus or plus infinity depending on whether it is the left or the r...
Interval< Number > pow(const Interval< Number > &i, Integer exp)
Definition: Power.h:11
auto & get(const std::string &name)
The class which contains the interval arithmetic including trigonometric functions.
Definition: Interval.h:134
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
const Number & upper() const
The getter for the upper boundary of the interval.
Definition: Interval.h:849
boost::numeric::interval< Number, BoostIntervalPolicies > BoostInterval
Definition: Interval.h:143
bool contains(const Number &val) const
Checks if the interval contains the given value.
const Number & lower() const
The getter for the lower boundary of the interval.
Definition: Interval.h:840
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
BoundType upper_bound_type() const
The getter for the upper bound type of the interval.
Definition: Interval.h:892
bool is_infinite() const
Function which determines, if the interval is (-oo,oo).
Definition: Interval.h:1026
static const T & get()
Definition: constants.h:42