Lec09 Extra Algo
Lec09 Extra Algo
Quantum Computing
#9: Extra Quantum Algorithms
송기원
2022
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
Outline
1 Introduction
2 Grover’s Algorithm
5 Modular Exponents
6 Shor’s Algorithm
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
Caution
Example
Note that the subscript represents the number of digits.
|5⟩3 = |101⟩ = |1⟩ ⊗ |0⟩ ⊗ |1⟩
|1⟩8 = |00000001⟩ = |0⟩ ⊗ |0⟩ ⊗ |0⟩ ⊗ |0⟩ ⊗ |0⟩ ⊗ |0⟩ ⊗ |0⟩ ⊗ |1⟩
|0⟩⊗n = |0⟩n
2 −1 n N−1
1 X 1 X
H ⊗n |0⟩n = √ n |x⟩n = √ |x⟩n where N = 2n
2 x=0 N x=0
Abbreviation of qubits
1 1 1 1
|+⟩ = H |0⟩ = √ |0⟩ + √ |1⟩, |−⟩ = H |1⟩ = √ |0⟩ − √ |1⟩
2 2 2 2
Example
1 1
√ |+⟩ + √ |−⟩ = |0⟩
2 2
QFT2 |11⟩ = (− |−⟩) ⊗ (− |+⟩) = |−+⟩
▶ QFT explained later
H ⊗n |0⟩n = |+⟩⊗n = |+⟩ ⊗ |+⟩ ⊗ · · · ⊗ |+⟩
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
Outline
1 Introduction
2 Grover’s Algorithm
5 Modular Exponents
6 Shor’s Algorithm
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
Grover’s problem
Grover’s problem
For given f : { 0, 1 }m → { 0, 1 }, find unique α such that f (α) = 1.
Phase oracle
Definition(Phase oracle)
A phase oracle Pf of f : { 0, 1 }m → { 0, 1 } maps |x⟩ where x is
m-qubits , to (−1)f (x) |x⟩.
Amplitude amplifier
Grover iteration
The phase vector always exists on the plane that |a⟩ and |b⟩ spans.
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
θ 1
Starting from θ/2 as the angle of |s⟩ where sin =√
2 N
Making rotation of θ, we need to get it close to |b⟩
If r rotation is made, the probability amplitude of |b⟩ is
!
1 1
sin r+ θ where θ = 2 sin−1 √
2 N
√
π N
Thus to make this near 1, r (N) ≈ which gives this
√ 4
O( N) query complexity. (When N is large)
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
Grover’s Algorithm
So the number of iteration is r = O (N/M)1/2
▶ How much time complexity for one iteration?
2n Hadamard gates and 2n X gates, one MCZ gate: O(n)
▶ As N = 2n , O(n) = O(log N)
Phase oracle Pf : O(???)
▶ So it hardly depends on the time complexity of the oracle.
So the time complexity is O (N/M)1/2 (log N + f (N))
▶ where f (N) is the time complexity of simulating Pf .
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
Outline
1 Introduction
2 Grover’s Algorithm
5 Modular Exponents
6 Shor’s Algorithm
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
Concept
Different Basis
Definition(QFT)
N−1
1 X 2πixy /N
QFT of n is a matrix that maps QFTn |x⟩n = √ e |y ⟩n
N y =0
Rotation matrix
Definition(Rθ )
" #
1 0
Rθ = is a matrix that rotates the second element by θ.
0 e iθ
π
The first output qubit rotates if k-th qubit is 1
2k−1
▶ We need controlled Rk−1 , which is controlled by k, targeting 1.
Thus we define the controlled rotation matrix CRθ :
So first qubit gets H for rotating π for itself, CR2 with the
second qubit, CR3 with the third, · · · , CRn for the last.
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
QFT circuit
|x1 ⟩ H R2 R3 ··· Rn
|x3 ⟩
|xn−1 ⟩ H R2
|xn ⟩ H
|x1 ⟩
|x2 ⟩
|x3 ⟩
QFTn
|xn−1 ⟩
|xn ⟩
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
Definition(QFT−1 )
N−1
1 X −2πixy /N
QFT−1 is a matrix that maps QFT † |x⟩n = √ e |y ⟩n .
N y =0
Outline
1 Introduction
2 Grover’s Algorithm
5 Modular Exponents
6 Shor’s Algorithm
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
Eigenvalue
Definition(Eigenvalue)
An eigenvalue λ of a matrix M is a value such that there exists
some nonzero vector x such that Mx = λx.
Proof
For eigenvalue λ of a unitary matrix U with its eigenvector x,
x† x = x† I x = x† U † Ux = (Ux)† Ux = λλx† x so λλ = 1 as x† x ̸= 0.
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
Eigenvector
Definition(Eigenvector)
For an eigenvalue λ of a matrix M, any nonzero vector x such that
Mx = λx is an eigenvector of λ.
Definition(Orthogonality)
Eigenvectors of different eigenvalues of U are orthogonal.
Proof
For eigenvalue λx for x and λy for y of matrix U where λx ̸= λy ,
x† y = x† I y = (λx x)† (λy y) = λx λy x† y so λx λy = 1 or x† y = 0.
But λx λy = 1 ⇐⇒ λx λx λy = λx ⇐⇒ λy = λx so x† y = 0.
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
|ψ⟩ U
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
|0⟩ H H
|ψ⟩ U
1
Initial state: |0⟩ |ψ⟩, after Hadamard gate: √ (|0⟩ + |1⟩) ⊗ |ψ⟩
2
1 e iθ
After controlled U: √ |0⟩ |ψ⟩ + √ |1⟩ |ψ⟩
2 2
1
After Hadamard gate: (1 + e ) |0⟩ + (1 − e iθ ) |1⟩ |ψ⟩
iθ
2
2 2
1 − e iθ 1 + e iθ
Chance p of measuring 1: , while 0:
2 2
▶ Find θ = ± cos−1 (1 − 2p) by finding probability p by testing.
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
|0⟩ H ···
.. ..
. .
QFTn†
|0⟩ H ···
|0⟩ H ···
m
|ψ⟩ U2
0
U2
1
··· U2
n−1
|0⟩ H ···
.. ..
. QFTn† .
|0⟩ H ···
|0⟩ H ···
m 0 1 n−1
|ψ⟩ U2 U2 ··· U2
1
Initial state: |0⟩⊗n |ψ⟩, after H gate: √ n (|0⟩ + |1⟩)⊗n |ψ⟩
2
2 k i2 kθ k
As U |ψ⟩ = e |ψ⟩, k-th qubit: (|0⟩ + e i2 θ |1⟩) |ψ⟩
n−1
1 X k
Before inverse QFT: √ n (|0⟩ + e i2 θ |1⟩) |ψ⟩
2 k=0
▶ So we can say |ψ⟩ is left unchanged.
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
|0⟩ H ···
.. ..
. QFTn† .
|0⟩ H ···
|0⟩ H ···
m 0 1 n−1
|ψ⟩ U2 U2 ··· U2
2 −1 n
1 X ikθ
Rewriting the qubits above: √ n e |k⟩n
2 k=0
N−1 N−1
1 X ikθ X −2πikx/N
Applying QFT inverse: n e e |x⟩n
2
k=0 x=0
N−1 N−1
1 XX 2πik
Let θ = 2πω then e− N
(x−Nω)
|x⟩n
N
k=0 x=0
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
m 0 1 n−1
|ψ⟩ U2 U2 ··· U2
N−1 N−1
1 X X − 2πik (x−Nω)
We have |ϕ⟩ = e N |x⟩n
N
k=0 x=0
1 1
Let Nθ = Nω = A + Nδ where A ∈ Z and |Nδ| ≤ .
2π 2
N−1 N−1
1 X X − 2πik (x−A)+2πiδk
Then |ϕ⟩ = e N |x⟩n
N
k=0 x=0
2
N−1
2 1 X −2πiδk
So Pr (A) = ⟨A|ϕ⟩ = e
N
k=0
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
Accuracy of QPE
2
N−1
2 1 X −2πiδk
Pr (A) = ⟨A|ϕ⟩ = e
N
k=0
4
If δ = 0 then Pr (A) = 1 and otherwise Pr (A) ≥ ≈ 0.405
π
2
1 1 − e 2πiNδ
Pr (A) = 2
N 1 − e 2πδ
2 2
1 2 sin(πNδ) 1 2Nδ 4
= ≥ =
N 2 2 sin(πδ) N 2 πδ π
1
as |δ| ≤ implies | sin(πδ)| ≤ |πδ| and | sin(πNδ)| ≥ |2Nδ|.
2N
A can be found quickly, as Pr (A) ≥ 4/π.
Thus θ′ = A/N can be found, less than 1/2N error from θ.
▶ As θ′ − θ = δ
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
Outline
1 Introduction
2 Grover’s Algorithm
5 Modular Exponents
6 Shor’s Algorithm
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
Modular arithmetics
Definition(Modulo operation)
For integers a and nonzero integer n, a mod n is defined as a
nonnegative integer b < n such that a = kn + b for some k ∈ Z.
Definition(Divisibility)
For a, b ∈ Z, if there exists some k ∈ Z such that a = kb, we say
that b can divide a, or b | a.
Definition(Primality)
p is prime when there is no d such that |d| =
̸ p, |d| =
̸ 1, and d | p.
Hardness of FACTOR
Definition(FACTOR)
FACTOR is a problem that receives N as an input, and outputs the
prime factorization of N.
Outline
1 Introduction
2 Grover’s Algorithm
5 Modular Exponents
6 Shor’s Algorithm
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
Shor’s algorithm
|0⟩ H ···
.. ..
. .
QFTn†
|0⟩ H ···
|0⟩ H ···
n
0 1 n−1
|1⟩n Ua2 Ua2 ··· Ua2
k
In QPE, Ua2 must be a repeated multiplication of Ua .
However, it takes too much time, so we can make use of
k k
Ua2 = Ua2k by calculating a2 classically.
Introduction Grover’s Algorithm Quantum Fourier Transform Quantum Phase Estimation Modular Exponents Shor’s Algorithm
Summary
For given N:
Pick any integer 1 < a < N.
Calculate K = gcd(a, N) and if K ̸= 1, K is a nontrivial
factor of N.
If K = 1, find minimum r ∈ N such that ar ≡ 1(mod N)
▶ New QPE is made for each a.
If r is odd, try another a.
If r is even but ar /2 ≡ −1(mod N), try another a.
Then both gcd(ar /2 + 1, N) and gcd(ar /2 − 1, N) are a
nontrivial factor of N.
Boolean and Phase Oracle Rotation effect of Grover iteration Additional Information of QFT Probability Theories for QPE
|b⟩ |b⟩
As Pf |ψ⟩
|ψ⟩ |ψ⟩
|s⟩ |s⟩
|a⟩ |a⟩
Pf |ψ⟩ Pf |ψ⟩
P P
For A |x⟩ = f (x, y ) |y ⟩, we can say A = f (x, y ) |y ⟩ ⟨x|.
y x,y
▶ It is because the inputs are in the orthonormal basis.
Let F is the matrix representing QFT , then the claim is:
N−1 N−1
1 X 2πixy /N 1 X −2πix ′ y ′ /N ′
F =√ e |x⟩ ⟨y | F† = √ e |y ⟩ ⟨x ′ |
N x,y =0 N x ′ ,y ′ =0
Proof of F † F = I
1 X ′ y ′ )/N
F †F = e 2πi(xy −x |x⟩ ⟨x ′ | ⟨y |y ′ ⟩
N
x,y ,x ′ ,y ′
1 X 2πi(x−x ′ )y /N
= e |x⟩ ⟨x ′ |
N ′x,y ,x
1 X 2πi(x−x ′ )y /N X
= e |x⟩ ⟨x ′ | = |x⟩ ⟨x| = I
N ′ x
x,y ,x
Boolean and Phase Oracle Rotation effect of Grover iteration Additional Information of QFT Probability Theories for QPE
0
0 0.2 0.4 0.6 0.8 1