AlVin  1.0
A C++ implementation of the Vinberg's algorithm for Q, Q( sqrt(d) ) and Q( cos(2 pi / 7) )
rcyclotomic7integer.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 RCYCLOTOMI7CINTEGER_H
32 #define RCYCLOTOMI7CINTEGER_H
33 
34 #include <map>
35 #include <algorithm>
36 #include <pari/pari.h>
37 #include <gaol/gaol.h>
38 #include <gmpxx.h>
39 #include <string>
40 
41 #include "algebraicinteger.h"
43 
45 {
46  public:
47  array< mpz_class, 3 > iC;
48 
49  private:
50  static bool bClassInitialized;
51 
52  static vector< vector< int > > iPowersL;
53  static array< array< array<mpq_class, 2>, 3 >, 2 > mpqRationalApproximations;
54 
55  public:
57  RCyclotomic7Integer( const int& n );
58  RCyclotomic7Integer( const mpz_class& n );
59  RCyclotomic7Integer( const array< mpz_class, 3 >& iCoefficients );
61  virtual ~RCyclotomic7Integer();
62 
63  virtual void set(AlgebraicInteger* ai);
64  virtual void set(const int& n);
65  AlgebraicInteger* copy() const;
66  AlgebraicInteger* aiCopyToInteger( const int& n ) const;
67 
68  virtual void removeSquareFactors();
69 
70  virtual bool bIsSquareOfIvertible() const;
71  virtual bool bIsInvertible() const;
72  bool bIsAssociateTo( const AlgebraicInteger* ai );
73 
74  virtual void gcd(const AlgebraicInteger* ai);
75  virtual bool bIsDivisbleBy(const AlgebraicInteger* ai) const;
76  virtual void divideBy(const AlgebraicInteger* ai);
77  virtual bool divideByIfDivisible( const AlgebraicInteger* ai );
78  virtual void multiplyBy(const AlgebraicInteger* ai);
79  virtual void multiplyBy(const int& n);
80  virtual void opp();
81  virtual void substract(const AlgebraicInteger* ai);
82  virtual void add(const AlgebraicInteger* ai);
83 
84  virtual bool bIsEqualTo(const int& n) const;
85  virtual bool bIsEqualTo(const AlgebraicInteger& ai) const;
86  virtual bool bIsGreaterOEThan(const int& n) const;
87  virtual bool bIsGreaterThan(const int& n) const;
88  virtual bool bIsLessOEThan(const AlgebraicInteger& ai) const;
89  virtual bool bIsLessThan(const AlgebraicInteger& ai) const;
90  virtual bool bIsLessThan(const int& n) const;
91 
92  ostream& print( ostream& ) const;
93  virtual std::string get_classname() const;
94 
95  virtual std::string to_string( const string& strFormat = "generic", const bool& bProtect = false ) const;
96  virtual double to_double() const;
97  interval to_interval() const;
98 
99  long int floor() const;
100 
101  public:
102  static void initialize();
103  mpz_class iNorm() const;
104 
105  bool bIsLongInt() const;
106 
107  void conjugate( unsigned int i );
108 
109  vector< RCyclotomic7Integer > rciPrimeFactors() const;
110  map< RCyclotomic7Integer, unsigned int > rciPrimeDecomposition() const;
111 
112  static void initializePrimeDecomposition();
113  static bool computePrimeDecomposition( const unsigned int& iPrime );
114 
115  // --------------------------------------------
116  // Operators
117  RCyclotomic7Integer& operator=( const RCyclotomic7Integer& rci );
118  RCyclotomic7Integer& operator/=( RCyclotomic7Integer const &rci );
119  RCyclotomic7Integer& operator*=( RCyclotomic7Integer const &rci );
120 
121  RCyclotomic7Integer operator+( const RCyclotomic7Integer& ) const;
122  RCyclotomic7Integer operator*( const RCyclotomic7Integer& ) const;
123  RCyclotomic7Integer operator-( const RCyclotomic7Integer& ) const;
124  RCyclotomic7Integer operator-() const;
125 
126  bool operator>(const RCyclotomic7Integer& rci ) const;
127  bool operator==(const RCyclotomic7Integer& rci ) const;
128  bool operator==(const long int& ) const;
129 
130  private:
131  static void computePrimesDecomposition_factorMinimalPolynomial( GEN& gFactors, const unsigned int& iPrime );
132  static void computePrimesDecomposition_addFactor( const unsigned int& iPrime, const unsigned int& iFactorsCount, RCyclotomic7Integer rci );
133 };
134 
135 bool operator<( const RCyclotomic7Integer& rci1, const RCyclotomic7Integer& rci2 );
136 
137 inline interval gaol_intervalFromMPZclass( const mpz_class& i )
138 {
139  if( i.fits_slong_p() )
140  return interval( i.get_si() );
141  else
142  return interval( i.get_str().c_str() );
143 }
144 
145 inline interval gaol_SQRTQuotient( RCyclotomic7Integer rciNum, const RCyclotomic7Integer& rciDenom )
146 {
147  if( rciNum.divideByIfDivisible( &rciDenom ) )
148  {
149  if( rciNum.bIsLongInt() )
150  return sqrt( interval( -rciNum.iC[0].get_si() ) );
151  else
152  return sqrt( rciNum.to_interval() );
153  }
154  else
155  return sqrt( rciNum.to_interval() / rciDenom.to_interval() );
156 }
157 
158 #endif // RCYCLOTOMIC7INTEGER_H
virtual void opp()
Computes the opp.
Definition: rcyclotomic7integer.cpp:476
virtual bool bIsSquareOfIvertible() const
Check whether the number is the square of an invertible element.
Definition: rcyclotomic7integer.cpp:663
virtual bool bIsGreaterOEThan(const int &n) const
Check whether *this >= n.
Definition: rcyclotomic7integer.cpp:328
virtual void add(const AlgebraicInteger *ai)
Performs the addition of *this by the parameter.
Definition: rcyclotomic7integer.cpp:492
virtual bool bIsGreaterThan(const int &n) const
Check whether *this > n.
Definition: rcyclotomic7integer.cpp:344
virtual bool bIsEqualTo(const int &n) const
Check whether *this == n.
Definition: rcyclotomic7integer.cpp:318
virtual double to_double() const
Convert to double (approximation)
Definition: rcyclotomic7integer.cpp:241
virtual std::string get_classname() const
Return the type (string)
Definition: rcyclotomic7integer.cpp:839
virtual void removeSquareFactors()
Remove all the square factors of the algebraic integer.
Definition: rcyclotomic7integer.cpp:807
RC7 and their operations.
Definition: rcyclotomic7integer.h:44
ostream & print(ostream &) const
Print the number.
Definition: rcyclotomic7integer.cpp:303
AlgebraicInteger * aiCopyToInteger(const int &n) const
Create an algebraic integer from an integer.
Definition: rcyclotomic7integer.cpp:834
virtual void gcd(const AlgebraicInteger *ai)
*this becomes the gcd of *this and the parameter
Definition: rcyclotomic7integer.cpp:583
virtual bool bIsLessOEThan(const AlgebraicInteger &ai) const
Check whether *this <= ai.
Definition: rcyclotomic7integer.cpp:357
Parent class for rational, quadratic and rc7 integers.
Definition: algebraicinteger.h:43
virtual std::string to_string(const string &strFormat="generic", const bool &bProtect=false) const
Convert to string.
Definition: rcyclotomic7integer.cpp:216
virtual void multiplyBy(const AlgebraicInteger *ai)
Performs the multiplication of *this by the parameter.
Definition: rcyclotomic7integer.cpp:501
virtual void substract(const AlgebraicInteger *ai)
Substracts the parameter from *this.
Definition: rcyclotomic7integer.cpp:483
AlgebraicInteger * copy() const
Create a copy of an algebraic integer.
Definition: rcyclotomic7integer.cpp:829
virtual bool bIsInvertible() const
Check whether the number is invertible.
Definition: rcyclotomic7integer.cpp:677
array< mpz_class, 3 > iC
Decomposition in the basis lambda_1, ..., lambda_(iDegree)
Definition: rcyclotomic7integer.h:47
virtual bool bIsLessThan(const AlgebraicInteger &ai) const
Check whether *this < ai.
Definition: rcyclotomic7integer.cpp:414
virtual bool bIsDivisbleBy(const AlgebraicInteger *ai) const
Check whether *this is divisible by the parameter.
Definition: rcyclotomic7integer.cpp:571
virtual void divideBy(const AlgebraicInteger *ai)
Performs the division of *this by the parameter Remark: we do not check that the *this is divisible b...
Definition: rcyclotomic7integer.cpp:541
Some decompositions of rational primes into RC7.