Gröbner basis project
Codebase for research into Gröbner basis computation
polynomial_ring.cpp
1 #ifndef __POLYNOMIAL_RING_CPP_
2 #define __POLYNOMIAL_RING_CPP_
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 <cstring>
22 
23 #include "polynomial_ring.hpp"
24 
26  Prime_Field & field,
27  string * new_names
28 ) : F(field) {
29  n = num_vars;
30  names = nullptr;
31  if (new_names != nullptr)
32  set_names(new_names, n);
33 }
34 
36  if (names != nullptr)
37  delete [] names;
38 }
39 
40 bool Polynomial_Ring::set_names(string * new_names, NVAR_TYPE length) {
41  bool result = false;
42  if (new_names != nullptr) {
43  if (names == nullptr)
44  names = new string [n];
45  for (NVAR_TYPE i = 0; i < n; ++i) {
46  names[i] = new_names[i];
47  }
48  result = true;
49  }
50  return result;
51 }
52 
53 NVAR_TYPE Polynomial_Ring::number_of_variables() const { return n; }
54 
56  Indeterminate * result = (Indeterminate *)malloc(sizeof(Indeterminate) * n);
57  for (NVAR_TYPE i = 0; i < n; ++i)
58  result[i] = Indeterminate(*this, i);
59  return result;
60 }
61 
63 
64 const string Polynomial_Ring::name(NVAR_TYPE i) const {
65  static char my_name[2];
66  if (names == nullptr) {
67  my_name[0] = 'x';
68  my_name[1] = i + char(i);
69  return my_name;
70  } else
71  return names[i];
72 }
73 
74 #endif
Polynomial_Ring(NVAR_TYPE num_vars, Prime_Field &field, string *var_names=nullptr)
Initialize the ring for the given field and number of indeterminates.
virtual Prime_Field & ground_field() const
ground field
~Polynomial_Ring()
Deletes the names.
Prime_Field & F
the ring&#39;s ground field
virtual NVAR_TYPE number_of_variables() const
number of indeterminates (variables) in the ring
Information necessary for a field modulo a prime.
Definition: fields.hpp:49
bool set_names(string *new_names, NVAR_TYPE length)
sets the names of the indeterminates, if you do not want the default
virtual Indeterminate * indeterminates()
an array of the ring’s indeterminates; use only to biuld polynomials
virtual const string name(NVAR_TYPE i) const
name of the th indeterminate
Implementation of indeterminates, for easier building of polynomials.
string * names
optional names for the variables
NVAR_TYPE n
the number of indeterminates for every monomial in the ring