Insight·Foundations: Maths & Stats·13 March 2017

Approximating Pi with the Mandelbrot Set

Imagine you're stranded on a desert island and you really need a good approximation of π for some super machine you're building to make your escape. You can't remember enough decimal places — but you do remember your fractals.

Topic
Foundations: Maths & Stats
Published
13 March 2017
By
Dr Stuart Woolley
In short

Near the cusp of the Mandelbrot Set at c = 0.25, count how many iterations I of the feedback equation z² + c it takes to escape past 2.0 when you start a tiny distance ε beyond the cusp. As ε shrinks, those iteration counts spell out the digits of π — and √ε × I converges on π directly. It's beautiful, and the least efficient method of computing π you'll ever meet.

Perhaps your machine is AC powered from a tidal source or wind generator and there are phase-angle calculations to make for the flux capacitor to power up. Suffice it to say you really need a good approximation of π for things to work just right — and you can’t remember it to enough decimal places. Given a pencil, some paper and a simple calculator, there just may be a way, if you have a good recollection of the Mandelbrot Set and its properties.

Its calculation is based on the concept of prisoners and escapees — quite relevant to our island scenario. The core of the computation is a feedback equation of the form z² + c. Feeding the result back in from z = 0.0 gives an infinite sequence:

0 → c → c² + c → c⁴ + 2c³ + c² + c → …

As the sequence progresses, the result either shrinks or grows without bound: the original point is either imprisoned within the set or escapes it. If a number’s iterations stay ≤ 2 it’s in the set; if they exceed 2 it’s out. (The value 2 is an arbitrary boundary that comfortably encompasses the whole set for our purposes.)

The Mandelbrot Set plotted on the complex plane, with a green arrow marking the cusp where it crosses the real axis at x = 0.25.
The cusp of the Mandelbrot Set crosses the real axis at x = 0.25.

What happens near the cusp?

The set crosses the x-axis exactly at x = 0.25 — the cusp. Anything ≤ 0.25 is in the set; anything greater escapes. Take c = 0.25 as our starting point and explore values just a little bigger, c + ε, asking how many iterations I(c) it takes for the result to grow past 2.0. With ε = 1.0 (so c = 1.25):

I(0): 0.0²    + 1.25
I(1): 1.25²   + 1.25
I(2): 1.5625² + 1.25 = 2.8125  [bang — bigger than 2.0]

Two iterations. With ε = 0.5 (c = 0.75) it again takes two. With ε = 0.3 (c = 0.55):

I(0): 0.0²    + 0.55
I(1): 0.3025² + 0.55 = 0.8525
I(2): 0.8525² + 0.55 = 1.2767
I(3): 1.2767² + 0.55 = 2.1801…  [bang]

Three iterations. Tabulating ε against the iterations to escape:

εI(c)
1.02
0.18
0.0130
0.00197
0.0001312
0.00001991
0.0000013140
0.00000019933
0.0000000131414
0.00000000199344
0.0000000001314157
0.00000000001993457
0.0000000000013141625

Can you see what’s happening?

As we approach 0.25 with ever-smaller offsets, the iteration count alternately approximates the digit sequence of π. Even with only a rough memory that π starts “3.something”, you can place the decimal point and read off the answer. But there’s something subtler. Add a column of √ε × I(n):

εI(n)√ε × I(n)
1.022.000000
0.182.529822
0.01303.000000
0.001973.067409
0.00013123.120000
0.000019913.133817
0.00000131403.140000
0.000000199333.141090
0.00000001314143.141400
0.000000001993443.141533
0.00000000013141573.141570
0.000000000019934573.141587

It’s a little like magic: √ε × I(n) is an approximation to π on every row, and it’s closing in — no need even to insert the decimal point yourself.

It’s the most inefficient method of approximating π I’ve ever come across — but it’s certainly something you could do on a desert island while awaiting rescue. A lot of time.

Extra credit

If you have a powerful machine and want to continue the sequence, here’s the Mathematica snippet for counting iterations:

ostart = 0.25;
e = 0.0000000000000001;
c = ostart + e;
iter2[x_] := x^2 + c;
Length[NestWhileList[iter2, c, # <= 2.0 &]]

As the iteration count grows, so do floating-point rounding errors, so there’s a machine-dependent limit to how far you can go. There are many other ways to approximate π using the Mandelbrot Set, but this is about the simplest — and it avoids complex numbers entirely, even if the arithmetic is intensive.

From island maths to energy data

Curiosities like this are the same pattern-spotting instinct we bring to operational data — finding the structure hiding inside a stream of numbers. It’s exactly what powers AI in the energy sector and anomaly detection like finding needles in the digital haystack.

We like hard problems

From fractals to forecasting, finding the structure inside data is what we do. If you've a complex energy problem worth solving, let's talk.