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

1140

1141

1142

1143

1144

1145

1146

1147

1148

1149

1150

1151

1152

1153

1154

1155

1156

1157

1158

1159

1160

1161

1162

1163

1164

1165

1166

1167

1168

1169

1170

1171

1172

1173

1174

1175

1176

1177

1178

1179

1180

1181

1182

1183

1184

1185

1186

1187

1188

1189

1190

1191

1192

1193

1194

1195

1196

1197

1198

1199

1200

r""" 

Lists of Manin symbols (elements of `\mathbb{P}^1(R/N)`) over number fields 

 

Lists of elements of `\mathbb{P}^1(R/N)` where `R` is the ring of integers of a number 

field `K` and `N` is an integral ideal. 

 

AUTHORS: 

 

- Maite Aranes (2009): Initial version 

 

EXAMPLES: 

 

We define a P1NFList: 

 

:: 

 

sage: k.<a> = NumberField(x^3 + 11) 

sage: N = k.ideal(5, a^2 - a + 1) 

sage: P = P1NFList(N); P 

The projective line over the ring of integers modulo the Fractional ideal (5, a^2 - a + 1) 

 

List operations with the P1NFList: 

 

:: 

 

sage: len(P) 

26 

sage: [p for p in P] 

[M-symbol (0: 1) of level Fractional ideal (5, a^2 - a + 1), 

... 

M-symbol (1: 2*a^2 + 2*a) of level Fractional ideal (5, a^2 - a + 1)] 

 

The elements of the P1NFList are M-symbols: 

 

:: 

 

sage: type(P[2]) 

<class 'sage.modular.modsym.p1list_nf.MSymbol'> 

 

Definition of MSymbols: 

 

:: 

 

sage: alpha = MSymbol(N, 3, a^2); alpha 

M-symbol (3: a^2) of level Fractional ideal (5, a^2 - a + 1) 

 

Find the index of the class of an M-Symbol `(c: d)` in the list: 

 

:: 

 

sage: i = P.index(alpha) 

sage: P[i].c*alpha.d - P[i].d*alpha.c in N 

True 

 

Lift an MSymbol to a matrix in `SL(2, R)`: 

 

:: 

 

sage: alpha = MSymbol(N, a + 2, 3*a^2) 

sage: alpha.lift_to_sl2_Ok() 

[-3*a^2 + a + 12, 25*a^2 - 50*a + 100, a + 2, a^2 - 3*a + 3] 

sage: Ok = k.ring_of_integers() 

sage: M = Matrix(Ok, 2, alpha.lift_to_sl2_Ok()) 

sage: det(M) 

1 

sage: M[1][1] - alpha.d in N 

True 

 

Lift an MSymbol from P1NFList to a matrix in `SL(2, R)` 

 

:: 

 

sage: P[3] 

M-symbol (1: -2*a) of level Fractional ideal (5, a^2 - a + 1) 

sage: P.lift_to_sl2_Ok(3) 

[0, -1, 1, -2*a] 

""" 

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

# Copyright (C) 2009, Maite Aranes <M.T.Aranes@warwick.ac.uk> 

# 

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

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

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

 

from sage.structure.richcmp import richcmp_method, richcmp 

from sage.structure.sage_object import SageObject 

 

from sage.misc.search import search 

 

_level_cache = {} # The info stored here is used in the normalization of MSymbols. 

 

def P1NFList_clear_level_cache(): 

""" 

Clear the global cache of data for the level ideals. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^3 + 11) 

sage: N = k.ideal(a+1) 

sage: alpha = MSymbol(N, 2*a^2, 5) 

sage: alpha.normalize() 

M-symbol (-4*a^2: 5*a^2) of level Fractional ideal (a + 1) 

sage: sage.modular.modsym.p1list_nf._level_cache 

{Fractional ideal (a + 1): (...)} 

sage: sage.modular.modsym.p1list_nf.P1NFList_clear_level_cache() 

sage: sage.modular.modsym.p1list_nf._level_cache 

{} 

""" 

global _level_cache 

_level_cache = {} 

 

 

@richcmp_method 

class MSymbol(SageObject): 

