Gröbner basis project
Codebase for research into Gröbner basis computation
algorithm_buchberger_basic.hpp
1 #ifndef __ALGORITHM_BUCHBERGER_BASIC_HPP_
2 #define __ALGORITHM_BUCHBERGER_BASIC_HPP_
3 
4 /*****************************************************************************\
5 * This file is part of DynGB. *
6 * *
7 * DynGB is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * Foobar is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with DynGB. If not, see <http://www.gnu.org/licenses/>. *
19 \*****************************************************************************/
20 
21 #include <set>
22 #include <list>
23 #include <iostream>
24 #include <iterator>
25 
26 using std::list;
27 using std::cout; using std::endl;
28 using std::next;
29 using std::set;
30 using std::iterator; using std::forward_iterator_tag;
31 
32 #include "system_constants.hpp"
33 
34 #include "fields.hpp"
35 #include "monomial.hpp"
36 #include "polynomial.hpp"
37 #include "critical_pair.hpp"
38 #include "normal_strategy.hpp"
39 #include "polynomial_array.hpp"
40 #include "polynomial_geobucket.hpp"
41 #include "polynomial_linked_list.hpp"
42 #include "polynomial_double_buffered.hpp"
43 
44 #include "sugar_strategy.hpp"
45 #include "weighted_sugar_strategy.hpp"
46 
60 template <typename T>
61 bool no_triplet(const T *p, const list<T *>C) {
62  bool result = true;
63  for (T * c : C) {
64  const Monomial & u = c->lcm();
65  bool degrees_smaller = true;
66  for (NVAR_TYPE i = 0; degrees_smaller and i < u.num_vars(); ++i)
67  degrees_smaller = degrees_smaller and u.degree(i) <= p->lcm_degree(i);
68  result = result and !degrees_smaller;
69  if (not result) break;
70  }
71  return result;
72 }
73 
74 template bool no_triplet<Critical_Pair_Basic>(
75  const Critical_Pair_Basic *, const list<Critical_Pair_Basic *>
76 );
77 
86 bool lcm_alike(
87  const Monomial & t,
88  const Monomial & u,
89  const Critical_Pair_Basic * p
90 );
91 
100 list<Abstract_Polynomial *> reduce_basis(list<Abstract_Polynomial *>G);
101 
111 void gm_update(
112  list<Critical_Pair_Basic *> & P,
113  list<Abstract_Polynomial *> & G,
115  StrategyFlags strategy
116 );
117 
125 template <typename T>
126 void report_critical_pairs(const list<T *>P, bool verbose = false) {
127  cout << P.size() << " critical pairs remaining\n";
128  if (verbose)
129  for (T * p : P)
130  cout << '\t' << *p << endl;
131 }
132 
133 template void report_critical_pairs<Critical_Pair_Basic>(
134  const list<Critical_Pair_Basic *>, bool
135 );
136 
141 struct smaller_lm {
151  return f->leading_monomial() < g->leading_monomial();
152  }
153 };
154 
162 void check_correctness(list<Constant_Polynomial *>G, StrategyFlags strategy);
163 
169 void report_basis(
170  list<Abstract_Polynomial *> G,
171  bool verbose=false,
172  bool very_verbose=false
173 );
174 
179 void report_front_pair(Critical_Pair_Basic *p, StrategyFlags strategy);
180 
194 list<Constant_Polynomial *> buchberger(
195  const list<Abstract_Polynomial *> &F,
196  SPolyCreationFlags rep = SPolyCreationFlags::GEOBUCKETS,
197  StrategyFlags strategy = StrategyFlags::SUGAR_STRATEGY,
198  WT_TYPE * strategy_weights = nullptr
199 );
200 
211 template <typename T>
212 void sort_pairs_by_strategy(list<T *> & P) {
213  // identify lowest lcm
214  typename list<T *>::iterator minkey_i = P.begin();
215  const Pair_Strategy_Data * minkey_data = (*minkey_i)->pair_key();
216  for (typename list<T *>::iterator pi = next(minkey_i);
217  pi != P.end();
218  ++pi
219  )
220  {
221  const Pair_Strategy_Data * pairkey = (*pi)->pair_key();
222  if (*pairkey < *minkey_data) {
223  minkey_i = pi;
224  minkey_data = pairkey;
225  }
226  }
227  // move it to front
228  T * minkey = *minkey_i;
229  P.erase(minkey_i);
230  P.push_front(minkey);
231 }
232 
233 template void sort_pairs_by_strategy<Critical_Pair_Basic>(
234  list<Critical_Pair_Basic *> &
235 );
236 
237 #endif
The general class of a polynomial.
Definition: polynomial.hpp:101
bool operator()(Abstract_Polynomial *f, Abstract_Polynomial *g)
returns true iff f’s leading monomial is smaller than g’s
void sort_pairs_by_strategy(list< T *> &P)
Applies the strategy to find the “smallest” critical pair.
void gm_update(list< Critical_Pair_Basic *> &P, list< Abstract_Polynomial *> &G, Abstract_Polynomial *r, StrategyFlags strategy)
Implementation of Gebauer-Moeller algorithm. Based on description in Becker and Weispfenning (1993)...
list< Constant_Polynomial * > buchberger(const list< Abstract_Polynomial *> &F, SPolyCreationFlags rep=SPolyCreationFlags::GEOBUCKETS, StrategyFlags strategy=StrategyFlags::SUGAR_STRATEGY, WT_TYPE *strategy_weights=nullptr)
Implementation of Buchberger’s algorithm.
virtual Monomial & leading_monomial() const =0
leading monomial – call after sort_by_order()!
Structure for sorting critical pairs.
Definition: strategies.hpp:145
StrategyFlags
flag indicating which strategy to use for computation
Definition: strategies.hpp:34
list< Abstract_Polynomial * > reduce_basis(list< Abstract_Polynomial *>G)
Remove redundant polynomials from G.
SPolyCreationFlags
flag indicating which structure to use for an s-polynomial
bool lcm_alike(const Monomial &t, const Monomial &u, const Critical_Pair_Basic *p)
Checks if the lcm of t and u is like the lcm stored in p.
NVAR_TYPE num_vars() const
number of variables
Definition: monomial.hpp:130
Implementation of monomials.
Definition: monomial.hpp:69
void check_correctness(list< Constant_Polynomial *>G, StrategyFlags strategy)
checks that G is a Gröbner basis by verifying each s-polynomial reduces to zero
DEG_TYPE degree(NVAR_TYPE i) const
Degree of th variable.
Definition: monomial.cpp:183
Monomial lcm(const Monomial &u) const
Least common multiple: largest exponents.
Definition: monomial.cpp:365
bool no_triplet(const T *p, const list< T *>C)
Checks whether p is in danger of forming a Buchberger triple with some pair listed in C...
Controls the creation of s-polynomials.
void report_critical_pairs(const list< T *>P, bool verbose=false)
A brief report on the number of critical pairs. If verbose is true, also lists them.
used to sort polynomials by leading monomial