Squaring complex numbers

As I mentioned in my post about quantum computing, complex numbers are a crucial part of quantum computing programs.  I rushed over their details (and lots of other things) in that post, because I was trying to lay out the headlines of everything that you (and I) would need to know in order to understand quantum computers.

I was watching an excellent video by 3 Blue 1 Brown about Pythagorean triples, that uses complex numbers as a tool, and I realised that I wasn’t as confident about complex numbers as I should be.  So, this article is hopefully for your benefit (as always) but definitely for mine. When you try to explain something to someone else, it helps to expose where you still don’t understand it, and that’s certainly been the case with this!

I realised it’s as if I’m trying to build a tower of mental bricks up to reach the height of quantum computing, except the bricks come flat-packed and I need to assemble them and glue them as I build.  With a tower of solid bricks built up to a particular height, I can add a new brick on top before it’s properly glued together, because I can hold it together with my hands and get a look at what the new version of the tower would look like.  However, before I can add yet another brick on top I need to make this one solid, otherwise I run out of mental hands and things fall apart.  So this article is an attempt to consolidate complex numbers, before I progress to the later bricks.

First, I’ll give a brief recap on what complex numbers are, how you can do addition with them, and then move onto multiplication.  The multiplication bit will touch on the concepts of helpful and unhelpful mental models, and will concentrate on squaring complex numbers as a special case of multiplication.

This will probably be a pale imitation of 3 Blue 1 Brown or How to Fold a Julia Fractal, so for the real stuff I suggest you go there.

What is a complex number?

The short but possibly not terribly clear answer is: A complex number is a number that has a real part and an imaginary part.  The real part is a number that you’re used to.  It’s something like 4, -12, 0, 8.222224, etc.  The imaginary part is some multiple of i, where i is defined as the square root of -1.  This might seem bonkers and arbitrary, but for the price of only one fairly small bit of bonkers and arbitrary, you get quite a lot of interesting, useful and self-consistent maths.

The problem with imaginary numbers is that they don’t fit anywhere on the familiar number line.

The real number line, showing -12, 0, 4 and 8.222224

i is nowhere on this line.  This bit needs you to stretch your brain a bit, but imaginary numbers get their own number line:

The imaginary number line, showing -12i, 0i, 4, and 8.22224i

You can think of the familiar number line as showing how many lots of 1 each number is.  I.e. 4 is 4 lots of 1.  -28 is -28 lots of 1 etc.  The imaginary number line is equivalent, but says how many lots of i each number is: 4i is 4 lots of i etc.

The two number lines together describe the complex plane.  Each point on this plane is a complex number – a combination of a real part and an imaginary part.  If the imaginary part is 0 then the point is on the real number line, i.e. you are back to having a real number.  If the real part is 0 then the point is on the imaginary number line, i.e. you have an imaginary number.  The bulk of the points are off the two number lines, and so are complex – something like 3 + 4i, –4 + 1i, 5 –3i etc.

The points (3,4), (-4,1), (5,-3) on the complex plane

How do you add complex numbers?

This is straightforward – if you are adding these two complex numbers:

  • 3 + 5i
  • 7 + 11i

The answer is 10 + 16i.  The real parts (3 and 7) are added together to give the real part of the answer (10) and the imaginary parts (5i and 11i) are added together to give the imaginary part of the answer (16i).

More formally, if you add the number a + bi to the number c + di:

(a + bi) + (c + di) = (a+c) + (b+d)i

How do you multiply complex numbers?

I’ll go straight to the formal version this time.  If you’re familiar with secondary school algebra, this should be what you might expect from that:

(a + bi) * (c + di) = ac + bci +adi + (bi * di)

                              = ac + (bc + ad)i + (b * d * i *i)

                              = ac + (bc + ad)i + (bd * -1)

                              = ac – bd + (bc + ad)i

If we go for the special case of squaring a number:

(a + bi) * (a + bi) = a2 + abi + abi -b2

                              = a2 – b2 + 2abi

I’ll try that out with some sample values.  First will be values on the 4 different parts of the axes (positive and negative bits of both)

NumberSquared Number
RealImaginary     RealImaginary
3090
03-90
-3090
0-3-90

That’s a bit weird.  No matter which part is 0 in the number before you square it, when you square it the imaginary part is 0 and the real part is non-0.  The size of the real part makes sense, as 32 is 9, but the sign doesn’t have an obvious relationship to anything.

Maybe numbers on the axes are an unhelpful special case, and things will get clearer if we use numbers away from the axes.  So I’ll pick numbers on the diagonals, where the real and imaginary parts are the same size (but possibly different sign).

NumberSquared Number
RealImaginary     RealImaginary
55050
-5-5050
-550-50
5-50-50

That’s also weird, in a way that looks different from the previous kind of weird.  Now all the real parts of the result are 0, even though no part of the number was 0 to start with.

These numbers are correct, because I’ve used the correct rule in the correct way.  However, I don’t have a good feel for why they are correct.  If I had a quick glimpse at the tables, would I get an initial “hmmm… looks a bit wrong” reaction, which would prompt me to take the time to check the details?

