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

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

744

745

746

747

748

749

750

751

752

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768

769

770

771

772

773

774

775

776

777

778

779

780

781

782

783

784

785

786

787

788

789

790

791

792

793

794

795

796

797

798

799

800

801

802

803

804

805

806

807

808

809

810

811

812

813

814

815

816

817

818

819

820

821

822

823

824

825

826

827

828

829

830

831

832

833

834

835

836

837

838

839

840

841

842

843

844

845

846

847

848

849

850

851

852

853

854

855

856

857

858

859

860

861

862

863

864

865

866

867

868

869

870

871

872

873

874

875

876

877

878

879

880

881

882

883

884

885

886

887

888

889

890

891

892

893

894

895

896

897

898

899

900

901

902

903

904

905

906

907

908

909

910

911

912

913

914

915

916

917

918

919

920

921

922

923

924

925

926

927

928

929

930

931

932

933

934

935

936

937

938

939

940

941

942

943

944

945

946

947

948

949

950

951

952

953

954

955

956

957

958

959

960

961

962

963

964

965

966

967

968

969

970

971

972

973

974

975

976

977

978

979

980

981

982

983

984

985

986

987

988

989

990

991

992

993

994

995

996

997

998

999

1000

1001

1002

1003

1004

1005

1006

1007

1008

1009

1010

1011

1012

1013

1014

1015

1016

1017

1018

1019

1020

1021

1022

1023

1024

1025

1026

1027

1028

1029

1030

1031

1032

1033

1034

1035

1036

1037

1038

1039

1040

1041

1042

1043

1044

1045

1046

1047

1048

1049

1050

1051

1052

1053

1054

1055

1056

1057

1058

1059

1060

1061

1062

1063

1064

1065

1066

1067

1068

1069

1070

1071

1072

1073

1074

1075

1076

1077

1078

1079

1080

1081

1082

1083

1084

1085

1086

1087

1088

1089

1090

1091

1092

1093

1094

1095

1096

1097

1098

1099

1100

1101

1102

1103

1104

1105

1106

1107

1108

1109

1110

1111

1112

1113

1114

1115

1116

1117

1118

1119

1120

1121

1122

1123

1124

1125

1126

1127

1128

1129

1130

1131

1132

1133

1134

1135

1136

1137

1138

1139

# -*- coding: utf-8 -*- 

r""" 

The set `\mathbb{P}^1(\QQ)` of cusps 

 

EXAMPLES:: 

 

sage: Cusps 

Set P^1(QQ) of all cusps 

 

:: 

 

sage: Cusp(oo) 

Infinity 

""" 

 

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

# Copyright (C) 2005 William Stein <wstein@gmail.com> 

# 

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

# 

# This code is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 

# General Public License for more details. 

# 

# The full text of the GPL is available at: 

# 

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

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

from __future__ import print_function 

from six import integer_types 

 

from sage.rings.all import Rational, Integer, ZZ, QQ 

from sage.rings.infinity import is_Infinite, Infinity 

 

from sage.structure.parent_base import ParentWithBase 

from sage.structure.element import Element, is_InfinityElement 

from sage.structure.richcmp import richcmp 

 

from sage.modular.modsym.p1list import lift_to_sl2z_llong 

from sage.structure.element import is_Matrix 

from sage.misc.cachefunc import cached_method 

from sage.misc.superseded import deprecated_function_alias 

 

 

class Cusps_class(ParentWithBase): 

""" 

The set of cusps. 

 

EXAMPLES:: 

 

sage: C = Cusps; C 

Set P^1(QQ) of all cusps 

sage: loads(C.dumps()) == C 

True 

""" 

def __init__(self): 

r""" 

The set of cusps, i.e. `\mathbb{P}^1(\QQ)`. 

 

EXAMPLES:: 

 

sage: C = sage.modular.cusps.Cusps_class() ; C 

Set P^1(QQ) of all cusps 

sage: Cusps == C 

True 

""" 

ParentWithBase.__init__(self, self) 

 

def __eq__(self, right): 

""" 

Return equality only if ``right`` is the set of cusps. 

 

EXAMPLES:: 

 

sage: Cusps == Cusps 

True 

sage: Cusps == QQ 

False 

""" 

return isinstance(right, Cusps_class) 

 

def __ne__(self, right): 

""" 

Check that ``self`` is not equal to ``right``. 

 

EXAMPLES:: 

 

sage: Cusps != Cusps 

False 

sage: Cusps != QQ 

True 

""" 

return not (self == right) 

 

def _repr_(self): 

