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

""" 

Database of Modular Polynomials 

""" 

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

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

# Copyright (C) 2006 David Kohel <kohel@maths.usyd.edu.au> 

# Copyright (C) 2016 Vincent Delecroix <vincent.delecroix@labri.fr> 

# 

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

# as published by the Free Software Foundation; either version 2 of 

# the License, or (at your option) any later version. 

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

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

 

from __future__ import print_function, absolute_import 

 

def _dbz_to_string(name): 

r""" 

TESTS:: 

 

sage: from sage.databases.db_modular_polynomials import _dbz_to_string 

sage: _dbz_to_string('PolMod/Atk/pol.002.dbz') # optional - database_kohel 

'3 0 1 \n2 1 -1 \n2 0 744 \n1 1 -1 \n1 0 184512 \n0 2 1 \n0 1 7256 \n0 0 15252992 \n' 

sage: _dbz_to_string('PolMod/Cls/pol.001.dbz') # optional - database_kohel 

'1 0 1 \n' 

sage: _dbz_to_string('PolMod/Eta/pol.002.dbz') # optional - database_kohel 

'3 0 1 \n2 0 48 \n1 1 -1 \n1 0 768 \n0 0 4096 \n' 

sage: _dbz_to_string('PolMod/EtaCrr/crr.02.002.dbz') # optional - database_kohel 

'2 1 1 \n2 0 -48 \n1 1 2304 \n0 2 -4096 \n0 1 196608 \n' 

sage: _dbz_to_string('PolHeeg/Cls/0000001-0005000/pol.0000003.dbz') # optional - database_kohel 

'0\n1\n' 

""" 

import bz2, os 

from sage.env import SAGE_SHARE 

dblocation = os.path.join(SAGE_SHARE, 'kohel') 

filename = os.path.join(dblocation, name) 

 

try: 

f = open(filename) 

except IOError: 

raise LookupError("filename {} does not exist".format(filename)) 

 

data = bz2.decompress(f.read()) 

 

return data 

 

def _dbz_to_integer_list(name): 

r""" 

TESTS:: 

 

sage: from sage.databases.db_modular_polynomials import _dbz_to_integer_list 

sage: _dbz_to_integer_list('PolMod/Atk/pol.002.dbz') # optional - database_kohel 

[[3, 0, 1], 

[2, 1, -1], 

[2, 0, 744], 

[1, 1, -1], 

[1, 0, 184512], 

[0, 2, 1], 

[0, 1, 7256], 

[0, 0, 15252992]] 

sage: _dbz_to_integer_list('PolMod/Cls/pol.001.dbz') # optional - database_kohel 

[[1, 0, 1]] 

sage: _dbz_to_integer_list('PolMod/Eta/pol.002.dbz') # optional - database_kohel 

[[3, 0, 1], [2, 0, 48], [1, 1, -1], [1, 0, 768], [0, 0, 4096]] 

""" 

from sage.rings.integer import Integer 

data = _dbz_to_string(name) 

return [[Integer(v) for v in row.strip().split(" ")] 

for row in data.split("\n")[:-1]] 

 

 

def _dbz_to_integers(name): 

r""" 

TESTS:: 

 

sage: from sage.databases.db_modular_polynomials import _dbz_to_integers 

sage: _dbz_to_integers('PolHeeg/Cls/0000001-0005000/pol.0000003.dbz') # optional - database_kohel 

[0, 1] 

""" 

from sage.rings.integer import Integer 

return [Integer(i) for i in _dbz_to_string(name).split()] 

 

 

class ModularPolynomialDatabase: 

def _dbpath(self, level): 

r""" 

TESTS:: 

 

sage: C = ClassicalModularPolynomialDatabase() 

sage: C._dbpath(3) 

'PolMod/Cls/pol.003.dbz' 

sage: C._dbpath(8) 

'PolMod/Cls/pol.008.dbz' 

""" 

return "PolMod/%s/pol.%03d.dbz" % (self.model, level) 

 

def __repr__(self): 

r""" 

EXAMPLES:: 

 

sage: ClassicalModularPolynomialDatabase() 

Classical modular polynomial database 

 

sage: DedekindEtaModularPolynomialDatabase() 

Dedekind eta modular polynomial database 

sage: DedekindEtaModularPolynomialDatabase() 

Dedekind eta modular polynomial database 

 

sage: AtkinModularPolynomialDatabase() 

Atkin modular polynomial database 

""" 

