Lecture Notes on Quantum Algorithms

Author

Your Name

Published

February 5, 2025

Introduction

In this lecture, we will explore key quantum algorithms that demonstrate the potential of quantum computation. We begin by revisiting the Discrete Fourier Transform (DFT), a fundamental mathematical tool with applications across various fields. We will then introduce its quantum counterpart, the Quantum Fourier Transform (QFT), highlighting its efficiency and relevance in quantum algorithms.

Building on the QFT, we will discuss Quantum Phase Estimation, a core subroutine for estimating eigenvalues of unitary operators. This algorithm is crucial for many quantum algorithms, including Shor’s algorithm.

Next, we will examine Shor’s Algorithm, a landmark quantum algorithm for integer factorization. Shor’s algorithm has profound implications for cryptography as it offers an exponential speedup over the best-known classical algorithms for factorization. We will discuss its underlying principles and complexity.

Finally, we will introduce Grover’s Algorithm, a quantum search algorithm that provides a quadratic speedup for searching unstructured databases. We will explore the concept of amplitude amplification and the probabilistic nature of Grover’s algorithm.

This lecture aims to provide a concise overview of these essential quantum algorithms, emphasizing their key ideas, computational advantages, and implications.

Discrete Fourier Transform

Definition and Basis Transformation

The Discrete Fourier Transform (DFT) is a linear transformation that maps a vector from the time domain to the frequency domain. For a vector space of dimension \(N\), the DFT acts on the basis elements \(\{\ensuremath{\left|{j}\right\rangle}\}_{j=0}^{N-1}\) as: \[\ensuremath{\left|{j}\right\rangle} \xrightarrow{DFT} \frac{1}{\sqrt{N}} \sum_{k=0}^{N-1} e^{\frac{2\pi i j k}{N}} \ensuremath{\left|{k}\right\rangle}. \label{eq:dft_basis_transform}\] Here, \(\ensuremath{\left|{j}\right\rangle}\) is the \(j\)-th basis element, and its DFT is a superposition of all basis elements \(\ensuremath{\left|{k}\right\rangle}\) with complex coefficients. The coefficient of \(\ensuremath{\left|{k}\right\rangle}\) in the transformed state of \(\ensuremath{\left|{j}\right\rangle}\) is given by \(\frac{1}{\sqrt{N}} e^{\frac{2\pi i j k}{N}}\). The factor \(\frac{1}{\sqrt{N}}\) ensures that the transformation is unitary.

By linearity, the DFT can be extended to a general vector \(\ensuremath{\left|{x}\right\rangle} = \sum_{j=0}^{N-1} x_j \ensuremath{\left|{j}\right\rangle}\). The transformed vector \(\ensuremath{\left|{y}\right\rangle} = DFT\ensuremath{\left|{x}\right\rangle} = \sum_{k=0}^{N-1} y_k \ensuremath{\left|{k}\right\rangle}\) has components \(y_k\) given by: \[y_k = \frac{1}{\sqrt{N}} \sum_{j=0}^{N-1} e^{\frac{2\pi i j k}{N}} x_j. \label{eq:dft_generic_vector}\]

Unitarity

The DFT is a unitary transformation, a crucial property for quantum operations as it ensures norm preservation and reversibility. A transformation \(U\) is unitary if \(U^\dagger U = I\), where \(U^\dagger\) is the conjugate transpose of \(U\) and \(I\) is the identity operator. For the DFT, this means the DFT matrix \(U_{DFT}\) satisfies \(U_{DFT}^\dagger U_{DFT} = I\). This unitarity is equivalent to the orthonormality of the columns (and rows) of the DFT matrix.

Quantum Circuit Complexity

The quantum implementation of the DFT is known as the Quantum Fourier Transform (QFT). The QFT has a significantly lower circuit complexity compared to classical algorithms for the DFT.

The quantum circuit for the QFT on \(n\) qubits (corresponding to dimension \(N=2^n\)) has a size of \(O(n^2)\) gates. This is quadratic in the number of qubits, or \(O((\log N)^2)\) in terms of the dimension \(N\).

In contrast, the classical Fast Fourier Transform (FFT) algorithm, the most efficient classical algorithm for DFT, has a complexity of \(O(N \log N)\). Therefore, the QFT provides an exponential speedup in terms of circuit complexity compared to the FFT when considering the dimension \(N\) in terms of the number of qubits \(n\) (\(N=2^n\)). This quantum advantage is a key motivation for using the QFT in quantum algorithms.

Matrix Representation and Roots of Unity

