12 template<
typename Poly>
17 template<
typename Poly>
26 template<
typename Poly>
28 using Rational =
typename Poly::NumberType;
30 if (!constraint.
variables().has(eliminationVar)) {
34 std::vector<Poly> factors;
41 factors.push_back(iter.first);
46 sideConditions.insert(cons);
51 factors.push_back(constraint.
lhs());
54 for (
const auto& factor : factors) {
56 const auto& coeffs = varInfo.coeffs();
57 assert(!coeffs.empty());
59 switch (coeffs.rbegin()->first) {
67 auto iter = coeffs.find(0);
68 if (iter != coeffs.end()) constantCoeff = iter->second;
74 sideCond.insert(cons);
76 SqrtEx<Poly> sqEx(-constantCoeff, Poly(), coeffs.rbegin()->second, Poly());
77 results.push_back({std::move(sqEx), std::move(sideCond)});
84 auto iter = coeffs.find(0);
85 if (iter != coeffs.end()) constantCoeff = iter->second;
87 iter = coeffs.find(1);
88 if (iter != coeffs.end()) linearCoeff = iter->second;
89 Poly radicand =
carl::pow(linearCoeff, 2) -
Rational(4) * coeffs.rbegin()->second * constantCoeff;
97 sideCond.insert(cons11);
99 sideCond.insert(cons12);
100 SqrtEx<Poly> sqEx(-constantCoeff, Poly(), linearCoeff, Poly());
101 results.push_back({std::move(sqEx), std::move(sideCond)});
110 sideCond.insert(cons21);
113 sideCond.insert(cons22);
118 results.push_back({std::move(sqExA), sideCond});
122 results.push_back({std::move(sqExB), std::move(sideCond)});
138 template<
typename Poly>
140 using Rational =
typename Poly::NumberType;
142 if (varcomp.
var() != eliminationVar && !
carl::variables(varcomp).has(eliminationVar) ) {
152 assert(varcomp.
var() == eliminationVar);
154 const auto& ran = std::get<IntRepRealAlgebraicNumber<Rational>>(varcomp.
value());
155 if (ran.is_numeric()) {
161 assert(factor.degree(eliminationVar) > 0);
162 if (factor.degree(eliminationVar) > 2)
continue;
165 assert(roots.is_univariate());
166 auto it = std::find(roots.roots().begin(), roots.roots().end(), ran);
167 if (it != roots.roots().end()) {
168 size_t idx = std::distance(roots.roots().begin(), it);
171 const auto& coeffs = varInfo.coeffs();
172 assert(!coeffs.empty());
174 if (coeffs.rbegin()->first == 1) {
177 auto iter = coeffs.find(0);
178 if (iter != coeffs.end()) constantCoeff = iter->second;
182 SqrtEx<Poly> sqEx(-constantCoeff, Poly(), coeffs.rbegin()->second, Poly());
183 results.push_back({std::move(sqEx), {}});
185 assert(coeffs.rbegin()->first == 2);
188 auto iter = coeffs.find(0);
189 if (iter != coeffs.end()) constantCoeff = iter->second;
191 iter = coeffs.find(1);
192 if (iter != coeffs.end()) linearCoeff = iter->second;
193 Poly radicand =
carl::pow(linearCoeff, 2) -
Rational(4) * coeffs.rbegin()->second * constantCoeff;
202 results.push_back({std::move(sqExA), {}});
207 results.push_back({std::move(sqExB), {}});
UnivariatePolynomial< C > to_univariate_polynomial(const MultivariatePolynomial< C, O, P > &p)
Convert a univariate polynomial that is currently (mis)represented by a 'MultivariatePolynomial' into...
auto irreducible_factors(const ContextPolynomial< Coeff, Ordering, Policies > &p, bool constants=true)
std::set< Constraint< Poly >, carl::less< Constraint< Poly >, false > > Constraints
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'.
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 is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
VarInfo< MultivariatePolynomial< Coeff, Ordering, Policies > > var_info(const MultivariatePolynomial< Coeff, Ordering, Policies > &poly, const Variable var, bool collect_coeff=false)
bool is_trivial(const Factors< MultivariatePolynomial< C, O, P >> &f)
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...
void variables(const BasicConstraint< Pol > &c, carlVariables &vars)
Factors< MultivariatePolynomial< C, O, P > > factorization(const MultivariatePolynomial< C, O, P > &p, bool includeConstants=true)
Try to factorize a multivariate polynomial.
Interval< Number > pow(const Interval< Number > &i, Integer exp)
static bool gather_zeros(const Constraint< Poly > &constraint, const Variable &eliminationVar, std::vector< zero< Poly >> &results)
Gathers zeros with side conditions from the given constraint in the given variable.
std::ostream & operator<<(std::ostream &os, const Term< Poly > &s)
A Variable represents an algebraic variable that can be used throughout carl.
Represent a sum type/variant of an (in)equality between a variable on the left-hand side and multivar...
const std::variant< MR, RAN > & value() const
Represent a polynomial (in)equality against zero.
const auto & variables() const
const Factors< Pol > & lhs_factorization() const
A square root expression with side conditions.
Constraints< Poly > side_condition