Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/databases/jones.py
8814 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 = os.path.join(sage.misc.misc.SAGE_SHARE, 'jones')
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 = sorted([eval(z) for z in filename[i:j+1].split("-")])
96
data = open(path + "/" + filename).read()
97
data = data.replace("^","**")
98
x = PolynomialRing(RationalField(), 'x').gen()
99
v = eval(data)
100
s = tuple(S)
101
if s in self.root:
102
self.root[s] += v
103
self.root[s].sort()
104
else:
105
self.root[s] = v
106
107
def _init(self, path):
108
"""
109
Create the database from scratch from the PARI files on John Jones's
110
web page, downloaded (e.g., via wget) to a local directory, which
111
is specified as path above.
112
113
INPUT:
114
115
116
- ``path`` - (default works on William Stein install.)
117
path must be the path to Jones's Number_Fields directory
118
http://hobbes.la.asu.edu/Number_Fields These files should have
119
been downloaded using wget.
120
121
122
EXAMPLE: This is how to create the database from scratch, assuming
123
that the number fields are in the default directory above: From a
124
cold start of Sage::
125
126
sage: J = JonesDatabase()
127
sage: J._init() # not tested
128
...
129
130
This takes about 5 seconds.
131
"""
132
from sage.misc.misc import sage_makedirs
133
n = 0
134
x = PolynomialRing(RationalField(),'x').gen()
135
self.root = {}
136
self.root[tuple([])] = [x-1]
137
if not os.path.exists(path):
138
raise IOError("Path %s does not exist."%path)
139
for X in os.listdir(path):
140
if X[-4:] == "solo":
141
Z = path + "/" + X
142
print(X)
143
for Y in os.listdir(Z):
144
if Y[-3:] == ".gp":
145
self._load(Z, Y)
146
sage_makedirs(JONESDATA)
147
save(self.root, JONESDATA+ "/jones.sobj")
148
149
def unramified_outside(self, S, d=None, var='a'):
150
"""
151
Return all fields in the database of degree d unramified
152
outside S. If d is omitted, return fields of any degree up to 6.
153
The fields are ordered by degree and discriminant.
154
155
INPUT:
156
157
158
- ``S`` - list or set of primes, or a single prime
159
160
- ``d`` - None (default, in which case all fields of degree <= 6 are returned)
161
or a positive integer giving the degree of the number fields returned.
162
163
- ``var`` - the name used for the generator of the number fields (default 'a').
164
165
EXAMPLES::
166
167
sage: J = JonesDatabase() # optional - database_jones_numfield
168
sage: J.unramified_outside([101,109]) # optional - database_jones_numfield
169
[Number Field in a with defining polynomial x - 1,
170
Number Field in a with defining polynomial x^2 - 101,
171
Number Field in a with defining polynomial x^2 - 109,
172
Number Field in a with defining polynomial x^3 - x^2 - 36*x + 4,
173
Number Field in a with defining polynomial x^4 - x^3 + 13*x^2 - 19*x + 361,
174
Number Field in a with defining polynomial x^4 - x^3 + 14*x^2 + 34*x + 393,
175
Number Field in a with defining polynomial x^5 + 2*x^4 + 7*x^3 + 4*x^2 + 11*x - 6,
176
Number Field in a with defining polynomial x^5 + x^4 - 6*x^3 - x^2 + 18*x + 4,
177
Number Field in a with defining polynomial x^5 - x^4 - 40*x^3 - 93*x^2 - 21*x + 17]
178
"""
179
try:
180
S = list(S)
181
except TypeError:
182
S = [S]
183
Z = []
184
for X in powerset(S):
185
Z += self.ramified_at(X, d=d, var=var)
186
Z = sorted([(k.degree(), k.discriminant().abs(), k.discriminant() > 0, k) for k in Z])
187
return [z[-1] for z in Z]
188
189
def __getitem__(self, S):
190
return self.get(S)
191
192
def get(self, S, var='a'):
193
"""
194
Return all fields in the database ramified exactly at
195
the primes in S.
196
197
INPUT:
198
199
- ``S`` - list or set of primes, or a single prime
200
201
- ``var`` - the name used for the generator of the number fields (default 'a').
202
203
EXAMPLES::
204
205
sage: J = JonesDatabase() # optional - database_jones_numfield
206
sage: J.get(163, var='z') # optional - database_jones_numfield
207
[Number Field in z with defining polynomial x^2 + 163,
208
Number Field in z with defining polynomial x^3 - x^2 - 54*x + 169,
209
Number Field in z with defining polynomial x^4 - x^3 - 7*x^2 + 2*x + 9]
210
sage: J.get([3, 4]) # optional - database_jones_numfield
211
Traceback (most recent call last):
212
...
213
ValueError: S must be a list of primes
214
"""
215
if self.root is None:
216
if os.path.exists(JONESDATA+ "/jones.sobj"):
217
self.root = load(JONESDATA+ "/jones.sobj")
218
else:
219
raise RuntimeError("You must install the Jones database optional package.")
220
try:
221
S = list(S)
222
except TypeError:
223
S = [S]
224
if not all([p.is_prime() for p in S]):
225
raise ValueError("S must be a list of primes")
226
S.sort()
227
s = tuple(S)
228
if s not in self.root:
229
return []
230
return [NumberField(f, var, check=False) for f in self.root[s]]
231
232
def ramified_at(self, S, d=None, var='a'):
233
"""
234
Return all fields in the database of degree d ramified exactly at
235
the primes in S. The fields are ordered by degree and discriminant.
236
237
INPUT:
238
239
- ``S`` - list or set of primes
240
241
- ``d`` - None (default, in which case all fields of degree <= 6 are returned)
242
or a positive integer giving the degree of the number fields returned.
243
244
- ``var`` - the name used for the generator of the number fields (default 'a').
245
246
EXAMPLES::
247
248
sage: J = JonesDatabase() # optional - database_jones_numfield
249
sage: J.ramified_at([101,109]) # optional - database_jones_numfield
250
[]
251
sage: J.ramified_at([109]) # optional - database_jones_numfield
252
[Number Field in a with defining polynomial x^2 - 109,
253
Number Field in a with defining polynomial x^3 - x^2 - 36*x + 4,
254
Number Field in a with defining polynomial x^4 - x^3 + 14*x^2 + 34*x + 393]
255
sage: J.ramified_at(101) # optional - database_jones_numfield
256
[Number Field in a with defining polynomial x^2 - 101,
257
Number Field in a with defining polynomial x^4 - x^3 + 13*x^2 - 19*x + 361,
258
Number Field in a with defining polynomial x^5 + 2*x^4 + 7*x^3 + 4*x^2 + 11*x - 6,
259
Number Field in a with defining polynomial x^5 + x^4 - 6*x^3 - x^2 + 18*x + 4,
260
Number Field in a with defining polynomial x^5 - x^4 - 40*x^3 - 93*x^2 - 21*x + 17]
261
sage: J.ramified_at((2, 5, 29), 3, 'c') # optional - database_jones_numfield
262
[Number Field in c with defining polynomial x^3 - x^2 - 8*x - 28,
263
Number Field in c with defining polynomial x^3 - x^2 + 10*x + 102,
264
Number Field in c with defining polynomial x^3 - x^2 + 97*x - 333,
265
Number Field in c with defining polynomial x^3 - x^2 - 48*x - 188]
266
"""
267
Z = self.get(S, var=var)
268
if d == None:
269
Z = [(k.degree(), k.discriminant().abs(), k.discriminant() > 0, k) for k in Z]
270
else:
271
Z = [(k.discriminant().abs(), k.discriminant() > 0, k) for k in Z if k.degree() == d]
272
Z.sort()
273
return [z[-1] for z in Z]
274
275