Numerical Errors in Logistic Map Calculation

J. C. Sprott
Department of Physics, University of Wisconsin, Madison, WI 53706, USA
September 15, 1997
(Modified April 20, 2000)

    When numerically iterating the logistic equation

Xn+1 = AXn(1 - Xn)

round-off errors can cause spurious results.  Consider the case A = 4 which maps the unit interval (0, 1) back onto itself exactly twice.  Because of the shape of the parabolic logistic function, many values of Xn near 0.5 map into values of Xn+1 near 1.0 which in turn map into values of Xn+2 close to zero.  If these values of Xn+2 are indistinguishable from zero to within machine precision, they will thereafter remain at zero because zero is an unstable fixed point solution of the logistic map.  As a result, initial conditions X0 will iterate to zero on average after a relatively small number of iterations N whose value we estimate below.

    Suppose that the logistic equation with A = 4 is iterated using (4-byte) single-precision arithmetic.  Four bytes is 32 bits, of which 23 are used for the mantissa, 8 for the exponent, and 1 for the sign according to the IEEE standard for floating point arithmetic.  Thus the computer can represent 223 = 8,388,608 unique values in the range (0, 1) for a given exponent.  Values near zero can be represented more accurately by changing the exponent.  Thus the problem occurs for values of Xn+1 that are indistinguishable from 1.  Values larger than 1 - 2-24 will round to 1.0.  With this value of Xn+1, we can calculate the range of Xn values whose next iterates round to 1.0 by solving the quadratic equation

X2 - X + 1/4 - 2-26 = 0

which has solutions X = 0.5 ± 2-13.  Thus the region of the interval (0, 1) over which  Xn is an eventually fixed point is of width 2-12 = 2.44 x 10-4 centered on 0.5.  Since the probability density of finding an iterate of the logistic map with A = 4 is

P = 1 / pi[X(1 - X)]1/2

which has a value of P = 2 / pi = 0.637 for X = 0.5, the probability that an iterate will fall within the region above is 1.55 x 10-4.  Thus on average, we would expect the reciprocal of this number of iterates before the fixed point at zero is reached, or N = 6400.

    To test this prediction, the logistic map was iterated in single precision many times using a uniform random initial condition in (0,1), and the number of iterations required for zero to be reached was determined.  The source and object code used for this test are available.  Typical results follow:

Occasionally the orbit gets stuck in some very high periodic cycle and never reaches zero.  Excluding such cases, the average over 32,000 runs is N = 2031.  This result is about 3 ( or pi?) times worse than expected for reasons that are not clear.  Furthermore, the expectation is that the number N is inversely proportional to the square root of the precision.  Thus for (8-byte) double-precision with a mantissa of 52 bits, the expectation is for N = 1.5 x 108, which is in reasonable agreement with numerical results.  This particular problem can be solved by using a value of A slightly less than 4.0, such as 3.999999, although the orbit still occasionally gets caught in a cycle of some presumably high period.


Update (November 7, 2026): The "3 (or pi?)" puzzle resolved

    The estimate above used the wrong threshold.  With IEEE round-to-nearest arithmetic, the single-precision numbers just below 1 are spaced 2-24 apart, so a result rounds to 1.0 when it exceeds the halfway point 1 - 2-25, not 1 - 2-24.  The quadratic equation then becomes

X2 - X + 1/4 - 2-27 = 0

with solutions X = 0.5 ± 2-13.5, a region of width 2-12.5 = 1.73 x 10-4, a probability of 1.10 x 10-4, and an expected N = (pi/2)212.5 ≈ 9100.  A direct count of the 4345 single-precision values near 0.5 whose correctly rounded image is exactly 1.0 gives N = 9098.  Thus the measured N = 2031 is about 4.5 times (not 3 or pi times) shorter than expected, and the near-agreement with pi was a coincidence.

    New simulations with 200,000 random initial conditions each (C on a modern PC with IEEE arithmetic) give:

    The explanation is that the single-precision logistic map is a many-to-one mapping of a finite set of numbers onto itself.  X and 1 - X have the same image, and thousands of neighboring values near 0.5 (or near 0 and 1) map onto the same number.  Once two orbits land on the same number, they coincide forever.  Starting from 106 random initial conditions, only about 270,000 different values remain after 79 iterations and 57,000 after 421 iterations, compared with 866,000 and 836,000 when the small random perturbation is added.  The orbits thus merge into a tree that drains into zero (or into one of a few cycles), and the time to reach zero is set by the depth of that tree rather than by random sampling of the probability density P.  The estimate of 9100 is correct for a random sequence of iterates, but the actual orbits are not random.

    A similar thing happens in double precision.  The corrected estimate for round-to-nearest is N = (pi/2)227 ≈ 2.1 x 108 (2.2 x 108 from a direct count), and 1200 orbits with a small random perturbation gave N = (2.20 ± 0.06) x 108.  Without the perturbation, however, 84% of 8000 double-precision orbits were caught in cycles (68% of all orbits in a single cycle of period 5,638,349), and the other 16% reached zero after an average of only 1.0 x 107 iterations.  Thus the agreement with numerical results claimed above for double precision is not borne out by these calculations, although the 1997 test may have used different arithmetic, which I cannot check.  Details, figures, and a short Python program are in the note Finite-Precision Funnels in Chaotic Maps.

Updated November 7, 2026 by Rob - Clint Sprott's AI assistant.


Back to Sprott's Technical Notes