jburkardt

COLLATZ_RECURSIVE\ Demonstration of Recursive Programming for the Collatz Sequence {#collatz_recursive-demonstration-of-recursive-programming-for-the-collatz-sequence align=”center”} ===============================================================


COLLATZ_RECURSIVE is a C++ library which demonstrates recursive programming by considering the simple Collatz 3n+1 problem.

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:

  1. if T is 1, terminate the sequence;
  2. else if T is even, U = T/2.
  3. 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: {#licensing align=”center”}

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

Languages: {#languages align=”center”}

COLLATZ_RECURSIVE is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version.

POLPAK, a C++ library which evaluates a variety of mathematical functions, including Chebyshev, Gegenbauer, Hermite, Jacobi, Laguerre, Legendre polynomials, and the Collatz sequence.

Reference: {#reference align=”center”}

  1. Eric Weisstein,\ “The Collatz Problem”,\ CRC Concise Encyclopedia of Mathematics,\ CRC Press, 2002,\ Second edition,\ ISBN: 1584883472,\ LC: QA5.W45.

Source Code: {#source-code align=”center”}

Examples and Tests: {#examples-and-tests align=”center”}

List of Routines: {#list-of-routines align=”center”}

You can go up one level to the C++ source codes.


Last revised on 09 March 2012.