""" 

The constructor for an M-symbol over a number field. 

 

INPUT: 

 

- ``N`` -- integral ideal (the modulus or level). 

 

- ``c`` -- integral element of the underlying number field or an MSymbol of 

level N. 

 

- ``d`` -- (optional) when present, it must be an integral element such 

that <c> + <d> + N = R, where R is the corresponding ring of integers. 

 

- ``check`` -- bool (default True). If ``check=False`` the constructor does 

not check the condition <c> + <d> + N = R. 

 

OUTPUT: 

 

An M-symbol modulo the given ideal N, i.e. an element of the 

projective line `\\mathbb{P}^1(R/N)`, where R is the ring of integers of 

the underlying number field. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^3 + 11) 

sage: N = k.ideal(a + 1, 2) 

sage: MSymbol(N, 3, a^2 + 1) 

M-symbol (3: a^2 + 1) of level Fractional ideal (2, a + 1) 

 

We can give a tuple as input: 

 

:: 

 

sage: MSymbol(N, (1, 0)) 

M-symbol (1: 0) of level Fractional ideal (2, a + 1) 

 

We get an error if <c>, <d> and N are not coprime: 

 

:: 

 

sage: MSymbol(N, 2*a, a - 1) 

Traceback (most recent call last): 

... 

ValueError: (2*a, a - 1) is not an element of P1(R/N). 

sage: MSymbol(N, (0, 0)) 

Traceback (most recent call last): 

... 

ValueError: (0, 0) is not an element of P1(R/N). 

 

Saving and loading works: 

 

:: 

 

sage: alpha = MSymbol(N, 3, a^2 + 1) 

sage: loads(dumps(alpha))==alpha 

True 

""" 

def __init__(self, N, c, d=None, check=True): 

""" 

See ``MSymbol`` for full documentation. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^4 + 13*x - 7) 

sage: N = k.ideal(5) 

sage: MSymbol(N, 0, 6*a) 

M-symbol (0: 6*a) of level Fractional ideal (5) 

sage: MSymbol(N, a^2 + 3, 7) 

M-symbol (a^2 + 3: 7) of level Fractional ideal (5) 

""" 

k = N.number_field() 

R = k.ring_of_integers() 

self.__N = N 

if d is None: # if we give a list (c, d) or an MSymbol as input 

if isinstance(c, MSymbol): 

if c.N() is N: 

c1 = R(c[0]) 

d1 = R(c[1]) 

else: 

raise ValueError("Cannot change level of an MSymbol") 

else: 

try: 

c1 = R(c[0]) 

d1 = R(c[1]) 

except (ValueError, TypeError): 

raise TypeError("Unable to create a Manin symbol from %s"%c) 

else: 

try: 

c1 = R(c) 

d1 = R(d) 

except (ValueError, TypeError): 

raise TypeError("Unable to create a Manin symbol from (%s, %s)"%(c, d)) 

if check: 

if (c1.is_zero() and d1.is_zero()) or not N.is_coprime(k.ideal(c1, d1)): 

raise ValueError("(%s, %s) is not an element of P1(R/N)."%(c1, d1)) 

self.__c, self.__d = (c1, d1) 

 

def __repr__(self): 

""" 

Returns the string representation of this MSymbol. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^2 + 23) 

sage: N = k.ideal(3, a - 1) 

sage: MSymbol(N, 3, a) 

M-symbol (3: a) of level Fractional ideal (3, 1/2*a - 1/2) 

""" 

return "M-symbol (%s: %s) of level %s"%(self.__c, self.__d, self.__N) 

 

def _latex_(self): 

r""" 

Return latex representation of self. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^4 + 13*x - 7) 

sage: N = k.ideal(a^3 - 1) 

sage: alpha = MSymbol(N, 3, 5*a^2 - 1) 

sage: latex(alpha) # indirect doctest 

\(3: 5 a^{2} - 1\) 

""" 

return "\\(%s: %s\)"%(self.c._latex_(), self.d._latex_()) 

 

def __richcmp__(self, other, op): 

""" 

Comparison function for objects of the class MSymbol. 

 

The order is the same as for the underlying lists of lists. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^2 + 23) 

sage: N = k.ideal(3, a - 1) 

sage: alpha = MSymbol(N, 3, a) 

sage: beta = MSymbol(N, 1, 0) 

sage: alpha < beta 

False 

sage: beta = MSymbol(N, 3, a + 1) 

sage: alpha < beta 

True 

""" 

if not isinstance(other, MSymbol): 

raise ValueError("You can only compare with another M-symbol") 

return richcmp([self.__c.list(), self.__d.list()], 

[other.__c.list(), other.__d.list()], op) 

 

def N(self): 

""" 

Returns the level or modulus of this MSymbol. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^2 + 23) 

sage: N = k.ideal(3, a - 1) 

sage: alpha = MSymbol(N, 3, a) 

sage: alpha.N() 

Fractional ideal (3, 1/2*a - 1/2) 

""" 

return self.__N 

 

def tuple(self): 

""" 

Returns the MSymbol as a list (c, d). 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^2 + 23) 

sage: N = k.ideal(3, a - 1) 

sage: alpha = MSymbol(N, 3, a); alpha 

M-symbol (3: a) of level Fractional ideal (3, 1/2*a - 1/2) 

sage: alpha.tuple() 

(3, a) 

""" 

return self.__c, self.__d 

 

def __getitem__(self, n): 

