Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/modular/arithgroup/congroup_gamma.py
8820 views
1
r"""
2
Congruence Subgroup `\Gamma(N)`
3
"""
4
5
################################################################################
6
#
7
# Copyright (C) 2009, The Sage Group -- http://www.sagemath.org/
8
#
9
# Distributed under the terms of the GNU General Public License (GPL)
10
#
11
# The full text of the GPL is available at:
12
#
13
# http://www.gnu.org/licenses/
14
#
15
################################################################################
16
17
from congroup_generic import CongruenceSubgroup
18
from sage.misc.misc import prod
19
from sage.rings.all import ZZ, Zmod, gcd, QQ
20
from sage.rings.integer import GCD_list
21
from sage.groups.matrix_gps.finitely_generated import MatrixGroup
22
from sage.matrix.constructor import matrix
23
from sage.modular.cusps import Cusp
24
25
from congroup_sl2z import SL2Z
26
27
_gamma_cache = {}
28
def Gamma_constructor(N):
29
r"""
30
Return the congruence subgroup `\Gamma(N)`.
31
32
EXAMPLES::
33
34
sage: Gamma(5) # indirect doctest
35
Congruence Subgroup Gamma(5)
36
sage: G = Gamma(23)
37
sage: G is Gamma(23)
38
True
39
sage: TestSuite(G).run()
40
41
Test global uniqueness::
42
43
sage: G = Gamma(17)
44
sage: G is loads(dumps(G))
45
True
46
sage: G2 = sage.modular.arithgroup.congroup_gamma.Gamma_class(17)
47
sage: G == G2
48
True
49
sage: G is G2
50
False
51
"""
52
if N == 1: return SL2Z
53
try:
54
return _gamma_cache[N]
55
except KeyError:
56
_gamma_cache[N] = Gamma_class(N)
57
return _gamma_cache[N]
58
59
class Gamma_class(CongruenceSubgroup):
60
r"""
61
The principal congruence subgroup `\Gamma(N)`.
62
"""
63
64
65
def _repr_(self):
66
"""
67
Return the string representation of self.
68
69
EXAMPLES::
70
71
sage: Gamma(133)._repr_()
72
'Congruence Subgroup Gamma(133)'
73
"""
74
return "Congruence Subgroup Gamma(%s)"%self.level()
75
76
def _latex_(self):
77
r"""
78
Return the \LaTeX representation of self.
79
80
EXAMPLES::
81
82
sage: Gamma(20)._latex_()
83
'\\Gamma(20)'
84
sage: latex(Gamma(20))
85
\Gamma(20)
86
"""
87
return "\\Gamma(%s)"%self.level()
88
89
def __reduce__(self):
90
"""
91
Used for pickling self.
92
93
EXAMPLES::
94
95
sage: Gamma(5).__reduce__()
96
(<function Gamma_constructor at ...>, (5,))
97
"""
98
return Gamma_constructor, (self.level(),)
99
100
def __cmp__(self, other):
101
r"""
102
Compare self to other.
103
104
EXAMPLES::
105
106
sage: Gamma(3) == SymmetricGroup(8)
107
False
108
sage: Gamma(3) == Gamma1(3)
109
False
110
sage: Gamma(5) < Gamma(6)
111
True
112
sage: Gamma(5) == Gamma(5)
113
True
114
sage: Gamma(3) == Gamma(3).as_permutation_group()
115
True
116
"""
117
if is_Gamma(other):
118
return cmp(self.level(), other.level())
119
else:
120
return CongruenceSubgroup.__cmp__(self, other)
121
122
def index(self):
123
r"""
124
Return the index of self in the full modular group. This is given by
125
126
.. math::
127
128
\prod_{\substack{p \mid N \\ \text{$p$ prime}}}\left(p^{3e}-p^{3e-2}\right).
129
130
EXAMPLE::
131
sage: [Gamma(n).index() for n in [1..19]]
132
[1, 6, 24, 48, 120, 144, 336, 384, 648, 720, 1320, 1152, 2184, 2016, 2880, 3072, 4896, 3888, 6840]
133
sage: Gamma(32041).index()
134
32893086819240
135
"""
136
return prod([p**(3*e-2)*(p*p-1) for (p,e) in self.level().factor()])
137
138
def _contains_sl2(self, a,b,c,d):
139
r"""
140
EXAMPLES::
141
142
sage: G = Gamma(5)
143
sage: [1, 0, -10, 1] in G
144
True
145
sage: 1 in G
146
True
147
sage: SL2Z([26, 5, 5, 1]) in G
148
True
149
sage: SL2Z([1, 1, 6, 7]) in G
150
False
151
"""
152
N = self.level()
153
# don't need to check d == 1 as this is automatic from det
154
return ((a%N == 1) and (b%N == 0) and (c%N == 0))
155
156
def ncusps(self):
157
r"""
158
Return the number of cusps of this subgroup `\Gamma(N)`.
159
160
EXAMPLES::
161
162
sage: [Gamma(n).ncusps() for n in [1..19]]
163
[1, 3, 4, 6, 12, 12, 24, 24, 36, 36, 60, 48, 84, 72, 96, 96, 144, 108, 180]
164
sage: Gamma(30030).ncusps()
165
278691840
166
sage: Gamma(2^30).ncusps()
167
432345564227567616
168
"""
169
n = self.level()
170
if n==1:
171
return ZZ(1)
172
if n==2:
173
return ZZ(3)
174
return prod([p**(2*e) - p**(2*e-2) for (p,e) in n.factor()])//2
175
176
def nirregcusps(self):
177
r"""
178
Return the number of irregular cusps of self. For principal congruence subgroups this is always 0.
179
180
EXAMPLE::
181
182
sage: Gamma(17).nirregcusps()
183
0
184
"""
185
return 0
186
187
def _find_cusps(self):
188
r"""
189
Calculate the reduced representatives of the equivalence classes of
190
cusps for this group. Adapted from code by Ron Evans.
191
192
EXAMPLE::
193
194
sage: Gamma(8).cusps() # indirect doctest
195
[0, 1/4, 1/3, 3/8, 1/2, 2/3, 3/4, 1, 4/3, 3/2, 5/3, 2, 7/3, 5/2, 8/3, 3, 7/2, 11/3, 4, 14/3, 5, 6, 7, Infinity]
196
"""
197
n = self.level()
198
C=[QQ(x) for x in xrange(n)]
199
200
n0=n//2
201
n1=(n+1)//2
202
203
for r in xrange(1, n1):
204
if r > 1 and gcd(r,n)==1:
205
C.append(ZZ(r)/ZZ(n))
206
if n0==n/2 and gcd(r,n0)==1:
207
C.append(ZZ(r)/ZZ(n0))
208
209
for s in xrange(2,n1):
210
for r in xrange(1, 1+n):
211
if GCD_list([s,r,n])==1:
212
# GCD_list is ~40x faster than gcd, since gcd wastes loads
213
# of time initialising a Sequence type.
214
u,v = _lift_pair(r,s,n)
215
C.append(ZZ(u)/ZZ(v))
216
217
return [Cusp(x) for x in sorted(C)] + [Cusp(1,0)]
218
219
def reduce_cusp(self, c):
220
r"""
221
Calculate the unique reduced representative of the equivalence of the
222
cusp `c` modulo this group. The reduced representative of an
223
equivalence class is the unique cusp in the class of the form `u/v`
224
with `u, v \ge 0` coprime, `v` minimal, and `u` minimal for that `v`.
225
226
EXAMPLES::
227
228
sage: Gamma(5).reduce_cusp(1/5)
229
Infinity
230
sage: Gamma(5).reduce_cusp(7/8)
231
3/2
232
sage: Gamma(6).reduce_cusp(4/3)
233
2/3
234
235
TESTS::
236
237
sage: G = Gamma(50); all([c == G.reduce_cusp(c) for c in G.cusps()])
238
True
239
"""
240
N = self.level()
241
c = Cusp(c)
242
u,v = c.numerator() % N, c.denominator() % N
243
if (v > N//2) or (2*v == N and u > N//2):
244
u,v = -u,-v
245
u,v = _lift_pair(u,v,N)
246
return Cusp(u,v)
247
248
def are_equivalent(self, x, y, trans=False):
249
r"""
250
Check if the cusps `x` and `y` are equivalent under the action of this group.
251
252
ALGORITHM: The cusps `u_1 / v_1` and `u_2 / v_2` are equivalent modulo
253
`\Gamma(N)` if and only if `(u_1, v_1) = \pm (u_2, v_2) \bmod N`.
254
255
EXAMPLE::
256
257
sage: Gamma(7).are_equivalent(Cusp(2/3), Cusp(5/4))
258
True
259
"""
260
if trans:
261
return CongruenceSubgroup.are_equivalent(self, x,y,trans=trans)
262
N = self.level()
263
u1,v1 = (x.numerator() % N, x.denominator() % N)
264
u2,v2 = (y.numerator(), y.denominator())
265
266
return ((u1,v1) == (u2 % N, v2 % N)) or ((u1,v1) == (-u2 % N, -v2 % N))
267
268
def nu3(self):
269
r"""
270
Return the number of elliptic points of order 3 for this arithmetic
271
subgroup. Since this subgroup is `\Gamma(N)` for `N \ge 2`, there are
272
no such points, so we return 0.
273
274
EXAMPLE::
275
276
sage: Gamma(89).nu3()
277
0
278
"""
279
return 0
280
281
# We don't need to override nu2, since the default nu2 implementation knows
282
# that nu2 = 0 for odd subgroups.
283
284
def image_mod_n(self):
285
r"""
286
Return the image of this group modulo `N`, as a subgroup of `SL(2, \ZZ
287
/ N\ZZ)`. This is just the trivial subgroup.
288
289
EXAMPLE::
290
291
sage: Gamma(3).image_mod_n()
292
Matrix group over Ring of integers modulo 3 with 1 generators (
293
[1 0]
294
[0 1]
295
)
296
"""
297
return MatrixGroup([matrix(Zmod(self.level()), 2, 2, 1)])
298
299
300
def is_Gamma(x):
301
r"""
302
Return True if x is a congruence subgroup of type Gamma.
303
304
EXAMPLES::
305
306
sage: from sage.modular.arithgroup.all import is_Gamma
307
sage: is_Gamma(Gamma0(13))
308
False
309
sage: is_Gamma(Gamma(4))
310
True
311
"""
312
313
return isinstance(x, Gamma_class)
314
315
def _lift_pair(U,V,N):
316
r"""
317
Utility function. Given integers ``U, V, N``, with `N \ge 1` and `{\rm
318
gcd}(U, V, N) = 1`, return a pair `(u, v)` congruent to `(U, V) \bmod N`,
319
such that `{\rm gcd}(u,v) = 1`, `u, v \ge 0`, `v` is as small as possible,
320
and `u` is as small as possible for that `v`.
321
322
*Warning*: As this function is for internal use, it does not do a
323
preliminary sanity check on its input, for efficiency. It will recover
324
reasonably gracefully if ``(U, V, N)`` are not coprime, but only after
325
wasting quite a lot of cycles!
326
327
EXAMPLE::
328
329
sage: from sage.modular.arithgroup.congroup_gamma import _lift_pair
330
sage: _lift_pair(2,4,7)
331
(9, 4)
332
sage: _lift_pair(2,4,8) # don't do this
333
Traceback (most recent call last):
334
...
335
ValueError: (U, V, N) must be coprime
336
"""
337
u = U % N
338
v = V % N
339
if v == 0:
340
if u == 1:
341
return (1,0)
342
else:
343
v = N
344
while gcd(u, v) > 1:
345
u = u+N
346
if u > N*v: raise ValueError, "(U, V, N) must be coprime"
347
return (u, v)
348
349