Help language development. Donate to The Perl Foundation

OEIS cpan:TOBS last updated on 2019-05-31

OEIS-1.0.0/

NAME

OEIS - Look up sequences on the On-Line Encyclopedia of Integer Sequences®

SYNOPSIS

use OEIS;

say OEIS::lookup 1, 1, * + * ... *;
#= OEIS A000045 «Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.»

say OEIS::lookup((1, 1, *+* ... *), :all).grep(* !~~ OEIS::easy).head;
#= OEIS A290689 «Number of transitive rooted trees with n nodes.»

say OEIS::lookup(1, 2, 4 ... ∞).mathematica.head;
#= Table[2^n, {n, 0, 50}]

DESCRIPTION

This module provides an interface to the On-Line Encyclopedia of Integer Sequences® (OEIS®), a web database of integer sequences. Stick an array or Seq into the OEIS::lookup routine and get back the most relevant result that OEIS finds, as an instance of OEIS::Entry. With the :all adverb, it returns a lazy Seq of all results. Sequences can also be looked up by their IDs. See below for details.

sub fetch

multi fetch (Int $ID, :$type 'A')
multi fetch (Str $ID where { … })
multi fetch (Seq $seq)
multi fetch (*@partial-seq)

Searches for a sequence identified

and returns all result pages in OEIS's internal text format as a lazy Seq.

This is a very low-level method. See OEIS::lookup for a more convenient interface.

sub chop-records

multi chop-records (Seq \pages)
multi chop-records (Str $page)

Takes a single page in OEIS' internal format, or a Seq of them (the return value of OEIS::fetch), and returns a Seq of all OEIS records contained in them, as multiline strings.

You will only need this sub if you get pages from a source that isn't OEIS::fetch, e.g. from a cache on disk, or if you want the textual records instead of OEIS::Entry objects.

More a more convenient interface, see OEIS::lookup.

sub lookup

sub lookup (:$all = False, |c)

This high-level sub calls OEIS::fetch with the captured arguments |c, followed by OEIS::chop-records and then creates for each record an OEIS::Entry object. Naturally, all search features of OEIS::fetch are supported.

By default only the first record is returned. This is the one that OEIS deems most relevant to the search. If the named argument $all is True, all records are returned as a lazy Seq.

If no result was found, the Seq is empty. Note that a too general query leads to "too many results, please narrow search" error from the OEIS. For other possible errors, see X::OEIS.

SEE ALSO

AUTHOR

Tobias Boege tobs@taboege.de

COPYRIGHT AND LICENSE

Copyright 2018/9 Tobias Boege

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.