collatz
collatz,
a MATLAB code which
computes the Collatz sequence.
The rules for generation of the Collatz sequence are recursive.
If T is the current entry of the sequence, (T is
assumed to be a positive integer), then the next
entry, U is determined as follows:
-
if T is 1, terminate the sequence;
-
else if T is even, U = T/2.
-
else (if T is odd and not 1), U = 3*T+1;
Although the Collatz sequence seems to be finite for every
starting point, this has not been proved. Over the range of
starting values that have been examined, a great irregularity
has been observed in the number of entries in the corresponding
sequence.
The Collatz sequence is also known as the "hailstone" sequence or
the "3n+1" sequence.
Licensing:
The computer code and data files described and made available on this web page
are distributed under
the MIT license
Languages:
collatz is available in
a MATLAB version and
an Octave version and
a Python version.
Related Data and Programs:
collatz_test
collatz_recursive,
a MATLAB code which
demonstrates recursive programming by considering the simple Collatz 3n+1 problem.
polpak,
a MATLAB code which
evaluates a variety of mathematical functions, polynomials, and
sequences, including Bell, Benford, Bernoulli, Bernstein, Cardan,
Catalan, Charlier, Chebyshev, Collatz, Delannoy, Euler, Fibonacci,
Gegenbauer, Gudermannian, Hermite, Hofstadter, Jacobi, Krawtchouk,
Laguerre, Lambert, Legendre, Lerch, Meixner, Mertens, Moebius, Motzkin,
Phi, Sigma, Stirling, Tau, Tribonacci, Zernike.
Reference:
-
Martin Gardner,
"Slither, 3X+1 and Other Curious Questions",
Wheels, Life, and Other Mathematical Amusements,
WH Freeman, 1983.
-
Patrick Honner,
"The Simple Math Problem We Still Can't Solve",
Quanta,
22 September 2022.
-
Eric Weisstein,
"The Collatz Problem",
CRC Concise Encyclopedia of Mathematics,
CRC Press, 2002,
Second edition,
ISBN: 1584883472,
LC: QA5.W45.
Source Code:
-
collatz.m,
computes the Collatz sequence for a given starting point;
-
collatz_count.m,
returns the number of entries in the Collatz sequence
for a given starting point;
-
collatz_inverse.m,
returns the preimage or "inverse" of a set of values
under the Collatz transformation;
-
collatz_level.m,
returns the values that are k steps away from 1.
-
collatz_max.m,
returns the maximum entry in the Collatz sequence
for a given starting point;
-
collatz_write.m,
writes a Collatz sequence to a file;
-
lollatz_permutation.m,
applies the Lollatz permutation to a given set of values.
-
lollatz_sequence.m,
computes a Lollatz sequence that stops if it repeats,
or if it exceeds a maximum number of steps.
-
mollatz.m,
computes the Mollatz 3N-1 sequence for a given starting point;
-
nollatz.m,
computes the Nollatz N+1 sequence for a given starting point;
Last revised on 16 June 2022.