Download The classical and quantum Fourier transform

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Quantum electrodynamics wikipedia , lookup

Density matrix wikipedia , lookup

Quantum machine learning wikipedia , lookup

Scalar field theory wikipedia , lookup

Quantum computing wikipedia , lookup

Canonical quantization wikipedia , lookup

Probability amplitude wikipedia , lookup

Quantum state wikipedia , lookup

T-symmetry wikipedia , lookup

Quantum teleportation wikipedia , lookup

Quantum group wikipedia , lookup

Symmetry in quantum mechanics wikipedia , lookup

Path integral formulation wikipedia , lookup

Bra–ket notation wikipedia , lookup

Transcript
The classical and quantum Fourier transform
Ronald de Wolf
February 22, 2011
1
The classical Fourier transform
1.1
The discrete Fourier transform
The Fourier transform occurs in many different versions throughout classical computing, in areas
ranging from signal-processing to data compression to complexity theory.
For our purposes, the Fourier transform is going to be an N × N unitary matrix, all of whose
entries have the same magnitude. For N = 2, it’s just our familiar Hadamard transform:
1
1
1
.
F2 = H = √
2 1 −1
Doing something similar in 3 dimensions is impossible with real numbers: we can’t give three
orthogonal vectors in {+1, −1}3 . However, using complex numbers1 allows us to define the Fourier
k =1
transform for any N . Let ωN = e2πi/N be an N -th root of unity (“root of unity” means that ωN
for some integer k, in this case k = N ). The rows of the matrix will be indexed by j ∈ {0, . . . , N −1}
jk
and the columns by k ∈ {0, . . . , N − 1}. and define the (j, k)-entry of the matrix FN by √1N ωN
:


..
.


1 
jk
FN = √  · · · ωN · · · 

