Gröbner basis project
Codebase for research into Gröbner basis computation
test_cab_es4.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 [6] = {"B", "P", "S", "T", "W", "Z"} ;
49  Polynomial_Ring R(6, FF, X );
50  Prime_Field_Element a = FF.unity();
51  DEG_TYPE e0 [] { 0, 0, 0, 0, 0, 0 };
52  // set up our polynomials
53  // first poly
54  Monomial P { 0, 1, 0, 0, 0, 0 };
55  Monomial S { 0, 0, 1, 0, 0, 0 };
56  Monomial B { 1, 0, 0, 0, 0, 0 };
57  Monomial one { 0, 0, 0 ,0, 0, 0 };
58  Monomial M1 [] { P, S, B, one };
59  Prime_Field_Element C1 [] { a*45, a*35, -a*165, -a*36 };
60  Constant_Polynomial f1(4, R, M1, C1);
61  f1.sort_by_order();
62  // second poly
63  Monomial Z { 0, 0, 0, 0, 0, 1 } ;
64  Monomial T { 0, 0, 0, 1, 0, 0 };
65  Monomial M2 [] { P, Z, T, S };
66  Prime_Field_Element C2 [] { a*35, a*40, a*25, -a*27 };
67  Constant_Polynomial f2(4, R, M2, C2);
68  f2.sort_by_order();
69  // third poly
70  Monomial W { 0, 0, 0, 0, 1, 0 };
71  Monomial PS { 0, 1, 1, 0, 0, 0 };
72  Monomial B2 { 2, 0, 0, 0, 0, 0 };
73  Monomial M3 [] { W, PS, Z, T, B2 };
74  Prime_Field_Element C3 [] { a*15, a*25, a*30, -a*18, -a*165 };
75  Constant_Polynomial f3(5, R, M3, C3);
76  f3.sort_by_order();
77  // fourth poly
78  Monomial PT { 0, 1, 0, 1, 0, 0 };
79  Monomial ZS { 0, 0, 1, 0, 0, 1 };
80  Monomial M4 [] { W, PT, ZS };
81  Prime_Field_Element C4 [] { -a*9, a*15, a*20 };
82  Constant_Polynomial f4(3, R, M4, C4);
83  f4.sort_by_order();
84  // fifth poly
85  Monomial WP { 0, 1, 0, 0, 1, 0 };
86  Monomial ZT { 0, 0, 0, 1, 0, 1 };
87  Monomial B3 { 3, 0, 0, 0, 0, 0 };
88  Monomial M5 [] { WP, ZT, B3 };
89  Prime_Field_Element C5 [] { a, a*2, -a*11 };
90  Constant_Polynomial f5(3, R, M5, C5);
91  f5.sort_by_order();
92  // sixth poly
93  Monomial SB { 1, 0, 1, 0, 0, 0 };
94  Monomial M6 [] { W, SB, B2 };
95  Prime_Field_Element C6 [] { a*99, -a*11, a*3 };
96  Constant_Polynomial f6(3, R, M6, C6);
97  f6.sort_by_order();
98  // message
99  cout << "Computing a Groebner basis for\n\t" << f1
100  << ",\n\t" << f2
101  << ",\n\t" << f3
102  << ",\n\t" << f4
103  << ",\n\t" << f5
104  << ",\n\t" << f6
105  << endl;
106  // compute basis
107  list<Abstract_Polynomial *> F;
108  F.push_back(&f1); F.push_back(&f2); F.push_back(&f3);
109  F.push_back(&f4); F.push_back(&f5); F.push_back(&f6);
110  list<Constant_Polynomial *> G;
111  if (static_algorithm) G = buchberger(F, method, StrategyFlags::SUGAR_STRATEGY);
112  else G = buchberger_dynamic(
113  F, method, StrategyFlags::SUGAR_STRATEGY,
114  nullptr, DynamicHeuristic::ORD_HILBERT_THEN_DEG
115  );
116  cout << "Basis:\n";
117  for (Constant_Polynomial * g : G) {
118  cout << '\t';
119  g->leading_monomial().print(true, cout, R.name_list());
120  delete g;
121  }
122  cout << "bye\n";
123 }
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