Gröbner basis project
Codebase for research into Gröbner basis computation
test_cab_es9.cpp
1 /*****************************************************************************\
2 * This file is part of DynGB. *
3 * *
4 * DynGB 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 * Foobar 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 DynGB. If not, see <http://www.gnu.org/licenses/>. *
16 \*****************************************************************************/
17 
18 #include <set>
19 #include <cstdlib>
20 #include <cstring>
21 #include <iostream>
22 
23 using std::set;
24 using std::cout; using std::endl;
25 
26 #include "system_constants.hpp"
27 
28 #include "fields.hpp"
29 #include "monomial.hpp"
30 #include "polynomial.hpp"
31 
32 #include "dynamic_engine.hpp"
33 
34 #include "algorithm_buchberger_basic.hpp"
35 #include "algorithm_buchberger_dynamic.hpp"
36 
37 int main(int argc, char *argv[]) {
38  if (argc != 3 or (strcmp(argv[2],"stat") and strcmp(argv[2],"dyn"))) {
39  cout << "need to know method (usually 2) and then if dynamic (stat or dyn)\n";
40  return 1;
41  }
42  // obtain method -- don't screw it up b/c we don't check it
43  SPolyCreationFlags method = (SPolyCreationFlags )atoi(argv[1]);
44  bool static_algorithm = true;
45  if (!strcmp(argv[2],"dyn")) static_algorithm = false;
46  // set up the field
47  Prime_Field FF = Prime_Field(32003);
48  string X [9] = { "t", "u", "v", "w", "x", "y", "z" } ;
49  Polynomial_Ring R(7, FF, X );
50  Prime_Field_Element a = FF.unity();
51  Monomial one { 0, 0, 0, 0, 0, 0, 0 };
52  // set up our polynomials
53  // first poly
54  Monomial x2y1z4 { 0, 0, 0, 0, 2, 1, 4 };
55  Monomial t1 { 1, 0, 0, 0, 0, 0, 0 };
56  Monomial M1 [] { x2y1z4, t1 };
57  Prime_Field_Element C1 [] { -a, a };
58  Constant_Polynomial f1(2, R, M1, C1);
59  f1.sort_by_order();
60  // second poly
61  Monomial x5y7 { 0, 0, 0, 0, 5, 7, 0 };
62  Monomial u1z2 { 0, 1, 0, 0, 0, 0, 2 };
63  Monomial M2 [] { x5y7, u1z2 };
64  Prime_Field_Element C2 [] { -a, a };
65  Constant_Polynomial f2(2, R, M2, C2);
66  f2.sort_by_order();
67  // third poly
68  Monomial v1x3z1 { 0, 0, 1, 0, 3, 0, 1 };
69  Monomial y2 { 0, 0, 0, 0, 0, 2, 0 };
70  Monomial M3 [] { v1x3z1, y2 };
71  Prime_Field_Element C3 [] { a, -a };
72  Constant_Polynomial f3(2, R, M3, C3);
73  f3.sort_by_order();
74  // fourth poly
75  Monomial w1z5 { 0, 0, 0, 1, 0, 0, 5 };
76  Monomial x1y3 { 0, 0, 0, 0, 1, 3, 0 };
77  Monomial M4 [] { w1z5, x1y3 };
78  Prime_Field_Element C4 [] { a, -a };
79  Constant_Polynomial f4(2, R, M4, C4);
80  f4.sort_by_order();
81  // message
82  cout << "Computing a Groebner basis for\n\t" << f1
83  << ",\n\t" << f2
84  << ",\n\t" << f3
85  << ",\n\t" << f4
86  << endl;
87  // compute basis
88  list<Abstract_Polynomial *> F;
89  F.push_back(&f1); F.push_back(&f2); F.push_back(&f3);
90  F.push_back(&f4);
91  list<Constant_Polynomial *> G;
92  if (static_algorithm) G = buchberger(F, method, StrategyFlags::SUGAR_STRATEGY);
93  else G = buchberger_dynamic(
94  F, method, StrategyFlags::SUGAR_STRATEGY, nullptr,
95  DynamicHeuristic::ORD_HILBERT_THEN_DEG
96  );
97  cout << "Basis:\n";
98  for (Constant_Polynomial * g : G) {
99  cout << '\t';
100  g->leading_monomial().print(true, cout, R.name_list());
101  delete g;
102  }
103  cout << "bye\n";
104 }
A Constant_Polynomial is a polynomial that should not change.
list< Constant_Polynomial * > buchberger(const list< Abstract_Polynomial *> &F, SPolyCreationFlags method, StrategyFlags strategy, WT_TYPE *strategy_weights)
Implementation of Buchberger’s algorithm.
Information necessary for a field modulo a prime.
Definition: fields.hpp:49
Prime_Field_Element unity()
“unity” is the multiplicative identity.
Definition: fields.cpp:188
SPolyCreationFlags
flag indicating which structure to use for an s-polynomial
Implementation of monomials.
Definition: monomial.hpp:69
Element of a field of prime characteristic.
Definition: fields.hpp:137
Encapsulates information about a polynomial ring for easy access: ground field, number of indetermina...
list< Constant_Polynomial * > buchberger_dynamic(const list< Abstract_Polynomial *> &F, SPolyCreationFlags method, StrategyFlags strategy, WT_TYPE *strategy_weights, DynamicHeuristic heuristic, DynamicSolver solver_type, bool analyze_inputs)
implementation of the dynamic Buchberger algorithm