25 std::vector<std::pair<Variable, exponent>> exps(this->
mExponents);
33 newExps.insert(newExps.end(), it,
mExponents.end());
48 newExps.insert(newExps.end(), it+1,
mExponents.end());
63 CARL_LOG_TRACE(
"carl.core.monomial", *
this <<
" / " << v <<
" = " << res);
72 CARL_LOG_TRACE(
"carl.core.monomial", *
this <<
" / " << m <<
" = " << res);
78 CARL_LOG_TRACE(
"carl.core.monomial", *
this <<
" / " << m <<
" fails");
84 auto itright = m->mExponents.begin();
88 if(itright == m->mExponents.end())
91 newExps.insert(newExps.end(), itleft,
mExponents.end());
93 CARL_LOG_TRACE(
"carl.core.monomial", *
this <<
" / " << m <<
" = " << res);
97 if(itleft->first == itright->first)
99 if (itleft->second < itright->second)
102 CARL_LOG_TRACE(
"carl.core.monomial", *
this <<
" / " << m <<
" fails");
105 std::size_t newExp = itleft->second - itright->second;
108 newExps.emplace_back(itleft->first, newExp);
113 else if(itleft->first > itright->first)
115 CARL_LOG_TRACE(
"carl.core.monomial", *
this <<
" / " << m <<
" fails");
120 assert(itleft->first < itright->first);
121 newExps.emplace_back(*itleft);
125 if(itright != m->mExponents.end())
127 CARL_LOG_TRACE(
"carl.core.monomial", *
this <<
" / " << m <<
" fails");
132 CARL_LOG_TRACE(
"carl.core.monomial", *
this <<
" / " << m <<
" fails");
137 CARL_LOG_TRACE(
"carl.core.monomial", *
this <<
" / " << m <<
" = " << res);
145 if (it.second % 2 == 1)
return nullptr;
146 newExps.emplace_back(it.first, it.second / 2);
153 if (!lhs && !rhs)
return nullptr;
154 if (!lhs)
return rhs;
155 if (!rhs)
return lhs;
157 assert(lhs->is_consistent());
158 assert(rhs->is_consistent());
161 std::size_t expsum = lhs->tdeg() + rhs->tdeg();
163 auto itright = rhs->mExponents.cbegin();
164 auto leftEnd = lhs->mExponents.cend();
165 auto rightEnd = rhs->mExponents.cend();
166 for(
auto itleft = lhs->mExponents.cbegin(); itleft != leftEnd;)
169 if(itright == rightEnd)
172 newExps.insert(newExps.end(), itleft, lhs->mExponents.end());
178 if(itleft->first == itright->first)
180 std::size_t newExp = std::max(itleft->second, itright->second);
181 newExps.emplace_back(itleft->first, newExp);
182 expsum -= std::min(itleft->second, itright->second);
188 else if(itleft->first > itright->first)
190 newExps.push_back(*itright);
195 assert(itleft->first < itright->first);
196 newExps.push_back(*itleft);
201 newExps.insert(newExps.end(), itright, rhs->mExponents.end());
211 std::size_t tdegree = 0;
214 if (ve.second <= 0) {
218 tdegree += ve.second;
224 if (!std::is_sorted(
mExponents.begin(),
mExponents.end(), [](
const std::pair<Variable, exponent>& p1,
const std::pair<Variable, exponent>& p2){ return p1.first < p2.first; })) {
233 assert( (&lhs != &rhs) || (lhs.
id() == rhs.
id()) );
234 assert((lhs.
id() != 0) && (rhs.
id() != 0));
240 while (lhsit != lhsend) {
244 if (lhsit->first == rhsit->first) {
246 if (lhsit->second > rhsit->second)
248 if (lhsit->second < rhsit->second)
256 assert(rhsit != rhsend);
266 assert( rhs->tdeg() > 0 );
267 assert( lhs->tdeg() > 0 );
268 assert(lhs->is_consistent());
269 assert(rhs->is_consistent());
271 newExps.reserve(lhs->exponents().size() + rhs->exponents().size());
274 auto itleft = lhs->begin();
275 auto itright = rhs->begin();
276 while( itleft != lhs->end() && itright != rhs->end() )
279 if(itleft->first == itright->first)
281 newExps.emplace_back( itleft->first, itleft->second + itright->second);
286 else if(itleft->first > itright->first)
288 newExps.emplace_back( itright->first, itright->second );
294 newExps.emplace_back( itleft->first, itleft->second );
299 if( itleft != lhs->end() )
300 newExps.insert(newExps.end(), itleft, lhs->end());
301 else if( itright != rhs->end() )
302 newExps.insert(newExps.end(), itright, rhs->end());
304 CARL_LOG_TRACE(
"carl.core.monomial", lhs <<
" * " << rhs <<
" = " << result);
305 if (result) assert(lhs->tdeg() + rhs->tdeg() == result->tdeg());
316 bool inserted =
false;
317 for (
const auto& p: *lhs) {
318 if (inserted) newExps.push_back(p);
319 else if (p.first < rhs) newExps.push_back(p);
320 else if (p.first == rhs) {
321 newExps.emplace_back(rhs, p.second + 1);
323 }
else if (p.first > rhs) {
324 newExps.emplace_back(rhs, 1);
325 newExps.push_back(p);
329 if (!inserted) newExps.emplace_back(rhs, 1);
332 CARL_LOG_TRACE(
"carl.core.monomial", lhs <<
" * " << rhs <<
" = " << result);
334 assert(lhs->tdeg() + 1 == result->tdeg());
A small wrapper that configures logging for carl.
#define CARL_LOG_FUNC(channel, args)
#define CARL_LOG_TRACE(channel, msg)
carl is the main namespace for the library.
Monomial::Arg createMonomial(T &&... t)
void swap(Variable &lhs, Variable &rhs)
std::size_t exponent
Type of an exponent.
Interval< Number > exp(const Interval< Number > &i)
Interval< Number > operator*(const Interval< Number > &lhs, const Interval< Number > &rhs)
Operator for the multiplication of two intervals.
Interval< Number > pow(const Interval< Number > &i, Integer exp)
A Variable represents an algebraic variable that can be used throughout carl.
The general-purpose monomials.
std::size_t mTotalDegree
Some applications performance depends on getting the degree of monomials very fast.
std::shared_ptr< const Monomial > Arg
static Monomial::Arg lcm(const Monomial::Arg &lhs, const Monomial::Arg &rhs)
Calculates the least common multiple of two monomial pointers.
bool is_consistent() const
Checks if the monomial is consistent.
Content mExponents
A vector of variable exponent pairs (v_i^e_i) with nonzero exponents.
std::vector< std::pair< Variable, std::size_t > > Content
std::size_t id() const
Return the id of this monomial.
static CompareResult lexicalCompare(const Monomial &lhs, const Monomial &rhs)
This method performs a lexical comparison as defined in , page 47.
std::size_t mHash
Cached hash.
bool divide(Variable v, Monomial::Arg &res) const
Divides the monomial by a variable v.
Monomial::Arg sqrt() const
Calculates and returns the square root of this monomial, iff the monomial is a square as checked by i...
Monomial::Arg drop_variable(Variable v) const
For a monomial m = Prod( x_i^{e_i} ) * v^e, divides m by v^e.
Monomial::Arg create(Variable _var, exponent _exp)
Creates a monomial from a variable and an exponent.
void free(const Monomial *m)
static MonomialPool & getInstance()
Returns the single instance of this class by reference.