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

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, per Math::OEIS::Names. This may include some non-ASCII characters (in people's names usually).

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 want, an interesting unexpected connection, a match somewhere in the middle of a sequence, 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 that somehow.)

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 usual ways if desired.

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

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

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

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.

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)
    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 which can occur 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 sequence with bigger or smaller is not a match.

    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" ],

COMMAND LINE

The module import() has 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 option prints non-ASCII characters in the charset given by Encode::Locale if that module and PerlIO::encoding are available. (The search() method call doesn'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 a buffer

See examples/grep-not-in-oeis.pl in the sources for a way to keep searches in a document.

SEE ALSO

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

HOME PAGE

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

LICENSE

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