You can find the code used to generate the post’s images and animations in github.com/gabriel-msilva/fractal-sets.
Update 2022-10-10: Fixed first example for Mandelbrot set.
Fractals are a beautifully complex – and I usually do not use these words together – topic in Mathematics. Among many conceptual disagreements between mathematicians, at some point Benoit Mendelbrot proposed a simple and approachable definition:
A fractal is a shape made of parts similar to the whole in some way.
Figure 1 illustrates this. You could painstakingly count how many triangles do you see to measure your IQ in some online test, but let’s look at some properties of this shape.
Figure 1: A simple example of a fractal, called Sierpiński triangle. The triangular patterns repeat over and over in smaller scales.
We notice that the main equilateral triangle repeats itself into many other smaller triangles. More formally, this property is called self-similarity, when parts of a shape have exactly or approximately similar parts of itself (“the whole”). This is observed by zooming into the shape, just to find the same patterns again.
Despite the figure presenting a limited number of triangles, you could easily extrapolate the shape at arbitrarily smaller scales by understanding the repeating pattern, the rule used to create this shape. Maybe something like:
- Start with an equilateral triangle of any size;
- Inscribe another equilateral triangle into it and remove this area;
- Repeat step 2 for each triangle formed
Figure 1 illustrates the first iterations Notice that this set of rules does not halt, i.e. it goes on indefinitely. If you did not stop drawing this pattern, you would obtain a fractal called Sierpiński triangle.
This a simple example of a fractal. There are many others that create more complex patterns, but not necessarily by much more complex rules. Gaston Julia and Benoit Mandelbrot were influential mathematicians in fractal geometry, well-known for the sets which take their names.
Mandelbrot set
The Mandelbrot set is the set of complex numbers c=x+yic=x+yi for which the sequence
zn+1=z2n+c,z0=0zn+1=z2n+c,z0=0
does not diverge as nn grows. For example, when c=1c=1,
z0=0z1=02+1=1z2=12+1=2z3=22+1=5z4=52+1=26…z0=0z1=02+1=1z2=12+1=2z3=22+1=5z4=52+1=26…
We can see that |zn|→∞|zn|→∞ when n→∞n→∞ and thus c=1c=1 is not part of the Mandelbrot set. On the other hand, for c=−1c=−1, znzn oscillates between −1−1 and 00, i.e. it remains bounded, so it belongs to the set.
z0=0z1=02−1=−1z2=(−1)2−1=0z3=02−1=−1z4=(−1)2−1=0…z0=0z1=02−1=−1z2=(−1)2−1=0z3=02−1=−1z4=(−1)2−1=0…
For the boundary |z|≤2|z|≤2 (|z|=√x2+y2|z|=√x2+y2, so a circle in the complex plane), the Mandelbrot set looks like Figure 3. We are looking at cc points for which |zn|≤2|zn|≤2 for every n={1,2,3,…,100}n={1,2,3,…,100} iteration.
It also interesting to see how many iterations does it take for znzn to escape the boundary. For c=−0.8+0.5ic=−0.8+0.5i in Figure 4, zz takes n=6n=6 iterations to escape the boundary.
## Warning in ggforce::geom_circle(aes(x0 = 0, y0 = 0, r = 2), fill = "gray80", : All aesthetics have length 1, but the data has 7 rows.
## ℹ Did you mean to use `annotate()`?
Figure 4: For c=−0.8+0.5ic=−0.8+0.5i, zz escapes the boundary |z|≤2|z|≤2 at the 6th iteration.
If we map this iteration count to the color aesthetic of each point cc, we get Figure 5.
Figure 5: Colored Mandelbrot set for 100 iterations, where the color represents the iteration nn when |zn|>2|zn|>2.
But where is the self-similarity? We need to zoom-in to see it better – and there are many “hidden” repeating patterns inside the Mandelbrot set. Figure 6 focus on one of these, but you probably can spot other across the way.
Actually, the colored Mandelbrot is not so smooth as can be seen on Figure 5. It creates “bands of color” as in Figure 7a, because the iteration count is a natural number. The continuous coloring (Figure 7b) is obtained by applying an algorithm called “normalized iteration count”, which adds δ∈[0,1[δ∈[0,1[ to iteration count as function of |z||z|.
Julia set
Similarly to the Mandelbrot set, the Julia set is the set of complex numbers zz for which the recursive function
R(z)=P(z)Q(z)R(z)=P(z)Q(z)
does not diverge (or escapes a boundary) for a increasing number of iterations. PP and QQ are polynomials without common divisors. Consider a particular Julia set where R(z)=z2+cR(z)=z2+c, then we have an equation analogous to the logistic mapping of the Mandelbrot set
zn+1=z2n+czn+1=z2n+c
but for a fixed complex cc instead of a fixed z0z0. In the same manner, we will count how many iterations does it take for znzn to escape the boundary |z|≤2|z|≤2 for a given cc. Figure 8 shows this particular Julia set for two values of cc.
The Julia set also has many self-similarities, as illustrated by Figure 9.
Relation between Mandelbrot and Julia sets
While Mandelbrot set is mapped into zz complex plane, Julia set is mapped into cc complex plane. So, for each point of the Mandelbrot set there is a corresponding Julia set, and vice-versa. Figure 10 shows this correspondence along a line segment on the Mandelbrot set.
Let’s take this opportunity to remember “the most remarkable formula in mathematics”, the Euler’s formula:
eix=cosx+isinx,for any x∈R When x=π,
eiπ+1=0
A beautiful identity as it contains five of the most fundamental numbers in Mathematics. Let c=reiθ, then
{Re(c)=rcosθIm(c)=rsinθ
which is a circumference in the complex plane, thus connecting trigonometry and complex numbers. Figure 11 shows Julia sets for a counter-clockwise rotation around a circumference reiθ.
Final notes
Fractal shapes can be seen in Nature like in a humble cauliflower, but they are also applied in technology, as fractal antennas, or in explaining considerable differences in coastline length measurements.
Aside from its applications, I think fractals are just pretty neat. I mean, look at this:
To close, my recommendation of a couple of videos from amazing YouTube channels to dive more into fractals.







