Topic

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 f1,…,fNf_1, \dots, f_N be maps of the plane with ∣fi(p)−fi(q)∣≤ri∣p−q∣|f_i(p) - f_i(q)| \le r_i |p - q| and every ri<1r_i < 1. The map on compact sets F(K)=f1(K)∪⋯∪fN(K)F(K) = f_1(K) \cup \dots \cup f_N(K) is then a contraction in the Hausdorff distance, so it has exactly one fixed set A=F(A)A = F(A), and Fn(K)→AF^n(K) \to A from any start. That set is the attractor.

Each map here is affine, (x,y)↦(ax+by+e, cx+dy+f)(x, y) \mapsto (ax + by + e,\ cx + dy + f), 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 FF 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, σ=λmax⁡(MTM)\sigma = \sqrt{\lambda_{\max}(M^{\mathsf T} M)}, usually irrational. contraction() returns a rational upper bound for each map, from λmax⁡=t+t2−4det⁡22\lambda_{\max} = \tfrac{t + \sqrt{t^2 - 4\det^2}}{2} with t=a2+b2+c2+d2t = a^2+b^2+c^2+d^2, every square root rounded up. When all bounds are below 1 the attractor exists. The bound is exact for similarities, so the dragons' 1/21/\sqrt2 comes out as the rational just above it.

Similarity dimension

When every map is a similarity with ratio rir_i (a rotation or reflection times a scale), the similarity dimension is the s with

r1 s+⋯+rN s=1 r_1^{\,s} + \dots + r_N^{\,s} = 1

(Moran's equation). If the pieces overlap little (the open set condition), this is also the Hausdorff dimension. With equal ratios, s=log⁡N/log⁡(1/r)s = \log N / \log(1/r): exact when that is rational, as for the Heighway dragon (two pieces of ratio 1/21/\sqrt2, so s = 2), and otherwise a certified interval, as for Sierpinski's log⁡3/log⁡2\log 3/\log 2. Unequal ratios are solved by bisection with each term enclosed, so moran(["1/2", "1/4"]) encloses log⁡2φ\log_2\varphi, 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 2−k2^{-k} the points meet and fits a line: an estimate of the box dimension, which for Sierpinski comes out near 1.585.

callreturns
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 }
attractorssierpinski, carpet, vicsek, cantorDust, heighway, levyDragon, barnsley
Try itEdit the code and run it with @ratmath/chaos and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs