Orbits, true and floating
Iterating a map is the whole subject, and it is the one computation floating point cannot be trusted with. An orbit here comes in three kinds, and they can be put side by side.
const f = logistic(4); // or map("r*x*(1 - x)", { params: { r: 4 } })
f.orbit("1/3", 3); // exact rationals
f.enclosedOrbit("1/10", 200); // { terms, bits, width }: the true orbit as intervals
f.floatOrbit(0.1, 200); // what a program computes
f.compare("1/10", 80); // { rows, parted }
doubling("1/10"); // x → 2x mod 1 on a rational, with its cycle
The exact orbit
If f is a polynomial with rational coefficients and is rational, every is rational and orbit returns them. This is the true orbit, but it cannot be long: for a quadratic map the number of digits doubles at every step, so already has about a million. orbit stops with an error once a term passes maxBits binary digits.
The enclosed orbit
For long orbits each term is kept as an interval with rational ends that is certain to contain the true . The next interval is computed so that it contains f(x) for every x in the current one, and its ends are rounded outward to a fixed number of binary digits. Chaos stretches intervals too: with a Lyapunov exponent λ the width grows like . The cure is to carry more digits than the stretching eats, and enclosedOrbit does that itself: it starts again with twice the digits until the last term is known to the accuracy asked for. For the logistic map with r = 4, one binary digit is lost per step, so 200 steps to 12 decimals needs about 250 binary digits. The result reports the number it used.
An orbit that runs off to infinity is reported as such, and an interval that reaches a division by zero is refused.
The floating-point orbit, and where it parts
A double has 53 binary digits. Each step of a chaotic map magnifies the rounding error of the step before, so the float orbit drifts from the true one and, after roughly 53/(λ/ln 2) steps, has nothing in common with it. compare returns both, with the error and the number of correct digits at every step, and parted, the first step at which no digit is right. The float orbit still looks like an orbit of the map, which is why the failure is invisible without the true one beside it.
The doubling map
shifts the binary expansion of x one place to the left. A rational p/q has a repeating expansion, so its orbit is eventually periodic, and doubling finds the cycle exactly. In doubles every number has a finite binary expansion, so every float orbit reaches 0 within about 55 steps and stays there: the computed behaviour is wrong for every starting point that does not really end at 0. floatReachesZeroAt gives the step.
| call | returns |
|---|---|
| map(formula, { variable = "x", params }) | IteratedMap |
| logistic(r), tent(mu), quadratic(c) | , , |
| f.at(x), f.enclose(X), f.float(x), f.derivativeAt(x) | Rational, RationalInterval, number |
| f.orbit(x0, n, { maxBits }) | Rational[] |
| f.enclosedOrbit(x0, n, { digits = 12 }) | { terms, bits, width } |
| f.floatOrbit(x0, n), f.cobweb(x0, n) | number[]; points of a cobweb diagram |
| f.compare(x0, n) | { rows: [{ n, float, exact, error, digits }], parted } |
| f.with({ r: "3.2" }) | the same family at another parameter |
| doubling(x0, { base = 2 }) | { orbit, preperiod, period, cycle, floatReachesZeroAt } |
@ratmath/chaos and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.