NAME
Math::NumSeq::OEIS  number sequence by OEIS Anumber
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 an Anumber of Sloane's Online Encyclopedia of Integer Sequences.
If there's NumSeq
code implementing the sequence then that's used, otherwise local downloaded OEIS files if available. See Math::NumSeq::OEIS::Catalogue for querying available Anumbers.
Files
Local files should be in a ~/OEIS direectory, ie. an OEIS directory in the user's home directory (see File::HomeDir). Files can be HTML, OEIS internal, bfile, and/or afile.
~/OEIS/A000032.html
~/OEIS/A000032.internal.txt
~/OEIS/A000032.internal.html
~/OEIS/b000032.txt
~/OEIS/a000032.txt
As downloaded from for example
http://oeis.org/A000032
http://oeis.org/search?q=id:A000032&fmt=text
http://oeis.org/A000032/internal
http://oeis.org/A000032/b000032.txt
http://oeis.org/A000032/a000032.txt
The "internal" text format is the most reliable for parsing. This is the "text" link in the main sequence pages. The "internal" link is the same wrapped in HTML. It can be used here as .internal.html.
bfiles b000000.txt are long lists of values. afiles a000000.txt similarly and even longer, but sometimes are auxiliary info instead (and in that case not used). Some sequences don't have these, only the 30 or 40 sample values from the HTML or internal page. Those samples might be enough for fast growing sequences.
bfile or afile can be used alone by this module, without the text or HTML parts. In that case there's no $seq>description()
and it may limit the $seq>characteristic()
attributes.
Other Notes
Sometimes more than one NumSeq module generates an OEIS sequence. For example A000290 is Squares but also Polygonal k=4. The catalogue is arranged so Math::NumSeq::OEIS
selects the better, faster, or more specific one.
Sometimes the OEIS has duplicates, ie. two Anumbers which are the same sequence. Both are catalogued so they both give NumSeq module code, but the $seq>oeis_anum()
method generally reads 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.
Iterating
($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 int or float are returned as
Math::BigInt
objects in order to preserve precision. Is that a good idea?An a000000.txt or b000000.txt file is read line by line. For Perl 5.8 ithreads there's a
CLONE
setup which reopens the file in a new thread so$seq
in each thread has its own position. (See perlthrtut and "Making your module threadsafe" in perlmod.)But a process
fork()
will have both parent and child with the same open file so care should be taken that only one of them uses$seq
in that case. The same is true of all open file handling across afork()
.
Random Access
$value = $seq>ith($i)

Return the
$i
'th value from$seq
, orundef
if$i
is outside the range of available values.An a000000.txt or b000000.txt file is read by a binary search to find the target
$i
. This is reasonably efficient and avoids loading or processing an entire file if just a few values are wanted.If
$i
happens to be the next line or just a short distance ahead of what was last read then no search is necessary. This means thatith()
called sequentially i=1,2,3,4,etc simply reads successive lines the same asnext()
would do.
Information
$str = $seq>description()

Return a humanreadable description of the sequence. For the downloaded files this is the name part ("%N") which is a short description of the sequence.
A few sequences may have nonASCII characters in the description. For Perl 5.8 and up they're decoded to widechars. Not sure what to do for earlier Perl, currently they're left as the bytes from the download, which may be utf8.
$value = $seq>values_min()
$value = $seq>values_max()

Return the minimum or maximum values in the sequence, or
undef
if unknown or infinity.For files
values_min()
is guessed from the first few values if nonnegative, andvalues_max()
is normally considered to be infinite. For keyword "full" the samples are the entire sequence and gives the range. If a range seems to be limited (eg. sequences of 1,0,1) then min and max are obtained from those. $ret = $seq>characteristic($key)

For a file the following standard characteristics are obtained (per "Information" in Math::NumSeq),
"integer" always true.
"increasing", "non_decreasing" and "smaller" are determined from the sample values or the first few values from an afile or bfile. Looking at only the few ensures a big file isn't read in its entirety and is normally enough. The intention would be to look at enough values not to be tricked by decreasing values after the first few, etc.
"digits" is from keyword "cons" for decimal constants. Some other digit sequences are recognised by their name part though this may be unreliable.
"count" is from a name 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/mathnumseq/index.html
LICENSE
Copyright 2011, 2012, 2013, 2014 Kevin Ryde
MathNumSeq 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.
MathNumSeq 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 MathNumSeq. If not, see <http://www.gnu.org/licenses/>.