AlVin  1.0
A C++ implementation of the Vinberg's algorithm for Q, Q( sqrt(d) ) and Q( cos(2 pi / 7) )
quadraticinteger_big.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_BIG_H
32 #define QUADRATICINTEGER_BIG_H
33 
34 #include "algebraicinteger.h"
35 #include "quadraticinteger.h"
36 
37 #include <cmath>
38 #include <vector>
39 #include <map>
40 #include <array>
41 #include <string>
42 #include <gmpxx.h>
43 
44 using namespace std;
45 
47 {
48  public:
49  mpz_class a;
50  mpz_class b;
51 
52  static int d;
53  static mpf_class sqrtd;
54  static bool bIsOneMod4;
55  static int iDiscriminant;
56 
57  static map< unsigned int, vector< unsigned int > > iPellMinimalSolution;
58  static map< unsigned int, vector< long int > > iFundamentalUnits;
59 
60  public:
62  QuadraticIntegerBig( const int& iVal );
63  QuadraticIntegerBig( const mpz_class& iVal );
66  QuadraticIntegerBig( const int& a, const int& b );
67  QuadraticIntegerBig( const mpz_class& a, const mpz_class& b );
68  virtual ~QuadraticIntegerBig();
69 
70  AlgebraicInteger* copy() const;
71  AlgebraicInteger* aiCopyToInteger( const int& n ) const;
72  virtual void set( const int& n );
73  virtual void set( AlgebraicInteger* ai );
74 
75  virtual void removeSquareFactors();
76 
77  virtual bool bIsInvertible() const;
78  virtual bool bIsSquareOfIvertible() const;
79 
80  virtual void gcd( const AlgebraicInteger* ai );
81  virtual bool bIsDivisbleBy( const AlgebraicInteger* ) const;
82  virtual void divideBy( const AlgebraicInteger *ai );
83  virtual bool divideByIfDivisible( const AlgebraicInteger* ai );
84  virtual void multiplyBy( const int& n );
85  virtual void multiplyBy( const AlgebraicInteger *ai );
86  virtual void add( const AlgebraicInteger *ai );
87  virtual void substract( const AlgebraicInteger *ai );
88  virtual void opp();
89 
90  virtual bool bIsLessThan( const int& n ) const;
91  virtual bool bIsLessThan( const long int& n ) const;
92  virtual bool bIsLessThan( const AlgebraicInteger& ai ) const;
93  virtual bool bIsLessOEThan( const AlgebraicInteger& ai ) const;
94  virtual bool bIsGreaterThan( const int& n ) const;
95  virtual bool bIsGreaterThan( const long int& n ) const;
96  virtual bool bIsGreaterOEThan( const int& n ) const;
97  virtual bool bIsEqualTo( const AlgebraicInteger& ai ) const;
98  virtual bool bIsEqualTo( const int& n ) const;
99 
100  ostream& print( ostream& ) const;
101  virtual string to_string( const string& strFormat = "generic", const bool& bProtect = false ) const;
102  virtual double to_double() const;
103  virtual string get_classname() const;
104 
105  mpz_class floor() const;
106 
107  public:
108  static bool bIsDAdmissible( const unsigned int& d );
109  static void set_d( const unsigned int& d );
110  static vector< QuadraticIntegerBig > qiFactorsRationalPrime( const unsigned int& iPrime, bool bWithMultiplicities = false );
111  static array< long int, 2 > iPellEquation( const unsigned int& iPrime );
112  static mpz_class iSQRT_quotient( const QuadraticIntegerBig &qiNum, const QuadraticIntegerBig &qiDen );
113  static mpz_class iSQRTsup_quotient( const QuadraticIntegerBig &qiNum, const QuadraticIntegerBig &qiDen );
114 
115  void conjugate();
116  mpz_class iNorm() const;
117  mpz_class iTrace() const;
118 
119  int iValuation( const QuadraticIntegerBig& qi );
120 
121  vector< QuadraticIntegerBig > qiPrimeFactors() const;
122  map< QuadraticIntegerBig, unsigned int > qiPrimeDecomposition() const;
123 
124  bool bIsAssociateTo( QuadraticIntegerBig qi2 );
125 
126  // --------------------------------------------
127  // Operators
128  QuadraticIntegerBig& operator=( const QuadraticIntegerBig& );
129  QuadraticIntegerBig& operator/=( QuadraticIntegerBig const &qi );
130  QuadraticIntegerBig& operator*=( QuadraticIntegerBig const &qi );
131 
132  QuadraticIntegerBig operator+( const QuadraticIntegerBig& ) const;
133  QuadraticIntegerBig operator*( const QuadraticIntegerBig& ) const;
134  QuadraticIntegerBig operator-( const QuadraticIntegerBig& ) const;
135  QuadraticIntegerBig operator-() const;
136 
137  bool operator==(const long int& ) const;
138  bool operator==(const QuadraticIntegerBig& ) const;
139  bool operator>(const QuadraticIntegerBig& ) const;
140 };
141 
142 bool operator<( const QuadraticIntegerBig& qi1, const QuadraticIntegerBig& qi2 );
143 
144 #endif // QUADRATICINTEGER_H
static mpf_class sqrtd
Square root of d.
Definition: quadraticinteger_big.h:53
static map< unsigned int, vector< unsigned int > > iPellMinimalSolution
Solutions for the Pell equations (used to compute the decompositions of rational prime numbers) ...
Definition: quadraticinteger_big.h:57
static map< unsigned int, vector< long int > > iFundamentalUnits
Fundamental units.
Definition: quadraticinteger_big.h:58
static bool bIsOneMod4
True if d is 1 mod 4, false otherwise.
Definition: quadraticinteger_big.h:54
Quadratic integers.
Definition: quadraticinteger.h:44
mpz_class a
First component of the quadratic integer (in the usual Z-basis)
Definition: quadraticinteger_big.h:49
Parent class for rational, quadratic and rc7 integers.
Definition: algebraicinteger.h:43
static int iDiscriminant
Discriminant of the quadratic field.
Definition: quadraticinteger_big.h:55
Quadratic integers with bigint components.
Definition: quadraticinteger_big.h:46
static int d
We work in Q[ sqrt d ].
Definition: quadraticinteger_big.h:52
mpz_class b
Second component of the quadratic integer (in the usual Z-basis)
Definition: quadraticinteger_big.h:50