# A Mathematical Approach to Quantum Computing

## Leveraging Linear Algebra and Quantum Mechanics to Understand Quantum Computing

The introduction of classical computers into modern society was a miracle.

The thought of being able to pull out a *book-sized machine* that can communicate with **anybody** **around the globe **and access the *bizarre* world of the **internet** is pretty insane. It’s even more insane to think that we have handheld devices capable of doing the same thing.

Classical computers introduced us to the **world of Artificial Intelligence**, we’re now moving into a new phase of the internet known as **Web 3.0**, and these computers are now in every inch of our lives. There’s no doubt that classical computing is propelling us into the future of modernity.

**But what if I said that there’s another type of computer** — one that can process data

*exponentially*faster than classical computers, destroy classical encryption methods, and completely redefine the way we look at classical algorithms?

# Quantum Computers — A New Era

We’ve entered the era of **quantum computers**. Before you ask, **no**… they won’t replace classical computers… **yet**. Classical computers *do *have their place in modern society and quantum simply isn’t at a current state where it’s able to **replace classical computation**.

However, there *are *various** applications of quantum computing **in which quantum computers can outperform their classical counterparts.

Quantum supremacy is a term used to describe the state of quantum computing in which quantum computers outperform classical computers in complex problem solving

Our world is working towards quantum supremacy — an event that may happen sooner than we think on a large scale. Despite quantum computers *not *being able to **replace classical computers**, they’re a pretty massive **next step** in the world of computing.

## Applications of Quantum Computing

The applications of quantum computing take the **status quo** to the *next level. *Current applications of quantum computing include:

**QML (Quantum Machine Learning) —**drastic improvements upon the current standard for ML in computational speeds, data processing, and accuracy rates**Computational Chemistry**— allows for superpositions within molecules, opening doors for pharmaceutical research and simulations that simply aren’t possible on their classical counterparts**Drug Discovery and Development —**increasing accuracy for molecular property prediction and drug reaction to human simulations, removing various “trial-and-error” elements in current drug discovery**Quantum Finance**— solving complex financial problems such as long-term forecasting, large-scale portfolio optimization, and stock-market simulations**Cryptography**— quantum cryptography allows for the completion of normally impossible cryptographic tasks while providing physics-based security as opposed to mathematical algorithmic-based security

# How can we Learn Quantum Computing?

There’s no doubt that **quantum computing **is an *incredible* technology! However, it’s, unfortunately, a very rigorous technology in terms of prerequisites.

That being said, it’s ** not** a technology exclusive to

**Ph.D.'s**or

**university students**. In fact, it’s very possible for

**High School students**to

*learn*and

*apply*this technology.

## Prerequisites

There are two primary prerequisites to learn quantum computing:

**Quantum Mechanics**— Quantum computing is entirely based on the foundation of physics, and quantum mechanics, making it somewhat a requirement to have*some*knowledge of quantum mechanics, and classical mechanics by extension**Linear Algebra**— Quantum computing concepts are all represented with the mathematical field of linear algebra. Without a thorough quantum-oriented understanding of linear algebra, it becomes incredibly difficult to truly apply this technology

This article will touch on the first prerequisite but isn’t going to touch **Quantum Mechanics** in-depth. However, this article aims to provide *most *of the prerequisite knowledge required in a mathematical sense.

Realistically speaking, a single article can’t *teach* you the entirety of the subject of **Linear Algebra**. That being said, it can provide all of the quantum-specific knowledge that is required so you can get started!

# What Exactly **IS Quantum Computing?**

Quantum computing is essentially a *new type of computing *that utilizes the phenomena of **quantum mechanics** as opposed to its classical counterpart. Let’s simplify this a bit.

## Classical Bits

Classical computation uses something known as **bits** — tiny storage compartments for **0’s and 1’s**. Different combinations of 0’s and 1’s represent *different things* on our computers.

For example,‘01101000 01100101 01101100 01101100 01101111 00100000 01110111 01101111 01110010 01101100 01100100’is“Hello World”in binary.

Each **0 or 1 **is stored in a bit. This means that above, there are 88 bits in use.

