Go to the documentation of this file.
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 CoefBigTermConsumer * doCreatePolynomialWriter(FILE *out)
static bool isIdentity(const Exponent *a, size_t varCount)
Returns whether a is 1, i.e. whether all entries of a are 0.
virtual bool doPeekRing(Scanner &in)
static const DataType & getMonomialIdealListType()
Returns the one and only instance for monomial ideal lists.
void readCoefTerm(mpz_class &coef, vector< mpz_class > &term, bool firstTerm, Scanner &in)
void readInteger(mpz_class &integer)
Read an arbitrary-precision integer.
static const DataType & getPolynomialType()
Returns the one and only instance for polynomials.
virtual void doReadRing(Scanner &in, VarNames &names)
void writeRing(const VarNames &names, FILE *out)
void readTerm(Scanner &in, InputConsumer &consumer)
virtual void doWriteEmptyList()
This class offers an input interface which is more convenient and for some purposes more efficient th...
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)
void registerInput(const DataType &type)
Specify that input of the argument type is supported.
void readVarPower(vector< mpz_class > &term, Scanner &in)
virtual void consumeRing(const VarNames &names)=0
void writeTermProduct(const Term &term, const TermTranslator &translator, FILE *out)
CoCoA4PolyWriter(FILE *out)
const VarNames & getNames()
virtual void doWriteTerm(const mpz_class &coef, const vector< mpz_class > &term, bool firstGenerator)
virtual void doWriteTerm(const vector< mpz_class > &term, bool first)
void readTerm(Scanner &in, vector< mpz_class > &term)
size_t getVarCount() const
virtual void doWriteTerm(const mpz_class &coef, const Term &term, const TermTranslator &translator, bool firstGenerator)
bool match(char c)
Return true if the next character is c, and in that case skip past it.
virtual void beginConsuming()=0
const char * readIdentifier()
The returned string is only valid until the next method on this object gets called.
const string & getName(size_t index) const
The returned reference can become invalid next time addVar is called.
virtual void doWriteHeader()
TermTranslator handles translation between terms whose exponents are infinite precision integers and ...
void addVarSyntaxCheckUnique(const Scanner &in, const string &name)
As addvar, except it reports a syntax error if name is already a variable.
const VarNames & getNames() const
size_t getVarCount() const
Returns the current number of variables.
virtual void doWriteHeader(bool first)
CoCoA4IdealWriter(FILE *out)
virtual void doneConsuming()=0
bool peekWhite()
Returns true if the next character is whitespace.
virtual void doReadBareIdeal(Scanner &in, InputConsumer &consumer)
Term represents a product of variables which does not include a coefficient.
void expect(char expected)
Require the next character to be equal to expected.
void reportSyntaxError(const Scanner &scanner, const string &errorMsg)
virtual void doWriteTerm(const vector< mpz_class > &term, 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.
void clear()
Resets the number of variables to zero.
void readVarPower(Scanner &in, InputConsumer &consumer)
virtual void doWriteTerm(const Term &term, const TermTranslator &translator, bool first)
void registerOutput(const DataType &type)
Specify that output 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.
static const DataType & getMonomialIdealType()
Returns the one and only instance for monomial ideals.
virtual void doWriteFooter(bool wasZero)
A replacement for stringstream.
void eatWhite()
Reads past any whitespace, where whitespace is defined by the standard function isspace().
virtual void doReadTerm(Scanner &in, InputConsumer &consumer)
void writeTermProduct(const vector< mpz_class > &term, const VarNames &names, FILE *out)
virtual void consume(const mpz_class &coef, const Term &term)
virtual void doWriteFooter(bool wasZeroIdeal)
bool peekIdentifier()
Skips whitespace and returns true if the next token is an identifier.
Defines the variables of a polynomial ring and facilities IO involving them.
virtual BigTermConsumer * doCreateIdealWriter(FILE *out)
bool peek(char character)
Skips whitespace and returns true if the next character is equal to the parameter(s).
static const char * staticGetName()
bool isIdentity(const Word *a, Word *aEnd)