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

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

""" 

Elements of Arithmetic Subgroups 

""" 

  

################################################################################ 

# 

# Copyright (C) 2009, The Sage Group -- http://www.sagemath.org/ 

# 

# Distributed under the terms of the GNU General Public License (GPL) 

# 

# The full text of the GPL is available at: 

# 

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

# 

################################################################################ 

from __future__ import absolute_import 

  

from sage.structure.element cimport MultiplicativeGroupElement, MonoidElement, Element 

from sage.structure.richcmp cimport richcmp 

from sage.rings.all import ZZ 

from sage.modular.cusps import Cusp 

  

from sage.matrix.matrix_space import MatrixSpace 

from sage.matrix.matrix_integer_dense cimport Matrix_integer_dense 

  

M2Z = MatrixSpace(ZZ, 2) 

  

  

cdef class ArithmeticSubgroupElement(MultiplicativeGroupElement): 

r""" 

An element of the group `{\rm SL}_2(\ZZ)`, i.e. a 2x2 integer matrix of 

determinant 1. 

""" 

  

cdef Matrix_integer_dense __x 

  

def __init__(self, parent, x, check=True): 

""" 

Create an element of an arithmetic subgroup. 

  

INPUT: 

  

- ``parent`` -- an arithmetic subgroup 

  

- `x` -- data defining a 2x2 matrix over ZZ 

which lives in parent 

  

- ``check`` -- if True, check that parent is an arithmetic 

subgroup, and that `x` defines a matrix of 

determinant `1`. 

  

We tend not to create elements of arithmetic subgroups that aren't 

SL2Z, in order to avoid coercion issues (that is, the other arithmetic 

subgroups are "facade parents"). 

  

EXAMPLES:: 

  

sage: G = Gamma0(27) 

sage: sage.modular.arithgroup.arithgroup_element.ArithmeticSubgroupElement(G, [4,1,27,7]) 

[ 4 1] 

[27 7] 

sage: sage.modular.arithgroup.arithgroup_element.ArithmeticSubgroupElement(Integers(3), [4,1,27,7]) 

Traceback (most recent call last): 

... 

TypeError: parent (= Ring of integers modulo 3) must be an arithmetic subgroup 

sage: sage.modular.arithgroup.arithgroup_element.ArithmeticSubgroupElement(G, [2,0,0,2]) 

Traceback (most recent call last): 

... 

TypeError: matrix must have determinant 1 

sage: sage.modular.arithgroup.arithgroup_element.ArithmeticSubgroupElement(G, [2,0,0,2], check=False) 

[2 0] 

[0 2] 

sage: x = Gamma0(11)([2,1,11,6]) 

sage: TestSuite(x).run() 

  

sage: x = Gamma0(5).0 

sage: SL2Z(x) 

[1 1] 

[0 1] 

sage: x in SL2Z 

True 

""" 

if check: 

from .arithgroup_generic import is_ArithmeticSubgroup 

if not is_ArithmeticSubgroup(parent): 

raise TypeError("parent (= %s) must be an arithmetic subgroup"%parent) 

  

x = M2Z(x, copy=True, coerce=True) 

if x.determinant() != 1: 

raise TypeError("matrix must have determinant 1") 

else: 

x = M2Z(x, copy=True, coerce=False) 

# Getting rid of this would result in a small speed gain for 

# arithmetic operations, but it would have the disadvantage of 

# causing strange and opaque errors when inappropriate data types 

# are used with "check=False". 

  

x.set_immutable() 

MultiplicativeGroupElement.__init__(self, parent) 

self.__x = x 

  

def __setstate__(self, state): 

r""" 

For unpickling objects pickled with the old ArithmeticSubgroupElement class. 

  

EXAMPLES:: 

  

sage: si = unpickle_newobj(sage.modular.arithgroup.arithgroup_element.ArithmeticSubgroupElement, ()) 

sage: x = matrix(ZZ,2,[1,1,0,1]) 

sage: unpickle_build(si, (Gamma0(13), {'_ArithmeticSubgroupElement__x': x})) 

""" 

from .congroup_sl2z import SL2Z 

oldparent, kwdict = state 

self._parent = SL2Z 

if '_ArithmeticSubgroupElement__x' in kwdict: 

self.__x = M2Z(kwdict['_ArithmeticSubgroupElement__x']) 

elif '_CongruenceSubgroupElement__x' in kwdict: 

self.__x = M2Z(kwdict['_CongruenceSubgroupElement__x']) 

else: 

raise ValueError("Don't know how to unpickle %s" % repr(state)) 

  

def __iter__(self): 

