This post assumes that you have knowledge of linear algebra, such as matrix and vector multiplications, eigenvectors and eigenvalues, etc. More advanced concepts like the Kronecker product will be explained briefly, but I won't go into too much detail about them. Knowledge of complex numbers and operations is also assumed.
Quantum computing is this hot new topic that's been around tech news in the last few years. There's claims flying around about how it's orders of magnitude faster than classical computers, and that it's going to break all of our encryption and cybersecurity. To be fair, a lot of that is true, to a certain extent. Quantum computers are much, much faster than classical computers at certain tasks, and there are in fact quantum algorithms that can break some older encryption schemes in a reasonable amount of time.
That said, quantum computing isn't a 1:1 replacement for classical computing; the way that quantum computers work is both very different and, at least to me, very fascinating. It's also not nearly as complicated as its often made to sound.
The humble (qu)bit
Classical computers work on binary digits (a.k.a. bits), i.e. 0s and 1s. You've probably heard this a million times, but there's a key observation here that you might not have considered before. 0 and 1 are discrete values; if a bit isn't 0 it must be 1 and vice versa. We can call these the bit's "states": it can be in a state of 0 or a state of 1.
Qubits, on the other hand, aren't as straightforward. Bits are represented in hardware by low and high electrical signals, and qubits are represented by a two-level quantum mechanical system, like electron spin ("up" or "down"), or photon polarisation ("left-handed" or "right-handed"). However, due to the way that quantum mechanics works, these properties aren't inherently discrete.
An quantum mechanical system can exist in what's called a superposition, which is a separate, mixed state of its two discrete options. You'll often hear that it's "in both states at the same time" until you measure it, at which point the state collapses into one of its discrete options. But that's not fully accurate.
The way I understood it best is flipping a coin. While the coin is in the air flipping, it's not "heads" or "tails", it's in a third mixed state called "flipping". When the coin lands and you check it, its "flipping" state collapses into "heads" or "tails" with, assuming a fair coin, equal probability.
This isn't possible to model with a single bit, as a bit can only ever be 0 or 1, it can't ever be in that "flipping" state. However, a qubit can be, and we can write it as:
is read as "ket 0", and it represents the part of the qubit's vector pointing in the $0$ direction. The counterpart to a "ket" is a "bra", written as . Together they make "bra-ket" notation, also known as Dirac notation. It's important to remember, the "0" and "1" here are just labels, they aren't real values. We could have just as well named them and and all of the math would work out exactly the same.
Defining a bra is a bit complicated, but you can imagine it as the counterpart to a ket. The mathematical application of it is that, when you apply a bra to a ket, if the labels inside both are the same, then they cancel out to 1, otherwise they cancel out to 0:
Here, is just a shorthand for , and you're effectively taking a dot product. We'll see this in closer detail when we look at vector notation.
Here, and are the qubit's basis states. The definition of an eigenbasis is a bit complicated, but an easy way to imagine this is that a qubit exists on a unit circle, and these are the graph's and axes. The coefficients of the basis states then represent the actual and coordinates on that graph:
The actual thing we're talking about here is called "orthonormality". This consists of two properties: orthogonality and normality. For an orthonormal eigenbasis:
- Orthogonality: The basis vectors must be orthogonal, or at 90º to each other. This is what I meant when I said they were the and axes of a graph. The way this is actually defined is that their inner product . This holds true for and since .
- Normality: The basis vectors must be normal. A vector is considered "normal" if its inner product with itself . This must be true for any vector in the space, so any combination of the basis vectors. This is what I meant when I said that a qubit exists on the unit circle.
So if two vectors and meet the condition:
then they are said to be orthonormal. While there are non-orthonormal eigenbases, we'll only be talking about orthonormal bases in this post.
In reality, the coefficients of the and are complex numbers, so even drawing a single qubit would actually require a 4-dimensional graph. I don't know how to make 4D graphs, so I'm just going to stick with this simplified example for now. Besides, it's not very useful to work with qubits on graphs since, as you can see, you run out of dimensions pretty quickly.
However, this graphical representation shows that qubits can be written as vectors using their coefficients:
Now that we have our vector definitions for , we can better define . If is a vertical vector, then is a horizontal vector, such that:
We could derive the same result by doing the multiplication algebraically:
I'm going to use both Dirac notation and vector notation interchangeably throughout this post since it's sometimes easier to do calculations with one or the other, so it's worth getting familiar with translating between both.
Measuring a qubit
When we measure a qubit, we're collapsing it down from its superposition state down to one of its basis states. To do that, we're going to use the coefficient of each basis state, also known as the amplitude. The square of the amplitude represents the probability that, when measured, the qubit will collapse into that state:
So for the case, we can say that represents "heads" and represents tails. The probability of each would be:
thus representing our fair coin's 50/50 chance of heads or tails.
This brings with it another key observation: the sum of the squares of the amplitudes must equal 1. If we have a qubit , then the probability of measuring $0$ is and the probability of measuring $1$ is . Since measuring must return something, the total probability must equal 100%, and therefore:
Using our vector definitions as well as our new sum of squares rule, we can also show how :
Note that we didn't specify any values of or , so this applies to any quantum state, including basis states:
Now that we have our qubits, we want to be able to do something with them. To do that, we use operators.
Operators
In classical computing, there are a number of operators, or gates, that can act on bits, which can be written out as truth tables. For example, the NOT operator, which inverts the bit:
0 | 1 |
1 | 0 |
Similarly, there are a number of quantum operators that can act on qubits. The quantum analogue to the classical NOT operator is the Pauli X operator:
We can derive the operator using the vector forms of and :
The way to apply an operator is to take the dot product with the qubit you want to apply it to:
or in vector notation:
Below is a brief list of common single-qubit quantum operators:
| Name | Symbol | Matrix | Dirac |
|---|---|---|---|
| Hadamard | |||
| Pauli X | |||
| Pauli Y | |||
| Pauli Z | |||
| Identity |
Multiple qubits
Just as adding more classical bits makes it easier to perform larger calculations, adding more qubits makes a quantum computer more powerful. But now we have to worry about how to handle all of these qubits! Turns out, this isn't that difficult (at least mathematically), we just put them together!
We can combine multiple qubits by taking their Kronecker product:
However, that's tedious to write, so there are shorter forms of this:
For example, a 2-qubit state can be written as:
The Kronecker product, also known as the tensor product, is denoted by and is an operation on a vector or matrix that increases its size. The way it works is pretty simple, you just multiply the right hand side by each element of the left hand side:
For instance, let's take the tensor product :
If we have two qubits and we take their Kronecker product, we can write the output in a form known as product form:
As before, any multiple-qubit state can be written in vector notation as well. For example, a two qubit state:
Entanglement
Entanglement is a property that allows qubits to combine together into a single combined state. Before we explore that, we need to understand what defines entanglement.
To start, let's try writing this qubit in product form:
Here, and . That in turn implies that either or must be zero, and either or must be zero.
- If , then .
- If , then .
- If , then .
- If , then .
Uh oh, we've hit a roadblock! No matter what values for , , and we choose, we will never get this state. Since we cannot separate the state into its individual qubits, we say that this state is entangled. In fact, this specific state is known as the "maximally entangled state".
Let's look at a non-entangled state for comparison:
Here, and , meaning that either or must be zero, and either or must be zero. From that, we can see quite easily that setting solves our problem.
Separating out the original qubit:
Entanglement means that the qubits are linked together into one single system. Affecting one affects the other instantly; you can't change them individually. Physically, this is a bit complicated, but you can imagine a long invisible rod that's connecting the two particles, where moving one end of the rod moves the other end instantly.
Where this analogy falls apart is that it assumes a perfectly rigid object, which doesn't exist. Every material on Earth is made up of molecules that are held together by electromagnetic forces, and the speed at which the movement of one molecule affects the next is basically just the speed of sound in that material, since sound is simply a wave of pushing molecules in its direction of travel. However, making changes (applying operators) to entangled qubits is genuinely instant.
We'll explore some of the consequences of this later. For now, since we have a good understanding of how multiple-qubit systems work, we can look at how to apply operators onto them.
Multiple qubit operators
Just as you could apply operators to a single qubit, you can apply them to multiple qubits at the same time. We can start by applying a single-qubit gate to a two-qubit state:
Uh oh, we seem to have hit another roadblock! Since this is a single-qubit gate, it can only be applied to a single qubit. In order to apply an operator to a two-qubit state, we need to make it a two-qubit gate. We can do this by using the tensor product again:
The way this works is that, going from left to right, the first gate applies to the first qubit, the second gate applies to the second qubit, and so on.
We can again derive this using both vector and Dirac notations.
Vector notation:
Dirac notation:
When you're doing the tensor product , you can pull the and through to their respective ket and bra on the other side:
We can apply individual operators on individual qubits, but that doesn't get us very far. For the true power of quantum computing, we need to be able to entangle qubits. For that, we need a truly multi-qubit operator. One common example is the controlled NOT, or the operator. Since we know that the gate is the quantum analogue to the NOT gate, this is also sometimes called the operator.
The way this works is, when applied to a two-qubit state, it'll apply a NOT onto the second qubit if the first qubit is a .
As you can see, when the first qubit is a , such as in the and cases, the second qubit gets toggled ( and , respectively).
Gates like these are the only way to get entangled qubits, you cannot get them from combining single-qubit gates alone. To see how, let's look at the maximally entangled state again:
How would we go about making this state? Well let's start from a very simple state: the . If we have a look at the single-qubit operators table from earlier, we can see that the Hadamard looks like it'll get us about halfway there. So let's apply a to this state.
Ooh, so close. We just need a way to turn that into a . Let's try applying an gate on the second qubit, so an :
Well that solved our problem, but it left us with a instead. We need something that'll apply an , but only when that first qubit is a . So let's use our handy dandy !
We got it! As you can see, there's no single qubit gate that could've done that, so we required a multiple-qubit gate like the . Any combination of single-qubit gates would be of the form , which cannot entangle qubits since they act separately on individual qubits. Whereas multiple-qubit gates act on the entire multiple-qubit state at once to entangle it.
And that's it! That's all of the basic math of quantum computation. Everything we do from now on will be based on various applications of these basic rules. Pretty much all of quantum computation is based on these fairly simple (though not always easy) matrix multiplications.
A fairly well-known fact about classical computing is that all bit operations can be implemented with just the NAND gate. This is pretty easy to prove, you could probably do it yourself if you know your logic gates, there's even a whole game about it!
Similarly, there exists a minimal set of quantum gates, known as the universal gate set, that can be used to make every other operator. The smallest one found so far is the Toffoli gate and the Hadamard gate. However, the proof for this isn't as straightforward as that for the NAND gate.
Measurement
We talked briefly about measuring a qubit earlier, but let's dive a little deeper into what that actually means.
Spectral decomposition
Before we talk about measurement, we have to talk about spectral decomposition. This is basically breaking down an -by- operator into the form:
where are known as the eigenvalues. These eigenvalues are the things that we can observe, not the actual qubit values and themselves, since remember, those are just labels. Let's try to get the spectral decomposition of the Pauli operator. Since is a 1-qubit operator, . For 2-qubit operators, , for 3 qubits, , and so on.
We can't do this in the and eigenbasis because and wouldn't have the same label, while and would both be :
Looks like we'll need to use a different one. Let's look at the and eigenbasis, where:
We can prove that this eigenbasis is orthonormal.
Proving this for and is left as an exercise to the reader ;)
Relabelling $0$ to and $1$ to , we can write as:
Let's try using and :
Setting and , we get:
which was our original definition for .
We now have our two eigenvalues and that we can use when measuring a qubit with . The way to get the probability of these eigenvalues is by using something called the projector. That's just the state we saw in the spectral decomposition. So the projectors for and are:
Measurement
Measurement is just the application of an operator in a given basis. For example, we can take the Pauli operator again. We use the spectral decomposition:
The probability of the measurement outcome is then given by:
where is the state you're trying to measure. So for the state:
So when measuring with , there is a 50% chance of seeing a when you have a . Conversely, the probability of getting a outcome is also 50%:
You'd get the same values when trying to measure the state with .
Applications
By playing around with some quantum computing applications, we can get a better sense of what it's good for and what its limitations are. The math in this section gets a lot more involved than what we've been doing so far, so keep that in mind and make sure you're fairly comfortable with everything before this point.
Teleportation
Let's say we have our two classic characters, Alice and Bob. Alice wants to send a message to Bob, but Bob, being about a light year away at Proxima Centauri, is really far away, so I don't think the post will work. She thinks about using email, but email is, at best, limited by the speed of light, meaning it'll still take a year for the email to reach Bob. Suddenly, she remembers that she and Bob share a maximally entangled state:
where the subscript is Alice's qubit, and is Bob's qubit. Knowing that quantum entanglement works instantly, could she use this to send her message?
Let's say Alice's message is the unknown state . The complete state is then
which can be expanded out to
Alice then measures her two-qubit state, the one with the , with an operator such that it has 4 different eigenvalues , , and corresponding to each of the states.
You'll notice these look pretty similar to the , , and gates we saw earlier.
All of this probably sounds a bit confusing, but notice what happened to Bob's state above. All of those look kind of like that state we started out with. In fact, based on what eigenvalue Alice finds from her measurement, she knows which state Bob got:
since it's just the corresponding state from her state above. So if she got for instance, she got the state that has since that's the vector that corresponds to that eigenvalue. Since her and Bob's qubits are entangled, Bob therefore must have gotten the other half of that state, .
However, Bob doesn't know this yet. As far as he knows, he could still have any of the 4 possibilities:
with equal probability . However, based on the eigenvalue that Alice measures, she can send him a 2 bit message to tell him which operator to measure with.
Following these instructions, Bob can get back in all cases:
There's a factor of in the last case but we can just ignore it.
Now you may be thinking, how exactly is Alice meant to send the 2 bit message to Bob? I thought we were doing all this to send a message instantly and avoid that pesky speed of light limit. Well the truth is, you can't. Even though Alice knew which state Bob had, since Bob never got that knowledge, there was no information transfer faster than the speed of light. I'm sure Einstein is very pleased with this.
Super-dense coding
Although we couldn't send messages faster than light, we can make the message itself smaller.
Let's start simple. Alice wants to send a bit to Bob, but she only has a qubit. This is pretty simple, she just sends the corresponding qubit, for bit 0 and for bit 1. Bob measures with , gets the corresponding eigenvalue out, and he knows what bit Alice sent.
Pretty simple stuff.
Now let's say Alice wants to send 2 bits like in the previous example, but she only has one qubit. She could try sending one of , , or , but that'll always be unclear to Bob what he received. If he tries measuring that with the operator:
and he gets , all he knows now is that it's not . There's still a pretty good chance it could be any of the other choices. That's because these 4 states aren't orthogonal to each other.
This might seem impossible at first glance, but the power of quantum entanglement saves the day yet again! Let's say Alice and Bob share a pair of particles in the same maximally entangled state as before:
where represents Alice's qubit and represents Bob's qubit. Alice can then do one of 4 things to her qubit depending on the message she wants to send.
Alice then sends her qubit. Now Bob has a 2 qubits in 1 of 4 possible orthonormal states, and all he needs to do is measure with a 2-qubit operator that has , , and as its eigenstates. The eigenvalue he gets from that will tell him with certainty which message Alice sent.
Alice just managed to send 2 bits by sending 1 qubit! This coding is known as super-dense coding.
Cloning
All this talk of teleportation and quantum computation is making me think of sci-fi, and sci-fi makes me think of cloning. Is cloning possible? And is it a good idea? Well I can't answer the second question, but I can try answering the first.
We can prove this by pretending that we have a quantum operator that does cloning. That means that if we apply to a pair of qubits, it should copy the first qubit into the second:
We want this operator to be universal, so should be allowed to be any state. Now let's say we have a superposition state . This should be no problem for our cloning operator:
But wait a minute, since quantum operators are linear, we can expand those brackets out on the left hand side:
That's a contradiction! That's not what we wanted, our perfect little cloning operator doesn't work!
Reality is often disappointing. So cloning is not allowed, as specified by the aptly-named no-cloning theorem. I guess we won't have to answer that second question after all.
You're probably thinking: what about Dolly the sheep? I read in the news that she was the first cloned animal, and yet you're here telling me that cloning isn't even real?
Both things are true, they just have different versions of "cloning". There's nothing stopping you from cloning a cell, so long as the particles that make up that cell are different. The no-cloning theorem doesn't really apply for anything except quantum states. You can make a copy of every cell in your body, but it won't be a 100% atom-for-atom clone of you, which who knows what kinds of consequences that could end up having.
CHSH game
Say you have a group of 4 friends: Alice, Bob, Carol and Dan. Alice and Bob want to meet on Saturday, but they each have a 50% chance of being visited by Carol and Dan, respectively. That's not an issue on its own, they can just bring Carol and/or Dan along, but actually Carol and Dan just went through a really bad fight and aren't on speaking terms, so if both of them show up, that would ruin the evening for everyone.
Alice and Bob meet up on Friday to devise a strategy. They have 2 locations they could go to: the park or the beach. If both Carol and Dan show up, Alice and Bob have to find a way to avoid each other. But if only one of them shows up, they have to find a way to meet up. They can't talk on Saturday because that would make Carol and Dan suspicious, so they have to decide what to do beforehand. They'll succeed if they avoid each other if both Carol and Dan show up, and if they meet up when one or neither of them show.
Let's start with a fairly simple strategy. Let's say they decide that Alice should go to the park regardless of whether Carol shows up or not. If Dan shows up, then Bob will go to the beach, otherwise he'll head to the park.
- If neither Carol nor Dan show up, then both Alice and Bob will meet at the park and have a nice evening.
- If only Carol shows up, then Alice, Carol and Bob will meet at the park and have a nice evening.
- If both Carol and Dan show up, then Alice and Carol will go to the park while Bob and Dan go to the beach, successfully avoiding each other.
- If only Dan shows up, then Alice will be alone at the park while Bob and Dan go to the beach.
This strategy works 75% of the time, which sounds pretty good.
In fact, any classical strategy will work at most 75% of the time. To prove this, let's convert this word problem to math.
Alice and Bob receive bits and each with equal probability. We can say that 0 represents their respective friend not showing up, while 1 represents them showing up.
Alice and Bob must then each produce a bit and of their own. Let's say 0 represents going to the park, while 1 represents going to the beach. They win if their bits satisfy the relation:
where the rules of (addition modulo 2) are:
It's basically an XOR.
These are the 4 cases above:
- Neither Carol nor Dan show up, meet up at same place: , meaning .
- Carol shows up but not Dan, meet up at the same place: , meaning .
- Dan shows up but not Carol, meet up at the same place: , meaning .
- Both Carol and Dan show up, meet at different places: , meaning .
where
- is Alice's response when Carol doesn't show up ()
- is Alice's response when Carol does show up ()
- is Bob's response when Dan doesn't show up ()
- is Bob's response when Dan does show up ()
To prove that we can't win the game 100% of the time using any classical strategy, we can prove that there's no combination of values for , , and that work. To do that, we can simply add them up (modulo 2):
Here, we used the rule that , as we saw in the modulo 2 rules above. We ended up with the result $0 = 1$, which we know for a fact is nonsensical, and we didn't even assign any values to , , or !
So that means that there don't exist any values where you can get 100% success, meaning out of our 4 equations at least one must not be satisfied, giving us an upper bound of 3/4 or 75% success, which we already achieved.
Now let's use the power of quantum entanglement to pump up those numbers!
As usual, we start with Alice and Bob sharing the maximally entangled state:
If Carol shows up, Alice measures her qubit with operator , otherwise she uses . Similarly, Bob uses on his qubit if Dan shows up, and otherwise. , , and all have eigenvalues and , so to produce their answers and , they use:
where and are the eigenvalues that Alice and Bob get from measuring their respective operator on their respective qubit.
The operators that Alice and Bob use are:
The thing we're actually measuring is the outcome after both Alice and Bob apply their operators:
which we can rearrange to get:
The statement comes from the fact that measurement of a quantum system is equivalent to finding the expectation value. It holds true for any state and pair of operators and with eigenvalues , not just the particular ones we've chosen here.
Since both Alice and Bob decide to give the answer $0$ when their respective measurement outcome is , and $1$ when their respective measurement outcome is , we know that when , . This means that we can rewrite that expression as
and by using :
Now we just have to find the values of . This calculation is going to be tedious if we try to do it manually, so let's try and simplify things a bit. Looking at our 4 operators, we can notice that they're basically the same operator with an angle on the - plane:
We can use this more general formula to simplify our expression, and since we know that our 4 operators are just special cases of this more general operator, we can plug in our angles for those later.
We can simplify this a bit, knowing that :
Similarly, we have and :
where , i.e. and are orthogonal.
Simplifying:
That last step comes from the trigonometry rule:
since and .
Let's plug this back in to our original formula:
That's much better! We can plug in our operator angles and check each case:
For the case, when both Carol and Dan show up, we want Alice and Bob to go to different places, meaning :
So we see that using this quantum strategy, Alice and Bob can succeed approximately 85.4% of the time! We just proved that a quantum strategy is significantly better than any classical strategy we could have found!
Whew, that's a lot of math! If you made it through all that, congratulations! If you just scrolled past it all and skipped to this point, I don't blame you.
"CHSH" stands for Clauser, Horne, Shimony and Holt. They presented a simpler and more powerful version of Bell's theorem about quantum nonlocality. The version presented here is the more modern framing in the form of a game. That's how it was first taught to me, though with a lot more math (if you can believe it) and a lot of details that I decided to skip here.
Conclusion
I think I'll wrap it up there for now. There are a lot of other things left that I could have covered, like Grover's algorithm, Shor's algorithm, quantum circuits, quantum cryptography, etc., but this post is more than long enough already, and I think most of you have probably left by now after seeing that wall of math. Maybe I'll end up writing about those things in the future.
I'm not sure if you can tell, but this kind of stuff really excites me. We have mathematical proof that quantum computers are capable of doing things that classical computers aren't, and all of it is based entirely upon linear algebra and complex numbers! And that's just scratching the surface of what's possible!
I'd also like to mention QCSim, a quantum computer simulator I built. Most of the stuff I've talked about in this post were what inspired me to build this, and in turn inspired me to look into quantum information and quantum computation as a career path in the first place.
Anyway, that's all I've got for now, seeya next time (hopefully sooner than 5 months lol)!