IrreducibleIdealSplitter.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 "IrreducibleIdealSplitter.h"
#include "VarNames.h"
#include "TermTranslator.h"
IrreducibleIdealSplitter::IrreducibleIdealSplitter
(BigTermConsumer& consumer):
_consumer(consumer),
_inList(false) {
}
IrreducibleIdealSplitter::IrreducibleIdealSplitter
(unique_ptr<BigTermConsumer> consumer):
_consumer(*consumer),
_consumerDeleter(std::move(consumer)),
_inList(false) {
}
void IrreducibleIdealSplitter::consumeRing(const VarNames& names) {
_tmp.reset(names.getVarCount());
_bigTmp.resize(names.getVarCount());
_consumer.consumeRing(names);
ASSERT(_tmp.isIdentity());
ASSERT(_bigTmp == vector<mpz_class>(_bigTmp.size()));
}
void IrreducibleIdealSplitter::beginConsumingList() {
ASSERT(!_inList);
_inList = true;
_consumer.beginConsumingList();
}
void IrreducibleIdealSplitter::beginConsuming() {
if (!_inList)
_consumer.beginConsumingList();
}
void IrreducibleIdealSplitter::consume(const Term& term) {
ASSERT(term.getVarCount() == _tmp.getVarCount());
ASSERT(_tmp.isIdentity());
_consumer.beginConsuming();
for (size_t var = 0; var < term.getVarCount(); ++var) {
if (term[var] != 0) {
_tmp[var] = term[var];
_consumer.consume(_tmp);
_tmp[var] = 0;
}
}
_consumer.doneConsuming();
ASSERT(_tmp.isIdentity());
}
void IrreducibleIdealSplitter::consume
(const Term& term, const TermTranslator& translator) {
ASSERT(term.getVarCount() == _tmp.getVarCount());
ASSERT(_tmp.isIdentity());
_consumer.beginConsuming();
for (size_t var = 0; var < term.getVarCount(); ++var) {
if (translator.getExponent(var, term) != 0) {
_tmp[var] = term[var];
_consumer.consume(_tmp, translator);
_tmp[var] = 0;
}
}
_consumer.doneConsuming();
ASSERT(_tmp.isIdentity());
}
void IrreducibleIdealSplitter::consume(const vector<mpz_class>& term) {
ASSERT(term.size() == _bigTmp.size());
ASSERT(_bigTmp == vector<mpz_class>(_bigTmp.size()));
_consumer.beginConsuming();
for (size_t var = 0; var < term.size(); ++var) {
if (term[var] != 0) {
_bigTmp[var] = term[var];
_consumer.consume(_bigTmp);
_bigTmp[var] = 0;
}
}
_consumer.doneConsuming();
ASSERT(_bigTmp == vector<mpz_class>(_bigTmp.size()));
}
void IrreducibleIdealSplitter::doneConsuming() {
if (!_inList)
_consumer.doneConsumingList();
}
void IrreducibleIdealSplitter::doneConsumingList() {
ASSERT(_inList);
_consumer.doneConsumingList();
}
IrreducibleIdealSplitter.h
TermTranslator.h
VarNames.h
BigTermConsumer
Definition BigTermConsumer.h:29
IrreducibleIdealSplitter::IrreducibleIdealSplitter
IrreducibleIdealSplitter(BigTermConsumer &consumer)
Definition IrreducibleIdealSplitter.cpp:24
IrreducibleIdealSplitter::_consumerDeleter
unique_ptr< BigTermConsumer > _consumerDeleter
Definition IrreducibleIdealSplitter.h:41
IrreducibleIdealSplitter::beginConsuming
virtual void beginConsuming()
Tell the consumer to begin consuming an ideal.
Definition IrreducibleIdealSplitter.cpp:51
IrreducibleIdealSplitter::_tmp
Term _tmp
Definition IrreducibleIdealSplitter.h:42
IrreducibleIdealSplitter::_inList
bool _inList
Definition IrreducibleIdealSplitter.h:44
IrreducibleIdealSplitter::consume
virtual void consume(const Term &term)
Consume a term.
Definition IrreducibleIdealSplitter.cpp:56
IrreducibleIdealSplitter::beginConsumingList
virtual void beginConsumingList()
Tell the consumer that the ideals that are consumed until the next call to doneConsumingList are to b...
Definition IrreducibleIdealSplitter.cpp:45
IrreducibleIdealSplitter::_bigTmp
vector< mpz_class > _bigTmp
Definition IrreducibleIdealSplitter.h:43
IrreducibleIdealSplitter::doneConsuming
virtual void doneConsuming()
Must be called once after each time beginConsuming has been called.
Definition IrreducibleIdealSplitter.cpp:108
IrreducibleIdealSplitter::doneConsumingList
virtual void doneConsumingList()
Must be called once after each time beginConsumingList has been called.
Definition IrreducibleIdealSplitter.cpp:113
IrreducibleIdealSplitter::_consumer
BigTermConsumer & _consumer
Definition IrreducibleIdealSplitter.h:40
IrreducibleIdealSplitter::consumeRing
virtual void consumeRing(const VarNames &names)
Tell the consumer which ring is being used.
Definition IrreducibleIdealSplitter.cpp:36
TermTranslator
TermTranslator handles translation between terms whose exponents are infinite precision integers and ...
Definition TermTranslator.h:41
TermTranslator::getExponent
const mpz_class & getExponent(size_t variable, Exponent exponent) const
This method translates from IDs to arbitrary precision integers.
Definition TermTranslator.cpp:392
Term
Term represents a product of variables which does not include a coefficient.
Definition Term.h:49
Term::getVarCount
size_t getVarCount() const
Definition Term.h:85
VarNames
Defines the variables of a polynomial ring and facilities IO involving them.
Definition VarNames.h:40
VarNames::getVarCount
size_t getVarCount() const
Returns the current number of variables.
Definition VarNames.h:113
stdinc.h
This header file includes common definitions and is included as the first line of code in every imple...
ASSERT
#define ASSERT(X)
Definition stdinc.h:86