Frobby  0.9.5
BigIdeal.h
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 #ifndef BIG_IDEAL_GUARD
18 #define BIG_IDEAL_GUARD
19 
20 #include "VarNames.h"
21 #include <vector>
22 
23 class TermTranslator;
24 class Ideal;
25 class SquareFreeIdeal;
26 
27 class BigIdeal {
28 public:
29  BigIdeal();
30  BigIdeal(const VarNames& names);
31 
32  void insert(const Ideal& ideal);
33  void insert(const Ideal& ideal, const TermTranslator& translator);
34  void insert(const SquareFreeIdeal& ideal);
35  void insert(const vector<mpz_class>& term);
36 
37  void renameVars(const VarNames& names);
38 
39  void newLastTerm();
40  void reserve(size_t capacity);
41 
42  mpz_class& getLastTermExponentRef(size_t var);
43  vector<mpz_class>& getLastTermRef();
44  const vector<mpz_class>& getTerm(size_t term) const;
45 
46  void getLcm(vector<mpz_class>& lcm) const;
47 
48  const mpz_class& getExponent(size_t term, size_t var) const;
49  mpz_class& getExponent(size_t term, size_t var);
50  void setExponent(size_t term, size_t var, const mpz_class& exp);
51 
52  bool operator==(const BigIdeal& b) const;
53 
54  vector<mpz_class>& operator[](size_t index);
55  const vector<mpz_class>& operator[](size_t index) const;
56 
57  void projectVar(size_t var);
58 
59  // This also depends on the order of the variables.
60  bool operator<(const BigIdeal& ideal) const;
61 
62  bool empty() const;
63  bool containsIdentity() const;
64  bool contains(const vector<mpz_class>& term) const;
65 
66  void clear();
67 
68  inline size_t getGeneratorCount() const;
69  size_t getVarCount() const;
70 
71  void clearAndSetNames(const VarNames& names);
72 
73  // Adds a variable to the VarNames associated to the ideal. It is an
74  // error to call this method when the ideal has any generators. If
75  // var is already a known variable, nothing is changed, and the
76  // return value is false. Otherwise, the return value is true.
77  bool addVarToClearedIdeal(const char* var);
78 
79  // Remove variable from each generator and from the ring.
80  void eraseVar(size_t var);
81 
82  const VarNames& getNames() const;
83 
84  // Applies a generic deformation.
85  void deform();
86 
87  // Takes the radical of every generator.
88  void takeRadical();
89 
90  // Sorts the generators and removes duplicates.
91  void sortGeneratorsUnique();
92 
93  // Sorts the generators.
94  void sortGenerators();
95 
96  // Sorts the variables.
97  void sortVariables();
98 
99  void swap(BigIdeal& ideal);
100 
101  void print(FILE* file) const;
102  void print(ostream& out) const;
103 
104  static bool bigTermCompare(const vector<mpz_class>& a,
105  const vector<mpz_class>& b);
106 private:
107  vector<vector<mpz_class> > _terms;
109 };
110 
111 ostream& operator<<(ostream& out, const BigIdeal& ideal);
112 ostream& operator<<(ostream& out, const vector<BigIdeal>& ideals);
113 
114 
115 
116 inline vector<mpz_class>& BigIdeal::operator[](size_t index) {
117  ASSERT(index < _terms.size());
118  return _terms[index];
119 }
120 
121 inline const vector<mpz_class>& BigIdeal::operator[](size_t index) const {
122  ASSERT(index < _terms.size());
123  return _terms[index];
124 }
125 
126 inline mpz_class& BigIdeal::getLastTermExponentRef(size_t var) {
127  ASSERT(!empty());
128  ASSERT(var < _names.getVarCount());
129 
130  return _terms.back()[var];
131 }
132 
133 inline vector<mpz_class>& BigIdeal::getLastTermRef() {
134  ASSERT(!empty());
135 
136  return _terms.back();
137 }
138 
139 inline const vector<mpz_class>& BigIdeal::getTerm(size_t term) const {
140  ASSERT(term < getGeneratorCount());
141  return _terms[term];
142 }
143 
144 inline size_t BigIdeal::getGeneratorCount() const {
145  return _terms.size();
146 }
147 
148 inline size_t BigIdeal::getVarCount() const {
149  return _names.getVarCount();
150 }
151 
152 #endif
ostream & operator<<(ostream &out, const BigIdeal &ideal)
Definition: BigIdeal.cpp:361
void reserve(size_t capacity)
Definition: BigIdeal.cpp:112
void eraseVar(size_t var)
Definition: BigIdeal.cpp:233
void sortGenerators()
Definition: BigIdeal.cpp:280
void clearAndSetNames(const VarNames &names)
Definition: BigIdeal.cpp:222
void newLastTerm()
Definition: BigIdeal.cpp:104
void swap(BigIdeal &ideal)
Definition: BigIdeal.cpp:305
static bool bigTermCompare(const vector< mpz_class > &a, const vector< mpz_class > &b)
Definition: BigIdeal.cpp:349
bool empty() const
Definition: BigIdeal.cpp:192
void sortGeneratorsUnique()
Definition: BigIdeal.cpp:273
const vector< mpz_class > & getTerm(size_t term) const
Definition: BigIdeal.h:139
mpz_class & getLastTermExponentRef(size_t var)
Definition: BigIdeal.h:126
void renameVars(const VarNames &names)
Definition: BigIdeal.cpp:99
void getLcm(vector< mpz_class > &lcm) const
Definition: BigIdeal.cpp:143
bool contains(const vector< mpz_class > &term) const
Definition: BigIdeal.cpp:207
vector< vector< mpz_class > > _terms
Definition: BigIdeal.h:107
void deform()
Definition: BigIdeal.cpp:257
size_t getVarCount() const
Definition: BigIdeal.h:148
void clear()
Definition: BigIdeal.cpp:218
bool operator==(const BigIdeal &b) const
Definition: BigIdeal.cpp:154
VarNames _names
Definition: BigIdeal.h:108
void insert(const Ideal &ideal)
Definition: BigIdeal.cpp:60
const VarNames & getNames() const
Definition: BigIdeal.cpp:253
size_t getGeneratorCount() const
Definition: BigIdeal.h:144
BigIdeal()
Definition: BigIdeal.cpp:53
void projectVar(size_t var)
Definition: BigIdeal.cpp:158
void sortVariables()
Definition: BigIdeal.cpp:298
bool operator<(const BigIdeal &ideal) const
Definition: BigIdeal.cpp:166
void print(FILE *file) const
Definition: BigIdeal.cpp:310
vector< mpz_class > & operator[](size_t index)
Definition: BigIdeal.h:116
void takeRadical()
Definition: BigIdeal.cpp:264
bool containsIdentity() const
Definition: BigIdeal.cpp:196
const mpz_class & getExponent(size_t term, size_t var) const
Definition: BigIdeal.cpp:328
bool addVarToClearedIdeal(const char *var)
Definition: BigIdeal.cpp:227
vector< mpz_class > & getLastTermRef()
Definition: BigIdeal.h:133
void setExponent(size_t term, size_t var, const mpz_class &exp)
Definition: BigIdeal.cpp:342
Represents a monomial ideal with int exponents.
Definition: Ideal.h:27
TermTranslator handles translation between terms whose exponents are infinite precision integers and ...
Defines the variables of a polynomial ring and facilities IO involving them.
Definition: VarNames.h:40
size_t getVarCount() const
Returns the current number of variables.
Definition: VarNames.h:113
void lcm(Word *res, const Word *resEnd, const Word *a, const Word *b)
#define ASSERT(X)
Definition: stdinc.h:86