YouTube Courses - Learn Smarter

YouTube-Courses.site transforms YouTube videos and playlists into structured courses, making learning more efficient and organized.

Quantum Computing Fundamentals: A Comprehensive Introduction



This chapter provides a foundational understanding of quantum computing, starting from the basic mathematical concepts and progressing to quantum algorithms. It aims to explain the principles of quantum computation without relying on analogies, focusing on the actual mechanics of how quantum computers function.

1. Introduction to Quantum Computing

Quantum computing is a revolutionary field that harnesses the principles of quantum mechanics to process information.

Quantum mechanics: The branch of physics dealing with the behavior of matter and energy at the atomic and subatomic level. It describes phenomena that classical physics cannot explain, such as superposition and entanglement.

Unlike classical computers that store information as bits representing 0 or 1, quantum computers utilize qubits to achieve unprecedented computational speeds.

Qubit (Quantum bit): The basic unit of information in quantum computing. Unlike classical bits that are either 0 or 1, qubits can exist in a superposition of both states simultaneously.

This course will guide you through the core concepts of quantum computing, from fundamental mathematics to the workings of popular quantum algorithms, revealing why quantum computers hold the potential to transform technology.

1.1 Course Structure

This course is structured in four sections to provide a comprehensive learning experience:

  • Section 1: Essential Mathematics: This section lays the groundwork by introducing the necessary mathematical tools for understanding quantum computing. It covers:

    • Complex Numbers
    • Linear Algebra
  • Section 2: Quantum Bits (Qubits) and Single Qubit Operations: This section delves into the nature of qubits, their mathematical representation, and operations that can be performed on single qubits. Key topics include:

    • Mathematical representation of qubits.
    • Single qubit operations and their properties.
  • Section 3: Multiple Qubit Systems and Quantum Phenomena: Expanding on single qubits, this section explores the representation and manipulation of multiple qubits. It also introduces fundamental quantum phenomena:

    • Mathematical representation of multiple qubits.
    • Operations on multiple qubits.
    • Quantum Entanglement: A quantum mechanical phenomenon where the states of two or more particles become linked together in such a way that they are correlated, even when separated by a large distance.
    • Phase Kickback: A phenomenon in quantum computing where the phase of a target qubit can be transferred back to the control qubit in a controlled operation.
  • Section 4: Quantum Algorithms: This final section applies the knowledge gained in previous sections to analyze and understand quantum algorithms, demonstrating the revolutionary potential of quantum computers.

2. Essential Mathematics: Complex Numbers

Understanding complex numbers is crucial for grasping quantum computing, as they are fundamental to representing quantum states.

2.1 Imaginary Numbers

Before diving into complex numbers, let’s revisit the concept of square roots. For a simple equation like $x^2 = 4$, the solutions are $x = \pm 2$. However, consider $x^2 = -4$. In the realm of real numbers, there’s no solution because squaring any real number always results in a non-negative number. This is where imaginary numbers come into play.

We define the imaginary unit, denoted as $i$, as the square root of -1: $i = \sqrt{-1}$. Using this, we can express the square root of -4 as $\sqrt{-4} = \pm \sqrt{4 \times -1} = \pm \sqrt{4} \times \sqrt{-1} = \pm 2i$.

An imaginary number is any number that contains a factor of the imaginary unit, $i$.

2.2 Complex Numbers: Definition and Representation

Complex numbers extend the number system by including both a real part and an imaginary part.

Complex number: A number of the form $a + bi$, where $a$ and $b$ are real numbers, and $i$ is the imaginary unit ($\sqrt{-1}$).

A standard complex number is written in the form $a + bi$, where:

  • $a$ is the real part of the complex number.

    Real Part (of a complex number): The real number component ($a$) in a complex number expressed in the form $a + bi$.

  • $b$ is the imaginary part of the complex number.

    Imaginary Part (of a complex number): The real number coefficient ($b$) of the imaginary unit ($i$) in a complex number expressed in the form $a + bi$.

While complex numbers might initially seem abstract, they are indispensable for modeling quantum states, as we will see in subsequent sections.

2.3 Operations with Complex Numbers

2.3.1 Addition and Subtraction

Adding or subtracting complex numbers is straightforward: simply add or subtract the real parts and the imaginary parts separately.

For example, to add $(2 + 3i) + (1 - 2i)$:

$(2 + 3i) + (1 - 2i) = (2 + 1) + (3i - 2i) = 3 + i$

2.3.2 Multiplication

Multiplying complex numbers involves using the distributive property and remembering that $i^2 = -1$.

For example, to multiply $(2 + 3i) \times (1 - 2i)$:

$(2 + 3i) \times (1 - 2i) = 2(1) + 2(-2i) + 3i(1) + 3i(-2i) = 2 - 4i + 3i - 6i^2 = 2 - i - 6(-1) = 2 - i + 6 = 8 - i$

2.3.3 Complex Conjugate

The complex conjugate of a complex number is obtained by negating the imaginary part.

Complex Conjugate: For a complex number $z = a + bi$, its complex conjugate, denoted as $z^*$, is $a - bi$.

The complex conjugate of a complex number $z = a + bi$ is denoted as $z^$ or $\bar{z}$ and is defined as $z^ = a - bi$.

For example:

  • If $z = 2 + 3i$, then $z^* = 2 - 3i$.
  • If $z = -1 - i$, then $z^* = -1 + i$.

A notable property of complex conjugates is that multiplying a complex number by its complex conjugate always results in a real number. For example, $(2 + 3i)(2 - 3i) = 2^2 - (3i)^2 = 4 - 9i^2 = 4 - 9(-1) = 4 + 9 = 13$.

2.4 Geometric Representation: Complex Plane and Magnitude

We can visualize complex numbers as vectors on a complex plane, where the horizontal axis represents the real part and the vertical axis represents the imaginary part.

Complex Plane: A two-dimensional plane where the horizontal axis represents the real part and the vertical axis represents the imaginary part of complex numbers.

For example, the complex number $-2 + 3i$ can be represented as a vector ending at the point $(-2, 3)$ in the complex plane.

The magnitude of a complex number, denoted as $|z|$ or $|a + bi|$, is its distance from the origin in the complex plane. It is calculated using the Pythagorean theorem.

Magnitude (of a complex number): The distance of a complex number from the origin in the complex plane. For $z = a + bi$, the magnitude is $|z| = \sqrt{a^2 + b^2}$.

For a complex number $z = a + bi$, the magnitude is given by $|z| = \sqrt{a^2 + b^2}$.

For example, the magnitude of $4 - 3i$ is $|4 - 3i| = \sqrt{4^2 + (-3)^2} = \sqrt{16 + 9} = \sqrt{25} = 5$.

2.5 Polar and Exponential Forms

Besides representing complex numbers using real and imaginary parts ($a + bi$), we can also use polar form and exponential form.

Polar Form (of a complex number): Representing a complex number using its magnitude ($r$) and the angle ($\theta$) it makes with the positive real axis: $r(\cos \theta + i \sin \theta)$.

In polar form, a complex number is represented by its magnitude $r$ and the angle $\theta$ it makes with the positive real axis. The polar form is given by:

$z = r(\cos \theta + i \sin \theta)$

Where:

  • $r = |z| = \sqrt{a^2 + b^2}$ (magnitude)
  • $\theta = \arctan(\frac{b}{a})$ (angle or argument)

The angle $\theta$ can be found using the arctangent function: $\theta = \arctan(\frac{b}{a})$.

Exponential form provides a more compact way to represent complex numbers using Euler’s formula.

Exponential Form (of a complex number): Representing a complex number using its magnitude ($r$) and angle ($\theta$) in terms of the exponential function: $re^{i\theta}$.

Using Euler’s formula, $e^{i\theta} = \cos \theta + i \sin \theta$, the polar form can be written in exponential form as:

$z = re^{i\theta}$

