Frobby  0.9.5
TermPredicate.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  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 #include "stdinc.h"
20 #include "TermPredicate.h"
21 
22 #include "NameFactory.h"
23 
25  _varCount(varCount) {
26 }
27 
29 }
30 
31 namespace {
32  typedef NameFactory<TermPredicate> PredFactory;
33  PredFactory getPredFactory() {
34  PredFactory factory("Term ordering");
35 
36  nameFactoryRegister<LexComparator>(factory);
37  nameFactoryRegister<ReverseLexComparator>(factory);
38 
39  return factory;
40  }
41 }
42 
43 auto_ptr<TermPredicate> createTermPredicate(const string& prefix, size_t varCount) {
44  auto_ptr<TermPredicate> pred = createWithPrefix(getPredFactory(), prefix);
45  ASSERT(pred.get() != 0);
46  pred->setVarCount(varCount);
47  return pred;
48 }
49 
50 int lexCompare(const Exponent* a, const Exponent* b, size_t varCount) {
51  ASSERT(a != 0 || varCount == 0);
52  ASSERT(b != 0 || varCount == 0);
53 
54  for (size_t var = 0; var < varCount; ++var) {
55  if (a[var] == b[var])
56  continue;
57 
58  if (a[var] < b[var])
59  return -1;
60  else
61  return 1;
62  }
63  return 0;
64 }
65 
66 int lexCompare(const Term& a, const Term& b) {
67  ASSERT(a.getVarCount() == b.getVarCount());
68  return lexCompare(a.begin(), b.begin(), a.getVarCount());
69 }
70 
71 int reverseLexCompare(const Exponent* a, const Exponent* b, size_t varCount) {
72  ASSERT(a != 0 || varCount == 0);
73  ASSERT(b != 0 || varCount == 0);
74  return -lexCompare(a, b, varCount);
75 }
76 
77 bool equals(const Exponent* a, const Exponent* b, size_t varCount) {
78  ASSERT(a != 0 || varCount == 0);
79  ASSERT(b != 0 || varCount == 0);
80 
81  for (size_t var = 0; var < varCount; ++var)
82  if (a[var] != b[var])
83  return false;
84  return true;
85 }
86 
88  TermPredicate(varCount) {
89 }
90 
92  return "lex";
93 }
94 
96  TermPredicate(varCount) {
97 }
98 
100  return "revlex";
101 }
102 
104  TermPredicate(varCount),
105  _var(var) {
106 }
107 
109  size_t varCount):
110  TermPredicate(varCount),
111  _var(var) {
112 }
113 
115  TermPredicate(varCount) {
116 }
auto_ptr< AbstractProduct > createWithPrefix(const NameFactory< AbstractProduct > &factory, const string &prefix)
Creates the unique product that has the indicated prefix, or create the actual product that has name ...
Definition: NameFactory.h:154
bool equals(const Exponent *a, const Exponent *b, size_t varCount)
Returns whether the entries of a are equal to the entries of b.
int lexCompare(const Exponent *a, const Exponent *b, size_t varCount)
Indicates how a relates to b according to the lexicographic term order where .
auto_ptr< TermPredicate > createTermPredicate(const string &prefix, size_t varCount)
Returns the predicate whose name has the given prefix.
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 .
EqualsPredicate(size_t varCount=0)
static const char * staticGetName()
LexComparator(size_t varCount=0)
A NameFactory takes a name and then creates an instance of a class that has been previously registere...
Definition: NameFactory.h:33
ReverseLexComparator(size_t varCount=0)
static const char * staticGetName()
ReverseSingleDegreeComparator(size_t var, size_t varCount=0)
SingleDegreeComparator(size_t var, size_t varCount=0)
virtual ~TermPredicate()
TermPredicate(size_t varCount=0)
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