Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

r""" 

Congruence Subgroup `\Gamma(N)` 

""" 

from __future__ import absolute_import 

 

#***************************************************************************** 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 2 of the License, or 

# (at your option) any later version. 

# http://www.gnu.org/licenses/ 

#***************************************************************************** 

from six.moves import range 

 

from .congroup_generic import CongruenceSubgroup 

from sage.misc.all import prod 

from sage.rings.all import ZZ, Zmod, QQ 

from sage.rings.integer import GCD_list 

from sage.groups.matrix_gps.finitely_generated import MatrixGroup 

from sage.matrix.constructor import matrix 

from sage.modular.cusps import Cusp 

from sage.arith.all import gcd 

from sage.structure.richcmp import richcmp_method, richcmp 

 

from .congroup_sl2z import SL2Z 

 

_gamma_cache = {} 

def Gamma_constructor(N): 

r""" 

Return the congruence subgroup `\Gamma(N)`. 

 

EXAMPLES:: 

 

sage: Gamma(5) # indirect doctest 

Congruence Subgroup Gamma(5) 

sage: G = Gamma(23) 

sage: G is Gamma(23) 

True 

sage: TestSuite(G).run() 

 

Test global uniqueness:: 

 

sage: G = Gamma(17) 

sage: G is loads(dumps(G)) 

True 

sage: G2 = sage.modular.arithgroup.congroup_gamma.Gamma_class(17) 

sage: G == G2 

True 

sage: G is G2 

False 

""" 

if N == 1: return SL2Z 

try: 

return _gamma_cache[N] 

except KeyError: 

_gamma_cache[N] = Gamma_class(N) 

return _gamma_cache[N] 

 

 

@richcmp_method 

class Gamma_class(CongruenceSubgroup): 

r""" 

The principal congruence subgroup `\Gamma(N)`. 

""" 

def _repr_(self): 

""" 

Return the string representation of self. 

 

EXAMPLES:: 

 

sage: Gamma(133)._repr_() 

'Congruence Subgroup Gamma(133)' 

""" 

return "Congruence Subgroup Gamma(%s)"%self.level() 

 

def _latex_(self): 

r""" 

Return the \LaTeX representation of self. 

 

EXAMPLES:: 

 

sage: Gamma(20)._latex_() 

'\\Gamma(20)' 

sage: latex(Gamma(20)) 

\Gamma(20) 

""" 

return "\\Gamma(%s)"%self.level() 

 

def __reduce__(self): 

""" 

Used for pickling self. 

 

EXAMPLES:: 

 

sage: Gamma(5).__reduce__() 

(<function Gamma_constructor at ...>, (5,)) 

""" 

return Gamma_constructor, (self.level(),) 

 

def __richcmp__(self, other, op): 

r""" 

Compare self to other. 

 

EXAMPLES:: 

 

sage: Gamma(3) == SymmetricGroup(8) 

False 

sage: Gamma(3) == Gamma1(3) 

False 

sage: Gamma(5) < Gamma(6) 

True 

sage: Gamma(5) == Gamma(5) 

True 

sage: Gamma(3) == Gamma(3).as_permutation_group() 

True 

""" 

if is_Gamma(other): 

return richcmp(self.level(), other.level(), op) 

else: 

return NotImplemented 

 

def index(self): 

r""" 

Return the index of self in the full modular group. This is given by 

 

.. MATH:: 

 

\prod_{\substack{p \mid N \\ \text{$p$ prime}}}\left(p^{3e}-p^{3e-2}\right). 

 

EXAMPLES:: 

 

sage: [Gamma(n).index() for n in [1..19]] 

[1, 6, 24, 48, 120, 144, 336, 384, 648, 720, 1320, 1152, 2184, 2016, 2880, 3072, 4896, 3888, 6840] 

sage: Gamma(32041).index() 

32893086819240 

""" 

return prod([p**(3*e-2)*(p*p-1) for (p,e) in self.level().factor()]) 

 

def _contains_sl2(self, a,b,c,d): 

r""" 

EXAMPLES:: 

 

sage: G = Gamma(5) 

sage: [1, 0, -10, 1] in G 

True 

sage: 1 in G 

True 

sage: SL2Z([26, 5, 5, 1]) in G 

True 

sage: SL2Z([1, 1, 6, 7]) in G 

False 

""" 

N = self.level() 

# don't need to check d == 1 as this is automatic from det 

return ((a%N == 1) and (b%N == 0) and (c%N == 0)) 

 

def ncusps(self): 

r""" 

Return the number of cusps of this subgroup `\Gamma(N)`. 

 

EXAMPLES:: 

 

sage: [Gamma(n).ncusps() for n in [1..19]] 

[1, 3, 4, 6, 12, 12, 24, 24, 36, 36, 60, 48, 84, 72, 96, 96, 144, 108, 180] 

sage: Gamma(30030).ncusps() 

278691840 

sage: Gamma(2^30).ncusps() 

432345564227567616 

""" 

n = self.level() 

if n==1: 

return ZZ(1) 

if n==2: 

return ZZ(3) 

return prod([p**(2*e) - p**(2*e-2) for (p,e) in n.factor()])//2 

 

def nirregcusps(self): 

r""" 

Return the number of irregular cusps of self. For principal congruence subgroups this is always 0. 

 

EXAMPLES:: 

 

sage: Gamma(17).nirregcusps() 

0 

""" 

return 0 

 

def _find_cusps(self): 

