AlVin  1.0
A C++ implementation of the Vinberg's algorithm for Q, Q( sqrt(d) ) and Q( cos(2 pi / 7) )
quadraticinteger.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2014, 2015, 2016
3 Rafael Guglielmetti, rafael.guglielmetti@unifr.ch
4 */
5 
6 /*
7 This file is part of AlVin.
8 
9 CoxIter is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as
11 published by the Free Software Foundation, either version 3 of the
12 License, or (at your option) any later version.
13 
14 CoxIter is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with AlVin. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
31 #ifndef QUADRATICINTEGER_SMALL_H
32 #define QUADRATICINTEGER_SMALL_H
33 
34 #include "algebraicinteger.h"
35 
36 #include <cmath>
37 #include <vector>
38 #include <map>
39 #include <array>
40 #include <string>
41 
42 using namespace std;
43 
45 {
46  public:
47  long int a;
48  long int b;
49  static int d;
50  static bool bIsOneMod4;
51  static int iDiscriminant;
52 
53  static map< unsigned int, vector< unsigned int > > iPellMinimalSolution;
54  static map< unsigned int, vector< long int > > iFundamentalUnits;
55 
56  public:
58  QuadraticInteger( const int& iVal );
60  QuadraticInteger( int a, int b );
61  virtual ~QuadraticInteger();
62 
63  AlgebraicInteger* copy() const;
64  AlgebraicInteger* aiCopyToInteger( const int& n ) const;
65  virtual void set( const int& n );
66  virtual void set( AlgebraicInteger* ai );
67 
68  virtual void removeSquareFactors();
69 
70  virtual bool bIsInvertible() const;
71  virtual bool bIsSquareOfIvertible() const;
72 
73  virtual void gcd( const AlgebraicInteger* ai );
74  virtual bool bIsDivisbleBy( const AlgebraicInteger* ) const;
75  virtual void divideBy( const AlgebraicInteger *ai );
76  virtual bool divideByIfDivisible( const AlgebraicInteger* ai );
77  virtual void multiplyBy( const int& n );
78  virtual void multiplyBy( const AlgebraicInteger *ai );
79  virtual void add( const AlgebraicInteger *ai );
80  virtual void substract( const AlgebraicInteger *ai );
81  virtual void opp();
82 
83  virtual bool bIsLessThan( const int& n ) const;
84  virtual bool bIsLessThan( const long int& n ) const;
85  virtual bool bIsLessThan( const AlgebraicInteger& ai ) const;
86  virtual bool bIsLessOEThan( const AlgebraicInteger& ai ) const;
87  virtual bool bIsGreaterThan( const int& n ) const;
88  virtual bool bIsGreaterThan( const long int& n ) const;
89  virtual bool bIsGreaterOEThan( const int& n ) const;
90  virtual bool bIsEqualTo( const AlgebraicInteger& ai ) const;
91  virtual bool bIsEqualTo( const int& n ) const;
92 
93  ostream& print( ostream& ) const;
94  virtual string to_string( const string& strFormat = "generic", const bool& bProtect = false ) const;
95  virtual double to_double() const;
96  virtual string get_classname() const;
97 
98  long int floor() const;
99 
100  public:
101  static bool bIsDAdmissible( const unsigned int& d );
102  static void set_d( const unsigned int& d );
103  static vector< QuadraticInteger > qiFactorsRationalPrime( const unsigned int& iPrime, bool bWithMultiplicities = false );
104  static array< long int, 2 > iPellEquation( const unsigned int& iPrime );
105  static long int iSQRT_quotient( const QuadraticInteger &qiNum, const QuadraticInteger &qiDen );
106  static long int iSQRTsup_quotient( const QuadraticInteger &qiNum, const QuadraticInteger &qiDen );
107 
108  void conjugate();
109  long int iNorm() const;
110  long int iTrace() const;
111 
112  int iValuation( const QuadraticInteger& qi );
113 
114  vector< QuadraticInteger > qiPrimeFactors() const;
115  map< QuadraticInteger, unsigned int > qiPrimeDecomposition() const;
116 
117  bool bIsAssociateTo( QuadraticInteger qi2 );
118 
119  // --------------------------------------------
120  // Operators
121  QuadraticInteger& operator=( const QuadraticInteger& );
122  QuadraticInteger& operator/=( QuadraticInteger const &qi );
123  QuadraticInteger& operator*=( QuadraticInteger const &qi );
124 
125  QuadraticInteger operator+( const QuadraticInteger& ) const;
126  QuadraticInteger operator*( const QuadraticInteger& ) const;
127  QuadraticInteger operator-( const QuadraticInteger& ) const;
128  QuadraticInteger operator-() const;
129 
130  bool operator>(const QuadraticInteger& );
131 };
132 
133 bool operator<( const QuadraticInteger& qi1, const QuadraticInteger& qi2 );
134 
135 #endif // QUADRATICINTEGER_H
static bool bIsOneMod4
True if d is 1 mod 4, false otherwise.
Definition: quadraticinteger.h:50
Quadratic integers.
Definition: quadraticinteger.h:44
static int d
We work in Q[ sqrt d ].
Definition: quadraticinteger.h:49
Parent class for rational, quadratic and rc7 integers.
Definition: algebraicinteger.h:43
long int a
First component of the quadratic integer (in the usual Z-basis)
Definition: quadraticinteger.h:47
static map< unsigned int, vector< long int > > iFundamentalUnits
Fundamental units.
Definition: quadraticinteger.h:54
long int b
Second component of the quadratic integer (in the usual Z-basis)
Definition: quadraticinteger.h:48
static int iDiscriminant
Discriminant of the quadratic field.
Definition: quadraticinteger.h:51
static map< unsigned int, vector< unsigned int > > iPellMinimalSolution
Solutions for the Pell equations (used to compute the decompositions of rational prime numbers) ...
Definition: quadraticinteger.h:53