""" 

EXAMPLES:: 

  

sage: Gamma0(2).0 

[1 1] 

[0 1] 

sage: list(Gamma0(2).0) 

[1, 1, 0, 1] 

  

Warning: this is different from the iteration on the matrix:: 

  

sage: list(Gamma0(2).0.matrix()) 

[(1, 1), (0, 1)] 

""" 

yield self.__x[0,0] 

yield self.__x[0,1] 

yield self.__x[1,0] 

yield self.__x[1,1] 

  

def __repr__(self): 

r""" 

Return the string representation of ``self``. 

  

EXAMPLES:: 

  

sage: Gamma1(5)([6,1,5,1]).__repr__() 

'[6 1]\n[5 1]' 

""" 

return "%s" % self.__x 

  

def _latex_(self): 

r""" 

Return latex representation of ``self``. 

  

EXAMPLES:: 

  

sage: Gamma1(5)([6,1,5,1])._latex_() 

'\\left(\\begin{array}{rr}\n6 & 1 \\\\\n5 & 1\n\\end{array}\\right)' 

""" 

return '%s' % self.__x._latex_() 

 

cpdef _richcmp_(self, right_r, int op): 

""" 

Compare self to right, where right is guaranteed to have the same 

parent as self. 

  

EXAMPLES:: 

  

sage: x = Gamma0(18)([19,1,18,1]) 

sage: x == 3 

False 

sage: x == x 

True 

  

sage: x = Gamma0(5)([1,1,0,1]) 

sage: y = Gamma0(5)([1,4,0,1]) 

sage: x == 0 

False 

sage: x == y 

False 

sage: x != y 

True 

  

This once caused a segfault (see :trac:`5443`):: 

  

sage: r,s,t,u,v = map(SL2Z, [[1, 1, 0, 1], [-1, 0, 0, -1], [1, -1, 0, 1], [1, -1, 2, -1], [-1, 1, -2, 1]]) 

sage: v == s*u 

True 

sage: s*u == v 

True 

""" 

cdef ArithmeticSubgroupElement right = <ArithmeticSubgroupElement>right_r 

return richcmp(self.__x, right.__x, op) 

  

def __nonzero__(self): 

""" 

Return True, since the self lives in SL(2,\Z), which does not 

contain the zero matrix. 

  

EXAMPLES:: 

  

sage: x = Gamma0(5)([1,1,0,1]) 

sage: x.__nonzero__() 

True 

""" 

return True 

  

cpdef _mul_(self, right): 

""" 

Return self * right. 

  

EXAMPLES:: 

  

sage: x = Gamma0(7)([1,0,7,1]) * Gamma0(7)([3,2,7,5]) ; x # indirect doctest 

[ 3 2] 

[28 19] 

sage: x.parent() 

Modular Group SL(2,Z) 

  

We check that :trac:`5048` is fixed:: 

  

sage: a = Gamma0(10).1 * Gamma0(5).2; a # random 

sage: a.parent() 

Modular Group SL(2,Z) 

  

""" 

return self.__class__(self.parent(), self.__x * (<ArithmeticSubgroupElement> right).__x, check=False) 

  

def __invert__(self): 

""" 

Return the inverse of self. 

  

EXAMPLES:: 

  

sage: Gamma0(11)([1,-1,0,1]).__invert__() 

[1 1] 

[0 1] 

""" 

return self._parent( 

[self.__x.get_unsafe(1,1), -self.__x.get_unsafe(0,1), 

-self.__x.get_unsafe(1,0), self.__x.get_unsafe(0,0)], 

check=False) 

  

def matrix(self): 

""" 

Return the matrix corresponding to self. 

  

EXAMPLES:: 

  

sage: x = Gamma1(3)([4,5,3,4]) ; x 

[4 5] 

[3 4] 

sage: x.matrix() 

[4 5] 

[3 4] 

sage: type(x.matrix()) 

<type 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'> 

""" 

return self.__x 

  

def determinant(self): 

""" 

Return the determinant of self, which is always 1. 

  

EXAMPLES:: 

  

sage: Gamma0(691)([1,0,691,1]).determinant() 

1 

""" 

return ZZ(1) 

  

def det(self): 

""" 

Return the determinant of self, which is always 1. 

  

EXAMPLES:: 

  

sage: Gamma1(11)([12,11,-11,-10]).det() 

1 

""" 

return self.determinant() 

  

def a(self): 

""" 

Return the upper left entry of self. 

  

EXAMPLES:: 

  

sage: Gamma0(13)([7,1,13,2]).a() 

7 

""" 

return self.__x.get_unsafe(0,0) 

  

def b(self): 

