33 _allocator(varCount) {
37 _varCount(term.getVarCount()),
38 _allocator(term.getVarCount()) {
43 _varCount(ideal.getVarCount()),
44 _allocator(ideal.getVarCount()) {
107 for (
size_t var = 0; var <
_varCount; ++var) {
113 if (lastExponent != 0 && lastExponent == (*it)[var])
115 lastExponent = (*it)[var];
133 goto foundStrictDivisor;
146 if ((*it)[var] > 0) {
173 for (++it; it != stop; ++it)
182 for (; it != stop; ++it) {
202 for (; it != stop; ++it) {
222 for (
size_t var = 0; var <
_varCount; ++var)
223 if (least[var] == 0 || ((*it)[var] < least[var] && (*it)[var] > 0))
224 least[var] = (*it)[var];
231 for (
size_t var = 0; var <
_varCount; ++var)
242 for (
size_t var = 0; var <
_varCount; ++var) {
253 if (lastExponent == exponent)
258 if (count > maxCount) {
261 typicalExponent = exponent;
264 lastExponent = exponent;
272 (
size_t& mostNGVar,
Exponent& mostNGExponent) {
279 for (
size_t var = 0; var <
_varCount; ++var) {
284 while (blockBegin != stop) {
285 Exponent blockExponent = (*blockBegin)[var];
289 }
while (blockEnd != stop && (*blockEnd)[var] == blockExponent);
296 size_t span = blockEnd - blockBegin;
297 if (blockExponent == 0 || (span * (span + 1)) / 2 <= maxCount) {
298 blockBegin = blockEnd;
302 size_t nonGenericCount = 0;
303 for (; blockBegin != blockEnd; ++blockBegin) {
305 for (++it; it != blockEnd; ++it) {
306 lcm.lcm(*blockBegin, *it);
314 if (nonGenericCount > maxCount) {
315 maxCount = nonGenericCount;
317 mostNGExponent = blockExponent;
326 (
size_t& typicalVar,
Exponent& typicalExponent) {
333 for (
size_t var = 0; var <
_varCount; ++var) {
338 while (blockBegin != stop) {
339 Exponent blockExponent = (*blockBegin)[var];
343 }
while (blockEnd != stop && (*blockEnd)[var] == blockExponent);
350 size_t count = blockEnd - blockBegin;
351 if (blockExponent == 0 || count <= maxCount) {
352 blockBegin = blockEnd;
356 for (; blockBegin != blockEnd; ++blockBegin) {
358 for (++it; it != blockEnd; ++it) {
359 lcm.lcm(*blockBegin, *it);
365 typicalExponent = blockExponent;
366 blockBegin = blockEnd;
379 (
size_t& ngVar,
Exponent& ngExponent) {
385 for (
size_t var = 0; var <
_varCount; ++var) {
390 while (blockBegin != stop) {
391 Exponent blockExponent = (*blockBegin)[var];
395 }
while (blockEnd != stop && (*blockEnd)[var] == blockExponent);
401 if (blockExponent == 0) {
402 blockBegin = blockEnd;
406 for (; blockBegin != blockEnd; ++blockBegin) {
408 for (++it; it != blockEnd; ++it) {
409 lcm.lcm(*blockBegin, *it);
413 ngExponent = blockExponent;
433 for (; it != stop; ++it, ++it2)
443 fputs(out.str().c_str(), file);
447 out <<
"//------------ Ideal:\n";
452 out <<
"------------\\\\\n";
458 copy(exponents, exponents +
_varCount, term);
554 pair<iterator, bool> pair =
567 pair<iterator, bool> pair =
593 _terms.erase(newEnd, stop);
600 if ((*it)[var] < e) {
605 _terms.erase(newEnd, stop);
631 _terms.erase(newEnd, stop);
655 for (
size_t var = 0; var <
_varCount; ++var)
656 if ((*it)[var] == zeroExponents[var])
663 for (
size_t var = 0; var <
_varCount; ++var)
719 }
catch (
const bad_alloc&) {
725 for (
size_t i = 0; i <
_chunks.size(); ++i)
751 if (_chunkIterator +
_varCount > _chunkEnd) {
752 if (useSingleChunking()) {
755 _chunks.push_back(term);
767 _chunks.push_back(_chunkIterator);
776 ASSERT(_chunkIterator <= _chunkEnd);
784 if (useSingleChunking()) {
785 for (
size_t i = 0; i < _chunks.size(); ++i)
792 for (
size_t i = 0; i < _chunks.size(); ++i)
803 _chunks.swap(allocator.
_chunks);
const int ExponentsPerChunk
class ChunkPool globalChunkPool
const int MinTermsPerChunk
void deallocate(Exponent *chunk)
vector< Exponent * > _chunks
A predicate that compares for equality.
Exponent * _chunkIterator
void reset(size_t newVarCount)
void swap(ExponentAllocator &allocator)
vector< Exponent * > _chunks
bool useSingleChunking() const
ExponentAllocator(size_t varCount)
Represents a monomial ideal with int exponents.
void getGcdOfMultiplesOf(Exponent *gcd, const Exponent *divisor)
Sets gcd to the greatest common divisor of those generators that are divisible by divisor.
void removeStrictMultiples(const Exponent *term)
void singleDegreeSort(size_t var)
bool isSquareFree() const
void product(const Exponent *term)
void remove(const_iterator it)
void getGcd(Exponent *gcd) const
Sets gcd to the greatest common divisor of all generators.
void insertNonMultiples(const Exponent *term, const Ideal &ideal)
size_t getGeneratorCount() const
ExponentAllocator _allocator
size_t getMostNonGenericExponent(size_t &var, Exponent &exp)
Sets var and exp such that var^exp is the most non-generic degree.
const_iterator getMultiple(size_t var) const
bool containsIdentity() const
void colon(const Exponent *by)
void clearAndSetVarCount(size_t varCount)
void getLcm(Exponent *lcm) const
Sets lcm to the least common multiple of all generators.
void takeRadicalNoMinimize()
Replaces all generators with their support and does not remove any non-minimal generators this may pr...
bool getNonGenericExponent(size_t &var, Exponent &exp)
Sets var and exp such that var^exp is some non-generic degree.
bool isIncomparable(const Exponent *term) const
Cont::const_iterator const_iterator
static void clearStaticCache()
Ideal caches memory allocated with new internally and reuses it to avoid calling new all the time.
vector< Exponent * > _terms
void mapExponentsToZeroNoMinimize(const Term &zeroExponents)
Replaces the exponents from zeroExponents with zero and does not remove any non-minimal generators th...
bool contains(const Exponent *term) const
size_t getTypicalExponent(size_t &var, Exponent &exp)
Sets var and exp such that var^exp is the typical non-zero exponent.
void insert(const Exponent *term)
bool strictlyContains(const Exponent *term) const
void insertReminimize(const Exponent *term)
void getLeastExponents(Exponent *least) const
bool disjointSupport() const
Returns true if all pairs of generators have disjoint support.
const_iterator end() const
Ideal & operator=(const Ideal &ideal)
void print(FILE *file) const
const_iterator begin() const
void getSupportCounts(Exponent *counts) const
counts[var] will be the number of generators divisible by var.
Ideal(size_t varCount=0)
Initialize this object to the zero ideal in varCount variables.
bool isIrreducible() const
void removeMultiples(const Exponent *term)
bool isWeaklyGeneric() const
size_t getTypicalNonGenericExponent(size_t &var, Exponent &exp)
Sets var and exp such that var^exp is the typical non-generic degree.
bool colonReminimize(const Exponent *colon)
bool isMinimallyGenerated() const
void getGcdAtExponent(Exponent *gcd, size_t var, Exponent exp)
Sets gcd to the greatest common divisor of those generators that raise the variable var to the power ...
bool operator==(const Ideal &ideal) const
Rereturns true if *this equals ideal.
size_t getVarCount() const
A predicate that sorts terms according to lexicographic order.
bool isMinimallyGenerated(const_iterator begin, const_iterator end)
pair< iterator, bool > colonReminimize(iterator begin, iterator end, const Exponent *colon)
iterator minimize(iterator begin, iterator end) const
A predicate that sorts according to reverse lexicographic order.
A predicate that sorts terms in weakly ascending order according to degree of the specified variable.
Term represents a product of variables which does not include a coefficient.
static void product(Exponent *res, const Exponent *a, const Exponent *b, size_t varCount)
Sets res equal to the product of a and b.
static bool dominates(const Exponent *a, const Exponent *b, size_t varCount)
Returns whether a dominates b, i.e. whether b divides a.
static bool strictlyDivides(const Exponent *a, const Exponent *b, size_t varCount)
Returns whether a strictly divides b.
bool isSquareFree() const
static void print(FILE *file, const Exponent *e, size_t varCount)
Writes e to file in a format suitable for debug output.
static void colon(Exponent *res, const Exponent *a, const Exponent *b, size_t varCount)
Sets res equal to .
static void gcd(Exponent *res, const Exponent *a, const Exponent *b, size_t varCount)
Sets res equal to the greatest common divisor of a and b.
size_t getSizeOfSupport() const
static bool divides(const Exponent *a, const Exponent *b, size_t varCount)
Returns whether a divides b.
static bool sharesNonZeroExponent(const Exponent *a, const Exponent *b, size_t varCount)
Returns whether there is some such that .
static void lcm(Exponent *res, const Exponent *a, const Exponent *b, size_t varCount)
Sets res equal to the least commom multiple of a and b.
void lcm(Word *res, const Word *resEnd, const Word *a, const Word *b)
bool equals(const Word *a, const Word *b, size_t varCount)
Returns true if a equals b.
void gcd(Word *res, const Word *resEnd, const Word *a, const Word *b)
void swap(hashtable< _Val, _Key, _HF, _Extract, _EqKey, _All > &__ht1, hashtable< _Val, _Key, _HF, _Extract, _EqKey, _All > &__ht2)