Iterated function systems
A handful of maps that each shrink the plane determine one compact set, the attractor, that is the union of its own images. With rational coefficients its stages are exact, and its dimension is exact or proven.
const S = attractors.sierpinski(); // three maps (x, y) → (x/2, y/2) + shift
S.stage(5); // 243 exact rational points
S.contraction(); // { bounds: [1/2, 1/2, 1/2], contracting: true }
S.similarityDimension(); // log 3 / log 2, as a certified interval
S.chaosGame(20000, { seed: 7 }); // float points, kind "estimated"
new IFS([{ a: "1/3", d: "1/3" }, { a: "1/3", d: "1/3", e: "2/3" }]); // the Cantor set on a line
Hutchinson's theorem
Let be maps of the plane with and every . The map on compact sets is then a contraction in the Hausdorff distance, so it has exactly one fixed set , and from any start. That set is the attractor.
Each map here is affine, , with rational coefficients, written as an Affine or as a plain object such as { a: "1/2", d: "1/2", e: "1/4", f: "1/2" }. stage(n) applies n times to the fixed point of the first map (which lies in A), so every point it returns is a point of the attractor, exactly.
Is it a contraction?
The Lipschitz constant of an affine map is the largest singular value of its matrix, , usually irrational. contraction() returns a rational upper bound for each map, from with , every square root rounded up. When all bounds are below 1 the attractor exists. The bound is exact for similarities, so the dragons' comes out as the rational just above it.
Similarity dimension
When every map is a similarity with ratio (a rotation or reflection times a scale), the similarity dimension is the s with
(Moran's equation). If the pieces overlap little (the open set condition), this is also the Hausdorff dimension. With equal ratios, : exact when that is rational, as for the Heighway dragon (two pieces of ratio , so s = 2), and otherwise a certified interval, as for Sierpinski's . Unequal ratios are solved by bisection with each term enclosed, so moran(["1/2", "1/4"]) encloses , the golden ratio's logarithm. The open set condition is not checked.
The chaos game, and box counting
Picking one map at random each step and applying it to a point gives points that fill the attractor (the probabilities matter for Barnsley's fern, where the stem map is chosen 1% of the time). The library seeds its own generator, so a picture can be repeated, and returns floats with kind: "estimated". boxCounting(points) counts the boxes of side the points meet and fits a line: an estimate of the box dimension, which for Sierpinski comes out near 1.585.
| call | returns |
|---|---|
| new IFS(maps, { name, probabilities }) | An IFS; maps are Affine or { a, b, c, d, e, f } |
| stage(n, start), step(points), fixedPoint(i) | Exact rational points |
| contraction() | { bounds, contracting } |
| similarityDimension(), moran(ratios) | { kind: "exact" | "certified", value, interval, formula } |
| chaosGame(n, { seed, skip }), boxCounting(points, { scales }) | Estimated: Float64Array points; { dimension, rows } |
| attractors | sierpinski, carpet, vicsek, cantorDust, heighway, levyDragon, barnsley |
@ratmath/chaos and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.