""" 

Indexing function for the list defined by an M-symbol. 

 

INPUT: 

 

- ``n`` -- integer (0 or 1, since the list defined by an M-symbol has 

length 2) 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^2 + 23) 

sage: N = k.ideal(3, a - 1) 

sage: alpha = MSymbol(N, 3, a); alpha 

M-symbol (3: a) of level Fractional ideal (3, 1/2*a - 1/2) 

sage: alpha[0] 

3 

sage: alpha[1] 

a 

""" 

return self.tuple()[n] 

 

def __get_c(self): 

""" 

Returns the first coefficient of the M-symbol. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^3 + 11) 

sage: N = k.ideal(a + 1, 2) 

sage: alpha = MSymbol(N, 3, a^2 + 1) 

sage: alpha.c # indirect doctest 

3 

""" 

return self.__c 

c = property(__get_c) 

 

def __get_d(self): 

""" 

Returns the second coefficient of the M-symbol. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^3 + 11) 

sage: N = k.ideal(a + 1, 2) 

sage: alpha = MSymbol(N, 3, a^2 + 1) 

sage: alpha.d # indirect doctest 

a^2 + 1 

""" 

return self.__d 

d = property(__get_d) 

 

def lift_to_sl2_Ok(self): 

""" 

Lift the MSymbol to an element of `SL(2, Ok)`, where `Ok` is the ring 

of integers of the corresponding number field. 

 

OUTPUT: 

 

A list of integral elements `[a, b, c', d']` that are the entries of 

a 2x2 matrix with determinant 1. The lower two entries are congruent 

(modulo the level) to the coefficients `c, d` of the MSymbol self. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^2 + 23) 

sage: N = k.ideal(3, a - 1) 

sage: alpha = MSymbol(N, 3*a + 1, a) 

sage: alpha.lift_to_sl2_Ok() 

[0, -1, 1, a] 

""" 

return lift_to_sl2_Ok(self.__N, self.__c, self.__d) 

 

def normalize(self, with_scalar=False): 

""" 

Returns a normalized MSymbol (a canonical representative of an element 

of `\mathbb{P}^1(R/N)` ) equivalent to ``self``. 

 

INPUT: 

 

- ``with_scalar`` -- bool (default False) 

 

OUTPUT: 

 

- (only if ``with_scalar=True``) a transforming scalar `u`, such that 

`(u*c', u*d')` is congruent to `(c: d)` (mod `N`), where `(c: d)` 

are the coefficients of ``self`` and `N` is the level. 

 

- a normalized MSymbol (c': d') equivalent to ``self``. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^2 + 23) 

sage: N = k.ideal(3, a - 1) 

sage: alpha1 = MSymbol(N, 3, a); alpha1 

M-symbol (3: a) of level Fractional ideal (3, 1/2*a - 1/2) 

sage: alpha1.normalize() 

M-symbol (0: 1) of level Fractional ideal (3, 1/2*a - 1/2) 

sage: alpha2 = MSymbol(N, 4, a + 1) 

sage: alpha2.normalize() 

M-symbol (1: -a) of level Fractional ideal (3, 1/2*a - 1/2) 

 

We get the scaling factor by setting ``with_scalar=True``: 

 

:: 

 

sage: alpha1.normalize(with_scalar=True) 

(a, M-symbol (0: 1) of level Fractional ideal (3, 1/2*a - 1/2)) 

sage: r, beta1 = alpha1.normalize(with_scalar=True) 

sage: r*beta1.c - alpha1.c in N 

True 

sage: r*beta1.d - alpha1.d in N 

True 

sage: r, beta2 = alpha2.normalize(with_scalar=True) 

sage: r*beta2.c - alpha2.c in N 

True 

sage: r*beta2.d - alpha2.d in N 

True 

""" 

N = self.__N 

k = N.number_field() 

R = k.ring_of_integers() 

 

if self.__c in N: 

if with_scalar: 

return N.reduce(self.d), MSymbol(N, 0, 1) 

else: 

return MSymbol(N, 0, 1) 

if self.d in N: 

if with_scalar: 

return N.reduce(self.c), MSymbol(N, 1, 0) 

else: 

return MSymbol(N, 1, 0) 

if N.is_coprime(self.c): 

cinv = R(self.c).inverse_mod(N) 

if with_scalar: 

return N.reduce(self.c), MSymbol(N, 1, N.reduce(self.d*cinv)) 

else: 

return MSymbol(N, 1, N.reduce(self.d*cinv)) 

 

if N in _level_cache: 

Lfacs, Lxs = _level_cache[N] 

else: 

Lfacs = [p**e for p, e in N.factor()] 

Lxs = [(N/p).element_1_mod(p) for p in Lfacs] 

# Lfacs, Lxs only depend of the ideal: same lists every time we 

# call normalize for a given level, so we store the lists. 

_level_cache[N] = (Lfacs, Lxs) 

u = 0 # normalizer factor 

p_i = 0 

for p in Lfacs: 

if p.is_coprime(self.c): 

inv = self.c.inverse_mod(p) 

else: 

inv = self.d.inverse_mod(p) 

u = u + inv*Lxs[p_i] 

p_i = p_i + 1 

c, d = (N.reduce(u*self.c), N.reduce(u*self.d)) 

if (c - 1) in N: 

c = R(1) 

if with_scalar: 

return u.inverse_mod(N), MSymbol(N, c, d) 

else: 

return MSymbol(N, c, d) 

 

 

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

#* P1NFList class * 

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

 

@richcmp_method 

class P1NFList(SageObject): 

""" 

The class for `\mathbb{P}^1(R/N)`, the projective line modulo `N`, where 

`R` is the ring of integers of a number field `K` and `N` is an integral ideal. 

 

INPUT: 

 

- ``N`` - integral ideal (the modulus or level). 

 

OUTPUT: 

 

A P1NFList object representing `\mathbb{P}^1(R/N)`. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^3 + 11) 

sage: N = k.ideal(5, a + 1) 

sage: P = P1NFList(N); P 

The projective line over the ring of integers modulo the Fractional ideal (5, a + 1) 

 

Saving and loading works. 

 

:: 

 

sage: loads(dumps(P)) == P 

True 

""" 

def __init__(self, N): 

""" 

The constructor for the class P1NFList. See ``P1NFList`` for full 

documentation. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^2 + 5) 

sage: N = k.ideal(3, a - 1) 

sage: P = P1NFList(N); P 

The projective line over the ring of integers modulo the Fractional ideal (3, a + 2) 

""" 

self.__N = N 

self.__list = p1NFlist(N) 

self.__list.sort() 

 

def __richcmp__(self, other, op): 

""" 

Comparison function for objects of the class P1NFList. 

 

The order is the same as for the underlying modulus. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^2 + 23) 

sage: N1 = k.ideal(3, a + 1) 

sage: P1 = P1NFList(N1) 

sage: N2 = k.ideal(a + 2) 

sage: P2 = P1NFList(N2) 

sage: P1 < P2 

True 

sage: P1 > P2 

False 

sage: P1 == P1NFList(N1) 

True 

""" 

if not isinstance(other, P1NFList): 

raise ValueError("You can only compare with another P1NFList") 

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

 

def __getitem__(self, n): 

""" 

Standard indexing function for the class P1NFList. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^3 + 11) 

sage: N = k.ideal(a) 

sage: P = P1NFList(N) 

sage: list(P) == P._P1NFList__list 

True 

sage: j = randint(0,len(P)-1) 

sage: P[j] == P._P1NFList__list[j] 

True 

""" 

return self.__list[n] 

 

def __len__(self): 

""" 

Returns the length of this P1NFList. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^3 + 11) 

sage: N = k.ideal(5, a^2 - a + 1) 

sage: P = P1NFList(N) 

sage: len(P) 

26 

""" 

return len(self.__list) 

 

def __repr__(self): 

""" 

Returns the string representation of this P1NFList. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^3 + 11) 

sage: N = k.ideal(5, a+1) 

sage: P = P1NFList(N); P 

The projective line over the ring of integers modulo the Fractional ideal (5, a + 1) 

 

""" 

return "The projective line over the ring of integers modulo the %s"%self.__N 

 

def list(self): 

""" 

Returns the underlying list of this P1NFList object. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^3 + 11) 

sage: N = k.ideal(5, a+1) 

sage: P = P1NFList(N) 

sage: type(P) 

<class 'sage.modular.modsym.p1list_nf.P1NFList'> 

sage: type(P.list()) 

<... 'list'> 

""" 

return self.__list 

 

def normalize(self, c, d=None, with_scalar=False): 

""" 

Returns a normalised element of `\mathbb{P}^1(R/N)`. 

 

INPUT: 

 

- ``c`` -- integral element of the underlying number field, or an 

MSymbol. 

 

- ``d`` -- (optional) when present, it must be an integral element of 

the number field such that `(c, d)` defines an M-symbol of level `N`. 

 

- ``with_scalar`` -- bool (default False) 

 

OUTPUT: 

 

- (only if ``with_scalar=True``) a transforming scalar `u`, such that 

`(u*c', u*d')` is congruent to `(c: d)` (mod `N`). 

 

- a normalized MSymbol (c': d') equivalent to `(c: d)`. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^2 + 31) 

sage: N = k.ideal(5, a + 3) 

sage: P = P1NFList(N) 

sage: P.normalize(3, a) 

M-symbol (1: 2*a) of level Fractional ideal (5, 1/2*a + 3/2) 

 

We can use an MSymbol as input: 

 

:: 

 

sage: alpha = MSymbol(N, 3, a) 

sage: P.normalize(alpha) 

M-symbol (1: 2*a) of level Fractional ideal (5, 1/2*a + 3/2) 

 

If we are interested in the normalizing scalar: 

 

:: 

 

sage: P.normalize(alpha, with_scalar=True) 

(-a, M-symbol (1: 2*a) of level Fractional ideal (5, 1/2*a + 3/2)) 

sage: r, beta = P.normalize(alpha, with_scalar=True) 

sage: (r*beta.c - alpha.c in N) and (r*beta.d - alpha.d in N) 

True 

""" 

