Gröbner basis project
Codebase for research into Gröbner basis computation
test_cyclic4.cpp
1 #include <set>
2 #include <iostream>
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 using std::set;
22 using std::cout; using std::endl;
23 
24 #include "algorithm_buchberger_basic.hpp"
25 #include "fields.hpp"
26 #include "monomial.hpp"
27 #include "polynomial.hpp"
28 
29 int main(int argc, char *argv[]) {
30  // set up the field
31  Prime_Field F43 = Prime_Field(43);
32  Polynomial_Ring R(4, F43);
33  Prime_Field_Element a = F43.unity();
34  // set up our polynomials
35  // first poly: linear
36  unsigned e1 [] {1,0,0,0}; Monomial t1(4, e1);
37  unsigned e2 [] {0,1,0,0}; Monomial t2(4, e2);
38  unsigned e3 [] {0,0,1,0}; Monomial t3(4, e3);
39  unsigned e4 [] {0,0,0,1}; Monomial t4(4, e4);
40  Monomial M1 [] { t1, t2, t3, t4 };
41  Prime_Field_Element C1 [] { a, a, a, a };
42  Constant_Polynomial f1(4, R, M1, C1);
43  // second poly: quadratic
44  unsigned e5 [] {1,1,0,0}; Monomial t5(4, e5);
45  unsigned e6 [] {0,1,1,0}; Monomial t6(4, e6);
46  unsigned e7 [] {0,0,1,1}; Monomial t7(4, e7);
47  unsigned e8 [] {1,0,0,1}; Monomial t8(4, e8);
48  Monomial M2 [] { t5, t6, t7, t8 };
49  Prime_Field_Element C2 [] { a, a, a, a };
50  Constant_Polynomial f2(4, R, M2, C2);
51  f2.sort_by_order();
52  // third poly: cubic
53  unsigned e9 [] {1,1,1,0}; Monomial t9 (4, e9);
54  unsigned e10 [] {0,1,1,1}; Monomial t10(4, e10);
55  unsigned e11 [] {1,0,1,1}; Monomial t11(4, e11);
56  unsigned e12 [] {1,1,0,1}; Monomial t12(4, e12);
57  Monomial M3 [] { t9, t10, t11, t12 };
58  Prime_Field_Element C3 [] { a, a, a, a };
59  Constant_Polynomial f3(4, R, M3, C3);
60  f3.sort_by_order();
61  // fourth poly: quartic
62  unsigned e13 [] {1,1,1,1}; Monomial t13(4, e13);
63  Monomial t14(4);
64  Monomial M4 [] { t13, t14 };
65  Prime_Field_Element C4 [] { a, -a };
66  Constant_Polynomial f4(2, R, M4, C4);
67  f4.sort_by_order();
68  // message
69  cout << "Computing a Groebner basis for " << f1 << ", " << f2
70  << ", " << f3 << ", " << f4 << endl;
71  // compute basis
72  set<Abstract_Polynomial *> F;
73  F.insert(&f1); F.insert(&f2); F.insert(&f3); F.insert(&f4);
74  list<Constant_Polynomial *> G = buchberger(F);
75  cout << "Basis:\n";
76  for (list<Constant_Polynomial *>::iterator g = G.begin(); g != G.end(); ++g)
77  cout << '\t' << *(*g) << endl;
78  cout << "bye\n";
79 }
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
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...