In User Experience (UX) terms, I don’t have a good mental model that helps me understand what’s going on.  The mental model should help me to predict the outcome of my actions, at least roughly.  I have a detailed rule that I can follow blindly, but I don’t have understanding around it.  In the next section I’ll introduce a different approach that will produce the same results but also a better mental model (after a bit of effort).

Polar co-ordinates

I described complex numbers as lying on the complex plane, and being described as a real part plus an imaginary part.  This works well for addition, where you just add up the real parts and imaginary parts separately to get the answer.  It doesn’t work so well for multiplication, as we’ve just seen.

This way of describing a number’s location in the complex plane is called Cartesian co-ordinates.  If I translate this to the world of my back garden, I could describe where something is on my patio by counting how many paving slabs along it is, and how many paving slabs up it is.  There’s an alternative to Cartesian co-ordinates, that I’ll describe in terms of my back garden again, but also with the aid of my dog.

Imagine I’m stood in the middle of my garden, I have my dog on a retractable lead which is set to freely extend or retract, and I’m looking at the back fence.  My dog starts off by feet and then wanders off to smell something somewhere in the garden.  I want to keep an eye on what she’s up to, so I turn around to keep looking at her.  When she stops to smell, I will have turned by so much of a full turn, and the lead will be at a particular length.  If I measure my turn as if I have always turned the same way (clockwise or anti-clockwise), I can describe any point in the garden uniquely by how much I’ve turned and how long the lead is.  These are polar co-ordinates.

My dog, curled up asleep in her bed
It’s tiring work being the star of an analogy for polar co-ordinates

Translating back to the complex plane, we imagine that we’re stood at the origin where the axes cross, looking to the right along the positive x (or real) axis.  We always turn to the left, i.e. anti-clockwise, towards whichever number we want to locate, and when we’re looking at it we say how far away from the origin it is.

You still need two numbers to uniquely locate somewhere on the complex plane, but in polar co-ordinates it’s an angle and a distance, rather than the two distances used by Cartesian co-ordinates.

It’s important to remember that switching between polar and Cartesian co-ordinates doesn’t change where a point is on the complex plane, i.e. doesn’t make it bigger or smaller in any way. It’s just the same as the way the next town from where you live doesn’t get closer or further away if you switch the distance to it between miles and kilometres. It’s the same distance, just measured or described in a different way. You can use whatever approach you like, as long as you’re careful to be consistent. So, you can’t add distances when one is in miles and the other in kilometres, and you can’t multiply two complex numbers together when one’s in polar co-ordinates and the other in Cartesian.

Multiplying numbers via polar co-ordinates

There is a rule for multiplying numbers defined by polar co-ordinates, just as there’s a rule for multiplying numbers defined by Cartesian co-ordinates.

If you are multiplying the number (a, r) – where a is the angle and r is the radius or distance from the origin – and the number (b, s) then:

(a, r) * (b, s) = (a + b, r * s)

You add the angles and multiply the distances.  That means, if you’re squaring the number (a, r) you get:

(a, r)2 = (2a, r2)

You double the angle and square the distance.

Squaring example complex numbers in polar co-ordinates

I’ll go through the two sets of example numbers as before, but expressed as polar co-ordinates rather than Cartesian.  All angles will be measured in degrees.

CartesianEquivalent polarPolar squared
RealImaginary     AngleRadius     AngleRadius
300309
039031809
-3018033609
0-327035409

The angle in the squared number is where the magic happens, that explains the weirdness we’ve already seen.

Because there are 360 degrees in a circle, turning through 360 will leave us where we started.  540 degrees is a full turn and then a further half turn.  In terms of where we end up, there’s no difference between this and doing just a half turn.  If you think about an analogue clock, the hour hand is continually turning more and more.  However, every hour it has looped around, and it seems to be back where it started.  So, any angle greater than 360 can be simplified by taking off 360 as many times as we can to leave something 0 or bigger.  (This is also known as the original number modulo 360.)

If we take off full turns in this way, the results are as follows:

CartesianEquivalent polarPolar squared
RealImaginary     AngleRadius     AngleRadius
300309
039031809
-30180309
0-327031809

If we translate the result back to Cartesian, (0, 9) is the number 9 + 0i and (180, 9) is the number -9 + 0i.  This is what we got in the Cartesian multiplication table.

I’ll now do the other set of examples, and carry on to remove any full turns too. The radius of the unsquared polar number is calculated via Pythagoras’ theorem, hence the slightly unusual number.

CartesianEquivalent polarPolar squaredPolar squared without full turns
RealImaginary     AngleRadius     AngleRadius     AngleRadius
5545√5090509050
-55135√502705027050
-5-5225√50450509050
5-5315√506305027050

The polar co-ordinate (90, 50) is the number 0 + 50i, and (270, 50) is 0 -50i.  These fit with the Cartesian multiplication table.

Squaring a goal