r""" 

Calculate the reduced representatives of the equivalence classes of 

cusps for this group. Adapted from code by Ron Evans. 

 

EXAMPLES:: 

 

sage: Gamma(8).cusps() # indirect doctest 

[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] 

""" 

n = self.level() 

C = [QQ(x) for x in range(n)] 

 

n0=n//2 

n1=(n+1)//2 

 

for r in range(1, n1): 

if r > 1 and gcd(r,n)==1: 

C.append(ZZ(r)/ZZ(n)) 

if n0==n/2 and gcd(r,n0)==1: 

C.append(ZZ(r)/ZZ(n0)) 

 

for s in range(2,n1): 

for r in range(1, 1+n): 

if GCD_list([s,r,n])==1: 

# GCD_list is ~40x faster than gcd, since gcd wastes loads 

# of time initialising a Sequence type. 

u,v = _lift_pair(r,s,n) 

C.append(ZZ(u)/ZZ(v)) 

 

return [Cusp(x) for x in sorted(C)] + [Cusp(1,0)] 

 

def reduce_cusp(self, c): 

r""" 

Calculate the unique reduced representative of the equivalence of the 

cusp `c` modulo this group. The reduced representative of an 

equivalence class is the unique cusp in the class of the form `u/v` 

with `u, v \ge 0` coprime, `v` minimal, and `u` minimal for that `v`. 

 

EXAMPLES:: 

 

sage: Gamma(5).reduce_cusp(1/5) 

Infinity 

sage: Gamma(5).reduce_cusp(7/8) 

3/2 

sage: Gamma(6).reduce_cusp(4/3) 

2/3 

 

TESTS:: 

 

sage: G = Gamma(50); all([c == G.reduce_cusp(c) for c in G.cusps()]) 

True 

""" 

N = self.level() 

c = Cusp(c) 

u,v = c.numerator() % N, c.denominator() % N 

if (v > N//2) or (2*v == N and u > N//2): 

u,v = -u,-v 

u,v = _lift_pair(u,v,N) 

return Cusp(u,v) 

 

def are_equivalent(self, x, y, trans=False): 

r""" 

Check if the cusps `x` and `y` are equivalent under the action of this group. 

 

ALGORITHM: The cusps `u_1 / v_1` and `u_2 / v_2` are equivalent modulo 

`\Gamma(N)` if and only if `(u_1, v_1) = \pm (u_2, v_2) \bmod N`. 

 

EXAMPLES:: 

 

sage: Gamma(7).are_equivalent(Cusp(2/3), Cusp(5/4)) 

True 

""" 

if trans: 

return CongruenceSubgroup.are_equivalent(self, x,y,trans=trans) 

N = self.level() 

u1,v1 = (x.numerator() % N, x.denominator() % N) 

u2,v2 = (y.numerator(), y.denominator()) 

 

return ((u1,v1) == (u2 % N, v2 % N)) or ((u1,v1) == (-u2 % N, -v2 % N)) 

 

def nu3(self): 

r""" 

Return the number of elliptic points of order 3 for this arithmetic 

subgroup. Since this subgroup is `\Gamma(N)` for `N \ge 2`, there are 

no such points, so we return 0. 

 

EXAMPLES:: 

 

sage: Gamma(89).nu3() 

0 

""" 

return 0 

 

# We don't need to override nu2, since the default nu2 implementation knows 

# that nu2 = 0 for odd subgroups. 

 

def image_mod_n(self): 

r""" 

Return the image of this group modulo `N`, as a subgroup of `SL(2, \ZZ 

/ N\ZZ)`. This is just the trivial subgroup. 

 

EXAMPLES:: 

 

sage: Gamma(3).image_mod_n() 

Matrix group over Ring of integers modulo 3 with 1 generators ( 

[1 0] 

[0 1] 

) 

""" 

return MatrixGroup([matrix(Zmod(self.level()), 2, 2, 1)]) 

 

 

def is_Gamma(x): 

r""" 

Return True if x is a congruence subgroup of type Gamma. 

 

EXAMPLES:: 

 

sage: from sage.modular.arithgroup.all import is_Gamma 

sage: is_Gamma(Gamma0(13)) 

False 

sage: is_Gamma(Gamma(4)) 

True 

""" 

 

return isinstance(x, Gamma_class) 

 

def _lift_pair(U,V,N): 

r""" 

Utility function. Given integers ``U, V, N``, with `N \ge 1` and `{\rm 

gcd}(U, V, N) = 1`, return a pair `(u, v)` congruent to `(U, V) \bmod N`, 

such that `{\rm gcd}(u,v) = 1`, `u, v \ge 0`, `v` is as small as possible, 

and `u` is as small as possible for that `v`. 

 

*Warning*: As this function is for internal use, it does not do a 

preliminary sanity check on its input, for efficiency. It will recover 

reasonably gracefully if ``(U, V, N)`` are not coprime, but only after 

wasting quite a lot of cycles! 

 

EXAMPLES:: 

 

sage: from sage.modular.arithgroup.congroup_gamma import _lift_pair 

sage: _lift_pair(2,4,7) 

(9, 4) 

sage: _lift_pair(2,4,8) # don't do this 

Traceback (most recent call last): 

... 

ValueError: (U, V, N) must be coprime 

""" 

u = U % N 

v = V % N 

if v == 0: 

if u == 1: 

return (1,0) 

else: 

v = N 

while gcd(u, v) > 1: 

u = u+N 

if u > N*v: raise ValueError("(U, V, N) must be coprime") 

return (u, v)