4 #include "../poly/umvpoly/functions/Definiteness.h"
11 template<
typename Pol>
13 CARL_LOG_FUNC(
"carl.constraint", var <<
", " << rel <<
", " << bound);
20 lhs += bound +
typename Pol::NumberType(1);
45 lhs -= (bound -
typename Pol::NumberType(1));
68 lhs =
Pol(
typename Pol::NumberType(0));
80 lhs =
Pol(
typename Pol::NumberType(0));
91 template<
typename Pol>
94 if (lhs.is_constant()) {
95 CARL_LOG_TRACE(
"carl.core.constraint", lhs <<
" is constant, we simply evaluate.");
99 CARL_LOG_TRACE(
"carl.core.constraint",
"Normalizing leading coefficient of linear poly.");
119 return init_bound<Pol>(lhs.single_variable(), rel, (-lhs.constant_part()) / lhs.lcoeff());
121 CARL_LOG_TRACE(
"carl.core.constraint",
"Normalizing " << lhs <<
" " << rel <<
" 0");
122 auto new_lhs =
is_zero(lhs) ?
Pol(
typename Pol::NumberType(0)) : lhs.coprime_coefficients();
124 if (!
is_zero(new_lhs) && new_lhs.lterm().coeff() <
typename Pol::NumberType(0)) new_lhs = -new_lhs;
126 if (!
is_zero(new_lhs) && (lhs.lterm().coeff() < 0) != (new_lhs.lterm().coeff() < 0)) new_lhs = -new_lhs;
128 if (!
is_zero(new_lhs) && (lhs.lterm().coeff() < 0) == (new_lhs.lterm().coeff() < 0)) new_lhs = -new_lhs;
131 if (!
is_zero(new_lhs) && (lhs.lterm().coeff() < 0) == (new_lhs.lterm().coeff() < 0)) new_lhs = -new_lhs;
139 template<
typename Pol>
142 if (!vars.integer().empty() && vars.real().empty()) {
153 template<
typename Pol>
155 if (constraint.
lhs().is_constant()) {
156 CARL_LOG_TRACE(
"carl.formula.constraint",
"Lhs " << constraint.
lhs() <<
" is constant");
159 if (!lhs_definiteness) {
162 CARL_LOG_TRACE(
"carl.formula.constraint",
"Checking " << constraint.
relation() <<
" against " << *lhs_definiteness);
200 template<
typename Pol>
203 if (consistency == 0) {
205 }
else if (consistency == 1) {
210 template<
typename Pol>
212 using PolyT =
typename Pol::PolyType;
215 if (!(vars.size() == 1 && !constraint.
lhs().is_linear() && constraint.
lhs().nr_terms() == 1))
return false;
217 if (!lhs_definiteness) {
236 constraint =
init_constraint(PolyT(
typename Pol::NumberType(-1)) * PolyT(var) * PolyT(var), rel);
238 constraint =
init_constraint((constraint.
lhs().trailingTerm().coeff() > 0 ? PolyT(
typename Pol::NumberType(1)) : PolyT(
typename Pol::NumberType(-1))) * PolyT(var), rel);
245 constraint =
init_constraint((constraint.
lhs().trailingTerm().coeff() > 0 ? PolyT(
typename Pol::NumberType(1)) : PolyT(
typename Pol::NumberType(-1))) * PolyT(var), rel);
254 constraint =
init_constraint((constraint.
lhs().trailingTerm().coeff() > 0 ? PolyT(
typename Pol::NumberType(1)) : PolyT(
typename Pol::NumberType(-1))) * PolyT(var), rel);
261 constraint =
init_constraint(PolyT(
typename Pol::NumberType(-1)) * PolyT(var) * PolyT(var), rel);
263 constraint =
init_constraint((constraint.
lhs().trailingTerm().coeff() > 0 ? PolyT(
typename Pol::NumberType(1)) : PolyT(
typename Pol::NumberType(-1))) * PolyT(var), rel);
273 template<
typename Pol>
277 if (vars.integer().empty() || !vars.real().empty())
return false;
279 typename Pol::NumberType constPart = constraint.
lhs().constant_part();
280 if (constPart !=
typename Pol::NumberType(0)) {
282 typename Pol::NumberType g =
carl::abs(constraint.
lhs().coprime_factor_without_constant());
283 assert(g !=
typename Pol::NumberType(0));
295 Pol newLhs = ((constraint.
lhs() - constPart) * g);
296 newLhs +=
carl::floor((constPart * g)) +
typename Pol::NumberType(1);
301 Pol newLhs = ((constraint.
lhs() - constPart) * g);
307 Pol newLhs = ((constraint.
lhs() - constPart) * g);
308 newLhs +=
carl::floor((constPart * g)) +
typename Pol::NumberType(1);
313 Pol newLhs = ((constraint.
lhs() - constPart) * g);
327 template<
typename Pol>
329 auto constraint = init_bound<Pol>(var,rel,bound);
338 template<
typename Pol>
344 if (!constraint.is_trivial_true() && !constraint.is_trivial_false()) {
#define CARL_LOG_FUNC(channel, args)
#define CARL_LOG_TRACE(channel, msg)
MultivariatePolynomial< Rational > Pol
Interval< Number > ceil(const Interval< Number > &_in)
Method which returns the next larger integer of the passed number or the number itself,...
Interval< Number > abs(const Interval< Number > &_in)
Method which returns the absolute value of the passed number.
Interval< Number > floor(const Interval< Number > &_in)
Method which returns the next smaller integer of this number or the number itself,...
cln::cl_I mod(const cln::cl_I &a, const cln::cl_I &b)
Calculate the remainder of the integer division.
Definiteness definiteness(const Term< Coeff > &t)
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)
cln::cl_I get_num(const cln::cl_RA &n)
Extract the numerator from a fraction.
bool is_integer(const Interval< Number > &n)
bool is_negative(const cln::cl_I &n)
cln::cl_I get_denom(const cln::cl_RA &n)
Extract the denominator from a fraction.
@ NEGATIVE_SEMI
Indicates that .
@ NEGATIVE
Indicates that .
@ POSITIVE
Indicates that .
@ POSITIVE_SEMI
Indicates that .
void variables(const BasicConstraint< Pol > &c, carlVariables &vars)
unsigned is_consistent_definiteness(const BasicConstraint< Pol > &constraint, std::optional< Definiteness > lhs_definiteness=std::nullopt)
BasicConstraint< Pol > create_normalized_constraint(const Pol &lhs, Relation rel)
BasicConstraint< Pol > create_normalized_bound(Variable var, Relation rel, const typename Pol::NumberType &bound)
BasicConstraint< Pol > init_bound(Variable var, Relation rel, const typename Pol::NumberType &bound)
static constexpr bool FULL_EFFORT_FOR_DEFINITENESS_CHECK
bool simplify_nonlinear_univariate_monomial_inplace(BasicConstraint< Pol > &constraint, std::optional< Definiteness > lhs_definiteness=std::nullopt)
bool simplify_integer_inplace(BasicConstraint< Pol > &constraint)
BasicConstraint< Pol > init_constraint(const Pol &lhs, Relation rel)
void normalize_integer_inplace(BasicConstraint< Pol > &constraint)
void normalize_consistency_inplace(BasicConstraint< Pol > &constraint, std::optional< Definiteness > lhs_definiteness=std::nullopt)
Represent a polynomial (in)equality against zero.
void set_relation(Relation rel)
Relation relation() const
A Variable represents an algebraic variable that can be used throughout carl.
constexpr VariableType type() const noexcept
Retrieves the type of the variable.