For example, let’s convert $1 + i$ into polar and exponential forms:

  • Magnitude: $r = \sqrt{1^2 + 1^2} = \sqrt{2}$
  • Angle: $\theta = \arctan(\frac{1}{1}) = \arctan(1) = \frac{\pi}{4}$

Therefore:

  • Polar form: $\sqrt{2}(\cos(\frac{\pi}{4}) + i \sin(\frac{\pi}{4}))$
  • Exponential form: $\sqrt{2}e^{i\frac{\pi}{4}}$

In quantum computing, the exponential form is frequently used, especially when dealing with quantum states. A key property of exponential form is that multiplying complex numbers with a magnitude of 1 corresponds to rotating points on a unit circle, which is highly relevant in representing quantum states.

3. Essential Mathematics: Matrices

Matrices are two-dimensional arrays of numbers and are essential for representing and manipulating quantum operations.

Matrix: A rectangular array of numbers arranged in rows and columns.

3.1 Matrix Dimensions and Types

A matrix is described by its dimensions: $M \times N$, where $M$ is the number of rows and $N$ is the number of columns.

For example:

$\begin{pmatrix} 1 & 2 & 3 \ 4 & 5 & 6 \end{pmatrix}$

This is a $2 \times 3$ matrix (2 rows, 3 columns).

3.2 Matrix Operations

3.2.1 Addition and Subtraction

Matrices can be added or subtracted element-wise, but only if they have the same dimensions.

For example, to add two $2 \times 2$ matrices:

$\begin{pmatrix} 1 & 2 \ 3 & 4 \end{pmatrix} + \begin{pmatrix} 5 & 6 \ 7 & 8 \end{pmatrix} = \begin{pmatrix} 1+5 & 2+6 \ 3+7 & 4+8 \end{pmatrix} = \begin{pmatrix} 6 & 8 \ 10 & 12 \end{pmatrix}$

3.2.2 Scalar Multiplication

Multiplying a matrix by a scalar involves multiplying each element of the matrix by that scalar.

Scalar: A single number, as opposed to a vector or matrix.

For example, multiplying a $2 \times 2$ matrix by a scalar 2:

$2 \times \begin{pmatrix} 1 & 2 \ 3 & 4 \end{pmatrix} = \begin{pmatrix} 2 \times 1 & 2 \times 2 \ 2 \times 3 & 2 \times 4 \end{pmatrix} = \begin{pmatrix} 2 & 4 \ 6 & 8 \end{pmatrix}$

3.2.3 Matrix Multiplication

Matrix multiplication is a more complex operation. To multiply two matrices $A$ and $B$, the number of columns in $A$ must be equal to the number of rows in $B$. The resulting matrix $C = AB$ has dimensions (rows of $A$) $\times$ (columns of $B$).

The element $C_{ij}$ (element in the $i$-th row and $j$-th column of $C$) is calculated as the dot product of the $i$-th row of $A$ and the $j$-th column of $B$.

Dot Product: The sum of the products of corresponding elements in two sequences of numbers (usually vectors). For vectors $a = (a_1, a_2, …, a_n)$ and $b = (b_1, b_2, …, b_n)$, the dot product is $a \cdot b = a_1b_1 + a_2b_2 + … + a_nb_n$.

For example, to multiply a $2 \times 2$ matrix $A$ and a $2 \times 2$ matrix $B$:

$A = \begin{pmatrix} a & b \ c & d \end{pmatrix}$, $B = \begin{pmatrix} e & f \ g & h \end{pmatrix}$

$AB = \begin{pmatrix} ae+bg & af+bh \ ce+dg & cf+dh \end{pmatrix}$

3.2.4 Column Vectors

A column vector is a matrix with only one column (an $n \times 1$ matrix).

Column Vector: A matrix with only one column. It can be visualized as a vector in n-dimensional space.

Column vectors are often used to represent vectors in linear algebra and, crucially, quantum states in quantum computing.

Multiplying a matrix by a column vector results in another column vector. This is interpreted as transforming the original vector using the matrix. In quantum computing, matrices represent operations (quantum gates) applied to quantum states (represented as column vectors).

3.2.5 Identity Matrix

The identity matrix, denoted as $I$, is a square matrix with ones on the main diagonal and zeros elsewhere.

Identity Matrix: A square matrix where all elements on the main diagonal are 1, and all other elements are 0. When multiplied by any compatible matrix, it leaves the matrix unchanged.

For example, the $2 \times 2$ identity matrix is:

$I = \begin{pmatrix} 1 & 0 \ 0 & 1 \end{pmatrix}$

Multiplying any matrix by the identity matrix (where multiplication is defined) results in the original matrix.

3.2.6 Inverse Matrix

The inverse matrix of a square matrix $A$, denoted as $A^{-1}$, is a matrix such that when multiplied by $A$, it yields the identity matrix: $A A^{-1} = A^{-1} A = I$.

Inverse Matrix: For a square matrix $A$, its inverse matrix, denoted as $A^{-1}$, is such that $A A^{-1} = A^{-1} A = I$, where $I$ is the identity matrix. Not all matrices have an inverse.

Graphically, if a matrix $A$ transforms a vector, applying $A^{-1}$ undoes this transformation, returning the vector to its original position.

3.2.7 Complex Conjugate of a Matrix

The complex conjugate of a matrix is obtained by taking the complex conjugate of each element in the matrix.

Complex Conjugate (of a matrix): The matrix obtained by taking the complex conjugate of each element of the original matrix.

If $A = \begin{pmatrix} 1+i & 2 \ 3i & 4-i \end{pmatrix}$, then the complex conjugate $A^$ is $A^ = \begin{pmatrix} 1-i & 2 \ -3i & 4+i \end{pmatrix}$.

3.2.8 Transpose of a Matrix

The transpose of a matrix $A$, denoted as $A^T$, is obtained by swapping its rows and columns.

Transpose (of a matrix): The matrix obtained by interchanging the rows and columns of the original matrix. If $A$ is an $m \times n$ matrix, then $A^T$ is an $n \times m$ matrix.

If $A = \begin{pmatrix} 1 & 2 & 3 \ 4 & 5 & 6 \end{pmatrix}$, then the transpose $A^T$ is $A^T = \begin{pmatrix} 1 & 4 \ 2 & 5 \ 3 & 6 \end{pmatrix}$.

3.2.9 Conjugate Transpose (Dagger)

The conjugate transpose or dagger of a matrix $A$, denoted as $A^\dagger$, is obtained by taking the transpose of the complex conjugate of $A$ (or equivalently, the complex conjugate of the transpose).

Conjugate Transpose (Dagger): For a matrix $A$, its conjugate transpose, denoted as $A^\dagger$, is the transpose of its complex conjugate (or the complex conjugate of its transpose). For a matrix with real entries, the conjugate transpose is the same as the transpose.

$A^\dagger = (A^)^T = (A^T)^$

3.3 Unitary and Hermitian Matrices

In quantum computing, two special types of matrices are particularly important: unitary matrices and Hermitian matrices.

Unitary Matrix: A square matrix $U$ whose conjugate transpose is also its inverse, i.e., $U U^\dagger = U^\dagger U = I$, where $I$ is the identity matrix. Unitary matrices preserve the length (norm) of vectors when applied.

Unitary matrices ($U$) have the property that $U U^\dagger = I$. This means that the conjugate transpose of a unitary matrix is its inverse ($U^\dagger = U^{-1}$). Geometrically, unitary matrices represent transformations that preserve the length of vectors, essentially rotations and reflections. This property is crucial in quantum mechanics because it ensures that probabilities are conserved.

Hermitian Matrix: A square matrix $H$ that is equal to its own conjugate transpose, i.e., $H = H^\dagger$. Hermitian matrices have real eigenvalues and are important in quantum mechanics as they represent observable quantities.

