TermPredicate.cpp
Go to the documentation of this file.
/* Frobby: Software for monomial ideal computations.
Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
Copyright (C) 2010 University of Aarhus
Contact Bjarke Hammersholt Roune for license information (www.broune.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
*/
#include "stdinc.h"
#include "TermPredicate.h"
#include "NameFactory.h"
TermPredicate::TermPredicate(size_t varCount):
_varCount(varCount) {
}
TermPredicate::~TermPredicate() {
}
namespace {
typedef NameFactory<TermPredicate> PredFactory;
PredFactory getPredFactory() {
PredFactory factory("Term ordering");
nameFactoryRegister<LexComparator>(factory);
nameFactoryRegister<ReverseLexComparator>(factory);
return factory;
}
}
unique_ptr<TermPredicate> createTermPredicate(const string& prefix, size_t varCount) {
unique_ptr<TermPredicate> pred = createWithPrefix(getPredFactory(), prefix);
ASSERT(pred.get() != 0);
pred->setVarCount(varCount);
return pred;
}
int lexCompare(const Exponent* a, const Exponent* b, size_t varCount) {
ASSERT(a != 0 || varCount == 0);
ASSERT(b != 0 || varCount == 0);
for (size_t var = 0; var < varCount; ++var) {
if (a[var] == b[var])
continue;
if (a[var] < b[var])
return -1;
else
return 1;
}
return 0;
}
int lexCompare(const Term& a, const Term& b) {
ASSERT(a.getVarCount() == b.getVarCount());
return lexCompare(a.begin(), b.begin(), a.getVarCount());
}
int reverseLexCompare(const Exponent* a, const Exponent* b, size_t varCount) {
ASSERT(a != 0 || varCount == 0);
ASSERT(b != 0 || varCount == 0);
return -lexCompare(a, b, varCount);
}
bool equals(const Exponent* a, const Exponent* b, size_t varCount) {
ASSERT(a != 0 || varCount == 0);
ASSERT(b != 0 || varCount == 0);
for (size_t var = 0; var < varCount; ++var)
if (a[var] != b[var])
return false;
return true;
}
LexComparator::LexComparator(size_t varCount):
TermPredicate(varCount) {
}
const char* LexComparator::staticGetName() {
return "lex";
}
ReverseLexComparator::ReverseLexComparator(size_t varCount):
TermPredicate(varCount) {
}
const char* ReverseLexComparator::staticGetName() {
return "revlex";
}
SingleDegreeComparator::SingleDegreeComparator(size_t var, size_t varCount):
TermPredicate(varCount),
_var(var) {
}
ReverseSingleDegreeComparator::ReverseSingleDegreeComparator(size_t var,
size_t varCount):
TermPredicate(varCount),
_var(var) {
}
EqualsPredicate::EqualsPredicate(size_t varCount):
TermPredicate(varCount) {
}
NameFactory.h
nameFactoryRegister
void nameFactoryRegister(NameFactory< AbstractProduct > &factory)
Registers the string returned by ConcreteProduct::getStaticName() to a function that default-construc...
Definition NameFactory.h:142
createWithPrefix
unique_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
equals
bool equals(const Exponent *a, const Exponent *b, size_t varCount)
Returns whether the entries of a are equal to the entries of b.
Definition TermPredicate.cpp:77
lexCompare
int lexCompare(const Exponent *a, const Exponent *b, size_t varCount)
Indicates how a relates to b according to the lexicographic term order where .
Definition TermPredicate.cpp:50
createTermPredicate
unique_ptr< TermPredicate > createTermPredicate(const string &prefix, size_t varCount)
Returns the predicate whose name has the given prefix.
Definition TermPredicate.cpp:43
reverseLexCompare
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 .
Definition TermPredicate.cpp:71
TermPredicate.h
EqualsPredicate::EqualsPredicate
EqualsPredicate(size_t varCount=0)
Definition TermPredicate.cpp:114
LexComparator::staticGetName
static const char * staticGetName()
Definition TermPredicate.cpp:91
LexComparator::LexComparator
LexComparator(size_t varCount=0)
Definition TermPredicate.cpp:87
NameFactory
A NameFactory takes a name and then creates an instance of a class that has been previously registere...
Definition NameFactory.h:33
ReverseLexComparator::ReverseLexComparator
ReverseLexComparator(size_t varCount=0)
Definition TermPredicate.cpp:95
ReverseLexComparator::staticGetName
static const char * staticGetName()
Definition TermPredicate.cpp:99
ReverseSingleDegreeComparator::_var
size_t _var
Definition TermPredicate.h:151
ReverseSingleDegreeComparator::ReverseSingleDegreeComparator
ReverseSingleDegreeComparator(size_t var, size_t varCount=0)
Definition TermPredicate.cpp:108
SingleDegreeComparator::SingleDegreeComparator
SingleDegreeComparator(size_t var, size_t varCount=0)
Definition TermPredicate.cpp:103
SingleDegreeComparator::_var
size_t _var
Definition TermPredicate.h:136
TermPredicate::~TermPredicate
virtual ~TermPredicate()
Definition TermPredicate.cpp:28
TermPredicate::TermPredicate
TermPredicate(size_t varCount=0)
Definition TermPredicate.cpp:24
TermPredicate::_varCount
size_t _varCount
Definition TermPredicate.h:59
Term
Term represents a product of variables which does not include a coefficient.
Definition Term.h:49
Term::begin
Exponent * begin()
Definition Term.h:79
Term::getVarCount
size_t getVarCount() const
Definition Term.h:85
stdinc.h
This header file includes common definitions and is included as the first line of code in every imple...
Exponent
unsigned int Exponent
Definition stdinc.h:89
ASSERT
#define ASSERT(X)
Definition stdinc.h:86