6 #include "../MultivariatePolynomial.h"
11 template<
typename C,
typename O,
typename P>
13 std::vector<std::pair<C,MultivariatePolynomial<C,O,P>>> result;
18 for (
auto term = p.
rbegin(); term != p.
rend(); ++term) {
24 auto resMonomial = term->monomial()->sqrt();
25 if (resMonomial ==
nullptr) {
42 while (!rem.is_constant()) {
44 assert(rem.total_degree() <= 2);
45 Variable var = (*rem.lterm().monomial())[0].first;
47 CARL_LOG_TRACE(
"carl.core.sos_decomposition",
"Complete the square for " << var);
49 auto lcoeffIter = varInfos.coeffs().find(2);
50 if (lcoeffIter == varInfos.coeffs().end()) {
51 CARL_LOG_TRACE(
"carl.core.sos_decomposition",
"Cannot construct sos due to line " << __LINE__);
54 assert(lcoeffIter->second.is_constant());
56 CARL_LOG_TRACE(
"carl.core.sos_decomposition",
"Cannot construct sos due to line " << __LINE__);
60 auto constCoeffIter = varInfos.coeffs().find(0);
62 CARL_LOG_TRACE(
"carl.core.sos_decomposition",
"Constant part is " << rem);
63 auto coeffIter = varInfos.coeffs().find(1);
64 if (coeffIter != varInfos.coeffs().end()) {
67 rem -=
carl::pow(qr, 2)*lcoeffIter->second.constant_part();
71 CARL_LOG_TRACE(
"carl.core.sos_decomposition",
"Add " << result.back().first <<
" * (" << result.back().second <<
")^2");
74 CARL_LOG_TRACE(
"carl.core.sos_decomposition",
"Cannot construct sos due to line " << __LINE__);
79 CARL_LOG_TRACE(
"carl.core.sos_decomposition",
"Add " << result.back().first <<
" * (" << result.back().second <<
")^2");
Implements utility functions concerning the (total) degree of monomials, terms and polynomials.
#define CARL_LOG_TRACE(channel, msg)
carl is the main namespace for the library.
std::vector< std::pair< C, MultivariatePolynomial< C, O, P > > > sos_decomposition(const MultivariatePolynomial< C, O, P > &p, bool not_trivial=false)
bool is_constant(const ContextPolynomial< Coeff, Ordering, Policies > &p)
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_negative(const cln::cl_I &n)
Interval< Number > pow(const Interval< Number > &i, Integer exp)
A Variable represents an algebraic variable that can be used throughout carl.
The general-purpose multivariate polynomial class.
const Coeff & lcoeff() const
Returns the coefficient of the leading term.
std::size_t total_degree() const
Calculates the max.