The quantum Fourier transform (QFT) is a quantum counterpart
of the classical discrete Fourier transform.
It is defined like so, where ∣x⟩
is an n-qubit computational basis state ∣x1⟩⋯∣xn⟩,
and ωN is an Nth complex root of unity ωNN=1 with N=2n:
∣x⟩→N1k=0∑N−1ωNxk∣k⟩
Note that ∣x⟩ and ∣k⟩ refer to the same basis set;
we use these names to clarify which “space” we are considering.
Furthermore, note the sign of the exponent of ωN,
which is the opposite of the classical DFT convention.
In other words, the forward QFT corresponds to the inverse DFT.
The inverse quantum Fourier transform (iQFT) has a different sign in the exponent:
∣k⟩→N1x=0∑N−1ωN−xk∣x⟩
The above definitions of the QFT and iQFT describe
the effect on a single basis vector ∣x⟩,
so the effect on an abitrary superposition follows from linearity,
e.g. for the QFT:
x=0∑N−1cx∣x⟩→x=0∑N−1cx(N1k=0∑N−1ωNxk∣k⟩)
Classically, such a double sum takes
O(N2)=O(22n) time to evaluate naively,
with a potential improvement to O(NlogN)=O(n2n)
for smarter algorithms.
Quantum computers can do a QFT in O(log2(N))=O(n2) time,
and approximate it in O(nlogn) time.
To find out how, we look at the forward QFT,
which maps a basis state ∣x⟩ to another state ∣x~⟩:
Expanding the exponential-of-a-sum into a product-of-exponentials then yields:
∣x~⟩=2n1k=0∑2n−1j=1∏nexp(i2πx2jkj)∣k⟩
If kj=0, the exponential is zero.
We can thus separate this state into its individual qubits:
∣x~⟩=j=1⨂n21(∣0⟩+exp(2ji2πx)∣1⟩)
Next, we use the trick from before:
decompose x as x12n−1+x22n−2+...+xn20:
∣x~⟩=j=1⨂n21(∣0⟩+exp(i2πr=1∑nxr2n−r−j)∣1⟩)
The factor 2n−r−j may be smaller or bigger than 1,
so it is convenient for us to use the following notation
for non-integer binary numbers.
Note the decimal point in the middle:
[a1⋯ad.ad+1⋯an]=r=1∑nar2d−r
In the above QFT state, the position of the decimal point is d=n−j,
so we write it as:
This suggests a way to implement the QFT using
quantum gates in a circuit.
If the jth qubit is in ∣+⟩=(∣0⟩+∣1⟩)/2,
then for each bit xn−j+r where r∈{1,...,j}:
If xn−j+r=0, do nothing.
If xn−j+r=1, add a relative phase 2π/2r.
The full QFT algorithm therefore proceeds as follows,
for the (n−j+1)‘th input ∣xn−j+1⟩:
Apply the Hadamard gate H.
If xn−j+1=0, this puts the qubit in ∣+⟩.
If xn−j+1=1, this puts the qubit in ∣+⟩,
and then adds a phase π, yielding ∣−⟩.
Apply the phase shift gate Rϕ controlled by xn−j+2,
with angle ϕ=2π/22.
Apply Rϕ controlled by xn−j+3,
with angle ϕ=2π/23…
And so on, until the nth bit xn is reached,
and used to control Rϕ with ϕ=2π/2j.
And so on, for each j∈{1,...,n},
and we reach the above expression for ∣x~⟩.
We started from the (n−j+1)‘th input qubit,
i.e. we read the input in reverse order.
Therefore all the qubits need to be swapped back to front,
either before or after the above algorithm is run.
The quantum circuit to execute the mentioned steps is illustrated below,
excluding the swapping part to get the right order.
Here, Rm means Rϕ with ϕ=2π/2m:
Again, note how the inputs ∣xj⟩ and outputs ∣kj⟩ are in the opposite order.
The complete circuit, including the swapping at the end,
therefore looks like this:
For each of the n qubits, O(n) gates are applied,
so overall the QFT algorithm is O(n2).