Elixir OEIS

Hex.pmDocumentationLicense

An Elixir client for the On-Line Encyclopedia of Integer Sequences (OEIS).

This library provides a convenient way to search the OEIS database for integer sequences.

Installation

Add oeis to your list of dependencies in mix.exs:

def deps do
  [
    {:oeis, "~> 0.7.1"}
  ]
end

Then, run mix deps.get to fetch the new dependency.

Usage

The primary function is OEIS.search/2. It can be called with a keyword list, a list of integers, or a string.

Searching

OEIS.search/2 returns:

# Search with a keyword list
iex> OEIS.search(sequence: [1, 2, 3, 6, 11, 23], keyword: "core")
{:multi, [%OEIS.Sequence{id: "A000055", ...}]}

# Search with an ID string (A-number)
iex> OEIS.search("A000045")
{:single, %OEIS.Sequence{id: "A000045", name: "Fibonacci numbers..."}}

# Search with a general string query
iex> OEIS.search("Fibonacci")
{:partial, [%OEIS.Sequence{id: "A000045", ...}, ...]}

# Search by author (greedy) and general query
iex> OEIS.search(author: "Sloane", query: "partitions")
{:partial, [%OEIS.Sequence{...}, ...]}

Advanced Features

Fetching More Terms

OEIS sequences often have limited terms in the primary record. OEIS.fetch_more_terms/2 fetches the full "b-file" containing many more terms. It also extracts any comments within the b-file and appends them to the sequence's comment list, annotated with their line numbers.

iex> {:single, seq} = OEIS.search("A000001")
iex> {:ok, updated_seq} = OEIS.fetch_more_terms(seq)
# updated_seq.data now contains all terms from the b-file
# updated_seq.comment now includes annotated comments from the b-file

Fetching Related Sequences

OEIS.fetch_xrefs/2 extracts OEIS IDs from the cross-references field and fetches the full sequence definitions in parallel. It also supports streaming for sequences with many references.

iex> {:single, seq} = OEIS.search("A000045")
iex> related = OEIS.fetch_xrefs(seq, max_concurrency: 5)
# related is a list of OEIS.Sequence structs for Lucas numbers, etc.

# Or stream them
iex> OEIS.fetch_xrefs(seq, stream: true) |> Enum.take(5)

Enumerable Sequences

OEIS.Sequence implements the Enumerable protocol, allowing you to iterate over its data directly.

iex> {:single, seq} = OEIS.search("A000045")
iex> Enum.take(seq, 5)
[0, 1, 1, 2, 3]

Standardized Options

Most functions accept a standard set of options:

Documentation

Documentation is available at https://hexdocs.pm/oeis.

License

This project is licensed under the MIT License - see the LICENSE file for details.