""" 

String representation of the set of cusps. 

 

EXAMPLES:: 

 

sage: Cusps 

Set P^1(QQ) of all cusps 

sage: Cusps._repr_() 

'Set P^1(QQ) of all cusps' 

sage: Cusps.rename('CUSPS'); Cusps 

CUSPS 

sage: Cusps.rename(); Cusps 

Set P^1(QQ) of all cusps 

sage: Cusps 

Set P^1(QQ) of all cusps 

""" 

return "Set P^1(QQ) of all cusps" 

 

def _latex_(self): 

""" 

Return latex representation of self. 

 

EXAMPLES:: 

 

sage: latex(Cusps) 

\mathbf{P}^1(\QQ) 

sage: latex(Cusps) == Cusps._latex_() 

True 

""" 

return "\\mathbf{P}^1(\\QQ)" 

 

def __call__(self, x): 

""" 

Coerce x into the set of cusps. 

 

EXAMPLES:: 

 

sage: a = Cusps(-4/5); a 

-4/5 

sage: Cusps(a) is a 

False 

sage: Cusps(1.5) 

3/2 

sage: Cusps(oo) 

Infinity 

sage: Cusps(I) 

Traceback (most recent call last): 

... 

TypeError: unable to convert I to a cusp 

""" 

return Cusp(x, parent=self) 

 

def _coerce_impl(self, x): 

""" 

Canonical coercion of x into the set of cusps. 

 

EXAMPLES:: 

 

sage: Cusps._coerce_(7/13) 

7/13 

sage: Cusps._coerce_(GF(7)(3)) 

Traceback (most recent call last): 

... 

TypeError: no canonical coercion of element into self 

sage: Cusps(GF(7)(3)) 

3 

sage: Cusps._coerce_impl(GF(7)(3)) 

Traceback (most recent call last): 

... 

TypeError: no canonical coercion of element into self 

""" 

if is_Infinite(x): 

return Cusp(x, parent=self) 

else: 

return self._coerce_try(x, QQ) 

 

@cached_method 

def zero(self): 

""" 

Return the zero cusp. 

 

.. NOTE:: 

 

The existence of this method is assumed by some 

parts of Sage's coercion model. 

 

EXAMPLES:: 

 

sage: Cusps.zero() 

0 

""" 

return Cusp(0, parent=self) 

 

zero_element = deprecated_function_alias(17694, zero) 

 

Cusps = Cusps_class() 

 

 

class Cusp(Element): 

""" 

A cusp. 

 

A cusp is either a rational number or infinity, i.e., an element of 

the projective line over Q. A Cusp is stored as a pair (a,b), where 

gcd(a,b)=1 and a,b are of type Integer. 

 

EXAMPLES:: 

 

sage: a = Cusp(2/3); b = Cusp(oo) 

sage: a.parent() 

Set P^1(QQ) of all cusps 

sage: a.parent() is b.parent() 

True 

""" 

def __init__(self, a, b=None, parent=None, check=True): 

r""" 

Create the cusp a/b in `\mathbb{P}^1(\QQ)`, where if b=0 

this is the cusp at infinity. 

 

When present, b must either be Infinity or coercible to an 

Integer. 

 

EXAMPLES:: 

 

sage: Cusp(2,3) 

2/3 

sage: Cusp(3,6) 

1/2 

sage: Cusp(1,0) 

Infinity 

sage: Cusp(infinity) 

Infinity 

sage: Cusp(5) 

5 

sage: Cusp(1/2) 

1/2 

sage: Cusp(1.5) 

3/2 

sage: Cusp(int(7)) 

7 

sage: Cusp(1, 2, check=False) 

1/2 

sage: Cusp('sage', 2.5, check=False) # don't do this! 

sage/2.50000000000000 

 

:: 

 

sage: I**2 

-1 

sage: Cusp(I) 

Traceback (most recent call last): 

... 

TypeError: unable to convert I to a cusp 

 

:: 

 

sage: a = Cusp(2,3) 

sage: loads(a.dumps()) == a 

True 

 

:: 

 

sage: Cusp(1/3,0) 

Infinity 

sage: Cusp((1,0)) 

Infinity 

 

TESTS:: 

 

sage: Cusp("1/3", 5) 

1/15 

sage: Cusp(Cusp(3/5), 7) 

3/35 

sage: Cusp(5/3, 0) 

Infinity 

sage: Cusp(3,oo) 

0 

sage: Cusp((7,3), 5) 

7/15 

sage: Cusp(int(5), 7) 

5/7 

 

:: 

 

sage: Cusp(0,0) 

Traceback (most recent call last): 

... 

TypeError: unable to convert (0, 0) to a cusp 

 

:: 

 

sage: Cusp(oo,oo) 

Traceback (most recent call last): 

... 

TypeError: unable to convert (+Infinity, +Infinity) to a cusp 

 

:: 

 

sage: Cusp(Cusp(oo),oo) 

Traceback (most recent call last): 

... 

TypeError: unable to convert (Infinity, +Infinity) to a cusp 

""" 