""" 

Return the upper right entry of self. 

  

EXAMPLES:: 

  

sage: Gamma0(13)([7,1,13,2]).b() 

1 

""" 

return self.__x.get_unsafe(0,1) 

  

def c(self): 

""" 

Return the lower left entry of self. 

  

EXAMPLES:: 

  

sage: Gamma0(13)([7,1,13,2]).c() 

13 

""" 

return self.__x.get_unsafe(1,0) 

  

def d(self): 

""" 

Return the lower right entry of self. 

  

EXAMPLES:: 

  

sage: Gamma0(13)([7,1,13,2]).d() 

2 

""" 

return self.__x.get_unsafe(1,1) 

  

def acton(self, z): 

""" 

Return the result of the action of self on z as a fractional linear 

transformation. 

  

EXAMPLES:: 

  

sage: G = Gamma0(15) 

sage: g = G([1, 2, 15, 31]) 

  

An example of g acting on a symbolic variable:: 

  

sage: z = var('z') 

sage: g.acton(z) 

(z + 2)/(15*z + 31) 

  

An example involving the Gaussian numbers:: 

  

sage: K.<i> = NumberField(x^2 + 1) 

sage: g.acton(i) 

1/1186*i + 77/1186 

  

An example with complex numbers:: 

  

sage: C.<i> = ComplexField() 

sage: g.acton(i) 

0.0649241146711636 + 0.000843170320404721*I 

  

An example with the cusp infinity:: 

  

sage: g.acton(infinity) 

1/15 

  

An example which maps a finite cusp to infinity:: 

  

sage: g.acton(-31/15) 

+Infinity 

  

Note that when acting on instances of cusps the return value 

is still a rational number or infinity (Note the presence of 

'+', which does not show up for cusp instances):: 

  

sage: g.acton(Cusp(-31/15)) 

+Infinity 

  

TESTS: 

  

We cover the remaining case, i.e., infinity mapped to infinity:: 

  

sage: G([1, 4, 0, 1]).acton(infinity) 

+Infinity 

  

""" 

from sage.rings.infinity import is_Infinite, infinity 

if is_Infinite(z): 

if self.c() != 0: 

return self.a() / self.c() 

else: 

return infinity 

if hasattr(z, 'denominator') and hasattr(z, 'numerator'): 

p = z.numerator() 

q = z.denominator() 

P = self.a()*p + self.b()*q 

Q = self.c()*p + self.d()*q 

if not Q and P: 

return infinity 

else: 

return P/Q 

return (self.a()*z + self.b())/(self.c()*z + self.d()) 

  

def __getitem__(self, q): 

r""" 

Fetch entries by direct indexing. 

  

EXAMPLES:: 

sage: SL2Z([3,2,1,1])[0,0] 

3 

""" 

return self.__x[q] 

  

def __hash__(self): 

r""" 

Return a hash value. 

  

EXAMPLES:: 

  

sage: hash(SL2Z.0) 

-8192788425652673914 # 64-bit 

-1995808122 # 32-bit 

""" 

return hash(self.__x) 

  

def __reduce__(self): 

r""" 

Used for pickling. 

  

EXAMPLES:: 

  

sage: (SL2Z.1).__reduce__() 

(Modular Group SL(2,Z), ( 

[1 1] 

[0 1] 

)) 

""" 

from .congroup_sl2z import SL2Z 

return SL2Z, (self.__x,) 

  

def multiplicative_order(self): 

r""" 

Return the multiplicative order of this element. 

  

EXAMPLES:: 

  

sage: SL2Z.one().multiplicative_order() 

1 

sage: SL2Z([-1,0,0,-1]).multiplicative_order() 

2 

sage: s,t = SL2Z.gens() 

sage: ((t^3*s*t^2) * s * ~(t^3*s*t^2)).multiplicative_order() 

4 

sage: (t^3 * s * t * t^-3).multiplicative_order() 

6 

sage: (t^3 * s * t * s * t^-2).multiplicative_order() 

3 

sage: SL2Z([2,1,1,1]).multiplicative_order() 

+Infinity 

sage: SL2Z([-2,1,1,-1]).multiplicative_order() 

+Infinity 

""" 

m = self.matrix() 

  

if m.is_one(): 

return ZZ(1) 

elif (-m).is_one(): 

return ZZ(2) 

  

t = m.trace() 

if t <= -2 or t >= 2: 

from sage.rings.infinity import infinity 

return infinity 

elif t == 0: 

return ZZ(4) 

elif t == 1: 

return ZZ(6) 

elif t == -1: 

return ZZ(3) 

  

raise RuntimeError