Gröbner basis project
Codebase for research into Gröbner basis computation
cyclic_n.hpp
1 #ifndef __CYCLIC_N_HPP_
2 #define __CYCLIC_N_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 <iostream>
23 
24 using std::set;
25 using std::cout; using std::endl;
26 
27 #include "system_constants.hpp"
28 
29 #include "fields.hpp"
30 #include "monomial.hpp"
31 #include "polynomial.hpp"
32 #include "polynomial_ring.hpp"
33 #include "monomial_ordering.hpp"
34 #include "algorithm_buchberger_basic.hpp"
35 
36 extern Monomial_Ordering * generic_grevlex_ptr;
37 
57 list<Abstract_Polynomial *> cyclic_n(
58  NVAR_TYPE n, Prime_Field & F, bool homog,
59  Monomial_Ordering * mord = generic_grevlex_ptr
60 ) {
61  list <Abstract_Polynomial *> result;
62  // set up coefficients and monomials
63  Polynomial_Ring * R = (homog) ? new Polynomial_Ring(n+1, F)
64  : new Polynomial_Ring(n, F);
65  NVAR_TYPE max_n = (homog) ? n + 1 : n;
67  (Prime_Field_Element *)malloc(sizeof(Prime_Field_Element) * n);
68  Monomial * M = (Monomial *)calloc(n, sizeof(Monomial));
69  for (NVAR_TYPE i = 0; i < n; ++i) {
70  M[i].common_initialization();
71  M[i].initialize_exponents(max_n);
72  M[i].set_monomial_ordering(mord);
73  }
74  // ith polynomial for i = 1, ... n-1
75  for (NVAR_TYPE i = 0; i < n - 1; ++i) {
76  // jth monomial...
77  for (NVAR_TYPE j = 0; j < n; ++j)
78  {
79  A[j] = F.unity();
80  // clear exponents first...
81  for (NVAR_TYPE k = 0; k < max_n; ++k)
82  M[j].set_exponent(k,0);
83  // set relevant exponents to 1
84  for (NVAR_TYPE k = j; k < i + j + 1; ++k)
85  {
86  NVAR_TYPE l = (k >= n) ? k - n : k;
87  M[j].set_exponent(l, 1);
88  }
89  }
90  Constant_Polynomial * f = new Constant_Polynomial(n, *R, M, A);
91  f->sort_by_order();
92  result.push_back(f);
93  }
94  // last polynomial has a different structure so we can't run it in the loop
95  for (NVAR_TYPE i = 0; i < max_n; ++i) {
96  if (!homog or i < max_n - 1) {
97  M[0].set_exponent(i, 1);
98  M[1].set_exponent(i, 0);
99  }
100  else {
101  M[0].set_exponent(i, 0);
102  M[1].set_exponent(i, n);
103  }
104  }
105  M[0].set_monomial_ordering(mord);
106  M[0].set_monomial_ordering(mord);
107  A[0] = F.unity();
108  A[1] = -A[0];
109  result.push_back(new Constant_Polynomial(2, *R, M, A));
110  for (DEG_TYPE i = 0; i < n; ++i) M[i].deinitialize();
111  free(M);
112  free(A);
113  return result;
114 }
115 
116 #endif
A Constant_Polynomial is a polynomial that should not change.
Information necessary for a field modulo a prime.
Definition: fields.hpp:49
void set_monomial_ordering(const Monomial_Ordering *mord)
sets the Monomial_Ordering associated with this Monomial
Definition: monomial.cpp:211
Prime_Field_Element unity()
“unity” is the multiplicative identity.
Definition: fields.cpp:188
void set_exponent(NVAR_TYPE i, DEG_TYPE e)
change th exponent to
Definition: monomial.cpp:78
virtual void sort_by_order() override
sort by order
Implementation of monomials.
Definition: monomial.hpp:69
Element of a field of prime characteristic.
Definition: fields.hpp:137
interface to a monomial ordering
Encapsulates information about a polynomial ring for easy access: ground field, number of indetermina...
void initialize_exponents(NVAR_TYPE number_of_vars)
allocates memory for exponents This is useful when you want to allocate an array of monomials...
Definition: monomial.cpp:65
void common_initialization(const Monomial_Ordering *ord=nullptr)
things all Monomial initializers must do
Definition: monomial.hpp:74
list< Abstract_Polynomial * > cyclic_n(NVAR_TYPE n, Prime_Field &F, bool homog, Monomial_Ordering *mord=generic_grevlex_ptr)
generates the Cyclic- system
Definition: cyclic_n.hpp:57