if parent is None: 

parent = Cusps 

Element.__init__(self, parent) 

 

if not check: 

self.__a = a 

self.__b = b 

return 

 

if b is None: 

if isinstance(a, Integer): 

self.__a = a 

self.__b = ZZ.one() 

elif isinstance(a, Rational): 

self.__a = a.numer() 

self.__b = a.denom() 

elif is_InfinityElement(a): 

self.__a = ZZ.one() 

self.__b = ZZ.zero() 

elif isinstance(a, Cusp): 

self.__a = a.__a 

self.__b = a.__b 

elif isinstance(a, integer_types): 

self.__a = ZZ(a) 

self.__b = ZZ.one() 

elif isinstance(a, (tuple, list)): 

if len(a) != 2: 

raise TypeError("unable to convert %r to a cusp" % a) 

if ZZ(a[1]) == 0: 

self.__a = ZZ.one() 

self.__b = ZZ.zero() 

return 

try: 

r = QQ((a[0], a[1])) 

self.__a = r.numer() 

self.__b = r.denom() 

except (ValueError, TypeError): 

raise TypeError("unable to convert %r to a cusp" % a) 

else: 

try: 

r = QQ(a) 

self.__a = r.numer() 

self.__b = r.denom() 

except (ValueError, TypeError): 

raise TypeError("unable to convert %r to a cusp" % a) 

return 

 

if is_InfinityElement(b): 

if is_InfinityElement(a) or (isinstance(a, Cusp) and a.is_infinity()): 

raise TypeError("unable to convert (%r, %r) to a cusp" % (a, b)) 

self.__a = ZZ.zero() 

self.__b = ZZ.one() 

return 

elif not b: 

if not a: 

raise TypeError("unable to convert (%r, %r) to a cusp" % (a, b)) 

self.__a = ZZ.one() 

self.__b = ZZ.zero() 

return 

 

if isinstance(a, Integer) or isinstance(a, Rational): 

r = a / ZZ(b) 

elif is_InfinityElement(a): 

self.__a = ZZ.one() 

self.__b = ZZ.zero() 

return 

elif isinstance(a, Cusp): 

if a.__b: 

r = a.__a / (a.__b * b) 

else: 

self.__a = ZZ.one() 

self.__b = ZZ.zero() 

return 

elif isinstance(a, integer_types): 

r = ZZ(a) / b 

elif isinstance(a, (tuple, list)): 

if len(a) != 2: 

raise TypeError("unable to convert (%r, %r) to a cusp" % (a, b)) 

r = ZZ(a[0]) / (ZZ(a[1]) * b) 

else: 

try: 

r = QQ(a) / b 

except (ValueError, TypeError): 

raise TypeError("unable to convert (%r, %r) to a cusp" % (a, b)) 

 

self.__a = r.numer() 

self.__b = r.denom() 

 

def __hash__(self): 

""" 

EXAMPLES:: 

 

sage: hash(Cusp(1/3)) 

1298787075 # 32-bit 

3713081631933328131 # 64-bit 

sage: hash(Cusp(oo)) 

1302034650 # 32-bit 

3713081631936575706 # 64-bit 

""" 

return hash((self.__a, self.__b)) 

 

def _richcmp_(self, right, op): 

""" 

Compare the cusps ``self`` and ``right``. 

 

Comparison is as for rational numbers, except with the cusp oo 

greater than everything but itself. 

 

The ordering in comparison is only really meaningful for infinity 

or elements that coerce to the rationals. 

 

EXAMPLES:: 

 

sage: Cusp(2/3) == Cusp(oo) 

False 

 

sage: Cusp(2/3) < Cusp(oo) 

True 

 

sage: Cusp(2/3)> Cusp(oo) 

False 

 

sage: Cusp(2/3) > Cusp(5/2) 

False 

 

sage: Cusp(2/3) < Cusp(5/2) 

True 

 

sage: Cusp(2/3) == Cusp(5/2) 

False 

 

sage: Cusp(oo) == Cusp(oo) 

True 

 

sage: 19/3 < Cusp(oo) 

True 

 

sage: Cusp(oo) < 19/3 

False 

 

sage: Cusp(2/3) < Cusp(11/7) 

True 

 

sage: Cusp(11/7) < Cusp(2/3) 

False 

 

sage: 2 < Cusp(3) 

True 

""" 

if not self.__b: 

s = Infinity 

else: 

s = self._rational_() 

if not right.__b: 

o = Infinity 

else: 

o = right._rational_() 

return richcmp(s, o, op) 

 

def is_infinity(self): 

