27 template<
typename Poly>
46 if (
value.is_univariate()) {
70 const std::variant<MR, RAN>&
value()
const {
73 std::variant<MR, RAN>&
value() {
97 template<typename Poly, std::enable_if_t<!needs_context_type<Poly>::value,
bool> =
true>
101 const auto& mr = std::get<typename VariableComparison<Poly>::MR>(f.
value());
102 if (mr.poly().degree(mr.var()) != 1)
return std::nullopt;
103 if (mr.k() != 1)
return std::nullopt;
104 auto lcoeff = mr.poly().coeff(mr.var(), 1);
106 auto ccoeff = mr.poly().coeff(mr.var(), 0);
117 template<typename Poly, std::enable_if_t<needs_context_type<Poly>::value,
bool> =
true>
118 std::optional<BasicConstraint<Poly>>
as_constraint(
const VariableComparison<Poly>& f) {
121 const auto& mr = std::get<typename VariableComparison<Poly>::MR>(f.value());
122 assert(mr.var() == mr.poly().main_var());
123 if (mr.poly().degree() != 1)
return std::nullopt;
124 if (mr.k() != 1)
return std::nullopt;
125 auto lcoeff = mr.poly().lcoeff();
127 auto ccoeff = mr.poly().coeff(0);
128 return BasicConstraint<Poly>(Poly(mr.poly().context(), f.var())*lcoeff + ccoeff, lcoeff>0 ? rel :
carl::turn_around(rel));
137 template<typename Poly, std::enable_if_t<!needs_context_type<Poly>::value,
bool> =
true>
140 const auto& ran = std::get<typename VariableComparison<Poly>::RAN>(f.
value());
141 if (ran.is_numeric())
return Poly(f.
var()) - ran.value();
144 const auto& mr = std::get<typename VariableComparison<Poly>::MR>(f.
value());
145 assert(mr.var() == f.
var());
150 template<typename Poly, std::enable_if_t<needs_context_type<Poly>::value,
bool> =
true>
153 const auto& mr = std::get<typename VariableComparison<Poly>::MR>(f.value());
154 assert(mr.var() == f.var());
158 template<
typename Poly>
161 if (a.find(f.
var()) == a.end())
return boost::indeterminate;
164 lhs = std::get<typename VariableComparison<Poly>::RAN>(f.
value());
166 if (!evaluate_non_welldef) {
168 if (!res)
return boost::indeterminate;
172 for (
const auto& v : vars) {
173 if (a.find(v) == a.end())
return boost::indeterminate;
184 template<
typename Pol>
193 template<
typename Poly>
197 template<
typename Poly>
200 if (lhs.
var() != rhs.
var())
return lhs.
var() < rhs.
var();
204 template<
typename Poly>
206 return os <<
"(" << vc.
var() <<
" " << (vc.
negated() ?
"! " :
"") << vc.
relation() <<
" " << vc.
value() <<
")";
211 template<
typename Pol>
212 struct hash<
carl::VariableComparison<Pol>> {
Represent a dynamic root, also known as a "root expression".
Represent a real algebraic number (RAN) in one of several ways:
#define CARL_LOG_DEBUG(channel, msg)
carl is the main namespace for the library.
bool operator<(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
bool is_constant(const ContextPolynomial< Coeff, Ordering, Policies > &p)
std::ostream & operator<<(std::ostream &os, const BasicConstraint< Poly > &c)
Prints the given constraint on the given stream.
std::optional< BasicConstraint< Poly > > as_constraint(const VariableComparison< Poly > &f)
Convert this variable comparison "v < root(..)" into a simpler polynomial (in)equality against zero "...
bool evaluate(const BasicConstraint< Poly > &c, const Assignment< Number > &m)
UnivariatePolynomial< Coeff > replace_main_variable(const UnivariatePolynomial< Coeff > &p, Variable newVar)
Replaces the main variable in a polynomial.
void visit(const Formula< Pol > &formula, Visitor func)
Recursively calls func on every subformula.
Relation inverse(Relation r)
Inverts the given relation symbol.
bool operator==(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
Relation turn_around(Relation r)
Turns around the given relation symbol, in the sense that LESS (LEQ) and GREATER (GEQ) are swapped.
Poly defining_polynomial(const VariableComparison< Poly > &f)
Return a polynomial containing the lhs-variable that has a same root for the this lhs-variable as the...
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)
auto & get(const std::string &name)
Represent a polynomial (in)equality against zero.
A Variable represents an algebraic variable that can be used throughout carl.
typename Poly::RootType RAN
Represent a sum type/variant of an (in)equality between a variable on the left-hand side and multivar...
VariableComparison(Variable v, const std::variant< MR, RAN > &value, Relation rel, bool neg)
const std::variant< MR, RAN > & value() const
VariableComparison resolve_negation() const
std::variant< MR, RAN > & value()
typename MultivariateRoot< Poly >::RAN RAN
typename UnderlyingNumberType< Poly >::type Number
std::variant< MR, RAN > m_value
Relation relation() const
VariableComparison(Variable v, const RAN &value, Relation rel)
VariableComparison invert_relation() const
VariableComparison(Variable v, const MR &value, Relation rel)
VariableComparison negation() const
MultivariateRoot< Poly > MR
std::size_t operator()(const carl::VariableComparison< Pol > &vc) const
T type
A type associated with the type.