Quantum Gates: When Vectors Meet Matrices
How Linear Algebra Powers Quantum Logic

1. Recap: Where We Left Off
In the last post, “Speaking Quantum: The Math Beneath the Magic”, we explored how a qubit isn't just a bit—it’s a vector ∣ψ⟩ living in a complex vector space. We swapped spooky analogies for precise tools to describe a static qubit: Hilbert Space (the arena), Kets ∣ψ⟩ (the address), and the Bloch Sphere (the map).
We looked at the math that defines a static qubit. But a static computer is useless; we need to change those states to compute. That brings us to this week's discovery: Quantum Gates.
Right now, we can perfectly describe a qubit floating in superposition. But before we can actually "ask" the qubit a question (measurement), it is important to know and understand the Quantum Gates that manipulate it.
Definition: A quantum gate is a reversible, unitary operation represented by a matrix that manipulates the state vector of a qubit to perform computation.
Table of Contents
The Golden Rule
Single Qubit Gates
Two-Qubit Gates
Multi-Qubit Gates
My Takeaway
2. The Golden Rule: Unitary Matrices
Before diving into specific gates, I learned there is one strict rule all quantum gates must follow: they must be Unitary Matrices.
Mathematically, a matrix U is unitary if:
$$U^\dagger U = I$$
(Where U† is the conjugate transpose and I is the identity matrix).
Why does this matter? It’s all about preserving the length of the qubit. In quantum mechanics, the length (or "norm") of the state vector represents the total probability of all possible outcomes. This must always equal 1 (100%). You can't have a 120% chance of an event happening!
If we act on a state ∣ψ⟩ with a gate U, the length of the new state must remain unchanged:
$$\|U\ket{\psi}\| = \|\ket{\psi}\| = 1$$
There is a powerful theorem in linear algebra that connects these concepts: If U is a matrix, then the equation ∣∣ U∣ψ⟩ ∣∣=∣∣ ∣ψ⟩ ∣∣ is true if and only if U is unitary for all ∣ψ⟩.
Hence, all quantum gates must be unitary in order to preserve the length of the state vector and ensure we always obtain a normalized output with a magnitude of 1.
3. Single Qubit Gates: The Toolkit
Since a single qubit is a vector, we need a toolkit of matrices to move it around the Bloch Sphere. Here are the essential ones I’ve learned.
A. The Identity Gate (I)
This is the "do nothing" gate. It might seem useless, but in quantum circuits, it's often used as a placeholder or to describe a "wait" period where the qubit is left alone.
- Matrix:
$$I = \begin{pmatrix}1&0\\0&1\end{pmatrix}$$
- Effect:
$$I∣ψ⟩=∣ψ⟩$$
B. The Pauli Gates (X, Y, Z)
These are the quantum workhorses. They correspond to rotating the qubit 180∘ (π radians) around the X, Y, or Z axes of the Bloch Sphere.
1. Pauli-X (The "Bit Flip") Acts like a classical NOT gate.
- Matrix:
$$X=\begin{pmatrix}0&1\\1&0\end{pmatrix}$$
- Effect: Swaps amplitudes of ∣0⟩ and ∣1⟩. (∣0⟩→∣1⟩).
2. Pauli-Y (The "Bit & Phase Flip") This one is tricky. It flips the bit and multiplies by the imaginary unit i.
Matrix:
$$Y=\begin{pmatrix}0&i\\-i&0\end{pmatrix}$$
Effect: ∣0⟩→i∣1⟩ and ∣1⟩→−i∣0⟩. It rotates around the Y-axis.
3. Pauli-Z (The "Phase Flip") This gate leaves ∣0⟩ alone but flips the sign of ∣1⟩.
- Matrix:
$$Z=\begin{pmatrix}1&0\\0&-1\end{pmatrix}$$
Effect: ∣0⟩→∣0⟩ and ∣1⟩→−∣1⟩.
Why care? It creates "quantum interference" by changing the relative phase without changing the probability of measuring 0 or 1.
C. The Hadamard Gate (H)
The most famous quantum gate. It creates superposition.
- Matrix:
$$H=\frac{1}{\sqrt{2}}\begin{pmatrix}1&1\\1&-1\end{pmatrix}$$
- Effect: It maps basis states to superpositions:
$$\ket{0}\rightarrow\frac{\ket{0}+\ket{1}}{\sqrt{2}}=∣+⟩, \qquad \ket{1}\rightarrow\frac{\ket{0}-\ket{1}}{\sqrt{2}}=∣−⟩$$
D. The Phase Gates (S, T)
The Pauli-Z gate rotates the qubit by 180 degrees around the Z-axis. But what if we want smaller rotations? That's where S and T come in.
1. The S Gate (Phase Gate). It is the square root of Z. It rotates the qubit 90 degrees around the Z-axis.
Matrix:
$$S=\begin{pmatrix}1&0\\0&i\end{pmatrix}$$
2. The T Gate (π/8 Gate). It is the square root of S. It rotates the qubit 45 degrees around the Z-axis.
Matrix:
$$T=\begin{pmatrix}1&0\\0&e^{i\pi/4}\end{pmatrix}$$
E. Rotation Gates (Rx, Ry, Rz)
Sometimes we don't want a fixed flip; we want to rotate the qubit by a specific angle θ. These are crucial for Quantum Machine Learning.
1. Rotation around X (Rx(θ))
Matrix:
$$R_x(\theta)=\begin{pmatrix} \cos(\theta/2)&-i\sin(\theta/2)\\ -i\sin(\theta/2)&\cos(\theta/2) \end{pmatrix}$$
2. Rotation around Y (Ry(θ))
Matrix:
$$R_y(\theta)=\begin{pmatrix} \cos(\theta/2)&\sin(\theta/2)\\ -\sin(\theta/2)&\cos(\theta/2) \end{pmatrix}$$
3. Rotation around Z (Rz(θ))
Matrix:
$$R_z(\theta)=\begin{pmatrix} e^{-i\theta/2}&0\\ 0&e^{i\theta/2} \end{pmatrix}$$
- Takeaway: These rotation gates prove that quantum computing is continuous, not just discrete like classical bits. We can rotate a qubit by 1 degree, 45 degrees, or 0.0001 degrees!
4. Two-Qubit Gates: Interaction & Entanglement
This is where the magic happens. A single qubit is just a fancy wave; two qubits allow for entanglement. Mathematically, the state space now has 4 basis states (∣00⟩,∣01⟩,∣10⟩,∣11⟩), so our gates become 4×4 matrices.
A. The Controlled-X Gate (CNOT)
The "Hello World" of multi-qubit gates. It’s a conditional gate:
Control Qubit (1st): Decides if the action happens.
Target Qubit (2nd): Gets flipped (X) only if Control is ∣1⟩.
Matrix:
$$CX = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix}$$
Effect: It maps ∣10⟩→∣11⟩ and ∣11⟩→∣10⟩. If you apply this to a superposition (like putting the control through a Hadamard first), you generate the famous Bell State (entanglement):
$$\frac{\ket{00}+\ket{11}}{\sqrt{2}}$$
B. The SWAP Gate
Sometimes, you just need to move data around. If Qubit A is in state ∣ϕ⟩ and Qubit B is in state ∣ξ⟩, the SWAP gate switches them.
Matrix: Notice the middle two rows are swapped compared to the Identity matrix.
$$SWAP=\begin{pmatrix} 1&0&0&0\\ 0&0&1&0\\ 0&1&0&0\\ 0&0&0&1 \end{pmatrix}$$
Effect:
$$SWAP∣01⟩=∣10⟩$$
This is crucial in actual hardware (like superconducting qubits), where qubits might not be physically connected. You have to "swap" information down the line to get two distant qubits to talk to each other.
C. The Ising Gates (Rxx, Ryy, Rzz)
While CNOT is great for logic, these "Rotation" gates are closer to the physics of how atoms actually interact. They rotate two qubits simultaneously based on their relationship to each other.
Why are they called "Ising" gates? It sounds like a typo, but it's actually physics history! They are named after physicist Ernst Ising, who created the Ising Model to explain ferromagnetism (how magnets work).
In his model, neighboring atoms "talk" to each other based on their spin. Since these quantum gates simulate that exact same interaction—coupling two qubits based on their spin state—we call them Ising Gates.
1. The Rzz Gate (Rzz(θ)): This is a rotation based on the "parity" of the bits.
If the bits are the same (00 or 11), it adds a phase of −θ/2.
If the bits are different (01 or 10), it adds a phase of +θ/2.
Matrix (Diagonal):
$$R_{zz}(\theta)=\begin{pmatrix} e^{-i\theta/2}&0&0&0\\ 0&e^{i\theta/2}&0&0\\ 0&0&e^{i\theta/2}&0\\ 0&0&0&e^{-i\theta/2} \end{pmatrix}$$
2. The Rxx Gate (Rxx(θ)): This causes an interaction that rotates the states between ∣00⟩↔∣11⟩ and ∣01⟩↔∣10⟩. It is the native gate for Ion Trap quantum computers.
Matrix:
$$R_{xx}(\theta)=\begin{pmatrix} \cos\frac\theta2&0&0&-i\sin\frac\theta2\\ 0&\cos\frac\theta2&-i\sin\frac\theta2&0\\ 0&-i\sin\frac\theta2&\cos\frac\theta2&0\\ -i\sin\frac\theta2&0&0&\cos\frac\theta2 \end{pmatrix}$$
Effect: Just like the single-qubit rotation gates, these allow for continuous evolution of entanglement, rather than just a digital on/off flip.
3. The Ryy Gate (Ryy(θ)): This gate performs a rotation based on the Y-basis interaction. It is mathematically similar to Rxx but introduces imaginary phase components on the "outer" corners of the matrix.
Matrix: Notice that the signs on the imaginary sine terms are different from Rxx (positive on the outer corners, negative on the inner).
$$R_{yy}(\theta) = \begin{pmatrix} \cos\frac{\theta}{2} & 0 & 0 & i\sin\frac{\theta}{2} \\ 0 & \cos\frac{\theta}{2} & -i\sin\frac{\theta}{2} & 0 \\ 0 & -i\sin\frac{\theta}{2} & \cos\frac{\theta}{2} & 0 \\ i\sin\frac{\theta}{2} & 0 & 0 & \cos\frac{\theta}{2} \end{pmatrix}$$
5. Three-Qubit (and Multi-Qubit) Gates
As we add qubits, the matrices grow exponentially. For 3 qubits, we deal with 23=8 states, meaning we need 8×8 matrices. These gates allow us to build complex logic like "If A and B are true, then do C."
A. The CCX Gate (Toffoli)
Also known as the Controlled-Controlled-NOT. This gate is legendary in quantum computing because it is "universal" for classical logic. It acts as a standard reversible "AND" gate.
- Logic: It looks at two control qubits. If—and only if—both are ∣1⟩, it flips the target qubit.
Matrix: It looks like an Identity matrix, except for the bottom-right corner, where the bits corresponding to ∣110⟩ and ∣111⟩ are swapped.
$$CCX=\begin{pmatrix} 1&0&0&0&0&0&0&0\\ 0&1&0&0&0&0&0&0\\ 0&0&1&0&0&0&0&0\\ 0&0&0&1&0&0&0&0\\ 0&0&0&0&1&0&0&0\\ 0&0&0&0&0&1&0&0\\ 0&0&0&0&0&0&0&1\\ 0&0&0&0&0&0&1&0 \end{pmatrix}$$
Effect:
CCX ∣110⟩ = ∣111⟩
CCX ∣100⟩ = ∣100⟩ (Nothing happens because the second qubit is 0)
B. The CSWAP Gate (Fredkin)
Also known as the Controlled-SWAP gate. This gate is fascinating because it allows us to conditionally route data. It has one control qubit and two target qubits.
Logic:
If Control is ∣0⟩: Do nothing.
If Control is ∣1⟩: Swap the two target qubits.
Matrix: Here, the swap happens between state ∣101⟩ (decimal 5) and state ∣110⟩ (decimal 6).
$$CSWAP=\begin{pmatrix} 1&0&0&0&0&0&0&0\\ 0&1&0&0&0&0&0&0\\ 0&0&1&0&0&0&0&0\\ 0&0&0&1&0&0&0&0\\ 0&0&0&0&1&0&0&0\\ 0&0&0&0&0&0&1&0\\ 0&0&0&0&0&1&0&0\\ 0&0&0&0&0&0&0&1 \end{pmatrix}$$
Effect:
$$CSWAP∣101⟩=∣110⟩$$
(The first qubit was 1, so the second and third qubits swapped: 01→10).
C. The MCX Gate (Multi-Controlled X)
What if you have more than 3 qubits? The MCX is the generalized version of the Toffoli gate. It can have any number of control qubits (n) and one target qubit.
- Logic: The target flips if all n control qubits are ∣1⟩.
Matrix Structure: Writing out the matrix for, say, 10 qubits would require a 1024×1024 grid! However, the pattern is simple. It is a giant Identity matrix, except for the very last 2×2 block, which is a Pauli-X (NOT) gate.
$$MCX_n = \begin{pmatrix} I_{2^{n-2}} & 0 \\ 0 & X \end{pmatrix}$$
Where:
I(2n−2) is an Identity matrix of size (2n−2)×(2n−2).
X is the standard Pauli-X gate
6. My Takeaway
This week taught me that the "magic" of quantum computing is really just Linear Algebra in disguise.
Matrices are the machinery: Every single operation we perform on a quantum computer—whether it's flipping a bit or entangling atoms—is just a matrix multiplication. If you can multiply a matrix by a vector, you can simulate a quantum gate.
Dimensions explode: I realized why simulating quantum computers on classical laptops is so hard.
1 Qubit = 2×2 matrix (4 numbers)
3 Qubits = 8×8 matrix (64 numbers)
10 Qubits = 1024×1024 matrix (Over 1 million numbers!) The math gets too big, too fast.
Reversibility is key: Because all these matrices are Unitary, they are always reversible. In classical computing, if an AND gate outputs 0, we've lost the input information. In quantum computing, we never "lose" information until we measure.
But there is one operation that breaks all these rules. It’s irreversible, probabilistic, and collapses everything we've built. Next week, I’m going to tackle the most controversial concept in quantum mechanics: Measurement. See you then!

