Squaring a complex number

More on complex arithmetics for the curious

Although there is enough other information elsewhere on this site to write a Mandelbrot program, you may still be curious about the background, or more specifically the strange formula for multiplying to complex numbers.

Here it is: A complex number is really written as a + bi.

bi is called the "imaginary component", and its origin is in the very reason for using complex numbers, namely in making it possible to calculate the square root of a negative number.

In non-complex mathematics, the square root of a negative number is undefined. The only thing complex arithmetic adds is the symbol i representing the square root of -1, and this enables us to represent the square root of any negative number.

The calculation rules are simple. The only thing worth mentioning is that

i2 = -1

Now, to multiply two parenthesized sums (a1 + b1) (a2 + b2), you just multiply and add together the four possible combinations of elements:

(a1 + b1)(a2 + b2) = a1a2 + a1b2 + b1a2 + b1b2

If we do this to two complex numbers (a1 + b1i) and (a2 + b2i), we end up with

a1a2 + a1b2i+ b1a2i + b1b2i2

But i2 is of course -1, so we can simplify this:

a1a2 - b1b2 + (a1b2 + a2b1)i

If we do this to the z2 calculation we used in the Mandelbrot formula above, writing z as (x,y), we just substitute "x" for "a1" and "a2", and "y" for "b1" and "b2" to yield

x2 - y2 + 2xyi

or, written as a complex number

(x2 - y2, 2xy)

which is equvalent to the formula used in the Mandelbrot code.