Lecture Notes on Quantum Algorithms and Protocols
Introduction
This lecture covers advanced quantum algorithms and protocols, focusing on Shor’s algorithm for integer factorization, Grover’s algorithm for quantum search, and the BB84 protocol for quantum key distribution. The main objective is to understand the principles behind these algorithms and protocols, their quantum mechanical foundations, and their implications for computation and communication security.
Shor’s Algorithm for Integer Factorization
Problem Statement: Integer Factorization
The goal of integer factorization is to decompose a composite integer \(n\) into its prime factors. We assume that \(n\) is a composite number, having already ruled out the case where \(n\) is prime using efficient classical primality tests. We also assume that \(n\) is not a perfect power (\(n \neq a^b\) for integers \(a > 1, b > 1\)), as these cases are efficiently solvable classically. While the prime factorization of \(n\) can be represented as \(n = p_1^{e_1} p_2^{e_2} \cdots p_k^{e_k}\), where \(p_i\) are prime numbers, the algorithm’s explanation in this context focuses on finding non-trivial factors without explicitly requiring this full prime factorization form initially.
Order Finding and its Relevance
Shor’s algorithm leverages the order-finding problem. For given integers \(x\) and \(n\), where \(n\) is composite and \(\text{gcd}(x, n) = 1\), the order \(r\) of \(x\) modulo \(n\) is the smallest positive integer such that \(x^r \equiv 1 \pmod{n}\). This is equivalent to saying that \(x^r - 1\) is an integer multiple of \(n\): \[x^r - 1 \equiv 0 \pmod{n}\] \[x^r - 1 = k \cdot n, \quad k \in \mathbb{Z}\] A crucial requirement for Shor’s algorithm to proceed successfully is that the order \(r\) must be an even number. If \(r\) is odd, this path of the algorithm fails, and a different random \(x\) must be chosen.
Failure Cases in Shor’s Algorithm
Shor’s algorithm, in this simplified explanation, has two primary failure conditions that necessitate restarting the algorithm with a different randomly chosen value of \(x\):
Odd Order r: If the computed order \(r\) of \(x\) modulo \(n\) is found to be odd, the algorithm cannot proceed with the current \(x\). In this scenario, the algorithm iteration fails, and one must return to the step of randomly selecting \(x\).
Trivial GCD Result: Even when the order \(r\) is even, a further check is required. We compute the greatest common divisor of \((x^{r/2} + 1)\) and \(n\). If \(\text{gcd}(x^{r/2} + 1, n) = n\), it implies that \(x^{r/2} + 1\) is a multiple of \(n\), and thus, all prime factors of \(n\) are contained within \(x^{r/2} + 1\) in a way that does not directly yield a factorization through this method. In this case, the algorithm also fails for this choice of \(x\), and a new random \(x\) must be selected.
If neither of these failure conditions is met, it is likely that the prime factors of \(n\) are distributed between the values \(\text{gcd}(x^{r/2} - 1, n)\) and \(\text{gcd}(x^{r/2} + 1, n)\), allowing for factorization.
Factor Extraction
When Shor’s algorithm avoids the failure conditions, we can proceed to extract factors of \(n\). We compute: \[m = \text{gcd}(x^{r/2} - 1, n)\] \[m' = \text{gcd}(x^{r/2} + 1, n)\] The values \(m\) and \(m'\) are likely to be non-trivial factors of \(n\). If these factors are non-trivial (i.e., \(1 < m < n\) and \(1 < m' < n\)), we have successfully reduced the problem of factoring \(n\) to factoring potentially smaller numbers \(m\) and \(m'\). If \(m\) or \(m'\) is still composite, the factorization process can be applied recursively.
A critical quantum subroutine within Shor’s algorithm, not detailed here, is the efficient quantum computation of the order \(r\) using the Quantum Fourier Transform (QFT). The QFT enables the order-finding to be performed exponentially faster than known classical algorithms. This quantum speedup in order finding is the core reason why Shor’s algorithm provides an exponential advantage for factorization over the best-known classical algorithms. The transcript notes that the technical details of QFT and its application to order-finding are skipped in this lecture, but it is essential to recognize its central role and the fact that it is not efficiently computable classically.
It is important to note that Shor’s algorithm is a probabilistic algorithm with a bounded probability of error. While there are failure cases as described, the probability of encountering these failures can be controlled and reduced to an arbitrarily small value by repeating the algorithm with different random choices of \(x\). For Shor’s algorithm to be considered a bounded-error quantum polynomial time (BQP) algorithm, the probability of failure must be strictly less than one-half, which is achievable through repetition and probabilistic analysis of the algorithm’s success rate.
Grover’s Algorithm for Quantum Search
Problem Statement: Unstructured Search
Grover’s algorithm addresses the problem of searching an unstructured database. Imagine a search space of \(N\) items, indexed from \(0\) to \(N-1\). We are given a Boolean function \(f(x)\) which acts as an oracle. For exactly one unique input \(\omega \in \{0, 1, \ldots, N-1\}\), \(f(\omega) = 1\), and for all other inputs \(x \neq \omega\), \(f(x) = 0\). The task is to find this specific input \(\omega\). Classically, in the absence of any structure, we would need to examine, on average, \(N/2\) items and in the worst case, all \(N\) items to find \(\omega\).
Quantum Initialization and Oracle Query
Grover’s algorithm begins by preparing a uniform superposition over all possible input states. If we are working with \(n\) qubits, the size of the search space is \(N = 2^n\). The initial quantum state is: \[\left|{\psi_0}\right\rangle = \frac{1}{\sqrt{N}} \sum_{x=0}^{N-1} \left|{x}\right\rangle\] This uniform superposition is created by applying Hadamard gates to each qubit initialized in the \(\left|{0}\right\rangle\) state: \(H^{\otimes n} \left|{0}\right\rangle^{\otimes n} = \left|{\psi_0}\right\rangle\).
The algorithm utilizes a quantum oracle \(O_f\) that encodes the function \(f(x)\). This oracle is a unitary operator that acts on a state \(\left|{x}\right\rangle\) and marks the solution \(\left|{\omega}\right\rangle\) by flipping its phase. The oracle’s action is defined as: \[O_f \left|{x}\right\rangle = (-1)^{f(x)} \left|{x}\right\rangle = \begin{cases} -\left|{x}\right\rangle & \text{if } x = \omega \\ \left|{x}\right\rangle & \text{if } x \neq \omega \end{cases}\] This phase flip is a form of quantum marking that distinguishes the solution state \(\left|{\omega}\right\rangle\).
Amplitude Amplification via Reflections
Grover’s algorithm achieves quantum speedup through a technique called amplitude amplification. Starting from the uniform superposition \(\left|{\psi_0}\right\rangle\), the algorithm iteratively applies two reflection operations to increase the amplitude of the target state \(\left|{\omega}\right\rangle\) while decreasing the amplitudes of the non-target states. These reflections are:
Oracle Reflection (\(R_f\)): The oracle reflection is directly related to the oracle \(O_f\). It can be expressed as \(R_f = I - 2\left|{\omega}\right\rangle\left\langle{\omega}\right|\), or equivalently as \(R_f = O_f\) in this simplified phase-flipping oracle definition. Applying \(R_f\) reflects the amplitude about the axis perpendicular to \(\left|{\omega}\right\rangle\). As defined earlier, its action on a basis state \(\left|{x}\right\rangle\) is: \[R_f \left|{x}\right\rangle = \begin{cases} -\left|{x}\right\rangle & \text{if } x = \omega \\ \left|{x}\right\rangle & \text{if } x \neq \omega \end{cases}\] This operator is unitary because it is a reflection.
An alternative implementation of the oracle, inspired by Deutsch’s algorithm, involves using an ancillary qubit. By preparing an initial state \(\left|{0}\right\rangle^{\otimes n} \left|{-}\right\rangle = \left|{0}\right\rangle^{\otimes n} \frac{1}{\sqrt{2}}(\left|{0}\right\rangle - \left|{1}\right\rangle)\), applying Hadamard gates \(H^{\otimes n} \otimes I\), and then a controlled-U operation where \(U\left|{y}\right\rangle = (-1)^{f(x)}\left|{y}\right\rangle\), followed by measurement of the ancillary qubit, one can effectively implement the oracle reflection on the system qubits.
Inversion About Average (\(R_{\psi_0}\)): This reflection boosts the amplitude of states that are above the average amplitude and diminishes those below. It is defined as \(R_{\psi_0} = 2\left|{\psi_0}\right\rangle\left\langle{\psi_0}\right| - I\), where \(\left|{\psi_0}\right\rangle\) is the initial uniform superposition. This operator reflects amplitudes about the average amplitude. It can also be implemented using Hadamard gates and a reflection about the \(\left|{0}\right\rangle^{\otimes n}\) state: \(R_{\psi_0} = H^{\otimes n} (2\left|{0}\right\rangle^{\otimes n}\left\langle{0}\right|^{\otimes n} - I) H^{\otimes n}\). The operator \(2\left|{0}\right\rangle^{\otimes n}\left\langle{0}\right|^{\otimes n} - I\) performs a reflection about \(\left|{0}\right\rangle^{\otimes n}\) and is unitary.
The Grover iteration, denoted as \(G\), is the composition of these two reflections, applied in sequence: \(G = R_{\psi_0} R_f\).
Input: Oracle function \(f(x)\) such that \(f(x) = 1\) if \(x = \omega\) and \(f(x) = 0\) otherwise, search space size \(N = 2^n\). Output: The state \(\left|{\omega}\right\rangle\). Initialization: Prepare the uniform superposition state \(\left|{\psi_0}\right\rangle = H^{\otimes n} \left|{0}\right\rangle^{\otimes n} = \frac{1}{\sqrt{N}} \sum_{x=0}^{N-1} \left|{x}\right\rangle\). Number of iterations: Calculate the optimal number of iterations \(k \approx \frac{\pi}{4} \sqrt{N}\). Apply the oracle reflection \(R_f\). Apply the inversion about average \(R_{\psi_0}\). Measurement: Measure the resulting quantum state in the computational basis. Result: The measurement outcome will be \(x = \omega\) with high probability.
Example: Case of N=4
Consider a search space of size \(N=4\) (2 qubits). The initial state is \(\left|{\psi_0}\right\rangle = \frac{1}{2} (\left|{00}\right\rangle + \left|{01}\right\rangle + \left|{10}\right\rangle + \left|{11}\right\rangle)\). Let \(A = \frac{1}{2}\) be the initial amplitude of each basis state. Suppose \(\left|{\omega}\right\rangle = \left|{11}\right\rangle\) is the target state.
Oracle Reflection \(R_f\): Applying \(R_f\) flips the sign of the amplitude of \(\left|{11}\right\rangle\). The state becomes \(\frac{1}{2} (\left|{00}\right\rangle + \left|{01}\right\rangle + \left|{10}\right\rangle - \left|{11}\right\rangle)\). The amplitudes are now \(A = \frac{1}{2}\) for \(\left|{00}\right\rangle, \left|{01}\right\rangle, \left|{10}\right\rangle\) and \(-A = -\frac{1}{2}\) for \(\left|{11}\right\rangle\).
Inversion About Average \(R_{\psi_0}\): The average amplitude \(A'\) after the oracle reflection is calculated as the sum of amplitudes divided by \(N\): \[A' = \frac{3 \times (\frac{1}{2}) + 1 \times (-\frac{1}{2})}{4} = \frac{\frac{3}{2} - \frac{1}{2}}{4} = \frac{1}{4}\] For each amplitude \(B\), the new amplitude after inversion about average is \(2A' - B\).
For states \(x \neq \omega\) (e.g., \(\left|{00}\right\rangle, \left|{01}\right\rangle, \left|{10}\right\rangle\)), the new amplitude is \(2A' - A = 2 \cdot \frac{1}{4} - \frac{1}{2} = 0\).
For the target state \(\omega = \left|{11}\right\rangle\), the new amplitude is \(2A' - (-A) = 2A' + A = 2 \cdot \frac{1}{4} + \frac{1}{2} = 1\).
After one Grover iteration, the state becomes \(0 \cdot \left|{00}\right\rangle + 0 \cdot \left|{01}\right\rangle + 0 \cdot \left|{10}\right\rangle + 1 \cdot \left|{11}\right\rangle = \left|{11}\right\rangle\).
In the \(N=4\) case, a single iteration of Grover’s algorithm precisely isolates the target state \(\left|{\omega}\right\rangle = \left|{11}\right\rangle\). Measuring this state yields \(\left|{11}\right\rangle\) with probability 1.
Optimal Number of Iterations and Quadratic Speedup
For a search space of size \(N\), the optimal number of Grover iterations is approximately \(k \approx \frac{\pi}{4} \sqrt{N}\). After \(k\) iterations, the probability of measuring the target state \(\left|{\omega}\right\rangle\) is close to unity. This demonstrates a quadratic speedup compared to classical unstructured search, which requires \(O(N)\) queries in the worst case. Grover’s algorithm achieves the search in \(O(\sqrt{N})\) oracle queries.
Over-iteration and Algorithm Limitations
Applying the Grover iteration more than the optimal number of times leads to over-rotation. The probability of finding the target state starts to decrease, and the algorithm’s performance degrades. Repeated application of any unitary operator can, after a sufficient number of repetitions, approximate the identity operator. In the context of Grover’s algorithm, excessive iterations can rotate the state away from \(\left|{\omega}\right\rangle\) and back towards the initial uniform superposition, reducing the success probability. Therefore, knowing or estimating the optimal number of iterations is crucial. In practical scenarios where the exact optimal number is not known, repeating the algorithm a few times with a number of iterations around \(\sqrt{N}\) and taking the majority result can be a strategy.
Extensions and Applications
Grover’s algorithm serves as a foundation for various quantum algorithms, including:
Complexity Analysis
Grover’s algorithm provides a quadratic speedup for unstructured search.
Classical Search: In the worst case, \(O(N)\) queries to the function \(f(x)\) are needed. On average \(O(N/2) = O(N)\) queries.
Grover’s Algorithm: Requires \(O(\sqrt{N})\) queries to the quantum oracle \(O_f\) to find the target state with high probability.
While the speedup is quadratic rather than exponential (like in Shor’s algorithm), it is still a significant improvement for computationally intensive search problems and highlights the power of quantum algorithms for specific tasks. This quadratic speedup is the basis for the growing field of quantum information retrieval and motivates research into new quantum search algorithms and applications.
Solves the unstructured search problem with quadratic speedup.
Utilizes amplitude amplification through iterative applications of oracle reflection and inversion about average.
Optimal number of iterations is approximately \(O(\sqrt{N})\).
Provides a significant, though not exponential, speedup compared to classical search.
Forms the basis for advanced quantum search and information retrieval algorithms.
Quantum Key Distribution: BB84 Protocol
Introduction to Quantum Key Distribution
Quantum Key Distribution (QKD) protocols, such as BB84, provide a method for two parties, Alice and Bob, to establish a shared secret key using quantum mechanics. This key can then be used with classical encryption algorithms for secure communication over a classical channel. A primary advantage of QKD is its ability to detect the presence of any eavesdropper, such as Eve, attempting to intercept the key exchange.
BB84 Protocol and Non-Orthogonal States
The BB84 protocol’s security is rooted in the fundamental principles of quantum mechanics, specifically the properties of non-orthogonal quantum states and the disturbance caused by quantum measurement. The protocol utilizes two pairs of conjugate bases:
Rectilinear Basis (Z-basis): \(\{\left|{0}\right\rangle, \left|{1}\right\rangle\}\)
Diagonal Basis (X-basis): \(\{\left|{+}\right\rangle = \frac{1}{\sqrt{2}}(\left|{0}\right\rangle + \left|{1}\right\rangle), \left|{-}\right\rangle = \frac{1}{\sqrt{2}}(\left|{0}\right\rangle - \left|{1}\right\rangle)\}\)
States within the same basis are orthogonal and can be perfectly distinguished when measured in that basis. However, states from different bases are non-orthogonal. For example, \(\left|{+}\right\rangle\) is not orthogonal to either \(\left|{0}\right\rangle\) or \(\left|{1}\right\rangle\). Measuring a state prepared in one basis using the other basis leads to probabilistic outcomes, fundamentally limiting the ability to gain information without causing disturbance. Specifically, measuring \(\left|{+}\right\rangle\) in the Z-basis yields \(\left|{0}\right\rangle\) or \(\left|{1}\right\rangle\) with equal probability (50
BB84 Protocol Steps
The BB84 protocol proceeds through the following steps to establish a secret key:
Alice’s Qubit Transmission: For each bit she wants to send, Alice performs these actions:
Bob’s Measurement: For each qubit received from Alice, Bob independently:
Basis Choice: Bob randomly chooses a measurement basis \(b'_i \in \{0, 1\}\) (Z-basis or X-basis).
Measurement: Bob measures the received qubit in the chosen basis \(b'_i\), obtaining a measurement outcome \(a'_i \in \{0, 1\}\).
Basis Reconciliation (Sifting): Alice and Bob communicate over a public classical channel to perform basis sifting:
Basis Announcement: Bob publicly announces the sequence of bases \(b'_i\) he used for each measurement.
Basis Revelation: Alice publicly reveals the sequence of bases \(b_i\) she used for encoding.
Key Sifting: Alice and Bob keep only the bits for which they used the same basis (\(b_i = b'_i\)). They discard the bits where their bases differed (\(b_i \neq b'_i\)). The retained bits form the raw key.
If no eavesdropping occurred, for the bits where they used the same basis, Bob’s measurement outcome \(a'_i\) should ideally be equal to Alice’s original bit \(a_i\).
Eavesdropping Detection and Security
The security of BB84 lies in the possibility of detecting eavesdropping. If Eve attempts to intercept the qubits transmitted by Alice, she must perform a measurement to gain information. However, Eve does not know which basis Alice used to encode each qubit.
If Eve guesses the basis correctly, she can measure the qubit in the correct basis and resend a copy to Bob without introducing errors. However, if Eve guesses incorrectly, she will inevitably disturb the quantum state due to the measurement postulate. When Bob subsequently measures in the correct basis (matching Alice’s original basis), this disturbance can introduce errors in Bob’s measurement outcomes compared to Alice’s original bits.
Probability of Eavesdropping Detection
Consider the scenario where Alice and Bob use the same basis for a particular bit (which occurs with probability 1/2). If Eve intercepts this qubit and chooses to measure in the wrong basis (which happens with probability 1/2 for Eve’s random guess), her measurement will introduce a disturbance. When Bob measures in the correct basis, there is a 50
Therefore, even with a simple intercept-resend strategy, Eve has a significant probability of introducing detectable errors. By publicly comparing a subset of the sifted key bits, Alice and Bob can estimate the Quantum Bit Error Rate (QBER). If the QBER is below a certain threshold, they can assume the channel is reasonably secure and proceed with error correction and privacy amplification to distill a secure secret key. A higher QBER would indicate likely eavesdropping, and they would discard the key and restart the protocol.
In a simplified analysis, if Eve randomly guesses the basis for each intercepted qubit, and Alice and Bob happen to use the same basis, the probability that Eve’s incorrect basis choice introduces a detectable error is 1/4 (probability of same basis * probability of Eve’s wrong guess * probability of error given wrong guess measurement = 1/2 * 1/2 * 1/2, but simplified to 1/4 in transcript discussion, likely considering error introduction when bases mismatch). This error rate allows Alice and Bob to detect Eve’s presence with a quantifiable probability.
Any attempt by Eve to eavesdrop and gain information about the transmitted qubits will introduce detectable errors in the key exchange due to the principles of quantum measurement and the properties of non-orthogonal states. This allows Alice and Bob to detect eavesdropping and ensure the security of their key.
Conclusion
This lecture has provided an introduction to three pivotal topics in quantum computing: Shor’s algorithm for integer factorization, Grover’s algorithm for unstructured search, and the BB84 protocol for quantum key distribution. These examples illustrate the potential of quantum mechanics to revolutionize computation and communication security.
Key Takeaways:
Shor’s Algorithm: Achieves exponential speedup over classical algorithms for integer factorization by employing the Quantum Fourier Transform to solve the order-finding problem. The algorithm is probabilistic and has specific failure conditions related to the order of chosen elements and GCD results.
Grover’s Algorithm: Offers a quadratic speedup for unstructured search problems through amplitude amplification. This technique uses iterative applications of oracle and inversion-about-average reflections. Optimal performance is achieved with approximately \(\sqrt{N}\) iterations, and over-iteration can reduce the probability of success.
BB84 Protocol: Demonstrates a practical application of quantum mechanics for secure communication by enabling the distribution of cryptographic keys with security guaranteed by the principles of quantum mechanics, particularly the measurement disturbance of non-orthogonal states. Eavesdropping attempts introduce detectable errors, ensuring a mechanism for security verification.
Further Exploration:
The subsequent lectures will delve deeper into related quantum cryptographic protocols and explore advanced topics in quantum algorithm design and their potential applications in various computational domains.