37 for (
size_t i = 0; i < upToExponent; ++i)
40 for (
size_t var = 1; var < varCount; ++var)
47 vector<BigIdeal*> bigIdeals;
48 bigIdeals.push_back(
const_cast<BigIdeal*
>(&bigIdeal));
55 vector<Ideal*>& ideals) {
56 ASSERT(!bigIdeals.empty());
63 for (
size_t i = 0; i < bigIdeals.size(); ++i) {
91 vector<mpz_class>& exponents,
92 const string& varName) {
93 vector<mpz_class*> exponentRefs;
96 exponentRefs.push_back(&zero);
100 for (
size_t i = 0; i < ideals.size(); ++i)
101 termCount += ideals[i]->getGeneratorCount();
102 exponentRefs.reserve(termCount + 1);
105 const int MaxSmall = 900;
106 bool seen[MaxSmall + 1];
107 fill_n(seen, MaxSmall + 1,
false);
109 for (
size_t i = 0; i < ideals.size(); ++i) {
116 for (
size_t term = 0; term < generatorCount; ++term) {
120 unsigned int ui = e.get_ui();
125 exponentRefs.push_back(&(ideal.
getExponent(term, var)));
134 exponentRefs.push_back(&zero);
137 exponents.resize(exponentRefs.size());
138 size_t size = exponentRefs.size();
139 for (
size_t e = 0; e < size; ++e)
140 exponents[e] = *(exponentRefs[e]);
156 (
const string* a,
const string* b) {
161 (
const string* a,
const string* b) {
167 ASSERT(!bigIdeals.empty());
170 vector<const string*> variables;
171 for (
size_t ideal = 0; ideal < bigIdeals.size(); ++ideal) {
172 const VarNames& names = bigIdeals[ideal]->getNames();
173 if (ideal != 0 && names == bigIdeals[ideal - 1]->
getNames())
175 for (
size_t var = 0; var < bigIdeals[ideal]->getVarCount(); ++var)
176 variables.push_back(&(names.
getName(var)));
178 std::sort(variables.begin(), variables.end(),
181 (std::unique(variables.begin(), variables.end(),
185 for (vector<const string*>::const_iterator var = variables.begin();
186 var != variables.end(); ++var)
189 ASSERT(bigIdeals.size() == 1);
190 _names = bigIdeals[0]->getNames();
200 Ideal& ideal)
const {
204 vector<size_t> newVars;
208 for (
size_t var = 0; var < bigIdeal.
getVarCount(); ++var)
209 newVars.push_back(var);
211 for (
size_t var = 0; var < bigIdeal.
getVarCount(); ++var) {
214 newVars.push_back(newVar);
224 for (
size_t var = 0; var < varCount; ++var) {
225 size_t newVar = newVars[var];
236 vector<bool> hasPurePower(varCount);
247 hasPurePower[var] =
true;
251 for (
size_t var = 0; var < varCount; ++var) {
252 if (hasPurePower[var])
255 Term purePower(varCount);
267 while (term != ideal.
end()) {
268 bool changed =
false;
269 for (
size_t var = 0; var < varCount; ++var) {
270 if ((*term)[var] ==
getMaxId(var)) {
279 bool last = (term + 1 == ideal.
end());
290 for (
size_t var = 0; var <
_exponents.size(); ++var)
291 for (
size_t exp = 0; exp <
_exponents[var].size(); ++exp)
298 for (
size_t var = 0; var <
_exponents.size(); ++var)
299 for (
size_t exp = 0; exp <
_exponents[var].size(); ++exp)
329 out <<
"TermTranslator(\n";
330 for (
size_t var = 0; var <
_exponents.size(); ++var) {
331 out <<
" var " << var + 1 <<
':';
332 for (
size_t e = 0; e <
_exponents[var].size(); ++e) {
347 vector<vector<const char*> >& strings =
353 for (
unsigned int i = 0; i <
_exponents.size(); ++i) {
355 for (
unsigned int j = 0; j <
_exponents[i].size(); ++j) {
368 str =
new char[out.
str().size() + 1];
369 strcpy(str, out.
str().c_str());
431 const mpz_class& exponent)
const {
432 const vector<mpz_class>& exponents =
_exponents[var];
436 vector<mpz_class>::const_iterator it =
437 lower_bound(exponents.begin(), exponents.end() - 1, exponent);
440 return it - exponents.begin();
455 for (
size_t var = 0; var < varCount; ++var) {
467 const Term& b)
const {
485 for (
size_t var = 0; var < translator.
getVarCount(); ++var)
493 translator.
print(out);
void exceptionSafePushBack(Container &container, auto_ptr< Element > pointer)
void setToZeroOne(TermTranslator &translator)
bool mpzClassPointerLess(const mpz_class *a, const mpz_class *b)
bool mpzClassPointerEqual(const mpz_class *a, const mpz_class *b)
void extractExponents(const vector< BigIdeal * > &ideals, vector< mpz_class > &exponents, const string &varName)
ostream & operator<<(ostream &out, const TermTranslator &translator)
bool TermTranslatorInitializeHelper_StringPointerCompareLess(const string *a, const string *b)
bool TermTranslatorInitializeHelper_StringPointerCompareEqual(const string *a, const string *b)
mpz_class & getLastTermExponentRef(size_t var)
size_t getVarCount() const
const VarNames & getNames() const
size_t getGeneratorCount() const
const mpz_class & getExponent(size_t term, size_t var) const
A replacement for stringstream.
Represents a monomial ideal with int exponents.
void remove(const_iterator it)
void clearAndSetVarCount(size_t varCount)
Cont::const_iterator const_iterator
void insert(const Exponent *term)
const_iterator end() const
const_iterator begin() const
size_t getVarCount() const
TermTranslator handles translation between terms whose exponents are infinite precision integers and ...
void swapVariables(size_t a, size_t b)
const mpz_class & getExponent(size_t variable, Exponent exponent) const
This method translates from IDs to arbitrary precision integers.
size_t getVarCount() const
void addPurePowersAtInfinity(Ideal &ideal) const
Adds a generator of the form v^e, e > 0, for any variable v where generator of that form is not alrea...
void renameVariables(const VarNames &names)
bool lessThanReverseLex(const Exponent *a, const Exponent *b) const
vector< vector< const char * > > _stringExponents
TermTranslator(size_t varCount, size_t upToExponent)
Constructs a translator of varCount variables that translates each number to itself,...
void makeStrings(bool includeVar) const
vector< vector< const char * > > _stringVarExponents
void dualize(const vector< mpz_class > &a)
Replaces var^v by var^(a[i] - v) except that var^0 is left alone.
TermTranslator & operator=(const TermTranslator &translator)
const char * getExponentString(size_t variable, Exponent exponent) const
as getExponent, except the string "e" is returned, where e is the exponent.
Exponent getMaxId(size_t variable) const
The assigned IDs are those in the range [0, getMaxId(var)].
Exponent shrinkExponent(size_t var, const mpz_class &exponent) const
void shrinkBigIdeal(const BigIdeal &bigIdeal, Ideal &ideal) const
vector< vector< mpz_class > > _exponents
void initialize(const vector< BigIdeal * > &bigIdeals, bool sortVars)
void setInfinityPowersToZero(Ideal &ideal) const
The method addPurePowersAtInfinity adds high exponents that map to zero.
const char * getVarExponentString(size_t variable, Exponent exponent) const
As getExponent, except the string "var^e" is returned or null if the exponent is zero,...
void decrement()
Replaces var^v by var^(v-1).
void print(ostream &out) const
const VarNames & getNames() const
Term represents a product of variables which does not include a coefficient.
size_t getVarCount() const
size_t getFirstNonZeroExponent() const
size_t getSizeOfSupport() const
bool operator()(const Term &a, const Term &b) const
const TermTranslator & _translator
Defines the variables of a polynomial ring and facilities IO involving them.
bool addVar(const string &name)
Adds the variable and returns true if name is not already a variable.
size_t getVarCount() const
Returns the current number of variables.
const string & getName(size_t index) const
The returned reference can become invalid next time addVar is called.
void swapVariables(size_t a, size_t b)
Swaps the variables with indexes a and b.
static const size_t invalidIndex
Returns a fixed variable offset that is always invalid.
size_t getIndex(const string &name) const
Returns VarNames::invalidIndex() if name is not known.
void swap(hashtable< _Val, _Key, _HF, _Extract, _EqKey, _All > &__ht1, hashtable< _Val, _Key, _HF, _Extract, _EqKey, _All > &__ht2)