47 vector<mpz_class>& term,
61 fputs(
"I := Ideal(",
getFile());
67 fputs(first ?
"\n " :
",\n ",
getFile());
73 fputs(first ?
"\n " :
",\n ",
getFile());
99 bool firstGenerator) {
102 if (coef >= 0 && !firstGenerator)
106 gmp_fprintf(
getFile(),
"%Zd", coef.get_mpz_t());
113 gmp_fprintf(
getFile(),
"%Zd", coef.get_mpz_t());
119 const vector<mpz_class>& term,
120 bool firstGenerator) {
122 if (coef >= 0 && !firstGenerator)
126 for (
size_t var = 0; var < term.size(); ++var)
131 gmp_fprintf(
getFile(),
"%Zd", coef.get_mpz_t());
138 gmp_fprintf(
getFile(),
"%Zd", coef.get_mpz_t());
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') {
virtual void beginConsuming()=0
virtual void consume(const mpz_class &coef, const Term &term)
virtual void doneConsuming()=0
virtual void consumeRing(const VarNames &names)=0
static const DataType & getMonomialIdealListType()
Returns the one and only instance for monomial ideal lists.
static const DataType & getMonomialIdealType()
Returns the one and only instance for monomial ideals.
static const DataType & getPolynomialType()
Returns the one and only instance for polynomials.
A replacement for stringstream.
virtual BigTermConsumer * doCreateIdealWriter(FILE *out)
virtual void doReadBarePolynomial(Scanner &in, const VarNames &names, CoefBigTermConsumer &consumer)
virtual void doReadBareIdeal(Scanner &in, InputConsumer &consumer)
virtual void doReadRing(Scanner &in, VarNames &names)
virtual CoefBigTermConsumer * doCreatePolynomialWriter(FILE *out)
virtual void doReadTerm(Scanner &in, InputConsumer &consumer)
static const char * staticGetName()
virtual bool doPeekRing(Scanner &in)
virtual void doWriteTerm(const vector< mpz_class > &term, const VarNames &names, FILE *out)
CoCoA4IdealWriter(FILE *out)
virtual void doWriteEmptyList()
virtual void doWriteTerm(const Term &term, const TermTranslator &translator, bool first)
virtual void doWriteFooter(bool wasZeroIdeal)
virtual void doWriteHeader(bool first)
virtual void doWriteTerm(const vector< mpz_class > &term, bool first)
virtual void doWriteTerm(const mpz_class &coef, const Term &term, const TermTranslator &translator, bool firstGenerator)
virtual void doWriteHeader()
virtual void doWriteFooter(bool wasZero)
CoCoA4PolyWriter(FILE *out)
virtual void doWriteTerm(const mpz_class &coef, const vector< mpz_class > &term, bool firstGenerator)
This class contains further functionality that makes it more convenient to derive from than IOHandler...
void registerInput(const DataType &type)
Specify that input of the argument type is supported.
void registerOutput(const DataType &type)
Specify that output of the argument type is supported.
const VarNames & getNames()
const VarNames & getNames() const
This class offers an input interface which is more convenient and for some purposes more efficient th...
bool peek(char character)
Skips whitespace and returns true if the next character is equal to the parameter(s).
void eatWhite()
Reads past any whitespace, where whitespace is defined by the standard function isspace().
bool peekWhite()
Returns true if the next character is whitespace.
void expect(char expected)
Require the next character to be equal to expected.
const char * readIdentifier()
The returned string is only valid until the next method on this object gets called.
bool peekIdentifier()
Skips whitespace and returns true if the next token is an identifier.
void readSizeT(size_t &size)
Reads a size_t, where the representable range of that type determines when the number is too big.
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 * getExponentString(size_t variable, Exponent exponent) const
as getExponent, except the string "e" is returned, where e is the exponent.
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 clear()
Resets the number of variables to zero.
void addVarSyntaxCheckUnique(const Scanner &in, const string &name)
As addvar, except it reports a syntax error if name is already a variable.
void reportSyntaxError(const Scanner &scanner, const string &errorMsg)
void writeTermProduct(const Term &term, const TermTranslator &translator, FILE *out)
void readTerm(Scanner &in, InputConsumer &consumer)
void readCoefTerm(mpz_class &coef, vector< mpz_class > &term, bool firstTerm, Scanner &in)
void readTerm(Scanner &in, vector< mpz_class > &term)
void readVarPower(vector< mpz_class > &term, Scanner &in)
void readVarPower(Scanner &in, InputConsumer &consumer)
void writeTermProduct(const vector< mpz_class > &term, const VarNames &names, FILE *out)
void writeRing(const VarNames &names, FILE *out)
bool isIdentity(const Word *a, Word *aEnd)