COLLATZ
A Simple Package for the Collatz Sequence


COLLATZ is a Mathematica package which evaluates the Collatz sequence for a given starting point.

The most interesting thing about COLLATZ is not the Collatz sequence, but rather the way that it demonstrates how a user can define new functions for Mathematica, to be stored in a package file, and accessed later by, for example, a notebook.

The Collatz sequence itself, sometimes called the "3N+1" sequence, is defined as follows. Choose a starting value n, a positive integer. Now compute the next value of n:

For every starting value of n, the sequence seems to terminate, and it is conjectured that this is always so.

However, we are much more interested in the steps necessary to make it possible for a user to be able to start up Mathematica, and type

        Collatz[17]
      
and see the appropriate sequence of values.

Package Installation:

In order for the package to be accessible, the package file must be placed in the appropriate place. A typical place is the "Applications" subdirectory of the "User Base Directory". These are directories set up by Mathematica. You can find out where the User Base Directory is by the Mathematica command:

        $UserBaseDirectory
      
Then you need to copy the package file to the "Applications" subdirectory of that directory.

Once the new package has been placed, you should probably run Mathematica and direct it to rebuild the Help database. This will serve to update Mathematica's internal information so that it can explain how the functions in the package are called.

Package Usage:

To use the Collatz function, the user must first load the package, with the command

        << Collatz.m
      
after which, for the duration of the Mathematica session, the user can invoke the Collatz function with commands like
        Collatz[99]
      

Related Data and Programs:

COLLATZ is also available in a JAVA version and a MATLAB version and a PERL version.

POLPAK includes the routine collatz_count for counting the length of a Collatz sequence.

Reference:

  1. Roman Maeder,
    Programming in Mathematica,
    Second Edition, Addison Wesley, 1991.
  2. Eric Weisstein,
    "The Collatz Problem",
    CRC Concise Encyclopedia of Mathematics,
    CRC 1998.
  3. Stephen Wolfram,
    The Mathematica Book,
    Fourth Edition,
    Wolfram Media / Cambridge University Press, 1999.

Source Code:

Examples and Tests:

List of Routines:

You can go up one level to the Mathematica packages and notebooks.


Last revised on 05 March 2006.