In order to keep advancing in our study of quantum algorithms, we now have to visit something called the fourier transform. The fourier transform is a mathematical tool that is well used outside of quantum computing but will prove useful for us.
Specifically, we will find that quantum computers are able to implement a special quantum version of the fourier transform that will be aplicable to many problems.
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.
We will define the quantum fourier transform as follows:
∣y⟩=N1j=0∑N−1ωNyj∣j⟩
This looks fairly similar, but notice that we have yj in the omega exponent rather than jk like we did earlier. This is because instead of transforming a discrete sequence of numbers we are transforming a superposition quantum state.
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.
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:
∣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:
∣y⟩=N1l=1⨂njl=0∑1e2πiy2−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:
∣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.
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/2SWAP gates to move the positions of the qubits.
Great! So we've found a circuit that implements the quantum fourier transform!
We apply n gates to the first qubit, n−1 gates to the 2nd etc. followed by n/2SWAP gates so we end up using a total of (n+(n−1)+…+2+1)+n/2=2n(n+1)+n/2=21n2+n gates. So this is fairly efficient, no exponential scaling.
We'll begin exploring in the next articles how this quantum fourier transform can be used.