17 using carl::operator<<;
25 template<
typename Number>
35 std::vector<IntRepRealAlgebraicNumber<Number>>
mRoots;
68 CARL_LOG_TRACE(
"carl.ran.interval",
"Constant polynomial, thus no roots");
88 Number rad = b*b - 4*a*c;
93 if (res.first == res.second) {
148 bool found_root =
false;
178 assert(queue.empty());
180 std::vector<double> coeffs;
189 for (
double& a: approx) {
192 std::sort(approx.begin(), approx.end());
193 approx.erase(std::unique(approx.begin(), approx.end()), approx.end());
194 CARL_LOG_DEBUG(
"carl.ran.interval",
"Double approximations: " << approx);
196 std::vector<Number> roots;
197 for (
double r: approx) {
199 Number n = carl::rationalize<Number>(r);
204 roots.emplace_back(n);
209 std::vector<Number> endpoints;
210 endpoints.emplace_back(
mInterval.lower());
211 if (roots.size() > 0) {
212 for (std::size_t i = 0; i < roots.size() - 1; ++i) {
217 endpoints.emplace_back(tmp);
220 endpoints.emplace_back(
mInterval.upper());
224 for (std::size_t i = 0; i < endpoints.size() - 1; ++i) {
232 std::deque<Interval<Number>> queue;
239 while (!queue.empty()) {
240 auto cur = queue.front();
245 if (variations == 0) {
249 if (variations == 1) {
250 CARL_LOG_DEBUG(
"carl.ran.interval",
"A single root within " << cur);
262 CARL_LOG_DEBUG(
"carl.ran.interval",
"Splitting " << cur <<
" at " << pivot);
301 std::vector<IntRepRealAlgebraicNumber<Number>>
get_roots() {
306 for (
const auto& factor: factors) {
307 CARL_LOG_DEBUG(
"carl.ran.interval",
"Coputing root of factor " << factor);
#define CARL_LOG_TRACE(channel, msg)
#define CARL_LOG_DEBUG(channel, msg)
carl is the main namespace for the library.
MultivariatePolynomial< C, O, P > squareFreePart(const MultivariatePolynomial< C, O, P > &polynomial)
Number sample(const Interval< Number > &i, bool includingBounds=true)
Searches for some point in this interval, preferably near the midpoint and with a small representatio...
std::pair< cln::cl_RA, cln::cl_RA > sqrt_fast(const cln::cl_RA &a)
Compute square root in a fast but less precise way.
int count_real_roots(const std::vector< UnivariatePolynomial< Coefficient >> &seq, const Interval< Coefficient > &i)
Calculate the number of real roots of a polynomial within a given interval based on a sturm sequence ...
std::size_t sign_variations(InputIterator begin, InputIterator end)
Counts the number of sign variations in the given object range.
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
bool is_root_of(const UnivariatePolynomial< Coeff > &p, const Coeff &value)
Interval< Number > set_intersection(const Interval< Number > &lhs, const Interval< Number > &rhs)
Intersects two intervals in a set-theoretic manner.
void eliminate_root(UnivariatePolynomial< Coeff > &p, const Coeff &root)
Reduces the polynomial such that the given root is not a root anymore.
double to_double(const cln::cl_RA &n)
Converts the given fraction to a double.
cln::cl_I round(const cln::cl_RA &n)
Round a fraction to next integer.
Coeff lagrangeBound(const UnivariatePolynomial< Coeff > &p)
@ WEAK
the given bound is compared by a weak ordering relation
@ STRICT
the given bound is compared by a strict ordering relation
void eliminate_zero_root(UnivariatePolynomial< Coeff > &p)
Reduces the given polynomial such that zero is not a root anymore.
Factors< MultivariatePolynomial< C, O, P > > factorization(const MultivariatePolynomial< C, O, P > &p, bool includeConstants=true)
Try to factorize a multivariate polynomial.
std::vector< double > root_approximation(const std::vector< double > &coeffs)
Compute approximations of the real roots of the univariate polynomials with the given coefficients.
The class which contains the interval arithmetic including trigonometric functions.
const std::vector< Coefficient > & coefficients() const &
Retrieves the coefficients defining this polynomial.
uint degree() const
Get the maximal exponent of the main variable.
bool zero_is_root() const
Checks if zero is a real root of this polynomial.
Compact class to isolate real roots from a univariate polynomial using bisection.
UnivariatePolynomial< Number > mPolynomial
The polynomial.
static constexpr bool simplify_by_factorization
Factorize polynomial and handle factors individually.
std::vector< IntRepRealAlgebraicNumber< Number > > mRoots
The list of roots.
Interval< Number > mInterval
The bounding interval.
void add_trivial_root(const Number &n)
bool check_interval_bounds()
Check whether the interval bounds are roots.
void add_root(const Number &n)
Add a root to mRoots and simplify polynomial accordingly (essentially divide by x-n)
void bisect_by_approximation(std::deque< Interval< Number >> &queue)
Initialize the bisection queue using approximations.
void compute_roots()
Do actual root isolation.
void eliminate_zero_roots()
The sturm sequence for mPolynomial.
void isolate_by_bisection()
Perform bisection.
bool isolate_roots_trivially()
Directly solve low-degree polynomials.
std::vector< IntRepRealAlgebraicNumber< Number > > get_roots()
Compute and sort the roots of mPolynomial within mInterval.
void add_trivial_root(const Interval< Number > &i)
void add_root(const Interval< Number > &i)
Add a root to mRoots, based on an isolating interval.
void update_root_bounds()
Use root bounds to shrink mInterval.
static constexpr bool initialize_bisection_by_approximation
Initialize bisection intervals using approximations.
RealRootIsolation(const UnivariatePolynomial< Number > &polynomial, const Interval< Number > &interval)