""" 

Returns True if this is the cusp infinity. 

 

EXAMPLES:: 

 

sage: Cusp(3/5).is_infinity() 

False 

sage: Cusp(1,0).is_infinity() 

True 

sage: Cusp(0,1).is_infinity() 

False 

""" 

return not self.__b 

 

def numerator(self): 

""" 

Return the numerator of the cusp a/b. 

 

EXAMPLES:: 

 

sage: x=Cusp(6,9); x 

2/3 

sage: x.numerator() 

2 

sage: Cusp(oo).numerator() 

1 

sage: Cusp(-5/10).numerator() 

-1 

""" 

return self.__a 

 

def denominator(self): 

""" 

Return the denominator of the cusp a/b. 

 

EXAMPLES:: 

 

sage: x=Cusp(6,9); x 

2/3 

sage: x.denominator() 

3 

sage: Cusp(oo).denominator() 

0 

sage: Cusp(-5/10).denominator() 

2 

""" 

return self.__b 

 

def _rational_(self): 

""" 

Coerce to a rational number. 

 

EXAMPLES:: 

 

sage: QQ(Cusp(oo)) 

Traceback (most recent call last): 

... 

TypeError: cusp Infinity is not a rational number 

sage: QQ(Cusp(-3,7)) 

-3/7 

sage: Cusp(11,2)._rational_() 

11/2 

""" 

try: 

return self.__rational 

except AttributeError: 

pass 

 

if not self.__b: 

raise TypeError("cusp %s is not a rational number"%self) 

self.__rational = self.__a / self.__b 

return self.__rational 

 

def _integer_(self, ZZ=None): 

""" 

Coerce to an integer. 

 

EXAMPLES:: 

 

sage: ZZ(Cusp(-19)) 

-19 

sage: Cusp(4,2)._integer_() 

2 

 

:: 

 

sage: ZZ(Cusp(oo)) 

Traceback (most recent call last): 

... 

TypeError: cusp Infinity is not an integer 

sage: ZZ(Cusp(-3,7)) 

Traceback (most recent call last): 

... 

TypeError: cusp -3/7 is not an integer 

""" 

if self.__b != 1: 

raise TypeError("cusp %s is not an integer"%self) 

return self.__a 

 

def _repr_(self): 

""" 

String representation of this cusp. 

 

EXAMPLES:: 

 

sage: a = Cusp(2/3); a 

2/3 

sage: a._repr_() 

'2/3' 

sage: a.rename('2/3(cusp)'); a 

2/3(cusp) 

""" 

if self.__b.is_zero(): 

return "Infinity" 

if self.__b != 1: 

return "%s/%s" % (self.__a,self.__b) 

else: 

return str(self.__a) 

 

def _latex_(self): 

r""" 

Latex representation of this cusp. 

 

EXAMPLES:: 

 

sage: latex(Cusp(-2/7)) 

\frac{-2}{7} 

sage: latex(Cusp(oo)) 

\infty 

sage: latex(Cusp(oo)) == Cusp(oo)._latex_() 

True 

""" 

if self.__b.is_zero(): 

return "\\infty" 

if self.__b != 1: 

return "\\frac{%s}{%s}" % (self.__a,self.__b) 

else: 

return str(self.__a) 

 

def __neg__(self): 

""" 

The negative of this cusp. 

 

EXAMPLES:: 

 

sage: -Cusp(2/7) 

-2/7 

sage: -Cusp(oo) 

Infinity 

""" 

return Cusp(-self.__a, self.__b) 

 

def is_gamma0_equiv(self, other, N, transformation = None): 

r""" 

Return whether self and other are equivalent modulo the action of 

`\Gamma_0(N)` via linear fractional transformations. 

 

INPUT: 

 

 

- ``other`` - Cusp 

 

- ``N`` - an integer (specifies the group 

Gamma_0(N)) 

 

- ``transformation`` - None (default) or either the string 'matrix' or 'corner'. If 'matrix', 

it also returns a matrix in Gamma_0(N) that sends self to other. The matrix is chosen such that the lower left entry is as small as possible in absolute value. If 'corner' (or True for backwards compatibility), it returns only the upper left entry of such a matrix. 

 

 

OUTPUT: 

 

 

- a boolean - True if self and other are equivalent 

 

- a matrix or an integer- returned only if transformation is 'matrix' or 'corner', respectively. 

 

 

EXAMPLES:: 

 

sage: x = Cusp(2,3) 

sage: y = Cusp(4,5) 

sage: x.is_gamma0_equiv(y, 2) 

True 

sage: _, ga = x.is_gamma0_equiv(y, 2, 'matrix'); ga 

[-1 2] 

[-2 3] 

sage: x.is_gamma0_equiv(y, 3) 

False 

sage: x.is_gamma0_equiv(y, 3, 'matrix') 

(False, None) 

sage: Cusp(1/2).is_gamma0_equiv(1/3,11,'corner') 

(True, 19) 

 

sage: Cusp(1,0) 

Infinity 

sage: z = Cusp(1,0) 

sage: x.is_gamma0_equiv(z, 3, 'matrix') 

( 

[-1 1] 

True, [-3 2] 

) 

 

 

ALGORITHM: See Proposition 2.2.3 of Cremona's book 'Algorithms for 

Modular Elliptic Curves', or Prop 2.27 of Stein's Ph.D. thesis. 

""" 

