NAME

Math::OEIS::Stripped - read the OEIS stripped file

SYNOPSIS

my @values = Math::OEIS::Stripped->anum_to_values('A123456');

DESCRIPTION

This is an interface to the big OEIS stripped file. The file should be downloaded and unzipped to ~/OEIS/stripped,

cd ~/OEIS
wget http://oeis.org/stripped.gz
gunzip stripped.gz

stripped is a very large file containing each A-number and its sample values. There's usually about 180 characters worth of sample values but possibly less or more.

The stripped file is sorted by A-number so anum_to_values() is a text file binary search (currently implemented with Search::Dict).

Terms of use for the stripped file data can be found at (Creative Commons Attribution Non-Commercial 3.0 at the time of writing)

FUNCTIONS

@values = Math::OEIS::Stripped->anum_to_values($anum)
$values_str = Math::OEIS::Stripped->anum_to_values_str($anum)

Return the values from the stripped file for $anum (a string) such as "A000001".

anum_to_values() returns a list of values, or an empty list if no such A-number.

Values bigger than a Perl integer are converted to Math::BigInt so as to be exact in numeric operations, such as comparisons == or >=.

anum_to_values_str() returns a string like "1,2,3,4", or undef if no such A-number. The stripped file has leading and trailing commas on its values list but these are removed here for convenience of subsequent split or similar.

In the past, draft sequences were in the stripped with an empty values list ",,". The return for them is an empty list (meaning no values yet).

If running in perl -T taint mode then $values_str and each value string in @values is tainted in the usual way for reading from a file. Values converted to Math::BigInt do not keep a notion of taintedness, but Math::BigInt should validate as digits which is in the spirit of untainting after checking.

Math::OEIS::Stripped->close()

Close the stripped file handle, or do nothing if already closed or never opened.

Oopery

$obj = Math::OEIS::Stripped->new (key => value, ...)

Create and return a new Math::OEIS::Stripped object to read an OEIS stripped file. The optional key/value parameters can be

filename     => $filename       # default ~/OEIS/stripped
fh           => $filehandle

use_bigint   => string
                  "if_necessary", # default
                  0,              # never
                  1,              # always
bigint_class => $classname        # default "Math::BigInt"

filename defaults to ~/OEIS/stripped per Math::OEIS->local_directories(). Another filename can be given, or an open filehandle. If a handle is given then filename is used in diagnostics so can be given too.

use_bigint controls conversion of values to bignum objects in anum_to_values() etc. Default "if_necessary" converts values bigger than a Perl integer, or option 1 or 0 for always or never convert. When not converted, each value is a string suitable for any string operation but possibly not numeric operations.

bigint_class is the module name for bignum conversion. It is loaded with require when needed and values are created by $classname->new("123"). If the class has runtime options, such as the choice of back-ends in Math::BigInt, then they should be setup in mainline code.

@values = $obj->anum_to_values($anum)
$values_str = $obj->anum_to_values_str($anum)

Return the values from the stripped file for an $anum string such as "A000001", like the class method described above (but with values() following the use_bigint in $obj).

$filename = $obj->filename()

Return the filename from $obj.

$filename = Math::OEIS::Stripped->default_filename()
$filename = $obj->default_filename()

Return the default filename which is used if no filename or fh option is given. default_filename() can be called either as a class method or object method.

$obj->close()

Close the stripped file handle, or do nothing if already closed.

($anum,$values_str) = Math::OEIS::Stripped->line_split_anum($line)

Split a line of the stripped file into A-number and values string. $line should be like

A123456 ,1,6,9,-23,65,17,-5,997,

Leading and trailing comma (and any trailing newline) are discarded so $values_str is like "1,2,3".

If $line is not A-number and values like this then return an empty list. The stripped file starts with some comment lines (#) and they get this empty return.

In the past, draft sequences were included in the stripped file with empty values list. They are reckoned non-lines since no values, so an empty return.

@values = Math::OEIS::Stripped->values_split($values_str)
@values = $obj->values_split($values_str)

$values_str is a string of integers and commas like "123,-456,789". Return them split to a list of integers.

This a split() on commas, and apply the use_bigint option to the result. See new() above about that option.

SEE ALSO

Math::OEIS, Math::OEIS::Names

OEIS files page http://oeis.org/allfiles.html

HOME PAGE

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

LICENSE

Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2020 Kevin Ryde

Math-OEIS 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-OEIS 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-OEIS. If not, see http://www.gnu.org/licenses/.