1Math::NumSeq(3)       User Contributed Perl Documentation      Math::NumSeq(3)
2
3
4

NAME

6       Math::NumSeq -- number sequences
7

SYNOPSIS

9        # only a base class, use one of the actual classes, such as
10        use Math::NumSeq::Squares;
11        my $seq = Math::NumSeq::Squares->new;
12        my ($i, $value) = $seq->next;
13

DESCRIPTION

15       This is a base class for some number sequences.  Sequence objects can
16       iterate through values and some sequences have random access and/or a
17       predicate test.
18
19       The idea is to generate things like squares or primes in a generic way.
20       Some sequences, like squares, are so easy there's no need for a class
21       except for the genericness.  Other sequences are trickier and an
22       iterator is a good way to go through values.  The iterating tries to be
23       progressive, so not calculating too far ahead yet doing reasonable size
24       chunks for efficiency.
25
26       Sequence values have an integer index "i" starting either from i=0 or
27       i=1 or whatever best suits the sequence.  The values can be anything,
28       positive, negative, fractional, etc.
29
30       The intention is that all modules "Math::NumSeq::Foo" are sequence
31       classes, and that supporting things are deeper, such as under
32       "Math::NumSeq::Something::Helper" or "Math::NumSeq::Base::SharedStuff".
33
34   Number Types
35       The various methods try to support "Math::BigInt" and similar
36       overloaded number types.  So for instance "pred()" might be applied to
37       test a big value, or "ith()" on a bigint to preserve precision from
38       some rapidly growing sequence.  Infinities and NaNs give some kind of
39       NaN or infinite return (some unspecified kind as yet).
40

FUNCTIONS