N
..
.
Note that FN is a unitary matrix, since each column has norm 1, and any pair of columns (say
those indexed by k and k′ ) is orthogonal:
N −1
N
−1
X
1 X j(k′ −k)
1
1 if k = k′
jk ∗ 1
jk ′
√ (ωN ) √ ωN =
=
ωN
0 otherwise
N
N
N
j=0
j=0
Since FN is unitary and symmetric, the inverse FN−1 = FN∗ only differs from FN by having minus
signs in the exponent of the entries. For a vector v ∈ RN , the vector vb = FN v is called the
Fourier transform of v.2 Doing the matrix-vector multiplication, its entries are given by vbj =
PN −1 jk
√1
k=0 ωN vk .
N
1
A complex number is of the form c = a + bi, where a,√b ∈ R, and i is the imaginary unit, which satisfies i2 = −1.
Such a c can also be written as c = reiφ where r = |c| = a2 + b2 is the magnitude of c, and φ ∈ [0, 2π) is the angle
that c makes with the positive horizontal axis when we view it as a point (a, b) in the plane. Note that complex
numbers of magnitude 1 lie on the unit circle in this plane. We can also write those as eiφ = cos(φ) + i sin(φ). The
complex conjugate c∗ is a − ib, equivalently c∗ = re−iφ .
2
The literature on Fourier analysis usually talks about the Fourier transform of a function rather than of a vector,
1
1.2
The Fast Fourier Transform
The naive way of computing the Fourier transform vb = FN v of v ∈ RN just does the matrixvector multiplication to compute all the entries of vb. This would take O(N ) steps (additions and
multiplications) per entry, and O(N 2 ) steps to compute the whole vector vb. However, there is a
more efficient way of computing b
v . This algorithm is called the Fast Fourier Transform (FFT), and
takes only O(N log N ) steps. This difference between the quadratic N 2 steps and the near-linear
N log N is tremendously important in practice, and is the main reason that Fourier transforms are
so widely used.
We will assume N = 2n , which is usually fine because we can add zeroes to our vector to make
its dimension a power of 2 (but similar FFTs can be given also directly for most N that aren’t a
power of 2). The key to the FFT is to rewrite the entries of vb as follows:
vbj
=
=
=
N −1
1 X jk
√
ω vk
N k=0 N
1
√
N
1
√
2
X
jk
ωN
vk
even k
+
X
odd k
jk
ωN
vk
!
j
X j(k−1)/2
ωN
1
jk/2
p
vk
ωN/2 vk + p
ω
N/2 even k
N/2 odd k N/2
X
!
Note that we’ve rewritten the entries of the N -dimensional Fourier transform vb in terms of two
N/2-dimensional Fourier transforms, one of the even-numbered entries of v, and one of the oddnumbered entries of v.
This suggest a recursive procedure for computing b
v : first separately compute the Fourier transform v[
of
the
N/2-dimensional
vector
of
even-numbered
entries of v and the Fourier transform
even
vd
odd of the N/2-dimensional vector of odd-numbered entries of v, and then compute the N entries
1
j
vd
vevenj + ωN
vbj = √ ([
oddj ).
2
Strictly speaking this is not well-defined, because v[
even and vd
odd are just N/2-dimensional vectors.
However, if we define v[
[
even j+N/2 = v
evenj (and similarly for vd
odd ) then it all works out.
The time T (N ) it takes to implement FN this way can be written recursively as T (N ) =
2T (N/2) + O(N ), because we need to compute two N/2-dimensional Fourier transforms and do
O(N ) additional operations to compute vb. This works out to time T (N ) = O(N log N ), as promised.
Similarly, we have an equally efficient circuit for the inverse Fourier transform FN−1 = FN∗ .
1.3
Application: multiplying two polynomials
Suppose we are given two real-valued polynomials p and q, each of degree at most d:
p(x) =
d
X
aj xj and q(x) =
j=0
d
X
bk xk
k=0
but on finite domains that’s just a notational variant of what we do here: a vector v ∈ RN can also be viewed as a
function v : {0, . . . , N − 1} → R defined by v(i) = vi . Also, in the classical literature people sometimes use the term
“Fourier transform” for what we call the inverse Fourier transform.
2
We would like to compute the product of these two polynomials, which is


!
2d
d
d
2d X
X
X
X
j
k
aj bℓ−j )xℓ ,
aj x 
bk x
(
(p · q)(x) = 
=
j=0
k=0
ℓ=0 j=0
|
{z
cℓ
}
where implicitly we set bℓ−j = 0 if j > ℓ. Clearly, each coefficient cℓ by itself takes O(d) steps
(additions and multiplications) to compute, which suggests an algorithm for computing the coefficients of p · q that takes O(d2 ) steps. However, using the fast Fourier transform we can do this in
O(d log d) steps, as follows.
N
N
The convolution
PN −1 of two vectors a, b ∈ R is a vector a ∗ b ∈ R whose ℓ-th entry is defined by
1
(a ∗ b)ℓ = √N j=0 aj bℓ−jmodN . Let us set N = 2d + 1 (the number of nonzero coefficients of p · q)
and make the (d + 1)-dimensional vectors of coefficients a and b N -dimensional by adding d zeroes.
Then√the coefficients of the polynomial p · q are proportional to the entries of the convolution:
cℓ = N (a ∗ b)ℓ . It is easy to show that the Fourier coefficients of the convolution of
a and
b are the
d
products of the Fourier coefficients of a and b: for every ℓ ∈ {0, . . . , N −1} we have a ∗ b = b
aℓ ·bbℓ .
ℓ
This immediately suggests an algorithm for computing the vector of coefficients cℓ : apply the FFT
to a and b to get b
a and bb, multiply those √
two vectors entrywise to get ad
∗ b, apply the inverse FFT
to get a∗b, and finally multiply a∗b with N to get the vector c of the coefficients of p ·q. Since the
FFTs and their inverse take O(N log N ) steps, and pointwise multiplication of two N -dimensional
vectors takes O(N ) steps, this whole algorithm takes O(N log N ) = O(d log d) steps.
Note that if two numbers ad · · · a1 a0 and bd · · · b1 b0 are given in decimal notation, then we can
interpret the digits as coefficients of polynomials p and q, respectively, and the two numbers will
be p(10) and q(10). Their product is the evaluation of the product-polynomial p · q at the point
x = 10. This suggests that we can use the above procedure (for fast multiplication of polynomials)
to multiply two numbers in O(d log d) steps, which would be a lot faster than the standard O(d2 )
algorithm for multiplication that one learns in primary school. However, in this case we have to
be careful since the steps of the above algorithm are themselves multiplications between numbers,
which we cannot count at unit cost anymore if our goal is to implement a multiplication between
numbers! Still, it turns out that implementing this idea carefully allows one to multiply two d-digit
numbers in O(d log d log log d) elementary operations. This is known as the Schönhage-Strassen
algorithm. We’ll skip the details.
2
The quantum Fourier transform
Since FN is an N × N unitary matrix, we can interpret it as a quantum operation, mapping an N dimensional vector of amplitudes to another N -dimensional vector of amplitudes. This is called the
quantum Fourier transform (QFT). In case N = 2n (which is the only case we will care about), this
will be an n-qubit unitary. Notice carefully that this quantum operation does something different
from the classical Fourier transform: in the classical case we are given a vector v, written on a piece
of paper so to say, and we compute the vector vb = FN v, and also write the result on a piece of
paper. In the quantum case, we are working on quantum states; these are vectors of amplitudes, but
we don’t have those written down anywhere—they only exist as the amplitudes in a superposition.
We will see below that the QFT can be implemented by a quantum circuit using O(n2 ) elementary
3
gates. This is exponentially faster than even the FFT (which takes O(N log N ) = O(2n n) steps),
but it achieves something different: computing the QFT won’t give us the entries of the Fourier
transform written down on a piece of paper, but only as the amplitudes of the resulting state.
2.1
An efficient quantum circuit
Here we will describe the efficient circuit for the n-qubit QFT. Theelementary gates we will
1
0
. Note that
allow ourselves are Hadamards and controlled-Rs gates, where Rs =
s
0 e2πi/2
1 0
1
0
. Since the QFT is linear, it suffices if our circuit
and R2 =
R1 = Z =
0 i
0 −1
implements it correctly on basis states |ki, i.e., it should map
N −1
1 X jk
|ki 7→ FN |ki = √
ωN |ji.
N j=0
The key to doing this efficiently is to rewrite FN |ki, which turns out to be a product state. Let
|ki = |kP
1 . . . kn i (k1 being the most significant bit). Note that for integer j = j1 . . . jn , we can write
n
j/2 = nℓ=1 jℓ 2−ℓ . For example, binary 0.101 is 1 · 2−1 + 0 · 2−2 + 1 · 2−3 = 5/8. We have
FN |ki =
=
=
N −1
1 X 2πijk/2n
√
e
|ji
N j=0
N −1
1 X 2πi(Pnℓ=1 jℓ 2−ℓ )k
√
e
|j1 . . . jn i
N j=0
N −1 n
1 X Y 2πijℓ k/2ℓ
√
|j1 . . . jn i
e
N j=0 ℓ=1
n
O
1 ℓ
√ |0i + e2πik/2 |1i .
=
2
ℓ=1
ℓ
Note that e2πik/2 = e2πi0.kℓ ...kn : the ℓ − 1 most significant bits of k don’t matter for this.
As an example, for n = 3 we have the 3-qubit product state
1
1
1
F8 |k1 k2 k3 i = √ (|0i + e2πi0.k3 |1i) ⊗ √ (|0i + e2πi0.k2 k3 |1i) ⊗ √ (|0i + e2πi0.k1 k2 k3 |1i).
2
2
2
This example suggests what the circuit should be. To prepare the first qubit of the desired state
F8 |k1 k2 k3 i, just apply a Hadamard to |k3 i, giving state √12 (|0i + (−1)k3 |1i) and observe that
(−1)k3 = e2πi0.k3 . To prepare the second qubit of the desired state, apply a Hadamard to |k2 i, giving
√1 (|0i + e2πi0.k2 |1i), and then conditioned on k3 (before we apply the Hadamard to |k3 i) apply
3
R2 . This multiplies |1i with a phase e2πi0.0k3 , producing the correct qubit √12 (|0i + e2πi0.k2 k3 |1i).
Finally, to prepare the third qubit of the desired state, we apply a Hadamard to |k1 i, apply R2
conditioned on k2 and R3 conditioned k3 . This produces the correct qubit √12 (|0i + e2πi0.k1 k2 k3 |1i).
We have now produced all three qubits of the desired state F8 |k1 k2 k3 i, but in the wrong order : the
4
Figure 1: The circuit for the 3-qubit QFT
first qubit should be the third and vice versa. So the final step is just to swap qubits 1 and 3.
The picture illustrates the circuit in the case n = 3. The general case works analogously: starting
with ℓ = 1, we apply a Hadamard to |kℓ i and then “rotate in” the additional phases required,
conditioned on the values of the later bits kℓ+1 . . . kn . Some swap gates at the end then put the
qubits in the right order.
Since the circuit involves n qubits, and at most n gates are applied to each qubit, the overall
circuit uses at most n2 gates. In fact, many of those gates are phase gates Rs with s ≫ log n,
which are very close to the identity and hence don’t do much anyway. We can actually omit those
from the circuit, keeping only O(log n) gates per qubit and O(n log n) gates overall. Intuitively,
the overall error caused by these omissions will be small (a homework exercise asks you to make
this precise). Finally, note that by inverting the circuit (i.e., reversing the order of the gates and
taking the adjoint U ∗ of each gate U ) we obtain an equally efficient circuit for the inverse Fourier
transform FN−1 = FN∗ .
5