Local copy of the On-Line Encyclopedia of Integer Sequences - Databases

Skip to content
Back to top
View this page
Edit this page

# 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

    sage: SloaneEncyclopedia[60843]
    [1, 6, 21, 107, 47176870]

Python

    >>> from sage.all import *
    >>> SloaneEncyclopedia[Integer(60843)]
    [1, 6, 21, 107, 47176870]

To get the name of a sequence, type

Sage

    sage: SloaneEncyclopedia.sequence_name(1)
    'Number of groups of order n.'

[Python]

    >>> from sage.all import *
    >>> SloaneEncyclopedia.sequence_name(Integer(1))
    'Number of groups of order n.'

To search locally for a particular subsequence, type

Sage

    sage: SloaneEncyclopedia.find([1,2,3,4,5], 1)
    [(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])]

Python

    >>> from sage.all import *
    >>> SloaneEncyclopedia.find([Integer(1),Integer(2),Integer(3),Integer(4),Integer(5)], Integer(1))
    [(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

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

[Python]

    >>> from sage.all import *
    >>> SloaneEncyclopedia.find([Integer(1),Integer(2),Integer(3),Integer(4),Integer(5)], Integer(100))
    [(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

  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)

    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` – integer

    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)

    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)

    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

  is_installed()

    Check if a local copy of the encyclopedia is installed.

    EXAMPLES:

    Sage

        sage: SloaneEncyclopedia.is_installed()
        True

    Python

        >>> from sage.all import *
        >>> SloaneEncyclopedia.is_installed()
        True

  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.

  sequence_name(N)

    Return the name of sequence `N` in the encyclopedia.

    If sequence `N` does not exist, return `''`. If the names database is not installed, raise an `IOError`.

    INPUT:

    - `N` – integer

    OUTPUT: string

    EXAMPLES:

    Sage

        sage: SloaneEncyclopedia.sequence_name(1)
        'Number of groups of order n.'

    Python

        >>> from sage.all import *
        >>> SloaneEncyclopedia.sequence_name(Integer(1))
        'Number of groups of order n.'

  unload()

    Remove the database from memory.

sage.databases.sloane.copy_gz_file(gz_source, bz_destination)

  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