collatz_polynomial, a Python code which implements the Collatz polynomial iteration, a polynomial analog of the numerical iteration that is also known as the 3n+1 conjecture or the hailstone sequence.

Let p0(x) be a polynomial with integer coefficients mod 2. Then define the next Collatz polynomial p1(x) as follows:

  1. if p0(x) is divisible by x, p1(x) = p0(x) / x.
  2. Otherwise, p1(x) = p0(x) * ( x + 1 ) + 1 mod 2.

This transformation can be repeated, generating a Collatz polynomial sequence. For all starting polynomials checked so far, the sequence reaches the polynomial p(x) = 1, at which point the convention is to halt. (There is also the exceptional polynomial p(x)=0.) It is interesting to investigate the number of steps required to drive a particular polynomial to 1, and to find patterns in this behavior.


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


collatz_polynomial is available in a MATLAB version and a Python version.

Related Data and Programs:

collatz, a Python code which computes and analyzes the Collatz or hailstone or 3n+1 sequence;


  1. John D Cook,
    Polynomial analog of the Collatz conjecture,
    27 July 2021,

Source Code:

Last modified on 18 December 2022.