The DFT can be represented by a unitary matrix \(U_{DFT}\). The entry in the \(j\)-th row and \(k\)-th column of \(U_{DFT}\) (with indices starting from 0) is given by: \[[U_{DFT}]_{jk} = \frac{1}{\sqrt{N}} e^{\frac{2\pi i j k}{N}} = \frac{1}{\sqrt{N}} \omega_N^{jk}, \label{eq:dft_matrix_element}\] where \(\omega_N = e^{\frac{2\pi i}{N}}\) is the \(N\)-th principal root of unity. The \(N\)-th roots of unity are complex numbers that, when raised to the power of \(N\), equal 1. Geometrically, they are equally spaced points on the unit circle in the complex plane. The term \(e^{\frac{2\pi i j k}{N}}\) samples these roots of unity, and their arrangement in the DFT matrix determines the transformation’s properties.

Example: DFT for N=4

Consider the DFT for \(N=4\). The \(4\)-th roots of unity are \(\omega_4^k = e^{\frac{2\pi i k}{4}}\) for \(k = 0, 1, 2, 3\), which are \(1, i, -1, -i\) respectively. The DFT matrix \(U_{DFT}^{(4)}\) is: \[U_{DFT}^{(4)} = \frac{1}{\sqrt{4}} \begin{pmatrix} \omega_4^{0\cdot 0} & \omega_4^{0\cdot 1} & \omega_4^{0\cdot 2} & \omega_4^{0\cdot 3} \\ \omega_4^{1\cdot 0} & \omega_4^{1\cdot 1} & \omega_4^{1\cdot 2} & \omega_4^{1\cdot 3} \\ \omega_4^{2\cdot 0} & \omega_4^{2\cdot 1} & \omega_4^{2\cdot 2} & \omega_4^{2\cdot 3} \\ \omega_4^{3\cdot 0} & \omega_4^{3\cdot 1} & \omega_4^{3\cdot 2} & \omega_4^{3\cdot 3} \end{pmatrix} = \frac{1}{2} \begin{pmatrix} 1 & 1 & 1 & 1 \\ 1 & i & -1 & -i \\ 1 & -1 & 1 & -1 \\ 1 & -i & -1 & i \end{pmatrix}. \label{eq:dft_matrix_n4}\] Analyzing the columns of \(U_{DFT}^{(4)}\):

  • Column 0 (\(k=0\)): All entries are \(1 = \omega_4^0\).

  • Column 1 (\(k=1\)): Entries are \(1, \omega_4^1 = i, \omega_4^2 = -1, \omega_4^3 = -i\). Each entry is obtained by multiplying the previous entry by \(\omega_4^1 = e^{2\pi i / 4} = i\), representing a rotation by an angle of \(\frac{2\pi}{4} = \frac{\pi}{2}\) in the complex plane.

  • Column 2 (\(k=2\)): Entries are \(1, \omega_4^2 = -1, \omega_4^4 = 1, \omega_4^6 = -1\). Each entry is obtained by multiplying the previous entry by \(\omega_4^2 = e^{2\pi i \cdot 2 / 4} = -1\), representing a rotation by an angle of \(2 \cdot \frac{\pi}{2} = \pi\).

  • Column 3 (\(k=3\)): Entries are \(1, \omega_4^3 = -i, \omega_4^6 = -1, \omega_4^9 = i\). Each entry is obtained by multiplying the previous entry by \(\omega_4^3 = e^{2\pi i \cdot 3 / 4} = -i\), representing a rotation by an angle of \(3 \cdot \frac{\pi}{2} = \frac{3\pi}{2}\).

This example illustrates the structure of the DFT matrix in terms of roots of unity and their geometric interpretation as rotations in the complex plane.

To confirm unitarity, we can verify the orthonormality of the columns. For instance, the inner product of column 0 and column 1 is: \[\frac{1}{4} (1\cdot 1^* + 1\cdot i^* + 1\cdot (-1)^* + 1\cdot (-i)^*) = \frac{1}{4} (1 - i - 1 + i) = 0.\] Similarly, one can verify that all pairs of distinct columns are orthogonal and that each column is normalized, thus confirming the unitarity of \(U_{DFT}^{(4)}\).

Quantum Phase Estimation

Phase Kickback and Eigenvalue Estimation

