Ticket #2366: trac_2366.patch
| File trac_2366.patch, 2.4 kB (added by mhansen, 4 months ago) |
|---|
-
a/sage/databases/sloane.py
old new 254 254 return [seqnum, description, [ZZ(n) for n in list]] 255 255 256 256 def sloane_sequence(number): 257 """ 258 Returns a list with the number, name, and values for the sequence 259 \code{number} in Sloane's online database of integer sequences. 260 261 EXAMPLES: 262 sage: sloane_sequence(22) #optional -- requires internet 263 Searching Sloane's online database... 264 [22, 265 'Number of centered hydrocarbons with n atoms.', 266 [0, 267 1, 268 0, 269 1, 270 ... 271 36201693122]] 272 273 """ 257 274 results = sloane_find('id:A%s'%number) 258 275 if len(results) == 0: 259 276 raise ValueError, "sequence '%s' not found"%number 260 277 return results[0] 261 278 262 279 def sloane_find(list, nresults = 30, verbose=True): 280 """ 281 Searches Sloane's Online Encyclopedia of Integer Sequences for 282 a sequence containing the number provided in \code{list}. 283 284 INPUT: 285 list -- (list) a list of integers to search Sloane's for 286 nresults -- (integer) the maximum number of results to return 287 default: 30 288 verbose -- (boolean) print a string to let the user know that 289 it is working and not hanging. 290 default: True 291 292 OUTPUT: 293 A list of matches in Sloane's database. Each match consists of 294 a list of the sequence number, the name of the sequence, and 295 some initial terms of the sequence. 296 297 EXAMPLES: 298 sage: sloane_find([1,1,2,3,5,8,13,21], nresults=1) #optional -- requires internet 299 Searching Sloane's online database... 300 [[45, 301 'Fibonacci numbers: F(n) = F(n-1) + F(n-2), F(0) = 0, F(1) = 1, F(2) = 1, ...', 302 [0, 303 1, 304 1, 305 2, 306 3, 307 5, 308 8, 309 13, 310 21, 311 ... 312 39088169]]] 313 314 """ 263 315 liststr = re.sub(r'[\[\] ]', '', str(list)) 264 316 urlparams = urllib.urlencode({'q': liststr, 265 317 'p': 1,