Knowledge Sprint SeriesMT24 Learning

Phase 12 · Sprint 38/90 · The Complexity LensKoch · Richardson · Mandelbrot · Zipf · Clauset

Fractals, Scaling and the Shape of Complexity

A coast has no length until you name the ruler, and a straight line on a log plot is not yet a law.

In short. Self-similar shapes, the length of the coast of Britain, why scaling holds only over a range, and how to test a power law properly.

Sprint 38 of 90 infographic: Fractals, Scaling and the Shape of Complexity. A coast has no length until you name the ruler, and a straight line on a log plot is not yet a law. The full text of the image is on this page.
Full resolution2160 × 2700 PNGPhase summary

The part of the image you are reading lights up. Tap a part to jump to its text.

Fig. 1 in words

Rulers, a coast and a novel · real map + real text · same data as code 05

  1. 1 Ruler check

    • the Koch curve, drawn in blue: reads 1.259 · true 1.262
    • Koch curve: 7 levels (drawn at 4),
    • 4 rulers: the method checked on a curve whose answer is known
  2. 2 One island

    • the outline of the island walked with two rulers: 200 km ruler · 2 404 km (purple) and 50 km ruler · 3 424 km (brown)
    • 1:10m map
  3. 3 Length by ruler

    • length (axis 2 000 · 4 000 · 8 000) against ruler from 200 km to 1.6 km: four points on a dashed line marked D 1.27, then four on a flatter dashed line marked D 1.14
    • ruler shrinks →, length grows ↑
    • slope eases from 12.5 km down
  4. 4 Words by rank

    • count of each word (axis 1 · 100 · 10 000) against rank 1 to 16 950: the points follow a dashed straight line; R² 0.980 · α 1.94
    • dotted line: tail: count ≥ 7
    • Moby Dick: straight line, yet a lognormal fits the tail as well

01 Self-Similar Dimension

  • Koch (1904): replace the middle third of each segment by a tent, again and again
  • 4 copies at ⅓ scale: D = log 4 ÷ log 3 = 1.262, between a line and a plane
  • My ruler method reads 1.259 on it: test a method on a known answer first

A fractal dimension says how fast detail grows as you zoom in.

02 How Long Is Britain? Coast

  • Richardson (1961): measured length grows as the ruler shrinks
  • Mandelbrot (1967) read the slope as a dimension: D = 1.25 for Britain’s west coast
  • My 1:10m map, whole island: D = 1.27 for rulers 200 to 25 km

Claim tested: “a coast has one true length.” Not without its ruler.

03 Scaling Has a Range Limits

  • From 12.5 km down the slope eases to 1.14; the map’s points are a median 1.4 km apart
  • A map cannot show bays smaller than its own spacing
  • If D stayed 1.27, length would grow 3.7× over these rulers; it grew 2.89×

Report a dimension with the range of rulers it came from.

04 Power Laws, Tested Clauset

  • Zipf (1949): frequency falls with rank; Moby Dick’s rank line has R² 0.980
  • Clauset et al. (2009): a straight log–log line is “necessary but not sufficient”
  • Tail from 7 (3 077 words), α 1.94 (theirs 1.95); lognormal not ruled out, as in their p 0.69

Claim tested: “straight on log–log means power law.” The inference fails.

05 Try It Yourself NUMPY 2.5.3 · POWERLAW 2.0.0

sprint38_fractals_scaling_shape_of_complexity.py

import json, re, warnings, numpy as np, powerlaw
from collections import Counter; from pyproj import Transformer
from shapely.geometry import shape
warnings.simplefilter("ignore", DeprecationWarning)
def divider(P, r):  # walk a ruler of length r along P
    p, j, n = P[0], 0, 0
    while True:
        d = np.hypot(*(P[j+1:] - p).T)
        far = np.flatnonzero(d >= r)
        if not len(far): return n*r + (d[-1] if len(d) else 0)
        k = far[0]; A = P[j+k] if k else p; B = P[j+k+1]
        u, w = B - A, A - p; a, b = u @ u, 2 * u @ w
        t = (-b + np.sqrt(b*b - 4*a*(w @ w - r*r))) / (2*a)
        p, j, n = A + t*u, j + k, n + 1
def dim(r, L): return 1 - np.polyfit(np.log(r), np.log(L), 1)[0]
k = np.array([[0., 0], [1, 0]])  # Koch curve, 7 levels
for _ in range(7):
    a, b = k[:-1], k[1:]; d = (b - a) / 3
    c = a + d + d @ [[.5, -3**.5/2], [3**.5/2, .5]]
    s = np.stack([a, a+d, c, a+2*d], 1).reshape(-1, 2)
    k = np.vstack([s, k[-1:]])