if d is None: 

try: 

c = MSymbol(self.__N, c) # check that c is an MSymbol 

except ValueError: # catch special case of wrong level 

raise ValueError("The MSymbol is of a different level") 

return c.normalize(with_scalar) 

return MSymbol(self.N(), c, d).normalize(with_scalar) 

 

def N(self): 

""" 

Returns the level or modulus of this P1NFList. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^2 + 31) 

sage: N = k.ideal(5, a + 3) 

sage: P = P1NFList(N) 

sage: P.N() 

Fractional ideal (5, 1/2*a + 3/2) 

""" 

return self.__N 

 

def index(self, c, d=None, with_scalar=False): 

""" 

Returns the index of the class of the pair `(c, d)` in the fixed list 

of representatives of `\mathbb{P}^1(R/N)`. 

 

INPUT: 

 

- ``c`` -- integral element of the corresponding number field, or an 

MSymbol. 

 

- ``d`` -- (optional) when present, it must be an integral element of 

the number field such that `(c, d)` defines an M-symbol of level `N`. 

 

- ``with_scalar`` -- bool (default False) 

 

OUTPUT: 

 

- ``u`` - the normalizing scalar (only if ``with_scalar=True``) 

 

- ``i`` - the index of `(c, d)` in the list. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^2 + 31) 

sage: N = k.ideal(5, a + 3) 

sage: P = P1NFList(N) 

sage: P.index(3,a) 

5 

sage: P[5]==MSymbol(N, 3, a).normalize() 

True 

 

We can give an MSymbol as input: 

 

:: 

 

sage: alpha = MSymbol(N, 3, a) 

sage: P.index(alpha) 

5 

 

We cannot look for the class of an MSymbol of a different level: 

 

:: 

 

sage: M = k.ideal(a + 1) 

sage: beta = MSymbol(M, 0, 1) 

sage: P.index(beta) 

Traceback (most recent call last): 

... 

ValueError: The MSymbol is of a different level 

 

If we are interested in the transforming scalar: 

 

:: 

 

sage: alpha = MSymbol(N, 3, a) 

sage: P.index(alpha, with_scalar=True) 

(-a, 5) 

sage: u, i = P.index(alpha, with_scalar=True) 

sage: (u*P[i].c - alpha.c in N) and (u*P[i].d - alpha.d in N) 

True 

""" 

if d is None: 

try: 

c = MSymbol(self.__N, c) # check that c is an MSymbol 

except ValueError: # catch special case of wrong level 

raise ValueError("The MSymbol is of a different level") 

if with_scalar: 

u, norm_c = c.normalize(with_scalar=True) 

else: 

norm_c = c.normalize() 

else: 

if with_scalar: 

u, norm_c = MSymbol(self.__N, c, d).normalize(with_scalar=True) 

else: 

norm_c = MSymbol(self.__N, c, d).normalize() 

t, i = search(self.__list, norm_c) 

if t: 

if with_scalar: 

return u, i 

else: 

return i 

return False 

 

def index_of_normalized_pair(self, c, d=None): 

""" 

Returns the index of the class `(c, d)` in the fixed list of 

representatives of `\mathbb(P)^1(R/N)`. 

 

INPUT: 

 

- ``c`` -- integral element of the corresponding number field, or a 

normalized MSymbol. 

 

- ``d`` -- (optional) when present, it must be an integral element of 

the number field such that `(c, d)` defines a normalized M-symbol of 

level `N`. 

 

OUTPUT: 

 

- ``i`` - the index of `(c, d)` in the list. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^2 + 31) 

sage: N = k.ideal(5, a + 3) 

sage: P = P1NFList(N) 

sage: P.index_of_normalized_pair(1, 0) 

3 

sage: j = randint(0,len(P)-1) 

sage: P.index_of_normalized_pair(P[j])==j 

True 

""" 

if d is None: 

try: 

c = MSymbol(self.__N, c) # check that c is an MSymbol 

except ValueError: # catch special case of wrong level 

raise ValueError("The MSymbol is of a different level") 

t, i = search(self.__list, c) 

else: 

t, i = search(self.__list, MSymbol(self.__N, c, d)) 

