Tuesday 23 February 2016

The maths of qubits


This is part of a project to get people involved with quantum error correction. See here for more info.

If you are reading this, you've probably seen the word 'quantum' before. Probably in a popular science article that called it 'weird', and didn't tell you much else. Or maybe you heard it in Sci-Fi, where scientists treat equations like incantations that just need to be put it in a computer for magic to happen.

In this blog, which is usually about quantum error correction, I have been guilty of this exact same thing. But descriptions like this have serious drawbacks. They make everything seem intangible, beyond the understanding of mere mortals and only to be dealt with by great sages. This is not true at all. I work on quantum stuff, and I'm a bit of an idiot. So now it's time to tell you the truth about quantum!

To do this, we are going to need some maths. But don't be scared! Maths isn't always scary. Puzzles are maths, and they are fun (check out our own quantum game, for example).

I'm not saying that the maths in this post will be fun, but I'll keep it as simple and painless as I can. I'll only use the kind of maths that people learn at school, and I'll bear in mind that you've probably forgotten it all (and probably never understood it in the first place).

The basic maths of quantum mechanics isn’t all that hard. In fact, it can be a lot easier than what we have to deal with in the non-quantum world sometimes. If you have already been taught about vectors and complex numbers, you should probably find it quite straightforward. But for those who don't know about such things, this blog will try to give you some idea of the maths behind qubits.

States and measurements

First, let’s talk about states. We use the word ‘state’ to describe what a bit, or qubit or whatever is doing. Bits are pretty simple because they only have two possible states: 0 and 1. At any time it is either in state 0 or state 1. It cannot be both and it cannot be neither. A qubit is also built around these two basic states. But it can also be one of an infinite number of superposition states, where it is some degree of 0 and some degree of 1 at the same time.

When you measure a bit, you ask it whether it is in state 0 or state 1. You can also ask the same question of qubits. If its state is not 0 or 1, but is instead in a superposition of them, the qubit will randomly choose which one to be. If the superposition is more biased towards 0, you'll most likely get 0 and vice-versa.

It would be nice to get more information out of a qubit. It would be nice to find out exactly which of the infinite number of superposition states it is in. Unfortunately, there is no way to do this. We are limited to simply asking whether it is in one state (like 0) or a completely different state (like 1), and putting up with randomness in the result when it is neither.

Though the two basic states for a qubit are called 0 and 1, these are just labels we have chosen. They could equally be called ‘Yes’ and ‘No’, or ‘Grey’ and ‘Pineapple’, or ‘£’ and ‘%’. They are not really the actual numbers ‘0’ and ‘1’, that we can add and multiply. So it can be confusing when we start putting them into equations. To avoid this confusion, we usually write them down in a slightly strange way. For a qubit in state 0 we write |0>. For one in state 1 we write |1>. Here the | and > aren’t going to actual do anything in any equations. They are just to remind us that the 0 and 1 are names for quantum states and not actual numbers.

This notation has scared many an undergraduate physics student, so let’s avoid it here. Instead let’s use different labels for the qubit states. For the qubit state usually known as 0, let’s instead call it up. For the state usually known as 1, let’s call it down. Now that the names we are using for qubit states no longer look like numbers, we can avoid the weirdness of | and >.

Making up some maths

Now let’s try to describe quantum states with maths. One thing you need to know about maths is that it’s perfectly fine to make the rules up as you go along. This might come as a surprise to you, since you’ve probably been taught it as a set of rigid rules and methods that must be obeyed. But these are just sets of rules that turned out to be useful for something. For quantum mechanics we’ll need some new maths*, so let’s start making it up.

Firstly, it would be useful to have some way of quantifying how similar two states are. We'll call this the overlap. The states up and down are completely different, so these should have an overlap of 0. For states that are 100% the same, let's say that the overlap is 1.

Now we have a new mathematical thing to calculate. We just have to make up the mathematical rules that we can use to calculate it.

For the two states up and down, there are only four possible overlaps to calculate and we know what they should be already.

overlap of up and up = 1
overlap of up and down = 0
overlap of down and up = 0
overlap of down and down = 1

