TermPredicate.h
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/.
*/
#ifndef TERM_ORDER_GUARD
#define TERM_ORDER_GUARD
#include "Term.h"
class TermPredicate {
public:
TermPredicate(size_t varCount = 0);
virtual ~TermPredicate();
bool operator()(const Term& a, const Term& b) const {
ASSERT(a.getVarCount() == getVarCount());
ASSERT(b.getVarCount() == getVarCount());
return doPredicate(a.begin(), b.begin());
}
bool operator()(const Term& a, const Exponent* b) const {
ASSERT(a.getVarCount() == getVarCount());
ASSERT(b != 0 || getVarCount() == 0);
return doPredicate(a.begin(), b);
}
bool operator()(const Exponent* a, const Term& b) const {
ASSERT(b.getVarCount() == getVarCount());
ASSERT(a != 0 || getVarCount() == 0);
return doPredicate(a, b.begin());
}
bool operator()(const Exponent* a, const Exponent* b) const {
ASSERT(a != 0 || getVarCount() == 0);
ASSERT(b != 0 || getVarCount() == 0);
return doPredicate(a, b);
}
size_t getVarCount() const {return _varCount;}
void setVarCount(size_t varCount) {_varCount = varCount;}
private:
virtual bool doPredicate(const Exponent* a, const Exponent* b) const = 0;
size_t _varCount;
};
class StlTermPredicate {
public:
StlTermPredicate(const TermPredicate& pred): _pred(pred) {}
template<class T>
bool operator()(const T& a, const T& b) const {return _pred(a, b);}
private:
const TermPredicate& _pred;
};
unique_ptr<TermPredicate> createTermPredicate(const string& prefix,
size_t varCount = 0);
int lexCompare(const Exponent* a, const Exponent* b, size_t varCount);
int lexCompare(const Term& a, const Term& b);
int reverseLexCompare(const Exponent* a, const Exponent* b, size_t varCount);
bool equals(const Exponent* a, const Exponent* b, size_t varCount);
class LexComparator : public TermPredicate {
public:
LexComparator(size_t varCount = 0);
static const char* staticGetName();
private:
virtual bool doPredicate(const Exponent* a,
const Exponent* b) const {
return lexCompare(a, b, getVarCount()) < 0;
}
};
class ReverseLexComparator : public TermPredicate {
public:
ReverseLexComparator(size_t varCount = 0);
static const char* staticGetName();
private:
virtual bool doPredicate(const Exponent* a,
const Exponent* b) const {
return reverseLexCompare(a, b, getVarCount()) < 0;
}
};
class SingleDegreeComparator : public TermPredicate {
public:
SingleDegreeComparator(size_t var, size_t varCount = 0);
private:
virtual bool doPredicate(const Exponent* a,
const Exponent* b) const {
return a[_var] < b[_var];
}
size_t _var;
};
class ReverseSingleDegreeComparator : public TermPredicate {
public:
ReverseSingleDegreeComparator(size_t var, size_t varCount = 0);
private:
virtual bool doPredicate(const Exponent* a,
const Exponent* b) const {
return a[_var] > b[_var];
}
size_t _var;
};
class EqualsPredicate : public TermPredicate {
public:
EqualsPredicate(size_t varCount = 0);
private:
virtual bool doPredicate(const Exponent* a,
const Exponent* b) const {
return equals(a, b, getVarCount());
}
};
#endif
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=0)
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
Term.h
EqualsPredicate::EqualsPredicate
EqualsPredicate(size_t varCount=0)
Definition TermPredicate.cpp:114
EqualsPredicate::doPredicate
virtual bool doPredicate(const Exponent *a, const Exponent *b) const
Definition TermPredicate.h:160
LexComparator::doPredicate
virtual bool doPredicate(const Exponent *a, const Exponent *b) const
Definition TermPredicate.h:104
LexComparator::staticGetName
static const char * staticGetName()
Definition TermPredicate.cpp:91
LexComparator::LexComparator
LexComparator(size_t varCount=0)
Definition TermPredicate.cpp:87
ReverseLexComparator::doPredicate
virtual bool doPredicate(const Exponent *a, const Exponent *b) const
Definition TermPredicate.h:118
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
ReverseSingleDegreeComparator::doPredicate
virtual bool doPredicate(const Exponent *a, const Exponent *b) const
Definition TermPredicate.h:146
SingleDegreeComparator::SingleDegreeComparator
SingleDegreeComparator(size_t var, size_t varCount=0)
Definition TermPredicate.cpp:103
SingleDegreeComparator::_var
size_t _var
Definition TermPredicate.h:136
SingleDegreeComparator::doPredicate
virtual bool doPredicate(const Exponent *a, const Exponent *b) const
Definition TermPredicate.h:131
StlTermPredicate::StlTermPredicate
StlTermPredicate(const TermPredicate &pred)
Definition TermPredicate.h:66
StlTermPredicate::operator()
bool operator()(const T &a, const T &b) const
Definition TermPredicate.h:68
StlTermPredicate::_pred
const TermPredicate & _pred
Definition TermPredicate.h:70
TermPredicate
Definition TermPredicate.h:24
TermPredicate::getVarCount
size_t getVarCount() const
Definition TermPredicate.h:53
TermPredicate::~TermPredicate
virtual ~TermPredicate()
Definition TermPredicate.cpp:28
TermPredicate::operator()
bool operator()(const Exponent *a, const Term &b) const
Definition TermPredicate.h:41
TermPredicate::TermPredicate
TermPredicate(size_t varCount=0)
Definition TermPredicate.cpp:24
TermPredicate::operator()
bool operator()(const Term &a, const Term &b) const
Definition TermPredicate.h:29
TermPredicate::operator()
bool operator()(const Term &a, const Exponent *b) const
Definition TermPredicate.h:35
TermPredicate::doPredicate
virtual bool doPredicate(const Exponent *a, const Exponent *b) const =0
TermPredicate::operator()
bool operator()(const Exponent *a, const Exponent *b) const
Definition TermPredicate.h:47
TermPredicate::setVarCount
void setVarCount(size_t varCount)
Definition TermPredicate.h:54
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
Exponent
unsigned int Exponent
Definition stdinc.h:89
ASSERT
#define ASSERT(X)
Definition stdinc.h:86