r = .9 * 3.0 ** -np.arange(2, 6)  # off the grid
print(f"Koch: D = {dim(r, [divider(k, x) for x in r]):.3f}"
      f" (log 4 / log 3 = {np.log(4)/np.log(3):.3f})")
with open("ne_10m_admin_0_countries.json") as fh:
    uk = [f for f in json.load(fh)["features"]
          if f["properties"]["ADMIN"] == "United Kingdom"][0]
gb = max(shape(uk["geometry"]).geoms, key=lambda g: g.area)
to_m = Transformer.from_crs(4326, 27700, always_xy=True)
xy = np.array(gb.exterior.coords).T  # lon, lat
P = np.column_stack(to_m.transform(*xy))  # metres
gap = np.median(np.hypot(*np.diff(P, axis=0).T))
print(f"Great Britain: {len(P)} points, median gap {gap/1e3:.1f} km")
r = 200e3 / 2.0 ** np.arange(8)  # 200 km ... 1.6 km
L = np.array([divider(P, x) for x in r])
print("lengths, km:", *np.round(L / 1e3).astype(int))
print(f"D for rulers 200-25 km: {dim(r[:4], L[:4]):.2f}",
      f"| 12.5-1.6 km: {dim(r[4:], L[4:]):.2f}")
with open("melville-moby_dick.txt") as fh:
    w = Counter(re.findall(r"[a-z]+", fh.read().lower()))
f = np.array(sorted(w.values(), reverse=True))
lr, lf = np.log10(np.arange(1, len(f) + 1)), np.log10(f)
z = np.polyfit(lr, lf, 1)[0]; R2 = np.corrcoef(lr, lf)[0, 1]**2
print(f"Moby Dick: {len(f)} words, rank slope {z:.2f}, R^2 {R2:.3f}")
fit = powerlaw.Fit(f, discrete=True, verbose=False)
n = (f >= fit.xmin).sum()  # tail chosen by KS (Clauset)
print(f"tail from {fit.xmin:.0f} ({n} words): alpha {fit.alpha:.2f}")
out = {}
for alt in ("lognormal", "exponential"):
    R, p = fit.distribution_compare("power_law", alt)
    out[alt] = bool(R > 0 and p < .1)  # beaten at 10%?
print("ruled out by the power law:", out)

Output, as printed on the image

Output printed on the image:
Koch: D = 1.259 (log 4 / log 3 = 1.262)
Great Britain: 3707 points, median gap 1.4 km
lengths, km: 2404 2813 3424 4244 5175 5989 6585 6958
D for rulers 200-25 km: 1.27 | 12.5-1.6 km: 1.14
Moby Dick: 16950 words, rank slope -1.16, R^2 0.980
tail from 7 (3077 words): alpha 1.94
ruled out by the power law: {'lognormal': False, 'exponential': True}

Run it. sprint38_fractals_scaling_shape_of_complexity.py · versions, data and steps

Check: 1280.27 = 3.7 vs 6 958 ÷ 2 404 = 2.89 · log 4 ÷ log 3 = 1.262

06 General Notes Practice

  • Fit the tail by likelihood, pick its start by KS, test rivals (Clauset’s fit bootstrap not run here)
  • The lognormal stays in: p 0.95 in the powerlaw package, 0.78 in my own fit
  • Quote a length with its ruler: 2 404 and 6 958 km are both Britain

Two optimisers, different numbers, the same verdict.

07 Mini Project Hands-on

  • Austen’s Emma: the lognormal beats the power law (p 0.04)
  • Sprint 37’s 50 × 50 sandpile: tail from 916 topplings (925 avalanches); both rivals win
  • South Africa’s coast, picked as one of the smoothest, gives D = 1.02 (Mandelbrot 1967)

Check: 6 958 ÷ 2 404 = 2.89 for a 128× finer ruler.

R Trusted Sources

  1. Koch (1904) Arkiv för Matematik 1, 681
  2. Richardson (1961) Gen. Syst. Yearb. 6, 139
  3. Mandelbrot (1967) How Long Is the Coast of Britain?, Science 156(3775), 636–638
  4. Zipf (1949) Human Behavior and the Principle of Least Effort, Addison-Wesley
  5. Clauset, Shalizi & Newman (2009) Power-Law Distributions in Empirical Data, SIAM Rev. 51(4), 661–703
  6. Alstott et al. (2014) powerlaw, PLoS ONE 9(1), e85777
  7. Natural Earth 1:10m Admin 0
  8. Melville (1851) Moby Dick, Austen (1815) Emma: NLTK Gutenberg

Cite this phase

Tahri, M. (2026). MT24 Learning — Knowledge Sprint Series, Phase 12: The Complexity Lens (Version 1.0) [Educational resource]. Zenodo. https://doi.org/10.5281/zenodo.23694200

Version DOI 10.5281/zenodo.23694200 · all versions 10.5281/zenodo.23694199 · first published 20 October 2026