<html>

  <head>
    <title>
      COLLATZ - The Collatz Sequence
    </title>
  </head>

  <body bgcolor="#EEEEEE" link="#CC0000" alink="#FF3300" vlink="#000055">

    <h1 align = "center">
      COLLATZ <br> The Collatz Sequence
    </h1>

    <hr>

    <p>
      <b>COLLATZ</b>
      is a MATLAB library which
      computes the Collatz sequence.
    </p>

    <p>
      The rules for generation of the Collatz sequence are recursive.
      If <b>T</b> is the current entry of the sequence, (<b>T</b> is
      assumed to be a positive integer), then the next
      entry, <b>U</b> is determined as follows:
      <ol>
        <li>
          if <b>T</b> is 1, terminate the sequence;
        </li>
        <li>
          else if <b>T</b> is even, <b>U</b> = <b>T</b>/2.
        </li>
        <li>
          else (if <b>T</b> is odd and not 1), <b>U</b> = 3*<b>T</b>+1;
        </li>
      </ol>
    </p>

    <p>
      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.
    </p>

    <p>
      The Collatz sequence is also known as the "hailstone" sequence or
      the "3n+1" sequence.
    </p>

    <h3 align = "center">
      Licensing:
    </h3>

    <p>
      The computer code and data files described and made available on this web page
      are distributed under
      <a href = "../../txt/gnu_lgpl.txt">the GNU LGPL license.</a>
    </p>

    <h3 align = "center">
      Languages:
    </h3>

    <p>
      <b>COLLATZ</b> is available in
      <a href = "../../java_src/collatz/collatz.html">a JAVA version</a> and
      <a href = "../../math_src/collatz/collatz.html">a MATHEMATICA version</a> and
      <a href = "../../m_src/collatz/collatz.html">a MATLAB version</a> and
      <a href = "../../pl_src/collatz/collatz.html">a PERL version</a>.
    </p>

    <h3 align = "center">
      Related Data and Programs:
    </h3>

    <p>
      <a href = "../../m_src/collatz_parfor/collatz_parfor.html">
      COLLATZ_PARFOR</a>,
      a MATLAB program which
      seeks the maximum Collatz sequence between 1 and N; it runs in parallel
      using MATLAB's "parfor" facility.
    </p>

    <p>
      <a href = "../../m_src/collatz_recursive/collatz_recursive.html">
      COLLATZ_RECURSIVE</a>,
      a MATLAB library which
      demonstrates recursive programming by considering the simple Collatz 3n+1 problem.
    </p>

    <p>
      <a href = "../../m_src/polpak/polpak.html">
      POLPAK</a>,
      a MATLAB library which
      includes the routine <b>collatz_count</b> for counting the
      length of a Collatz sequence.
    </p>

    <p>
      <a href = "../../m_src/sequence_streak_display/sequence_streak_display.html">
      SEQUENCE_STREAK_DISPLAY</a>,
      a MATLAB program which
      can display a "streak plot" of a van der Corput sequence.
    </p>

    <p>
      <a href = "../../data/table/table.html">
      TABLE</a>,
      a data format which
      is used for the file output by <b>COLLATZ_WRITE</b>.
    </p>

    <h3 align = "center">
      Reference:
    </h3>

    <p>
      <ol>
        <li>
          Eric Weisstein,<br>
          "The Collatz Problem",<br>
          CRC Concise Encyclopedia of Mathematics,<br>
          CRC Press, 2002,<br>
          Second edition,<br>
          ISBN: 1584883472,<br>
          LC: QA5.W45.
        </li>
      </ol>
    </p>

    <h3 align = "center">
      Source Code:
    </h3>

    <p>
      <ul>
        <li>
          <a href = "collatz.m">collatz.m</a>,
          computes the Collatz sequence for a given starting point;
        </li>
        <li>
          <a href = "collatz_count.m">collatz_count.m</a>,
          returns the number of entries in the Collatz sequence
          for a given starting point;
        </li>
        <li>
          <a href = "collatz_max.m">collatz_max.m</a>,
          returns the maximum entry in the Collatz sequence
          for a given starting point;
        </li>
        <li>
          <a href = "collatz_write.m">collatz_write.m</a>,
          writes a Collatz sequence to a file;
        </li>
        <li>
          <a href = "timestamp.m">timestamp.m</a>,
          prints the current YMDHMS date as a timestamp;
        </li>
      </ul>
    </p>

    <h3 align = "center">
      Examples and Tests:
    </h3>

    <p>
      <ul>
        <li>
          <a href = "collatz_test.m">collatz_test.m</a>,
          runs all the tests.
        </li>
        <li>
          <a href = "collatz_test_output.txt">collatz_test_output.txt</a>,
          the output from the tests.
        </li>
        <li>
          <a href = "collatz_test01.m">collatz_test01.m</a>,
          computes the Collatz sequence for several seeds.
        </li>
        <li>
          <a href = "collatz_test02.m">collatz_test02.m</a>,
          computes the length of the Collatz sequence for seeds 1 to 100.
        </li>
        <li>
          <a href = "collatz_test03.m">collatz_test03.m</a>,
          writes the Collatz sequence for seed 27 to a file, and the
          Collatz sequence lengths for seeds 1 to 100 to a file.
        </li>
        <li>
          <a href = "collatz_27.txt">collatz_27.txt</a>,
          the points in the Collatz sequence for seed 27.
        </li>
        <li>
          <a href = "collatz_count.txt">collatz_count.txt</a>,
          the Collatz count for seeds 1 to 100.
        </li>
        <li>
          <a href = "collatz_test04.m">collatz_test04.m</a>,
          displays the Collatz sequence for seed 27.
        </li>
        <li>
          <a href = "collatz_sequence_27.png">collatz_sequence_27.png</a>,
          a plot of the Collatz sequence for seed 27.
        </li>
        <li>
          <a href = "collatz_test05.m">collatz_test05.m</a>,
          displays the Collatz max for seeds 1 to 1000.
        </li>
        <li>
          <a href = "collatz_max.png">collatz_max.png</a>,
          a plot of the Collatz max values for seeds 1 to 1000.
        </li>
        <li>
          <a href = "collatz_test06.m">collatz_test06.m</a>,
          displays the Collatz count for seeds 1 to 50.
        </li>
        <li>
          <a href = "collatz_count.png">collatz_count.png</a>,
          a plot of the Collatz coount values for seeds 1 to 50.
        </li>
      </ul>
    </p>

    <p>
      You can go up one level to <a href = "../m_src.html">
      the MATLAB source codes</a>.
    </p>

    <hr>

    <i>
      Last revised on 22 May 2012.
    </i>

    <!-- John Burkardt -->

  </body>

</html>