Mandelbrot and Julia sets
A pixel is a small square of the plane, not a point. Here every pixel of a Mandelbrot or Julia picture is proved to lie outside the set, proved to lie inside it, or left undecided, and only the boundary is ever undecided.
mandelbrot({ re: ["-2", "1/2"], im: ["-5/4", "5/4"], width: 72, height: 30 });
julia("-1", { re: ["-2", "2"], im: ["-1", "1"] }); // the basilica
mandelbrotPoint("-13/10"); // { verdict: "inside", period: 4, … }
juliaPoint("-1", "1/2"); // an exact z₀ under z → z² − 1
The sets
For , the filled Julia set is the set of whose orbit stays bounded, and the Mandelbrot set M is the set of c for which the orbit of 0 stays bounded. Both are compact, and the usual pictures colour a point by how many steps its float orbit takes to pass 2. That is a heuristic twice over: the point stands for a whole pixel, and the float orbit is not the true orbit.
Outside, proved
If then , and the orbit goes to infinity. The library carries the whole pixel as a box of complex numbers in interval arithmetic, with every float result moved outward by more than its rounding error, so if some iterate of the box lies entirely beyond the radius, every point of the pixel escapes.
Inside, proved
Being inside is harder, because no finite number of steps shows that an orbit stays bounded forever. Two tests prove it here. For M, the main cardioid with , and the disc , contain exactly the c with an attracting fixed point or 2-cycle; the inequalities are checked on the whole pixel. Otherwise the library looks for a trap: a box B around the orbit's current position with in intervals. Then every later iterate stays in B, so the orbit is bounded, and B holds an attracting cycle of period dividing p. A pixel that cannot be decided whole is split into 4, then 16 pieces (depth).
For Julia sets the trap is built around the attracting cycle (found in floats, then proved by the trap itself). If has no attracting cycle, as for c outside M, nothing can be inside and nothing is claimed.
Single points, exactly
mandelbrotPoint(c) and juliaPoint(c, z0) do the same for one exact point with the complex package's rational rectangles, rounded outward to a chosen number of bits. Points on the boundary, such as , or , stay undecided, which is the honest answer: they are in M, but no escape or trap argument shows it.
| call | returns |
|---|---|
| mandelbrot({ re, im, width, height, maxIter, maxPeriod, depth }) | PixelGrid: kind (0 undecided, 1 inside, 2 outside), counts, escape, toText() |
| julia(c, { re, im, width, height, maxIter, depth }) | PixelGrid, with the cycle it trapped |
| mandelbrotPoint(c, { maxIter, bits, maxPeriod }) | { verdict, reason, period? or escape? } |
| juliaPoint(c, z0, { … }) | The same for a point of the plane |
@ratmath/chaos and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.