if t: return i 

return False 

 

def lift_to_sl2_Ok(self, i): 

""" 

Lift the `i`-th element of this P1NFList to an element of `SL(2, R)`, 

where `R` is the ring of integers of the corresponding number field. 

 

INPUT: 

 

- ``i`` - integer (index of the element to lift) 

 

OUTPUT: 

 

If the `i`-th element is `(c : d)`, the function returns a list of 

integral elements `[a, b, c', d']` that defines a 2x2 matrix with 

determinant 1 and such that `c=c'` (mod `N`) and `d=d'` (mod `N`). 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^2 + 23) 

sage: N = k.ideal(3) 

sage: P = P1NFList(N) 

sage: len(P) 

16 

sage: P[5] 

M-symbol (1/2*a + 1/2: -a) of level Fractional ideal (3) 

sage: P.lift_to_sl2_Ok(5) 

[-a, 2*a - 2, 1/2*a + 1/2, -a] 

 

:: 

 

sage: Ok = k.ring_of_integers() 

sage: L = [Matrix(Ok, 2, P.lift_to_sl2_Ok(i)) for i in range(len(P))] 

sage: all([det(L[i]) == 1 for i in range(len(L))]) 

True 

""" 

return self[i].lift_to_sl2_Ok() 

 

def apply_S(self, i): 

""" 

Applies the matrix S = [0, -1, 1, 0] to the i-th M-Symbol of the list. 

 

INPUT: 

 

- ``i`` -- integer 

 

OUTPUT: 

 

integer -- the index of the M-Symbol obtained by the right action of 

the matrix S = [0, -1, 1, 0] on the i-th M-Symbol. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^3 + 11) 

sage: N = k.ideal(5, a + 1) 

sage: P = P1NFList(N) 

sage: j = P.apply_S(P.index_of_normalized_pair(1, 0)) 

sage: P[j] 

M-symbol (0: 1) of level Fractional ideal (5, a + 1) 

 

We test that S has order 2: 

 

:: 

 

sage: j = randint(0,len(P)-1) 

sage: P.apply_S(P.apply_S(j))==j 

True 

""" 

c, d = self.__list[i].tuple() 

t, j = search(self.__list, self.normalize(d, -c)) 

return j 

 

def apply_TS(self, i): 

""" 

Applies the matrix TS = [1, -1, 0, 1] to the i-th M-Symbol of the list. 

 

INPUT: 

 

- ``i`` -- integer 

 

OUTPUT: 

 

integer -- the index of the M-Symbol obtained by the right action of 

the matrix TS = [1, -1, 0, 1] on the i-th M-Symbol. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^3 + 11) 

sage: N = k.ideal(5, a + 1) 

sage: P = P1NFList(N) 

sage: P.apply_TS(3) 

2 

 

We test that TS has order 3: 

 

:: 

 

sage: j = randint(0,len(P)-1) 

sage: P.apply_TS(P.apply_TS(P.apply_TS(j)))==j 

True 

""" 

c, d = self.__list[i].tuple() 

t, j = search(self.__list, self.normalize(c + d, -c)) 

return j 

 

def apply_T_alpha(self, i, alpha=1): 

""" 

Applies the matrix T_alpha = [1, alpha, 0, 1] to the i-th M-Symbol of 

the list. 

 

INPUT: 

 

- ``i`` -- integer 

 

- ``alpha`` -- element of the corresponding ring of integers(default 1) 

 

OUTPUT: 

 

integer -- the index of the M-Symbol obtained by the right action of 

the matrix T_alpha = [1, alpha, 0, 1] on the i-th M-Symbol. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^3 + 11) 

sage: N = k.ideal(5, a + 1) 

sage: P = P1NFList(N) 

sage: P.apply_T_alpha(4, a^ 2 - 2) 

3 

 

We test that T_a*T_b = T_(a+b): 

 

:: 

 

sage: P.apply_T_alpha(3, a^2 - 2)==P.apply_T_alpha(P.apply_T_alpha(3,a^2),-2) 

True 

""" 

c, d = self.__list[i].tuple() 

t, j = search(self.__list, self.normalize(c, alpha*c + d)) 

return j 

 

def apply_J_epsilon(self, i, e1, e2=1): 

