Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/databases/jones.py
6915 views
1
r"""
2
John Jones's tables of number fields
3
4
In order to use the Jones database, the optional database package
5
must be installed using the Sage command !sage -i
6
database_jones_numfield
7
8
This is a table of number fields with bounded ramification and
9
degree `\leq 6`. You can query the database for all number
10
fields in Jones's tables with bounded ramification and degree.
11
12
EXAMPLES: First load the database::
13
14
sage: J = JonesDatabase()
15
sage: J
16
John Jones's table of number fields with bounded ramification and degree <= 6
17
18
List the degree and discriminant of all fields in the database that
19
have ramification at most at 2::
20
21
sage: [(k.degree(), k.disc()) for k in J.unramified_outside([2])] # optional - database_jones_numfield
22
[(1, 1), (2, -4), (2, -8), (2, 8), (4, 256), (4, 512), (4, -1024), (4, -2048), (4, 2048), (4, 2048), (4, 2048)]
23
24
List the discriminants of the fields of degree exactly 2 unramified
25
outside 2::
26
27
sage: [k.disc() for k in J.unramified_outside([2],2)] # optional - database_jones_numfield
28
[-4, -8, 8]
29
30
List the discriminants of cubic field in the database ramified
31
exactly at 3 and 5::
32
33
sage: [k.disc() for k in J.ramified_at([3,5],3)] # optional - database_jones_numfield
34
[-135, -675, -6075, -6075]
35
sage: factor(6075)
36
3^5 * 5^2
37
sage: factor(675)
38
3^3 * 5^2
39
sage: factor(135)
40
3^3 * 5
41
42
List all fields in the database ramified at 101::
43
44
sage: J.ramified_at(101) # optional - database_jones_numfield
45
[Number Field in a with defining polynomial x^2 - 101,
46
Number Field in a with defining polynomial x^4 - x^3 + 13*x^2 - 19*x + 361,
47
Number Field in a with defining polynomial x^5 + 2*x^4 + 7*x^3 + 4*x^2 + 11*x - 6,
48
Number Field in a with defining polynomial x^5 + x^4 - 6*x^3 - x^2 + 18*x + 4,
49
Number Field in a with defining polynomial x^5 - x^4 - 40*x^3 - 93*x^2 - 21*x + 17]
50
"""
51
52
#*****************************************************************************
53
# Sage: System for Algebra and Geometry Experimentation
54
#
55
# Copyright (C) 2005 William Stein <[email protected]>
56
#
57
# Distributed under the terms of the GNU General Public License (GPL)
58
#
59
# This code is distributed in the hope that it will be useful,
60
# but WITHOUT ANY WARRANTY; without even the implied warranty of
61
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
62
# General Public License for more details.
63
#
64
# The full text of the GPL is available at:
65
#
66
# http://www.gnu.org/licenses/
67
#*****************************************************************************
68
69
import os
70
71
from sage.rings.all import NumberField, RationalField, PolynomialRing
72
from sage.misc.misc import powerset
73
import sage.misc.misc
74
75
from sage.structure.sage_object import load, save
76
77
78
JONESDATA = "%s/data/jones/"%sage.misc.misc.SAGE_ROOT
79
80
class JonesDatabase:
81
def __init__(self):
82
self.root = None
83
84
def __repr__(self):
85
return "John Jones's table of number fields with bounded ramification and degree <= 6"
86
87
def _load(self, path, filename):
88
print filename
89
i = 0
90
while filename[i].isalpha():
91
i += 1
92
j = len(filename)-1
93
while filename[j].isalpha() or filename[j] in [".", "_"]:
94
j -= 1
95
S = [eval(z) for z in filename[i:j+1].split("-")]
96
S.sort()
97
data = open(path + "/" + filename).read()
98
data = data.replace("^","**")
99
x = PolynomialRing(RationalField(), 'x').gen()
100
v = eval(data)
101
s = tuple(S)
102
if self.root.has_key(s):
103
self.root[s] += v
104
self.root[s].sort()
105
else:
106
self.root[s] = v
107
108
109
def _init(self, path):
110
"""
111
Create the database from scratch from the PARI files on John Jones's
112
web page, downloaded (e.g., via wget) to a local directory, which
113
is specified as path above.
114
115
INPUT:
116
117
118
- ``path`` - (default works on William Stein install.)
119
path must be the path to Jones's Number_Fields directory
120
http://hobbes.la.asu.edu/Number_Fields These files should have
121
been downloaded using wget.
122
123
124
EXAMPLE: This is how to create the database from scratch, assuming
125
that the number fields are in the default directory above: From a
126
cold start of Sage::
127
128
sage: J = JonesDatabase()
129
sage: J._init() # not tested
130
...
131
132
This takes about 5 seconds.
133
"""
134
from sage.misc.misc import sage_makedirs
135
n = 0
136
x = PolynomialRing(RationalField(),'x').gen()
137
self.root = {}
138
self.root[tuple([])] = [x-1]
139
if not os.path.exists(path):
140
raise IOError, "Path %s does not exist."%path
141
for X in os.listdir(path):
142
if X[-4:] == "solo":
143
Z = path + "/" + X
144
print X
145
for Y in os.listdir(Z):
146
if Y[-3:] == ".gp":
147
self._load(Z, Y)
148
sage_makedirs(JONESDATA)
149
save(self.root, JONESDATA+ "/jones.sobj")
150
151
def unramified_outside(self, S, d=None, var='a'):
152
"""
153
Return all fields in the database of degree d unramified
154
outside S. If d is omitted, return fields of any degree up to 6.
155
The fields are ordered by degree and discriminant.
156
157
INPUT:
158
159
160
- ``S`` - list or set of primes, or a single prime
161
162
- ``d`` - None (default, in which case all fields of degree <= 6 are returned)
163
or a positive integer giving the degree of the number fields returned.
164
165
- ``var`` - the name used for the generator of the number fields (default 'a').
166
167
EXAMPLES::
168
169
sage: J = JonesDatabase() # optional - database_jones_numfield
170
sage: J.unramified_outside([101,109]) # optional - database_jones_numfield
171
[Number Field in a with defining polynomial x - 1,
172
Number Field in a with defining polynomial x^2 - 101,
173
Number Field in a with defining polynomial x^2 - 109,
174
Number Field in a with defining polynomial x^3 - x^2 - 36*x + 4,
175
Number Field in a with defining polynomial x^4 - x^3 + 13*x^2 - 19*x + 361,
176
Number Field in a with defining polynomial x^4 - x^3 + 14*x^2 + 34*x + 393,
177
Number Field in a with defining polynomial x^5 + 2*x^4 + 7*x^3 + 4*x^2 + 11*x - 6,
178
Number Field in a with defining polynomial x^5 + x^4 - 6*x^3 - x^2 + 18*x + 4,
179
Number Field in a with defining polynomial x^5 - x^4 - 40*x^3 - 93*x^2 - 21*x + 17]
180
"""
181
try:
182
S = list(S)
183
except TypeError:
184
S = [S]
185
Z = []
186
for X in powerset(S):
187
Z += self.ramified_at(X, d=d, var=var)
188
Z = [(k.degree(), k.discriminant().abs(), k.discriminant() > 0, k) for k in Z]
189
Z.sort()
190
return [z[-1] for z in Z]
191
192
def __getitem__(self, S):
193
return self.get(S)
194
195
def get(self, S, var='a'):
196
"""
197
Return all fields in the database ramified exactly at
198
the primes in S.
199
200
INPUT:
201
202
- ``S`` - list or set of primes, or a single prime
203
204
- ``var`` - the name used for the generator of the number fields (default 'a').
205
206
EXAMPLES::
207
208
sage: J = JonesDatabase() # optional - database_jones_numfield
209
sage: J.get(163, var='z') # optional - database_jones_numfield
210
[Number Field in z with defining polynomial x^2 + 163,
211
Number Field in z with defining polynomial x^3 - x^2 - 54*x + 169,
212
Number Field in z with defining polynomial x^4 - x^3 - 7*x^2 + 2*x + 9]
213
sage: J.get([3, 4]) # optional - database_jones_numfield
214
Traceback (most recent call last):
215
...
216
ValueError: S must be a list of primes
217
"""
218
if self.root is None:
219
if os.path.exists(JONESDATA+ "/jones.sobj"):
220
self.root = load(JONESDATA+ "/jones.sobj")
221
else:
222
raise RuntimeError, "You must install the Jones database optional package."
223
try:
224
S = list(S)
225
except TypeError:
226
S = [S]
227
if not all([p.is_prime() for p in S]):
228
raise ValueError, "S must be a list of primes"
229
S.sort()
230
s = tuple(S)
231
if not self.root.has_key(s):
232
return []
233
return [NumberField(f, var, check=False) for f in self.root[s]]
234
235
def ramified_at(self, S, d=None, var='a'):
236
"""
237
Return all fields in the database of degree d ramified exactly at
238
the primes in S. The fields are ordered by degree and discriminant.
239
240
INPUT:
241
242
- ``S`` - list or set of primes
243
244
- ``d`` - None (default, in which case all fields of degree <= 6 are returned)
245
or a positive integer giving the degree of the number fields returned.
246
247
- ``var`` - the name used for the generator of the number fields (default 'a').
248
249
EXAMPLES::
250
251
sage: J = JonesDatabase() # optional - database_jones_numfield
252
sage: J.ramified_at([101,109]) # optional - database_jones_numfield
253
[]
254
sage: J.ramified_at([109]) # optional - database_jones_numfield
255
[Number Field in a with defining polynomial x^2 - 109,
256
Number Field in a with defining polynomial x^3 - x^2 - 36*x + 4,
257
Number Field in a with defining polynomial x^4 - x^3 + 14*x^2 + 34*x + 393]
258
sage: J.ramified_at(101) # optional - database_jones_numfield
259
[Number Field in a with defining polynomial x^2 - 101,
260
Number Field in a with defining polynomial x^4 - x^3 + 13*x^2 - 19*x + 361,
261
Number Field in a with defining polynomial x^5 + 2*x^4 + 7*x^3 + 4*x^2 + 11*x - 6,
262
Number Field in a with defining polynomial x^5 + x^4 - 6*x^3 - x^2 + 18*x + 4,
263
Number Field in a with defining polynomial x^5 - x^4 - 40*x^3 - 93*x^2 - 21*x + 17]
264
sage: J.ramified_at((2, 5, 29), 3, 'c') # optional - database_jones_numfield
265
[Number Field in c with defining polynomial x^3 - x^2 - 8*x - 28,
266
Number Field in c with defining polynomial x^3 - x^2 + 10*x + 102,
267
Number Field in c with defining polynomial x^3 - x^2 + 97*x - 333,
268
Number Field in c with defining polynomial x^3 - x^2 - 48*x - 188]
269
"""
270
Z = self.get(S, var=var)
271
if d == None:
272
Z = [(k.degree(), k.discriminant().abs(), k.discriminant() > 0, k) for k in Z]
273
else:
274
Z = [(k.discriminant().abs(), k.discriminant() > 0, k) for k in Z if k.degree() == d]
275
Z.sort()
276
return [z[-1] for z in Z]
277
278