1Math::NumSeq::CollatzStUespesr(3C)ontributed Perl DocumeMnattaht:i:oNnumSeq::CollatzSteps(3)
2
3
4

NAME

6       Math::NumSeq::CollatzSteps -- steps in the "3n+1" problem
7

SYNOPSIS

9        use Math::NumSeq::CollatzSteps;
10        my $seq = Math::NumSeq::CollatzSteps->new;
11        my ($i, $value) = $seq->next;
12

DESCRIPTION

14       The number of steps it takes to reach 1 by the Collatz "3n+1" problem,
15
16           0, 1, 7, 2, 5, 8, 16, 3, 19, 6, 14, 9, 9, 17, 17, 4, 12, 20, ...
17           starting i=1
18
19       The Collatz problem iterates
20
21           n -> / 3n+1  if n odd
22                \ n/2   if n even
23
24       For example i=6 takes value=8 many steps to reach 1,
25
26           6 -> 3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1
27
28       It's conjectured that any starting n will always eventually reduce to 1
29       and so the number of steps is finite.  There's no limit in the code on
30       how many steps counted.  "Math::BigInt" is used if 3n+1 steps go past
31       the usual scalar integer limit.
32
33   Up Steps
34       Option "step_type => "up"" counts only the 3n+1 up steps.
35
36           step_type => "up"
37           0, 0, 2, 0, 1, 2, 5, 0, 6, 1, 4, 2, 2, 5, 5, 0, 3, 6, 6, 1, 1, ...
38
39       This can also be thought of as steps iterating
40
41           n -> (3n+1)/2^k  for maximum k
42
43   Down Steps
44       Option "step_type => "down"" counts only the n/2 down steps.
45
46           step_type => "down"
47           0, 1, 5, 2, 4, 6, 11, 3, 13, 5, 10, 7, 7, 12, 12, 4, 9, 14, ...
48
49       The total up+down gives the default "step_type=both".
50
51   Odd Numbers
52       Option "on_values => "odd"" counts steps on the odd numbers 2*i+1.
53
54           on_values => "odd"
55           0, 7, 5, 16, 19, 14, 9, 17, 12, 20, 7, 15, 23, 111, 18, 106, ...
56           starting i=0 for odd number 1
57
58   Even Numbers
59       Option "on_values => "even"" counts steps on the even number 2*i,
60
61           on_values => "even"
62           1, 2, 8, 3, 6, 9, 17, 4, 20, 7, 15, 10, 10, 18, 18, 5, 13, 21, ...
63           starting i=0 for even number 2
64
65       Since 2*i is even the first step is down n/2 to give i and thereafter
66       the same as the plain count.  This means the steps for "even" is simply
67       1 more than for plain "all".
68

FUNCTIONS

70       See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence
71       classes.
72
73       "$seq = Math::NumSeq::CollatzSteps->new ()"
74       "$seq = Math::NumSeq::CollatzSteps->new (step_type => $str, on_values
75       => $str)"
76           Create and return a new sequence object.  The optional "step_type"
77           parameter (a string) can be
78
79               "up"      upward steps 3n+1
80               "down"    downward steps n/2
81               "both"    both up and down (the default)
82
83           The optional "on_values" parameter (a string) can be
84
85               "all"     all integers i
86               "odd"     odd integers 2*i+1
87               "even"    even integers 2*i
88
89   Random Access
90       "$value = $seq->ith($i)"
91           Return the number of steps to take $i down to 1.
92
93       "$bool = $seq->pred($value)"
94           Return true if $value occurs as a step count.  This is simply
95           "$value >= 0".
96

SEE ALSO

98       Math::NumSeq, Math::NumSeq::JugglerSteps, Math::NumSeq::ReverseAddSteps
99       Math::NumSeq::HappySteps
100

HOME PAGE

102       <http://user42.tuxfamily.org/math-numseq/index.html>
103

LICENSE

105       Copyright 2011, 2012, 2013, 2014 Kevin Ryde
106
107       Math-NumSeq is free software; you can redistribute it and/or modify it
108       under the terms of the GNU General Public License as published by the
109       Free Software Foundation; either version 3, or (at your option) any
110       later version.
111
112       Math-NumSeq is distributed in the hope that it will be useful, but
113       WITHOUT ANY WARRANTY; without even the implied warranty of
114       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
115       General Public License for more details.
116
117       You should have received a copy of the GNU General Public License along
118       with Math-NumSeq.  If not, see <http://www.gnu.org/licenses/>.
119
120
121
122perl v5.28.0                      2014-08-06     Math::NumSeq::CollatzSteps(3)
Impressum