TermTranslator.h
Go to the documentation of this file.
/* Frobby: Software for monomial ideal computations.
Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
*/
#ifndef TERM_TRANSLATOR_GUARD
#define TERM_TRANSLATOR_GUARD
#include "VarNames.h"
#include <vector>
#include <ostream>
class BigIdeal;
class Ideal;
class Term;
class TermTranslator {
public:
TermTranslator(size_t varCount, size_t upToExponent);
TermTranslator(const BigIdeal& bigIdeal, Ideal& ideal, bool sortVars = true);
TermTranslator(const vector<BigIdeal*>& bigIdeals, vector<Ideal*>& ideals);
TermTranslator(const TermTranslator& translator);
~TermTranslator();
TermTranslator& operator=(const TermTranslator& translator);
const mpz_class& getExponent(size_t variable, Exponent exponent) const;
const mpz_class& getExponent(size_t variable, const Term& term) const;
const char* getVarExponentString(size_t variable, Exponent exponent) const;
const char* getExponentString(size_t variable, Exponent exponent) const;
Exponent getMaxId(size_t variable) const;
void addPurePowersAtInfinity(Ideal& ideal) const;
void setInfinityPowersToZero(Ideal& ideal) const;
const VarNames& getNames() const;
size_t getVarCount() const;
void dualize(const vector<mpz_class>& a);
void decrement();
void renameVariables(const VarNames& names);
void swapVariables(size_t a, size_t b);
bool lessThanReverseLex(const Exponent* a, const Exponent* b) const;
void print(ostream& out) const;
string toString() const;
private:
void makeStrings(bool includeVar) const;
void clearStrings();
void initialize(const vector<BigIdeal*>& bigIdeals, bool sortVars);
void shrinkBigIdeal(const BigIdeal& bigIdeal, Ideal& ideal) const;
Exponent shrinkExponent(size_t var, const mpz_class& exponent) const;
vector<vector<mpz_class> > _exponents;
mutable vector<vector<const char*> > _stringExponents;
mutable vector<vector<const char*> > _stringVarExponents;
VarNames _names;
};
class TranslatedReverseLexComparator {
public:
TranslatedReverseLexComparator(const TermTranslator& translator):
_translator(translator) {
}
bool operator()(const Term& a, const Term& b) const;
bool operator()(const Exponent* a, const Exponent* b) const;
private:
const TermTranslator& _translator;
};
void setToZeroOne(TermTranslator& translator);
ostream& operator<<(ostream& out, const TermTranslator& translator);
#endif
setToZeroOne
void setToZeroOne(TermTranslator &translator)
Definition TermTranslator.cpp:481
operator<<
ostream & operator<<(ostream &out, const TermTranslator &translator)
Definition TermTranslator.cpp:492
VarNames.h
BigIdeal
Definition BigIdeal.h:27
Ideal
Represents a monomial ideal with int exponents.
Definition Ideal.h:27
TermTranslator
TermTranslator handles translation between terms whose exponents are infinite precision integers and ...
Definition TermTranslator.h:41
TermTranslator::swapVariables
void swapVariables(size_t a, size_t b)
Definition TermTranslator.cpp:310
TermTranslator::getExponent
const mpz_class & getExponent(size_t variable, Exponent exponent) const
This method translates from IDs to arbitrary precision integers.
Definition TermTranslator.cpp:392
TermTranslator::getVarCount
size_t getVarCount() const
Definition TermTranslator.cpp:447
TermTranslator::addPurePowersAtInfinity
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...
Definition TermTranslator.cpp:232
TermTranslator::renameVariables
void renameVariables(const VarNames &names)
Definition TermTranslator.cpp:303
TermTranslator::lessThanReverseLex
bool lessThanReverseLex(const Exponent *a, const Exponent *b) const
Definition TermTranslator.cpp:452
TermTranslator::_stringExponents
vector< vector< const char * > > _stringExponents
Definition TermTranslator.h:133
TermTranslator::TermTranslator
TermTranslator(size_t varCount, size_t upToExponent)
Constructs a translator of varCount variables that translates each number to itself,...
Definition TermTranslator.cpp:32
TermTranslator::makeStrings
void makeStrings(bool includeVar) const
Definition TermTranslator.cpp:346
TermTranslator::toString
string toString() const
Definition TermTranslator.cpp:340
TermTranslator::_stringVarExponents
vector< vector< const char * > > _stringVarExponents
Definition TermTranslator.h:134
TermTranslator::dualize
void dualize(const vector< mpz_class > &a)
Replaces var^v by var^(a[i] - v) except that var^0 is left alone.
Definition TermTranslator.cpp:288
TermTranslator::operator=
TermTranslator & operator=(const TermTranslator &translator)
Definition TermTranslator.cpp:380
TermTranslator::getExponentString
const char * getExponentString(size_t variable, Exponent exponent) const
as getExponent, except the string "e" is returned, where e is the exponent.
Definition TermTranslator.cpp:410
TermTranslator::clearStrings
void clearStrings()
Definition TermTranslator.cpp:143
TermTranslator::getMaxId
Exponent getMaxId(size_t variable) const
The assigned IDs are those in the range [0, getMaxId(var)].
Definition TermTranslator.cpp:424
TermTranslator::shrinkExponent
Exponent shrinkExponent(size_t var, const mpz_class &exponent) const
Definition TermTranslator.cpp:430
TermTranslator::shrinkBigIdeal
void shrinkBigIdeal(const BigIdeal &bigIdeal, Ideal &ideal) const
Definition TermTranslator.cpp:199
TermTranslator::_exponents
vector< vector< mpz_class > > _exponents
Definition TermTranslator.h:132
TermTranslator::initialize
void initialize(const vector< BigIdeal * > &bigIdeals, bool sortVars)
Definition TermTranslator.cpp:165
TermTranslator::~TermTranslator
~TermTranslator()
Definition TermTranslator.cpp:387
TermTranslator::setInfinityPowersToZero
void setInfinityPowersToZero(Ideal &ideal) const
The method addPurePowersAtInfinity adds high exponents that map to zero.
Definition TermTranslator.cpp:264
TermTranslator::getVarExponentString
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,...
Definition TermTranslator.cpp:400
TermTranslator::decrement
void decrement()
Replaces var^v by var^(v-1).
Definition TermTranslator.cpp:296
TermTranslator::print
void print(ostream &out) const
Definition TermTranslator.cpp:328
TermTranslator::_names
VarNames _names
Definition TermTranslator.h:135
TermTranslator::getNames
const VarNames & getNames() const
Definition TermTranslator.cpp:443
Term
Term represents a product of variables which does not include a coefficient.
Definition Term.h:49
TranslatedReverseLexComparator::TranslatedReverseLexComparator
TranslatedReverseLexComparator(const TermTranslator &translator)
Definition TermTranslator.h:143
TranslatedReverseLexComparator::operator()
bool operator()(const Term &a, const Term &b) const
Definition TermTranslator.cpp:466
TranslatedReverseLexComparator::_translator
const TermTranslator & _translator
Definition TermTranslator.h:151
VarNames
Defines the variables of a polynomial ring and facilities IO involving them.
Definition VarNames.h:40
Exponent
unsigned int Exponent
Definition stdinc.h:89