# Mandelbrot Sets, Fractals, Dynamical Systems, Mathematics, Physics, Arts by Rendering, Cryptography, Astrophotography and Spirituality – A Connecting Post

## Introduction

All fractals can be generated using an Iterated Function System (IFS). An IFS consists of a function f which is executed in a feedback loop, also known to computer students as a recursive function. That means, the output of the function is given as input when the function calls itself. The first time the function is called, you input some initial value f(0).

In the early 20th century french mathematicians Gaston Julia and Pierre Fatou ignited the inquiry of the behavior of sets of points in the complex plane as they are calculated through Iterated Function Systems (ITFs). At that time computers followed mostly Herman Hollerith designs a punch-card systems invented first at about 1890, so it was practically impossible to study the structure of practically impossible to study the structure of such sets in any insightful manner as suthe computing resources were to o far from being at their disposal.

Computing origins

This inquiry was ignited again in 1961 along with the research of one Jewish-Polish Mathematician Benoit Mandelbrot from IBM, who’s task was to reduce the noise disturbing transmission on telephony lines. The noise seemed to burst between rough or none at all.

With high-powered computers at his disposal the Jewish-Polish Mathematician Benoit Mandelbrot continued his research at IBM. Mandelbrot chose to visualise the data. The results showed a structure with self-similarity at all scales – This is called a Fractal.
The HPC of the time was enough to allow Mandelbrot to plot the sets on paper. He noted that they were also fractals, with astonishing richness of detail. By making a small change to the Iterated Function System (IFS), he came up with another fractal, which was later to be known as the Mandelbrot fractal or the Mandelbrot set. Benoit Mandelbrot wrote down his findings in the book “The Fractal Geometry of Nature” which was published in 1982.

The Fractal Geometry of Nature – Fractal Structure of a Romanesco Cauliflower

## The Cantor Set

The Cantor dust fractal can be created using a black square as initial value. Each time you run the IFS in a feedback loop you split each square into four smaller squares and put them beside each other in the figure below.

If you repeat this process many times, you will eventually end up with a large amount of uniformly distributed dots, or ”Cantor dust”.

## Mandelbrot Set

### Definition of the Mandelbrot Set

The Mandelbrot set is a set of points in the complex plane which as we know is a two-dimensional space with the a vertical imaginary axis, and a horizontal real axis.
A point in the plane can be described using a complex number c ∈ C (∈ means sign for belonging as mathematics is the best spoken language to describe physics in as far as nowadays scientists have) written on the form c=a+bi where a, b ∈ R and i is the square root of -1 by definition.

If you let the points belonging to the Mandelbrot set to be coloured in black, you obtain the shape depicted below:

Now pay close attention: the black bulb in the middle is the actual Mandelbrot set.
This is perhaps the most interesting point about Mandelbrot Sets:

We shall now return to our most precise language (e.g. mathematics) to formally the Mandelbrot set:

A point c ∈ C belong to the Mandelbrot set iff (if and only if – in mathematical logic where “if and only if” {shortened as “iff“} is a biconditional logical connective between statements, where either both statements are true or both are false):

Here we have an IFS with the recursive formula above and an initial value of z0 = 0. In ea ch loop, you square the previous number and seed the result with the value of c.
The vertical brackets denotes the well known Euclidean Norm which means how far away a point in the complex plane is from the origin:

We also say that a point c belongs to the Mandelbrot set if it remains bounded when we run the formula in a feedback loop.
Another important point to take in mind is that It is not obvious whether the point will eventually escape towards infinity or not, and it is usually not possible to tell. This is the reason why, in practical implementations, you run the feedback loop for a maximum number of times, say n times.
We say if the point still remains within a radius of 2 from origin, the point may be considered to belong to the set. We choose the value of 2 because it is possible to mathematically show that if the norm of z in the nth iteration is greater than 2, successive iterations will eventually escape towards infinity (Mathematics is a strong language to be able to speak fluently… ❣). This has his own name: The Bailout Radius.
To earn the ability to distinguish and appreciate the nature of fractals, one would recognize that as zooming in, the the size of n has to be increased, and as a direct result also the need for HPC.

