Frobby  0.9.5
IdealComparator.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 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see http://www.gnu.org/licenses/.
16 */
17 #include "stdinc.h"
18 #include "IdealComparator.h"
19 
20 #include "BigIdeal.h"
21 #include "Ideal.h"
22 #include "TermTranslator.h"
23 #include "TermPredicate.h"
24 #include "Term.h"
25 
28  _translator(translator) {
29 }
30 
32  template<class MyIdeal, class MyTermCompare>
33  bool idealLessThanImpl(const MyIdeal& a,
34  const MyIdeal& b,
35  const MyTermCompare& predicate) {
36  ASSERT(a.getVarCount() == b.getVarCount());
37 
38  for (size_t term = 0; term < a.getGeneratorCount(); ++term) {
39  if (term == b.getGeneratorCount())
40  return true;
41 
42  if (predicate(a[term], b[term]))
43  return true;
44  if (predicate(b[term], a[term]))
45  return false;
46  }
47  ASSERT(a.getGeneratorCount() <= b.getGeneratorCount());
48 
49  return false;
50  }
51 
52  bool idealLessThan(const BigIdeal& a, const BigIdeal& b) {
53  if (a.getNames() < b.getNames())
54  return true;
55  if (b.getNames() < a.getNames())
56  return false;
57 
59  }
60 
61  bool idealLessThan(const Ideal& a, const Ideal& b) {
62  ASSERT(a.getVarCount() == b.getVarCount());
63 
65  }
66 
67  bool idealLessThan(const Ideal& a, const Ideal& b,
68  TermTranslator& translator) {
69  ASSERT(a.getVarCount() == translator.getVarCount());
70  ASSERT(b.getVarCount() == translator.getVarCount());
71 
72  return idealLessThanImpl(a, b, TranslatedReverseLexComparator(translator));
73  }
74 }
static bool bigTermCompare(const vector< mpz_class > &a, const vector< mpz_class > &b)
Definition: BigIdeal.cpp:349
const VarNames & getNames() const
Definition: BigIdeal.cpp:253
Represents a monomial ideal with int exponents.
Definition: Ideal.h:27
size_t getVarCount() const
Definition: Ideal.h:56
A predicate that sorts according to reverse lexicographic order.
TermTranslator handles translation between terms whose exponents are infinite precision integers and ...
size_t getVarCount() const
TranslatedIdealComparator(TermTranslator &translator)
A predicate that sorts according to reverse lexicographic order on the translated values of a term.
bool idealLessThan(const BigIdeal &a, const BigIdeal &b)
bool idealLessThanImpl(const MyIdeal &a, const MyIdeal &b, const MyTermCompare &predicate)
#define ASSERT(X)
Definition: stdinc.h:86