Local copy of the On-Line Encyclopedia of Integer Sequences#
The SloaneEncyclopedia
object provides access to a local copy of the database
containing only the sequences and their names. To use this, you must download
and install the database using SloaneEncyclopedia.install()
, or
SloaneEncyclopedia.install_from_gz()
if you have already downloaded the
database manually.
To look up a sequence, type
sage: SloaneEncyclopedia[60843] # optional - sloane_database
[1, 6, 21, 107]
>>> from sage.all import *
>>> SloaneEncyclopedia[Integer(60843)] # optional - sloane_database
[1, 6, 21, 107]
To get the name of a sequence, type
sage: SloaneEncyclopedia.sequence_name(1) # optional - sloane_database
'Number of groups of order n.'
>>> from sage.all import *
>>> SloaneEncyclopedia.sequence_name(Integer(1)) # optional - sloane_database
'Number of groups of order n.'
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])]
>>> from sage.all import *
>>> SloaneEncyclopedia.find([Integer(1),Integer(2),Integer(3),Integer(4),Integer(5)], Integer(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, ...
>>> from sage.all import *
>>> SloaneEncyclopedia.find([Integer(1),Integer(2),Integer(3),Integer(4),Integer(5)], Integer(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) ].
See also
If you want to get more informations relative to a sequence (references, links, examples, programs, …), you can use the On-Line Encyclopedia of Integer Sequences provided by the
OEIS
module.Some infinite OEIS sequences are implemented in Sage, via the
sloane_functions
module.
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 is now also smarter about loading the local database in that it does not convert a sequence from string form to a list of integers until absolutely necessary. This seems to cut the loading time roughly in half.
Steven Sivek (2009-12-22): added the SloaneEncyclopedia functions install() and install_from_gz() so users can get the latest versions of the OEIS without having to get an updated spkg; added sequence_name() to return the description of a sequence; and changed the data type for elements of each sequence from int to Integer.
Thierry Monteil (2012-02-10): deprecated dead code and update related doc and tests.
- class sage.databases.sloane.SloaneEncyclopediaClass[source]#
Bases:
object
A local copy of the Sloane Online Encyclopedia of Integer Sequences that contains only the sequence numbers and the sequences themselves.
- find(seq, maxresults=30)[source]#
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
– listmaxresults
– int
OUTPUT: list of 2-tuples (i, v), where v is a sequence with seq as a subsequence.
- install(oeis_url='https://oeis.org/stripped.gz', names_url='https://oeis.org/names.gz', overwrite=False)[source]#
Download and install the online encyclopedia, raising an IOError if either step fails.
INPUT:
oeis_url
– string (default: “https://oeis.org…”) The URL of the stripped.gz encyclopedia file.names_url
– string (default: “https://oeis.org…”) The URL of the names.gz encyclopedia file. If you do not want to download this file, set names_url=None.overwrite
– boolean (default:False
) If the encyclopedia is already installed and overwrite=True, download and install the latest version over the installed one.
- install_from_gz(stripped_file, names_file, overwrite=False)[source]#
Install the online encyclopedia from a local stripped.gz file.
INPUT:
stripped_file
– string. The name of the stripped.gz OEIS file.names_file
– string. The name of the names.gz OEIS file, or None if the user does not want it installed.overwrite
– boolean (default:False
) If the encyclopedia is already installed and overwrite=True, install ‘filename’ over the old encyclopedia.
- load()[source]#
Load the entire encyclopedia into memory from a file. This is done automatically if the user tries to perform a lookup or a search.
- sequence_name(N)[source]#
Return the name of sequence
N
in the encyclopedia.If sequence
N
does not exist, return''
. If the names database is not installed, raise anIOError
.INPUT:
N
– int
OUTPUT: string
EXAMPLES:
sage: SloaneEncyclopedia.sequence_name(1) # optional - sloane_database 'Number of groups of order n.'
>>> from sage.all import * >>> SloaneEncyclopedia.sequence_name(Integer(1)) # optional - sloane_database 'Number of groups of order n.'
- sage.databases.sloane.copy_gz_file(gz_source, bz_destination)[source]#
Decompress a gzipped file and install the bzipped version.
This is used by SloaneEncyclopedia.install_from_gz to install several gzipped OEIS database files.
INPUT:
gz_source
– string. The name of the gzipped file.bz_destination
– string. The name of the newly compressed file.