Вы находитесь на странице: 1из 8

Introduction

Last lecture, we:


• showed how to analyse some simple quantum logic circuits
Lecture 6: The Quantum Fourier Transform
In this lecture we will:
Dr Iain Styles: I.B.Styles@cs.bham.ac.uk • introduce the discrete Fourier transform (DFT)
• show how the quantum Fourier transform (QFT) emerges from the DFT
• construct a quantum circuit that performs the QFT

Lecture 6: The Quantum Fourier Transform – p.1/16 Lecture 6: The Quantum Fourier Transform – p.2/16

The Fourier Transform The Fourier Transform

The Fourier Transform (FT) is one of the most useful mathematical tools in We can Fourier Transform the data to get a frequency spectrum:
modern science and engineering. It is used, amongst many other things, to: 350

300

• remove noise from data 250

• examine the properties of crystals 200

F(k)
150

• produce holograms 100

50

The FT is especially useful when we have something with underlying 0

periodicity: imagine a sine wave with a bit of high-frequency noise −50


0 200 400 600
k
800 1000 1200 1400

We then remove the high-frequency components (the noise) from the


1.5

1
spectrum, and inverse-FT to give a clean set of data:

fig
1.5
0.5
y

1
0

2
fig
0.5
−0.5

y
0
−1
−8 −6 −4 −2 0 2 4 6 8
x

−0.5

−1
−8 −6 −4 −2 0 2 4 6 8
x

Lecture 6: The Quantum Fourier Transform – p.3/16 Lecture 6: The Quantum Fourier Transform – p.4/16
The Fourier Transform Discrete Fourier Transform

• FT allows us to extract the underlying periodic behaviour of a function • The DFT is a version of the FT which works on discrete data sets
• Period finding is the basis for Shor’s factoring algorithm, and wewill use • Mathematically, the DFT is written as
the QFT in this important application of quantum computing
N −1
• We must begin by defining the discrete version of the Fourier Transform, 1 !
yk = √ xj e2πijk/N
which will form the basis for the quantum algorithm N j=0

• Looks formidable, but isn’t too hard to calculate


• xj are complex numbers, with j = 0 . . . N − 1
• yk are complex numbers, with k = 0 . . . N − 1

• i = −1; j and k are indices
• An example will show us how to calculate this in practice

Lecture 6: The Quantum Fourier Transform – p.5/16 Lecture 6: The Quantum Fourier Transform – p.6/16

An Example Calculation The Quantum Fourier Transform

• Given xj = {1, 2}, calculate yk • Since our state vectors for qubits are just vectors of complex numbers,
• x0 = 1, x1 = 2, and N = 2 we should not be surprised to learn that the DFT can be applied to them
 
• So yk = √1
"1 2πijk/2 a0
2 j=0 xj e "N −1  . 
• Given a state vector |ψ# = j=0 aj |j# =  .. 
• For k = 0, y0 = √1 1
√1 + √2 = √3
"
j=0 xj =
 
2 2 2 2 aN −1
• For k = 1, y1 = √1 1 1
2eπi = − √12
" 2πij/2
# $
2 j=0 jx e = √
2
1 + • We can compute the DFT of this state as
• So it’s really not that hard to calculate
N −1
• The Fast Fourier Transform (FFT) algorithm of Cooley and Tukey allows
!
F |ψ# = bk |k#
us to compute the DFT very rapidly k=0
• The FFT is often use in sound and image processing for the removal of N −1
1 !
noise where bk = √ aj e2πijk/N
N j=0
• In general, the FT is useful when there is underlying periodicity
• We will later see that the FT allows us to manipulate quantum state • It can be shown that this is unitary, and so can be implemented
vectors to allow us to measure the result of quantum computations
Lecture 6: The Quantum Fourier Transform – p.7/16 Lecture 6: The Quantum Fourier Transform – p.8/16
Example of a QFT Example of a QFT

• Consider the 2-qubit state |ψ# = a00 |00# + a01 |00# + a10 |10# + a11 |11#,
which has N = 4.
Fl
• Writing ω = eπi/2 , and noting that ω 4 = e2πi = 1 and so, e.g.
e9iπ/2 = eiπ/2 = i, we can write the 2-qubit QFT in matrix form:
ID
• Then bk = 1 3j=0 aj e2πijk/4 , and we have
"
2    
1 1 1 1 1 1 1 1
1
3
1 11 ω ω2 3
ω  1 1 i −1 −i 
F =  = 
! 
b0 = aj = (a00 + a01 + a10 + a11 ) 2 1 ω2 1 ω 2  2 1 −1 1 −1

