37 const char* formatDescription):
38 _formatName(formatName),
39 _formatDescription(formatDescription) {
51 return std::find(_supportedInputs.begin(), _supportedInputs.end(),
52 &type) != _supportedInputs.end();
56 return std::find(_supportedOutputs.begin(), _supportedOutputs.end(),
57 &type) != _supportedOutputs.end();
62 ASSERT(!supportsInput(type));
64 _supportedInputs.push_back(&type);
69 ASSERT(!supportsOutput(type));
71 _supportedOutputs.push_back(&type);
105 return _formatDescription;
110 vector<mpz_class>& term) {
112 for (
size_t var = 0; var < term.size(); ++var)
120 }
while (in.
match(
'*'));
128 if (coef >= 0 && !hidePlus)
132 gmp_fprintf(out,
"%Zd", coef.get_mpz_t());
139 gmp_fprintf(out,
"%Zd*", coef.get_mpz_t());
145 const vector<mpz_class>& term,
149 if (coef >= 0 && !hidePlus)
153 for (
size_t var = 0; var < term.size(); ++var)
158 gmp_fprintf(out,
"%Zd", coef.get_mpz_t());
165 gmp_fprintf(out,
"%Zd*", coef.get_mpz_t());
173 bool seenNonZero =
false;
175 for (
size_t var = 0; var < varCount; ++var) {
195 bool seenNonZero =
false;
196 size_t varCount = term.size();
197 for (
size_t var = 0; var < varCount; ++var) {
206 fputs(names.
getName(var).c_str(), out);
207 if ((term[var]) != 1) {
209 mpz_out_str(out, 10, term[var].get_mpz_t());
225 }
while (in.
match(
'*'));
229 vector<mpz_class>& term,
234 for (
size_t var = 0; var < term.size(); ++var)
237 bool positive =
true;
238 if (!firstTerm && in.
match(
'+'))
239 positive = !in.
match(
'-');
240 else if (in.
match(
'-'))
242 else if (!firstTerm) {
255 while (in.
match(
'*'))
267 vector<mpz_class>& term = polynomial.
getLastTerm();
277 if (term[var] != 0) {
278 const string& name = names.
getName(var);
280 name +
" appears more than once in monomial.");
285 if (term[var] <= 0) {
287 errorMsg <<
"Expected positive integer as exponent but got "
const VarNames & getNames() const
vector< mpz_class > & getLastTermRef()
mpz_class & getLastCoef()
vector< mpz_class > & getLastTerm()
const VarNames & getNames() const
The intention of this class is to describe the different kinds of mathematical structures that Frobby...
bool isNull() const
Returns true if this object was returned by getNullType().
A replacement for stringstream.
void registerInput(const DataType &type)
Specify that input of the argument type is supported.
virtual void doReadTerm(Scanner &in, InputConsumer &term)
virtual void doReadSatBinomIdeal(Scanner &in, SatBinomConsumer &consumer)
virtual BigTermConsumer * doCreateIdealWriter(FILE *out)=0
virtual bool doSupportsInput(const DataType &type) const
virtual void doReadIdeal(Scanner &in, InputConsumer &consumer)
virtual const char * doGetDescription() const
virtual const char * doGetName() const
virtual bool doSupportsOutput(const DataType &type) const
IOHandlerImpl(const char *formatName, const char *formatDescription)
virtual bool doHasMoreInput(Scanner &in) const
virtual CoefBigTermConsumer * doCreatePolynomialWriter(FILE *out)
virtual void doReadPolynomial(Scanner &in, CoefBigTermConsumer &consumer)
virtual void doReadIdeals(Scanner &in, InputConsumer &consumer)
void registerOutput(const DataType &type)
Specify that output of the argument type is supported.
This class offers an input interface which is more convenient and for some purposes more efficient th...
void expect(char expected)
Require the next character to be equal to expected.
bool peekIdentifier()
Skips whitespace and returns true if the next token is an identifier.
size_t readVariable(const VarNames &names)
Reads an identifier and returns the index of that identifier as the index of a variable in names.
bool matchEOF()
Return true if no more input.
void readInteger(mpz_class &integer)
Read an arbitrary-precision integer.
bool match(char c)
Return true if the next character is c, and in that case skip past it.
TermTranslator handles translation between terms whose exponents are infinite precision integers and ...
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,...
Term represents a product of variables which does not include a coefficient.
size_t getVarCount() const
static bool isIdentity(const Exponent *a, size_t varCount)
Returns whether a is 1, i.e. whether all entries of a are 0.
Defines the variables of a polynomial ring and facilities IO involving them.
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 reportSyntaxError(const Scanner &scanner, const string &errorMsg)
#define INTERNAL_ERROR_UNIMPLEMENTED()
void writeCoefTermProduct(const mpz_class &coef, const Term &term, const TermTranslator &translator, bool hidePlus, FILE *out)
void readVarPower(vector< mpz_class > &term, const VarNames &names, Scanner &in)
void readCoefTerm(BigPolynomial &polynomial, bool firstTerm, Scanner &in)
void readTermProduct(Scanner &in, const VarNames &names, vector< mpz_class > &term)
void writeTermProduct(const Term &term, const TermTranslator &translator, FILE *out)
bool isIdentity(const Word *a, Word *aEnd)