### Rendering (or the importance of coloring choice) In Mandelbrot Sets

The Mandelbrot set is actually a great example of how you can store an “infinite” amount of information on a finite medium. The prerequisite for creating an artistically appealing fractal lies in the existence of a colouring function c(x). The purpose of the colouring function is often to colour the points which lies outside the set. This is called the aura of the Mandelbrot set. It is also possible to colour the set itself, although it is usually coloured in a fixed colour like black.

The most common algorithm for colouring the aura of the set is called the escape time algorithm. The escape time algorithm is based on the value of n, that means, the number of iterations before zn end up outside the bailout radius.
A simple, yet beautiful way of colouring, is to colour the actual set in black and then fade the aura from red to black. One way of defining the colouring function.
A simple, yet beautiful way of colouring, is to colour the actual set in black and then fade the aura from red to black. One way of defining the colouring function. The colouring function will then be:

As explained above, the idea is to set in black and then fade the aura, so c for the nth iteration returns a component of a RGB-colour (which one?…  to each his own. An important rule for life: “never argue on what tastes and/or smells better”).
It is optional also to be more colorful and use all three (e.g. Red, Green and Blue). In such a case we shall use three functions: cr(x), cg(x) and cb(x) (where the subscript denotes the colouring).
In a very joyful mood it is optional to go with the choice of an a priori prepared color palette, such that c(x) points out a colour in the palette creating a rainbow 🌈 effect.

Mandelbrot Set Explained

## Buddhabrot

Buddha has many forms of transfiguration and incarnation, and can manifest himself in manifold ways according to the ability of each person – The Teaching of Buddha

I shall open this chapter with a full disclosure. I am quite a JewBu… I wake up very early (about 5:00 🕔) for the sole purpose of enjoying the practice of actually being present in the moment, which in turn I feel as if it helps me in becoming just a bit more mindful throughout the day, particularly when difficult times of any Cantor set of a difficult and noisy (from the inside) situation. Just like in a Cantor set The dots represents short periods of time where there I feel the noisy and multifaceted nature of relationships and desires arre shifting me away from the awareness of what’s going on in the present moment without being judgemental… Just be and aware… Such a Cantor set nature brings more clusters of noise to appear. These clusters represents ”a burst” of noise, periods of time where there is a lot of disturbance. I find my morning meditations to be very helpful dealing with these noise clusters and so have less confusion and more clarity in my life. The mathematical representation for of JewBu nature…

Returning to this chapter main theme, The Buddhabrot as shown above is a variant a Mandelbrot set. The term Buddhabrot arises of course from the fact that the fractal looks like a meditating Buddha.
What differs it from any other Mandelbrot set is not in its Mandelbrot set definition but in the colouring algorithm used.
To create a Buddhabrot we count the number of times a specific point has been visited and not the number of iterations required like in the escape time algorithm.
The fractalization is rendered by splitting the blank sheet into a matrix N. Each element of the matrix is the number of times a specific area of the sheet has been visited. For every iteration, the updated zn is added to the number on the corresponding position in the matrix. Once a cycle of the Iterated Function System (ITF) runs till an a priori n is reached for all possible c, one may make a second pass over N.

Note that even though the images resemble Hindu art, they were actually generated completely automatically, without any sort of human artistic intervention.

In sum, produce a Buddhabrot image only requires some very simple modifications to the traditional mandelbrot rendering technique: Instead of selecting initial points on the real-complex plane one for each pixel, initial points are selected randomly from the image region or larger as needed. Then, each initial point is iterated using the standard mandelbrot function in order to first test whether it escapes from the region near the origin or not. Only those that do escape are then re-iterated in a second, pass. (The ones that don’t escape – I.E. which are believed to be within the Mandelbrot Set – are ignored). During re-iteration, one increment a counter for each pixel that it lands on before eventually exiting. Eventually, successive images barely differ from each other.

