31 template<
typename Poly>
35 using RAN =
typename Poly::RootType;
60 std::size_t
k() const noexcept {
67 const Poly&
poly() const noexcept {
87 return m_poly.is_univariate();
94 template<
typename Poly>
96 return std::forward_as_tuple(lhs.
var(), lhs.
k(), lhs.
poly()) == std::forward_as_tuple(lhs.
var(), rhs.
k(), rhs.
poly());
98 template<
typename Poly>
100 return std::forward_as_tuple(lhs.
var(), lhs.
k(), lhs.
poly()) < std::forward_as_tuple(lhs.
var(), rhs.
k(), rhs.
poly());
105 return os <<
"rootExpr(" << mr.
poly() <<
", " << mr.
k() <<
", " << mr.
var() <<
")";
113 template<
typename Poly>
115 bool hadVar = vars.
has(mr.
var());
124 template<
typename Poly>
129 template<
typename Poly>
132 if (ran.is_numeric()) {
133 return (std::size_t)1;
136 auto it = std::find(roots.roots().begin(), roots.roots().end(), ran);
137 assert(it != roots.roots().end());
138 return (std::size_t)std::distance(roots.roots().begin(), it)+1;
151 template<
typename Poly>
153 CARL_LOG_DEBUG(
"carl.rootexpression",
"Evaluate: " << mr <<
" against: " << m);
162 if (!result.is_univariate()) {
163 CARL_LOG_TRACE(
"carl.rootexpression", mr.
poly() <<
" is not univariate (nullified: " << result.is_nullified() <<
"; non-univariate: " << result.is_non_univariate() <<
").");
166 CARL_LOG_DEBUG(
"carl.rootexpression",
"Roots: " << result.roots());
167 if (result.roots().size() < mr.
k()) {
168 CARL_LOG_TRACE(
"carl.rootexpression", mr.
k() <<
"th root does not exist.");
171 CARL_LOG_TRACE(
"carl.rootexpression",
"Take " << mr.
k() <<
"th of isolated roots " << result.roots());
172 assert(result.roots().size() >= mr.
k());
174 CARL_LOG_DEBUG(
"carl.rootexpression",
"Result is " << result.roots()[mr.
k()-1]);
175 return result.roots()[mr.
k()-1];
181 template<
typename Pol>
182 struct hash<
carl::MultivariateRoot<Pol>> {
Represent a real algebraic number (RAN) in one of several ways:
A small wrapper that configures logging for carl.
#define CARL_LOG_TRACE(channel, msg)
#define CARL_LOG_DEBUG(channel, msg)
carl is the main namespace for the library.
UnivariatePolynomial< C > to_univariate_polynomial(const MultivariatePolynomial< C, O, P > &p)
Convert a univariate polynomial that is currently (mis)represented by a 'MultivariatePolynomial' into...
MultivariateRoot< Poly > convert_to_mvroot(const typename MultivariateRoot< Poly >::RAN &ran, Variable var)
bool operator<(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
std::ostream & operator<<(std::ostream &os, const BasicConstraint< Poly > &c)
Prints the given constraint on the given stream.
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 evaluate(const BasicConstraint< Poly > &c, const Assignment< Number > &m)
bool operator==(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
std::map< Variable, T > Assignment
std::size_t hash_all(Args &&... args)
Hashes an arbitrary number of values.
void variables(const BasicConstraint< Pol > &c, carlVariables &vars)
UnivariatePolynomial< MultivariatePolynomial< typename UnderlyingNumberType< Coeff >::type > > switch_main_variable(const UnivariatePolynomial< Coeff > &p, Variable newVar)
Switches the main variable using a purely syntactical restructuring.
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.
A Variable represents an algebraic variable that can be used throughout carl.
bool has(Variable var) const
bool is_univariate() const
Variable m_var
The main variable.
std::size_t k() const noexcept
Return k, the index of the root.
typename Poly::RootType RAN
std::size_t m_k
Specifies which root to consider.
MultivariateRoot(const Poly &poly, std::size_t k, Variable var)
Poly m_poly
Polynomial defining this root.
const Poly & poly() const noexcept
friend std::optional< typename MultivariateRoot< P >::RAN > evaluate(const MultivariateRoot< P > &mr, const carl::Assignment< typename MultivariateRoot< P >::RAN > &m)
Variable var() const noexcept
typename UnderlyingNumberType< Poly >::type Number
std::size_t operator()(const carl::MultivariateRoot< Pol > &mv) const
T type
A type associated with the type.