Hello! Welcome back to your course on the principles of quantum computing.
In our previous lesson, we established that a qubit's state can be described by a 2-element column vector with complex entries. This was our first crucial step in building a mathematical language for quantum computing.
Today, we'll answer the next logical question: how do we change or manipulate a qubit's state? The answer lies in quantum gates, which are mathematically represented by matrices. This lesson will focus on the fundamental operation of applying these gates: matrix multiplication. You've mentioned this is an area you'd like to reinforce, and this lesson is designed to do just that in a way that's directly applicable to quantum circuits.
Our learning outcome is to perform matrix-vector and matrix-matrix multiplication (up to 4x4). By the end of this lesson, you'll understand how applying a single quantum gate is a matrix-vector product, and how combining a sequence of gates corresponds to matrix-matrix multiplication.
1. Why Matrices? Gates as State Transformations
In your electronics studies, you've seen how components like amplifiers or filters transform an input signal into an output signal. Quantum gates do something similar: they transform an input quantum state (a vector) into an output quantum state (another vector). The mathematical tool for this transformation is a matrix.
Let's see this in action. The video below introduces the Hadamard gate, one of the most important single-qubit gates, and shows how it's applied to a qubit state.
The Math Behind Quantum Computing
This clip from 'The Math Behind Quantum Computing' by Faisal's Devlog provides a great visual and mathematical introduction to why we use matrices for quantum gates.
Watch the segment from 00:24 to 02:54. Pay close attention to how the Hadamard matrix is multiplied by the |0⟩ state vector to produce a new vector representing a superposition.
As the video demonstrated, applying the Hadamard gate to the state is a matrix-vector multiplication:
To compute this, we multiply each row of the matrix by the column vector:
This resulting vector, , represents the |+⟩state, a perfect superposition of|0⟩and|1⟩`. This is the core mechanism: gates are matrices, states are vectors, and gate application is matrix-vector multiplication.
2. The Rules of Matrix Multiplication
Now, let's break down the mechanics of matrix multiplication. The process is systematic and follows a clear "row-by-column" rule.
This video from The Organic Chemistry Tutor provides a very clear, step-by-step guide to matrix multiplication. It covers the rules for when matrices can be multiplied and demonstrates the row-by-column procedure.
Watch the first two sections of the video (from 00:01 to 08:01). The first part explains how to determine if two matrices can be multiplied and the dimensions of the result. The second part demonstrates the core 'row-times-column' operation.
Let's summarize the essential rules from the video:
-
Dimension Rule: To multiply matrix by matrix (i.e., to compute ), the number of columns in must equal the number of rows in . If is an matrix and is an matrix, the product will be an matrix.
m x n⋅n x p→m x p
(The inner dimensions must match) -
Calculation Rule: The element in row and column of the product matrix is calculated by taking the dot product of row from matrix and column from matrix .

3. Practice: Composing Single-Qubit Gates (2x2)
In quantum computing, we often apply a sequence of gates. This is equivalent to multiplying their matrices. Let's see what happens when we apply the Hadamard gate twice.
Problem: Calculate the matrix product .
Based on what we've learned, we need to compute:
First, we can multiply the scalar constants: . Now for the matrix part:
- Row 1, Col 1:
- Row 1, Col 2:
- Row 2, Col 1:
- Row 2, Col 2:
Putting it all together with the scalar:
The result is the identity matrix, ! This means applying the Hadamard gate twice is equivalent to doing nothing. This is an essential property and a demonstration of the reversibility of quantum gates.
4. Scaling Up: Multi-Qubit Gates (4x4)
The same rules apply to larger matrices, which represent gates acting on multiple qubits. A common two-qubit gate is the Controlled-NOT (CNOT) gate.
The Math Behind Quantum Computing
Let's return to Faisal's Devlog to see what a 4x4 matrix for a two-qubit gate looks like.
Watch the short segment from 08:42 to 09:42. This will introduce the 4x4 matrix for the CNOT gate.
The CNOT gate is represented by the following 4x4 matrix:
Let's try the same exercise as before: what is the effect of applying a CNOT gate twice? We need to calculate .
The calculation is larger, but the process is identical. Let's compute one element as an example: the element in row 3, column 4 of the product.
- Take row 3 of the first CNOT matrix:
[0, 0, 0, 1] - Take column 4 of the second CNOT matrix:
[0, 0, 1, 0] - Calculate the dot product:
If you continue this for all 16 elements, you will find that , the 4x4 identity matrix. Just like the Hadamard gate, the CNOT gate is its own inverse.
For larger multiplications like this, it can be helpful to use a calculator to check your work once you're comfortable with the process.

Conclusion
Today we've demystified how quantum operations are performed mathematically. This skill is the engine that drives the evolution of quantum states in a circuit.
Key Takeaways:
- Quantum gates are represented by matrices, and applying a gate to a state is performed via matrix-vector multiplication.
- A sequence of gates applied to a state is equivalent to a single gate represented by the matrix-matrix product of the individual gate matrices.
- The rule for matrix multiplication is that the element at
(row i, col j)of the product is the dot product ofrow ifrom the first matrix andcol jfrom the second. - The dimensions must align: for a product , the number of columns in must equal the number of rows in . For our quantum gates, this will always be the case (e.g., 2x2 times 2x2, or 4x4 times 4x4).
Preview of the Next Lesson:
We've now seen how to represent single-qubit states (2x1 vectors) and two-qubit gates (4x4 matrices). But how do we represent the state of a two-qubit system itself? It's not as simple as stacking two vectors. In the next lesson, we will learn about the tensor product, the mathematical operation used to combine single-qubit state vectors into a multi-qubit state vector.