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

""" 

Submodules of Hecke modules 

""" 

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

# Sage: System for Algebra and Geometry Experimentation 

# 

# 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 absolute_import 

 

import sage.arith.all as arith 

import sage.misc.misc as misc 

from sage.misc.cachefunc import cached_method 

from sage.structure.richcmp import richcmp_method, richcmp_not_equal, richcmp 

import sage.modules.all 

 

from . import module 

 

 

 

def is_HeckeSubmodule(x): 

r""" 

Return True if x is of type HeckeSubmodule. 

 

EXAMPLES:: 

 

sage: sage.modular.hecke.submodule.is_HeckeSubmodule(ModularForms(1, 12)) 

False 

sage: sage.modular.hecke.submodule.is_HeckeSubmodule(CuspForms(1, 12)) 

True 

""" 

return isinstance(x, HeckeSubmodule) 

 

 

@richcmp_method 

class HeckeSubmodule(module.HeckeModule_free_module): 

""" 

Submodule of a Hecke module. 

""" 

def __init__(self, ambient, submodule, dual_free_module=None, check=True): 

r""" 

Initialise a submodule of an ambient Hecke module. 

 

INPUT: 

 

- ``ambient`` - an ambient Hecke module 

 

- ``submodule`` - a free module over the base ring which is a submodule 

of the free module attached to the ambient Hecke module. This should 

be invariant under all Hecke operators. 

 

- ``dual_free_module`` - the submodule of the dual of the ambient 

module corresponding to this submodule (or None). 

 

- ``check`` - whether or not to explicitly check that the submodule is 

Hecke equivariant. 

 

EXAMPLES:: 

 

sage: CuspForms(1,60) # indirect doctest 

Cuspidal subspace of dimension 5 of Modular Forms space of dimension 6 for Modular Group SL(2,Z) of weight 60 over Rational Field 

 

sage: M = ModularForms(4,10) 

sage: S = sage.modular.hecke.submodule.HeckeSubmodule(M, M.submodule(M.basis()[:3]).free_module()) 

sage: S 

Rank 3 submodule of a Hecke module of level 4 

 

sage: S == loads(dumps(S)) 

True 

""" 

from . import ambient_module 

if not isinstance(ambient, ambient_module.AmbientHeckeModule): 

raise TypeError("ambient must be an ambient Hecke module") 

if not sage.modules.free_module.is_FreeModule(submodule): 

raise TypeError("submodule must be a free module") 

if not submodule.is_submodule(ambient.free_module()): 

raise ValueError("submodule must be a submodule of the ambient free module") 

 

if check: 

if not ambient._is_hecke_equivariant_free_module(submodule): 

raise ValueError("The submodule must be invariant under all Hecke operators.") 

 

self.__ambient = ambient 

self.__submodule = submodule 

module.HeckeModule_free_module.__init__(self, 

ambient.base_ring(), ambient.level(), ambient.weight()) 

if not (dual_free_module is None): 

if not sage.modules.free_module.is_FreeModule(dual_free_module): 

raise TypeError("dual_free_module must be a free module") 

if dual_free_module.rank () != submodule.rank(): 

raise ArithmeticError("dual_free_module must have the same rank as submodule") 

self.dual_free_module.set_cache(dual_free_module) 

 

 

def _repr_(self): 

r""" 

String representation of self. 

 

EXAMPLES:: 

 

sage: M = ModularForms(4,10) 

sage: S = sage.modular.hecke.submodule.HeckeSubmodule(M, M.submodule(M.basis()[:3]).free_module()) 

sage: S._repr_() 

'Rank 3 submodule of a Hecke module of level 4' 

""" 

return "Rank %s submodule of a Hecke module of level %s"%( 

self.rank(), self.level()) 

 

def __add__(self, other): 

r""" 

Sum of self and other (as submodules of a common ambient 

module). 

 

EXAMPLES:: 

 

sage: M = ModularForms(4,10) 

sage: S = sage.modular.hecke.submodule.HeckeSubmodule(M, M.submodule(M.basis()[:3]).free_module()) 

sage: E = sage.modular.hecke.submodule.HeckeSubmodule(M, M.submodule(M.basis()[3:]).free_module()) 

sage: S + E # indirect doctest 

Modular Forms subspace of dimension 6 of Modular Forms space of dimension 6 for Congruence Subgroup Gamma0(4) of weight 10 over Rational Field 

""" 

