# The Simple Math of Quantum Superposition & Entanglement

## Quantum Computing sounds like science fiction. How can we even measure something so small? Do I need a PhD in physics to understand this? Can you REALLY teleport things? These were all questions I had when I first discovered the field of quantum computing.

This article is for anyone who is interested in quantum computing, not just those with a background in math or computer science. Contrary to popular opinion, you don’t need a PhD in mathematics to understand these concepts.

Of course, these topics sound scary: quantum superposition and entanglement were two buzzwords that I would never understand. However, the reasoning behind them are not all that complicated. Let’s dive in.

# Why do we care about quantum computing?

In classical computers, information is processed on the lowest level using a series of 0’s and 1’s. These 0’s and 1’s form the computer’s “alphabet” and they underpin everything you do from your word processor to the internet. These 0’s and 1’s form a base-2 numbering system. For comparison, we use a base-10 numbering system, meaning that as you count, each time you reach 10 you add a 1 to the next column and begin again from 0.

In the base-2, or binary, numbering system, another digit is added when 2 is reached. For example:

0 = 0

1 = 1

2 = 10

3 = 11

4 = 100

It seems like such simple capabilities could not possibly result in the incredibly complex and capable computers we have today. However, it is the speed of calculation that allows your computer to do so many complicated tasks in the blink of an eye.

For many years, the speed of computing has increased according to Moore’s Law — that the number of transistors on a circuit doubles every 2 years. If you’re not a hardware engineer, this might not mean much to you — but in more concrete terms, this is why your smartphone today is as fast as the supercomputers of the 1970's.

Nowadays, the world is wondering if Moore’s Law is ending, as transistors are now so close together on a chip that engineers must consider effects at the atomic level when attempting to make them smaller.

But that’s not the only issue. There are some problems that, no matter how fast we make our classical computers, will never be fast enough or big enough to solve some difficult problems. Some problems grow exponentially as the number of elements involved increases.

For example, if it takes you 1 second for each step in an exponential problem, a problem with 8 elements will take you a little over 3 minutes to complete. *However, an exponential problem with 100 elements will take you more than 40 sextillion years. *Not a great option!

# Enter the Quantum “Bit”

Quantum computing has the potential to calculate some of the most difficult tasks for a classical computer in exponentially faster time. In terms of hardware, we’re not there yet, but the algorithms have shown that it is possible. With advanced enough quantum computers, you may have heard that algorithms could break our current encryption models. Of course, by the time we get to the point where quantum computers have that capability, those scientists working on post-quantum cryptography will, I’m sure, have found a solution to encrypt data in a way even quantum computers can’t crack.

Quantum computers are based on the “qubit”. Qubits are represented as follows:

These are considered the |0⟩ state and the |1⟩ state, just like classical computers have 0 and 1 states. However, in quantum computing, each state is represented by a vector.

This is because in quantum computing, each qubit doesn’t have to be just 1 or just 0 — it can be partly 1 and partly 0. I like to think of the qubits like this:

# Superposition

Superposition is just a fancy way to describe a state that is partly 0 and partly 1. A qubit can be in equal superposition, as in the following, which is also referred to as the plus state, |+⟩:

Or it can be in some variation with a quarter in 0, and 75% in 1, etc. The only requirement (for calculation reasons) is that is sums up to 1. This is because the amount of the state in 0 and 1 corresponds to the probability that a state will collapse to that when it is measured, and all probabilities must sum to 1.

This is one of the most important and interesting properties in quantum computing — that a qubit can be in either or both of the two states for some period during calculation, and then only resolves to a particular state when it is measured.

After placing a qubit in equal superposition (the vector above), I measured that qubit and then ran the circuit through the Aer simulator from Qiskit. Below is an example of the kind of results you can achieve:

Indeed, it’s about a 50–50 chance of getting 0 versus getting 1. The only value you can’t get is the superposition itself — once a qubit is measured, it collapses to one of the two measurement states, and the superposition is gone.

# Multiple Qubits

Thus far, I’ve been talking only about single qubits. Multiple qubits add a little more complexity but also a lot of possibilities with what you can do.

As of this writing, the largest quantum computer has 65 qubits. For comparison’s sake, many common computers nowadays have 8 GB of RAM — which is 68,719,441,552 bits. So quantum computing still has a long way to go. (This is why we don’t need to worry about quantum computers cracking encryption… yet.)

Let’s start with how 2 qubits are represented. Just like a single qubit has to represent the amount of 0 and the amount of 1 state it has, two qubits have to represent 4 different possible states: 00, 01, 10 and 11. This is done with what is called the *tensor product*, which basically creates all of the possibilities of combining the two qubits together. This is what I mean:

And in general:

The same process can also be done with states in superposition, for example:

