Ticket #3869: sage-trac3869.patch
| File sage-trac3869.patch, 2.8 kB (added by cremona, 5 months ago) |
|---|
-
a/sage/databases/cremona.py
old new 41 41 import sage.schemes.elliptic_curves.constructor as elliptic 42 42 import sage.databases.db # very important that this be fully qualified 43 43 import sage.misc.misc 44 45 import re 46 import string 44 47 45 48 _map = {'allcurves':'a', 'degphi':'b', 'allbsd':'c', 'allgens':'d'} 46 49 … … 245 248 #iso = iso.lower() 246 249 return conductor, iso, num 247 250 251 def split_code(key): 252 """ 253 Splits class+curve id string into its two parts. 248 254 249 255 EXAMPLES: 256 sage: import sage.databases.cremona as cremona 257 sage: cremona.split_code('ba2') 258 ('ba', '2') 259 """ 260 cu = re.split("[a-z]*",key)[1] 261 cl = re.split("[0-9]*",key)[0] 262 return (cl,cu) 263 264 def class_to_int(k): 265 """ 266 Converts class id string into an integer. 267 268 EXAMPLES: 269 sage: import sage.databases.cremona as cremona 270 sage: cremona.class_to_int('ba') 271 26 272 """ 273 kk = [string.ascii_lowercase.index(ch) for ch in list(k)] 274 kk.reverse() 275 return sum([kk[i]*26**i for i in range(len(kk))]) 276 277 def cmp_code(key1,key2): 278 """ 279 Comparison function for curve id strings. 280 281 NOTE: Not the same as standard lexicographic order! 282 283 EXAMPLES: 284 sage: import sage.databases.cremona as cremona 285 sage: cremona.cmp_code('ba1','z1') 286 1 287 288 By contrast: 289 sage: cmp('ba1','z1') 290 -1 291 292 """ 293 cl1,cu1 = split_code(key1) 294 cl2,cu2 = split_code(key2) 295 d = class_to_int(cl1)-class_to_int(cl2) 296 if d!=0: return d 297 return cmp(cu1,cu2) 298 250 299 251 300 class LargeCremonaDatabase(sage.databases.db.Database): 252 301 """ … … 466 515 """ 467 516 for N in conductors: 468 517 K = self.allcurves(N).keys() 469 K.sort( )518 K.sort(cmp_code) 470 519 for e in K: 471 520 yield self.elliptic_curve(str(N) + e) 472 521 … … 481 530 classes = [] 482 531 A = self.allcurves(conductor) 483 532 K = A.keys() 484 K.sort( )533 K.sort(cmp_code) 485 534 for k in K: 486 535 v = A[k] 487 536 # test if not first curve in class … … 516 565 generator that iterates over EllipticCurve objects. 517 566 """ 518 567 for N in conductors: 519 for id in self.curves(N).keys(): 568 K = self.curves(N).keys() 569 K.sort(cmp_code) 570 for id in K: 520 571 yield self.elliptic_curve(str(N) + id) 521 572 522 573 def list(self, conductors):