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


 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


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).


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

If the given array of values is longer than the OEIS samples then it will still match. Matching stops at the end of the given values or the end of the OEIS samples, whichever comes first. A minimum match length is demanded, and it's possible this is at the end of the sample values. (Small values like 0,1 tend to hit various false matches under this rule. The intention is to tighten in some way.)

Values can be either numbers or strings and are stringized for the grep. For numbers, be careful of round-off if exceeding a Perl integer. Math::BigInt or anything similar can be used in the usual way if desired.

An array of constant values or small constant difference is noticed and not searched since there's usually too many matches and the first is often not the relevant OEIS sequence.

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 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 OEIS sequences with common factors are often present when they arise naturally from a sequence definition.

Non-integer constants appear in the OEIS as sequences of decimal digits (and sometimes other bases). Digits should be given here as values 0 to 9 etc. For angles, the OEIS is usually radians but sometimes degrees so it can be worth trying both. There's no attempt here to automate that.


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)
    values_min   => $integer or undef
    values_max   => $integer or undef
    exclude_list => arrayref of A-number strings

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

name is optional and is printed as a name of the values if matches are found. When doing many searches this can identify which one has matched, if not obvious from the values. 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 a small array or frequently occurring values.

values_min, values_max specify the range of values permitted in the matched sequence. Default undef means no limits. These limits can be used when the range of the target values is known and so sequences with bigger or smaller should be skipped.

    values_min => 0,
    values_max => 2,

exclude_list is an arrayref of A-numbers which should be excluded from matching. This can be used to avoid sequences close enough to match but which you have reviewed and know to be different.

    exclude_list => [ "A123456", "A234567" ],


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

This -search prints non-ASCII characters in sequence names with Encode::Locale if that module (and PerlIO::encoding) is available. (The module calls don't touch output encoding, that's left to application mainline setups.)

From within Emacs, see the author's oeis.el to run a search on numbers entered or at point in the buffer

examples/ in the sources is a way to keep searches in a document.


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




Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 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