The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Math::OEIS::Grep - search for numbers in OEIS stripped file

SYNOPSIS

 use Math::OEIS::Grep;
 Math::OEIS::Grep->search (array => [ 8,13,21,34,55,89 ]);
 # prints matches found

 # command line
 # perl -MMath::OEIS::Grep=-search,123,456,789

DESCRIPTION

This module searches for numbers in a downloaded copy of the OEIS stripped file. See Math::OEIS::Stripped on how to get that file.

This grep is an alternative to the OEIS web site search and is good if offline or for mechanically trying a large numbers of searches.

The exact form of the results printout and transformations is not settled. The intention is to do something sensible to find given numbers.

The OEIS names file, if available, is used to show the name of a matched sequence (see Math::OEIS::Names).

Details

When a match is found it's usually necessary to examine the sequence definition manually to check the relevance. It might be exactly what you're seeking, or it might be mere coincidence, or it might be an interesting unexpected connection.

If the given array of values is longer than the OEIS samples then they still match. The first few array values must be found but then matching stops either at the end of the given values or the end of the OEIS samples, whichever comes first.

The values can be either numbers or strings and are stringized for the grep. Beware of round-off if numbers might exceed a Perl UV. Math::BigInt or similar can be used in the usual way if necessary.

An array of constant values or small constant difference is recognised and not searched since there's usually too many matches and the OEIS sequence which is a constant or constant difference may not be the first match.

File::Map is used to read the stripped file if that module is available. This is recommended since mmap() is roughly a 2x speedup over plain reading (by blocks).

The OEIS search hints at http://oeis.org/hints.html note that it can be worth skipping some initial values in case you have a different idea of a start but then a known sequence. There's a slight attempt to automate that here by stripping leading zeros and one initial value if no full match.

It may be worth dividing out a small common factor. There's attempts here to automate that here by searching for /2 and /4 if no exact match (and doubling *2 too). Maybe more divisions could be attempted, even a full GCD. In practice sequences with common factors are often present when they arise naturally from a sequence definition.

FUNCTIONS

Math::OEIS::Grep->search (array => $aref, ...)

Print matches of the given array values in the OEIS stripped file. The key/value pairs can be

    array       => $arrayref (mandatory)
    name        => $string
    max_matches => $integer (default 10)

array is an arrayref of values to search for. This parameter must be given.

name is printed if matches are found. When doing many searches this identify which one has matched. Eg.

    name => "case d=123",

max_matches limits the number of sequences returned. This is intended as a protection against a large number of matches from some small list or frequently occurring values.

COMMAND LINE

The module import accepts a -search option which is designed for use from the command line

    perl -MMath::OEIS::Grep=-search,123,456,789
    # search and then exit perl

For Emacs see the author's oeis.el to run this search on numbers entered or at point, http://user42.tuxfamily.org/oeis-el/index.html.

SEE ALSO

Math::OEIS, Math::OEIS::Stripped, File::Map

HOME PAGE

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

LICENSE

Copyright 2010, 2011, 2012, 2013, 2014, 2015 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/.