Hermitian matrices (often mistakenly referred to as “Homan matrices” in the transcript, corrected to Hermitian) ($H$) are equal to their own conjugate transpose ($H = H^\dagger$). These matrices represent physical observables in quantum mechanics, and their eigenvalues are always real numbers.

3.4 Eigenvectors and Eigenvalues

An eigenvector of a square matrix $A$ is a non-zero vector $v$ such that when $A$ is multiplied by $v$, the result is a scalar multiple of $v$. The scalar factor is called the eigenvalue.

Eigenvector: A non-zero vector $v$ that, when multiplied by a matrix $A$, results in a scalar multiple of itself: $Av = \lambda v$. Eigenvalue: The scalar $\lambda$ in the equation $Av = \lambda v$, where $A$ is a matrix and $v$ is an eigenvector.

Mathematically, if $A$ is a matrix, $v$ is an eigenvector of $A$, and $\lambda$ is the corresponding eigenvalue, then:

$Av = \lambda v$

This means that applying the transformation represented by matrix $A$ to the eigenvector $v$ only scales $v$ by a factor of $\lambda$, without changing its direction.

For example, consider the matrix $A = \begin{pmatrix} 2 & 0 \ 1 & 2 \end{pmatrix}$ and vector $v = \begin{pmatrix} 0 \ 3 \end{pmatrix}$.

$Av = \begin{pmatrix} 2 & 0 \ 1 & 2 \end{pmatrix} \begin{pmatrix} 0 \ 3 \end{pmatrix} = \begin{pmatrix} 0 \ 6 \end{pmatrix} = 2 \begin{pmatrix} 0 \ 3 \end{pmatrix} = 2v$

Here, $v = \begin{pmatrix} 0 \ 3 \end{pmatrix}$ is an eigenvector of $A$, and $\lambda = 2$ is the corresponding eigenvalue.

4. Quantum Bits (Qubits) and Superposition

Classical computers operate using binary bits, which are either 0 or 1. Quantum computers, however, utilize qubits, which leverage quantum mechanics to represent and process information in a fundamentally different way.

4.1 Qubit Representation

Instead of being strictly 0 or 1, a qubit can exist in a superposition of both states.

Superposition: A fundamental principle of quantum mechanics where a quantum system can exist in multiple states simultaneously. For a qubit, this means it can be in a combination of the 0 and 1 states.

Physically, a qubit can be any quantum system with two distinct states, such as the polarization of a photon (horizontal or vertical). In quantum computing, these states are mathematically represented as column vectors using Dirac notation (or ket notation).

Dirac Notation (Ket Notation): A standard notation in quantum mechanics for representing quantum states. The state ‘ket 0’ is represented as $|0\rangle$ and ‘ket 1’ as $|1\rangle$.

  • The state $|0\rangle$ (representing classical 0) is represented as the column vector $\begin{pmatrix} 1 \ 0 \end{pmatrix}$.
  • The state $|1\rangle$ (representing classical 1) is represented as the column vector $\begin{pmatrix} 0 \ 1 \end{pmatrix}$.

A qubit in a superposition state $|\psi\rangle$ is represented as a linear combination of $|0\rangle$ and $|1\rangle$:

$|\psi\rangle = \alpha |0\rangle + \beta |1\rangle = \begin{pmatrix} \alpha \ \beta \end{pmatrix}$

Where:

  • $\alpha$ and $\beta$ are complex numbers called amplitudes.

    Amplitude (in quantum computing): Complex numbers ($\alpha$ and $\beta$) in the superposition state $|\psi\rangle = \alpha |0\rangle + \beta |1\rangle$ that determine the probability of measuring the qubit in the $|0\rangle$ or $|1\rangle$ state.

  • $|\alpha|^2$ represents the probability of measuring the qubit in the $|0\rangle$ state.

    Probability (in quantum measurement): The likelihood of obtaining a particular outcome when measuring a quantum state. For a qubit in state $|\psi\rangle = \alpha |0\rangle + \beta |1\rangle$, the probability of measuring $|0\rangle$ is $|\alpha|^2$ and the probability of measuring $|1\rangle$ is $|\beta|^2$.

  • $|\beta|^2$ represents the probability of measuring the qubit in the $|1\rangle$ state.

The probabilities must sum to 1, ensuring normalization: $|\alpha|^2 + |\beta|^2 = 1$.

4.2 Measurement of Qubits

When a qubit in superposition is measured, it collapses into one of the basis states ($|0\rangle$ or $|1\rangle$).

Collapse (of a quantum state): The process where a quantum system, upon measurement, transitions from a superposition of states to a single definite state.

The act of measurement changes the state of the qubit. We cannot directly measure the amplitudes $\alpha$ and $\beta$. Instead, measurement yields either 0 or 1, with probabilities determined by $|\alpha|^2$ and $|\beta|^2$ respectively. After measurement, the qubit is no longer in superposition; it is in the state that was measured.

For example, if a qubit is in the state $|\psi\rangle = \frac{\sqrt{3}}{2} |0\rangle + \frac{1}{2} |1\rangle$:

  • Probability of measuring 0: $|\frac{\sqrt{3}}{2}|^2 = \frac{3}{4} = 75%$
  • Probability of measuring 1: $|\frac{1}{2}|^2 = \frac{1}{4} = 25%$

If we measure this qubit and obtain 0, the qubit’s state immediately becomes $|0\rangle$. Subsequent measurements will always yield 0 until the qubit’s state is changed again through quantum operations.

4.3 Bloch Sphere Representation

The Bloch sphere is a geometric representation of a single qubit state.

Bloch Sphere: A geometrical representation of the state space of a qubit, using a unit sphere. Points on the surface of the sphere correspond to pure qubit states.

It provides a visual way to understand qubit states and transformations. In the Bloch sphere:

  • The north pole represents the $|0\rangle$ state.
  • The south pole represents the $|1\rangle$ state.
  • Points on the surface represent pure qubit states.

The position of a qubit on the Bloch sphere is determined by its amplitudes and phase.

Phase (in quantum computing): A complex factor in a quantum state that does not affect the measurement probabilities but is crucial for quantum interference and algorithms. In the Bloch sphere, phase corresponds to rotation around the Z-axis.

The closer a qubit is to the north pole, the higher the probability of measuring $|0\rangle$, and the closer to the south pole, the higher the probability of measuring $|1\rangle$. Rotation around the sphere represents changes in the qubit’s state.

5. Single Qubit Quantum Gates

Quantum gates are operations that manipulate the state of qubits, analogous to logic gates in classical computers.

Quantum Gate: A unitary operation that acts on qubits, changing their quantum state. Quantum gates are the building blocks of quantum circuits and algorithms.

Single qubit gates operate on individual qubits and are represented by unitary matrices. Common single qubit gates include the X, Y, and Z gates.

5.1 Pauli Gates: X, Y, and Z

The Pauli gates (X, Y, Z) are fundamental single-qubit gates.

