MQC Notes 4
MQC Notes 4
Dr. Venugopal K.
Circuit
1
1 GROVER’S SEARCH ALGORITHM
Our goal is to find |w⟩ with as few queries to the oracle as possible.
Figure 2:
4. Mathematical Setup
Start with n qubits, all in the |0⟩ state: |0⟩⊗n . Apply a Hadamard gate (H) to each qubit
to create an equal superposition of all N = 2n states:
−1
1 NX
H ⊗n |0⟩⊗n = √ |x⟩.
N x=0
This state, often called |s⟩, gives each state an amplitude of √1 . The probability of measuring
N
any state |x⟩ is:
2
1 1
√ = .
N N
1
Since |s⟩ is a superposition, it includes the target state |w⟩, but its probability is only N
—too
small to find efficiently by measuring now.
Let’s break |s⟩ into two parts: - |w⟩: The target state. - |s⊥ ⟩: The superposition of all
non-target states.
First, define |s⊥ ⟩ as the sum of all states except |w⟩, normalized:
N −1
1
|s⊥ ⟩ = √
X
|x⟩.
N − 1 x=0
x̸=w
We can write |s⟩ as a combination of |w⟩ and |s⊥ ⟩. The amplitude of |w⟩ in |s⟩ is √1N , since
all states have equal amplitude. The inner product ⟨w|s⟩ = √1N , so we decompose:
- ⟨w|s⟩ = √1N . - The component in |s⊥ ⟩: Since ⟨w|s⊥ ⟩ = 0 (they’re orthogonal), the ampli-
tude of |s⊥ ⟩ is: s s
q 1 N −1
⟨s⊥ |s⟩ = 1 − |⟨w|s⟩|2 = 1 − = .
N N
Thus: s
1 N −1 ⊥
|s⟩ = √ |w⟩ + |s ⟩.
N N
q
√1 , √1 N −1
Let’s define: - sin θ = N
so θ = arcsin N
. - cos θ = N
.
Then:
|s⟩ = sin θ|w⟩ + cos θ|s⊥ ⟩.
This geometric view helps us understand Grover’s algorithm as a rotation in a 2D plane
spanned by |w⟩ and |s⊥ ⟩.
This is a reflection of |s⟩ across the |s⊥ ⟩-axis in the |w⟩-|s⊥ ⟩ plane.
D = 2|s⟩⟨s| − I,
where I is the identity operator. This operator reflects the state around the vector |s⟩.
Let’s compute its effect. First, apply D to a general state |ψ⟩:
For our state after the oracle, |ψ⟩ = O|s⟩, the diffusion step reflects O|s⟩ around |s⟩, increas-
ing the amplitude of |w⟩.
Each Grover iteration (oracle + diffusion) rotates the state vector by 2θ toward |w⟩: - Initial
angle: θ, where sin θ = √1N . - After one iteration, the angle becomes 3θ. - After k iterations,
the angle is (2k + 1)θ.
We want the state to be close to |w⟩, which happens when the angle is near π2 :
!
π 1 π
(2k + 1)θ ≈ =⇒ (2k + 1) arcsin √ ≈ .
2 N 2
1 π π√
(2k + 1) √ ≈ =⇒ k ≈ N.
N 2 4
√ √
Thus, we need about π4 N ≈ 0.785 N iterations.
Apply D to O|s⟩:
− 12 1 1 1 1
0
2 2 2 2
1
− 12 1 1 1 0
2 2 2 = |10⟩.
2
D(O|s⟩) = =
1 1
− 21 1 1
− 2 1
2 2 2
1 1 1
2 2 2
− 12 1
2
0
After one iteration, the state is |10⟩, the target! Measuring now gives |10⟩ with probability
1.
9. Limitations
- Multiple
q Solutions: If there are M target states, the optimal number of iterations adjusts
to N/M .
- Quantum Hardware: Requires a quantum computer and a way to implement the oracle.
- Probabilistic Nature: The result is probabilistic, though the success probability is high
after the right number of iterations.
Question
Explain the purpose of Grover’s Search Algorithm and its quantum advantage. For a 2-
qubit search space with one marked state |11⟩, compute the state after one iteration of the
Grover operator, starting from the uniform superposition state, and verify the probability
of measuring the marked state.
Solution
Grover’s
√ Search Algorithm finds a marked item in an unsorted database of N items in
O( N ) queries, compared to O(N ) classically, offering a quadratic speedup. For N =
22 = 4, the search space is {|00⟩, |01⟩, |10⟩, |11⟩}, with |11⟩ marked. The Grover operator
G = (2|s⟩⟨s| − I)Uf , where Uf |x⟩ = (−1)f (x) |x⟩ (f (x) = 1 if x = 11, else 0), and |s⟩ is the
uniform superposition.
Start with |s⟩ = H ⊗2 |00⟩ = 21 (|00⟩ + |01⟩ + |10⟩ + |11⟩). Apply Uf :
1
Uf |x⟩ = (−1)f (x) |x⟩, Uf |s⟩ = (|00⟩ + |01⟩ + |10⟩ − |11⟩).
2
Apply the diffusion operator 2|s⟩⟨s| − I:
1 1 1 1 1 1 1 1 1 0 0 0 −1 1 1 1
1 1
1 1 1 1 1
1 1 1 0
1 0 0 1 1 −1 1
1
|s⟩⟨s| = ,
2|s⟩⟨s|−I = − = .
4 1 1 1 1 2 1 1 1 1 0 0 1 0 2 1 1 −1 1
1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 −1
Compute:
−1 1 1 1 1 3
1 1 1 −1 1
1 1 1 1
1
(2|s⟩⟨s|−I) (|00⟩+|01⟩+|10⟩−|11⟩) = = = (3|00⟩+|01⟩+|10⟩−5|11⟩
4 1 1 −1 1 1 4 1 4
2
1 1 1 −1 −1 −5
2
Probability of measuring |11⟩: Coefficient is − 45 , so probability is − 54 = 16
25
. Normalize the
state’s norm:
1 9 + 1 + 1 + 25 36 9
⟨ψ|ψ⟩ = (32 + 12 + 12 + (−5)2 ) = = = .
16 16 16 4
25
Actual probability: 169 = 25 16
· 49 = 25
36
≈ 0.694. After one iteration, the marked state’s
4
probability is significantly amplified, demonstrating Grover’s amplification process.
speedup over the best classical algorithms. We will cover its purpose, classical preliminar-
ies, quantum components, and a step-by-step example, with all mathematical derivations
explained clearly.
Circuit
Define the function f (x) = ax mod N . This function is periodic: there exists a smallest
integer r (called the period or order) such that ar ≡ 1 mod N . 3. If r is even, compute ar/2
mod N . If ar/2 ̸≡ −1 mod N , then gcd(ar/2 − 1, N ) and gcd(ar/2 + 1, N ) are non-trivial
factors of N .
For example, if N = 15, a = 2: - Compute f (x) = 2x mod 15: f (0) = 1, f (1) = 2, f (2) = 4,
f (3) = 8, f (4) = 1, so the period r = 4. - Since r = 4 is even, compute ar/2 = 22 = 4. -
Check: 4 ̸≡ −1 mod 15. - Compute gcd(ar/2 − 1, N ) = gcd(4 − 1, 15) = gcd(3, 15) = 3, and
gcd(ar/2 + 1, N ) = gcd(4 + 1, 15) = gcd(5, 15) = 5. - The factors of 15 are 3 and 5!
The hard part is finding r. Classically, this takes exponential time, but Shor’s algorithm
uses a quantum computer to find r in polynomial time.
4. Steps
We need n qubits for the first register, where N 2 ≤ 2n < 2N 2 (so n ≈ 2 log2 N ). For
N = 15, N 2 = 225, so choose n = 8 (since 28 = 256 ≥ 225). The second register needs
m = ⌈log2 15⌉ = 4 qubits to store numbers up to 15.
Start with both registers at zero:
Since f (x) has period r = 4, the values of 2x mod 15 repeat: 1, 2, 4, 8, 1, 2, ..., every 4
steps.
Apply the QFT to the first register. The QFT transforms |x⟩ into:
n −1
1 2X n
QFT|x⟩ = √ n e2πixy/2 |y⟩.
2 y=0
q=0 q=0
This sum is large when y/64 is an integer, i.e., y = 64ℓ for ℓ = 0, 1, 2, 3 (since 256/4 = 64).
Otherwise, it cancels out (geometric series). The state has large amplitudes when y = 64ℓ,
so measuring the first register yields y = 0, 64, 128, 192.
Each y = 64ℓ corresponds to a fraction of the period: y/2n = ℓ/r. So:
y ℓ 64ℓ ℓ
= =⇒ = .
256 r 256 4
This suggests r = 4, which we already knew, but in general, we use the continued fraction
algorithm to find ℓ/r. For y = 64, 64/256 = 1/4, so ℓ = 1, r = 4.
Now that we have r = 4: - r is even, so r/2 = 2. - Compute ar/2 = 22 = 4. - Check: 4 ̸≡ −1
mod 15. - Compute factors: gcd(4 − 1, 15) = gcd(3, 15) = 3, gcd(4 + 1, 15) = gcd(5, 15) = 5.
- Factors of 15 are 3 and 5.
7. Limitations
- Quantum Hardware: Requires a fault-tolerant quantum computer, which doesn’t yet exist
at scale (as of May 2025).
- Error Correction: Noise in current quantum computers can affect the QFT and oracle.
- Applicability: Works best for numbers like N = pq (two prime factors), less efficient if N
has many small factors.
Question
Describe the role of the Quantum Fourier Transform (QFT) in Shor’s Quantum Factoring
Algorithm. For factoring N = 15, consider the period-finding step for a = 2. If the QFT
output state for a 3-qubit register is |010⟩, estimate the period r using continued fractions.
Solution
Shor’s Quantum Factoring Algorithm factors a composite number N in polynomial time by
finding the period r of the function f (x) = ax mod N , where a is coprime with N . The
QFT is used in the period-finding subroutine to extract r. For a t-qubit register, QFT maps
P t −1 2πijk/2t
|j⟩ to √12t 2k=0 e |k⟩, revealing multiples of 2t /r.
For N = 15, a = 2, compute f (x) = 2x mod 15: - x = 0: 20 = 1, - x = 1: 21 = 2, -
x = 2: 22 = 4, - x = 3: 23 = 8, - x = 4: 24 = 16 ≡ 1 mod 15. Period r = 4. For a
3-qubit register (t = 3), 2t = 8. The period-finding circuit produces a state with peaks at
k ≈ m · 2t /r = m · 8/4 = 2m. Possible measurements include |010⟩ = |2⟩.
Estimate ϕ = k/2t = 2/8 = 1/4. Use continued fractions to find ϕ = s/r: - 1/4 = 0 + 41 ,
continued fraction: [0; 4]. - Convergent: 14 , so s = 1, r = 4. Verify: 24 = 16 ≡ 1 mod 15,
and r = 4 is correct. The QFT enables efficient period extraction, allowing Shor’s algorithm
to factor N = 15 by computing gcd(ar/2 ± 1, N ), e.g., gcd(22 − 1, 15) = gcd(3, 15) = 3.
2. Problem Setup
We need to solve:
Ax = b,
where: - A is an N × N Hermitian matrix (i.e., A = A† , meaning A’s conjugate transpose
equals itself). - b is a known N -dimensional vector. - x is the N -dimensional vector we want
to find.
Example Setup For simplicity, let’s consider a 2x2 system (N = 2):
" # " #
2 1 1
A= , b= .
1 2 0
" #
x
We want to find x = 1 .
x2
First, verify A is Hermitian:
" #† " #
† 2 1 2 1
A = = = A.
1 2 1 2
So:
1 1
|b⟩ = √ |u1 ⟩ + √ |u2 ⟩.
2 2
" # " #
1 0
In the computational basis (|0⟩ = , |1⟩ = ):
0 1
1 1
|u1 ⟩ = √ (|0⟩ + |1⟩), |u2 ⟩ = √ (|0⟩ − |1⟩),
2 2
! !
1 |0⟩ + |1⟩ 1 |0⟩ − |1⟩ 1
|b⟩ = √ √ +√ √ = (|0⟩ + |1⟩ + |0⟩ − |1⟩) = |0⟩.
2 2 2 2 2
The initial state is:
|0⟩⊗t |b⟩|0⟩ = |0⟩⊗5 |0⟩|0⟩.
Step 2: Quantum Phase Estimation (QPE) Apply QPE with the unitary U = eiAt0 , where t0
scales the eigenvalues to [0, 1). Since A = j λj |uj ⟩⟨uj |, we have U |uj ⟩ = eiλj t0 |uj ⟩. Choose
P
For our example: - λ1 = 3, λ̃1 ≈ 3 · 2π · 1 = 1, but in binary with t = 5 bits, λ̃1 ≈ 1 · 25 = 32.
3 2π
- λ2 = 1, λ̃2 ≈ 1 · 2π
3
1
· 2π = 13 , so λ̃2 ≈ 31 · 25 ≈ 10.67 ≈ 11.
The state is approximately:
1 1
√ |32⟩|u1 ⟩|0⟩ + √ |11⟩|u2 ⟩|0⟩.
2 2
Step 3: Controlled Rotation Apply a controlled rotation on the ancilla qubit, conditioned
on the first register. If the first register is |λ̃j ⟩, rotate the ancilla to:
C
|0⟩ + |1⟩,
λ̃j
1/3
For our example: - For j = 1, λ̃1 = 32, ancilla is |0⟩ + 32
|1⟩. - For j = 2, λ̃2 = 11, ancilla is
|0⟩ + 1/3
11
|1⟩.
Step 4: Uncompute with Inverse QPE Apply the inverse QPE to uncompute the first register,
leaving the second register in a state proportional to j βj λCj |uj ⟩, which is proportional to
P
|x⟩ = A−1 |b⟩. The final state, when the ancilla is |1⟩, is:
N
X 1
C βj |uj ⟩.
j=1 λj
√ √
β1 1/ 2 1 √1 (|0⟩ β2 1/ 2 √1 ,
Compute: - j = 1: λ1
= 3
= √
3 2
, |u1 ⟩ = 2
+ |1⟩). - j = 2: λ2
= 1
= 2
|u2 ⟩ = √12 (|0⟩ − |1⟩).
1 1 1 1 1 1 2 1
|x⟩ ∝ √ · √ (|0⟩ + |1⟩) + √ · √ (|0⟩ − |1⟩) = (|0⟩ + |1⟩) + (|0⟩ − |1⟩) = |0⟩ − |1⟩.
3 2 2 2 2 6 2 3 3
√
r
2 2 q
2
Normalize: Norm = 3
+ − 13 = 5
9
= 3
5
, so:
" #
1 2
|x⟩ = √ .
5 −1
7. Limitations
- Matrix Conditions: A must be Hermitian and well-conditioned.
- Quantum Hardware: Requires a fault-tolerant quantum computer (not yet available at
scale as of May 2025).
- Output: Gives a quantum state |x⟩, not x, so it’s best for tasks like computing expectation
values ⟨x|M |x⟩.
Question
Outline
" the # HHL"Algorithm
# for solving a linear system Ax = b. For a 2x2 system with
2 1 1
A= ,b= , and 1-qubit register for phase estimation, compute the eigenvalues of
1 2 0
A (assuming Hermitian) and describe how phase estimation contributes to solving for x.
Solution
The HHL Algorithm solves Ax = b for a Hermitian matrix A using quantum phase estima-
tion and controlled rotations, achieving exponential speedup for sparse systems. It encodes
b as |b⟩, uses phase estimation to approximate A−1 , and outputs |x⟩ ∝ A−1 |b⟩.
" # " #
2 1 1
Given A = ,b= . Verify A is Hermitian: A† = A. Compute eigenvalues:
1 2 0
" #
2−λ 1
det(A − λI) = det = (2 − λ)2 − 1 = λ2 − 4λ + 3 = 0.
1 2−λ
" #" #
√ −1 1 x
4± 16−12 4±2
Solve: λ = = ,
so λ1 = 3, λ2 = 1. Eigenvectors: - For λ = 3: =
2 2 1 −1 y
" # " #" #
1 1 1 x
0 =⇒ x = y, so |u1 ⟩ = √12 . - For λ = 1: = 0 =⇒ x = −y, so
1 1 1 y
" #
1
|u2 ⟩ = √12 .
−1
" #
1
Express |b⟩ = = 2j=1 bj |uj ⟩:
P
0
" # " # " # " #
1 1 1 1 1 b1 + b2 1
|b⟩ = b1 √ + b2 √ =√ = .
2 1 2 −1 b
2 1 − b 2 0
√ √
2
√
2
√
2
Solve: b1 + b2 = 2, b1 − b2 = 0 =⇒ b1 = b2 = 2
. Thus, |b⟩ = 2
|u1 ⟩ + 2
|u2 ⟩.
Phase estimation approximates eigenvalues λj . For a 1-qubit register, apply controlled-eiAt .
Since A = 3|u1 ⟩⟨u1 | + 1|u2 ⟩⟨u2 |, eiAt |uj ⟩ = eiλj t |uj ⟩. The phase for λj is ϕj = λj t/2π. With 1
qubit, precision is limited, but ideally, phases encode λ1 = 3, λ2 = 1. After phase estimation,
the state is:
2
X
bj |λ̃j ⟩|uj ⟩,
j=1
C
where |λ̃j ⟩ approximates λj . Controlled rotation applies λj
to an ancilla, yielding:
2
√ √
X bj 2 1 2 1
|x⟩ ∝ |uj ⟩ = · |u1 ⟩ + · |u2 ⟩.
j=1 λj 2 3 2 1
This approximates A−1 |b⟩, solving the system. Phase estimation is critical for extracting λj ,
enabling the inversion.