Frobby  0.9.5
TermPredicate.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  Copyright (C) 2010 University of Aarhus
4  Contact Bjarke Hammersholt Roune for license information (www.broune.com)
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see http://www.gnu.org/licenses/.
18 */
19 #ifndef TERM_ORDER_GUARD
20 #define TERM_ORDER_GUARD
21 
22 #include "Term.h"
23 
25  public:
26  TermPredicate(size_t varCount = 0);
27  virtual ~TermPredicate();
28 
29  bool operator()(const Term& a, const Term& b) const {
30  ASSERT(a.getVarCount() == getVarCount());
31  ASSERT(b.getVarCount() == getVarCount());
32  return doPredicate(a.begin(), b.begin());
33  }
34 
35  bool operator()(const Term& a, const Exponent* b) const {
36  ASSERT(a.getVarCount() == getVarCount());
37  ASSERT(b != 0 || getVarCount() == 0);
38  return doPredicate(a.begin(), b);
39  }
40 
41  bool operator()(const Exponent* a, const Term& b) const {
42  ASSERT(b.getVarCount() == getVarCount());
43  ASSERT(a != 0 || getVarCount() == 0);
44  return doPredicate(a, b.begin());
45  }
46 
47  bool operator()(const Exponent* a, const Exponent* b) const {
48  ASSERT(a != 0 || getVarCount() == 0);
49  ASSERT(b != 0 || getVarCount() == 0);
50  return doPredicate(a, b);
51  }
52 
53  size_t getVarCount() const {return _varCount;}
54  void setVarCount(size_t varCount) {_varCount = varCount;}
55 
56  private:
57  virtual bool doPredicate(const Exponent* a, const Exponent* b) const = 0;
58 
59  size_t _varCount;
60 };
61 
65  public:
66  StlTermPredicate(const TermPredicate& pred): _pred(pred) {}
67  template<class T>
68  bool operator()(const T& a, const T& b) const {return _pred(a, b);}
69  private:
71 };
72 
74 auto_ptr<TermPredicate> createTermPredicate(const string& prefix,
75  size_t varCount = 0);
76 
77 
82 int lexCompare(const Exponent* a, const Exponent* b, size_t varCount);
83 int lexCompare(const Term& a, const Term& b);
84 
89 int reverseLexCompare(const Exponent* a, const Exponent* b, size_t varCount);
90 
92 bool equals(const Exponent* a, const Exponent* b, size_t varCount);
93 
94 
95 
97 class LexComparator : public TermPredicate {
98  public:
99  LexComparator(size_t varCount = 0);
100 
101  static const char* staticGetName();
102 
103  private:
104  virtual bool doPredicate(const Exponent* a,
105  const Exponent* b) const {
106  return lexCompare(a, b, getVarCount()) < 0;
107  }
108 };
109 
112  public:
113  ReverseLexComparator(size_t varCount = 0);
114 
115  static const char* staticGetName();
116 
117  private:
118  virtual bool doPredicate(const Exponent* a,
119  const Exponent* b) const {
120  return reverseLexCompare(a, b, getVarCount()) < 0;
121  }
122 };
123 
127  public:
128  SingleDegreeComparator(size_t var, size_t varCount = 0);
129 
130  private:
131  virtual bool doPredicate(const Exponent* a,
132  const Exponent* b) const {
133  return a[_var] < b[_var];
134  }
135 
136  size_t _var;
137 };
138 
142  public:
143  ReverseSingleDegreeComparator(size_t var, size_t varCount = 0);
144 
145  private:
146  virtual bool doPredicate(const Exponent* a,
147  const Exponent* b) const {
148  return a[_var] > b[_var];
149  }
150 
151  size_t _var;
152 };
153 
156  public:
157  EqualsPredicate(size_t varCount = 0);
158 
159  private:
160  virtual bool doPredicate(const Exponent* a,
161  const Exponent* b) const {
162  return equals(a, b, getVarCount());
163  }
164 };
165 
166 #endif
bool equals(const Exponent *a, const Exponent *b, size_t varCount)
Returns whether the entries of a are equal to the entries of b.
auto_ptr< TermPredicate > createTermPredicate(const string &prefix, size_t varCount=0)
Returns the predicate whose name has the given prefix.
int lexCompare(const Exponent *a, const Exponent *b, size_t varCount)
Indicates how a relates to b according to the lexicographic term order where .
int reverseLexCompare(const Exponent *a, const Exponent *b, size_t varCount)
Indicates how a relates to b according to the reverse lexicographic term order where .
A predicate that compares for equality.
EqualsPredicate(size_t varCount=0)
virtual bool doPredicate(const Exponent *a, const Exponent *b) const
A predicate that sorts terms according to lexicographic order.
Definition: TermPredicate.h:97
virtual bool doPredicate(const Exponent *a, const Exponent *b) const
static const char * staticGetName()
LexComparator(size_t varCount=0)
A predicate that sorts according to reverse lexicographic order.
virtual bool doPredicate(const Exponent *a, const Exponent *b) const
ReverseLexComparator(size_t varCount=0)
static const char * staticGetName()
A predicate that sorts terms in weakly descending order according to degree of the specified variable...
ReverseSingleDegreeComparator(size_t var, size_t varCount=0)
virtual bool doPredicate(const Exponent *a, const Exponent *b) const
A predicate that sorts terms in weakly ascending order according to degree of the specified variable.
SingleDegreeComparator(size_t var, size_t varCount=0)
virtual bool doPredicate(const Exponent *a, const Exponent *b) const
Adapter for TermPredicate which allows it to be used as a predicate in STL.
Definition: TermPredicate.h:64
StlTermPredicate(const TermPredicate &pred)
Definition: TermPredicate.h:66
bool operator()(const T &a, const T &b) const
Definition: TermPredicate.h:68
const TermPredicate & _pred
Definition: TermPredicate.h:70
size_t getVarCount() const
Definition: TermPredicate.h:53
virtual ~TermPredicate()
bool operator()(const Exponent *a, const Term &b) const
Definition: TermPredicate.h:41
TermPredicate(size_t varCount=0)
bool operator()(const Term &a, const Term &b) const
Definition: TermPredicate.h:29
bool operator()(const Term &a, const Exponent *b) const
Definition: TermPredicate.h:35
virtual bool doPredicate(const Exponent *a, const Exponent *b) const =0
bool operator()(const Exponent *a, const Exponent *b) const
Definition: TermPredicate.h:47
void setVarCount(size_t varCount)
Definition: TermPredicate.h:54
size_t _varCount
Definition: TermPredicate.h:59
Term represents a product of variables which does not include a coefficient.
Definition: Term.h:49
Exponent * begin()
Definition: Term.h:79
size_t getVarCount() const
Definition: Term.h:85
unsigned int Exponent
Definition: stdinc.h:89
#define ASSERT(X)
Definition: stdinc.h:86