So far, I’ve looked at individual points on the complex plane, showing how they move when the number they correspond to is squared.  While this is useful (and weird) I think it’s worth moving on to seeing what happens to a shape made up of lines on the complex plane.  For reasons I’ll go into later, I’m going to limit it to just the top half of the complex plane, i.e. a non-negative imaginary part (and any kind of real part).

The shape I’ll use is like a goal in football.  At the risk of stating the bleeding obvious, it’s three straight lines that meet at right angles.  Or, in terms of the underlying numbers, it’s a line of a constant imaginary part (the crossbar) that goes between two lines of constant real part (the uprights).  I’ve got two copies of this, to show how relative sizes change.

Two goal mouths inside each other
The shapes before numbers are squared
Two concentric ovals
The shapes after numbers are squared

Several interesting things are happening.  The big picture is that it isn’t a simple rotation about the origin.  It’s a smearing out as things rotate.  What starts in the top right quadrant is spread out over the two top quadrants.  What starts in the top left quadrant is spread out over the bottom two quadrants.  This makes sense – the top right quadrant corresponds to points whose angle is in the range 0-90°.  After squaring this is doubled, resulting in the range 0-180°.  Similarly, the top left quadrant corresponds to points whose angle is in the range 90-180°.  After squaring, this turns into the range 180-360°.

If you look at the right-hand upright, you can see it is bent round to the left. Before squaring, the angle between the top of the upright and the positive part of the real axis is 45° (the corner is as far to the right of the origin as it is above the origin). After squaring this will double to 90°, meaning that the right-hand upright is stretched around to fill the top-right quadrant and ends up against the positive imaginary axis. At the other end of the upright, the bottom starts at 0° and stays at 0° because 2 * 0 = 0. The higher we go up the upright, the bigger the angle, and so the bigger the deflection from vertical.

Before squaring, the crossbar spans the range between 45° and 135° (45° up from the negative part of the real axis). Squaring doubles these, so it stretches from 90° to 270° – the positive imaginary axis round to the negative imaginary axis.

Squaring a square

This is where we can test our mental model.  So far, I have conveniently been using shapes that are in only the top two quadrants before the corresponding numbers are squared.  What would happen if the shape we started with had a part below the horizontal axis?  For instance, what if it were a square, formed by reflecting the goal in the horizontal axis?

Two concentric squared
The shapes before numbers are squared – the reason for the weird colours and extra thick lines in the bottom half of the diagram will become clearer soon

This is an occasion to make some predictions without worrying about the consequences of those predictions (so we can predict freely), and then only analyse things once we have the predictions.  If this were a video, I would invite you to pause the video and have a think…

It might have been that in the previous section (squaring a goal) you imagined the plane as being made of something stretchy like rubber, and squaring things meant that the plane was stretched around the origin so that the goal was pulled all the way around in a circle (while all the distances out from the origin were squared).

This is a valid approach, but for this example you need to extend it.  You need to imagine that the complex plane is slit along the positive horizontal / real / x axis.  In squaring, you grab the top bit of the bottom right quadrant (the bit just below the positive horizontal axis) and rotate it behind the complex plane above the positive horizontal axis.  This turns the complex plane into a corkscrew that goes through two full revolutions.  You also have to imagine that the rubber that the plane is made from is also see-through.  When you look at it from the front, you see both layers of the corkscrew.

Copied from How to Fold a Julia Fractal, which inspired this article

I realise that this is quite a mental journey in one article.  At the start there was just the (real) number line from primary school.  Then complex numbers came along and the real number line turned into the complex number plane.  Now we’re slitting and stretching this plane and turning it into a 3d object.  You don’t need to worry about distances in this third dimension (into and out of the screen), just that the third dimension’s a way of having bits of stretched-out and twisted complex number plane at what appear to be the same angle e.g. 45°. Also you don’t need to worry whether you stretch the plane into the bit behind where it started, or the bit in front of where it started – it’s just a way to have more than one version of the plane.

So, what would the squared square look like?  Because the unsquared square is rotationally symmetric (we can rotate the bottom half around the origin to exactly match up with the top half), and we are doubling angles in the squaring process, the squared version of the bottom will exactly match up with the squared version of the top.

The thicker lines are behind the thinner lines, but they are exactly on top of each other

Summary

Complex numbers can be useful, but they can also be weird, particularly when you multiply them.  Multiplying them causes a sloshing between the real and imaginary parts.  The product of the two imaginary components modifies the real part, and the two real parts modify the imaginary part.

This sloshing between two parts is similar to what happens when a point travels around the circumference of a circle – the equation is x2 + y2 = r2 (where r is the circle’s radius).  As x gets bigger, y gets smaller and vice versa.  So maybe it shouldn’t be a surprise that multiplying complex numbers involves rotation.

If you can make your brain accommodate the new, bigger, weirder, richer world that complex numbers usher in, all sorts of useful things become easier or even possible.  One of these is quantum computing.

UPDATE 18th OCTOBER: Apparently my cat and my other dog are feeling jealous, so here are gratuitous photos of them.

My other dog
A dog that definitely hasn’t helped herself to some flour
My cat
No, there was never any cheese here. None at all.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s