13 #include <unordered_map>
24 template<
typename Polynomial,
typename Ordering>
28 using Coeff =
typename Polynomial::CoeffType;
32 using Terms = std::vector<TermPtr>;
39 using Tuple = std::tuple<TermIDs,Terms,bool,Coeff,IDType>;
40 using TAMId =
typename std::list<Tuple>::iterator;
47 #define TAM_LOCK_GUARD std::lock_guard<std::mutex> lock( mMutex );
48 #define TAM_LOCK mMutex.lock();
49 #define TAM_UNLOCK mMutex.unlock();
51 #define TAM_LOCK_GUARD
58 std::get<4>(*res) = 1;
64 assert(std::get<2>(data));
65 Terms& t = std::get<1>(data);
66 return Ordering::less(t[t1], t[t2]);
87 Terms& terms = std::get<1>(data);
89 terms.resize(expectedSize + 1);
94 if( std::get<0>(data).size() < greatestIdPlusOne ) std::get<0>(data).resize(greatestIdPlusOne);
97 std::get<4>(data) = 1;
98 std::get<2>(data) =
true;
105 template<
bool SizeUnknown,
bool NewMonomials = true>
109 assert(std::get<2>(data));
110 TermIDs& termIDs = std::get<0>(data);
111 Terms& terms = std::get<1>(data);
113 std::size_t monId = term.
monomial()->id();
114 if (NewMonomials && monId >= termIDs.size()) termIDs.resize(monId + 1);
115 IDType locId = termIDs[monId];
117 if (SizeUnknown && locId >= terms.size()) terms.resize(locId + 1);
118 assert(locId < terms.size());
126 t.
coeff() = std::move(coeff);
131 IDType& nextID = std::get<4>(data);
132 if (SizeUnknown && nextID >= terms.size()) terms.resize(nextID + 1);
133 assert(nextID < terms.size());
134 assert(nextID < std::numeric_limits<IDType>::max());
135 termIDs[monId] = nextID;
136 terms[nextID] = term;
140 std::get<3>(data) += term.
coeff();
146 Terms& terms = std::get<1>(data);
148 assert(terms.size() > 0);
149 for (std::size_t i = 1; i < terms.size(); i++) {
150 if (Ordering::less(terms[max], terms[i])) max = i;
154 else return terms[max];
159 assert(std::get<2>(data));
160 Terms& t = std::get<1>(data);
161 TermIDs& termIDs = std::get<0>(data);
163 if (!
is_zero(std::get<3>(data))) {
164 t[0] = std::move(
TermType(std::move(std::get<3>(data)),
nullptr));
166 for (
auto i = t.begin(); i != t.end();) {
169 if (i == --t.end()) {
177 if ((*i).monomial()) termIDs[(*i).monomial()->id()] = 0;
185 if (!
is_zero(std::get<3>(data))) {
186 terms.push_back( std::make_shared<const TermType>(std::move(std::get<3>(data)),
nullptr) );
190 for (; i != t.end(); ++i)
194 termIDs[(*i)->monomial()->id()] = 0;
195 terms.push_back( *i );
202 std::get<2>(data) =
false;
207 assert(std::get<2>(data));
208 Terms& t = std::get<1>(data);
209 TermIDs& termIDs = std::get<0>(data);
210 for (
auto i = t.begin(); i != t.end(); i++) {
211 if ((*i).monomial()) termIDs[(*i).monomial()->id()] = 0;
214 std::get<2>(data) =
false;
carl is the main namespace for the library.
void swap(Variable &lhs, Variable &rhs)
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.
std::size_t largestID() const
Coefficient & coeff()
Get the coefficient.
Monomial::Arg & monomial()
Get the monomial.
std::tuple< TermIDs, Terms, bool, Coeff, IDType > Tuple
TAMId getId(std::size_t expectedSize=0)
void addTerm(TAMId id, const TermPtr &term)
std::vector< IDType > TermIDs
bool compare(TAMId id, IDType t1, IDType t2) const
std::vector< TermPtr > Terms
TermType getMaxTerm(TAMId id) const
typename std::list< Tuple >::iterator TAMId
void readTerms(TAMId id, Terms &terms)
typename Polynomial::CoeffType Coeff
static MonomialPool & getInstance()
Returns the single instance of this class by reference.