Each bit is capable of storing either a 0 or a 1, meaning there are **2 possible combinations **— 0 and 1. However, suppose we have 2 bits. We now have **4 possible combinations** — 00, 01, 10, and 11. Essentially, the # of combinations = 2 ^ # of bits. If you have 64 bits as an example, there are around **20 quintillion (18 zeros) **different combinations that you can make. That’s INSANE!

However, this is nothing in comparison to **quantum bits**…

**Quantum Bits (Qubits)**

Instead of only being able to store 0’s and 1’s, **qubits** can hold multiple states at the same time. They’re not actually storing **both 0 and 1**

**simultaneously**, but a

**probability of the two**.

Let’s use an analogy. Suppose we have a coin. There are only two possible results:** heads or tails**. This is similar to a bit. However, what if we spun the coin? While the coin is spinning, the coin isn’t heads *OR*** **tails, it’s a **probability** — 50% for heads, and 50% for tails.

**Qubits can store something known as a superposition **— a probability of being 0 or 1.

Qubits can essentially be in** multiple states **at the same time. However, they do *eventually* collapse into either 0 or 1 once measured. Let’s compare this to bits.

Let’s say we have** two bits **with the first storing a 0, and the second storing a 1.** The two bits together are 01**.

Now let’s say we have **two qubits **with them both being in a superposition of both 0 and 1. These two qubits can now store 00, 01, 10, and 11, depending on how they collapse.

The world itself isinnately quantum. Classical computers are incredibly bad at simulating the way our world works at an atomic level due to theiratomic nature. The world doesn’t run in0’s and 1’s— it’s just not that black and white.Quantum computersandsuperpositionsare able to simulate and represent the intricacies of our world at an atomic level, presenting itself as onlyoneof the vast applications ofquantum computing.

## Collapsing Qubits

I mentioned briefly that qubits eventually collapse into either a 0 or a 1. I want to elaborate on this further.

This gif is a good representation of how superpositions work. Think of it this way — when nobody is looking, our qubits can be either a **0 or a 1**. However, the second somebody takes a look at the qubit and tries to see its value, it’s very clearly either a **0 or a 1**, very similar to **binary**.

The action of observing a qubit in the quantum world is known as ‘measuring’ it.

# Putting Qubits into Superpositions

Now that we understand what quantum computing is, let’s talk about how we’re actually able to put **qubits into superpositions**. To understand this, we have to understand how we **change the state of a classical bit**.

## Classical Gates

Classical gates are the facet in which bits are able to be manipulated, and applied. Classical gates are like** mathematical functions** that take in an input and **produce an output**.

Let’s take the **‘NOT’** **gate** as an example. This gate reverses the state of the bit. For example, if a bit is a 0, the **‘NOT’** **gate **will return a 1. If a bit is a 1, the **‘NOT’** **gate** will return a 0.

We can create circuits using these gates to take a bit to do something to it. These circuits are used for classical computations such as **addition, subtraction, multiplication, division, etc.**

The circuit above is a **binary multiplier**. This essentially takes two binary integers and multiplies them with each other.

These circuits and gates are the way that we can manipulate classical bits to do what we need them to, and are the foundation of all classical computation.

## Quantum Gates

Quantum gates are **much more complicated** than classical gates. They work in a similar way in the sense that quantum gates are able to *manipulate the state of a qubit*.

That being said, the biggest difference is that qubits can have **superpositions** — meaning that it’s *much more complicated* to manipulate them.

To understand quantum gates, let’s quickly understand the **mathematical representation of a qubit.**

# Representing Qubits Mathematically — The Bloch Sphere

When we were talking about **classical bit manipulation**, it was very black and white. Bits are either** 0’s or 1’s.** The gates decide whether certain bits are 0’s or 1’s, allowing for *bit manipulation*.

To represent qubits, we need to find a way to represent a **probability** as opposed to simply just **0 or 1**. To do this, we use something known as the **‘Bloch Sphere’**

The Bloch sphere is a geometric representation of qubit states. Above, we can see what the* 0 and 1 states* look like on the** Bloch sphere**. The pink lines that we see are known mathematically as **vectors**.

## Vectors