if not isinstance(other, module.HeckeModule_free_module): 

raise TypeError("other (=%s) must be a Hecke module."%other) 

if self.ambient() != other.ambient(): 

raise ArithmeticError("Sum only defined for submodules of a common ambient space.") 

if other.is_ambient(): 

return other 

# Neither is ambient 

M = self.free_module() + other.free_module() 

return self.ambient().submodule(M, check=False) 

 

def _element_constructor_(self, x, check=True): 

""" 

Coerce x into the ambient module and checks that x is in this 

submodule. 

 

EXAMPLES:: 

 

sage: M = ModularSymbols(37) 

sage: S = M.cuspidal_submodule() 

sage: M([0,oo]) 

-(1,0) 

sage: S([0,oo]) 

Traceback (most recent call last): 

... 

TypeError: x does not coerce to an element of this Hecke module 

sage: S([-1/23,0]) 

(1,23) 

""" 

z = self.ambient_hecke_module()(x).element() 

if check and not z in self.__submodule: 

raise TypeError("x does not coerce to an element of this Hecke module") 

return self.element_class(self, z) 

 

def __richcmp__(self, other, op): 

""" 

Compare self to other. 

 

EXAMPLES:: 

 

sage: M = ModularSymbols(12,6) 

sage: S = sage.modular.hecke.submodule.HeckeSubmodule(M, M.cuspidal_submodule().free_module()) 

sage: T = sage.modular.hecke.submodule.HeckeSubmodule(M, M.new_submodule().free_module()) 

sage: S 

Rank 14 submodule of a Hecke module of level 12 

sage: T 

Rank 0 submodule of a Hecke module of level 12 

sage: S > T 

True 

sage: T < S 

True 

sage: S == S 

True 

""" 

if not isinstance(other, module.HeckeModule_free_module): 

return NotImplemented 

lx = self.ambient() 

rx = other.ambient() 

if lx != rx: 

return richcmp_not_equal(lx, rx, op) 

return self.free_module()._echelon_matrix_richcmp(other.free_module(), op) 

 

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

# Semi-Private functions 

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

def _compute_dual_hecke_matrix(self, n): 

""" 

Compute the matrix for the nth Hecke operator acting on 

the dual of self. 

 

EXAMPLES:: 

 

sage: M = ModularForms(4,10) 

sage: S = sage.modular.hecke.submodule.HeckeSubmodule(M, M.submodule(M.basis()[:3]).free_module()) 

sage: S._compute_dual_hecke_matrix(3) 

[ 0 0 1] 

[ 0 -156 0] 

[35568 0 72] 

sage: CuspForms(4,10).dual_hecke_matrix(3) 

[ 0 0 1] 

[ 0 -156 0] 

[35568 0 72] 

""" 

A = self.ambient_hecke_module().dual_hecke_matrix(n) 

check = arith.gcd(self.level(), n) != 1 

return A.restrict(self.dual_free_module(), check=check) 

 

def _compute_hecke_matrix(self, n): 

r""" 

Compute the matrix of the nth Hecke operator acting on this space, by 

calling the corresponding function for the ambient space and 

restricting. If n is not coprime to the level, we check that the 

restriction is well-defined. 

 

EXAMPLES:: 

 

sage: R.<q> = QQ[[]] 

sage: M = ModularForms(2, 12) 

sage: f = M(q^2 - 24*q^4 + O(q^6)) 

sage: A = M.submodule(M.free_module().span([f.element()]),check=False) 

sage: sage.modular.hecke.submodule.HeckeSubmodule._compute_hecke_matrix(A, 3) 

[252] 

sage: sage.modular.hecke.submodule.HeckeSubmodule._compute_hecke_matrix(A, 4) 

Traceback (most recent call last): 

... 

ArithmeticError: subspace is not invariant under matrix 

""" 

A = self.ambient_hecke_module().hecke_matrix(n) 

check = arith.gcd(self.level(), n) != 1 

return A.restrict(self.free_module(), check=check) 

 

def _compute_diamond_matrix(self, d): 

r""" 

EXAMPLES: 

 

sage: f = ModularSymbols(Gamma1(13),2,sign=1).cuspidal_subspace().decomposition()[0] 

sage: a = f.diamond_bracket_operator(2).matrix() # indirect doctest 

sage: a.charpoly() 

x^2 - x + 1 

sage: a^12 

[1 0] 

[0 1] 

""" 