""" 

Applies the matrix `J_{\epsilon}` = [e1, 0, 0, e2] to the i-th 

M-Symbol of the list. 

 

e1, e2 are units of the underlying number field. 

 

INPUT: 

 

- ``i`` -- integer 

 

- ``e1`` -- unit 

 

- ``e2`` -- unit (default 1) 

 

OUTPUT: 

 

integer -- the index of the M-Symbol obtained by the right action of 

the matrix `J_{\epsilon}` = [e1, 0, 0, e2] on the i-th M-Symbol. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^3 + 11) 

sage: N = k.ideal(5, a + 1) 

sage: P = P1NFList(N) 

sage: u = k.unit_group().gens_values(); u 

[-1, 2*a^2 + 4*a - 1] 

sage: P.apply_J_epsilon(4, -1) 

2 

sage: P.apply_J_epsilon(4, u[0], u[1]) 

1 

 

:: 

 

sage: k.<a> = NumberField(x^4 + 13*x - 7) 

sage: N = k.ideal(a + 1) 

sage: P = P1NFList(N) 

sage: u = k.unit_group().gens_values(); u 

[-1, a^3 + a^2 + a + 12, a^3 + 3*a^2 - 1] 

sage: P.apply_J_epsilon(3, u[2]^2)==P.apply_J_epsilon(P.apply_J_epsilon(3, u[2]),u[2]) 

True 

""" 

c, d = self.__list[i].tuple() 

t, j = search(self.__list, self.normalize(c*e1, d*e2)) 

return j 

 

 

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

# Global functions: 

# - p1NFList --compute list of M-symbols 

# - lift_to_sl2_Ok 

# - make_coprime -- need it for ``lift_to_sl2_Ok`` 

# - psi -- useful to check cardinality of the M-symbols list 

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

 

def p1NFlist(N): 

""" 

Returns a list of the normalized elements of `\\mathbb{P}^1(R/N)`, where 

`N` is an integral ideal. 

 

INPUT: 

 

- ``N`` - integral ideal (the level or modulus). 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^2 + 23) 

sage: N = k.ideal(3) 

sage: from sage.modular.modsym.p1list_nf import p1NFlist, psi 

sage: len(p1NFlist(N))==psi(N) 

True 

""" 

k = N.number_field() 

 

L = [MSymbol(N, k(0),k(1), check=False)] 

#N.residues() = iterator through the residues mod N 

L = L+[MSymbol(N, k(1), r, check=False) for r in N.residues()] 

 

from sage.arith.all import divisors 

for D in divisors(N): 

if not D.is_trivial() and D!=N: 

#we find Dp ideal coprime to N, in inverse class to D 

if D.is_principal(): 

Dp = k.ideal(1) 

c = D.gens_reduced()[0] 

else: 

it = k.primes_of_degree_one_iter() 

Dp = next(it) 

while not Dp.is_coprime(N) or not (Dp*D).is_principal(): 

Dp = next(it) 

c = (D*Dp).gens_reduced()[0] 

#now we find all the (c,d)'s which have associated divisor D 

I = D + N/D 

for d in (N/D).residues(): 

if I.is_coprime(d): 

M = D.prime_to_idealM_part(N/D) 

u = (Dp*M).element_1_mod(N/D) 

d1 = u*d + (1-u) 

L.append(MSymbol(N, c, d1, check=False).normalize()) 

return L 

 

def lift_to_sl2_Ok(N, c, d): 

""" 

Lift a pair (c, d) to an element of `SL(2, O_k)`, where `O_k` is the ring 

of integers of the corresponding number field. 

 

INPUT: 

 

- ``N`` -- number field ideal 

 

- ``c`` -- integral element of the number field 

 

- ``d`` -- integral element of the number field 

 

OUTPUT: 

 

A list [a, b, c', d'] of integral elements that are the entries of 

a 2x2 matrix with determinant 1. The lower two entries are congruent to 

c, d modulo the ideal `N`. 

 

 

EXAMPLES:: 

 

sage: from sage.modular.modsym.p1list_nf import lift_to_sl2_Ok 

sage: k.<a> = NumberField(x^2 + 23) 

sage: Ok = k.ring_of_integers() 

sage: N = k.ideal(3) 

sage: M = Matrix(Ok, 2, lift_to_sl2_Ok(N, 1, a)) 

sage: det(M) 

1 

sage: M = Matrix(Ok, 2, lift_to_sl2_Ok(N, 0, a)) 

sage: det(M) 

1 

sage: (M[1][0] in N) and (M[1][1] - a in N) 

True 

sage: M = Matrix(Ok, 2, lift_to_sl2_Ok(N, 0, 0)) 

Traceback (most recent call last): 

... 

ValueError: Cannot lift (0, 0) to an element of Sl2(Ok). 

 

:: 

 

sage: k.<a> = NumberField(x^3 + 11) 

sage: Ok = k.ring_of_integers() 

sage: N = k.ideal(3, a - 1) 

sage: M = Matrix(Ok, 2, lift_to_sl2_Ok(N, 2*a, 0)) 

sage: det(M) 

1 

sage: (M[1][0] - 2*a in N) and (M[1][1] in N) 

True 

sage: M = Matrix(Ok, 2, lift_to_sl2_Ok(N, 4*a^2, a + 1)) 

sage: det(M) 

1 

sage: (M[1][0] - 4*a^2 in N) and (M[1][1] - (a+1) in N) 

True 

 

:: 

 

sage: k.<a> = NumberField(x^4 - x^3 -21*x^2 + 17*x + 133) 

sage: Ok = k.ring_of_integers() 

sage: N = k.ideal(7, a) 

sage: M = Matrix(Ok, 2, lift_to_sl2_Ok(N, 0, a^2 - 1)) 

sage: det(M) 

1 

sage: (M[1][0] in N) and (M[1][1] - (a^2-1) in N) 

True 

sage: M = Matrix(Ok, 2, lift_to_sl2_Ok(N, 0, 7)) 

Traceback (most recent call last): 

... 

ValueError: <0> + <7> and the Fractional ideal (7, a) are not coprime. 

""" 