if transformation not in [False,True,"matrix",None,"corner"]: 

raise ValueError("Value %s of the optional argument transformation is not valid.") 

 

if not isinstance(other, Cusp): 

other = Cusp(other) 

N = ZZ(N) 

u1 = self.__a 

v1 = self.__b 

u2 = other.__a 

v2 = other.__b 

 

zero = ZZ.zero() 

one = ZZ.one() 

 

if transformation == "matrix": 

from sage.matrix.constructor import matrix 

 

#if transformation : 

# transformation = "corner" 

 

if v1 == v2 and u1 == u2: 

if not transformation: 

return True 

elif transformation == "matrix": 

return True, matrix(ZZ,[[1,0],[0,1]]) 

else: 

return True, one 

 

# a necessary, but not sufficient condition unless N is square-free 

if v1.gcd(N) != v2.gcd(N): 

if not transformation: 

return False 

else: 

return False, None 

 

if (u1,v1) != (zero,one): 

if v1 in [zero, one]: 

s1 = one 

else: 

s1 = u1.inverse_mod(v1) 

else: 

s1 = 0 

if (u2,v2) != (zero, one): 

if v2 in [zero,one]: 

s2 = one 

else: 

s2 = u2.inverse_mod(v2) 

else: 

s2 = zero 

g = (v1*v2).gcd(N) 

a = s1*v2 - s2*v1 

if a%g != 0: 

if not transformation: 

return False 

else: 

return False, None 

 

if not transformation: 

return True 

 

# Now we know the cusps are equivalent. Use the proof of Prop 2.2.3 

# of Cremona to find a matrix in Gamma_0(N) relating them. 

if v1 == 0: # the first is oo 

if v2 == 0: # both are oo 

if transformation == "matrix": 

return (True, matrix(ZZ,[[1,0],[0,1]])) 

else: 

return (True, one) 

else: 

dum, s2, r2 = u2.xgcd(-v2) 

assert dum.is_one() 

if transformation == "matrix": 

return (True, matrix(ZZ, [[u2,r2],[v2,s2]]) ) 

else: 

return (True, u2) 

 

elif v2 == 0: # the second is oo 

dum, s1, r1 = u1.xgcd(-v1) 

assert dum.is_one() 

if transformation == "matrix": 

return (True, matrix(ZZ, [[s1,-r1],[-v1,u1]]) ) 

else: 

return (True, s1) 

 

dum, s2, r2 = u2.xgcd(-v2) 

assert dum.is_one() 

dum, s1, r1 = u1.xgcd(-v1) 

assert dum.is_one() 

a = s1*v2 - s2*v1 

assert (a%g).is_zero() 

# solve x*v1*v2 + a = 0 (mod N). 

d,x0,y0 = (v1*v2).xgcd(N) # x0*v1*v2 + y0*N = d = g. 

# so x0*v1*v2 - g = 0 (mod N) 

x = -x0 * ZZ(a/g) 

# now x*v1*v2 + a = 0 (mod N) 

 

# the rest is all added in trac #10926 

s1p = s1+x*v1 

M = N//g 

 

if transformation == "matrix": 

C = s1p*v2 - s2*v1 

if C % (M*v1*v2) == 0 : 

k = - C//(M*v1*v2) 

else: 

k = - (C/(M*v1*v2)).round() 

 

s1pp = s1p + k *M* v1 

# C += k*M*v1*v2 # is now the smallest in absolute value 

C = s1pp*v2 - s2*v1 

A = u2*s1pp - r2*v1 

 

r1pp = r1 + (x+k*M)*u1 

B = r2 * u1 - r1pp * u2 

D = s2 * u1 - r1pp * v2 

 

ga = matrix(ZZ, [[A,B],[C,D]]) 

assert ga.det() == 1 

assert C % N == 0 

assert (A*u1 + B*v1)/(C*u1+D*v1) == u2/v2 

return (True, ga) 

 

else: 

# mainly for backwards compatibility and 

# for how it is used in modular symbols 

A = (u2*s1p - r2*v1) 

if u2 != 0 and v1 != 0: 

A = A % (u2*v1*M) 

return (True, A) 

 

def is_gamma1_equiv(self, other, N): 