Unlike the Mandelbrot where choosing the number of iterations that are tested in order to determine whether the point escapes or not (often called the “bail-out”) doesn’t have a profound effect on the actual structure, in the buddhabrot it can. For example in the following the first uses a bail-out of 200 and the second uses 20. For very high quality versions of the buddhabrot a bail-out above 1000 is suggested, of course that increases compute times:

There are a number of ways one might colour the buddhabrot, the most common is to compute the buddhabrot a number of times with different number of iterations. Each of these images is mapped to a colour and combined, sometimes with different bail-out values, thus combining different “exposures” (an algorithmic methodology used often in astrophotography and termed “false colour rendering” – see below.

An example for a “False Color” rendering algorithm may be applied (see Melinda Green on Usenet in 1993 buddhabrot) by rendering  a grayscale version with t=500, another grayscale version with t=5,000, and a third with t=50,000. Then use these three grayscale images as the red (t=500), green (t=5,000), and blue (t=50,000) channels to obtain a full-color image:

#### An Excerpt About Astrophotography and “False Colour Rendering”:

Different elements and compounds glow or reflect different colors of light. Instead of taking a standard color picture, astronomers often take a picture with a black and white camera (tends to be more sensitive) through filters. Some filters are designed to only allow light of certain colors (even infrared or ultraviolet) to get through.
For example, One may use an OIII filter – a filter designed to only show the color of light emitted by triple-ionized oxygen (prevalent in certain nebulae). A picture through this filter, that’s all I’m seeing, the OIII gas around an object (Emission from O III comes from a collision process, where free electrons with energies of ∼1eV – about the amount of the oxygen’s low excitation potential – collide with oxygen atoms).

When final picture is created, a combination of the images from different filters may be applied in any desirable way for the specific task of visual inspection. Typically red, blue, and green images are taken and used to make a regular color image. Then, for the inspection of OIII can add the OIII filter picture on-top of the RGB, and set it up to be whatever color is desired want (because the black and white cameras only records brightness levels, it doesn’t matter in principal which color is chosen as the base-color). For example one could make the OIII filter taken picture to appear orange and layer it in with the rest.

This is often done with “invisible” light sources. We cannot see infrared or ultraviolet, or x-rays. These can be taken in black and white and a color assigned and layered in with the rest. Because the colors assigned are not the “real” colors of those lights (else they would have been seen…) they are called “False Color“.

## Cryptography

In cryptography, a key exchange is the process of two parties exchanging keys with each other allowing the use of a cryptographic algorithm. A protocol termed “The Diffie-Hellman Protocol” is such a key exchange between the two parties. In the Diffie-Hellman Protocol the most important property is such that even if the information is intercepted by a third party it is not possible to deduct the meaning of the information. In other words, the Diffie-Hellman protocol is a secured protocol.

The Diffie-Hellman Protocol

#### Fractal Key Exchange algorithm

A very similar protocol to the Diffie-Hellman protocol relies on the following mathematical description (See: New Key Exchange Protocol Based on Mandelbrot and Julia Fractal Sets):

Translating the mathematical notations: qi here is a complex number, c, d, e ∈ C means that a, d, and e belong in the complex plane, ∀x means for every number x, and x∈ Z means that x is an integer.

qi is the result from running q in a feedback loop i times. Now comes the important part of defining the two keys, one for each of the two parties:

• A complex number c which is agreed upon between the two parties a priori. this c ∈ C belongs to a Mandelbrot set and to an integer x. These c and x are public, in other words, they can be intercepted by a third party.
• One of the two parties generates a non-public list  a finite ordered list (sequence) of 2 elements n and e (in mathematical words it said that one of the parties generates a non-public 2-tuple (n,e) ), where where n > x, and e belongs to the Mandelbrot set.
• the second of the two parties generates another key consisting of the 2-tuple (k, d) where k > x, and d belongs to a Mandelbrot set.
• Back to the first of the two parties. He now calculates zn by iterating the formula: zi+1 = zic2e with an initial z0=c(1), and does that n times (n iterations), then sends pa = zne to the second of the two parties.
• The second of the two parties calculates zn by iterating the formula zi+1 = zic2e with an initial z0=c(1) and does that k times (k iterations), then sends pb = zkd back to the first of the two parties.
• The first of the two parties then performs a non-public calculation cn−xqne by iterating:
qi+1 = qice with q0=pb(2) for n iterations (i.e. n times).
• The second of the two parties then performs a non-public calculation ck−xqke by iterating: qi+1 = qicd with q0=pa(2) for n iterations (i.e. k times).

I shall define the top-level database object that controls the replication for the object it contains at each datacenter in the cluster as a Keyspace. In other words, the Keyspace is  the outermost grouping of the data in the data store.

A close examination of the above reveals that given a key with length n, the keyspace is larger for the fractal key exchange algorithm than the keyspace for Diffie-Hellman protocol, because the keyspace of Diffie-Hellman is limited to the number of primes in the field Zp where p is the largest prime that can be represented by 2n bits. However, using the fractal key exchange algorithm we can (potentially) end up with any key, which means that the keyspace is exactly 2n.

Julia sets and the Mandelbrot set are similar in the fact that they have actually the same looking iterated function system. However, While the Mandelbrot set is created using variated values on c and an initial value of z0 = 0, a Julia set is created using a fixed c as seed and a variated values on z.

## The Relation Between Dynamical Systems and The Logistic Map to the Mandelbrot Set

It is actually quite easy to note the similarity with the Mandelbrot set iteration formula and the logistic map.

## Coding The Mandelbrot Set in Python

Let’s code…

• find if a complex number diverges under max_steps and if it does then when:
```import matplotlib.pyplot as plt
import numpy as np

def get_iter(c:complex, thresh:int =4, max_steps:int =25) -> int:
# Z_(n) = (Z_(n-1))^2 + c
# Z_(0) = c
z=c
i=1
while i<max_steps and (z*z.conjugate()).real<thresh:
z=z*z +c
i+=1
return i```
• Let’s finish the iterative function script (explanation follows the script):
```def plotter(n, thresh, max_steps=25):
mx = 2.48 / (n-1)
my = 2.26 / (n-1)
mapper = lambda x,y: (mx*x - 2, my*y - 1.13)
img=np.full((n,n), 255)
for x in range(n):
for y in range(n):
it = get_iter(complex(*mapper(x,y)), thresh=thresh, max_steps=max_steps)
img[y][x] = 255 - it
return img```

Line 4: Maps the image coordinate to the real-valued number in the range [-2,0.47] for x and in the range [-1.12,1.12] for y (with a margin of 0.01 on all sides), which will be used to make complex numbers.
Because it is known that the set is bounded with:
The left-most extent of the set ends with the spike at x = -2, and the right side extends out to approximately x = 0.47. The top and bottom are at approximately y = ± 1.12, respectively.

Line 5: Creates a Numpy array of shape N*N, to store the pixel values of Mandelbrot Set.

Line 6–8: We loop through all pixels coordinates, using two loops, and calculate the pixel value for that coordinate (it is really the iteration value).

Line 9–10: put the pixel value in the image. I used “img[y][x]=255-it” because more iterations mean heading toward brack color.
*** Note the rotation by 90 degrees by using: img[y][x]=255-it instead of using img[x][y]=255-it otherwise the image shall be rotated by 2700.

• Now let’s make some Mandelbrot set plots (one may “play” with the rendering):
``````n=1000
img = plotter(n, thresh=4, max_steps=50)
plt.imshow(img, cmap="plasma")
plt.axis("off")
plt.show()

``````