As a side note, this is why it is so difficult to simulate quantum computing on a classical computer: as the number of qubits increases, the size of the vector needed to hold the state vector increases exponentially. Read exponential increase = generally bad.

# Gates

Before we can proceed to quantum entanglement, we need to explore one more facet: gates. These are like transformations and can be applied to a single qubit or multiple qubits.

In classical computing, they represent logical actions like AND, OR, NOT, XOR. For example, an AND gate can work as follows:

In quantum computing, gates apply certain transformations to the qubit states that allow us to make calculations.

## The Hadamard

We’ve already talked about the quantum state |+⟩, which is an equal superposition of |0⟩ and |1⟩. There is an easy way to produce that state, using a single-qubit gate called a Hadamard gate (referred to in circuit diagrams as “H”).

The Hadamard gate is represented by the following matrix:

When this gate is applied to the |0⟩ state, the result is the |+⟩ state superposition. This is how:

## Controlled-NOT

The second class of gates I will briefly touch on are the multi-qubit gates. These gates rely on multiple qubits to perform their actions — in many case, using a “control” qubit and a “target” qubit.

The truth table resulting from the controlled-NOT gate is as follows:

When bit 0 (the control) is 0, nothing happens to bit 1 (the target). However, when the control bit is 1, then the target bit is flipped. That’s why it is called controlled-NOT — the target is flipped only when the control is on.

This gate is commonly referred to as CNOT, and can be applied as follows:

Bit 0 is generally written farthest to the right, which is why the above may appear backwards at first.

If you look closely at the input and output of the CNOT gate, you can also see that it can be described as follows:

When the CNOT gate is applied, elements a11 and a01 are swapped. This is an easier way to think about it than looking at the actual 4x4 matrix, which looks extremely complicated.

As a note, these two gates are by no means an exhaustive list of the possible single- and multi-qubit gates available. These are merely the two gates needed for an entanglement circuit.

# Entanglement

We’ve now established all of the building blocks — qubits, superposition, the two gates required — but what exactly is quantum entanglement?

Mathematically, it means that the tensor product of the two qubits cannot be factored out. One example of that is as follows:

There is no way to mathematically separate this into the tensor product of two vectors with two elements.

Sound complicated? Physically, entanglement means that when you measure one of those two qubits, the other qubit collapses to the same state. This happens no matter if the qubits are close together or if one of them is on the moon. And they don’t decide ahead of time — this is just a property of the quantum universe.

Entanglement is used in all kinds of circuits, including quantum teleportation. It is a fundamental building block of quantum computing. So how do we do it?

Visually, this is the circuit that is required for quantum entanglement:

Two qubits are present — q0 and q1. In a circuit such as this, all qubits are initialized to the |0⟩ state. The Hadamard gate “H” is applied to q0, following by the CNOT gate, which is applied so that the control is q0, and the target is q1. Then, I measured the qubits to check if I was successful.

So, recall what I am doing mathematically. q0 starts off at |0⟩ and then has the Hadamard gate applied:

Next, consider the pair of qubits together as two qubits are represented by the tensor product of the two:

Finally, apply the CNOT gate by swapping the elements as we did with a11 and a01:

Voila! You have now successfully entangled two qubits.

Running that through the Qiskit Aer simulator, the following results were achieved:

As expected, when the qubits were measured, they both either collapsed to 0, or to 1. Because they were in an equal superposition, there was a roughly equal chance that they would collapse to 00 versus 11.

Interestingly, when run on an actual quantum computer through IBM’s Quantum Experience, the results were slightly different:

This is because while in general the result is still the same, there is a long way to go still when it comes to quantum error correction. There are currently several different methods to deal with error correction — at the hardware level and in software, all of which are constantly improving. Quantum computers are extremely sensitive and one of the field’s biggest challenges at the moment is getting the maximum number of qubits while still ensuring those qubits are reliable.

# Now that you understand these core concepts, what’s next?

Quantum computing is at the beginning of an exciting new chapter in its development. As more and more researchers and investors flock to this field, it is worth knowing about quantum computing because these devices are only expanding in power and reach. They could soon have capabilities that would help many industries and research projects — from chemistry, to options trading, to fertilizer.

Because of the unique nature of quantum computing, it can tackle problems that classical computers cannot, giving exponential speedup to some of those problems that could take classical computers millions of years to complete.

More than that, quantum computing is a field with enormous potential — and it’s only growing. If you’re curious about learning more, check out Qiskit and the Qiskit textbook for more material.

# References

- Qiskit Textbook, https://qiskit.org/textbook/preface.html.
- IBM Quantum Experience, https://quantum-computing.ibm.com/.
- “IBM promises 1000-qubit quantum computer — a milestone — by 2023”, https://www.sciencemag.org/news/2020/09/ibm-promises-1000-qubit-quantum-computer-milestone-2023.