37 const char* formatDescription):
38 _formatName(formatName),
39 _formatDescription(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 "
virtual void doReadIdeals(Scanner &in, InputConsumer &consumer)
void readCoefTerm(BigPolynomial &polynomial, bool firstTerm, Scanner &in)
vector< mpz_class > & getLastTerm()
virtual BigTermConsumer * doCreateIdealWriter(FILE *out)=0
static bool isIdentity(const Exponent *a, size_t varCount)
Returns whether a is 1, i.e. whether all entries of a are 0.
size_t getVarCount() const
void readVarPower(vector< mpz_class > &term, const VarNames &names, Scanner &in)
virtual bool doSupportsOutput(const DataType &type) const
virtual CoefBigTermConsumer * doCreatePolynomialWriter(FILE *out)
IOHandlerImpl(const char *formatName, const char *formatDescription)
void registerOutput(const DataType &type)
Specify that output of the argument type is supported.
void readTermProduct(Scanner &in, const VarNames &names, vector< mpz_class > &term)
Defines the variables of a polynomial ring and facilities IO involving them.
The intention of this class is to describe the different kinds of mathematical structures that Frobby...
const char * _formatDescription
vector< const DataType * > _supportedOutputs
void readInteger(mpz_class &integer)
Read an arbitrary-precision integer.
vector< const DataType * > _supportedInputs
bool supportsOutput(const DataType &type) const
This class offers an input interface which is more convenient and for some purposes more efficient th...
void writeCoefTermProduct(const mpz_class &coef, const Term &term, const TermTranslator &translator, bool hidePlus, FILE *out)
bool peekIdentifier()
Skips whitespace and returns true if the next token is an identifier.
void registerInput(const DataType &type)
Specify that input of the argument type is supported.
virtual void doReadPolynomial(Scanner &in, CoefBigTermConsumer &consumer)
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 isNull() const
Returns true if this object was returned by getNullType().
bool isIdentity(const Word *a, Word *aEnd)
virtual bool doHasMoreInput(Scanner &in) const
virtual void doReadIdeal(Scanner &in, InputConsumer &consumer)
virtual const char * doGetName() const
TermTranslator handles translation between terms whose exponents are infinite precision integers and ...
void expect(char expected)
Require the next character to be equal to expected.
bool supportsInput(const DataType &type) const
#define INTERNAL_ERROR_UNIMPLEMENTED()
void reportSyntaxError(const Scanner &scanner, const string &errorMsg)
bool matchEOF()
Return true if no more input.
void writeTermProduct(const Term &term, const TermTranslator &translator, FILE *out)
size_t getVarCount() const
Returns the current number of variables.
const VarNames & getNames() const
vector< mpz_class > & getLastTermRef()
const string & getName(size_t index) const
The returned reference can become invalid next time addVar is called.
A replacement for stringstream.
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, where var is the variable and e is the exponent.
virtual void doReadSatBinomIdeal(Scanner &in, SatBinomConsumer &consumer)
virtual const char * doGetDescription() const
Term represents a product of variables which does not include a coefficient.
const VarNames & getNames() const
virtual void doReadTerm(Scanner &in, InputConsumer &term)
virtual bool doSupportsInput(const DataType &type) const
bool match(char c)
Return true if the next character is c, and in that case skip past it.
mpz_class & getLastCoef()