if self.model.startswith("Cls"): 

head = "Classical" 

elif self.model.startswith("Atk"): 

head = "Atkin" 

elif self.model.startswith("Eta"): 

head = "Dedekind eta" 

 

if self.model.endswith("Crr"): 

poly = "correspondence" 

else: 

poly = "polynomial" 

 

return "%s modular %s database"%(head,poly) 

 

def __getitem__(self, level): 

""" 

Return the modular polynomial of given level, or an error if 

there is no such polynomial in the database. 

 

EXAMPLES:: 

 

sage: DBMP = ClassicalModularPolynomialDatabase() 

sage: f = DBMP[29] # optional - database_kohel 

sage: f.degree() # optional - database_kohel 

58 

sage: f.coefficient([28,28]) # optional - database_kohel 

400152899204646997840260839128 

 

sage: DBMP[50] # optional - database_kohel 

Traceback (most recent call last): 

... 

LookupError: filename .../kohel/PolMod/Cls/pol.050.dbz does not exist 

""" 

from sage.rings.integer import Integer 

from sage.rings.integer_ring import IntegerRing 

from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing 

 

if self.model in ("Atk","Eta"): 

level = Integer(level) 

if not level.is_prime(): 

raise TypeError("Argument level (= %s) must be prime."%level) 

elif self.model in ("AtkCrr","EtaCrr"): 

N = Integer(level[0]) 

if not N in (2,3,5,7,13): 

raise TypeError("Argument level (= %s) must be prime."%N) 

modpol = self._dbpath(level) 

coeff_list = _dbz_to_integer_list(modpol) 

if self.model == "Cls": 

P = PolynomialRing(IntegerRing(),2,"j") 

else: 

P = PolynomialRing(IntegerRing(),2,"x,j") 

poly = {} 

if self.model == "Cls": 

if level == 1: 

return P({(1,0):1,(0,1):-1}) 

for cff in coeff_list: 

i = cff[0] 

j = cff[1] 

poly[(i,j)] = Integer(cff[2]) 

if i != j: 

poly[(j,i)] = Integer(cff[2]) 

else: 

for cff in coeff_list: 

poly[(cff[0],cff[1])] = Integer(cff[2]) 

return P(poly) 

 

class ModularCorrespondenceDatabase(ModularPolynomialDatabase): 

def _dbpath(self,level): 

r""" 

TESTS:: 

 

sage: DB = DedekindEtaModularCorrespondenceDatabase() 

sage: DB._dbpath((2,4)) 

'PolMod/EtaCrr/crr.02.004.dbz' 

""" 

(Nlevel,crrlevel) = level 

return "PolMod/%s/crr.%02d.%03d.dbz"%(self.model, Nlevel, crrlevel) 

 

class ClassicalModularPolynomialDatabase(ModularPolynomialDatabase): 

""" 

The database of classical modular polynomials, i.e. the polynomials 

Phi_N(X,Y) relating the j-functions j(q) and j(q^N). 

""" 

model = "Cls" 

 

class DedekindEtaModularPolynomialDatabase(ModularPolynomialDatabase): 

""" 

The database of modular polynomials Phi_N(X,Y) relating a quotient 

of Dedekind eta functions, well-defined on X_0(N), relating x(q) and 

the j-function j(q). 

""" 

model = "Eta" 

 

class DedekindEtaModularCorrespondenceDatabase(ModularCorrespondenceDatabase): 

""" 

The database of modular correspondences in $X_0(p) \times X_0(p)$, where 

the model of the curves $X_0(p) = \Bold{P}^1$ are specified by quotients of 

Dedekind's eta function. 

""" 

model = "EtaCrr" 

 

class AtkinModularPolynomialDatabase(ModularPolynomialDatabase): 

""" 

The database of modular polynomials Phi(x,j) for $X_0(p)$, where 

x is a function on invariant under the Atkin-Lehner invariant, 

with pole of minimal order at infinity. 

""" 

model = "Atk" 

 

class AtkinModularCorrespondenceDatabase(ModularCorrespondenceDatabase): 

model = "AtkCrr"