# HG changeset patch
# User Willem Jan Palenstijn <wjp@usecode.org>
# Date 1294554583 3600
# Node ID faf3acfa70f6bdae1c9d911ee42393a6b769271c
# Parent af388485d7ae58022ddbcb57db96ce89f3646c64
#8251: Store Jones database as list of python ints instead of polynomials
diff r af388485d7ae r faf3acfa70f6 sage/databases/jones.py
a

b


85  85  return "John Jones's table of number fields with bounded ramification and degree <= 6" 
86  86  
87  87  def _load(self, path, filename): 
 88  """ 
 89  Load number fields from a .gp file from John Jones's web page. 
 90  This is called by _init, and should not be called directly. 
 91  
 92  TESTS: This is how the database is created from scratch:: 
 93  
 94  sage: J = JonesDatabase() 
 95  sage: J._init() # not tested, indirect doctest 
 96  ... 
 97  """ 
88  98  print filename 
89  99  i = 0 
90  100  while filename[i].isalpha(): 
… 
… 

96  106  S.sort() 
97  107  data = open(path + "/" + filename).read() 
98  108  data = data.replace("^","**") 
99   x = PolynomialRing(RationalField(), 'x').gen() 
 109  x = PolynomialRing(IntegerRing(), 'x').gen() 
100  110  v = eval(data) 
 111  
 112  # We store the polynomials defining the number fields as 
 113  # lists of python ints, to be completely independent of the 
 114  # version of sage used to save/load jones.sobj. 
 115  v = [ [ int(c) for c in p ] for p in v ] 
101  116  s = tuple(S) 
102  117  if self.root.has_key(s): 
 118  def _cmp_nf(x,y): 
 119  """ 
 120  Compare two lists as polynomials. 
 121  NB: This is rather slow, but the _load() function is 
 122  only used when recreating the database from scratch. 
 123  """ 
 124  R = PolynomialRing(RationalField(), 'x') 
 125  return R(x).__cmp__(R(y)) 
103  126  self.root[s] += v 
104   self.root[s].sort() 
 127  self.root[s].sort(cmp=_cmp_nf) 
105  128  else: 
106  129  self.root[s] = v 
107  130  
… 
… 

147  170  os.makedirs(JONESDATA) 
148  171  save(self.root, JONESDATA+ "/jones.sobj") 
149  172  
 173  def _load_db(self): 
 174  """ 
 175  Load the Jones database from file. 
 176  This raises a RuntimeError if the optional package with the database 
 177  hasn't been installed. 
 178  
 179  TESTS:: 
 180  
 181  sage: J = JonesDatabase() # optional  jones_database 
 182  sage: len(J.get(163))# indirect doctest, optional  jones_database 
 183  3 
 184  
 185  """ 
 186  if self.root is not None: 
 187  return 
 188  
 189  if os.path.exists(JONESDATA+ "/jones.sobj"): 
 190  self.root = load(JONESDATA+ "/jones.sobj") 
 191  else: 
 192  raise RuntimeError, "You must install the Jones database optional package." 
 193  if not isinstance(self.root.iteritems().next()[1][0],list): 
 194  self.root = None 
 195  raise RuntimeError, "You must update the Jones database optional package to the latest version." 
 196  
150  197  def unramified_outside(self, S, d=None, var='a'): 
151  198  """ 
152  199  Return all fields in the database of degree d unramified 
… 
… 

215  262  ValueError: S must be a list of primes 
216  263  """ 
217  264  if self.root is None: 
218   if os.path.exists(JONESDATA+ "/jones.sobj"): 
219   self.root = load(JONESDATA+ "/jones.sobj") 
220   else: 
221   raise RuntimeError, "You must install the Jones database optional package." 
 265  self._load_db() 
222  266  try: 
223  267  S = list(S) 
224  268  except TypeError: 
… 
… 

229  273  s = tuple(S) 
230  274  if not self.root.has_key(s): 
231  275  return [] 
232   return [NumberField(f, var, check=False) for f in self.root[s]] 
 276  R = PolynomialRing(RationalField(),'x') 
 277  return [NumberField(R(f), var, check=False) for f in self.root[s]] 
233  278  
234  279  def ramified_at(self, S, d=None, var='a'): 
235  280  """ 