42       In the following "Foo" is one of the subclass names.
43
44       "$seq = Math::NumSeq::Foo->new (key=>value,...)"
45           Create and return a new sequence object.
46
47   Iterating
48       "($i, $value) = $seq->next()"
49           Return the next index and value in the sequence.
50
51           Most sequences are infinite and for them there's always a next
52           value.  But if $seq is finite then at the end the return is no
53           values.  So for example
54
55               while (my ($i, $value) = $seq->next) {
56                 print "$i $value\n";
57               }
58
59       "$seq->rewind()"
60           Rewind the sequence to its starting point.  The next call to
61           "next()" will be the initial "$i,$value" again.
62
63           See "Optional Methods" below for possible arbitrary "seeks".
64
65       "$i = $seq->tell_i()"
66           Return the current i position.  This is the i which the next call
67           to "next()" will return.
68
69   Information
70       "$i = $seq->i_start()"
71           Return the first index $i in the sequence.  This is the position
72           "rewind()" returns to.
73
74       "$str = $seq->description()"
75           Return a human-readable description of the sequence.  This might be
76           translated into the locale language, though there's no message
77           translations yet.
78
79       "$value = $seq->values_min()"
80       "$value = $seq->values_max()"
81           Return the minimum or maximum value taken by values in the
82           sequence, or "undef" if unknown or infinity.
83
84       "$ret = $seq->characteristic($key)"
85           Return something if the sequence has $key (a string)
86           characteristic, or "undef" if not.  This is intended as a loose set
87           of features or properties a sequence can have to describe itself.
88
89               digits            integer or undef, the radix if seq is digits
90               count             boolean, true if values are counts of something
91               smaller           boolean, true if value[i] < i generally
92               integer           boolean, true if all values are integers
93
94               increasing        boolean, true if value[i+1] > value[i] always
95               non_decreasing    boolean, true if value[i+1] >= value[i] always
96               increasing_from_i     integer, i for which value[i+1] > value[i]
97               non_decreasing_from_i integer, i for which value[i+1] >= value[i]
98
99               value_is_radix    boolean, value is radix for i
100
101           "value_is_radix" means each value is a radix applying to the i
102           index.  For example "RepdigitRadix" value is a radix for which i is
103           a repdigit.  These values might also be 0 or 1 or -1 or some such
104           non-radix to indicate no radix.
105
106       "$str = $seq->oeis_anum()"
107           Return the A-number (a string) for $seq in Sloane's Online
108           Encyclopedia of Integer Sequences, or return "undef" if not in the
109           OEIS or not known.  For example
110
111               my $seq = Math::NumSeq::Squares->new;
112               my $anum = $seq->oeis_anum;
113               # gives $anum = "A000290"
114
115           The web page for that is then
116
117               <http://oeis.org/A000290>
118
119           Sometimes the OEIS has duplicates, ie. two A-numbers which are the
120           same sequence.  When that's accidental or historical
121           "$seq->oeis_anum()" is whichever is reckoned the primary one.
122
123       "$aref = Math::NumSeq::Foo->parameter_info_array()"
124       "@list = Math::NumSeq::Foo->parameter_info_list()"
125           Return an arrayref or list describing the parameters taken by a
126           given class.  This meant to help making widgets etc for user
127           interaction in a GUI.  Each element is a hashref
128
129               {
130                 name            => parameter key arg for new()
131                 share_key       => string, or undef
132                 description     => human readable string
133                 type            => string "integer","boolean","enum" etc
134                 default         => value
135                 minimum         => number, or undef
136                 maximum         => number, or undef
137                 width           => integer, suggested display size
138                 choices         => for enum, an arrayref
139                 choices_display => for enum, an arrayref
140               }
141
142           "type" is a string, one of
143
144               "integer"
145               "enum"
146               "boolean"
147               "string"
148               "filename"
149
150           "filename" is separate from "string" since it might require subtly
151           different handling to ensure it reaches Perl as a byte string,
152           whereas a "string" type might in principle take Perl wide chars.
153
154           For "enum" the "choices" field is an arrayref of possible values,
155           such as
156
157               { name    => "flavour",
158                 type    => "enum",
159                 choices => ["strawberry","chocolate"],
160               }
161
162           "choices_display", if provided, is human-readable strings for those
163           choices, possibly translated into another language (though there's
164           no translations yet).
165
166           "minimum" and "maximum" are omitted (or "undef") if there's no hard
167           limit on the parameter.
168
169           "share_key" is designed to indicate when parameters from different
170           NumSeq classes can be a single control widget in a GUI etc.
171           Normally the "name" is enough, but when the same name has slightly
172           different meanings in different classes a "share_key" keeps
173           different meanings separate.
174
175   Optional Methods
176       The following methods are only implemented for some sequences since
177       it's sometimes difficult to generate an arbitrary numbered element etc.
178       Check "$seq->can('ith')" etc before using.
179
180       "$seq->seek_to_i($i)"
181       "$seq->seek_to_value($value)"
182           Move the current i so "next()" will return $i or $value on the next
183           call.  If $value is not in the sequence then move so as to return
184           the next higher value which is.
185
186           Usually "seek_to_value()" only makes sense for sequences where all
187           values are distinct, so that a value is an unambiguous location.
188
189       "$value = $seq->ith($i)"
190           Return the $i'th value in the sequence.  Only some sequence classes
191           implement this method.
192
193       "($v0, $v1) = $seq->ith_pair($i)"
194           Return two values "ith($i)" and "ith($i+1)" from the sequence.
195           This method can be used whenever "ith()" exists.
196           "$seq->can('ith_pair')" says whether "ith_pair()" can be used (and
197           gives a coderef).
198
199           For some sequences a pair of values can be calculated with less
200           work than two separate "ith()" calls.
201
202       "$bool = $seq->pred($value)"
203           Return true if $value occurs in the sequence.  For example for the
204           squares this returns true if $value is a square or false if not.
205
206       "$i = $seq->value_to_i($value)"
207       "$i = $seq->value_to_i_ceil($value)"
208       "$i = $seq->value_to_i_floor($value)"
209           Return the index i of $value.  If $value is not in the sequence
210           then "value_to_i()" returns "undef", or "value_to_i_ceil()" returns
211           the i of the next higher value which is, "value_to_i_floor()" the i
212           of the next lower value.
213
214           These methods usually only make sense for monotonic increasing
215           sequences, or perhaps non-decreasing so with some repeating values.
216
217       "$i = $seq->value_to_i_estimate($value)"
218           Return an estimate of the i corresponding to $value.
219
220           The accuracy of this estimate is unspecified, but can at least hint
221           at the growth rate of the sequence.  For example if making an
222           "intersection" checking for given values in the sequence then if
223           the estimated i is small it may be fastest to go through the
224           sequence by "next()" and compare, rather than apply "pred()" to
225           each target.
226

