Quantum Information Processing: Foundations - Part 3
Introduction
Having laid out some mathematical foundations in the [previous part][1], we will proceed to discuss quantum gates and circuits in depth here. As usual, we will drive home the theories with worked examples from [@Rieffel2011] and check their accuracy with qiskit and/or cirq code.
Prerequisite
Understanding quantum gates and circuits will be greatly aided by the knowledge of classical gates (AND, OR, NOT, XOR and the universal gates: NAND and NOR). Also, some familiarity with the Python programming language will help you understand qiskit and/or cirq code.
Classical & Quantum gates
A classical computer, possibly the one you're reading this with, is a sophisticated engineering piece, no doubt. However, the underlying "magic" comprises logic gates. The National Institute of Standards and Technology (NIST) gives this incredible analogical description of classical computers in relation to logic gates [@NISTQGATE2026]:
Traditional computers are like microscopic cities. The roads of these cities are wires with electricity coursing through them. These roads have lots of gates, known as logic gates, which enable computers to do their job. Like physical gates that allow or block cars, logic gates allow or block electricity. Electricity that goes through the gates represents a β1β of digital data, and blocked electricity is a β0.β When you pick up a motherboard, for instance, you may not see the said gates as they are made of tiny transistors (in modern systems, MOSFETs) in specific combinations.
Also, the $0$ and $1$ referred to in the analogy mean low and high voltage ranges, respectively. Their actual voltage values depend on the hardware.
:::note
All schematics were written in and rendered by @schemd/core . Check it out.
:::
Logic Gates refresher
Since we will be realizing some classical circuits using quantum gates, it's necessary to get familiar with common logic gates.
NOT ($\neg$) Gate
This gate takes a single classical bit and flips it. For instance, if $0$ is the input to this gate, $1$ will be seen in the output, vice versa. Just like a flip of a coin. Below, you find both the IEEE symbol of the gate and its truth table:
| in | out |
|---|---|
| 0 | 1 |
| 1 | 0 |
bounds="760x340" title="Classical NOT gate"
not:G1 "NOT" at (380, 170) #blue [standard=ieee]
AND ($\land$) Gate
Borrowing NIST's analogy again [@NISTQGATE2026]:
One kind of logic gate, known as the AND gate, could, for example, quickly determine whether two people agree to a business deal. It takes in two bits of information, and generates a 1 if both incoming bits are 1s. So, if both business people say βyesβ (1) to the deal, the AND gate will output 1. If one or both say βnoβ (0), the AND gate generates a 0 or a no.
From the analogy, the gate usually takes 2 bits (2 people who want to deal). It has the truth table and symbol shown below.
| $in_0$ | $in_1$ | $out$ |
|---|---|---|
| 0 | 0 | 0 |
| 1 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 1 | 1 |
bounds="760x340" title="Classical AND gate"
and:G1 "AND" at (380, 170) #amber
OR ($\lor$) Gate
This logic gate also takes 2 bits and functions based on the analogy that if two founders are deciding whether to launch a product, OR says βlaunch if at least one says yes.β Only when both say no does the result become no. Its symbol and truth table are as follows:
| $in_0$ | $in_1$ | $out$ |
|---|---|---|
| 0 | 0 | 0 |
| 1 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 1 | 1 |
bounds="760x340" title="Classical OR Gate"
or:G1 "OR" at (380, 170) #cyan
XOR ($\oplus$) Gate
Exclusive OR (XOR) gate is a core part of an adder circuit and, in algorithms, we use it for bitwise manipulation in problems including finding a number that does not have a duplicate in an array. For a 2-bit input, its output is $1$ if and only if the bits are of opposite values. Its truth table sheds more light on this:
| $in_0$ | $in_1$ | $out$ |
|---|---|---|
| 0 | 0 | 0 |
| 1 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 1 | 0 |
XOR gate's symbol is as follows:
bounds="760x340" title="Classical XOR gate"
xor:G1 "XOR" at (380, 170) #cyan
NAND Gate
NAND (Not AND) is one of the universal gates in digital circuits; the other is NOR (Not OR). It is universal because, with only this single gate, all other gates and circuits can be designed. Its behavior is simply as its name sounds: invert the output of an AND gate!
| $in_0$ | $in_1$ | $out$ |
|---|---|---|
| 0 | 0 | 1 |
| 1 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 1 | 0 |
NAND gate's symbol is as follows:
bounds="760x340" title="Classical NAND gate"
nand:G1 "NAND" at (380, 170) #cyan
NOR Gate
NOR does the same thing to an OR gate: it inverts its output. Therefore, it only returns $1$ when both inputs are $0$. Like NAND, it is universal.
| $in_0$ | $in_1$ | $out$ |
|---|---|---|
| 0 | 0 | 1 |
| 1 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 1 | 0 |
bounds="760x340" title="Classical NOR gate"
nor:G1 "NOR" at (380, 170) #cyan
Quantum Gates
Just as classical gates are the foundations of classical computers, quantum gates are those of quantum computers. They make it possible for quantum algorithms to run. The fundamental difference between them is that classical gates work on bits whose state is either $0$ or $1$ (and not both at the same time), whereas quantum gates operate on qubits where $0$ and $1$ can be superposed and even entangled (this will be discussed in the next part).
Quantum gates can either be single-qubit or multiple-qubit gates [@Gopalan2022]. As with almost anything in quantum computing, these gates can be mathematically expressed as matrices, and we will explore this heavily to understand how they work. One thing to keep in mind is that their matrices must be unitary. As discussed in the first part of this series, it means their inverses are the same as their Hermitian (conjugate transpose). It also means that the gate operations are reversible.
We will explore the X-, Y-, Z-, H-, S- and T-gates as examples of single-qubit gates. Though there are many multiple-qubit gates, we will only discuss the CNOT gate here. The reason is that the set of H-, CNOT, and T-gates is universal and can approximate any quantum computation to arbitrary precision [@MathWorksQGnd]. In simple terms, they can get as close as needed to any quantum operation.
X-Gate
This is the quantum equivalent of the classical NOT gate. In the quantum world, it is called the Pauli X-gate. Just like its classical counterpart, this gate flips its incoming qubit. If $\ket{0}$ is the input, $\ket{1}$ will be the output, vice versa.
Mathematically, this gate can be expressed, in matrix form, as:
$$
X= \begin{bmatrix}
0 & 1 \
1 & 0
\end{bmatrix}
$$
Now, let's look at the behaviour of this gate on a state, $\ket{\psi}$. If
$$
\ket{\psi} = \alpha\ket{0} + \beta\ket{1}
$$
Then, in matrix form,
$$
\ket{\psi} = \begin{bmatrix}\alpha \ \beta\end{bmatrix}
$$
Feeding this into the Pauli X-gate, we have:
$$
X\ket{\psi} = \begin{bmatrix}
0 & 1 \
1 & 0
\end{bmatrix}
\begin{bmatrix}\alpha \ \beta\end{bmatrix}
= \begin{bmatrix}
0\times\alpha+ 1\times\beta \
1\times\alpha+ 0\times\beta
\end{bmatrix}
= \begin{bmatrix}\beta \ \alpha\end{bmatrix}
= \beta\ket{0} + \alpha\ket{1}
$$
It got flipped!
bounds="760x340" title="Action of Pauli X on an arbitrary qubit"
port:A "β£Οβ©=Ξ±β£0β©+Ξ²β£1β©" at (164, 170) #cyan
qgate:XG "X" at (350, 170) #amber
port:B "Ξ²β£0β©+Ξ±β£1β©" at (550, 170) #cyan
A.out -> XG.in #blue [line]
XG.out -> B.in #blue [line]
Therefore, it can be demonstrated that if we feed $\ket{0}$ ($\begin{bmatrix}1 \ 0\end{bmatrix}$ in matrix form) into an X-gate, we will have:
$$
X\ket{0} = \begin{bmatrix}
0 & 1 \
1 & 0
\end{bmatrix}
\begin{bmatrix}1 \ 0\end{bmatrix}
= \begin{bmatrix}
0\times1+ 1\times0 \
1\times1+ 0\times0
\end{bmatrix}
= \begin{bmatrix}0 \ 1\end{bmatrix}
= \ket{1}
$$
bounds="760x340" title="Pauli X flips zero to one"
port:A "β£0β©" at (164, 170) #cyan
qgate:XG "X" at (350, 170) #amber
port:B "β£1β©" at (550, 170) #cyan
A.out -> XG.in #blue [line]
XG.out -> B.in #blue [line]
In the same vein, feeding $\ket{1}$ ($\begin{bmatrix}0 \ 1\end{bmatrix}$ in matrix form) into the gate gives:
$$
X\ket{1} = \begin{bmatrix}
0 & 1 \
1 & 0
\end{bmatrix}
\begin{bmatrix}0 \ 1\end{bmatrix}
= \begin{bmatrix}
0\times0+ 1\times1 \
1\times0+ 0\times1
\end{bmatrix}
= \begin{bmatrix}1 \ 0\end{bmatrix}
= \ket{0}
$$
The truth table can easily be built from here:
| Input | Output |
|---|---|
| $\ket{0}$ | $\ket{1}$ |
| $\ket{1}$ | $\ket{0}$ |
Y-Gate
The Pauli Y-gate also flips a qubit. However, unlike the X-gate, it adds a phase to the result. Its matrix is:
$$
Y = \begin{bmatrix}
0 & -i \
i & 0
\end{bmatrix}
$$
Let's feed the same arbitrary state, $\ket{\psi}$, into it:
$$
Y\ket{\psi} = \begin{bmatrix}
0 & -i \
i & 0
\end{bmatrix}
\begin{bmatrix}\alpha \ \beta\end{bmatrix}
= \begin{bmatrix}-i\beta \ i\alpha\end{bmatrix}
= -i\beta\ket{0} + i\alpha\ket{1}
$$
The amplitudes have been swapped, but they now carry the phases $-i$ and $i$.
From here, feeding $\ket{0}$ into the gate gives:
$$
Y\ket{0} = \begin{bmatrix}
0 & -i \
i & 0
\end{bmatrix}
\begin{bmatrix}1 \ 0\end{bmatrix}
= \begin{bmatrix}0 \ i\end{bmatrix}
= i\ket{1}
$$
In the same vein, feeding $\ket{1}$ into it gives:
$$
Y\ket{1} = \begin{bmatrix}
0 & -i \
i & 0
\end{bmatrix}
\begin{bmatrix}0 \ 1\end{bmatrix}
= \begin{bmatrix}-i \ 0\end{bmatrix}
= -i\ket{0}
$$
The truth table can be built from here:
| Input | Output |
|---|---|
| $\ket{0}$ | $i\ket{1}$ |
| $\ket{1}$ | $-i\ket{0}$ |
| $\alpha\ket{0}+\beta\ket{1}$ | $-i\beta\ket{0}+i\alpha\ket{1}$ |
bounds="760x340" title="Action of Pauli Y on an arbitrary qubit"
port:A "β£Οβ©=Ξ±β£0β©+Ξ²β£1β©" at (164, 170) #cyan
qgate:YG "Y" at (350, 170) #amber
port:B "-iΞ²β£0β©+iΞ±β£1β©" at (550, 170) #cyan
A.out -> YG.in #blue [line]
YG.out -> B.in #blue [line]
You may notice that $i\ket{1}$ and $-i\ket{0}$ still give the same measurement probabilities as $\ket{1}$ and $\ket{0}$, respectively, in the computational basis. This is because an overall phase does not affect the measurement probabilities. However, when the qubit is in a superposition, a phase on one part of the state matters. We will see this with the next gate.
Z-Gate
The Pauli Z-gate is also called the phase-flip gate. Unlike the X- and Y- gates, it does not swap the amplitudes. Instead, it changes the sign of the $\ket{1}$ amplitude. Its matrix is:
$$
Z = \begin{bmatrix}
1 & 0 \
0 & -1
\end{bmatrix}
$$
Feeding our arbitrary state into it, we have:
$$
Z\ket{\psi} = \begin{bmatrix}
1 & 0 \
0 & -1
\end{bmatrix}
\begin{bmatrix}\alpha \ \beta\end{bmatrix}
= \begin{bmatrix}\alpha \ -\beta\end{bmatrix}
= \alpha\ket{0} - \beta\ket{1}
$$
For the basis states:
$$
Z\ket{0}=\ket{0}, \qquad Z\ket{1}=-\ket{1}
$$
| Input | Output |
|---|---|
| $\ket{0}$ | $\ket{0}$ |
| $\ket{1}$ | $-\ket{1}$ |
| $\alpha\ket{0}+\beta\ket{1}$ | $\alpha\ket{0}-\beta\ket{1}$ |
You may ask: if $\ket{1}$ and $-\ket{1}$ produce the same measurement probability, what exactly changed? When $\ket{1}$ is by itself, the minus sign is a global phase and cannot be observed. However, in a superposition, it changes the relative phase between the amplitudes. For example:
$$
Z\left(\frac{\ket{0}+\ket{1}}{\sqrt{2}}\right) = \frac{\ket{0}-\ket{1}}{\sqrt{2}}
$$
Recall that $\frac{\ket{0}+\ket{1}}{\sqrt{2}}=\ket{+}$ and $\frac{\ket{0}-\ket{1}}{\sqrt{2}}=\ket{-}$. Therefore, $Z\ket{+}=\ket{-}$. Both states have a $50%$ probability of returning $0$ or $1$ when measured in the computational basis. They are, however, different states and behave differently when another gate, such as H, acts on them.
bounds="760x340" title="Pauli Z changes the relative phase"
port:A "β£+β©" at (164, 170) #cyan
qgate:ZG "Z" at (350, 170) #amber
port:B "β£-β©"
Comments
No comments yet. Start the discussion.