Pauli Gates (X, Y, Z): A set of fundamental single-qubit quantum gates. They are represented by the Pauli matrices and correspond to rotations of the Bloch sphere around the X, Y, and Z axes by $\pi$ radians.

  • X Gate (Pauli-X): The X gate, also known as the NOT gate in quantum computing, flips the qubit state. It is represented by the matrix:

    X Gate (Pauli-X Gate): A single-qubit quantum gate that performs a bit-flip operation, analogous to the NOT gate in classical computing. It is represented by the Pauli-X matrix: $X = \begin{pmatrix} 0 & 1 \ 1 & 0 \end{pmatrix}$.

    $X = \begin{pmatrix} 0 & 1 \ 1 & 0 \end{pmatrix}$

    Applying the X gate to $|0\rangle$ results in $|1\rangle$, and applying it to $|1\rangle$ results in $|0\rangle$. On the Bloch sphere, it rotates the qubit state by $\pi$ radians around the X-axis.

  • Y Gate (Pauli-Y): The Y gate rotates the qubit state by $\pi$ radians around the Y-axis on the Bloch sphere. Its matrix representation is:

    Y Gate (Pauli-Y Gate): A single-qubit quantum gate that rotates the qubit state by $\pi$ radians around the Y-axis on the Bloch sphere. It is represented by the Pauli-Y matrix: $Y = \begin{pmatrix} 0 & -i \ i & 0 \end{pmatrix}$.

    $Y = \begin{pmatrix} 0 & -i \ i & 0 \end{pmatrix}$

  • Z Gate (Pauli-Z): The Z gate rotates the qubit state by $\pi$ radians around the Z-axis on the Bloch sphere. Its matrix representation is:

    Z Gate (Pauli-Z Gate): A single-qubit quantum gate that introduces a phase shift. It rotates the qubit state by $\pi$ radians around the Z-axis on the Bloch sphere and is represented by the Pauli-Z matrix: $Z = \begin{pmatrix} 1 & 0 \ 0 & -1 \end{pmatrix}$.

    $Z = \begin{pmatrix} 1 & 0 \ 0 & -1 \end{pmatrix}$

    Applying the Z gate to $|0\rangle$ leaves it unchanged, while applying it to $|1\rangle$ introduces a phase of -1.

These gates are involutory, meaning applying them twice returns the qubit to its original state (e.g., $XX = I$, $YY = I$, $ZZ = I$, where $I$ is the identity matrix). This also implies that these gates are their own inverses.

5.2 Applying Quantum Gates Mathematically

To apply a quantum gate to a qubit, we multiply the matrix representing the gate with the column vector representing the qubit state.

For example, applying the X gate to the $|0\rangle$ state:

$X|0\rangle = \begin{pmatrix} 0 & 1 \ 1 & 0 \end{pmatrix} \begin{pmatrix} 1 \ 0 \end{pmatrix} = \begin{pmatrix} 0 \times 1 + 1 \times 0 \ 1 \times 1 + 0 \times 0 \end{pmatrix} = \begin{pmatrix} 0 \ 1 \end{pmatrix} = |1\rangle$

In Dirac notation, applying a gate $U$ to a superposition state $|\psi\rangle = \alpha |0\rangle + \beta |1\rangle$ can be done by linearity:

$U|\psi\rangle = U(\alpha |0\rangle + \beta |1\rangle) = \alpha U|0\rangle + \beta U|1\rangle$

This means we can apply the gate to each basis state individually and then combine the results.

6. Phase and Phase Gates

Phase is a critical concept in quantum computing, particularly for harnessing quantum interference to achieve computational advantages.

6.1 Relative and Global Phase

Phase refers to the complex factor in the amplitudes of a qubit’s superposition state. There are two types of phase: global phase and relative phase.

Global Phase: A phase factor that is applied to the entire quantum state. It is physically irrelevant because it does not affect measurement probabilities or relative quantum interference. Relative Phase: A phase difference between the amplitudes of the basis states in a superposition. Relative phase is crucial for quantum interference and is manipulated by quantum gates to perform computations.

Global phase is when the entire qubit state is multiplied by a complex number, e.g., $e^{i\phi}(\alpha |0\rangle + \beta |1\rangle)$. Global phase is physically irrelevant because it does not affect measurement probabilities or relative interference effects. The states $e^{i\phi}(\alpha |0\rangle + \beta |1\rangle)$ and $(\alpha |0\rangle + \beta |1\rangle)$ are physically indistinguishable.

Relative phase, on the other hand, is crucial. It refers to the phase difference between the amplitudes of the $|0\rangle$ and $|1\rangle$ states. It is typically associated with the amplitude of the $|1\rangle$ state, represented as $|\psi\rangle = \alpha |0\rangle + e^{i\phi}\beta |1\rangle$. Relative phase affects quantum interference and is manipulated by quantum gates.

For an arbitrary qubit state $\gamma |0\rangle + \delta |1\rangle$, we can factor out the phase of the $|0\rangle$ amplitude ($\gamma$) to separate global and relative phase: $\gamma |0\rangle + \delta |1\rangle = \gamma (|0\rangle + \frac{\delta}{\gamma} |1\rangle)$. If $\gamma = |\gamma|e^{i\theta}$ and $\delta = |\delta|e^{i\phi}$, then $\frac{\delta}{\gamma} = \frac{|\delta|}{|\gamma|}e^{i(\phi-\theta)} = \frac{|\delta|}{|\gamma|}e^{i\varphi}$, where $\varphi = \phi - \theta$ is the relative phase. Thus, the state becomes $|\gamma|e^{i\theta} (|0\rangle + \frac{|\delta|}{|\gamma|}e^{i\varphi} |1\rangle)$. The term $e^{i\theta}$ is the global phase and $e^{i\varphi}$ is the relative phase. We can discard the global phase as it’s physically irrelevant, leaving us with a qubit state with only relative phase information.

6.2 S and T Gates

The S gate and T gate are phase gates that introduce specific relative phases.

S Gate: A single-qubit quantum gate that adds a relative phase of $\pi/2$ radians. Its matrix representation is $S = \begin{pmatrix} 1 & 0 \ 0 & i \end{pmatrix}$. T Gate: A single-qubit quantum gate that adds a relative phase of $\pi/4$ radians. Its matrix representation is $T = \begin{pmatrix} 1 & 0 \ 0 & e^{i\pi/4} \end{pmatrix}$.

  • S Gate: The S gate, also known as the phase gate, adds a relative phase of $\frac{\pi}{2}$ radians. Its matrix is:

    $S = \begin{pmatrix} 1 & 0 \ 0 & i \end{pmatrix}$

    Applying the S gate to $|0\rangle$ leaves it unchanged, while applying it to $|1\rangle$ multiplies it by $i = e^{i\pi/2}$.

  • T Gate: The T gate adds a relative phase of $\frac{\pi}{4}$ radians. Its matrix is:

    $T = \begin{pmatrix} 1 & 0 \ 0 & e^{i\pi/4} \end{pmatrix}$

    Applying the T gate to $|0\rangle$ leaves it unchanged, while applying it to $|1\rangle$ multiplies it by $e^{i\pi/4}$.

The conjugate transpose of the S gate, $S^\dagger$, adds a relative phase of $-\frac{\pi}{2}$. Similarly, $T^\dagger$ adds a relative phase of $-\frac{\pi}{4}$. These are their respective inverse gates.

7. Hadamard Gate and Equator States

The Hadamard gate (H gate) is a crucial single-qubit gate that creates superposition states.

Hadamard Gate (H Gate): A fundamental single-qubit quantum gate that creates superposition. It transforms the basis states $|0\rangle$ and $|1\rangle$ into superposition states. Its matrix representation is $H = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \ 1 & -1 \end{pmatrix}$.

The Hadamard gate is represented by the matrix:

$H = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \ 1 & -1 \end{pmatrix}$

Applying the Hadamard gate to the basis states:

  • $H|0\rangle = \frac{1}{\sqrt{2}} (|0\rangle + |1\rangle) = |+\rangle$
  • $H|1\rangle = \frac{1}{\sqrt{2}} (|0\rangle - |1\rangle) = |-\rangle$

Here, $|+\rangle$ and $|-\rangle$ are states on the equator of the Bloch sphere, representing superposition states with equal probability of measuring 0 or 1 but with different relative phases.

  • Plus State ($|+\rangle$): The state $\frac{1}{\sqrt{2}} (|0\rangle + |1\rangle)$, representing an equal superposition with a relative phase of +1.
  • Minus State ($|-\rangle$): The state $\frac{1}{\sqrt{2}} (|0\rangle - |1\rangle)$, representing an equal superposition with a relative phase of -1.
  • I State ($|i\rangle$): The state $\frac{1}{\sqrt{2}} (|0\rangle + i|1\rangle)$, representing an equal superposition with a relative phase of $i$.
  • Negative I State ($|-i\rangle$): The state $\frac{1}{\sqrt{2}} (|0\rangle - i|1\rangle)$, representing an equal superposition with a relative phase of $-i$.