return self.ambient_hecke_module().diamond_bracket_matrix(d).restrict(self.free_module(), check=False) 

 

def _compute_atkin_lehner_matrix(self, d): 

""" 

Compute the Atkin-Lehner matrix corresponding to the 

divisor d of the level of self. 

 

EXAMPLES:: 

 

sage: M = ModularSymbols(4,10) 

sage: S = sage.modular.hecke.submodule.HeckeSubmodule(M, M.cuspidal_submodule().free_module()) 

sage: S 

Rank 6 submodule of a Hecke module of level 4 

sage: S._compute_atkin_lehner_matrix(1) 

[1 0 0 0 0 0] 

[0 1 0 0 0 0] 

[0 0 1 0 0 0] 

[0 0 0 1 0 0] 

[0 0 0 0 1 0] 

[0 0 0 0 0 1] 

""" 

A = self.ambient_hecke_module()._compute_atkin_lehner_matrix(d) 

return A.restrict(self.free_module(), check=True) 

 

def _set_dual_free_module(self, V): 

""" 

Set the dual free module of self to V. Here V must be a vector 

space of the same dimension as self, embedded in a space of 

the same dimension as the ambient space of self. 

 

EXAMPLES:: 

 

sage: M = ModularSymbols(4,10) 

sage: S = sage.modular.hecke.submodule.HeckeSubmodule(M, M.cuspidal_submodule().free_module()) 

sage: S._set_dual_free_module(M.cuspidal_submodule().dual_free_module()) 

sage: S._set_dual_free_module(S) 

""" 

if V.degree() != self.ambient_hecke_module().rank(): 

raise ArithmeticError("The degree of V must equal the rank of the ambient space.") 

if V.rank() != self.rank(): 

raise ArithmeticError("The rank of V must equal the rank of self.") 

self.dual_free_module.set_cache(V) 

 

 

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

# Public functions 

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

 

def ambient_hecke_module(self): 

r""" 

Return the ambient Hecke module of which this is a submodule. 

 

EXAMPLES:: 

 

sage: CuspForms(2, 12).ambient_hecke_module() 

Modular Forms space of dimension 4 for Congruence Subgroup Gamma0(2) of weight 12 over Rational Field 

""" 

return self.__ambient 

 

def ambient(self): 

r""" 

Synonym for ambient_hecke_module. 

 

EXAMPLES:: 

 

sage: CuspForms(2, 12).ambient() 

Modular Forms space of dimension 4 for Congruence Subgroup Gamma0(2) of weight 12 over Rational Field 

""" 

return self.__ambient 

 

@cached_method 

def complement(self, bound=None): 

""" 

Return the largest Hecke-stable complement of this space. 

 

EXAMPLES:: 

 

sage: M = ModularSymbols(15, 6).cuspidal_subspace() 

sage: M.complement() 

Modular Symbols subspace of dimension 4 of Modular Symbols space of dimension 20 for Gamma_0(15) of weight 6 with sign 0 over Rational Field 

sage: E = EllipticCurve("128a") 

sage: ME = E.modular_symbol_space() 

sage: ME.complement() 

Modular Symbols subspace of dimension 17 of Modular Symbols space of dimension 18 for Gamma_0(128) of weight 2 with sign 1 over Rational Field 

""" 

 

if self.dual_free_module.is_in_cache(): 

D = self.dual_free_module() 

V = D.basis_matrix().right_kernel() 

return self.submodule(V, check=False) 

 

if self.is_ambient(): 

return self.ambient_hecke_module().zero_submodule() 

 

if self.is_zero(): 

return self.ambient_hecke_module() 

 

if self.is_full_hecke_module(): 

anemic = False 

else: 

anemic = True 

 

# TODO: optimize in some cases by computing image of 

# complementary factor instead of kernel...? 

misc.verbose("computing") 

N = self.level() 

A = self.ambient_hecke_module() 

V = A.free_module() 

p = 2 

if bound is None: 

bound = A.hecke_bound() 

while True: 

if anemic: 

while N % p == 0: p = arith.next_prime(p) 

misc.verbose("using T_%s"%p) 

