The Beauty and the Mystery of Numbers

ark

Administrator
Administrator
Moderator
FOTCM Member
I decided to start a series of posts about the beauty and the mystery of numbers. This is the first post in this series.

What are complex numbers good for? Well, they are for, for instance, for the production of fractals. How much is investment is needed for starting such a production? Not much. Let me start from complex numbers next time I will move to the Mandelbrot fractal. Later on I will explain what quantum fractals are about.

First complex numbers. To deal with them one only needs to know how to add and how to multiply. Well, some knowledge of fractions will also prove to be useful.

A complex number is nothing else but an expression of the form

x+yj

Here x and y are „ordinary numbers”, real numbers, while j is a symbol. The only thing we need to know is the rule that „j times j is minus one”

j2 = jj = -1

Note: Mathematicians and physicist usual write „i” instead of „j”. In the science electricity „j” is used instead, mainly because "i" is reserved for the electric current. I will keep to the notation „j”.

The usual rule of addition and multiplication hold. Given two complex numbers, for instance

0.5+0.75j

0.3-2j

we can add them:

(0.5+0.75j)+(0.3-2j) = 0.5+0.75j+0.3-2j

collect the coefficients, those without j and those with j:

(0.5+0.3)+(0.75-2)j

and we obtain a new complex number, the sum of the two:

0.8-1.25j

There is no difference between this rule of addition of complex numbers and the usual rule of adding vectors using the parallelogram rule (the same way we add forces), as depicted below:

suma.jpg

Therefore complex numbers are vectors on the plane. The number x+yj is represented as a vector in Cartesian coordinates, with coordinates x,y.

xy.jpg

The same way as a vector, a complex number z can be described by giving its length and the angle between the vector z and the x axis. The length of the vector that represents z is called the modulus (or absolute value) of z. It is usually denoted as |z|. The angle between the vector and the x-axis is called the argument of z, and is usually denoted by arg(z). Sometimes we also use the term „phase of z” instead of „argument of z”. Here is the picture:

rt.jpg

Two complex numbers can be also multiplied one by another to give another complex number – their product. The only rule needed in order to multiply two complex numbers is this one: j times j is -1.

Therefore

(0.5+0.75j)(0.3-2j) =
(0.5)(0.3)+(0.5)(-2)j+(0.75j)(0.3)+(0.75j)(-2j) =
0.15-j+0.225j+1.5 = 1.65-0.775j

One can ask: why such a strange rule? Yet this rule has a simple geometrical interpretation. Multiplying two complex numbers, the lengths multiply while the phases add. Below is the illustration of this fact using the simple example of multiplying j = 0 + 1j by itself

z1z2.jpg

The vector representing j has unit length, therefore jj will also have length 1 (1 times 1 is 1). The vector representing j is at 90 degrees to the x axis, therefore jj will be at 90+90=180 degrees. And this exactly -1 on the x axis. This way we obtain back our starting rule: „j times j is -1.”

Given a complex number z=x+yj, the number x (x-component of the vector) is called the real part of z and denoted by the symbol Re(z) („Re” for „real”), while the number y (y- component of the vector) is called the imaginary part of z and denoted by the symbol Im(z) („Im” for „imaginary”). Yet there is nothing imaginary about it. It is as real as x. Just a tradition.

When we add two complex numbers, their real and imaginary parts add separately:

Re(z1+ z2) = Re(z1) + Re(z2)
Im(z1+ z2) = Im(z1) + Im(z2)

There is no „interaction between them”. With the multiplication it is differently. There is an interaction, and it is this interaction that is responsible for the beauty of complex numbers. Let us make a simple calculation. We will multiply two complex numbers z1 and z2.

z1=x1+y1j, z2 = x2+y2j

z1z2=(x1+y1j)(x2+y2j)=x1x2+x1y2j+x2y1j-x2y2= (x1x2-y1y2)+(x1y2+x2y1)j

We can write it as:

Re(z1z2) = Re(z1)Re(z2) – Im(z1)Im(z2)
Im(z1z2) = Re(z1)Im(z2) + Im(z1)Re(z2)

In particular we can take a complex number z=x+yj and multiply it by itself. What will be the result?

A) Re(z2) = Re(zz) = Re(z)Re(z) – Im(z)Im(z) = Re(z)2 – Im(z)2

B) Im(z2) = Im(zz) = Re(z)Im(z) + Im(z)Re(z) = 2Re(z)Im(z)

These two formulas A), B) will be useful in just a while. We will use them to build a fractal – the Mandelbrot set. But I will dive into it next time. First let us play with the numbers starting with a simple formula. Let us fix a complex number c, say:

c = 0.75 + 0.1j