The Hadamard gate is its own inverse ($HH = I$). Applying the Hadamard gate to $|+\rangle$ returns $|0\rangle$, and applying it to $|-\rangle$ returns $|1\rangle$. This demonstrates how the Hadamard gate and phase differences can be used to manipulate quantum states and differentiate states that initially have the same measurement probabilities.

8. Multi-Qubit Systems and Entanglement

Quantum computation’s power truly emerges when dealing with multiple qubits and phenomena like entanglement.

8.1 Representing Multi-Qubit States

Multiple qubit states are represented using the tensor product.

Tensor Product: A mathematical operation that combines vector spaces (and their elements) to create a larger vector space. In quantum computing, it is used to represent multi-qubit states and operations on them.

For example, if we have two qubits, each in the $|0\rangle$ state, the combined state is represented as $|0\rangle \otimes |0\rangle$, often written as $|00\rangle$.

$|00\rangle = |0\rangle \otimes |0\rangle = \begin{pmatrix} 1 \ 0 \end{pmatrix} \otimes \begin{pmatrix} 1 \ 0 \end{pmatrix} = \begin{pmatrix} 1 \times \begin{pmatrix} 1 \ 0 \end{pmatrix} \ 0 \times \begin{pmatrix} 1 \ 0 \end{pmatrix} \end{pmatrix} = \begin{pmatrix} 1 \ 0 \ 0 \ 0 \end{pmatrix}$

For two qubits, the basis states are $|00\rangle, |01\rangle, |10\rangle, |11\rangle$, which correspond to the column vectors:

$\begin{pmatrix} 1 \ 0 \ 0 \ 0 \end{pmatrix}, \begin{pmatrix} 0 \ 1 \ 0 \ 0 \end{pmatrix}, \begin{pmatrix} 0 \ 0 \ 1 \ 0 \end{pmatrix}, \begin{pmatrix} 0 \ 0 \ 0 \ 1 \end{pmatrix}$

A two-qubit state $|\Psi\rangle$ in superposition is a linear combination of these basis states:

$|\Psi\rangle = \alpha_{00} |00\rangle + \alpha_{01} |01\rangle + \alpha_{10} |10\rangle + \alpha_{11} |11\rangle$

Where $|\alpha_{00}|^2 + |\alpha_{01}|^2 + |\alpha_{10}|^2 + |\alpha_{11}|^2 = 1$.

For $n$ qubits, there are $2^n$ basis states. Measurement of a multi-qubit state yields one of these basis states with a probability determined by the square of the magnitude of its amplitude.

8.2 Quantum Circuits and Multi-Qubit Gates

Quantum circuits are diagrams that represent quantum algorithms.

Quantum Circuit: A diagrammatic representation of a quantum algorithm, showing qubits as horizontal lines and quantum gates as boxes acting on these lines, ordered from left to right in terms of operation sequence.

They consist of horizontal lines representing qubits and boxes representing quantum gates. Gates are applied in order from left to right.

Multi-qubit gates operate on two or more qubits. The most common multi-qubit gate is the CNOT (Controlled-NOT) gate.

CNOT Gate (Controlled-NOT Gate): A fundamental two-qubit quantum gate. It flips the state of the target qubit if the control qubit is in the $|1\rangle$ state, and does nothing if the control qubit is in the $|0\rangle$ state.

The CNOT gate acts on two qubits: a control qubit and a target qubit. It flips the target qubit if the control qubit is $|1\rangle$ and does nothing if the control qubit is $|0\rangle$.

Toffoli gate (or controlled-controlled-NOT gate) is a three-qubit gate, with two control qubits and one target qubit.

Toffoli Gate: A three-qubit quantum gate, also known as the controlled-controlled-NOT gate. It flips the state of the target qubit if both control qubits are in the $|1\rangle$ state, and does nothing otherwise. It is important for realizing classical reversible computations in quantum circuits.

Controlled versions of single-qubit gates also exist (e.g., controlled-Y, controlled-Z, controlled-Hadamard, controlled-S, controlled-T), applying the single-qubit gate to the target qubit only when the control qubit is $|1\rangle$.

8.3 Measurement of Multi-Qubit States and State Collapse

When measuring a single qubit in a multi-qubit system, we need to consider all superposition states where the qubit of interest is in the desired state. The probability of measuring a specific state for that qubit is the sum of the probabilities of all such superposition states.

If we measure a qubit in a multi-qubit state, the state collapses accordingly. For example, if we have a two-qubit state and measure the first qubit to be $|1\rangle$, all terms in the superposition where the first qubit is $|0\rangle$ are removed. The remaining state is then normalized so that the probabilities sum to 1 again.

Normalization Constant: A factor used to rescale a quantum state so that the sum of probabilities of all possible outcomes equals 1, after operations like measurement or projection have potentially altered the state’s normalization.

8.4 Quantum Entanglement

Entanglement is a unique quantum phenomenon where qubits become correlated in such a way that their states are interdependent, regardless of the distance separating them.

Bell states are a set of maximally entangled two-qubit states.

Bell States: A set of four maximally entangled two-qubit states, which are fundamental in quantum information theory and quantum computing. They are: $|\Phi^+\rangle = \frac{1}{\sqrt{2}}(|00\rangle + |11\rangle)$, $|\Phi^-\rangle = \frac{1}{\sqrt{2}}(|00\rangle - |11\rangle)$, $|\Psi^+\rangle = \frac{1}{\sqrt{2}}(|01\rangle + |10\rangle)$, and $|\Psi^-\rangle = \frac{1}{\sqrt{2}}(|01\rangle - |10\rangle)$.

Examples of Bell states include:

  • $|\Phi^+\rangle = \frac{1}{\sqrt{2}}(|00\rangle + |11\rangle)$
  • $|\Phi^-\rangle = \frac{1}{\sqrt{2}}(|00\rangle - |11\rangle)$
  • $|\Psi^+\rangle = \frac{1}{\sqrt{2}}(|01\rangle + |10\rangle)$
  • $|\Psi^-\rangle = \frac{1}{\sqrt{2}}(|01\rangle - |10\rangle)$

A state is entangled if it cannot be factored into the tensor product of single-qubit states.

Entangled State: A quantum state of two or more qubits that cannot be written as a tensor product of individual qubit states. In entangled states, the qubits are correlated in a way that classical systems cannot replicate. Maximally Entangled States: Entangled states where measuring one qubit completely determines the state of the other qubits. Bell states are examples of maximally entangled states for two qubits. Partially Entangled States: Entangled states where measuring one qubit affects the probabilities or phase of the other qubits, but does not completely determine their state.

Entangled states can be maximally entangled or partially entangled. Maximally entangled states exhibit perfect correlations, where measuring one qubit instantly reveals the state of the other. Partially entangled states show correlations, but the state of one qubit is not fully determined by measuring the other.

8.5 Phase Kickback

Phase kickback is a phenomenon in controlled quantum operations where the phase shift intended for the target qubit is “kicked back” to the control qubit. This occurs when the target qubit is in an eigenstate of the controlled operation.

Consider a controlled-$U$ gate with control qubit in state $|+\rangle = \frac{1}{\sqrt{2}}(|0\rangle + |1\rangle)$ and target qubit in an eigenstate $|v\rangle$ of $U$ with eigenvalue $e^{i\theta}$. When the controlled-$U$ gate is applied, the state evolves as follows:

$(|+\rangle \otimes |v\rangle) \xrightarrow{\text{Controlled-}U} \frac{1}{\sqrt{2}}(|0\rangle \otimes |v\rangle + |1\rangle \otimes U|v\rangle) = \frac{1}{\sqrt{2}}(|0\rangle \otimes |v\rangle + |1\rangle \otimes e^{i\theta}|v\rangle) = \frac{1}{\sqrt{2}}(|0\rangle + e^{i\theta}|1\rangle) \otimes |v\rangle$