2 j=0
2
1 ω3 ω2 ω 1 −i −1 i
3
1! 1+ ,
b1 = aj e2πij/4 = a00 + a01 eiπ/2 + a10 eiπ + a11 e3iπ/2 • This can easily be shown to be a unitary operator
2 j=0 2
3
• We can build a fairly simple quantum circuit that performs this
1! 1# transformation
aj e4πij/4 = a00 + a01 eiπ + a10 e2iπ + a11 e3iπ
$
b2 =
QFT
2 j=0 2

b3 =
1!
3
aj e6πij/4 =
1+
a00 + a01 e3iπ/2 + a10 e3iπ + a11 e9iπ/2
,
Single Qubit
Hadamard
just
2 j=0 2

107 1 bell 12141 13 is


gate
bulk Lecture 6: The Quantum Fourier Transform – p.9/16 Lecture 6: The Quantum Fourier Transform – p.10/16

Uzo QFT Circuit QFT Circuit

• The circuit that implements the QFT is quite simple, but has some new • We also need a gate which swaps the order of the qubits
elements in it. • On three qubits, this gate does the following:
• We need to introduce some new gates:
• The Controlled-Rk gate: |000# $→ |000#

1 0 0 0 0 0 0 0

|001# $→ |100# 0

0 0 0 1 0 0 0

 
  |010# $→ |010# 0 0 1 0 0 0 0 0
1 0 0 0  
|I> |Q> |011# $→ |110# 0 0 0 0 0 0 1 0
0 1 0 0  $→ S3 = 
 
Rk =  0 1 0 0 0 0 0 0
  
|100# $→ |001#
0 0 1 0  Rk

 
0 0 0 0 0 1 0 0
0 0 0 e2πi/2
k
|101# $→ |101#  
0 0 0 1 0 0 0 0
 
|110# $→ |011#
0 0 0 0 0 0 0 1
|111# $→ |111#
• In the circuit, we will use the symbol:

|I> |Q>
Lecture 6: The Quantum Fourier Transform – p.11/16 Lecture 6: The Quantum Fourier Transform – p.12/16
QFT Circuit Two Qubit QFT

The circuit which performs the QFT is drawn as follows: The circuit which implements the two-qubit QFT is:
H R2 Rn-1 R n H R2
H Rn-2 Rn-1 |I> |Q>
H
|I> |Q>
• What is the corresponding transformation matrix?
H R2
• We split things up as we have done previously:
H
H R2
|I> |A> |B> |C> |Q>
Let’s look in detail at an example of this H
• With |A# = U1 |I#, |B# = U2 |A#, |C# = U3 |B# and |Q# = U4 |C#
 
1 0 0 0
0 1 0 0
• We already know that U2 = R2 =  
0 0 1 0
 

0 0 0 i
Lecture 6: The Quantum Fourier Transform – p.13/16 Lecture 6: The Quantum Fourier Transform – p.14/16

Two Qubit QFT Conclusions

• It is easy to show that In this lecture we have:


      • Introduced the Discrete Fourier Transform