""" 

Return whether self and other are equivalent modulo the action of 

Gamma_1(N) via linear fractional transformations. 

 

INPUT: 

 

 

- ``other`` - Cusp 

 

- ``N`` - an integer (specifies the group 

Gamma_1(N)) 

 

 

OUTPUT: 

 

 

- ``bool`` - True if self and other are equivalent 

 

- ``int`` - 0, 1 or -1, gives further information 

about the equivalence: If the two cusps are u1/v1 and u2/v2, then 

they are equivalent if and only if v1 = v2 (mod N) and u1 = u2 (mod 

gcd(v1,N)) or v1 = -v2 (mod N) and u1 = -u2 (mod gcd(v1,N)) The 

sign is +1 for the first and -1 for the second. If the two cusps 

are not equivalent then 0 is returned. 

 

 

EXAMPLES:: 

 

sage: x = Cusp(2,3) 

sage: y = Cusp(4,5) 

sage: x.is_gamma1_equiv(y,2) 

(True, 1) 

sage: x.is_gamma1_equiv(y,3) 

(False, 0) 

sage: z = Cusp(QQ(x) + 10) 

sage: x.is_gamma1_equiv(z,10) 

(True, 1) 

sage: z = Cusp(1,0) 

sage: x.is_gamma1_equiv(z, 3) 

(True, -1) 

sage: Cusp(0).is_gamma1_equiv(oo, 1) 

(True, 1) 

sage: Cusp(0).is_gamma1_equiv(oo, 3) 

(False, 0) 

""" 

if not isinstance(other, Cusp): 

other = Cusp(other) 

N = ZZ(N) 

u1 = self.__a 

v1 = self.__b 

u2 = other.__a 

v2 = other.__b 

g = v1.gcd(N) 

if ((v2 - v1) % N == 0 and (u2 - u1) % g== 0): 

return True, 1 

elif ((v2 + v1) % N == 0 and (u2 + u1) % g== 0): 

return True, -1 

return False, 0 

 

def is_gamma_h_equiv(self, other, G): 

""" 

Return a pair (b, t), where b is True or False as self and other 

are equivalent under the action of G, and t is 1 or -1, as 

described below. 

 

Two cusps `u1/v1` and `u2/v2` are equivalent modulo 

Gamma_H(N) if and only if `v1 = h*v2 (\mathrm{mod} N)` and 

`u1 = h^{(-1)}*u2 (\mathrm{mod} gcd(v1,N))` or 

`v1 = -h*v2 (mod N)` and 

`u1 = -h^{(-1)}*u2 (\mathrm{mod} gcd(v1,N))` for some 

`h \in H`. Then t is 1 or -1 as c and c' fall into the 

first or second case, respectively. 

 

INPUT: 

 

 

- ``other`` - Cusp 

 

- ``G`` - a congruence subgroup Gamma_H(N) 

 

 

OUTPUT: 

 

 

- ``bool`` - True if self and other are equivalent 

 

- ``int`` - -1, 0, 1; extra info 

 

 

EXAMPLES:: 

 

sage: x = Cusp(2,3) 

sage: y = Cusp(4,5) 

sage: x.is_gamma_h_equiv(y,GammaH(13,[2])) 

(True, 1) 

sage: x.is_gamma_h_equiv(y,GammaH(13,[5])) 

(False, 0) 

sage: x.is_gamma_h_equiv(y,GammaH(5,[])) 

(False, 0) 

sage: x.is_gamma_h_equiv(y,GammaH(23,[4])) 

(True, -1) 

 

Enumerating the cusps for a space of modular symbols uses this 

function. 

 

:: 

 

sage: G = GammaH(25,[6]) ; M = G.modular_symbols() ; M 

Modular Symbols space of dimension 11 for Congruence Subgroup Gamma_H(25) with H generated by [6] of weight 2 with sign 0 and over Rational Field 

sage: M.cusps() 

[37/75, 1/2, 31/125, 1/4, -2/5, 2/5, -1/5, 1/10, -3/10, 1/15, 7/15, 9/20] 

sage: len(M.cusps()) 

12 

 

This is always one more than the associated space of weight 2 Eisenstein 

series. 

 

:: 

 

sage: G.dimension_eis(2) 

11 

sage: M.cuspidal_subspace() 

Modular Symbols subspace of dimension 0 of Modular Symbols space of dimension 11 for Congruence Subgroup Gamma_H(25) with H generated by [6] of weight 2 with sign 0 and over Rational Field 

sage: G.dimension_cusp_forms(2) 

0 

""" 

from sage.modular.arithgroup.all import is_GammaH 

if not isinstance(other, Cusp): 

other = Cusp(other) 

if not is_GammaH(G): 

raise TypeError("G must be a group GammaH(N).") 

 

