-
Notifications
You must be signed in to change notification settings - Fork 3
/
algebraicinteger.h
232 lines (188 loc) · 7.33 KB
/
algebraicinteger.h
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*
Copyright (C) 2014, 2015, 2016
Rafael Guglielmetti, [email protected]
*/
/*
This file is part of AlVin.
CoxIter 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 3 of the
License, or (at your option) any later version.
CoxIter 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 AlVin. If not, see <http://www.gnu.org/licenses/>.
*/
/*!
* \file algebraicinteger.h
* \author Rafael Guglielmetti
*
* \class AlgebraicInteger
* \brief Parent class for rational, quadratic and rc7 integers
*/
#ifndef ALGEBRAICINTEGER_H
#define ALGEBRAICINTEGER_H
#include <iostream>
#include <string>
#include <vector>
#include "CoxIter/lib/math_tools.h"
using namespace std;
using namespace MathTools;
class AlgebraicInteger {
public:
virtual ~AlgebraicInteger();
/*! \fn aiCopyToInteger
* \brief Create an algebraic integer from an integer
*
* \param n( const int ): Integer
* \return Pointer to the algebraic integer created
*/
virtual AlgebraicInteger *aiCopyToInteger(const int &n) const = 0;
/*! \fn copy
* \brief Create a copy of an algebraic integer
*
* \return Pointer to the algebraic integer created
*/
virtual AlgebraicInteger *copy() const = 0;
/*! \fn set( const int& n ) = 0
* \brief Assign an integer to the algebraic integer
* \param n( const int& ) Integer
*/
virtual void set(const int &n) = 0;
/*! \fn set( AlgebraicInteger* ai ) = 0
* \brief Assign an algebraic integer to the algebraic integer
* \param ai( AlgebraicInteger* ) Pointer to the algebraic integer
*/
virtual void set(AlgebraicInteger *ai) = 0;
/*! \fn removeSquareFactors()
* \brief Remove all the square factors of the algebraic integer
*/
virtual void removeSquareFactors() = 0;
/*! \fn isInvertible()
* \brief Check whether the number is invertible
* \return True if invertible or not
*/
virtual bool isInvertible() const = 0;
/*! \fn isSquareOfIvertible()
* \brief Check whether the number is the square of an invertible element
* \return True if invertible or not
*/
virtual bool isSquareOfIvertible() const = 0;
/*! \fn gcd( const AlgebraicInteger* ai )
* \brief *this becomes the gcd of *this and the parameter
* \param ai( const AlgebraicInteger* ) The other algebraic integer
*/
virtual void gcd(const AlgebraicInteger *ai) = 0;
/*! \fn isDivisibleBy( const AlgebraicInteger* ai )
* \brief Check whether *this is divisible by the parameter
* \param ai( const AlgebraicInteger* ) Pointer to the divisor
* \return True if *this is divisible by the parameter
*/
virtual bool isDivisibleBy(const AlgebraicInteger *ai) const = 0;
/*! \fn divideBy( const AlgebraicInteger* ai )
* \brief Performs the division of *this by the parameter
* Remark: we do not check that the *this is divisible by *ai. If it is not
* the case, the division will be an approximation! \param ai( const
* AlgebraicInteger* ) Pointer to the divisor
*/
virtual void divideBy(const AlgebraicInteger *ai) = 0;
/*! \fn multiplyBy( const int& n )
* \brief Performs the multiplication of *this by the parameter
* \param ai( const AlgebraicInteger* ) Pointer to the multiplicand
*/
virtual void multiplyBy(const int &n) = 0;
/*! \fn multiplyBy( const AlgebraicInteger* ai )
* \brief Performs the multiplication of *this by the parameter
* \param ai( const AlgebraicInteger* ) Pointer to the multiplicand
*/
virtual void multiplyBy(const AlgebraicInteger *ai) = 0;
/*! \fn add( const AlgebraicInteger* ai )
* \brief Performs the addition of *this by the parameter
* \param ai( const AlgebraicInteger* ) Pointer to the summand
*/
virtual void add(const AlgebraicInteger *ai) = 0;
/*! \fn substract( const AlgebraicInteger* ai ) = 0
* \brief Substracts the parameter from *this
* \param ai( const AlgebraicInteger* ) Pointer to the subtrahend
*/
virtual void substract(const AlgebraicInteger *ai) = 0;
/*! \fn opp( const AlgebraicInteger* ai )
* \brief Computes the opp
*/
virtual void opp() = 0;
/*! \fn bool isLessThan( const int& n ) const = 0
* \brief Check whether *this < n
*/
virtual bool isLessThan(const int &n) const = 0;
/*! \fn bool isLessThan( const AlgebraicInteger& ai )const = 0
* \brief Check whether *this < ai
*/
virtual bool isLessThan(const AlgebraicInteger &ai) const = 0;
/*! \fn isLessOEThan( const AlgebraicInteger& ai ) const = 0
* \brief Check whether *this <= ai
*/
virtual bool isLessOEThan(const AlgebraicInteger &ai) const = 0;
/*! \fn isGreaterThan( const int& n ) const = 0
* \brief Check whether *this > n
*/
virtual bool isGreaterThan(const int &n) const = 0;
/*! \fn isGreaterOEThan( const int& n ) const = 0
* \brief Check whether *this >= n
*/
virtual bool isGreaterOEThan(const int &n) const = 0;
/*! \fn isEqualTo( const AlgebraicInteger& n ) const = 0
* \brief Check whether *this == ai
*/
virtual bool isEqualTo(const AlgebraicInteger &ai) const = 0;
/*! \fn isEqualTo( const int& n ) const = 0
* \brief Check whether *this == n
*/
virtual bool isEqualTo(const int &n) const = 0;
/*! \fn operator==( const AlgebraicInteger& ai ) const
* \brief Check whether *this == ai
*/
bool operator==(const AlgebraicInteger &ai) const;
/*! \fn operator!=( const int& n ) const
* \brief Check whether *this != n
*/
bool operator!=(const int &n) const;
/*! \fn operator!=( const AlgebraicInteger& ai ) const
* \brief Check whether *this != ai
*/
bool operator!=(const AlgebraicInteger &ai) const;
friend ostream &operator<<(ostream &, AlgebraicInteger const &);
/*! \fn ostream& print( ostream& ) const
* \brief Print the number
*/
virtual ostream &print(ostream &) const;
/*! \fn string to_string( const string& strFormat = "generic", const bool&
* bProtect = false ) const = 0 \brief Convert to string \param strFormat(
* const string& ): Format for the output; can be: generic, mathematica, pari,
* latex \param bProtect( const bool& ): If true, avoid certain characters
* (for example if the string is used in for a file name)
*/
virtual string to_string(const string &strFormat = "generic",
const bool &bProtect = false) const = 0;
/*! \fn double to_double() const = 0
* \brief Convert to double (approximation)
*/
virtual double to_double() const = 0;
/*! \fn string get_classname() const = 0
* \brief Return the type (string)
*/
virtual string get_classname() const = 0;
private:
AlgebraicInteger &
operator=(AlgebraicInteger const &); ///< = is not defined ; use set
};
/*! \fn isLessThanPtrAlgebraicInteger( AlgebraicInteger* a,
* AlgebraicInteger* b ) \brief Check if *a < *b
*/
bool isLessThanPtrAlgebraicInteger(AlgebraicInteger *a, AlgebraicInteger *b);
/*! \fn isEqualToPtrAlgebraicInteger( AlgebraicInteger* a, AlgebraicInteger*
* b ) \brief Check if *a = *b
*/
bool isEqualToPtrAlgebraicInteger(AlgebraicInteger *a, AlgebraicInteger *b);
#endif // ALGEBRAICINTEGER_H