Go to the documentation of this file.00001
00002
00157
00158
00159 #ifndef BooleMonomial_h_
00160 #define BooleMonomial_h_
00161
00162
00163 #include "pbori_defs.h"
00164
00165
00166 #include "BoolePolynomial.h"
00167 #include "BooleVariable.h"
00168
00169 #include <map>
00170
00171
00172 #include "CVariableIter.h"
00173
00174
00175 #include "PBoRiError.h"
00176
00177 BEGIN_NAMESPACE_PBORI
00178
00179 class BooleVariable;
00180 class BooleExponent;
00181 template <class DDType, class MonomType> class CDDOperations;
00182
00191 class BooleMonomial {
00192
00193 public:
00194 template <class, class> friend class CDDOperations;
00195 friend class COrderBase;
00196 template <class, class> friend class CTermGeneratorBase;
00197
00198
00199
00200
00201
00203
00204 typedef CTypes::dd_type dd_type;
00205 typedef CTypes::size_type size_type;
00206 typedef CTypes::deg_type deg_type;
00207 typedef CTypes::idx_type idx_type;
00208 typedef CTypes::hash_type hash_type;
00209 typedef CTypes::bool_type bool_type;
00210 typedef CTypes::comp_type comp_type;
00211 typedef CTypes::integer_type integer_type;
00212 typedef CTypes::ostream_type ostream_type;
00214
00216 typedef BooleMonomial self;
00217
00219 typedef BoolePolynomial poly_type;
00220
00222 typedef poly_type::var_type var_type;
00223
00225 typedef poly_type::constant_type constant_type;
00226
00228 typedef poly_type::set_type set_type;
00229
00231 typedef poly_type::exp_type exp_type;
00232
00234 typedef poly_type::ring_type ring_type;
00235
00237 typedef poly_type::first_iterator const_iterator;
00238
00240 typedef CVariableIter<const_iterator, var_type> variable_iterator;
00241
00243
00244
00245 typedef std::map<self, idx_type, symmetric_composition<
00246 std::less<poly_type::navigator>,
00247 navigates<poly_type> > > idx_map_type;
00248
00250 typedef dd_type::easy_equality_property easy_equality_property;
00251
00253 BooleMonomial():
00254 m_poly( BooleEnv::one() ) { }
00255
00257 BooleMonomial(const self& rhs):
00258 m_poly(rhs.m_poly) {}
00259
00261 BooleMonomial(const var_type& rhs);
00262
00263
00265 BooleMonomial(const exp_type& rhs, const ring_type& ring):
00266 m_poly(rhs, ring) { }
00267
00269 BooleMonomial(const ring_type& ring):
00270 m_poly(ring.one()) {}
00271
00273 ~BooleMonomial() {}
00274
00276 operator const BoolePolynomial&() const { return m_poly; }
00277
00279 exp_type exp() const;
00280
00281
00283 const_iterator begin() const { return m_poly.firstBegin(); }
00284
00286 const_iterator end() const { return m_poly.firstEnd(); }
00287
00289 variable_iterator variableBegin() const {
00290 return variable_iterator(begin(), ring());
00291 }
00292
00294 variable_iterator variableEnd() const {
00295 return variable_iterator(end(), ring());
00296 }
00297
00299 deg_type deg() const {
00301 #if 0
00302 return m_poly.nNodes();
00303 #else
00304 return std::distance(m_poly.firstBegin(),m_poly.firstEnd());
00305 #endif
00306 }
00307
00309 size_type size() const { return (size_type)deg(); }
00310
00312 set_type divisors() const { return m_poly.lmDivisors(); }
00313
00315 set_type multiples(const self&) const;
00316
00318 hash_type stableHash() const {
00319 return stable_first_hash_range(m_poly.navigation());
00320 }
00321
00323 hash_type hash() const { return m_poly.hash(); }
00324
00326 self& changeAssign(idx_type);
00327
00329 self change(idx_type) const;
00330
00331
00333
00334 self& operator*=(const self&);
00335 self& operator/=(const self&);
00336 self& operator*=(const var_type&);
00337 self& operator/=(const var_type&);
00339
00341
00342 bool_type operator==(const self& rhs) const { return m_poly == rhs.m_poly; }
00343 bool_type operator!=(const self& rhs) const { return m_poly != rhs.m_poly; }
00344 bool_type operator==(constant_type rhs) const { return m_poly == rhs; }
00345 bool_type operator!=(constant_type rhs) const { return m_poly != rhs; }
00346 bool_type isOne() const { return m_poly.isOne(); }
00347 bool_type isConstant() const { return m_poly.isConstant(); }
00349
00351 bool_type reducibleBy(const self& rhs) const {
00352 return m_poly.reducibleBy(rhs); }
00353 bool_type reducibleBy(const var_type& rhs) const;
00354
00356 comp_type compare(const self&) const;
00357
00359 deg_type LCMDeg(const self&) const;
00360
00362 self& LCMAssign(const self&);
00363
00365 self LCM(const self&) const;
00366
00368 self& GCDAssign(const self&);
00369
00371 self GCD(const self&) const;
00372
00374 const dd_type& diagram() const { return m_poly.diagram(); }
00375
00377 set_type set() const { return m_poly.set(); }
00378
00380 self& popFirst() {
00381 assert(!m_poly.isConstant());
00382 return *this = set_type( dd_type(m_poly.diagram().manager(),
00383 m_poly.navigation().thenBranch()) );
00384 }
00385
00387 var_type firstVariable() const;
00388
00390 idx_type firstIndex() const {
00391 assert(!m_poly.isConstant());
00392 return *begin();
00393 }
00394
00396 ring_type ring() const { return m_poly.ring(); }
00397
00398 protected:
00400 dd_type& internalDiagram() { return m_poly.internalDiagram(); }
00401
00403
00405 BooleMonomial(const set_type& rhs): m_poly(rhs.diagram()) {
00406 assert(!m_poly.isZero());
00407 }
00408
00409 private:
00410 BoolePolynomial m_poly;
00411 };
00412
00414 inline BooleMonomial
00415 operator*(const BooleMonomial& lhs, const BooleMonomial& rhs) {
00416 return BooleMonomial(lhs) *= rhs;
00417 }
00419 inline BooleMonomial
00420 operator*(const BooleMonomial& lhs, const BooleVariable& rhs) {
00421 return BooleMonomial(lhs) *= rhs;
00422 }
00424 inline BoolePolynomial
00425 operator*(const BooleMonomial& lhs, BooleConstant rhs) {
00426 return BoolePolynomial(lhs) *= rhs;
00427 }
00428
00430 inline BoolePolynomial
00431 operator*(BooleConstant lhs, const BooleMonomial& rhs) {
00432 return rhs * lhs;
00433 }
00434
00436 inline BooleMonomial
00437 operator/(const BooleMonomial& lhs, const BooleMonomial& rhs) {
00438 return BooleMonomial(lhs) /= rhs;
00439 }
00440
00442 inline BooleMonomial
00443 operator/(const BooleMonomial& lhs, const BooleVariable& rhs) {
00444 return lhs / BooleMonomial(rhs);
00445 }
00446
00448 inline BooleMonomial::bool_type
00449 operator<(const BooleMonomial& lhs, const BooleMonomial& rhs) {
00450
00451 return (lhs.compare(rhs) == CTypes::less_than);
00452 }
00453
00455 inline BooleMonomial::bool_type
00456 operator>(const BooleMonomial& lhs, const BooleMonomial& rhs) {
00457
00458 return (lhs.compare(rhs) == CTypes::greater_than);
00459 }
00460
00462 inline BooleMonomial::bool_type
00463 operator<=(const BooleMonomial& lhs, const BooleMonomial& rhs) {
00464
00465 return (lhs.compare(rhs) <= CTypes::less_or_equal_max);
00466 }
00467
00469 inline BooleMonomial::bool_type
00470 operator>=(const BooleMonomial& lhs, const BooleMonomial& rhs) {
00471
00472 return (lhs.compare(rhs) >= CTypes::greater_or_equal_min);
00473 }
00474
00475
00477 inline BooleMonomial
00478 GCD(const BooleMonomial& lhs, const BooleMonomial& rhs ){
00479
00480 return lhs.GCD(rhs);
00481 }
00482
00484 inline BooleMonomial
00485 LCM(const BooleMonomial& lhs, const BooleMonomial& rhs ){
00486
00487 return lhs.LCM(rhs);
00488 }
00489
00492 BooleMonomial::bool_type
00493 greater_variable(BooleMonomial::idx_type lhs, BooleMonomial::idx_type rhs);
00494
00495
00497 inline BoolePolynomial
00498 operator*(const BooleVariable& lhs, const BooleConstant& rhs){
00499
00500 return BooleMonomial(lhs) * rhs;
00501 }
00502
00504 inline BoolePolynomial
00505 operator*(const BooleConstant& lhs, const BooleVariable& rhs){
00506
00507 return rhs * lhs;
00508 }
00509
00511 inline BoolePolynomial
00512 operator*(const BooleVariable& lhs,
00513 const BoolePolynomial& rhs){
00514
00515 return BoolePolynomial(rhs) *= BooleMonomial(lhs);
00516 }
00517
00519 inline BooleMonomial
00520 operator*(const BooleVariable& lhs,
00521 const BooleMonomial& rhs){
00522
00523 return BooleMonomial(lhs) * rhs;
00524 }
00525
00527 inline BoolePolynomial&
00528 operator*=(BoolePolynomial& lhs,
00529 const BooleVariable& rhs){
00530
00531 return lhs *= BooleMonomial(rhs);
00532 }
00533
00535 inline BooleMonomial
00536 operator*(const BooleVariable& lhs,
00537 const BooleVariable& rhs){
00538
00539 return BooleMonomial(lhs) *= BooleMonomial(rhs);
00540 }
00541
00543 inline BoolePolynomial
00544 operator*(const BoolePolynomial& lhs,
00545 const BooleVariable& rhs){
00546
00547 return BoolePolynomial(lhs) *= BooleMonomial(rhs);
00548 }
00549
00551 inline BoolePolynomial&
00552 operator/=(BoolePolynomial& lhs, const BooleVariable& rhs){
00553
00554 return lhs /= BooleMonomial(rhs);
00555 }
00556
00558 inline BoolePolynomial
00559 operator/(const BoolePolynomial& lhs,
00560 const BooleVariable& rhs){
00561
00562 return lhs / BooleMonomial(rhs);
00563 }
00564
00565
00567 inline BoolePolynomial
00568 operator%(const BoolePolynomial& lhs,
00569 const BooleVariable& rhs){
00570
00571 return lhs % BooleMonomial(rhs);
00572 }
00573
00575 inline BoolePolynomial&
00576 operator%=(BoolePolynomial& lhs,
00577 const BooleVariable& rhs){
00578
00579 return lhs %= BooleMonomial(rhs);
00580 }
00581
00582 END_NAMESPACE_PBORI
00583
00584
00585 #endif // of BooleMonomial_h_