H = G._list_of_elements_in_H() 

N = ZZ(G.level()) 

u1 = self.__a 

v1 = self.__b 

u2 = other.__a 

v2 = other.__b 

g = v1.gcd(N) 

 

for h in H: 

v_tmp = (h*v1) % N 

u_tmp = (h*u2) % N 

if (v_tmp - v2) % N == 0 and (u_tmp - u1) % g == 0: 

return True, 1 

if (v_tmp + v2) % N == 0 and (u_tmp + u1) % g == 0: 

return True, -1 

return False, 0 

 

def _acted_upon_(self, g, self_on_left): 

r""" 

Implements the left action of `SL_2(\ZZ)` on self. 

 

EXAMPLES:: 

 

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

[1 1] 

[0 1] 

sage: g * Cusp(2,5) 

7/5 

sage: Cusp(2,5) * g 

Traceback (most recent call last): 

... 

TypeError: unsupported operand parent(s) for *: 'Set P^1(QQ) of all cusps' and 'Full MatrixSpace of 2 by 2 dense matrices over Integer Ring' 

sage: h = matrix(ZZ, 2, [12,3,-100,7]) 

sage: h * Cusp(2,5) 

-13/55 

sage: Cusp(2,5)._acted_upon_(h, False) 

-13/55 

sage: (h*g) * Cusp(3,7) == h * (g * Cusp(3,7)) 

True 

 

sage: cm = sage.structure.element.get_coercion_model() 

sage: cm.explain(MatrixSpace(ZZ, 2), Cusps) 

Action discovered. 

Left action by Full MatrixSpace of 2 by 2 dense matrices over Integer Ring on Set P^1(QQ) of all cusps 

Result lives in Set P^1(QQ) of all cusps 

Set P^1(QQ) of all cusps 

""" 

if not self_on_left: 

if (is_Matrix(g) and g.base_ring() is ZZ 

and g.ncols() == 2 and g.nrows() == 2): 

a, b, c, d = g.list() 

return Cusp(a*self.__a + b*self.__b, c*self.__a + d*self.__b) 

 

 

def apply(self, g): 

""" 

Return g(self), where g=[a,b,c,d] is a list of length 4, which we 

view as a linear fractional transformation. 

 

EXAMPLES: Apply the identity matrix:: 

 

sage: Cusp(0).apply([1,0,0,1]) 

0 

sage: Cusp(0).apply([0,-1,1,0]) 

Infinity 

sage: Cusp(0).apply([1,-3,0,1]) 

-3 

""" 

return Cusp(g[0]*self.__a + g[1]*self.__b, g[2]*self.__a + g[3]*self.__b) 

 

def galois_action(self, t, N): 