Vectors are a fundamental part of **quantum computing**. All quantum computing states are represented as vectors. Think of a vector as a mathematical list that has certain **mathematical** **properties** such as addition and multiplication.

Geometrically speaking, a vector is very similar to a line. However, vectors have a magnitude and a direction. The magnitude refers to its **length**, and the direction refers to… well… its **direction**.

Mathematically speaking, vectors look like this:

These are **two-dimensional vectors**. For now, all of our vectors will be in two dimensions, meaning they have an** x-component **and a **y-component**. We also see that we can represent these vectors graphically on the cartesian plane.

We can also classify vectors as **row vectors **or **column vector**s. For now, it’s not super important but it will come up later.

Also note that we can **add vectors**, and **multiply them with scalars **(non-vector numbers). This is relatively intuitive.

## Dirac notation

Dirac notation, also known as **Bra-Ket notation** is a way of representing vectors in **quantum mechanics**. Let’s take a look at two of the most common vectors — the vectors for the 0 and 1 states.

The way that state vectors work is that the first number in the vector dictates **the probability of being a 0** and the second number in the vector dictates the **probability of being a 1**.

As we can see, if we have a 1 in the top and a 0 in the bottom, the qubit has a **100% probability** of collapsing into a 0. If we have a 0 in the top and a 1 in the bottom, the qubit has a **100% probability** of collapsing into a 1.

If we look at the notation, we see two vectors: |0 **⟩** and |1 **⟩**. This is known as a ‘**Ket’**. We can also have a **‘Bra’ **which looks like **⟨** 0| and **⟨** 1| instead. The only difference is that a **‘Bra’ **is a row vector and a** **‘**Ket’ **is a column vector.

## Basis Vectors

Basis vectors are **vectors** that are** linearly independent** and *span a given vector space*. This may be complicated to understand at first so let’s simplify this into easier language.

**Let’s grab our Bloch sphere again.**

The Bloch sphere represents the state of a qubit. W**e can find any vector on the Bloch sphere by taking a combination of the **|**0 ⟩ vector and the **|**1 ⟩ vector.**

Intuitively, this makes sense. The |0 **⟩** vector represents a vector in which there’s **a 100% probability** of our qubit **collapsing into a 0** — if we look at our Bloch sphere on the right, this vector points to the **top of the Bloch sphere**. The |1 **⟩** vector represents a vector in which there’s a **100% probability** of our qubit **collapsing into a 1** — if we look at our Bloch sphere on the left, the vector points to the **bottom of the Bloch sphere**.

If we combine a little bit of both of these vectors, we can see that it’s possible to derive vectors that have a 30% probability of collapsing into a 0 and a 70% probability of collapsing into a 1 as an example.

This means that the** **|**0 ⟩ vector **and** **the** **|**1 ⟩ vector **are** **our** basis vectors.**

The Bloch sphere, for example, could have a vector that looks like this. Here, our state is in a superposition. This vector is called a **state vector **and is essentially a vector that describes** the state of a given qubit**.

## State Vectors in a Mathematical Sense

I mentioned that every vector can be written as a kind of a **combination** of our basis vectors. This combination is known as a **linear combination**. A linear combination of two vectors is a vector that results from multiplying each vector by a scalar and adding them together.

Here, ‘**a’ **and ‘**b’ **are random scalar values (non-vector values). What I’m trying to say is that we can derive any vector on the Bloch sphere by taking a linear combination of **the **|**0 ⟩ vector and the **|**1 ⟩ vector.**

The general formula for a state vector would then be as follows:

## Calculating Probabilities — Born Rule

Now that we have a mathematical representation of a **state vector**, we can figure out how to **calculate** **probabilities**. After all, a superposition is made up of **probabilities**.

What we can do is take any given state vector, and take the coefficients of the vectors. In the above example, we have **‘Alpha’ **and **‘Beta**.**’ **Born rule states that the square of these coefficients gives us the probabilities of our state vector.

For example, **‘Alpha’ **squared is the probability of our qubit collapsing into a 0 and **‘Beta’ **squared is the probability of our qubit collapsing into a 1. For example:

Over here, the probability of our qubit collapsing to 0 and 1 is **50% **for both. Remember that probabilities **MUST add up to 100%**, meaning that **Alpha squared** **+** **Beta **squared **MUST = 1**.

## Representation on the Bloch Sphere

Let’s close this all up and represent our vector state ‘**phi**’ from our previous calculation on the **Bloch Sphere**.

As we can see, the vector looks around **halfway between 0 and 1**, displaying that it has a **50% probability** of being either 0 or 1 **after collapsing**.

All of this **Linear Algebra **went into representing a qubit on this Bloch sphere through a state vector. However, now that we understand how qubits are represented, we can now learn how to manipulate them using **Quantum Gates**.

# A Mathematical Approach to Quantum Gates

Now that we know all the math behind **qubit representation **and the **Bloch sphere**, we can move on to understanding **quantum gates**.

Quantum gates create some sort of **rotation of a vector** around the Bloch sphere. The idea is that we can manipulate the **state of a qubit **by manipulating the **state vector itself**.

This is a graph of a bunch of different quantum gates, and what they’re doing **geometrically**. For example, the ‘**X**’ gate creates a **pi rotation around the X-axis**. We know that a **pi radians** refers to **180 degrees** or half a rotation on a sphere.

For example, a **pi rotation around the X-axis** on the state |**0 ⟩ **would result in a |**1 ⟩** since it essentially flips the **statevector**. Similarly, a **pi rotation around the X-axis **on the state |**1 ⟩** would result in |**0 ⟩**.

This is very similar to the **Classical ‘NOT’ gate**. However, it allows for the manipulation of qubits in superposition as well, hence why it’s a quantum gate. As you can see, the intended purpose of these **quantum gates **is fulfilled simply by rotating a state vector on the Bloch sphere.

Every gate has** some sort of rotation** as such on **some axis**. The previous chart displays what all of the rotations are.

## How do Gates Rotate State Vectors?

Mathematically speaking, each gate is something known as a **matrix** that, when multiplied with the **state vector**, causes the rotation to occur.

These are a couple of examples of the **matrices** for these quantum gates. **Matrix-Vector multiplication **is a little bit complicated to explain in an article and it's not entirely necessary to apply quantum computing. That being said, it’s incredibly useful to understand how all of this works.

If we look above, to multiply a matrix and a vector, we simply take **each column of the matrix **and multiply it by **each row of the vecto**r, and then **add it up**.

For example, when we apply the **NOT gate** or the **X gate**, we start with the vector state** phi** and assign components **a** and **b**.** **We then multiply it by the **X matrix** given in the chart and we end up with a **new vector**. This vector essentially flipped the components **a**, and **b** to result in **b**, and **a**.

Graphically speaking, flipping the components of the vector does a rotation on the **X-axis **of the **Bloch sphere** by **pi radians**, exactly what we expected!

**Here’s a quick challenge for you:**

Mathematically apply thePauli-Z gateand theHadamard gateonto the statephiand get the result in terms ofaandb.

A quick hint for the Hadamard gate would be to save the **coefficient (1/sqrt2) until the end** and multiply every **component in the final vector with this coefficient**.

# Wow… That was a lot

This article was incredibly dense so you may need to read it a second time to truly understand everything that was said in it.

**In this article, we went through:**

- The Importance of Quantum Computing
- The Applications of Quantum Computing
- Prerequisites to Quantum Computing
- Classical and Quantum Bits
- A Mathematical Approach to Classical and Quantum Gates

## Next Steps

If you want to continue diving into the *mathematics, physics, and applications* of **quantum computing**, I **HIGHLY** recommend going through the entirety of the Qiskit Textbook. It’s an incredible resource that takes a rigorous approach to quantum computing and provides all of the knowledge you need to get started.

**From here on out, I wish you luck in your future endeavours through quantum computing!**

If you liked this article, please check out my other articles here, or check out my article on Quantum Teleportation here.

Feel free to check out my other socials: **LinkedIn**, **Twitter**

Consider subscribing to my newsletter here! I talk a lot about my progress, experiences, and my struggles. My February issue just came out where I discuss my relationship with momentum, as well as its importance over motivation.