1 0 1 0 1 1 0 0 1 0 0 0 • Shown how to apply it to quantum states (the Quantum Fourier
1 0 1 0 1 1 1 −1 0 0 0 0 1 0
U1 = √ 

U3 = √ 

U4 = 
  Transform
2 1 0 −1 0  2 0 0 1 1 0 1 0 0
  
• Shown how to implement the QFT using quantum logic gates
0 1 0 −1 0 0 1 −1 0 0 0 1
Next lecture we will:

1 1 1 1
 • Introduce the first of our applied quantum algorithms, Grover’s Algorithm,

1 i −1 −i  which can perform searches in time O( N )
• Then we have that F = U4 U3 U2 U1 = 1  
2 1 −1 1 −1
 

1 −i −1 i
• This is the same as we obtained by doing the calculation directly, and we
have verified that this circuit does indeed perform the QFT

Lecture 6: The Quantum Fourier Transform – p.15/16 Lecture 6: The Quantum Fourier Transform – p.16/16
Introduction

Last lecture, we:


• Introduced the Quantum Fourier Transform
Lecture 7: Shor’s Factorisation Algorithm
In this lecture we will:
Dr Iain Styles: I.B.Styles@cs.bham.ac.uk • Use the QFT to solve the period-finding problem
• Show how period finding leads to Shor’s algorithm for number factoring

Lecture 7: Shor’s Factorisation Algorithm – p.1/15 Lecture 7: Shor’s Factorisation Algorithm – p.2/15

The Factoring Problem Period Finding

• The RSA cryptosystem relies on our inability to find the prime factors of • The key idea underlying Shor’s algorithm is that of period finding
very large numbers • Suppose a function f (x) = f (x + r), e.g. a sine wave
• There are no classical algorithms which can do this efficiently • f (x) is said to have period r
• The best is the number field sieve, which factors a number n in • Classically, finding r is very hard: all we can do is test the function at
1 2
O(exp(n 3 log 3 n)) operations many different places and find the period in this way
• This is exponential in n and it is impossible to factor even modest • A Quantum Computer can do very much better than this
numbers, making RSA very secure • It can compute f (x) for all values of x in a single parallel computation
• It transpires that there is a quantum factoring algorithm due to Shor
• This makes finding the period easy
which is much better
• Shor’s algorithm can factor n in O(n2 log n log log n) operations • It turns out that the factoring problem reduces to finding the period of a
special function!
• This is exponentially faster than the number field sieve
• So how do we find the period, r of a function?
• Factoring now becomes a tractable problem!

Lecture 7: Shor’s Factorisation Algorithm – p.3/15 Lecture 7: Shor’s Factorisation Algorithm – p.4/15
Period Finding Evaluating f (x) in parallel

• Start with two qubit registers of size n (large enough to hold some • Now we operate on |ψ! with some unitary operator which calculates f (x)
number N ) and puts it in the second register:
• Prepare these registers both in state |0!.
Uf |x! |0! = |x! |f (x)!
• The composite system then has state |ψ! = |0! |0!
1000007107
14
• First we apply the QFT to the first register. Recall that the QFT is • The total state of the system is then

ω−1
N −1
1 ! 1 !

11711271137
yk = √ xj e2πijk/N |ψ! = √ |x! |f (x)!

E216071
ω x=0
N j=0

I
• Then the state after QFT is too • We’ve calculated f (x) for all ω = 2n values of x in one go!
• For 100 qubits, this is 2100 calculations in parallel!
ω−1
1 ! • But we can’t see the results of all the calculations due to the way
|ψ! = √ |x! |0!
ω j=0 measurement works
• Nonetheless, measuring the system is useful!
• where ω = 2n

Lecture 7: Shor’s Factorisation Algorithm – p.5/15 Lecture 7: Shor’s Factorisation Algorithm – p.6/15

Making the Measurement Making the Measurement

• Make a measurement of the second register, giving answer f (x) = u • It follows that
"m−1 "2
• The second register must collapse onto state |u! 1 "" ! 2πikry/2n ""
p(y) = √ e
2n m " k=0
" "
• The first register must collapse into a superposition of all values of x "
which give f (x) = u: • Maxima when y ≈ j2n /r (j an integer)

AI
m−1 • Measurement likely to give j2n /r
1 !
|ψ! = √ |x0 + kr! |u!
m • Easy to deduce r as long as j and r have no common factors
k=0
• If they do, the algorithm fails and we must run it again and hope for better
• Contents of first register are periodic: apply QFT to obtain the spectrum luck when we measure!
• So we can use a QC to find the period of a function
m−1 2 −1
n
1 ! 1 ! 2πi(x0 +kr)y/2n
|ψ! = √ e |y! • A careful choice of f(x) can allow us to solve the number factoring
m 2n/2
k=0 y=0 problem
1
2!n
−1 m−1
n !
• Choose f (x) = ax mod N , where N is the number to be factored and
e2πix0 y/2 e2πikry/2 |y!
n
= √ a < N is a random number, then the period r can be used to find the
2n m y=0 k=0
prime factors of N
Lecture 7: Shor’s Factorisation Algorithm – p.7/15 Lecture 7: Shor’s Factorisation Algorithm – p.8/15
Shor’s Algorithm Factoring 39

The stages of Shor’s Algorithm are as follows: • First, let’s make sure we can’t do this efficiently classically
1. If N is even, return the factor 2 • 39 is not even, and it cannot be written as y b for integers y and b
b • Therefore we cannot factor 39 efficiently classically
2. Determine whether N = y for integers y ≥ 1, b ≥ 2. If so, return y
3. Choose 1 ≤ a ≤ N − 1. If gcd(a, N ) > 1, return gcd(a, N ) • Choose a = 7, so that gcd(a, N ) = 1
4. Compute the period r of f (x) = ax mod N • Choose n = 10 so that the register is big enough. Note that the bigger n
we choose, the greater the accuracy of our calculations
5. If r is even, and ar/2 mod N '= −1 mod N , then compute
gcd(ar/2 ± 1, N ). For most a, ar/2 ± 1 share a common factor with n. • Initially, we start with |ψ! = |0! |0!. Applying the QFT to the first register
Otherwise the algorithm has failed and we must run it again. gives us
10
2 −1
• Note that efficient classical algorithms exist for stages 1,2, and for finding 1 !
|ψ! = |x! |0!
the gcd 25 x=0
• We are in desparate need of an example to show how this works! • Now compute f (x) = ax mod N and put the result in the second register
• Let’s try to factor N = 39

Er
10
2 −1
1 !
|ψ! = |x! |f (x)!
25 x=0
Lecture 7: Shor’s Factorisation Algorithm – p.9/15 Lecture 7: Shor’s Factorisation Algorithm – p.10/15

Factoring 39 Factoring 39

• The values of f (x) are: • The probability distribution of all possible measurements of the first
register is now
x 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 −6
x 10
f (x) 1 7 10 31 22 37 25 19 16 34 4 28 1 7 10 31 2

• In fact, it’s quite easy to see that since we are looking for r , where
f (x) = f (x + r), that in this case r = 12
Fante 1 1.5
• Nonetheless, let us continue to show how the algorithm works
• We measure f (x) and find (say), that f (x) = 22. Then:

p(x)
1

1
|ψ! = √ [|4! + |16! + |28! + |40! + . . . ] |22!
m 0.5

• We then apply the Inverse QFT.


• This leads to a probability distribution of all possible measurements on 0
0 200 400 600 800 1000 1200
x
the first qubit
• A highly likely measurement is y = 85
Lecture 7: Shor’s Factorisation Algorithm – p.11/15 Lecture 7: Shor’s Factorisation Algorithm – p.12/15
Factoring 39 Some Additional Notes

• Now remember that measuring the first register will give some y = j2n /r • Shor’s algorithm works! Most of the time.
• So j/r ≈ 85/2 ≈ 1/12, giving us period r = 12
10 • There are several causes of potential error
• The proper way to do this is to use continued fractions - see Appendix K • Firstly, when you measure the first register at the end, there is a finite
of Mermin’s book. probability of getting a bad result (i.e. not one of the peaks)
• So we’ve found the period of f (x). Now let’s find the factors of N • Secondly, j and r might have a common factor, making it impossible to
• Referring to step 5 of Shor’s algorithm, we note that r is even. We find r alone
compute ar/2 mod N = 76 mod 39 = 25, which is not equal to −1 • Both of these problems can be solved with some additional complexity:
mod N = 38 see Nielsen & Chuang for more details
• Finally, we compute gcd(ar/2 ± 1, N ), giving gcd(ar/2 − 1, N ) = 3, and • In practice, you use continued fractions to find r from the final
gcd(ar/2 + 1, N ) = 13 measurement. This is a little tricky and time consuming, but is what you’d
do on a computer.
• So 39 = 3 × 13
• On a classical computer, this would be very inefficient: it is the parallel
computation of f (x) which makes this algorithm fast on a quantum
computer

Lecture 7: Shor’s Factorisation Algorithm – p.13/15 Lecture 7: Shor’s Factorisation Algorithm – p.14/15

Conclusions

In this lecture we have:


• Shown how to use a Quantum Computer to find the period of a function
• Shown how period finding can be used to compute the factors of a
(large) number in an efficient manner
• Proved that 39 = 3 × 13!
Next lecture we will
• Show how Quantum Computers can perform efficient searches.

Lecture 7: Shor’s Factorisation Algorithm – p.15/15

Вам также может понравиться