Now we need to work out overlaps for superposition states. There are many different possible superpositions of up and down, which differ by how biased they are towards one or the other. This means we need two numbers, let's call them the upness and downness, that describe how much up and down there is in a superposition

It would also be nice to have a shortened name for the superposition state that we are trying to describe. Let's just call it S. Now we need to write down the fact that S is a superposition of up and down and also what its upness and downness are, in a way that looks mathsy. How about

S = (upness of S) × up + (downness of S) × down

This nicely puts all the required information on one line. It even has has an + and some ×'s in to make it look like maths. These look suspiciously like addition and multiplication. But what does it even mean to multiply a state by a number? Or to add two states? These aren't the addition and multiplication that we are used to. I've written them in bold to help us remember that. It will turn out that they will follow similar rules to the normal ones, though. So that's why we use these symbols.

Now, what is the overlap between our superposition state S and the state up? We still haven't made up enough rules to actually calculate this, so we have to choose something. We just introduced the notion of upness, which is how much up there is in S. This seems to be pretty much the same thing as the overlap between S and up, and it wouldn't contradict any of the rules we have already if they were the same thing. So let's just make up the rule that says they are the same thing.

overlap of S and up = upness of S

There's a more complicated way we can write this, that can help us understand a little more about what is going on.

overlap of S and up = (upness of S× (overlap of up and up)
                                         + (downness of S× (overlap of down and up)

Here the overlap of S and up is a sum of two things. The first is the contribution from the up part of S

(upness of S× (overlap of up and up) = (upness of S× 1 = upness of S

This tells us that the up part of S contributes the upness (obviously), and it contributes it fully because the overlap between the up part of S and up is 1.

The second contribution is from the down part of S

(downness of S× (overlap of down and up) = (downness of S× 0 = 0

This tells us that the down part of S would contribute the downness if it contributed anything. But it doesn't actually contribute it because the overlap between the down part of S and up is 0.

We get a similar equation for the overlap of S and down.

overlap of S and down = (upness of S× (overlap of up and down)
                                         + (downness of S× (overlap of down and down)

This time the overlaps of up and down ensure that the downess contributes fully, and the upness doesn't contribute at all.

What about the overlap with something else? If we look at the overlap between S and down, and the overlap for S and up, the only difference is that one has up in and the other has down. So maybe we can just replace that with anything else too. Let's invent a new state and call it T, for no other reason but it coming after S in the alphabet. The overlap of S and T is then

overlap of S and T = (upness of S× (overlap of up and T)
                                         + (downness of S× (overlap of down and T)

In these equations we have × and +, multiplying and adding normal numbers. These are indeed the multiplication and addition that we are used to. From these equations you can maybe see why I used × and + before. Compare the equation for S with the equation for its overlap with T

S = (upness of S) x up + (downness of S) x down


overlap of S and T = (upness of S× (overlap of up and T)
                                         + (downness of S× (overlap of down and T)

These are pretty much the same. The only difference is that each state in the first one has been replaced by the overlap of that state and T in the second. This means that the second one just has normal numbers in. So the weird multiplication and addition in the first one become normal in the second. So, whatever x and + are, they must be some version of multiplication and addition that work with the states of qubits, and just become normal multiplication and addition once we just start calculating with numbers. We won't need to think much more about this, though.

Let's think more about the overlap between S and our new state T. Firstly, just like S we should be able to write T as

T = (upness of T× up + (downness of T× down

Earlier we made a rule that the upness of a state is the same thing as its overlap with up. This rule lets us write the equation for the overlap of S and T in a simpler way.

overlap of S and T = (upness of S× (upness of T) + (downness of S× (downness of T)

This lets us work out the overlap of S and T using their upness and downess, which are just numbers that we know.

Now let's ask a question for which we already know the answer. What is the overlap between S and itself? Using the maths above

overlap of S and S = (upness of S× (upness of S) + (downness of S× (downness of S)
= (upness of S)2 + (downness of S)2

Since we are looking at the overlap between two states that are exactly the same, the answer should come out to be 1. So now we know something about the relationship between the upness and downness for any quantum superposition

upness2 + downness2 = 1

This makes a lot of sense. The more a state is biased towards up, the less it must be biased towards down. For example, a state with an upness of 1 (and so with an upness2 of 1 too) is completely up, and so has no downness. The first concrete fact that our quantum maths has told us isn't weird at all. See, quantum mechanics isn't so strange.

Well, maybe it is a little bit strange. Note that we don't just add upness and downness here. Instead we square them first. One thing we know from school is that negative numbers square to the same value as positive ones. (-1)2 = 1 just like 12 = 1, for example. So maybe this equation is telling us that its okay for the upness and downness to be negative, even though this would be a bit weird, because these numbers only need to be sensible after we've squared them. Let's keep this possibility in mind.

Left and Right

Now we've made up a nice bunch of maths, let's do something with it. Let's consider a specific superposition state, that has the same upness as downness. We can give it a name that also lies between up and down. Let's call it right.

We know that the upness and downness of right are the same, and we know that sum of their squares must be 1. With this we can get a specific number for the upness and downness: They will both be √½. Now we can write down right in our mathsy way

right = √½ × up + √½ × down,

Since we have called this right, it would be nice to know if there is a left to go with it. Is there as state that is as different from right as up is from down? If there is, we must also be able to write it down in our mathsy way

left = (upness of left× up + (downness of left× down

The overlap of left and right will then be, using the equation from before for S and T,

overlap of left and right = (upness of left× (upness of right)
                                               + (downness of left× (downness of right)
                                                    = (upness of left× √½ + (downness of left× √½

If left and right are to be as different as up and down, their overlap needs to be zero. This will happen only if

(downness of left) = - (upness of left)

because then we get

overlap of left and right = (upness of left× √½ - (upness of left× √½ = 0

So one possible choice for left is

left = √½ x up + (-√½) x down

This has an upness of √½, just as right does, but it has a downness of -√½. This is a negative downness, just like the equation earlier hinted might be possible. What does this mean? Does it make any sense? Well it is rather strange. But the equation earlier also told us to only expect the squares of numbers to be completely sensible, and (-√½)2 does give us a nice sensible ½. So let's not worry too much yet.

So far we've been thinking about everything as a superposition of up and down. But now we have left and right, which are two states just as different as up and down. What does a superposition of these look like? Something like

S = (leftness of S× left + (rightness of S× right

As an example, let's start with a state that has the same leftness as rightness. So

S = √½ × left ½ × right

The overlap of this state and left is obviously √½, and the overlap for right is √½ too. What is the overlap for our trusty old friends up and down? Using the same sort of method as before, and calculating the overlaps of both left and right with up, we find

overlap of S and up √½ × (overlap of left and up) √½ × (overlap of right and up)
                    = √½ × √½ + √½ × √½ = ½ + ½ = 1                                

So the upness of this state is 1! Let's check the downness.

overlap of S and down √½ × (overlap of left and down) √½ × (overlap of right and down)
                   √½ × √½ + √½ × (-√½) = ½ - ½ = 0                                 

It has a downness of 0! We already know a state with an upness of 1 and a downess of 0. It's up! This superposition of left and right turns out to be our good old friend up.

up √½ × left √½ × right

We can similarly find a superposition for down, but let's do this differently (for fun!). Let's trust that the weird × and + that we use on states really do have properties like multiplication and addition. Now let's look at the superposition

T = (-√½) × left √½ × right

Since we have equations for left and right as superpositions of up and down, let's stick these in.

T = (-√½) × (√½ × up + (-√½) × down) √½ × (√½ × up + √½ × down)

Doing a bunch of the maths from algebra lessons at school (see, it did come in useful), we can make this into

T = (-√½× (√½) × up + (-√½) × (-√½) × down √½ × √½ × up + √½ × √½ × down
= -½ × up + ½ × down ½ × up + ½ × down                                                    
= (½ – ½) × up + (½ + ½) × down                                                                      
= down                                                                                                               

The up part disappears and the down part gets strengthened. This is exactly the sort of thing that we call an interference effect, and which causes the strange quantumness in the double slit experiment.


All states are created equal

With left and right we have another pair of states that are completely different from each other, just as different as up and down. We saw that left and right are both superpositions of up and down, but up and down can also be thought of superpositions of left and right.

This shows us an important fact about the states of quantum things, like qubits. There are no states that can claim to be the 'proper' states, with everything else just being their superpositions. Any state is as important as any other. Any state can be thought of as a superposition of other states.

This fact often gets obscured when we are talking about quantum computation. We like to think of this as a quantum version of a normal computer, so the stories we tell ourselves have to be full of 0's and 1's. But the qubit states we choose to call 0 and 1 are not really any more special than any other.

This fact also gets obscured by the intuition we get from the real world. For a cat in a box, as in Schrödingers famous thought experiment, the states 'alive' and 'dead' do seem more sensible than all the possible superposition states. This is just because big and complicated objects, like cats, are constantly interacting with other big and complicated things. These interactions, like getting looked at or and having light and the air bashing into you all the time, tend to be easier to describe using some states rather than others. When and how things bash into into you, for example, depends on where you are. So the interaction is much easier to describe using states for which you have a definite position than ones for which you are a superposition of being in different places. But for tiny things like electrons, which haven't had all the quantumness bashed out of them, superpositions of different positions are perfectly fine. And that's what we see in the double slit experiment.

Since left and right are just as important as up and down, it means we can also use them for measurements. When ask a qubit what state its in, we can ask it whether it is up or down, and a qubit in state left will have to randomly decide one or the other. But we could also ask it whether it is left or right, and an up qubit would need to randomly decide. In fact we can do an infinite number of possible measurements, where we ask if it is some state S or another state S'. The only restriction is that S and S' must always be completely different from each other: they must have an overlap of 0.

What did we just calculate?

The maths we just did involved a bunch of numbers, like overlaps and the upness and downess. But what do these numbers actually mean? Do they correspond to something that we can measure in an actual experiment, to check that our maths is actually describing qubits correctly? Fortunately, the answer is yes. And experiments have conclusively shown that we are indeed doing it right.

Basically, if we have a qubit in a state that can be written

S = (upness of S× up (downness of S× down

and we measure whether it is up or down, it will randomly choose to be one or the other. The probability that it chooses up is (upness of S)2. The probability of down is (downess of S)2. This shows us why upness2 + downness2 = 1, as we discovered earlier. We must always get one of the two possible options, up or down. Since it is certain to get one or the other, the probability for this must be 1.

All other overlaps are similarly probabilities. If we have some state S and some other state T, the number
(overlap of S and T)2 

is the probability that you will get the result S if you are asking a qubit in state T if it is S or S'. It is also the probability that you will get the result T if you are asking a qubit in state S if it is T or T'. Here S' is the state that has no overlap with S, and T' is the state with no overlap with T

With this extra information we can start to wonder what it means when an overlap becomes negative. For example, say we have the state
(-1) × up

This has an upness of (-1). The condition upness2 + downness2 = 1 means that its downness must be zero, which is why it has no downness.

How does this new state differ from up? If we measure whether it is up or down, the probability of up is (-1)= 1. So it will definitely come out to be up. If we measure anything else we will also get the same probabilities as if it were just up. The fact that its upness is (-1) rather than 1 has no effect on what we actually see in the real world. So what does a negative upness mean? Not much, it seems. The difference between any state S and the corresponding state (-1) × S is not something we can ever measure. So they are basically the same thing. Only when the difference between positive and negative happens in a superposition, as we saw for left and right, does it matter at all.
As we said before, it is the squares of the overlap that seem to have the job of being sensible. So the best way of measuring how similar two states are is to use the overlap squared, rather than the overlap itself. The overlap squared will give a value of 1 if the states are the same, 0 if they are different and something in between for something in between. It won't ever give a negative value. But the overlap itself retains the freedom be a bit crazy. It can be negative, at that lets it have some quantum fun.

What can we do now?

We now have enough maths to actually show how quantum systems can do things that would otherwise be impossible. But this post has already run on much longer than my usual 1000-1500 word limit. We probably all need to go and lie down for a week. So come back some other times and we'll look at entanglement, and how Bell's inequalities show us that it can do things more awesome than even Einstein could easily believe.


* The maths we need is called linear algebra. It’s not unique to quantum mechanics. You can use it for loads of stuff in your normal everyday life too.