The phase $e^{i\theta}$ is “kicked back” to the control qubit, while the target qubit $|v\rangle$ remains unchanged. This phenomenon is utilized in several quantum algorithms.

8.6 Superdense Coding

Superdense coding is a quantum communication protocol that leverages entanglement to send two bits of classical information using only one qubit.

Superdense Coding: A quantum communication protocol that allows the transmission of two classical bits of information by sending only one qubit, using pre-shared entanglement between the sender and receiver.

It requires prior entanglement between sender (Alice) and receiver (Bob). Alice and Bob start with an entangled pair of qubits, say $|\Phi^+\rangle = \frac{1}{\sqrt{2}}(|00\rangle + |11\rangle)$, with Alice taking the first qubit and Bob the second. To send two classical bits, Alice performs operations on her qubit based on the message:

  • To send “00”: Alice does nothing.
  • To send “01”: Alice applies an X gate.
  • To send “10”: Alice applies a Z gate.
  • To send “11”: Alice applies both X and Z gates.

After Alice sends her qubit to Bob, Bob applies a CNOT gate (control: Alice’s qubit, target: Bob’s qubit) followed by a Hadamard gate on Alice’s qubit. Measuring both qubits then reveals the two classical bits Alice intended to send.

9. Reversible Classical Gates and Quantum Functions

Quantum operations, except for measurement, must be reversible. This is because quantum gates are represented by unitary matrices, which are inherently reversible. To understand how to implement functions in quantum computers, we first examine reversible classical computation.

9.1 Classical Logic Gates and Reversibility

Classical computers use logic gates like AND, OR, NOT, and XOR to process information.

Logic Gates: Elementary building blocks of digital circuits that perform basic logical operations on binary inputs to produce a binary output. Common logic gates include AND, OR, NOT, XOR, NAND, NOR, and XNOR. AND Gate: A logic gate that outputs 1 (TRUE) if and only if all of its inputs are 1 (TRUE), otherwise it outputs 0 (FALSE). OR Gate: A logic gate that outputs 1 (TRUE) if at least one of its inputs is 1 (TRUE), otherwise it outputs 0 (FALSE). NOT Gate: A logic gate that takes a single input and outputs the inverse of that input. If the input is 0 (FALSE), the output is 1 (TRUE), and vice versa. XOR Gate (Exclusive OR Gate): A logic gate that outputs 1 (TRUE) if and only if its inputs are different (one is 0 and the other is 1), otherwise it outputs 0 (FALSE).

  • NOT Gate: Reversible.
  • AND, OR, XOR Gates: Irreversible in their basic two-input, one-output form.

A function is reversible if, given the output, we can uniquely determine the input.

Reversible Function: A function where each output has a unique input mapping. In the context of computation, a reversible operation allows for the reconstruction of the input from the output.

To make classical gates reversible, we often introduce an ancillary bit and compute the function output using XOR. For example, to make the OR gate reversible, we can define a reversible OR gate that takes inputs $x, c$ and outputs $x, c \oplus (x \text{ OR } y)$, where $\oplus$ is XOR and $y$ is another input bit (assumed to be fixed or part of the input register in a larger context). This ensures reversibility because knowing the outputs $x’$ and $y’ = c \oplus (x \text{ OR } y)$ allows us to uniquely determine the inputs $x=x’$ and $c = y’ \oplus (x’ \text{ OR } y)$.

9.2 Quantum Functions and Phase Oracles

In quantum computing, all operations (except measurement) must be unitary, and therefore reversible.

Unitary Operation (in Quantum Computing): A transformation represented by a unitary matrix that preserves the norm (length) of quantum state vectors. All quantum gates must be unitary to ensure the reversibility and consistency of quantum evolution.

A standard way to implement a classical function $f(x)$ on a quantum computer is through a quantum function $U_f$.

Quantum Function: A unitary operation $U_f$ that implements a classical function $f(x)$ in a quantum circuit. Typically, it maps the state $|x\rangle |y\rangle$ to $|x\rangle |y \oplus f(x)\rangle$, where $\oplus$ is bitwise XOR.

A typical quantum function $U_f$ acts on two registers: input register $|x\rangle$ and output register $|y\rangle$, transforming $|x\rangle |y\rangle$ to $|x\rangle |y \oplus f(x)\rangle$. To obtain the output $f(x)$, we initialize the output register to $|0\rangle$. Then $U_f|x\rangle |0\rangle = |x\rangle |f(x)\rangle$.

A phase oracle is a special type of quantum function that encodes function values in the phase of a quantum state.

Phase Oracle: A type of quantum function that encodes the value of a classical function $f(x)$ into the phase of a quantum state. Typically, it acts as $|x\rangle \rightarrow (-1)^{f(x)}|x\rangle$.

For a function $f$, a phase oracle $O_f$ acts as $|x\rangle \rightarrow (-1)^{f(x)}|x\rangle$. This can be achieved by using an ancilla qubit initialized in the $|-\rangle = \frac{1}{\sqrt{2}}(|0\rangle - |1\rangle)$ state. Applying $U_f$ to $|x\rangle |-\rangle$ yields:

$U_f|x\rangle |-\rangle = |x\rangle |f(x) \oplus -\rangle$

If $f(x) = 0$, $|f(x) \oplus -\rangle = |0 \oplus -\rangle = |-\rangle$. If $f(x) = 1$, $|f(x) \oplus -\rangle = |1 \oplus -\rangle = |+\rangle = -|-\rangle$. Thus,

$U_f|x\rangle |-\rangle = (-1)^{f(x)}|x\rangle |-\rangle$

Ignoring the ancilla qubit in state $|-\rangle$, the effective operation on the input register is $|x\rangle \rightarrow (-1)^{f(x)}|x\rangle$, which is a phase oracle.

9.3 No-Cloning Theorem

The no-cloning theorem is a fundamental principle in quantum mechanics stating that it is impossible to create an identical copy of an arbitrary unknown quantum state.

No-Cloning Theorem: A fundamental theorem in quantum mechanics that states it is impossible to create a perfect copy of an arbitrary unknown quantum state. This theorem has significant implications for quantum information and cryptography.

This theorem has profound implications for quantum information processing. Unlike classical bits, quantum states cannot be copied arbitrarily. If we don’t know the state of a qubit $|\psi\rangle = \alpha |0\rangle + \beta |1\rangle$ (i.e., we don’t know $\alpha$ and $\beta$), we cannot create another qubit in the same state without destroying the original. Measurement will collapse the state, preventing perfect copying.

10. Quantum Algorithms: Deutsch’s Algorithm

Quantum algorithms leverage quantum phenomena to solve computational problems more efficiently than classical algorithms for certain tasks. Deutsch’s algorithm is one of the earliest examples demonstrating quantum advantage.

Deutsch’s Algorithm: One of the first quantum algorithms to demonstrate a quantum advantage over classical algorithms, albeit for a highly specific and not practically useful problem. It determines whether a function $f: {0, 1} \rightarrow {0, 1}$ is constant or balanced using only one query to the function.

10.1 Problem Statement: Constant vs. Balanced Functions

Consider a function $f: {0, 1} \rightarrow {0, 1}$ that takes a single bit input and returns a single bit output. We want to determine if $f$ is constant or balanced.

Constant Function: A function that returns the same output for all possible inputs. For $f: {0, 1} \rightarrow {0, 1}$, there are two constant functions: one that always returns 0 and another that always returns 1. Balanced Function: A function that returns 0 for half of its inputs and 1 for the other half. For $f: {0, 1} \rightarrow {0, 1}$, there are two balanced functions: the identity function ($f(x) = x$) and the NOT function ($f(x) = 1 - x$).

  • Constant function: $f(0) = f(1)$. Examples: $f(x) = 0$ for all $x$, $f(x) = 1$ for all $x$.
  • Balanced function: $f(0) \neq f(1)$. Examples: $f(x) = x$, $f(x) = 1 - x$.