We shall consider transformations of a complex number z described by the formula:

New z is the old z squared plus c

T(z) = z2+c

Let us start with z = 0. According to our transformation rule:

T(0) = 02+c = c = 0.75 + 0.1j

We can apply our transformation the second time, now to the result of the first transformation:

T(T(0)) = c2+c

and so continuing we will get

T(T(T(0))) = (c2+c)2+c

(T(T(T(0)))) = ((c2+c)2+c)2+c

Calculating even with a piece of paper and a calculator would soon cease to make sense. A computer can do it for us. Let us denote by Tn(0) the result after the n-th application of the transformation T. Let me show on the picture below the point obtained as the result of the first 33 transformations (note: when we apply the same transformation many times, as in for instance above, we use the term „iterations”). Why do I stop at 33 iterations? Because 33 is, for some reason, a mysterious number? Not exactly. You will see it in a while. So, we are iterating T thirty three times. Here is the result:

pi1.jpg

On the picture there is also a circle of radius 2 – I have put it there for a reason. We can see that for 32 iterations our complex number was politely wandering inside the circle. But, evidently, enough was enough, and the next time it escaped from the circle. Using some algebra it can be shown that once our point escapes from the circle of radius 2, it will never return there, independently of the value of our constant c. We will not discuss here these rather technical matters.

So, we got the number 33. Let's see what will happen if we choose this time

c = 0.75 + 0.01j.

How many iterations are needed for Tn(z) to escape the enchanted circle? A simple computer experiment shows that this time 315 iterations are needed. Here is the result. The 315 iteration is outside the circle:

pi2.jpg

It looks like there may be some regularity, some rule.... So let's continue with our experiments. What will happen with c = 0.75 + 0.001j? Well, I checked what will happen and here is the result:

pi3.jpg

This time 3143 iterations were necessary for the point to escape from the circle.

Well, look:

0.1 times 33 = 3.3
0.01 times 315 = 3.15
0.001 times 3143 = 3.143

If you know some programming language ( I am going to discuss it in the next note and my chosen language will be Basis, in fact I will suggest FreeBasic, a freeware available from here, in fact I am going to explain how to use it), you can continue the experiment. I did it and here is what comes out with c = -0.75+0.0000001j – the point escapes with 31415927-th iteration. Notice that:

0.0000001 times 31415927 = 3.1415927

It looks much like an approximation of a well known number. Is it Pi? Did we discover, while playing with numbers, something new? Well, not this time. This phenomenon was discovered by Dave Boll in 1992. It took a while before someone got interested, and then another while before the phenomenon has been understood. (see the pdf link). The author of the linked paper, Aaron Klebanoff is a mathematician and his research was supported by NSF and encouraged by the Navy.

So we see that playing with numbers one can discover new unsuspected regularities.

To be continued.
 
I saw a documentary about fractals a few weeks ago on (i think) the National Geographic Channel. It was very interesting to see how fractals play a part in nature. Fractals are now being used to accurately measuring the coastlines around the globe. Computer programmers are using fractals as a shortcut to drawing computer graphics. I wish I could remember the name of the show because it was fascinating.

Thank you Ark, I look forward to part II.
 
Very cool Ark! I love stuff like this.
I'm still getting over Euler's equation.

Your number: c = 0.75 + 0.1j

Looks pretty interesting in the form:

c = 3/4 + 1/(2X5)j

In other words, the first five natural numbers.
 
ark said:
I decided to start a series of posts about the beauty and the mystery of numbers. This is the first post in this series.

What are complex numbers good for? Well, they are for, for instance, for the production of fractals.

thank you ark for posting it. it has been 2 decades since I did some maths. It is a good refresher. I always find puzzling how to make sense of mathematics as none of the regular education talk about the physical interpretation of the math equations .I took it for the sake of courses and degree treating it as a some form of imaginary field in a mechanically way. No wonder we( general public ) take life also mechanically. Rarely ask the meaning of the life , even when asked , people look at us either as a monk or some strange guy.
 
Today I am going to help those of you who would like to use your PC for playing with numbers, and who did not do it before. As you will see – it is easy.

Long ago the interpreter of the programming language Basic was a part of the Windows operating system. Not so any more. I do not know the reasons for that.

Basic is simple, effective, easily available. Today I will show, on one particular example, how to use it. Next time we will produce our first fractal – the Mandelbrot set.

My first example will consist of calculating the approximate value of Pi by calculating the number of iterations necessary for the complex number to escape the enchanted circle. The necessary preparation is in my first post in this series.

Let us start with the installation of the package FreeBasic and its Editor and interface. I will restrict myself to the Windows operating system. FreeBasic is available also for other operating systems.

