-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolynomial_ring.cpp
More file actions
87 lines (75 loc) · 3.03 KB
/
Copy pathpolynomial_ring.cpp
File metadata and controls
87 lines (75 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef __POLYNOMIAL_RING_CPP_
#define __POLYNOMIAL_RING_CPP_
/*****************************************************************************\
* This file is part of DynGB. *
* *
* DynGB is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or *
* (at your option) any later version. *
* *
* DynGB is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with DynGB. If not, see <http://www.gnu.org/licenses/>. *
\*****************************************************************************/
#include <cstring>
#include "polynomial_ring.hpp"
Polynomial_Ring::Polynomial_Ring(NVAR_TYPE num_vars, Prime_Field &field,
string *new_names)
: F(field), n{num_vars} {
if (new_names != nullptr)
set_names(new_names, n);
else {
names.resize(n);
for (NVAR_TYPE i = 0; i < n; ++i) {
names[i] = "xi";
names[i][1] = '0' + i;
}
}
}
Polynomial_Ring::Polynomial_Ring(Prime_Field &field,
const vector<string> &new_names)
: F(field), n{static_cast<uint16_t>(new_names.size())}, names{new_names} {}
bool Polynomial_Ring::set_names(string *new_names, NVAR_TYPE length) {
bool result = false;
if (names.size() < length) {
names.resize(length);
}
names.resize(length);
for (NVAR_TYPE i = 0; i < n; ++i) {
names[i] = new_names[i];
}
return names.size() == length;
}
bool Polynomial_Ring::set_names(vector<string> new_names) {
cout << "setting names\n";
names.resize(new_names.size());
for (NVAR_TYPE i = 0; i < n; ++i) {
cout << "setting " << new_names[i] << endl;
names[i] = new_names[i];
}
return n == new_names.size();
}
NVAR_TYPE Polynomial_Ring::number_of_variables() const { return n; }
Indeterminate *Polynomial_Ring::indeterminates() {
Indeterminate *result =
static_cast<Indeterminate *>(malloc(sizeof(Indeterminate) * n));
for (NVAR_TYPE i = 0; i < n; ++i)
result[i] = Indeterminate(*this, i);
return result;
}
Prime_Field &Polynomial_Ring::ground_field() const { return F; }
const string Polynomial_Ring::name(NVAR_TYPE i) const {
if (names.size() == 0) {
char my_name[2];
my_name[0] = 'x';
my_name[1] = i + char(i);
return my_name;
} else
return names[i];
}
#endif