Classically, we need to evaluate $f(0)$ and $f(1)$ to determine if they are equal or not, requiring two queries to the function. Deutsch’s algorithm solves this problem with only one query using quantum computation.

10.2 Deutsch’s Algorithm Circuit and Steps

The quantum circuit for Deutsch’s algorithm is:

[Circuit diagram of Deutsch’s Algorithm - would be included in a visual textbook]

The algorithm steps are:

  1. Initialization: Start with two qubits in the state $|00\rangle$.
  2. Prepare Input Superposition: Apply a Hadamard gate to both qubits to create the state $|++\rangle = \frac{1}{2}(|00\rangle + |01\rangle + |10\rangle + |11\rangle)$. More specifically, initialize to $|0\rangle|-\rangle$. Apply Hadamard to both, resulting in $|+\rangle|-\rangle = \frac{1}{2}(|0\rangle + |1\rangle)(|0\rangle - |1\rangle) = \frac{1}{\sqrt{2}}(|0\rangle + |1\rangle) \otimes \frac{1}{\sqrt{2}}(|0\rangle - |1\rangle)$.
  3. Apply Quantum Function: Apply the quantum function $U_f$ (as a phase oracle) to the state.
  4. Apply Hadamard to Input Qubit: Apply a Hadamard gate to the first qubit.
  5. Measurement: Measure the first qubit in the computational basis.

Algorithm Analysis:

After applying Hadamard gates and the quantum function, and considering phase kickback, the state of the first qubit becomes:

  • If $f$ is constant: $\pm |0\rangle$
  • If $f$ is balanced: $\pm |1\rangle$

Measuring the first qubit:

  • If the result is 0, $f$ is constant.
  • If the result is 1, $f$ is balanced.

Deutsch’s algorithm demonstrates a quantum advantage by solving the constant vs. balanced problem with just one query, compared to two queries required classically.

11. Quantum Algorithms: Deutsch-Jozsa Algorithm

The Deutsch-Jozsa algorithm generalizes Deutsch’s algorithm to functions with multiple input bits.

Deutsch-Jozsa Algorithm: A generalization of Deutsch’s algorithm for functions $f: {0, 1}^n \rightarrow {0, 1}$. It determines if the function is constant or balanced (where balanced means it returns 1 for exactly half of the $2^n$ inputs) using only one query to the function, providing an exponential speedup over classical algorithms in the worst case.

11.1 Problem Statement: Constant vs. Balanced Functions (Generalized)

Consider a function $f: {0, 1}^n \rightarrow {0, 1}$ that takes an $n$-bit input string and returns a single bit output. We need to determine if $f$ is constant or balanced. In the Deutsch-Jozsa algorithm, “balanced” is defined more specifically: a function is balanced if it returns 1 for exactly half of the $2^n$ possible inputs and 0 for the other half.

Classically, in the worst case, we might need to query the function up to $2^{n-1} + 1$ times to determine if it’s constant or balanced. The Deutsch-Jozsa algorithm solves this with just one query using a quantum computer, offering an exponential speedup.

11.2 Deutsch-Jozsa Algorithm Circuit and Steps

The quantum circuit for the Deutsch-Jozsa algorithm is:

[Circuit diagram of Deutsch-Jozsa Algorithm - would be included in a visual textbook]

The algorithm steps are:

  1. Initialization: Start with $n$ qubits in the state $|0\rangle$ and one qubit in the state $|1\rangle$, resulting in the state $|0\rangle^{\otimes n}|1\rangle$.
  2. Prepare Output Qubit: Apply an X gate and then a Hadamard gate to the last qubit to transform it into $|-\rangle$. The state is now $|0\rangle^{\otimes n}|-\rangle$.
  3. Apply Hadamard Gates to Input Qubits: Apply a Hadamard gate to each of the $n$ qubits in the first register to create a uniform superposition. The state becomes $|+\rangle^{\otimes n}|-\rangle$.
  4. Apply Quantum Function: Apply the quantum function $U_f$ (as a phase oracle).
  5. Apply Hadamard Gates to Input Qubits Again: Apply a Hadamard gate to each of the $n$ qubits in the first register again.
  6. Measurement: Measure all $n$ qubits in the first register in the computational basis.

Algorithm Analysis:

After applying the circuit, if $f$ is constant, the measurement outcome will be $|0\rangle^{\otimes n}$ with probability 1. If $f$ is balanced, the measurement outcome will be different from $|0\rangle^{\otimes n}$ (i.e., at least one qubit will be measured as 1) with probability 1.

  • Measure $|0\rangle^{\otimes n}$: Function is constant.
  • Measure anything other than $|0\rangle^{\otimes n}$: Function is balanced.

The Deutsch-Jozsa algorithm provides an exponential speedup for this specific problem, demonstrating the potential power of quantum computation.

12. Quantum Algorithms: Bernstein-Vazirani Algorithm

The Bernstein-Vazirani algorithm is another early quantum algorithm that showcases quantum superiority by efficiently solving a specific problem.

Bernstein-Vazirani Algorithm: A quantum algorithm that efficiently finds a secret bit string $s$ given a function $f_s(x) = s \cdot x \pmod 2$, where $s \cdot x$ is the dot product of bit strings $s$ and $x$. It solves this problem with a single query to the function, while classical algorithms require $n$ queries in the worst case, where $n$ is the length of $s$.

12.1 Problem Statement: Finding a Secret Bit String

Given a function $f_s: {0, 1}^n \rightarrow {0, 1}$ defined as $f_s(x) = s \cdot x \pmod 2$, where $s$ is a secret $n$-bit string and $s \cdot x$ is the dot product of $s$ and $x$ modulo 2, the task is to find the secret string $s$.

Classically, to determine each bit of $s$, we need to make $n$ queries to $f_s$. For example, to find the $i$-th bit of $s$, we can query $f_s$ with an input string that is all zeros except for a 1 at the $i$-th position.

The Bernstein-Vazirani algorithm finds the entire string $s$ with just one quantum query.

12.2 Bernstein-Vazirani Algorithm Circuit and Steps

The quantum circuit for the Bernstein-Vazirani algorithm is structurally similar to the Deutsch-Jozsa algorithm:

[Circuit diagram of Bernstein-Vazirani Algorithm - would be included in a visual textbook - circuit is visually the same as Deutsch-Jozsa]

The algorithm steps are:

  1. Initialization: Start with $n$ qubits in the state $|0\rangle$ and one qubit in the state $|1\rangle$, resulting in the state $|0\rangle^{\otimes n}|1\rangle$.
  2. Prepare Output Qubit: Apply an X gate and then a Hadamard gate to the last qubit to transform it into $|-\rangle$. The state is now $|0\rangle^{\otimes n}|-\rangle$.
  3. Apply Hadamard Gates to Input Qubits: Apply a Hadamard gate to each of the $n$ qubits in the first register to create a uniform superposition: $|+\rangle^{\otimes n}|-\rangle$.
  4. Apply Quantum Function: Apply the quantum function $U_{f_s}$ (as a phase oracle) that implements $f_s(x) = s \cdot x \pmod 2$.
  5. Apply Hadamard Gates to Input Qubits Again: Apply a Hadamard gate to each of the $n$ qubits in the first register again.
  6. Measurement: Measure all $n$ qubits in the first register in the computational basis.

Algorithm Analysis:

After the quantum operations, measuring the first $n$ qubits directly yields the secret string $s$. The measurement outcome will be the binary representation of $s$ with probability 1.

The Bernstein-Vazirani algorithm efficiently finds the secret string $s$ in a single query, demonstrating a significant quantum speedup compared to the classical approach requiring $n$ queries.

13. Quantum Fourier Transform (QFT)

