3 #include "../common/RealRoots.h"
24 template<typename Coeff, typename Number = typename UnderlyingNumberType<Coeff>::type, EnableIf<std::is_same<Coeff, Number>> =
dummy>
32 CARL_LOG_DEBUG(
"carl.ran.interval", polynomial <<
" within " << interval);
44 template<typename Coeff, typename Number = typename UnderlyingNumberType<Coeff>::type, DisableIf<std::is_same<Coeff, Number>> =
dummy>
45 RealRootsResult<IntRepRealAlgebraicNumber<Number>>
real_roots(
46 const UnivariatePolynomial<Coeff>& polynomial,
49 assert(polynomial.is_univariate());
50 return real_roots(polynomial.convert(std::function<Number(
const Coeff&)>([](
const Coeff& c){
return c.constant_part(); })), interval);
68 template<
typename Coeff,
typename Number>
74 CARL_LOG_FUNC(
"carl.ran.interval", poly <<
" in " << poly.
main_var() <<
", " << varToRANMap <<
", " << interval);
75 assert(varToRANMap.count(poly.
main_var()) == 0);
82 CARL_LOG_TRACE(
"carl.ran.interval",
"poly is constant but not zero -> no root");
92 if (varToRANMap.count(v) == 0) {
93 CARL_LOG_TRACE(
"carl.ran.interval",
"poly still contains unassigned variable " << v <<
" -> non-univariate");
96 assert(varToRANMap.count(v) > 0);
97 if (varToRANMap.at(v).is_numeric()) {
100 ir_map.emplace(v, varToRANMap.at(v));
104 CARL_LOG_TRACE(
"carl.ran.interval",
"poly is 0 after substituting rational assignments -> nullified");
107 if (ir_map.empty()) {
109 CARL_LOG_TRACE(
"carl.ran.interval",
"poly " << polyCopy <<
" is univariate after substituting rational assignments");
112 CARL_LOG_TRACE(
"carl.ran.interval", polyCopy <<
" in " << polyCopy.
main_var() <<
", " << varToRANMap <<
", " << interval);
113 assert(ir_map.find(polyCopy.
main_var()) == ir_map.end());
117 for (
const auto& ass : ir_map) ord_ass.emplace_back(ass);
118 std::sort(ord_ass.begin(), ord_ass.end(), [](
const auto& a,
const auto& b){
119 return a.second.polynomial().degree() > b.second.polynomial().degree();
124 CARL_LOG_TRACE(
"carl.ran.interval",
"poly still contains unassigned variable -> non-univariate");
128 CARL_LOG_TRACE(
"carl.ran.interval",
"got zero polynomial -> nullified");
132 CARL_LOG_TRACE(
"carl.ran.interval",
"Calling on " << *evaledpoly);
134 std::vector<IntRepRealAlgebraicNumber<Number>> roots;
136 for (
const auto& r: res.roots()) {
139 CARL_LOG_TRACE(
"carl.ran.interval",
"Evaluating " << cons <<
" on " << ir_map);
141 roots.emplace_back(r);
143 CARL_LOG_TRACE(
"carl.ran.interval",
"Purging spurious root " << r);
150 template<
typename Coeff,
typename Ordering,
typename Policies>
A small wrapper that configures logging for carl.
#define CARL_LOG_FUNC(channel, args)
#define CARL_LOG_TRACE(channel, msg)
#define CARL_LOG_DEBUG(channel, msg)
carl is the main namespace for the library.
std::vector< std::pair< Variable, T > > OrderedAssignment
RealRootsResult< IntRepRealAlgebraicNumber< Number > > real_roots(const UnivariatePolynomial< Coeff > &polynomial, const Interval< Number > &interval=Interval< Number >::unbounded_interval())
Find all real roots of a univariate 'polynomial' with numeric coefficients within a given 'interval'.
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
bool evaluate(const BasicConstraint< Poly > &c, const Assignment< Number > &m)
typename UnderlyingNumberType< P >::type Coeff
std::map< Variable, T > Assignment
void variables(const BasicConstraint< Pol > &c, carlVariables &vars)
void substitute_inplace(MultivariateRoot< Poly > &mr, Variable var, const Poly &poly)
Create a copy of the underlying polynomial with the given variable replaced by the given polynomial.
std::optional< UnivariatePolynomial< Number > > substitute_rans_into_polynomial(const UnivariatePolynomial< Coeff > &p, const OrderedAssignment< IntRepRealAlgebraicNumber< Number >> &m, bool use_lazard=false)
Represent a polynomial (in)equality against zero.
A Variable represents an algebraic variable that can be used throughout carl.
The class which contains the interval arithmetic including trigonometric functions.
static Interval< Number > unbounded_interval()
Method which returns the unbounded interval rooted at 0.
This class represents a univariate polynomial with coefficients of an arbitrary type.
bool is_number() const
Checks whether the polynomial is only a number.
Variable main_var() const
Retrieves the main variable of this polynomial.
bool is_univariate() const
Checks if the polynomial is univariate, that means if only one variable occurs.
const UnivariatePolynomial< MultivariatePolynomial< Coeff, Ordering, Policies > > & content() const
typename UnivariatePolynomial< NumberType >::RootType RootType
Compact class to isolate real roots from a univariate polynomial using bisection.
std::vector< IntRepRealAlgebraicNumber< Number > > get_roots()
Compute and sort the roots of mPolynomial within mInterval.