47 vector<mpz_class>& term,
61 fputs(
"I := Ideal(", getFile());
67 fputs(first ?
"\n " :
",\n ", getFile());
73 fputs(first ?
"\n " :
",\n ", getFile());
78 fputs(
"\n);\n", getFile());
93 fputs(
"p :=", getFile());
99 bool firstGenerator) {
100 fputs(
"\n ", getFile());
102 if (coef >= 0 && !firstGenerator)
103 fputc(
'+', getFile());
106 gmp_fprintf(getFile(),
"%Zd", coef.get_mpz_t());
111 fputc(
'-', getFile());
113 gmp_fprintf(getFile(),
"%Zd", coef.get_mpz_t());
119 const vector<mpz_class>& term,
120 bool firstGenerator) {
121 fputs(
"\n ", getFile());
122 if (coef >= 0 && !firstGenerator)
123 fputc(
'+', getFile());
126 for (
size_t var = 0; var < term.size(); ++var)
131 gmp_fprintf(getFile(),
"%Zd", coef.get_mpz_t());
136 fputc(
'-', getFile());
138 gmp_fprintf(getFile(),
"%Zd", coef.get_mpz_t());
145 fputs(
"\n 0", getFile());
146 fputs(
";\n", getFile());
152 "Format understandable by the program CoCoA 4.") {
206 for (
size_t var = 0; var < varCount; ++var) {
217 if (var < varCount - 1)
226 return in.
peek(
'U') || in.
peek(
'u');
238 if (!in.
match(
')')) {
241 }
while (in.
match(
','));
265 }
while (!in.
match(
';'));
271 fputs(
"Use R ::= Q[x];\nNames := [];\n", out);
275 fprintf(out,
"Use R ::= Q[x[1..%lu]];\n",
278 fputs(
"Names := [", out);
280 const char* pre =
"\"";
283 fputs(names.
getName(i).c_str(), out);
286 fputs(
"\"];\n", out);
292 bool seenNonZero =
false;
294 for (
size_t var = 0; var < varCount; ++var) {
300 fprintf(out,
"x[%lu]", (
unsigned long)(var + 1));
301 if (exp[0] !=
'1' || exp[1] !=
'\0') {
314 bool seenNonZero =
false;
315 size_t varCount = term.size();
316 for (
size_t var = 0; var < varCount; ++var) {
321 fprintf(out,
"x[%lu]", (
unsigned long)(var + 1));
322 if (term[var] != 1) {
324 mpz_out_str(out, 10, term[var].get_mpz_t());
333 for (
size_t var = 0; var < term.size(); ++var)
342 }
while (in.
peek() ==
'x');
347 if (!in.
match(
'1')) {
351 }
while (in.
peek() ==
'x');
362 if (var == 0 || var > term.size()) {
364 errorMsg <<
"There is no variable x[" << var <<
"].";
371 if (term[var] != 0) {
373 errorMsg <<
"The variable x[" 375 <<
"] appears twice in the same monomial.";
381 if (term[var] <= 0) {
383 errorMsg <<
"Expected positive integer as exponent but got " 403 vector<mpz_class>& term,
406 for (
size_t var = 0; var < term.size(); ++var)
409 bool positive =
true;
410 if (!firstTerm && in.
match(
'+'))
411 positive = !in.
match(
'-');
412 else if (in.
match(
'-'))
414 else if (!firstTerm) {
428 while (in.
peek() ==
'x') {
static const DataType & getPolynomialType()
Returns the one and only instance for polynomials.
This class contains further functionality that makes it more convenient to derive from than IOHandler...
virtual void doReadBarePolynomial(Scanner &in, const VarNames &names, CoefBigTermConsumer &consumer)
virtual void consumeRing(const VarNames &names)=0
static bool isIdentity(const Exponent *a, size_t varCount)
Returns whether a is 1, i.e. whether all entries of a are 0.
void writeTermProduct(const Term &term, const TermTranslator &translator, FILE *out)
static const char * staticGetName()
virtual void doWriteEmptyList()
virtual void doReadTerm(Scanner &in, InputConsumer &consumer)
void eatWhite()
Reads past any whitespace, where whitespace is defined by the standard function isspace().
static const DataType & getMonomialIdealListType()
Returns the one and only instance for monomial ideal lists.
size_t getVarCount() const
void clear()
Resets the number of variables to zero.
virtual void doWriteFooter(bool wasZero)
virtual BigTermConsumer * doCreateIdealWriter(FILE *out)
bool peekWhite()
Returns true if the next character is whitespace.
void registerOutput(const DataType &type)
Specify that output of the argument type is supported.
void readCoefTerm(mpz_class &coef, vector< mpz_class > &term, bool firstTerm, Scanner &in)
virtual void consume(const mpz_class &coef, const Term &term)
void readTerm(Scanner &in, vector< mpz_class > &term)
Defines the variables of a polynomial ring and facilities IO involving them.
CoCoA4IdealWriter(FILE *out)
virtual bool doPeekRing(Scanner &in)
virtual void doWriteTerm(const vector< mpz_class > &term, bool first)
virtual void doWriteHeader(bool first)
void readInteger(mpz_class &integer)
Read an arbitrary-precision integer.
void addVarSyntaxCheckUnique(const Scanner &in, const string &name)
As addvar, except it reports a syntax error if name is already a variable.
void readVarPower(Scanner &in, InputConsumer &consumer)
This class offers an input interface which is more convenient and for some purposes more efficient th...
bool peekIdentifier()
Skips whitespace and returns true if the next token is an identifier.
void writeTermProduct(const vector< mpz_class > &term, const VarNames &names, FILE *out)
void registerInput(const DataType &type)
Specify that input of the argument type is supported.
void readSizeT(size_t &size)
Reads a size_t, where the representable range of that type determines when the number is too big...
bool isIdentity(const Word *a, Word *aEnd)
virtual void doWriteTerm(const Term &term, const TermTranslator &translator, bool first)
virtual void doReadBareIdeal(Scanner &in, InputConsumer &consumer)
bool peek(char character)
Skips whitespace and returns true if the next character is equal to the parameter(s).
const char * readIdentifier()
The returned string is only valid until the next method on this object gets called.
virtual void doWriteTerm(const mpz_class &coef, const vector< mpz_class > &term, bool firstGenerator)
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.
virtual CoefBigTermConsumer * doCreatePolynomialWriter(FILE *out)
virtual void doWriteTerm(const vector< mpz_class > &term, const VarNames &names, FILE *out)
void reportSyntaxError(const Scanner &scanner, const string &errorMsg)
static const DataType & getMonomialIdealType()
Returns the one and only instance for monomial ideals.
virtual void doWriteTerm(const mpz_class &coef, const Term &term, const TermTranslator &translator, bool firstGenerator)
CoCoA4PolyWriter(FILE *out)
void writeRing(const VarNames &names, FILE *out)
const char * getExponentString(size_t variable, Exponent exponent) const
as getExponent, except the string "e" is returned, where e is the exponent.
virtual void doWriteHeader()
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.
A replacement for stringstream.
void readVarPower(vector< mpz_class > &term, Scanner &in)
Term represents a product of variables which does not include a coefficient.
void readTerm(Scanner &in, InputConsumer &consumer)
virtual void beginConsuming()=0
virtual void doReadRing(Scanner &in, VarNames &names)
bool match(char c)
Return true if the next character is c, and in that case skip past it.
virtual void doWriteFooter(bool wasZeroIdeal)
virtual void doneConsuming()=0