Frobby
0.10.0
Toggle main menu visibility
Loading...
Searching...
No Matches
src
TermPredicate.h
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
24
class
TermPredicate {
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
64
class
StlTermPredicate {
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
:
70
const
TermPredicate
& _pred;
71
};
72
74
unique_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
111
class
ReverseLexComparator :
public
TermPredicate {
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
126
class
SingleDegreeComparator :
public
TermPredicate {
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
141
class
ReverseSingleDegreeComparator :
public
TermPredicate {
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
155
class
EqualsPredicate :
public
TermPredicate {
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
TermPredicate
Definition
TermPredicate.h:24
Term
Definition
Term.h:49
Generated by
1.17.0