PolyBoRi
BooleExponent.h
Go to the documentation of this file.
1 
2 // -*- c++ -*-
3 //*****************************************************************************
15 //*****************************************************************************
16 
17 #ifndef polybori_BooleExponent_h_
18 #define polybori_BooleExponent_h_
19 
20 // include basic definitions
21 #include <polybori/pbori_defs.h>
22 
23 // get definition of BoolePolynomial, BooleMonomial, and BooleVariable
24 #include <polybori/BooleMonomial.h>
25 #include <polybori/BooleVariable.h>
26 
28 
35  public CAuxTypes {
36 
37  public:
38 
39  //-------------------------------------------------------------------------
40  // types definitions
41  //-------------------------------------------------------------------------
42 
44  typedef std::vector<idx_type> data_type;
45 
47  typedef data_type::value_type value_type;
48 
50 
51  typedef data_type::iterator iterator;
52  typedef data_type::const_iterator const_iterator;
53  typedef data_type::reverse_iterator reverse_iterator;
54  typedef data_type::const_reverse_iterator const_reverse_iterator;
56 
58  typedef BooleExponent self;
59 
62 
65 
68 
71 
74 
77 
80 
82  BooleExponent();
83 
85  BooleExponent(const self&);
86 
87  // explicit BooleExponent(bool);
88 
90  self& get(const monom_type&);
91  explicit BooleExponent(const monom_type& rhs);
92 
94  ~BooleExponent();
95 
97  const_iterator begin() const { return m_data.begin(); }
98 
100  const_iterator end() const { return m_data.end(); }
101 
103  const_reverse_iterator rbegin() const { return m_data.rbegin(); }
104 
106  const_reverse_iterator rend() const { return m_data.rend(); }
107 
109  size_type size() const { return m_data.size(); }
110 
112  void reserve(size_type nsize) { m_data.reserve(nsize); }
113 
115  void resize(size_type nsize) { m_data.resize(nsize); }
116 
118  deg_type deg() const { return size(); }
119 
121  set_type divisors(const ring_type&) const;
122 
124  set_type multiples(const self&, const ring_type&) const;
125 
127  set_type multiples(const monom_type&) const;
128 
131  return stable_term_hash(begin(), end());
132  }
133 
135  hash_type hash() const { return stableHash(); }
136 
138  self& changeAssign(idx_type);
139 
141  self change(idx_type) const;
142 
144  self& insert(idx_type);
145 
147  self& push_back(idx_type idx);
148 
150  self& remove(idx_type);
151 
153  self insertConst(idx_type) const;
154 
156  self removeConst(idx_type) const;
157 
159  self divide(const self&) const;
160  self divideByIndex(const idx_type& rhs) const {
161  return (reducibleBy(rhs)? removeConst(rhs) : self() ); }
162 
163  self divide(const var_type& rhs) const { return divideByIndex(rhs.index()); }
164  self divide(const monom_type&) const;
165 
167  self multiply(const self&) const;
168 
169  self multiply(const idx_type& rhs) const { return insertConst(rhs); }
170  self multiply(const var_type& rhs) const { return multiply(rhs.index()); }
171  self multiply(const monom_type&) const;
172  self multiplyFirst(const set_type&) const;
173 
174 
175 // /// @name Arithmetical operations
176 // //@{
177 // self& operator*=(const self&);
178 // self& operator/=(const self&);
179 // self& operator*=(const var_type&);
180 // self& operator/=(const var_type&);
181 // //@}
182 
184 
185  bool_type operator==(const self& rhs) const { return m_data == rhs.m_data; }
186  bool_type operator!=(const self& rhs) const { return m_data != rhs.m_data; }
188 
190  self& operator=(const self& rhs) { m_data = rhs.m_data; return *this; }
191  self& operator=(const monom_type& rhs) {
192  m_data.resize(rhs.size());
193  std::copy(rhs.begin(), rhs.end(), internalBegin());
194  return *this;
195  }
196 
198  bool_type reducibleBy(const self& rhs) const;
199  bool_type reducibleBy(const monom_type& rhs) const;
200  bool_type reducibleBy(const idx_type& rhs) const;
201  bool_type reducibleBy(const var_type& rhs) const {
202  return reducibleBy(rhs.index()); }
203 
204 
205 // /// Test for reducibility wrt. to a given variable
206 // bool_type reducibleBy(const var_type& rhs) const;
207 
209  deg_type LCMDeg(const self&) const;
210 
213 
215  self LCM(const self&) const;
216 
218  //self& GCDAssign(const self&);
219 
221  self GCD(const self&) const;
222 
224  self& popFirst() {
225  if(!m_data.empty())
226  m_data.erase(m_data.begin());
227  return *this;
228  }
229 
231  ostream_type& print(ostream_type&) const;
232 
233 protected:
235  iterator internalBegin() { return m_data.begin(); }
236 
238  iterator internalEnd() { return m_data.end(); }
239 
241  reverse_iterator rInternalBegin() { return m_data.rbegin(); }
242 
244  reverse_iterator rInternalEnd() { return m_data.rend(); }
245 
248 };
249 
250 
252 template <class RHSType>
253 inline BooleExponent
254 operator+(const BooleExponent& lhs, const RHSType& rhs) {
255  return lhs.multiply(rhs);
256 }
257 
259 template <class RHSType>
260 inline BooleExponent
261 operator-(const BooleExponent& lhs, const RHSType& rhs) {
262  return lhs.divide(rhs);
263 }
264 
266 inline BooleExponent
267 GCD(const BooleExponent& lhs, const BooleExponent& rhs ){
268 
269  return lhs.GCD(rhs);
270 }
271 
273 inline BooleExponent
274 LCM(const BooleExponent& lhs, const BooleExponent& rhs ){
275 
276  return lhs.LCM(rhs);
277 }
278 
279 
281 inline BooleExponent::ostream_type&
282 operator<<(BooleExponent::ostream_type& os, const BooleExponent& rhs) {
283  return rhs.print(os);
284 }
285 
287 
288 #endif // of polybori_BooleExponent_h_