Interface to Sloane On-Line Encyclopedia of Integer Sequences

To look up sequence A060843, type one of the following:

sage: sloane_sequence(60843)       # optional - internet 
Searching Sloane's online database...
[60843, 'Busy Beaver problem: maximal number of steps that an n-state Turing machine can make on an initially blank tape before eventually halting.', [1, 6, 21, 107]]    
sage: sloane_sequence("60843")     # optional - internet 
Searching Sloane's online database...
[60843, 'Busy Beaver problem: maximal number of steps that an n-state Turing machine can make on an initially blank tape before eventually halting.', [1, 6, 21, 107]]    
sage: sloane_sequence("060843")    # optional - internet 
Searching Sloane's online database...    
[60843, 'Busy Beaver problem: maximal number of steps that an n-state Turing machine can make on an initially blank tape before eventually halting.', [1, 6, 21, 107]]    

Do not prefix an integer with a 0 or it will be interpreted in octal. Results are of the form [number, description, list], and invalid numbers will cause sloane_sequence to raise an ValueError exception:

sage: sloane_sequence('sage')     # optional - internet 
...
ValueError: sequence 'sage' not found

To look up the sequence

sage: sloane_find([2,3,5,7], 2)       # optional - internet 
Searching Sloane's online database...
[[40, 'The prime numbers.', [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271]], [41, 'a(n) = number of partitions of n (the partition numbers).', [1, 1, 2, 3, 5, 7, 11, 15, 22, 30, 42, 56, 77, 101, 135, 176, 231, 297, 385, 490, 627, 792, 1002, 1255, 1575, 1958, 2436, 3010, 3718, 4565, 5604, 6842, 8349, 10143, 12310, 14883, 17977, 21637, 26015, 31185, 37338, 44583, 53174, 63261, 75175, 89134]]]

To return no more than 2 results (default is 30), type

sage: sloane_find([1,2,3,4,5], 2)      # optional - internet 
Searching Sloane's online database...
[[27, 'The natural numbers. Also called the whole numbers, the counting numbers or the positive integers.', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77]], [961, 'Prime powers p^k (p prime, k >= 0).', [1, 2, 3, 4, 5, 7, 8, 9, 11, 13, 16, 17, 19, 23, 25, 27, 29, 31, 32, 37, 41, 43, 47, 49, 53, 59, 61, 64, 67, 71, 73, 79, 81, 83, 89, 97, 101, 103, 107, 109, 113, 121, 125, 127, 128, 131, 137, 139, 149, 151, 157, 163, 167, 169, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227]]]

Note that the OEIS (http://www.research.att.com/ njas/sequences/) claims to limit the number of results to 100. Results are lists of the form [ [number, description, list]], and invalid input will cause sloane_find to return [].

In some cases, these functions may return [] even though the inputs are legal. These cases correspond to errors from the OEIS server, and calling the functions again may fix the problem.

Alternatively, the SloaneEncyclopedia object provides access to a local copy of the database containing only the sequences. To use this you must install the optional database_sloane_oeis-2005-12 package using sage -i database_sloane_oeis-2005-12.

To look up a sequence, type

sage: SloaneEncyclopedia[60843]               # optional - sloane_database
[1, 6, 21, 107]

To search locally for a particular subsequence, type

sage: SloaneEncyclopedia.find([1,2,3,4,5], 1)    # optional - sloane_database
[(15, [1, 2, 3, 4, 5, 7, 7, 8, 9, 11, 11, 13, 13, 16, 16, 16, 17, 19, 19, 23, 23, 23, 23, 25, 25, 27, 27, 29, 29, 31, 31, 32, 37, 37, 37, 37, 37, 41, 41, 41, 41, 43, 43, 47, 47, 47, 47, 49, 49, 53, 53, 53, 53, 59, 59, 59, 59, 59, 59, 61, 61, 64, 64, 64, 67, 67, 67, 71, 71, 71, 71, 73])]

The default maximum number of results is 30, but to return up to 100, type

sage: SloaneEncyclopedia.find([1,2,3,4,5], 100)    # optional - sloane_database
[(15, [1, 2, 3, 4, 5, 7, 7, 8, 9, 11, 11, ...

Results in either case are of the form [ (number, list) ].

TODO:

  • When this program gets a sloane sequence from the database it actually downloads a huge amount of information about it, then throws most of it away. Also, it returns the data to the user as a very simple tuple. It would be much better to return an instance of a class:

    class SloaneSequence: ...
    

    and the class should have methods for each of the things that Sloane records about a sequence. Also, when possible, it should be able to compute more terms.

AUTHORS:

  • Steven Sivek (2005-12-22): first version
  • Steven Sivek (2006-02-07): updated to correctly handle the new search form on the Sloane website, and it’s now also smarter about loading the local database in that it doesn’t convert a sequence from string form to a list of integers until absolutely necessary. This seems to cut the loading time roughly in half.
class sage.databases.sloane.SloaneEncyclopediaClass

A local copy of the Sloane Online Encyclopedia of Integer Sequences that contains only the sequence numbers and the sequences themselves.

__getitem__(N)

Return sequence N in the encyclopedia. If sequence N does not exist, return [].

INPUT:

  • N - int

OUTPUT: list

__init__()
Initialize the database but do not load any of the data.
__iter__()
Returns an iterator through the encyclopedia. Elements are of the form [number, sequence].
__len__()
Return the number of sequences in the encyclopedia.
__repr__()
String representation of this database. OUTPUT: str
find(seq, maxresults=30)

Return a list of all sequences which have seq as a subsequence, up to maxresults results. Sequences are returned in the form (number, list).

INPUT:

  • seq - list
  • maxresults - int

OUTPUT: list of 2-tuples (i, v), where v is a sequence with seq as a subsequence.

load()
Load the entire encyclopedia into memory from a file. This is done automatically if the user tries to perform a lookup or a search.
unload()
Remove the database from memory.
sage.databases.sloane.parse_sequence(text)
sage.databases.sloane.sloane_find(list, nresults=30, verbose=True)

Searches Sloane’s Online Encyclopedia of Integer Sequences for a sequence containing the number provided in list.

INPUT:

  • list - (list) a list of integers to search Sloane’s for
  • nresults - (integer) the maximum number of results to return default: 30
  • verbose - (boolean) print a string to let the user know that it is working and not hanging. default: True

OUTPUT: A list of matches in Sloane’s database. Each match consists of a list of the sequence number, the name of the sequence, and some initial terms of the sequence.

EXAMPLES:

sage: sloane_find([1,1,2,3,5,8,13,21], nresults=1) #optional - internet
Searching Sloane's online database...
[[45,
  'Fibonacci numbers: F(n) = F(n-1) + F(n-2), F(0) = 0, F(1) = 1, F(2) = 1, ...',
  [0,
   1,
   1,
   2,
   3,
   5,
   8,
   13,
   21,
   ...
   39088169]]]
sage.databases.sloane.sloane_sequence(number)

Returns a list with the number, name, and values for the sequence number in Sloane’s online database of integer sequences.

EXAMPLES:

sage: sloane_sequence(22) # optional - internet
Searching Sloane's online database...
[22,
 'Number of centered hydrocarbons with n atoms.',
 [0,
  1,
  0,
  1,
  ...
  36201693122]]

The input must not be a sequence itself:

sage: sloane_sequence(prime_range(100))
...
TypeError: input must be an integer or string that specifies the id of the Sloane sequence to download

Previous topic

Linear codes

Next topic

Frank Luebeck’s tables of Conway polynomials over finite fields.

This Page