fourti2.cpp
Go to the documentation of this file.
/* Frobby: Software for monomial ideal computations.
Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
*/
#include "stdinc.h"
#include "fourti2.h"
#include "BigIdeal.h"
#include "Scanner.h"
#include "IOHandler.h"
#include "error.h"
namespace fourti2 {
void readTerm(BigIdeal& ideal, Scanner& scanner) {
ideal.newLastTerm();
mpz_class tmp;
scanner.readIntegerAndNegativeAsZero(tmp);
if (tmp > 0)
reportError("Encountered positive entry as first entry in term. "
"This is impossible if using the required degree reverse "
"lexicographic term order.\n");
for (size_t i = 0; i < ideal.getVarCount(); ++i) {
scanner.readIntegerAndNegativeAsZero(tmp);
if (tmp > 0)
ideal.getLastTermExponentRef(i) = tmp;
}
}
void readGrobnerBasis(Scanner& scanner, BigIdeal& basis) {
size_t termCount;
size_t varCount;
scanner.readSizeT(termCount);
scanner.readSizeT(varCount);
if (varCount == 0)
reportError
("The matrix defining the Frobenius-related Grobner basis must "
"have at least one column, and this one has none.");
VarNames names(varCount - 1);
basis.clearAndSetNames(names);
for (size_t i = 0; i < termCount; ++i)
readTerm(basis, scanner);
}
void readLatticeBasis(Scanner& scanner, BigIdeal& basis) {
size_t rowCount;
size_t columnCount;
scanner.readSizeT(rowCount);
scanner.readSizeT(columnCount);
VarNames names(columnCount);
basis.clearAndSetNames(names);
for (unsigned int i = 0; i < rowCount; ++i) {
basis.newLastTerm();
for (unsigned int j = 0; j < columnCount; ++j)
scanner.readInteger(basis.getLastTermExponentRef(j));
}
}
void writeLatticeBasis(FILE* out, const BigIdeal& basis) {
fprintf(out, "%lu %lu\n",
(unsigned long)basis.getGeneratorCount(),
(unsigned long)basis.getVarCount());
for (unsigned int i = 0; i < basis.getGeneratorCount(); ++i) {
const char* prefix = "";
for (unsigned int j = 0; j < basis[i].size(); ++j) {
gmp_fprintf(out, "%s%Zd", prefix, basis[i][j].get_mpz_t());
prefix = " ";
}
fputc('\n', out);
}
}
}
BigIdeal.h
IOHandler.h
Scanner.h
BigIdeal
Definition BigIdeal.h:27
BigIdeal::clearAndSetNames
void clearAndSetNames(const VarNames &names)
Definition BigIdeal.cpp:222
BigIdeal::newLastTerm
void newLastTerm()
Definition BigIdeal.cpp:104
BigIdeal::getLastTermExponentRef
mpz_class & getLastTermExponentRef(size_t var)
Definition BigIdeal.h:126
BigIdeal::getVarCount
size_t getVarCount() const
Definition BigIdeal.h:148
BigIdeal::getGeneratorCount
size_t getGeneratorCount() const
Definition BigIdeal.h:144
Scanner
This class offers an input interface which is more convenient and for some purposes more efficient th...
Definition Scanner.h:50
Scanner::readIntegerAndNegativeAsZero
void readIntegerAndNegativeAsZero(mpz_class &integer)
Read an integer and set it to zero if it is negative.
Definition Scanner.cpp:171
Scanner::readSizeT
void readSizeT(size_t &size)
Reads a size_t, where the representable range of that type determines when the number is too big.
Definition Scanner.cpp:205
Scanner::readInteger
void readInteger(mpz_class &integer)
Read an arbitrary-precision integer.
Definition Scanner.h:238
VarNames
Defines the variables of a polynomial ring and facilities IO involving them.
Definition VarNames.h:40
reportError
void reportError(const string &errorMsg)
Definition error.cpp:23
error.h
fourti2.h
fourti2
Definition fourti2.cpp:25
fourti2::readGrobnerBasis
void readGrobnerBasis(Scanner &scanner, BigIdeal &basis)
Definition fourti2.cpp:44
fourti2::readTerm
void readTerm(BigIdeal &ideal, Scanner &scanner)
Definition fourti2.cpp:26
fourti2::readLatticeBasis
void readLatticeBasis(Scanner &scanner, BigIdeal &basis)
Definition fourti2.cpp:63
fourti2::writeLatticeBasis
void writeLatticeBasis(FILE *out, const BigIdeal &basis)
Definition fourti2.cpp:80
stdinc.h
This header file includes common definitions and is included as the first line of code in every imple...