Frobby  0.9.0
IrreducibleIdealSplitter.cpp
Go to the documentation of this file.
1 /* Frobby: Software for monomial ideal computations.
2  Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see http://www.gnu.org/licenses/.
16 */
17 #include "stdinc.h"
19 
20 #include "VarNames.h"
21 #include "TermTranslator.h"
22 
24 (BigTermConsumer& consumer):
25  _consumer(consumer),
26  _inList(false) {
27 }
28 
30 (auto_ptr<BigTermConsumer> consumer):
31  _consumer(*consumer),
32  _consumerDeleter(consumer),
33  _inList(false) {
34 }
35 
37  _tmp.reset(names.getVarCount());
38  _bigTmp.resize(names.getVarCount());
39  _consumer.consumeRing(names);
40 
42  ASSERT(_bigTmp == vector<mpz_class>(_bigTmp.size()));
43 }
44 
46  ASSERT(!_inList);
47  _inList = true;
49 }
50 
52  if (!_inList)
54 }
55 
57  ASSERT(term.getVarCount() == _tmp.getVarCount());
59 
61  for (size_t var = 0; var < term.getVarCount(); ++var) {
62  if (term[var] != 0) {
63  _tmp[var] = term[var];
65  _tmp[var] = 0;
66  }
67  }
69 
71 }
72 
74 (const Term& term, const TermTranslator& translator) {
75  ASSERT(term.getVarCount() == _tmp.getVarCount());
76  ASSERT(_tmp.isIdentity());
77 
78  _consumer.beginConsuming();
79  for (size_t var = 0; var < term.getVarCount(); ++var) {
80  if (translator.getExponent(var, term) != 0) {
81  _tmp[var] = term[var];
82  _consumer.consume(_tmp, translator);
83  _tmp[var] = 0;
84  }
85  }
86  _consumer.doneConsuming();
87 
88  ASSERT(_tmp.isIdentity());
89 }
90 
91 void IrreducibleIdealSplitter::consume(const vector<mpz_class>& term) {
92  ASSERT(term.size() == _bigTmp.size());
93  ASSERT(_bigTmp == vector<mpz_class>(_bigTmp.size()));
94 
96  for (size_t var = 0; var < term.size(); ++var) {
97  if (term[var] != 0) {
98  _bigTmp[var] = term[var];
100  _bigTmp[var] = 0;
101  }
102  }
104 
105  ASSERT(_bigTmp == vector<mpz_class>(_bigTmp.size()));
106 }
107 
109  if (!_inList)
111 }
112 
114  ASSERT(_inList);
116 }
Term::isIdentity
static bool isIdentity(const Exponent *a, size_t varCount)
Returns whether a is 1, i.e. whether all entries of a are 0.
Definition: Term.h:308
TermConsumer::beginConsumingList
virtual void beginConsumingList()
Tell the consumer that the ideals that are consumed until the next call to doneConsumingList are to b...
Definition: TermConsumer.cpp:29
stdinc.h
TermConsumer::doneConsumingList
virtual void doneConsumingList()
Must be called once after each time beginConsumingList has been called.
Definition: TermConsumer.cpp:32
Term::reset
void reset(size_t newVarCount)
Definition: Term.h:543
IrreducibleIdealSplitter::doneConsumingList
virtual void doneConsumingList()
Must be called once after each time beginConsumingList has been called.
Definition: IrreducibleIdealSplitter.cpp:113
IrreducibleIdealSplitter::_bigTmp
vector< mpz_class > _bigTmp
Definition: IrreducibleIdealSplitter.h:43
Term::getVarCount
size_t getVarCount() const
Definition: Term.h:85
BigTermConsumer::beginConsuming
virtual void beginConsuming()=0
Tell the consumer to begin consuming an ideal.
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
BigTermConsumer::consume
virtual void consume(const vector< mpz_class > &term)=0
IrreducibleIdealSplitter::_tmp
Term _tmp
Definition: IrreducibleIdealSplitter.h:42
TermTranslator
TermTranslator handles translation between terms whose exponents are infinite precision integers and ...
Definition: TermTranslator.h:41
IrreducibleIdealSplitter::consume
virtual void consume(const Term &term)
Consume a term.
Definition: IrreducibleIdealSplitter.cpp:56
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
IrreducibleIdealSplitter::doneConsuming
virtual void doneConsuming()
Must be called once after each time beginConsuming has been called.
Definition: IrreducibleIdealSplitter.cpp:108
VarNames::getVarCount
size_t getVarCount() const
Returns the current number of variables.
Definition: VarNames.h:112
IrreducibleIdealSplitter::_inList
bool _inList
Definition: IrreducibleIdealSplitter.h:44
BigTermConsumer::doneConsuming
virtual void doneConsuming()=0
Must be called once after each time beginConsuming has been called.
VarNames.h
Term
Term represents a product of variables which does not include a coefficient.
Definition: Term.h:49
BigTermConsumer
Definition: BigTermConsumer.h:29
BigTermConsumer::consumeRing
virtual void consumeRing(const VarNames &names)=0
Tell the consumer which ring is being used.
IrreducibleIdealSplitter.h
IrreducibleIdealSplitter::IrreducibleIdealSplitter
IrreducibleIdealSplitter(BigTermConsumer &consumer)
Definition: IrreducibleIdealSplitter.cpp:24
TermTranslator.h
IrreducibleIdealSplitter::consumeRing
virtual void consumeRing(const VarNames &names)
Tell the consumer which ring is being used.
Definition: IrreducibleIdealSplitter.cpp:36
IrreducibleIdealSplitter::_consumer
BigTermConsumer & _consumer
Definition: IrreducibleIdealSplitter.h:40
VarNames
Defines the variables of a polynomial ring and facilities IO involving them.
Definition: VarNames.h:40
IrreducibleIdealSplitter::beginConsuming
virtual void beginConsuming()
Tell the consumer to begin consuming an ideal.
Definition: IrreducibleIdealSplitter.cpp:51
ASSERT
#define ASSERT(X)
Definition: stdinc.h:85