f = self.hecke_polynomial(p) 

T = A.hecke_matrix(p) 

g = T.charpoly('x') 

V = T.kernel_on(V, poly=g//f, check=False) 

if V.rank() + self.rank() <= A.rank(): 

break 

p = arith.next_prime(p) 

if p > bound: # to avoid computing Hecke bound unless necessary 

break 

 

if V.rank() + self.rank() == A.rank(): 

C = A.submodule(V, check=False) 

return C 

 

# first attempt to compute the complement failed, we now try 

# the following naive approach: decompose the ambient space, 

# decompose self, and sum the pieces of ambient that are not 

# subspaces of self 

misc.verbose("falling back on naive algorithm") 

D = A.decomposition() 

C = A.zero_submodule() 

for X in D: 

if self.intersection(X).dimension() == 0: 

C = C + X 

if C.rank() + self.rank() == A.rank(): 

return C 

 

# failed miserably 

raise RuntimeError("Computation of complementary space failed (cut down to rank %s, but should have cut down to rank %s)."%(V.rank(), A.rank()-self.rank())) 

 

 

def degeneracy_map(self, level, t=1): 

""" 

The t-th degeneracy map from self to the space of ambient modular 

symbols of the given level. The level of self must be a divisor or 

multiple of level, and t must be a divisor of the quotient. 

 

INPUT: 

 

 

- ``level`` - int, the level of the codomain of the 

map (positive int). 

 

- ``t`` - int, the parameter of the degeneracy map, 

i.e., the map is related to `f(q)` - `f(q^t)`. 

 

 

OUTPUT: A linear function from self to the space of modular symbols 

of given level with the same weight, character, sign, etc., as this 

space. 

 

EXAMPLES:: 

 

sage: D = ModularSymbols(10,4).cuspidal_submodule().decomposition(); D 

[ 

Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 10 for Gamma_0(10) of weight 4 with sign 0 over Rational Field, 

Modular Symbols subspace of dimension 4 of Modular Symbols space of dimension 10 for Gamma_0(10) of weight 4 with sign 0 over Rational Field 

] 

sage: d = D[1].degeneracy_map(5); d 

Hecke module morphism defined by the matrix 

[ 0 0 -1 1] 

[ 0 1/2 3/2 -2] 

[ 0 -1 1 0] 

[ 0 -3/4 -1/4 1] 

Domain: Modular Symbols subspace of dimension 4 of Modular Symbols space ... 

Codomain: Modular Symbols space of dimension 4 for Gamma_0(5) of weight ... 

 

:: 

 

sage: d.rank() 

2 

sage: d.kernel() 

Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 10 for Gamma_0(10) of weight 4 with sign 0 over Rational Field 

sage: d.image() 

Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 4 for Gamma_0(5) of weight 4 with sign 0 over Rational Field 

""" 

d = self.ambient_hecke_module().degeneracy_map(level, t) 

return d.restrict_domain(self) 

 

 

@cached_method 

def dual_free_module(self, bound=None, anemic=True, use_star=True): 

r""" 

Compute embedded dual free module if possible. In general this won't be 

possible, e.g., if this space is not Hecke equivariant, possibly if it 

is not cuspidal, or if the characteristic is not 0. In all these cases 

we raise a RuntimeError exception. 

 

If use_star is True (which is the default), we also use the +/- 

eigenspaces for the star operator to find the dual free module of self. 

If self does not have a star involution, use_star will automatically be 

set to False. 

 

EXAMPLES:: 

 

sage: M = ModularSymbols(11, 2) 

sage: M.dual_free_module() 

Vector space of dimension 3 over Rational Field 

sage: Mpc = M.plus_submodule().cuspidal_submodule() 

sage: Mcp = M.cuspidal_submodule().plus_submodule() 

sage: Mcp.dual_free_module() == Mpc.dual_free_module() 

True 

sage: Mpc.dual_free_module() 

Vector space of degree 3 and dimension 1 over Rational Field 

Basis matrix: 

[ 1 5/2 5] 

 

sage: M = ModularSymbols(35,2).cuspidal_submodule() 

sage: M.dual_free_module(use_star=False) 

Vector space of degree 9 and dimension 6 over Rational Field 

Basis matrix: 

[ 1 0 0 0 -1 0 0 4 -2] 

[ 0 1 0 0 0 0 0 -1/2 1/2] 

[ 0 0 1 0 0 0 0 -1/2 1/2] 

[ 0 0 0 1 -1 0 0 1 0] 

[ 0 0 0 0 0 1 0 -2 1] 

[ 0 0 0 0 0 0 1 -2 1] 

 

sage: M = ModularSymbols(40,2) 

sage: Mmc = M.minus_submodule().cuspidal_submodule() 

sage: Mcm = M.cuspidal_submodule().minus_submodule() 

sage: Mcm.dual_free_module() == Mmc.dual_free_module() 

True 

sage: Mcm.dual_free_module() 

Vector space of degree 13 and dimension 3 over Rational Field 

Basis matrix: 

[ 0 1 0 0 0 0 1 0 -1 -1 1 -1 0] 

[ 0 0 1 0 -1 0 -1 0 1 0 0 0 0] 

[ 0 0 0 0 0 1 1 0 -1 0 0 0 0] 

 

sage: M = ModularSymbols(43).cuspidal_submodule() 

sage: S = M[0].plus_submodule() + M[1].minus_submodule() 

sage: S.dual_free_module(use_star=False) 

Traceback (most recent call last): 

... 

RuntimeError: Computation of complementary space failed (cut down to rank 7, but should have cut down to rank 4). 

sage: S.dual_free_module().dimension() == S.dimension() 

True 

 

We test that :trac:`5080` is fixed:: 

 

sage: EllipticCurve('128a').congruence_number() 

32 

 

""" 

 

# if we know the complement we can read off the dual module 

if self.complement.is_in_cache(): 

misc.verbose('This module knows its complement already -- cheating in dual_free_module') 

C = self.complement() 

V = C.basis_matrix().right_kernel() 

return V 

 

misc.verbose("computing dual") 

 

A = self.ambient_hecke_module() 

 

if self.dimension() == 0: 

return A.zero_submodule() 

 

if A.dimension() == self.dimension(): 

return A.free_module() 

 

# ALGORITHM: Compute the char poly of each Hecke operator on 

# the submodule, then use it to cut out a submodule of the 

# dual. If the dimension cuts down to the dimension of self 

# terminate with success. If it stays larger beyond the Sturm 

# bound, raise a RuntimeError exception. 

 

# In the case that the sign of self is not 1, we need to use 

# the star involution as well as the Hecke operators in order 

# to find the dual of self. 

# 

# Note that one needs to comment out the line caching the 

# result of this computation below in order to get meaningful 

# timings. 

 

# If the star involution doesn't make sense for self, then we 

# can't use it. 

if not hasattr(self, 'star_eigenvalues'): 

use_star = False 

 

if use_star: 

# If the star involution has both + and - eigenspaces on self, 

# then we compute the dual on each eigenspace, then put them 

# together. 

if len(self.star_eigenvalues()) == 2: 

V = self.plus_submodule(compute_dual = False).dual_free_module() + \ 

self.minus_submodule(compute_dual = False).dual_free_module() 

return V 

 

# At this point, we know that self is an eigenspace for star. 

V = A.sign_submodule(self.sign()).dual_free_module() 

else: 

V = A.free_module() 

 

N = self.level() 

p = 2 

if bound is None: 

bound = A.hecke_bound() 

while True: 

if anemic: 

while N % p == 0: p = arith.next_prime(p) 

misc.verbose("using T_%s"%p) 

f = self.hecke_polynomial(p) 

T = A.dual_hecke_matrix(p) 

V = T.kernel_on(V, poly=f, check=False) 

if V.dimension() <= self.dimension(): 

break 

p = arith.next_prime(p) 

if p > bound: 

break 

 

if V.rank() == self.rank(): 

return V 

else: 

# Failed to reduce V to the appropriate dimension 

W = self.complement() 

V2 = W.basis_matrix().right_kernel() 

if V2.rank() == self.rank(): 

return V2 

else: 

raise RuntimeError("Computation of embedded dual vector space failed " + \ 

"(cut down to rank %s, but should have cut down to rank %s)."%(V.rank(), self.rank())) 

 

 

def free_module(self): 

""" 

Return the free module corresponding to self. 

 

EXAMPLES:: 

 

sage: M = ModularSymbols(33,2).cuspidal_subspace() ; M 

Modular Symbols subspace of dimension 6 of Modular Symbols space of dimension 9 for Gamma_0(33) of weight 2 with sign 0 over Rational Field 

sage: M.free_module() 

Vector space of degree 9 and dimension 6 over Rational Field 

Basis matrix: 

[ 0 1 0 0 0 0 0 -1 1] 

[ 0 0 1 0 0 0 0 -1 1] 

[ 0 0 0 1 0 0 0 -1 1] 

[ 0 0 0 0 1 0 0 -1 1] 

[ 0 0 0 0 0 1 0 -1 1] 

[ 0 0 0 0 0 0 1 -1 0] 

""" 

return self.__submodule 

 

def module(self): 

r""" 

Alias for \code{self.free_module()}. 

 

EXAMPLES:: 

 

sage: M = ModularSymbols(17,4).cuspidal_subspace() 

sage: M.free_module() is M.module() 

True 

""" 

return self.free_module() 

 

def intersection(self, other): 

""" 

Returns the intersection of self and other, which must both lie in 

a common ambient space of modular symbols. 

 

EXAMPLES:: 

 

sage: M = ModularSymbols(43, sign=1) 

sage: A = M[0] + M[1] 

sage: B = M[1] + M[2] 

sage: A.dimension(), B.dimension() 

(2, 3) 

sage: C = A.intersection(B); C.dimension() 

1 

 

TESTS:: 

 

sage: M = ModularSymbols(1,80) 

sage: M.plus_submodule().cuspidal_submodule().sign() # indirect doctest 

1 

""" 

if self.ambient_hecke_module() != other.ambient_hecke_module(): 

raise ArithmeticError("Intersection only defined for subspaces of"\ 

+ " a common ambient modular symbols space.") 

if other.is_ambient(): 

return self 

if self.is_ambient(): 

return other 

 

# Neither is ambient 

V = self.free_module().intersection(other.free_module()) 

M = self.ambient_hecke_module().submodule(V,check=False) 

 

## if sign is nonzero, the intersection will be, too 

## this only makes sense for modular symbols spaces (and hence shouldn't really be in this file) 

try: 

if self.sign(): 

M._set_sign(self.sign()) 

elif other.sign(): 

M._set_sign(other.sign()) 

except AttributeError: 

pass 

 

return M 

 

def is_ambient(self): 

r""" 

Return ``True`` if self is an ambient space of modular 

symbols. 

 

EXAMPLES:: 

 

sage: M = ModularSymbols(17,4) 

sage: M.cuspidal_subspace().is_ambient() 

False 

sage: A = M.ambient_hecke_module() 

sage: S = A.submodule(A.basis()) 

sage: sage.modular.hecke.submodule.HeckeSubmodule.is_ambient(S) 

True 

""" 

return self.free_module() == self.ambient_hecke_module().free_module() 

 

def is_new(self, p=None): 

""" 

Returns True if this Hecke module is p-new. If p is None, 

returns True if it is new. 

 

EXAMPLES:: 

 

sage: M = ModularSymbols(1,16) 

sage: S = sage.modular.hecke.submodule.HeckeSubmodule(M, M.cuspidal_submodule().free_module()) 

sage: S.is_new() 

True 

""" 

try: 

return self.__is_new[p] 

except AttributeError: 

self.__is_new = {} 

except KeyError: 

pass 

N = self.ambient_hecke_module().new_submodule(p) 

self.__is_new[p] = self.is_submodule(N) 

return self.__is_new[p] 

 

def is_old(self, p=None): 

""" 

Returns True if this Hecke module is p-old. If p is None, 

returns True if it is old. 

 

EXAMPLES:: 

 

sage: M = ModularSymbols(50,2) 

sage: S = sage.modular.hecke.submodule.HeckeSubmodule(M, M.old_submodule().free_module()) 

sage: S.is_old() 

True 

sage: S = sage.modular.hecke.submodule.HeckeSubmodule(M, M.new_submodule().free_module()) 

sage: S.is_old() 

False 

""" 

try: 

return self.__is_old[p] 

except AttributeError: 

self.__is_old = {} 

except KeyError: 

pass 

O = self.ambient_hecke_module().old_submodule(p) 

self.__is_old[p] = self.is_submodule(O) 

return self.__is_old[p] 

 

def is_submodule(self, V): 

""" 

Returns True if and only if self is a submodule of V. 

 

EXAMPLES:: 

 

sage: M = ModularSymbols(30,4) 

sage: S = sage.modular.hecke.submodule.HeckeSubmodule(M, M.cuspidal_submodule().free_module()) 

sage: S.is_submodule(M) 

True 

sage: SS = sage.modular.hecke.submodule.HeckeSubmodule(M, M.old_submodule().free_module()) 

sage: S.is_submodule(SS) 

False 

""" 

if not isinstance(V, module.HeckeModule_free_module): 

return False 

return self.ambient_hecke_module() == V.ambient_hecke_module() and \ 

self.free_module().is_subspace(V.free_module()) 

 

def linear_combination_of_basis(self, v): 

""" 

Return the linear combination of the basis of ``self`` given 

by the entries of `v`. 

 

The result can be of different types, and is printed 

accordingly, depending on the type of submodule. 

 

EXAMPLES:: 

 

sage: M = ModularForms(Gamma0(2),12) 

 

sage: S = sage.modular.hecke.submodule.HeckeSubmodule(M, M.cuspidal_submodule().free_module()) 

sage: S.basis() 

((1, 0, 0, 0), (0, 1, 0, 0)) 

sage: S.linear_combination_of_basis([3, 10]) 

(3, 10, 0, 0) 

 

sage: S = M.cuspidal_submodule() 

sage: S.basis() 

[ 

q + 252*q^3 - 2048*q^4 + 4830*q^5 + O(q^6), 

q^2 - 24*q^4 + O(q^6) 

] 

sage: S.linear_combination_of_basis([3, 10]) 

3*q + 10*q^2 + 756*q^3 - 6384*q^4 + 14490*q^5 + O(q^6) 

 

""" 

x = self.free_module().linear_combination_of_basis(v) 

return self(x) 

 

def new_submodule(self, p=None): 

""" 

Return the new or p-new submodule of this space of modular 

symbols. 

 

EXAMPLES:: 

 

sage: M = ModularSymbols(20,4) 

sage: M.new_submodule() 

Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 18 for Gamma_0(20) of weight 4 with sign 0 over Rational Field 

sage: S = sage.modular.hecke.submodule.HeckeSubmodule(M, M.cuspidal_submodule().free_module()) 

sage: S 

Rank 12 submodule of a Hecke module of level 20 

sage: S.new_submodule() 

Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 18 for Gamma_0(20) of weight 4 with sign 0 over Rational Field 

""" 

try: 

if self.__is_new[p]: 

return self 

except AttributeError: 

self.__is_new = {} 

except KeyError: 

pass 

 

if self.rank() == 0: 

self.__is_new[p] = True 

return self 

try: 

return self.__new_submodule[p] 

except AttributeError: 

self.__new_submodule = {} 

except KeyError: 

pass 

 

S = self.ambient_hecke_module().new_submodule(p) 

ns = S.intersection(self) 

if ns.rank() == self.rank(): 

self.__is_new[p] = True 

ns.__is_new = {p:True} 

self.__new_submodule[p] = ns 

return ns 

 

def nonembedded_free_module(self): 

""" 

Return the free module corresponding to self as an abstract 

free module, i.e. not as an embedded vector space. 

 

EXAMPLES:: 

 

sage: M = ModularSymbols(12,6) 

sage: S = sage.modular.hecke.submodule.HeckeSubmodule(M, M.cuspidal_submodule().free_module()) 

sage: S 

Rank 14 submodule of a Hecke module of level 12 

sage: S.nonembedded_free_module() 

Vector space of dimension 14 over Rational Field 

""" 

return self.free_module().nonembedded_free_module() 

 

def old_submodule(self, p=None): 

""" 

Return the old or p-old submodule of this space of modular 

symbols. 

 

EXAMPLES: We compute the old and new submodules of 

`\mathbf{S}_2(\Gamma_0(33))`. 

 

:: 

 

sage: M = ModularSymbols(33); S = M.cuspidal_submodule(); S 

Modular Symbols subspace of dimension 6 of Modular Symbols space of dimension 9 for Gamma_0(33) of weight 2 with sign 0 over Rational Field 

sage: S.old_submodule() 

Modular Symbols subspace of dimension 4 of Modular Symbols space of dimension 9 for Gamma_0(33) of weight 2 with sign 0 over Rational Field 

sage: S.new_submodule() 

Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 9 for Gamma_0(33) of weight 2 with sign 0 over Rational Field 

""" 

try: 

if self.__is_old[p]: 

return self 

except AttributeError: 

self.__is_old = {} 

except KeyError: 

pass 

 

if self.rank() == 0: 

self.__is_old[p] = True 

return self 

try: 

return self.__old_submodule[p] 

except AttributeError: 

self.__old_submodule = {} 

except KeyError: 

pass 

 

S = self.ambient_hecke_module().old_submodule(p) 

os = S.intersection(self) 

if os.rank() == self.rank(): 

self.__is_old[p] = True 

os.__is_old = {p:True} 

self.__old_submodule[p] = os 

return os 

 

def rank(self): 

r""" 

Return the rank of self as a free module over the base ring. 

 

EXAMPLES:: 

 

sage: ModularSymbols(6, 4).cuspidal_subspace().rank() 

2 

sage: ModularSymbols(6, 4).cuspidal_subspace().dimension() 

2 

""" 

return self.__submodule.rank() 

 

def submodule(self, M, Mdual=None, check=True): 

""" 

Construct a submodule of self from the free module M, which 

must be a subspace of self. 

 

EXAMPLES:: 

 

sage: M = ModularSymbols(18,4) 

sage: S = sage.modular.hecke.submodule.HeckeSubmodule(M, M.cuspidal_submodule().free_module()) 

sage: S[0] 

Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 18 for Gamma_0(18) of weight 4 with sign 0 over Rational Field 

sage: S.submodule(S[0].free_module()) 

Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 18 for Gamma_0(18) of weight 4 with sign 0 over Rational Field 

""" 

from . import ambient_module 

if not sage.modules.free_module.is_FreeModule(M): 

V = self.ambient_module().free_module() 

if isinstance(M, (list,tuple)): 

M = V.span([V(x.element()) for x in M]) 

else: 

M = V.span(M) 

 

if check: 

if not M.is_submodule(self.free_module()): 

raise TypeError("M (=%s) must be a submodule of the free module (=%s) associated to this module."%(M, self.free_module())) 

 

return self.ambient().submodule(M, Mdual, check=check) 

 

def submodule_from_nonembedded_module(self, V, Vdual=None, check=True): 

""" 

Construct a submodule of self from V. Here V should be a 

subspace of a vector space whose dimension is the same as that 

of self. 

 

INPUT: 

 

 

- ``V`` - submodule of ambient free module of the same 

rank as the rank of self. 

 

- ``check`` - whether to check that V is Hecke 

equivariant. 

 

 

OUTPUT: Hecke submodule of self 

 

EXAMPLES:: 

 

sage: M = ModularSymbols(37,2) 

sage: S = sage.modular.hecke.submodule.HeckeSubmodule(M, M.cuspidal_submodule().free_module()) 

sage: V = (QQ**4).subspace([[1,-1,0,1/2],[0,0,1,-1/2]]) 

sage: S.submodule_from_nonembedded_module(V) 

Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 5 for Gamma_0(37) of weight 2 with sign 0 over Rational Field 

""" 

E = self.free_module() 

M_V = V.matrix() 

M_E = E.matrix() 

# We encode the operation of taking the linear combinations of 

# the basis of E given by the basis of V as a single matrix 

# multiplication, since matrix multiplication is (presumed to be) 

# so fast, and their are asymptotically fast algorithms. 

A = M_V * M_E 

V = A.row_space() 

if not (Vdual is None): 

E = self.dual_free_module() 

M_Vdual = Vdual.matrix() 

M_E = E.matrix() 

A = M_Vdual * M_E 

Vdual = A.row_space() 

return self.ambient_hecke_module().submodule(V, Vdual, check=check) 

 

def hecke_bound(self): 

""" 

Compute the Hecke bound for self; that is, a number n such that the 

T_m for m = n generate the Hecke algebra. 

 

EXAMPLES:: 

 

sage: M = ModularSymbols(24,8) 

sage: M.hecke_bound() 

53 

sage: M.cuspidal_submodule().hecke_bound() 

32 

sage: M.eisenstein_submodule().hecke_bound() 

53 

""" 

if self.is_cuspidal(): 

return self.sturm_bound() 

else: 

return self.ambient_hecke_module().hecke_bound()