In order to understand the application of the fourier transform to more applications, we'll first look at an algorithm called order finding.
This algorithm takes a periodic function as input and produces, as output, the period of that function. We'll talk a bit more about exactly what that means in a bit. But first let's go back to an old friend: modular arithmetic.
We first met modular (or clock) arithmetic in our article on fields. Doing arithmetic modulo essentially means only being concerned with the number's remainder when divided by . So we get statements like the following:
This is saying that and are equal (or, more formally, congruent) mod as they both have the same remainder () when divided by .
Order finding, is concerned with this equation:
Specifically, we will choose some value of and and ask: what is ? Put more plainly, this is: how many times do I have to multiply by itself before it gets back to modulo ?
This is a very important question in number theory. We won't dwell too much on all the interesting details, but it is important to note that for some and there is no such . For example, if and , no matter how many times we multiply by itself, it will never get to . This is fairly easy to see since multiplying by and taking a remainder when divided by will always give us an even number, whereas is odd.
It turns out, that only exists if and are co-prime. That is, they share no common factors.
One example would be when and , . This is because:
Find when and
Does exist if and
We call this value the order. Generally, computing the order is really difficult. At least for classical computers. We'll now apply the quantum fourier transform in order to solve it more easily using a quantum computer.
Like a lot of quantum algorithms, lets start by introducing an oracle. Our oracle will be the following:
It's important to note here that the 2 kets represent multiple quantum bits as just having single bit numbers wouldn't be very useful. We'll deliberately leave these two keys separate during our calculations and refer to them as the first/second register.
If we start in a state where all our qubits are and then we apply a Hadamard gate to all the qubits in the first register we get:
Where is the number of qubits in the first register.
Applying our oracle now gives us:
We can then measure the second register. This will produce some value such that for some .
This now means the first register has dropped any states such that
So, where's going to come from in all this? For that, we'll jump back into a little bit of number theory.
Since we know we have that for any numbers and :
So, we know:
This means any value in the first register must now be of the form: for some .
So our state now becomes:
Where is the number of remaining kets.
And now we apply the Quantum Fourier Transform:
That part in the brackets will prove crucial to us now.
If we expand the we get:
In case the text is getting too small, that fraction in the exponent is:
This is a geometric series and we can use the formula for the sum of a geometric series to get:
Now, if is a value very close to an integer multiple of , i.e. for some , we can see the fraction in the exponent at the bottom is near to so the whole fraction gets very large. Otherwise the term is very small.
What this whole exercise essentially tells us is that the co-efficient for terms where is close to will be very large, and the rest will be very small.
This means, upon measuring now the first register, we have a very high probability to measure a state of the form:
Great! That's all the messy quantum stuff out the way, now how do we get from this?
If we let our measurement be then we can simply divide by the known value to get:
Notice we say approximately here. This is because we can't gaurantee we measure an exact multiple, only that our measurement is very close.
Now, if and are not co-prime (i.e. they share a common factor), we can't extract . e.g. if and then is , so our value gets "destroyed" by the common factor cancelling. If we have this problem there's unfortunately no real way of knowing. We'll see later that if we fail in this way we will simply retry the quantum part of the algorithm.
Trying to extract from our value comes with another difficulty: We only used a finite number of bits. If is odd, then has an infinite decimal representation. So it's likely we may end up with an approximate value that is cutoff at some point.
Luckily, we know that and are integers, so our number must be rational. This means we can approximate with the process of continued fractions.
Continued fractions provides a way to develop a sequence of fractions providing better and better approximations to a given number. This also helps because we know we didn't necessarily measure an exact multiple of .
The continued fraction for a number is:
Where the sequence of provides better and better approximations for .
For example, if we can find it's continued fraction with the following method:
Subbing each of those statements into the one above we have:
So our sequence is .
Our approximations are then:
So, continued fractions gives us a list of continuing better approximations for our rational fraction. We can simply read off the denominator of any of them to get a candidate value for . So our three candidate values in this example are: , and .
How do we check a candidate value? Just sub it into our original equation! can be easily computed and checked by a classical computer. If it equals we are done. If it doesn't, we simply move on to our next candidate value.
If all of our candidate values fail, it means either and were not co-prime or our continued fractions approximation was unnsuccesful. In this scenario we just try again.
Now at this point, you're probably confused about this "trying again". Trying again, is not something we do in classical algorithms, but it can still be shown that doing this produces the correct answer quicker than any classical algorithm on average.
In fact, this algorithm actually performs better with bigger numbers! More qubits, produces more "sharp" spikes in the co-efficient of the states and also gives us a closer approximation for the continued fraction process. So whereas a classical algorithm would have to work harder for larger values of and a quantum computer actually gets more accurate making the speedup even more noticeable!
Let's quickly review the steps we went through:
We've skipped over a few details, such as how many qubits we should use and what the probability of success actually is but it's enough for now.
In the next article we'll use what we've learned to factor prime numbers!
> Next Article (Shor's Algorithm)