Quantum Phase Estimation is a crucial quantum algorithm designed to estimate the eigenvalue of a unitary operator \(U\), given access to its eigenvector \(\ensuremath{\left|{v}\right\rangle}\). If \(\ensuremath{\left|{v}\right\rangle}\) is an eigenvector of \(U\) corresponding to an eigenvalue \(e^{2\pi i \phi}\), such that \(U\ensuremath{\left|{v}\right\rangle} = e^{2\pi i \phi} \ensuremath{\left|{v}\right\rangle}\), the algorithm estimates the phase \(\phi\). This phase is encoded in the eigenvalue and is the target of the estimation process.

The algorithm leverages the principle of phase kickback. When a controlled-\(U\) gate is applied to a control qubit and a target qubit initialized to an eigenvector \(\ensuremath{\left|{v}\right\rangle}\) of \(U\), the eigenvalue phase is transferred to the control qubit. Specifically, if the control qubit is in the state \(\frac{1}{\sqrt{2}}(\ensuremath{\left|{0}\right\rangle} + \ensuremath{\left|{1}\right\rangle})\) and the target qubit is in state \(\ensuremath{\left|{v}\right\rangle}\), applying a controlled-\(U\) gate results in the phase \(e^{2\pi i \phi}\) being ‘kicked back’ onto the control qubit, transforming its state to \(\frac{1}{\sqrt{2}}(\ensuremath{\left|{0}\right\rangle} + e^{2\pi i \phi} \ensuremath{\left|{1}\right\rangle})\).

To enhance the precision of phase estimation, we utilize repeated applications of \(U\). Applying \(U^{2^j}\), controlled by a qubit initially in state \(\ensuremath{\left|{0}\right\rangle}\), to the eigenvector \(\ensuremath{\left|{v}\right\rangle}\) results in the control qubit state becoming: \[\frac{1}{\sqrt{2}} (\ensuremath{\left|{0}\right\rangle} + e^{2\pi i 2^j \phi} \ensuremath{\left|{1}\right\rangle}). \label{eq:phase_kickback_repeated}\] By performing this operation for a sequence of \(j\) values (e.g., \(j=0, 1, 2, \dots, t-1\)) and subsequently employing the inverse Quantum Fourier Transform, we can extract an accurate estimate of the phase \(\phi\).

Quantum Circuit for Phase Estimation

The quantum circuit for phase estimation employs two registers:

  • Control Register: This register consists of \(t\) qubits, initialized to the state \(\ensuremath{\left|{0}\right\rangle}^{\otimes t}\). The number of qubits \(t\) determines the precision of the phase estimation. This register will ultimately hold the estimated phase value.

  • Eigenvector Register: This register holds the eigenvector \(\ensuremath{\left|{v}\right\rangle}\) of the unitary operator \(U\). It remains unchanged throughout the phase estimation process, except for being acted upon by controlled-\(U^{2^j}\) operations.

The quantum phase estimation circuit proceeds through the following steps:

  1. Initialization of Control Register: Apply Hadamard gates to each qubit in the control register to create a uniform superposition: \[\ensuremath{\left|{0}\right\rangle}^{\otimes t} \xrightarrow{H^{\otimes t}} \frac{1}{\sqrt{2^t}} (\ensuremath{\left|{0}\right\rangle} + \ensuremath{\left|{1}\right\rangle})^{\otimes t}. \label{eq:phase_estimation_hadamard}\]

  2. Controlled Unitary Operations: Sequentially apply controlled-\(U^{2^j}\) gates for \(j = 0, 1, \dots, t-1\). For each \(j\), use the \((j+1)\)-th qubit of the control register (starting from the least significant bit as the first qubit) as the control qubit and the eigenvector register as the target. This means applying controlled-\(U^{2^0}\), controlled-\(U^{2^1}\), ..., controlled-\(U^{2^{t-1}}\) operations, each controlled by a different qubit of the control register.

  3. Inverse Quantum Fourier Transform: Apply the inverse Quantum Fourier Transform (\(QFT^\dagger\)) to the control register. This step transforms the phase information encoded in the control register into a readable format in the computational basis.

  4. Measurement: Measure the control register in the computational basis. The measurement outcome, when read as a binary string, provides an estimate of the phase \(\phi\). If the measurement result is \(m = m_1 m_2 \dots m_t\), the estimated phase is \(\tilde{\phi} = 0.m_1 m_2 \dots m_t = \sum_{i=1}^{t} \frac{m_i}{2^i}\).

Role of the Inverse Quantum Fourier Transform

The inverse Quantum Fourier Transform (\(QFT^\dagger\)) is essential in the phase estimation algorithm. After the application of controlled-\(U^{2^j}\) operations, the control register’s state encodes the phase \(\phi\) in a Fourier basis. The \(QFT^\dagger\) effectively converts this representation from the Fourier basis back to the computational basis. This transformation allows us to extract the phase information through measurement in the computational basis.

