The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Math::NumSeq::OEIS -- number sequence by OEIS A-number

SYNOPSIS

 use Math::NumSeq::OEIS;
 my $seq = Math::NumSeq::OEIS->new (anum => 'A000032');
 my ($i, $value) = $seq->next;

DESCRIPTION

This module selects a NumSeq by its Online Encyclopedia of Integer Sequences A-number.

If there's NumSeq code implementing the sequence then that's used, otherwise local files if available. See Math::NumSeq::OEIS::Catalogue for querying available A-numbers.

Files

Files should be in an OEIS directory in the user's home directory (see File::HomeDir). Files can be HTML, OEIS internal, B-file, and/or A-file.

    ~/OEIS/A000032.html
    ~/OEIS/A000032.internal
    ~/OEIS/b000032.txt
    ~/OEIS/a000032.txt

    downloaded from:
    http://oeis.org/A000032
    http://oeis.org/A000032/internal
    http://oeis.org/A000032/b000032.txt
    http://oeis.org/A000032/a000032.txt

The "internal" format is more reliable than the HTML for parsing. The B-file or A-file can be used alone, but in that case there's no $seq->description() and it may limit the $seq->characteristic() attributes.

The b000000.txt file is a long list of values. The a000000.txt too and longer, but sometimes an auxiliary info. Some sequences don't have these, only 30 or 40 sample values from the HTML or internal page. Those few samples might be enough for fast growing sequences.

Other Notes

Sometimes more than one NumSeq module generates an OEIS sequence. For example A000290 both from Squares and from Polygonal k=4. Math::NumSeq::OEIS tries to give the better or faster one.

Sometimes the OEIS has duplicates, ie. two A-numbers which are the same sequence. Both are catalogued so they both give NumSeq module code, but the $seq->oeis_anum() method will read back as whichever is the "primary" one.

FUNCTIONS

See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.

$seq = Math::NumSeq::OEIS->new (anum => 'A000000')

Create and return a new sequence object.

($i, $value) = $seq->next()

Return the next index and value in the sequence.

In the current code when reading from a file any values bigger than a usual Perl IV or NV are returned as Math::BigInt objects. Is that a good idea? It preserves precision.

An a000000.txt or b000000.txt is read progressively. There's a Perl 5.8 ithreads CLONE which re-opens in a new thread so the $seq in each thread has its own position. But that doesn't help a fork() so care should be taken that only one of the parent or child use the $seq in that case, the same as for most open files when forking. Is this a good idea?

$str = $seq->description()

Return a human-readable description of the sequence. For the downloaded files this is the "name" part, a short description of the sequence.

A few sequences may have non-ascii characters in the description. For Perl 5.8 and up they're decoded to wide-chars. Not sure what to do for earlier Perl, currently they're left as whatever bytes the download gave, probably utf-8.

$value = $seq->values_min()
$value = $seq->values_max()

Return the minimum or maximum value taken by values in the sequence, or undef if unknown or infinity.

For files values_min() is guessed from the first few values if non-negative, but values_max() considered to be infinite. If the range seems to be limited (eg. sequences of -1,0,1) then min and max are obtained, and also for "full" sequences where the samples are all the values.

$ret = $seq->characteristic($key)

For a file the various standard characteristics are obtained as follows

  • "increasing", "non_decreasing" and "smaller" are determined from the sample values or the first few values from a a-file or b-file. Looking at only the few values ensures a big file isn't read in its entirety and is normally enough. The intention would be to try to look at enough values not to be tricked by decreasing values after the first few, etc.

  • "digits" is from KEYWORDS "cons" for decimal constants. Some other digit sequences are recognised by their DESCRIPTION part though this may be unreliable.

  • "count" is obtained from a DESCRIPTION with "number of". This is probably unreliable.

  • All the "KEYWORDS" from the OEIS are provided as booleans under names "OEIS_easy" etc. So for example

        if ($seq->characteristic("OEIS_nice")) {
          print "nooiice ...\n";
        }

SEE ALSO

Math::NumSeq, Math::NumSeq::OEIS::Catalogue

HOME PAGE

http://user42.tuxfamily.org/math-numseq/index.html

LICENSE

Copyright 2011, 2012 Kevin Ryde

Math-NumSeq is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

Math-NumSeq is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Math-NumSeq. If not, see <http://www.gnu.org/licenses/>.