We start with downloading the compiler for our operating system using this link. The interface-editor IDE – Integrated Development Environment - will also be handy. For Windows we can download it from this link. - just click on „Download”. After downloading the files we will need to unpack and to install them. By default FreeBasis will install itself in the standard application folder on our PC. I have installed IDE inside the FreeBasicFolder. The icon of fbide.exe will appear on our Desktop. With the first rung fbide will ask us where the compiler fbc.exe is located. We will have to help it by pointing it inside the folder FreeBasic, by default within Program Files.

And here is the lisiting of the program calculating the approximate value of Pi that I wrote. It calculates the number of iterations needed in order to escape the circle and also the approximate value of Pi resulting from multiplication of the imaginary part of c by this number of iterations.


''''''''''''''
Code:
'First we declare the variable numbering the iterations
' Integer means integer number

dim as integer i

' then we declare the variables needed in the program
' double means that we will need double precision - 16 significant digits

dim as double x,y,dum,a

' Then we declare the constants. cr is the real part, ci is the imaginary part
' of the complex number c that appears in our formula. With a different c we 
' will have to change these numbers 

const as double cr=-0.75
const as double ci=0.0000001

' we start with z = x+yj=0, that is x=0 and y=0
' the iterating variable i also starts with 0:

x=0
y=0
i=0

' Now we start the loop. In our dialect of the language the loop starts with 
' Do, and ends with Loop

Do

'we increase by one the iterating index

i = i+1

' dum is an auxiliary variable needed in order to store the real part of the 
' complex number z after the iteration

dum = x*x-y*y+cr

' y is the imaginary part of the number after iteration

y=2*x*y+ci

' Now that we have calculated new y, using the old values of x and y
' we can update the real part x

x=dum

' Let's calculate the square of the amplitude (modulus) of the resulting 
' complex number

a=x*x+y*y

' The next two lines have been changed into comments, as they were slowing down
' the calculations. They can be uncommented for  ci=0.1 and ci=0.01

'print
'print "abs(z)=";sqr(a);", i=";i

' We check now whether our complex number has escaped the circle. If it did, we 
' and we print the number of iterations used, the approximate value of Pi, 
' and break the loop (Exit Do).

if a>4 then
    print "escape for i=";i
    print "approximate value of Pi: ";i*ci
    Exit Do
end if
Loop

' Finally we prevent the quick disappearing of the DOS window right after 
' displaying the result

Sleep