k = N.number_field() 

#check the input 

if c.is_zero() and d.is_zero(): 

raise ValueError("Cannot lift (%s, %s) to an element of Sl2(Ok)."%(c, d)) 

if not N.is_coprime(k.ideal(c, d)): 

raise ValueError("<%s> + <%s> and the %s are not coprime."%(c, d, N)) 

#a few special cases 

if c - 1 in N: 

return [k(0), k(-1), 1, d] 

if d - 1 in N: 

return [k(1), k(0), c, 1] 

if c.is_zero(): # and d!=1, so won't happen for normalized M-symbols (c: d) 

it = k.primes_of_degree_one_iter() 

q = k.ideal(1) 

while not (q.is_coprime(d) and (q*N).is_principal()): 

q = next(it) 

m = (q*N).gens_reduced()[0] 

B = k.ideal(m).element_1_mod(k.ideal(d)) 

return [(1-B)/d, -B/m, m, d] 

if d.is_zero(): # and c!=1, so won't happen for normalized M-symbols (c: d) 

it = k.primes_of_degree_one_iter() 

q = k.ideal(1) 

while not (q.is_coprime(c) and (q*N).is_principal()): 

q = next(it) 

m = (q*N).gens_reduced()[0] 

B = k.ideal(c).element_1_mod(k.ideal(m)) 

return [(1-B)/m, -B/c, c, m] 

 

c, d = make_coprime(N, c, d) 

 

B = k.ideal(c).element_1_mod(k.ideal(d)) 

b = -B/c 

a = (1-B)/d 

return [a, b, c, d] 

 

def make_coprime(N, c, d): 

""" 

Returns (c, d') so d' is congruent to d modulo N, and such that c and d' are 

coprime (<c> + <d'> = R). 

 

INPUT: 

 

- ``N`` -- number field ideal 

 

- ``c`` -- integral element of the number field 

 

- ``d`` -- integral element of the number field 

 

OUTPUT: 

 

A pair (c, d') where c, d' are integral elements of the corresponding 

number field, with d' congruent to d mod N, and such that <c> + <d'> = R 

(R being the corresponding ring of integers). 

 

EXAMPLES:: 

 

sage: from sage.modular.modsym.p1list_nf import make_coprime 

sage: k.<a> = NumberField(x^2 + 23) 

sage: N = k.ideal(3, a - 1) 

sage: c = 2*a; d = a + 1 

sage: N.is_coprime(k.ideal(c, d)) 

True 

sage: k.ideal(c).is_coprime(d) 

False 

sage: c, dp = make_coprime(N, c, d) 

sage: k.ideal(c).is_coprime(dp) 

True 

""" 

k = N.number_field() 

if k.ideal(c).is_coprime(d): 

return c, d 

else: 

q = k.ideal(c).prime_to_idealM_part(d) 

it = k.primes_of_degree_one_iter() 

r = k.ideal(1) 

qN = q*N 

while not (r.is_coprime(c) and (r*qN).is_principal()): 

r = next(it) 

m = (r*qN).gens_reduced()[0] 

d1 = d + m 

return c, d1 

 

def psi(N): 

""" 

The index `[\Gamma : \Gamma_0(N)]`, where `\Gamma = GL(2, R)` for `R` the 

corresponding ring of integers, and `\Gamma_0(N)` standard congruence 

subgroup. 

 

EXAMPLES:: 

 

sage: from sage.modular.modsym.p1list_nf import psi 

sage: k.<a> = NumberField(x^2 + 23) 

sage: N = k.ideal(3, a - 1) 

sage: psi(N) 

4 

 

:: 

 

sage: k.<a> = NumberField(x^2 + 23) 

sage: N = k.ideal(5) 

sage: psi(N) 

26 

""" 

if not N.is_integral(): 

raise ValueError("psi only defined for integral ideals") 

 

from sage.misc.all import prod 

return prod([(np+1)*np**(e-1) \ 

for np,e in [(p.absolute_norm(),e) \ 

for p,e in N.factor()]])