r""" 

Suppose this cusp is `\alpha`, `G` a congruence subgroup of level `N` 

and `\sigma` is the automorphism in the Galois group of 

`\QQ(\zeta_N)/\QQ` that sends `\zeta_N` to `\zeta_N^t`. Then this 

function computes a cusp `\beta` such that `\sigma([\alpha]) = [\beta]`, 

where `[\alpha]` is the equivalence class of `\alpha` modulo `G`. 

 

This code only needs as input the level and not the group since the 

action of Galois for a congruence group `G` of level `N` is compatible 

with the action of the full congruence group `\Gamma(N)`. 

 

 

INPUT: 

 

- `t` -- integer that is coprime to N 

 

- `N` -- positive integer (level) 

 

OUTPUT: 

 

- a cusp 

 

 

.. WARNING:: 

 

In some cases `N` must fit in a long long, i.e., there 

are cases where this algorithm isn't fully implemented. 

 

.. NOTE:: 

 

Modular curves can have multiple non-isomorphic models over `\QQ`. 

The action of Galois depends on such a model. The model over `\QQ` 

of `X(G)` used here is the model where the function field 

`\QQ(X(G))` is given by the functions whose Fourier expansion at 

`\infty` have their coefficients in `\QQ`. For `X(N):=X(\Gamma(N))` 

the corresponding moduli interpretation over `\ZZ[1/N]` is that 

`X(N)` parametrizes pairs `(E,a)` where `E` is a (generalized) 

elliptic curve and `a: \ZZ / N\ZZ \times \mu_N \to E` is a closed 

immersion such that the Weil pairing of `a(1,1)` and `a(0,\zeta_N)` 

is `\zeta_N`. In this parameterisation the point `z \in H` 

corresponds to the pair `(E_z,a_z)` with `E_z=\CC/(z \ZZ+\ZZ)` and 

`a_z: \ZZ / N\ZZ \times \mu_N \to E` given by `a_z(1,1) = z/N` and 

`a_z(0,\zeta_N) = 1/N`. 

Similarly `X_1(N):=X(\Gamma_1(N))` parametrizes pairs `(E,a)` where 

`a: \mu_N \to E` is a closed immersion. 

 

EXAMPLES:: 

 

sage: Cusp(1/10).galois_action(3, 50) 

1/170 

sage: Cusp(oo).galois_action(3, 50) 

Infinity 

sage: c=Cusp(0).galois_action(3, 50); c 

50/67 

sage: Gamma0(50).reduce_cusp(c) 

0 

 

Here we compute the permutations of the action for t=3 on cusps for 

Gamma0(50). :: 

 

sage: N = 50; t=3; G = Gamma0(N); C = G.cusps() 

sage: cl = lambda z: exists(C, lambda y:y.is_gamma0_equiv(z, N))[1] 

sage: for i in range(5): 

....: print((i, t^i)) 

....: print([cl(alpha.galois_action(t^i,N)) for alpha in C]) 

(0, 1) 

[0, 1/25, 1/10, 1/5, 3/10, 2/5, 1/2, 3/5, 7/10, 4/5, 9/10, Infinity] 

(1, 3) 

[0, 1/25, 7/10, 2/5, 1/10, 4/5, 1/2, 1/5, 9/10, 3/5, 3/10, Infinity] 

(2, 9) 

[0, 1/25, 9/10, 4/5, 7/10, 3/5, 1/2, 2/5, 3/10, 1/5, 1/10, Infinity] 

(3, 27) 

[0, 1/25, 3/10, 3/5, 9/10, 1/5, 1/2, 4/5, 1/10, 2/5, 7/10, Infinity] 

(4, 81) 

[0, 1/25, 1/10, 1/5, 3/10, 2/5, 1/2, 3/5, 7/10, 4/5, 9/10, Infinity] 

 

TESTS: 

 

Here we check that the Galois action is indeed a permutation on the 

cusps of Gamma1(48) and check that :trac:`13253` is fixed. :: 

 

sage: G=Gamma1(48) 

sage: C=G.cusps() 

sage: for i in Integers(48).unit_gens(): 

....: C_permuted = [G.reduce_cusp(c.galois_action(i,48)) for c in C] 

....: assert len(set(C_permuted))==len(C) 

 

We test that Gamma1(19) has 9 rational cusps and check that :trac:`8998` 

is fixed. :: 

 

sage: G = Gamma1(19) 

sage: [c for c in G.cusps() if c.galois_action(2,19).is_gamma1_equiv(c,19)[0]] 

[2/19, 3/19, 4/19, 5/19, 6/19, 7/19, 8/19, 9/19, Infinity] 

 

 

REFERENCES: 

 

- Section 1.3 of Glenn Stevens, "Arithmetic on Modular Curves" 

 

- There is a long comment about our algorithm in the source code for this function. 

 

AUTHORS: 

 

- William Stein, 2009-04-18 

 

""" 

if self.is_infinity(): return self 

if not isinstance(t, Integer): t = Integer(t) 

 

# Our algorithm for computing the Galois action works as 

# follows (see Section 1.3 of Glenn Stevens "Arithmetic on 

# Modular Curves" for a proof that the action given below is 

# correct). We alternatively view the set of cusps as the 

# Gamma-equivalence classes of column vectors [a;b] with 

# gcd(a,b,N)=1, and the left action of Gamma by matrix 

# multiplication. The action of t is induced by [a;b] |--> 

# [a;t'*b], where t' is an inverse mod N of t. For [a;t'*b] 

# with gcd(a,t'*b)==1, the cusp corresponding to [a;t'*b] is 

# just the rational number a/(t'*b). Thus in this case, to 

# compute the action of t we just do a/b <--> [a;b] |---> 

# [a;t'*b] <--> a/(t'*b). IN the other case when we get 

# [a;t'*b] with gcd(a,t'*b) != 1, which can and does happen, 

# we have to work a bit harder. We need to find [c;d] such 

# that [c;d] is congruent to [a;t'*b] modulo N, and 

# gcd(c,d)=1. There is a standard lifting algorithm that is 

# implemented for working with P^1(Z/NZ) [it is needed for 

# modular symbols algorithms], so we just apply it to lift 

# [a,t'*b] to a matrix [A,B;c,d] in SL_2(Z) with lower two 

# entries congruent to [a,t'*b] modulo N. This exactly solves 

# our problem, since gcd(c,d)=1. 

 

a = self.__a 

b = self.__b * t.inverse_mod(N) 

if b.gcd(a) != 1: 

_,_,a,b = lift_to_sl2z_llong(a,b,N) 

a = Integer(a); b = Integer(b) 

 

# Now that we've computed the Galois action, we efficiently 

# construct the corresponding cusp as a Cusp object. 

return Cusp(a,b,check=False)