The Quantum Fourier Transform (QFT) is a quantum analogue of the classical Discrete Fourier Transform (DFT). It is a crucial subroutine in many quantum algorithms, including Shor’s algorithm.

Quantum Fourier Transform (QFT): A quantum algorithm that is the quantum analogue of the classical Discrete Fourier Transform (DFT). It efficiently transforms a quantum state from the computational basis to the Fourier basis and is a crucial component in many quantum algorithms like Shor’s algorithm and quantum phase estimation.

The QFT transforms a quantum state represented in the computational basis to its representation in the Fourier basis. It efficiently performs a transformation that would be computationally expensive classically.

13.1 QFT Circuit and Operation

The quantum circuit for the QFT on $n$ qubits involves Hadamard gates and controlled phase rotation gates. The controlled-R gate ($R_k$) introduces a phase shift.

Controlled-R Gate (Rk Gate): A two-qubit quantum gate used in the Quantum Fourier Transform. It applies a phase rotation of $e^{2\pi i / 2^k}$ to the target qubit if the control qubit is in the $|1\rangle$ state, and does nothing otherwise. The matrix for the controlled-$R_k$ gate with control on qubit $j$ and target on qubit $i$ (where $i < j$) is: $R_k = \begin{pmatrix} 1 & 0 & 0 & 0 \ 0 & 1 & 0 & 0 \ 0 & 0 & 1 & 0 \ 0 & 0 & 0 & e^{2\pi i / 2^k} \end{pmatrix}$

The QFT circuit uses Hadamard gates and controlled phase rotations $R_k$ with varying values of $k$. A swap gate is used at the end to reverse the order of the qubits to match the standard output order.

Swap Gate: A two-qubit quantum gate that swaps the states of two qubits. It is used in quantum circuits to reorder qubits.

13.2 Inverse Quantum Fourier Transform (IQFT)

The Inverse Quantum Fourier Transform (IQFT) reverses the operation of the QFT, transforming a state from the Fourier basis back to the computational basis.

Inverse Quantum Fourier Transform (IQFT): The inverse operation of the Quantum Fourier Transform (QFT). It transforms a quantum state from the Fourier basis back to the computational basis and is used to complete the Quantum Phase Estimation algorithm.

The IQFT circuit is similar to the QFT circuit but with the inverse phase rotation gates and in reverse order.

14. Quantum Phase Estimation (QPE)

Quantum Phase Estimation (QPE) is a quantum algorithm used to estimate the eigenvalue of a unitary operator. It is a core subroutine in many quantum algorithms, including Shor’s algorithm.

Quantum Phase Estimation (QPE): A quantum algorithm that estimates the phase $\theta$ of an eigenvalue $e^{2\pi i \theta}$ of a unitary operator $U$, given an eigenstate $|v\rangle$ of $U$. It is a crucial subroutine in many quantum algorithms, including Shor’s algorithm for factoring.

Given a unitary operator $U$ and its eigenstate $|v\rangle$ such that $U|v\rangle = e^{2\pi i \theta} |v\rangle$, QPE estimates the phase $\theta$.

14.1 QPE Circuit and Operation

The QPE circuit uses two registers:

  • First Register (Control Register): $m$ qubits initialized to $|0\rangle^{\otimes m}$. This register will store the estimated phase.
  • Second Register (Eigenstate Register): $n$ qubits initialized to the eigenstate $|v\rangle$.

[Circuit diagram of Quantum Phase Estimation - would be included in a visual textbook]

The algorithm steps are:

  1. Initialization: Prepare the state $|0\rangle^{\otimes m}|v\rangle$.
  2. Apply Hadamard Gates: Apply a Hadamard gate to each qubit in the first register to create a uniform superposition.
  3. Controlled-U Operations: Apply controlled-$U^{2^j}$ operations, where $j$ ranges from 0 to $m-1$. The $j$-th qubit in the first register controls $U^{2^j}$ applied to the second register.
  4. Inverse Quantum Fourier Transform (IQFT): Apply the IQFT to the first register.
  5. Measurement: Measure the first register in the computational basis.

Algorithm Analysis:

After these steps, measuring the first register yields an $m$-bit approximation of the phase $\theta$. If $\theta$ can be exactly represented with $m$ bits, the measurement will yield the exact phase. Otherwise, it provides the best $m$-bit approximation.

15. Quantum Algorithms: Shor’s Algorithm

Shor’s algorithm is a groundbreaking quantum algorithm that efficiently factors large numbers, a problem considered computationally intractable for classical computers. Its discovery has significant implications for cryptography, particularly for breaking RSA encryption.

Shor’s Algorithm: A quantum algorithm for integer factorization that provides an exponential speedup over the best-known classical algorithms. It is famous for its potential to break widely used public-key cryptography systems like RSA.

15.1 Problem Statement: Integer Factorization

Given a large composite number $N$, the task is to find its prime factors. For very large numbers, classical algorithms for factorization become exponentially slow. Shor’s algorithm solves this problem in polynomial time on a quantum computer.

15.2 Shor’s Algorithm Steps (Simplified)

Shor’s algorithm combines classical and quantum steps.

Classical Steps:

  1. Choose a Random Number $a$: Select a random integer $a$ such that $1 < a < N$ and $\text{gcd}(a, N) = 1$.
  2. Period Finding: Use the quantum part of Shor’s algorithm to find the period $r$ of the function $f(x) = a^x \pmod N$.
  3. Check for Even Period: If $r$ is odd, go back to step 1 and choose a different $a$.
  4. Compute Potential Factors: Calculate $\text{gcd}(a^{r/2} - 1, N)$ and $\text{gcd}(a^{r/2} + 1, N)$. These are potential factors of $N$.
  5. Verify Factors: Check if the potential factors are non-trivial factors of $N$. If successful, the factors are found. Otherwise, go back to step 1 and choose a different $a$.

Quantum Step (Period Finding):

The quantum part of Shor’s algorithm is efficient period finding, which utilizes QPE. The steps are:

  1. Prepare Input State: Initialize two registers:
    • First register: $m$ qubits in $|0\rangle^{\otimes m}$ (where $m$ is chosen to be large enough for desired precision).
    • Second register: $n$ qubits in $|0\rangle^{\otimes n}$ (large enough to represent numbers up to $N$).
  2. Create Superposition: Apply Hadamard gates to all qubits in the first register to create a uniform superposition.
  3. Apply Modular Exponentiation: Implement a controlled unitary operator $U_a$ that performs modular exponentiation: $|x\rangle |y\rangle \rightarrow |x\rangle |(y \cdot a^x) \pmod N\rangle$. For period finding, we effectively apply $U_a^j$ controlled by the $j$-th qubit of the first register.
  4. Quantum Phase Estimation: Apply QPE using $U_a$ and the eigenstate (related to periodicity) to estimate the phase. The estimated phase is related to the period $r$.
  5. Inverse QFT and Measurement: Apply IQFT to the first register and measure it. The measurement outcome provides an estimate of $\frac{s}{r}$ for some integer $s$.

Classical Post-Processing:

After QPE, we obtain an approximation of $\frac{s}{r}$. Use continued fractions to find a rational approximation $\frac{s’}{r’}$ for the measured value.

Continued Fractions: A representation of a real number as a fraction of the form $a_0 + \frac{1}{a_1 + \frac{1}{a_2 + \frac{1}{\ddots}}}$, where $a_i$ are integers. Continued fractions provide optimal rational approximations for real numbers.

From the continued fraction approximation, extract a candidate period $r’$. Check if $r’$ is the correct period. If so, proceed with the classical steps to find factors. If not, repeat the quantum period finding step.

Shor’s algorithm demonstrates the power of combining quantum computation for period finding with classical number theory to solve a problem of major practical importance, such as breaking RSA encryption. However, building a fault-tolerant quantum computer capable of running Shor’s algorithm for cryptographically relevant numbers remains a significant technological challenge.