The measurement outcome from the control register provides a binary fraction approximation of the phase \(\phi\). The accuracy of this approximation is determined by the number of qubits \(t\) in the control register. Increasing \(t\) improves the precision of the estimated phase. The algorithm provides a probabilistic estimate, and the probability of obtaining a good approximation of \(\phi\) increases with \(t\).

Shor’s Algorithm for Factorization

Relation to Quantum Phase Estimation

Shor’s Algorithm is a quantum algorithm designed to factorize large composite integers efficiently. A core component of Shor’s algorithm is the Quantum Phase Estimation algorithm. Shor’s algorithm reduces the problem of factorization to the problem of finding the order of an element modulo \(N\). Quantum Phase Estimation is then used to solve this order-finding problem exponentially faster than known classical algorithms.

The Order Finding Problem

The central quantum subroutine in Shor’s algorithm solves the order finding problem. Given an integer \(N\) and an integer \(x\) coprime to \(N\), the order of \(x\) modulo \(N\) is the smallest positive integer \(r\) such that \(x^r \equiv 1 \pmod{N}\). Finding this order \(r\) is classically believed to be computationally hard. Shor’s algorithm provides an efficient quantum solution to this problem.

The order finding problem is related to finding the period of the function \(f(a) = x^a \pmod{N}\). The sequence \(x^a \pmod{N}\) is periodic, and its period is the order \(r\). The set of elements \(\{x^a \pmod{N} \mid a \in \mathbb{Z}\}\) forms a cyclic subgroup of the multiplicative group of integers modulo \(N\).

Classical Pre-processing

Before invoking the quantum order-finding subroutine, Shor’s algorithm includes classical pre-processing steps to simplify the factorization task:

  1. Check for Evenness: If \(N\) is even, then 2 is a factor. Divide \(N\) by 2 and proceed to factorize the quotient.

  2. Check for Perfect Powers: Determine if \(N\) is of the form \(a^b\) for integers \(a > 1\) and \(b \ge 2\). If so, compute the integer \(a = N^{1/b}\) (e.g., by binary search for integer roots) and recursively factorize \(a\). This check can be done efficiently classically.

  3. Compute \(\gcd(x, N)\) for Random \(x\): Choose a random integer \(x\) such that \(1 < x < N\). Compute \(\gcd(x, N)\) using the Euclidean algorithm. If \(\gcd(x, N) > 1\), then a factor has been found. If \(\gcd(x, N) = 1\), then \(x\) is coprime to \(N\), and we can proceed to the quantum order-finding step. If we are unlucky and choose \(x\) such that \(\gcd(x,N) = N\), we should choose another random \(x\).

If these classical steps do not yield a factorization, we proceed to the quantum order-finding phase.

Quantum Order Finding using Phase Estimation