SEE ALSO

228       Math::NumSeq::Squares, Math::NumSeq::Cubes, Math::NumSeq::Pronic,
229       Math::NumSeq::Triangular, Math::NumSeq::Polygonal,
230       Math::NumSeq::Tetrahedral, Math::NumSeq::StarNumbers,
231       Math::NumSeq::Powerful, Math::NumSeq::PowerPart,
232       Math::NumSeq::PowerFlip
233
234       Math::NumSeq::Even, Math::NumSeq::Odd, Math::NumSeq::All,
235       Math::NumSeq::AllDigits, Math::NumSeq::ConcatNumbers,
236       Math::NumSeq::Runs
237
238       Math::NumSeq::Primes, Math::NumSeq::TwinPrimes,
239       Math::NumSeq::SophieGermainPrimes, Math::NumSeq::AlmostPrimes,
240       Math::NumSeq::DeletablePrimes, Math::NumSeq::Emirps,
241       Math::NumSeq::MobiusFunction, Math::NumSeq::LiouvilleFunction,
242       Math::NumSeq::DivisorCount, Math::NumSeq::GoldbachCount,
243       Math::NumSeq::LemoineCount, Math::NumSeq::PythagoreanHypots
244
245       Math::NumSeq::PrimeFactorCount, Math::NumSeq::AllPrimeFactors
246
247       Math::NumSeq::ErdosSelfridgeClass, Math::NumSeq::PrimeIndexOrder,
248       Math::NumSeq::PrimeIndexPrimes
249
250       Math::NumSeq::Totient, Math::NumSeq::TotientCumulative,
251       Math::NumSeq::TotientSteps, Math::NumSeq::TotientStepsSum,
252       Math::NumSeq::TotientPerfect, Math::NumSeq::DedekindPsiCumulative,
253       Math::NumSeq::DedekindPsiSteps, Math::NumSeq::Abundant,
254       Math::NumSeq::PolignacObstinate
255
256       Math::NumSeq::Factorials, Math::NumSeq::Primorials,
257       Math::NumSeq::Fibonacci, Math::NumSeq::LucasNumbers,
258       Math::NumSeq::FibonacciWord, Math::NumSeq::FibonacciRepresentations,
259       Math::NumSeq::PisanoPeriod, Math::NumSeq::PisanoPeriodSteps,
260       Math::NumSeq::Fibbinary, Math::NumSeq::FibbinaryBitCount
261
262       Math::NumSeq::Catalan, Math::NumSeq::BalancedBinary,
263       Math::NumSeq::Pell, Math::NumSeq::Tribonacci, Math::NumSeq::Perrin,
264       Math::NumSeq::SpiroFibonacci
265
266       Math::NumSeq::FractionDigits, Math::NumSeq::SqrtDigits,
267       Math::NumSeq::SqrtEngel, Math::NumSeq::SqrtContinued,
268       Math::NumSeq::SqrtContinuedPeriod, Math::NumSeq::AlgebraicContinued
269
270       Math::NumSeq::DigitCount, Math::NumSeq::DigitCountLow,
271       Math::NumSeq::DigitCountHigh
272
273       Math::NumSeq::DigitLength, Math::NumSeq::DigitLengthCumulative,
274       Math::NumSeq::SelfLengthCumulative, Math::NumSeq::DigitProduct,
275       Math::NumSeq::DigitProductSteps, Math::NumSeq::DigitSum,
276       Math::NumSeq::DigitSumModulo, Math::NumSeq::RadixWithoutDigit,
277       Math::NumSeq::RadixConversion, Math::NumSeq::MaxDigitCount
278
279       Math::NumSeq::Palindromes, Math::NumSeq::Xenodromes,
280       Math::NumSeq::Beastly, Math::NumSeq::Repdigits,
281       Math::NumSeq::RepdigitAny, Math::NumSeq::RepdigitRadix,
282       Math::NumSeq::UndulatingNumbers, Math::NumSeq::HarshadNumbers,
283       Math::NumSeq::MoranNumbers, Math::NumSeq::HappyNumbers,
284       Math::NumSeq::HappySteps
285
286       Math::NumSeq::CullenNumbers, Math::NumSeq::ProthNumbers,
287       Math::NumSeq::WoodallNumbers, Math::NumSeq::BaumSweet,
288       Math::NumSeq::GolayRudinShapiro,
289       Math::NumSeq::GolayRudinShapiroCumulative, Math::NumSeq::MephistoWaltz,
290       Math::NumSeq::HafermanCarpet, Math::NumSeq::KlarnerRado,
291       Math::NumSeq::UlamSequence, Math::NumSeq::ReRound,
292       Math::NumSeq::ReReplace, Math::NumSeq::LuckyNumbers
293
294       Math::NumSeq::CollatzSteps, Math::NumSeq::ReverseAdd,
295       Math::NumSeq::ReverseAddSteps, Math::NumSeq::JugglerSteps,
296       Math::NumSeq::SternDiatomic, Math::NumSeq::NumAronson,
297       Math::NumSeq::HofstadterFigure, Math::NumSeq::DuffinianNumbers
298
299       Math::NumSeq::Kolakoski, Math::NumSeq::GolombSequence,
300       Math::NumSeq::AsciiSelf, Math::NumSeq::Multiples, Math::NumSeq::Modulo
301
302       Math::NumSeq::Expression, Math::NumSeq::File, Math::NumSeq::OEIS
303
304       Math::NumSeq::AlphabeticalLength,
305       Math::NumSeq::AlphabeticalLengthSteps, Math::NumSeq::SevenSegments (in
306       the Math-NumSeq-Alpha dist)
307
308       Math::NumSeq::Aronson (in the Math-Aronson dist)
309
310       Math::NumSeq::PlanePathCoord, Math::NumSeq::PlanePathDelta,
311       Math::NumSeq::PlanePathTurn, Math::NumSeq::PlanePathN (in the Math-
312       PlanePath dist)
313
314   Other Modules Etc
315       Math::Sequence and Math::Series, for symbolic recursive sequence
316       definitions
317
318       math-image, for displaying images with the NumSeq sequences
319

HOME PAGE

321       http://user42.tuxfamily.org/math-numseq/index.html
322

LICENSE

324       Copyright 2010, 2011, 2012, 2013, 2014 Kevin Ryde
325
326       Math-NumSeq is free software; you can redistribute it and/or modify it
327       under the terms of the GNU General Public License as published by the
328       Free Software Foundation; either version 3, or (at your option) any
329       later version.
330
331       Math-NumSeq is distributed in the hope that it will be useful, but
332       WITHOUT ANY WARRANTY; without even the implied warranty of
333       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
334       General Public License for more details.
335
336       You should have received a copy of the GNU General Public License along
337       with Math-NumSeq.  If not, see <http://www.gnu.org/licenses/>.
338
339
340
341perl v5.28.0                      2014-06-29                   Math::NumSeq(3)
Impressum