'''''''''''''''''''''''''''
Before each command there is a short explanation. Comment lines within the program should start with '.

In order to check if our installation works, we start IDE by clicking the icon on the Desktop. Then click on File/New and copy the listing between '''''''' and '''''''', and paste into the Editor window. First we need to check if our copy and paste operation is ok. It is important that every comment line starts with ' - otherwise we will have a problem.
Next we click on File/Save and save the file somewhere on the disk. I have saved it within the folder FreeBasic/examples/misc, where there are other examples located. While saving we will need to the file. For example pi.bas. It is important that extension is „.bas”.

No we can check if all works. Click with the mouse on Run/Compile & run (equivalently F9) and, after a while, the DOS window should appear with the result:

escape for i=31415927
approximate value of Pi: 3.1415927

If we want to try another value of the constant c, in the Editor we change ci=0.0000001 to ci=0.1. We save the changed file on the disk: File/Save, then f9 again and we should see, almost instantly, the now only 3 iterations were needed for escape from the radius 2 circle.

Final comment: While I was playing with this program, I have noticed that Dave Boll who first discovered this phenomenon wrote that for c = -0.75+0.0000001j the complex number escapes from the circle with i = 31415928, while I got i = 31415927. The difference is rather insignificant, yet I was curious about the reasons. Where was this difference coming from? My working hypothesis was that it was the result of the difference of the precision in the calculations. I did not know what was the precision used by Boll. So I rewrote the program in Pascal, where I have 20 significant digits precision (FreeBasic, in double precision uses 16 significant digits). The result was the same as with FreeBasic. Therefore I guess that it was Boll who was using lower precision. Remember, Boll was making his experiments more than 15 years ago.

Next time we will use FreeBasic to produce the celebrated Mandelbrot fractal. Then, step by step, while learning about the beauty and the mystery of numbers, we will move towards quantum fractals – as yet under-explored territory.
 
It's a little disconcerting to be using a program named "FBI" to do transformations that were studied via military encouragement. :/ :)
 
Bluelamp said:
It's a little disconcerting to be using a program named "FBI" to do transformations that were studied via military encouragement. :/ :)

I would say: just the converse. Aren't we using computers that were created and devoloped mainly in order to produce the A-bomb" See "ENIAC: The Army-Sponsored Revolution" - "The world's first production electronic digital computer was developed by Army Ordnance to compute World War II ballistic firing tables." So we are simply changing the purpose: from firing bombs to firing Golden Ratios, from ballistic tables to not-so-sacred geometry tables and prime numbers that not only cryptographers are in love with, but also the mystics.
 
Interesting!

I'd like to let you know that with slight changes to the code,
I was able to get this program to run in Gambas2 (full IDE +
LOTS of support for forms, components, etc., etc.) on Fedora
9 (or any linux distros that has Gambas(2) installed for those
of you who use Linux.

Kind Regards!
Dan
 
Hi Ark, I get an error message after running the code in Freebasic.

Line 15 (const as double cr=-0.75)

Error nr 14

Expected identifier, found: 'as'

Any idea? My rusty knowledge of Commodore 64 Basic doesn't help here :huh:
 
salleles said:
Hi Ark, I get an error message after running the code in Freebasic.

Line 15 (const as double cr=-0.75)

Error nr 14

Expected identifier, found: 'as'

Any idea? My rusty knowledge of Commodore 64 Basic doesn't help here :huh:

Will try to experiment a little bit in order to be able to reproduce this error. Once reproduced, solution will follow.


Alright, I tried to reproduce the error, but was not able to reproduce it exactly.
My working hypothesis is that it is some copy/paste error and too long comment lines.
So, here is the clean code stripped of all comments. See if it will work:

Code:
dim as integer i
dim as double x,y,dum,a
const as double cr=-0.75
const as double ci=0.0000001
x=0
y=0
i=0
Do
i = i+1
dum = x*x-y*y+cr
y=2*x*y+ci
x=dum
a=x*x+y*y
if a>4 then
    print "escape for i=";i
    print "approximate value of Pi: ";i*ci
    Exit Do
end if
Loop
Sleep
In the Editor it should look EXACTLY like the above. The same lines.
 
salleles said:
Hi Ark, I get an error message after running the code in Freebasic.

Line 15 (const as double cr=-0.75)

Error nr 14

Expected identifier, found: 'as'

Any idea? My rusty knowledge of Commodore 64 Basic doesn't help here :huh:

Double check that you don't have a typo on the previous executable line (the "dim"). Often the line that the compiler complains about is not the line with the actual error.
 
Tried fbide 0.4.6 and it doesn't like the 'const as double' syntax, so when you find

const as double cr=-0.75
...

write instead:

const cr=-0.75
const ci=0.0000001

and it should run!
 
dantem said:
Tried fbide 0.4.6 and it doesn't like the 'const as double' syntax, so when you find

const as double cr=-0.75
...

write instead:

const cr=-0.75
const ci=0.0000001

and it should run!

That is strange. I have the same version of IDE and it likes it. Perhaps it is the version of the compiler that has changed in the meantime? I mean the last week or so....

No, it is the same version since August 2008. It's a mystery. But indeed "as double" is unnecessary and probably you are correct that removing it will solve the problem.
 
I got the same error first, and changed the lines to the following:

const cr as double = -0.75
const ci as double =0.0000001

and it worked. Then I realized I had only downloaded the IDE package for Windows. I then downloaded the Binaries from the link above, and it worked with the code Ark used. The complier (fbc.exe) that comes with the IDE seems to be of an older version (2005) vs 2008 from the binaries, is probably what causes the error.
 
Thanks for fixing the PDF link, Ark.
Here's the same thing in Matlab:

Code:
function ith = c( a, b, r )

ReZ = 0; ImZ = 0; ith = 0;
magicRsquared = r^2;

while 1
    ith = ith + 1;
    dum = (ReZ*ReZ - ImZ*ImZ) + a;
    ImZ = (2 * ReZ * ImZ) + b;
    ReZ = dum;
    if( ReZ^2 + ImZ^2 > magicRsquared ), break;, end;
end

(Yes I know I skipped Matlab's nice 'complex' variable type)

Called thus:
Code:
 c(-0.75, 0.0000001, 2.0)

I get: 31415927

The thing I can't get my mind around is that the addition
of each digit to 'ci' adds one digit to the pi approximation:

1.0 3
0.1 33
0.01 315
0.001 3143
0.0001 31417
0.00001 314160
0.000001 3141593
0.0000001 31415928 (from PDF)

I tried to check it further, but Matlab seems to lose precision?, and at
Code:
 c(-0.75, 0.00000001, 2.0)
I get 4.7124e+09.

I have had good experiences with Mike Ring's arbitrary precision lib "MAPM"
if anyone is interested:

http://www.tc.umn.edu/~ringx004/mapm-main.html
 
Back
Top Bottom