How 9 Cheenta students ranked in top 100 in ISI and CMI Entrances?

Learn MoreThere should be no such thing as boring mathematics.

Edsger W. Dijkstra

In one of our previous post, we have discussed on **Mandelbrot Set**. That set is one of the most beautiful piece of art and mystery. At the end of that post, I have said that we can calculate the value of $\pi $ using **Mandelbrot set**. So, today we will be doing exactly that.

Today our main goal is to write a **Julia programming language**. Well, I am using **Julia** as I am learning this new language and it's really great and also, "**Mandelbrot**" and "**Julia**" set are related. So, why not use **Julia language**.

It all started in $1991$. On that year, **Dave Boll** discovered a surprising occurrence of the number $\pi $ while exploring a seemingly unrelated property of the Mandelbrot set. So, let's see.

It all started when **Dave Boll** was trying to see **if the neck of the mandelbrot set** ($c=-0.75+i\cdot 0$) **is infinitely thin or not**. We was trying to find this by taking a number $\epsilon $, which is as small as we want (in simple terms $\epsilon \to 0$) and apply the recurrence relation $z = z^2 + c$ where $c$ is taken as $c = -0.75 + i\cdot \epsilon$.

Now, we see the number of steps it needs to go outside of the mandelbrot set.

$\epsilon $ | No if Iteration needed to go out |

1.0 | 3 |

0.1 | 33 |

0.01 | 315 |

0.001 | 3143 |

0.0001 | 31417 |

0.00001 | 314160 |

0.000001 | 3141593 |

What the !!... It was exactly the reaction of **Boll**, when he first saw this. Somehow the digits of $\pi $ was generated.

Let's take an example to see what is happening. Let's start with $c = -0.75 + \epsilon i = -0.75 + i $. Now, we apply the algorithm of Mandelbrot set. This is shown in the image below.

This picture clearly shows the algorithm. After taking the $c$ value, we apply the iteration. That iteration has $3$ values of $z$ ($z_0$,$z_1$,$z_2$) before the value of $z$ goes outside of the **mandelbrot set**. And as you have guessed the number is the first digit of $\pi $.

As we decrease the number $\epsilon $, the number of steps needed by the $z$ to go outside the **mandelbrot set** increases as seen in the table. In the limit $\epsilon \to 0$, the number needed will generate the exact value of $\pi $ (This value actually goes to infinity).

It doesn't just work for $-0.75 + \epsilon i$ but also works for $(0.25 + \epsilon )+ 0i $, $-0.75 - i\epsilon $, $\cdots $

The same for $0.25+\epsilon +0i$ can be visualized using a parabola. **This can also be compared with a reflective system formed by a parabolic and straight mirror**. The number of reflection will generate the value of $\pi $.

The proof of this a bit technical. If you want a proof read this - Proof of this Phenomenon.

The code is very simple to write. Remember in Julia the imaginary $i$ is represented by $im$.

The code for the case $\epsilon = 0.1$ is shown below.

As you can see it's so easy and it is giving me $33$. And if you have noticed... in Julia we can use symbols like "$\epsilon $".

Now, what we can do.. we can make a function from this and let's also use a function called **setprecision** to get high precision to decimal values to get many digits of $\pi $. We will also be using **BigInt** and **BigFloat** to handle high precision.

So, The final code is:

This function takes $n$, which is the number of digits you want in $\pi$. Now, let's see some of it's output.

Beautiful!!.. Isn't it?

We can visually see the path like shown below:

This is all for today. I hope you learnt something new and have grown a bit.

Cheenta is a knowledge partner of Aditya Birla Education Academy

Advanced Mathematical Science. Taught by olympians, researchers and true masters of the subject.

JOIN TRIAL