30 #ifndef __POLYNOMIALS_H__
31 #define __POLYNOMIALS_H__
40 #ifdef _USE_LOCAL_GMP_
53 template <
typename Type>
56 unsigned int iSize(polynomial.size());
58 for (
unsigned int i(0); i < iSize; i++) {
59 if (polynomial[i] != 0) {
62 << (i ?
" * x" + string(i > 1 ?
"^" + to_string(i) :
"") :
"");
65 if ((polynomial[i] != 1 && polynomial[i] != -1) || !i)
66 cout << (polynomial[i] > 0 ?
" + " :
" - ") <<
abs(polynomial[i])
67 << (i ?
" * x" + string(i > 1 ?
"^" + to_string(i) :
"") :
"");
69 cout << (polynomial[i] > 0 ?
" + " :
" - ")
70 <<
"x" +
string(i > 1 ?
"^" + to_string(i) :
"");
80 template <
typename Type>
void symbolDisplay(
const vector<Type> &symbol) {
82 unsigned int iSize(symbol.size());
85 for (
unsigned int i(0); i < iSize; i++) {
87 for (
unsigned int j(0); j < symbol[i]; j++) {
88 cout << (isFirst ?
"" :
",") << i;
101 template <
typename Type>
103 vector<Type> polynomialBackup(polynomial);
104 unsigned int polynomialDegree(polynomial.size() - 1);
106 for (
unsigned int i(1); i < symbol - 1; i++)
107 polynomial.push_back(0);
109 polynomial.push_back(polynomial[polynomialDegree]);
111 if (polynomialDegree < symbol) {
112 for (
unsigned int i(1); i <= polynomialDegree; i++)
113 polynomial[i] = polynomial[i - 1] + polynomialBackup[i];
115 fill(polynomial.begin() + polynomialDegree + 1,
116 polynomial.end() - polynomialDegree, polynomial[polynomialDegree]);
118 for (
unsigned int i(1); i <= polynomialDegree;
120 polynomial[polynomialDegree + symbol - i - 1] =
121 polynomial[polynomialDegree + symbol - i] +
122 polynomialBackup[polynomialDegree - i];
124 for (
unsigned int i(1); i < symbol; i++)
125 polynomial[i] = polynomial[i - 1] + polynomialBackup[i];
127 for (
unsigned int i(symbol); i < polynomialDegree; i++)
128 polynomial[i] = polynomial[i - 1] - polynomialBackup[i - symbol] +
131 for (
unsigned int i(1); i < symbol && i <= polynomialDegree; i++)
132 polynomial[polynomialDegree + symbol - i - 1] =
133 polynomial[polynomialDegree + symbol - i] +
134 polynomialBackup[polynomialDegree - i];
138 template <
typename Type>
140 const unsigned int &symbol) {
141 unsigned int polynomialDegree(polynomial.size() - 1);
144 while (polynomial[polynomialDegree] == 0)
147 vector<Type> iWorking(polynomial.begin(),
148 polynomial.begin() + polynomialDegree + 1);
149 vector<Type> quotient;
154 if (polynomialDegree < symbol - 1)
157 while (polynomialDegree >= symbol) {
158 temp = iWorking[polynomialDegree];
159 quotient.insert(quotient.begin(), temp);
161 for (i = 0; i < symbol; i++)
162 iWorking[polynomialDegree - i] -= temp;
166 while (iWorking[polynomialDegree] == 0 && polynomialDegree >= 1) {
167 quotient.insert(quotient.begin(), 0);
172 if (polynomialDegree < symbol - 1) {
173 for (i = 0; i <= polynomialDegree; i++) {
174 if (iWorking[i] != 0)
179 temp = iWorking[polynomialDegree];
180 quotient.insert(quotient.begin(), temp);
182 for (i = 0; i < polynomialDegree; i++) {
183 if (iWorking[i] != temp)
187 polynomial = quotient;
200 template <
typename Type>
202 const vector<Type> &denominator) {
203 unsigned int numDeg(numerator.size() - 1), denomDeg(denominator.size() - 1);
205 if (numDeg < denomDeg || (denomDeg == 0 && denominator[0] != 0))
208 vector<Type> working(numerator), quotient;
213 while (numDeg >= denomDeg) {
214 if (working[numDeg] % denominator[denomDeg] != 0)
217 temp = working[numDeg] / denominator[denomDeg];
218 quotient.insert(quotient.begin(), temp);
220 for (i = 0; i <= denomDeg; i++)
221 working[numDeg - i] -= temp * denominator[denomDeg - i];
225 while (working[numDeg] == 0 && numDeg >= 1 && numDeg >= denomDeg) {
226 quotient.insert(quotient.begin(), 0);
231 for (i = 0; i <= numDeg; i++) {
236 numerator = quotient;
241 extern vector<vector<mpz_class>>
Definition: polynomials.cpp:25
void polynomialDotSymbol(vector< Type > &polynomial, const unsigned int &symbol)
Definition: polynomials.h:102
bool dividePolynomialBySymbol(vector< Type > &polynomial, const unsigned int &symbol)
Definition: polynomials.h:139
vector< vector< mpz_class > > cyclotomicPolynomials
Definition: polynomials.cpp:26
bool dividePolynomialByPolynomial(vector< Type > &numerator, const vector< Type > &denominator)
Definition: polynomials.h:201
void polynomialDisplay(const vector< Type > &polynomial)
Definition: polynomials.h:54
void symbolDisplay(const vector< Type > &symbol)
Definition: polynomials.h:80
T abs(const T &r)
Definition: rational.h:95