The quantum part of Shor’s algorithm efficiently finds the order \(r\) using Quantum Phase Estimation. The steps are as follows:

  1. Construct the Unitary Operator: Define a unitary operator \(U_x\) that performs multiplication by \(x\) modulo \(N\). For a computational basis state \(\ensuremath{\left|{a}\right\rangle}\) where \(0 \le a < N\), define \(U_x \ensuremath{\left|{a}\right\rangle} = \ensuremath{\left|{xa \pmod{N}}\right\rangle}\). This operation can be implemented efficiently using modular exponentiation circuits.

  2. Prepare Input State for Phase Estimation: We need an eigenstate of \(U_x\) to apply phase estimation. While we may not know an eigenstate explicitly, starting with a superposition and applying phase estimation will probabilistically yield the desired phase related to the order. A suitable initial state for the eigenvector register in phase estimation can be \(\ensuremath{\left|{1}\right\rangle}\).

  3. Apply Quantum Phase Estimation: Apply the Quantum Phase Estimation algorithm to the operator \(U_x\) with the initial state \(\ensuremath{\left|{1}\right\rangle}\). The phase estimation algorithm will estimate the phase \(\phi\) in the eigenvalue \(e^{2\pi i \phi}\) of \(U_x\) corresponding to some eigenstate that has overlap with the initial state \(\ensuremath{\left|{1}\right\rangle}\). The eigenvalues of \(U_x\) are of the form \(e^{2\pi i s/r}\) for \(s = 0, 1, \dots, r-1\), where \(r\) is the order of \(x\) modulo \(N\). Thus, the estimated phase \(\phi\) will be approximately \(\frac{s}{r}\) for some integer \(s\).

  4. Extract Order from Phase Estimate using Continued Fractions: The measurement from phase estimation gives an approximation \(\tilde{\phi}\) of \(\phi = \frac{s}{r}\). Use the method of continued fractions to find a rational approximation \(\frac{s'}{r'}\) of \(\tilde{\phi}\) with a small denominator \(r'\). With high probability, \(r'\) will be the order \(r\), or a divisor of \(r\).

  5. Verify the Order: Check if \(x^{r'} \equiv 1 \pmod{N}\). If it is, then \(r'\) is the order \(r\). If not, or if the continued fraction approximation fails, repeat the quantum order finding process.

Post-processing to Find Factors

Once the order \(r\) of \(x\) modulo \(N\) is found, we can use it to find factors of \(N\).

  1. Check if Order is Even: If the order \(r\) is even, compute \(x^{r/2} \pmod{N}\).

  2. Compute Potential Factors: Calculate \(\gcd(x^{r/2} - 1, N)\) and \(\gcd(x^{r/2} + 1, N)\). These have a good probability of being non-trivial factors of \(N\).

  3. Check for Trivial Factors: If either \(\gcd(x^{r/2} - 1, N)\) or \(\gcd(x^{r/2} + 1, N)\) is a non-trivial factor (not 1 or \(N\)), we have successfully factorized \(N\).

  4. Handle Odd Order or Failure: If the order \(r\) is odd, or if the GCD computations do not yield non-trivial factors, we must restart the entire algorithm by choosing a different random \(x\).

Probabilistic Nature and BQP Complexity

Shor’s algorithm is a probabilistic algorithm because:

  • The choice of \(x\) is random. A ‘bad’ choice of \(x\) might lead to failure.

  • Quantum Phase Estimation is probabilistic and provides an approximation of the phase.

  • The continued fraction step might not always yield the correct order.

  • Even with the correct order, the post-processing might not directly give factors in every attempt, especially if the order is odd.

Despite its probabilistic nature, Shor’s algorithm is highly efficient and falls into the complexity class BQP (Bounded-error Quantum Polynomial time). This means that Shor’s algorithm runs in polynomial time on a quantum computer with a bounded probability of error (which can be made arbitrarily small by repeating the algorithm). The quantum complexity of Shor’s algorithm is polynomial in \(\log N\), where \(N\) is the number to be factored. In contrast, the best-known classical algorithms for integer factorization have super-polynomial complexity, suggesting an exponential quantum speedup. It is not known if integer factorization is in the classical complexity class BPP (Bounded-error Probabilistic Polynomial time), highlighting the potential quantum advantage for this problem.

Conclusion

In this lecture, we have examined four pivotal quantum algorithms: the Quantum Fourier Transform, Quantum Phase Estimation, Shor’s Algorithm, and Grover’s Algorithm. These algorithms illustrate the potential of quantum computation to outperform classical computation for specific problems, offering significant speedups.

Key Takeaways:

  • The Quantum Fourier Transform (QFT) achieves an exponential reduction in circuit complexity compared to the classical Fast Fourier Transform (FFT).

  • Quantum Phase Estimation is a fundamental algorithm for eigenvalue estimation and serves as a critical subroutine in algorithms like Shor’s algorithm.

  • Shor’s Algorithm offers an exponential speedup for integer factorization, posing a significant threat to current public-key cryptography. It is a probabilistic algorithm belonging to the complexity class BQP.

  • Grover’s Algorithm provides a quadratic speedup for unstructured search problems, demonstrating the power of amplitude amplification. It is also a probabilistic algorithm.

  • Quantum algorithms leverage quantum mechanical principles such as superposition and interference to achieve computational advantages over classical approaches for certain problems.

These algorithms highlight the transformative potential of quantum computing for tackling problems currently considered intractable for classical computers. Continued research and development in quantum algorithms and quantum hardware are essential to realize these theoretical advantages in practical applications.

Further Topics and Questions:

  • Quantum circuit implementations of the reflection operators \(R_f\) and \(R_s\) in Grover’s algorithm.

  • Determining the optimal number of iterations in Grover’s algorithm for maximum success probability.

  • Generalizations of Grover’s algorithm to scenarios with multiple marked items and applications to quantum counting.

  • Broader applications of Quantum Phase Estimation and Grover’s algorithm beyond factorization and search, including quantum simulation and optimization.

  • Current limitations and challenges in realizing practical quantum computers and their impact on the deployment of these quantum algorithms.