The quantum Fourier transform (QFT) applies a discrete Fourier transform to the amplitudes of a quantum state. It changes how information is encoded in the state, making it a useful building block for algorithms that work with phases and periodicity.
We'll start with the discrete Fourier transform, rewrite the QFT of a computational basis state as a product of single-qubit states, and use that expression to build a circuit with Hadamard and controlled phase gates.
What you will learn
Interpret the complex phase factors in the discrete Fourier transform.
Use binary fractions to derive the QFT's product representation.
Follow the Hadamard, controlled phase and SWAP gates in a QFT circuit.
Understand why the circuit uses a quadratic number of gates in the number of qubits.
The discrete fourier transform is a mathematical operation that takes, as input, a sequence of numbers x0,…,xN−1 and outputs a new sequence of numbers y0,…,yN−1 where:
yk=N1j=0∑N−1xje2πijk/N
Looks scary? Let's break it down.
Firstly, let's revise our complex numbers a bit. Remember that eiθ merely represents a rotation of θ radians around the complex unit circle. Since we know that 2π is a full rotation this means the exponential term is just jk/N full rotations around the circle.
In fact, to make this more obvious we will define a symbol to simplify our equation:
ωN=e2πi/N
So ωN is a 1/N-th rotation around the unit circle. ωN2 is a 2/N-th rotation and so on. We can then also see that ωNN is the same as ωN0 since doing a full rotation is the same as doing no rotation. And from there it's fairly clear that we get relations like: ωN2=ωNN+2=ωN2N+2. So we end up with a circular pattern very similar to the powers of i.
Just to be clear, let's now re-write our original equation with ω:
yk=N1j=0∑N−1xjωNjk
So our fourier transform is starting to make some more sense. Each term yk in the output sequence is a sum of all the input terms xj multiplied by a rotation of jk/N around the unit circle.
The rotation patterns can be seen easier if we look at a concrete example in the case when N=5:
It's not immediately clear what's useful about this. Usually this idea is first presented in a mathematics course where it can be used to analyze signals. In that context, the fourier transform is used to decompose a signal into its constituent frequencies. This is useful because it allows us to understand the signal better and to filter out noise.
For our case though, we'll simply stick with the definition and see how we can apply this to our quantum algorithms. It's use will hopefully become apparent later.
From the discrete transform to the QFT
The quantum Fourier transform is a linear operation. On a computational basis state ∣y⟩, it acts as follows:
QFT∣y⟩=N1j=0∑N−1ωNyj∣j⟩
Here y labels the input basis state, and j runs over the output basis states. The phase factors depend on both indices. For a superposition input, apply this rule to each basis state and add the results with the original amplitudes.
Note also that although y and j are used like normal numbers in this equation, we know that the kets are actually formed of a tensor product of ∣1⟩s and ∣0⟩s that are the binary representation of the number. We should therefore assume that y and j are formed from the same number of bits and therefore N=2n for some n.
Deriving the product representation
To understand how we implement this in a quantum circuit, we will use some algebra to transform this summation formula into a different tensor product form, that will more easily translate into a circuit.
To do this, our first step is to split the j summation into it's individual bits:
QFT∣y⟩=N1j1=0∑1…jn=0∑1ωNyj∣j1,…,jn⟩
Then we'll look at a slightly different representation of our ω term. We know that ωNyj=e2πiyj/N. But since N=2n the division by N here is simply shifting the bits of j to after the decimal point. i.e. if n=4 and j=0101 in binary, then we have j/2n=j/N=0.0101.
In general, this shifting the bits to the right of the decimal point can be represented as:
Since the exponential co-efficient is now represented as a sum ofjs individual bits, we can also separate the ket into a tensor product of the individual bits:
And now, since we know the tensor product stitches together the ∣1⟩s and ∣0⟩s, we can move the tensor product to the outside to do this instead of summing over each bit:
QFT∣y⟩=N1l=1⨂njl=0∑1e2πiyjl2−l∣jl⟩
And now our summation is just for 2 terms, so we can remove the big summation and write it explicitly:
The last step will involve that y2−l term in the exponent. If y has bits y1,…,yn then multiplying by 2−l is shifting these bits l places to the right. e.g. if y=01011 and l=3 we have y2−l=01.011. In general this is of the form: y2−l=y1…yn−l.yn−l+1…yn where the decimal place ends up between the n−lth and n−l+1th digit.
But, notice that this number is multiplying 2πi in the exponent so any whole part of this number (i.e. any number to the left of the decimal point) represents a full rotation so can be ignored. So we end up with:
QFT∣y⟩=N1l=1⨂n[∣0⟩+e2πi0.yn−l+1…yn∣1⟩]
To clean this up, let's drop the big ⊗ symbol and replace N with 2n:
This is the product representation of the quantum fourier transform. It's useful because it better shows the behaviour on individual bits and will allow us to construct a circuit easier.
Building the QFT circuit
To build the circuit, we'll need to invent some new gates. The quantum gates we've studied previously have mostly been focussed with discrete jumps around the Bloch Sphere. As we can see from our equation above, the quantum fourier transform will involve rotations of the phase of the ∣1⟩ state. So let's create the gates:
Rx∣0⟩=∣0⟩Rx∣1⟩=e2πi/2x∣1⟩
So all of these gates leave the ∣0⟩ state alone and rotate the phase of the ∣1⟩ state by a 1/2xth of a full rotation. i.e. R1 rotates ∣1⟩ by 180 degress and R2 rotates ∣1⟩ by 90 degrees etc.
Let's now present the quantum circuit for the quantum fourier transform and then examine why it works:
Notice that our R gates are controlled gates. Just like we've seen other controlled gates previously, these gates only apply their rotation if the control qubit is in the ∣1⟩ state.
To see that this works, let's start by just following the ∣y1⟩ qubit for now.
Applying the first Hadamard gate gives us 21(∣0⟩+e2πi0.y1∣1⟩) since if y1=0 then e2πi0.y1=1 and if y1=1 then e2πi0.y1=−1.
The controlled R2 gate then takes us to 21(∣0⟩+e2πi0.y1y2∣1⟩) since the ∣1⟩ state will undergo a further 90 degree rotation if y2=1.
Continuing on in this fashion, the first qubit ends in the state 21(∣0⟩+e2πi0.y1…yn∣1⟩). Our total state so far is then:
21/2(∣0⟩+e2πi0.y1…yn∣1⟩)∣y2,…,yn⟩
Continuing in this fasion we apply one fewer rotation for each qubit, so following the same steps for the second qubit brings us to:
This is almost what we want, but notice that the qubits are actually backwards compared to our equation from earlier!
This is easily solved by using ⌊n/2⌋SWAP gates to move the positions of the qubits.
After these SWAP gates, the output is QFT∣y⟩. So we've found a circuit that implements the quantum Fourier transform!
How many gates does the QFT need?
We apply n gates to the first qubit, n−1 gates to the 2nd etc. followed by ⌊n/2⌋SWAP gates so we end up using a total of (n+(n−1)+…+2+1)+⌊n/2⌋=2n(n+1)+⌊n/2⌋ gates. So this is fairly efficient, no exponential scaling.
This gives us an O(n2)-gate circuit on n qubits, treating each controlled phase gate as one gate. Its output is a quantum state: measuring it does not reveal every transformed amplitude. This distinction matters when comparing the QFT with a classical Fourier transform that returns a list of numbers.
Related lessons
Order Finding: see how the QFT helps extract periodic structure.
Shor's Algorithm: connect order finding to integer factorisation.
Grover Search: compare a search algorithm based on amplitude amplification.
Quantum algorithms: the chapter that continues from this transform through order finding to Shor's algorithm.