Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/modular/arithgroup/farey.hpp
4094 views
1
//
2
// farey.hpp
3
// FareySymbol
4
//
5
//****************************************************************************
6
// Copyright (C) 2011 Hartmut Monien <[email protected]>
7
//
8
// Distributed under the terms of the GNU General Public License (GPL)
9
//
10
// This code is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
// General Public License for more details.
14
//
15
// The full text of the GPL is available at:
16
//
17
// http://www.gnu.org/licenses/
18
//****************************************************************************
19
20
21
#ifndef FAREY_SYMBOL_HPP_
22
#define FAREY_SYMBOL_HPP_
23
24
#include <iostream>
25
#include <vector>
26
#include <string>
27
28
#include <Python.h>
29
#include <gmpxx.h>
30
#include "sl2z.hpp"
31
32
//--- pure virtual base class for helper class for membership test -----------
33
34
class is_element_group {
35
public:
36
virtual bool is_member(const SL2Z&) const = 0;
37
};
38
39
class is_element_Gamma0 : public is_element_group {
40
const int p;
41
public:
42
is_element_Gamma0(int p_) : p(p_) {
43
}
44
bool is_member(const SL2Z& V) const {
45
return (V.c() % p == 0);
46
}
47
};
48
49
class is_element_Gamma1 : public is_element_group {
50
const int p;
51
public:
52
is_element_Gamma1(int p_) : p(p_) {
53
}
54
bool is_member(const SL2Z& V) const {
55
return ((V.a()-1) % p == 0 &&
56
V.c() % p == 0 &&
57
(V.d()-1) % p == 0);
58
}
59
};
60
61
class is_element_Gamma : public is_element_group {
62
const int p;
63
public:
64
is_element_Gamma(int p_) : p(p_) {
65
}
66
bool is_member(const SL2Z& V) const {
67
return ((V.a()-1) % p == 0 &&
68
V.b() % p == 0 &&
69
V.c() % p == 0 &&
70
(V.d()-1) % p == 0);
71
}
72
};
73
74
class is_element_GammaH : public is_element_group {
75
const int p;
76
std::vector<long> H;
77
public:
78
is_element_GammaH(int p_, PyObject*);
79
~is_element_GammaH();
80
bool is_member(const SL2Z&) const;
81
};
82
83
class is_element_general : public is_element_group {
84
protected:
85
PyObject* group;
86
PyObject* method;
87
public:
88
is_element_general(PyObject*);
89
~is_element_general();
90
bool is_member(const SL2Z&) const;
91
};
92
93
class FareySymbol {
94
enum PAIRING { EVEN=-2, ODD=-3, NO=0, FREE=1 };
95
size_t pairing_max;
96
std::vector<int> pairing;
97
std::vector<int> cusp_classes;
98
std::vector<mpz_class> a, b;
99
std::vector<mpq_class> x;
100
std::vector<SL2Z> coset;
101
std::vector<SL2Z> generators;
102
std::vector<mpq_class> cusps;
103
std::vector<mpq_class> cusp_widths;
104
void add_term(const int, const mpq_class&);
105
void check_pair(const is_element_group*, const int);
106
size_t paired_side(const std::vector<int>& p, const size_t i) const;
107
SL2Z pairing_matrix(const std::vector<int>&, const size_t i) const;
108
void init_pairing(const is_element_group*);
109
std::vector<SL2Z> init_generators(const is_element_group*) const;
110
std::vector<SL2Z> init_coset_reps() const;
111
std::vector<int> init_cusp_classes() const;
112
std::vector<mpq_class> init_cusps() const;
113
std::vector<mpq_class> init_cusp_widths() const;
114
SL2Z pairing_matrix(const size_t) const;
115
size_t rank_pi() const;
116
public:
117
FareySymbol();
118
FareySymbol(PyObject*);
119
FareySymbol(PyObject*, const is_element_group*);
120
~FareySymbol();
121
const size_t size() const;
122
size_t nu2() const;
123
size_t nu3() const;
124
size_t index() const;
125
size_t number_of_cusps() const;
126
size_t level() const;
127
size_t genus() const;
128
friend std::ostream& operator<<(std::ostream&, const FareySymbol&);
129
friend std::istream& operator>>(std::istream&, FareySymbol&);
130
//--- communication with sage ---------------------------------------------
131
PyObject* get_cusps() const;
132
PyObject* get_fractions() const;
133
PyObject* get_cusp_widths() const;
134
PyObject* get_coset() const;
135
PyObject* get_generators() const;
136
PyObject* get_pairings() const;
137
PyObject* get_paired_sides() const;
138
PyObject* get_pairing_matrices() const;
139
void get_relations(const is_element_group* group) const;
140
PyObject* dumps() const;
141
};
142
143
#endif // FAREY_SYMBOL_HPP_
144
145