It can be difficult, at first, to understand the quantum
Fourier transform, as well as its circuit decomposition.
And here we are going to take a look at a
geometric picture for deriving the coefficients
of the quantum Fourier transform,
and a little example on two qubits.
So, let’s begin with this mathematical formula
which tells us what the quantum Fourier transform
on k qubits is doing.
It’s taking a state that represents an integer z.
So, for instance on three qubits the state
7 would be 1 1 1, the state two would be 0 1 0, etcetera.
And we map the integer z to a superposition
that is uniform in magnitude but varies in phase.
And here is the formula for evaluating that phase.
And we have a superposition
over all the computational basis states b.
The states from 0 0 0 up to 1 1 1,
in the regular old set eigenbasis.
This can be a little bit opaque and hard to understand,
but it gets easier if we look at an example on two qubits.
Here we have the matrix for the
quantum Fourier transform on two qubits.
It’s just a half.
Which is 1 over 2^k with k equals 2,
when squared rooted it cancels out the 2, you just get 2.
And we have the columns 1 1 1 1,
which is what happens if I multiply every integer b
by zero and then take e^(2 pi i) times zero.
And then to understand the rest of the coefficients.
We can understand z, the input,
as a speed at which the quantum Fourier
transform proceeds around the unit circle.
So, if we have 0 1, the one state.
The quantum Fourier transform
will take 1 step at a time on this diagram.
So, it will be 1 i -1 -i, as we see here 1 i -1 -i.
If we take two steps at a time for the input state 2,
it were 1 0 on two qubits.
We end up with 1 -1 1 -1,
exactly as we see on the two-state here.
If we take 3 steps at a time
on a circle with four points on it,
that is actually the same as 1 step backwards.
And we can see that we have 1 -i -1 i
in the coefficients in the final column of the matrix.
Now we went over a little bit over
how to decompose this into a circuit,
but I figured I do it concretely here for you.
We have a Hadamard gate,
a controlled square root of Z,
another Hadamard gate on the target 
qubit of the controlled square root of Z,
and then a swap gate at the end.
Now the swap gate at the end
wouldn’t always appear in different figures
that you might see in research papers or textbooks,
or courses for example,
because it is often assumed
that you can do swap gates like this one
classically just by relabeling
which qubits are which at the end.
But for the sake of completeness, I included it here.
Now we can calculate the result of 
performing these four gates in order
simply by putting the matrices in the reverse
of the order in which they appear in the circuit.
So, we have swap, identity tensor Hadamard,
the controlled square root of Z,
and Hadamard tensor identity here.
And I invite you to multiply these four matrices
by yourself and observe that they do indeed recreate the
quantum Fourier transform on two qubits.
Now if that is too easy, let’s do another
challenge or let’s have you do another challenge.
In which you decompose, into a circuit, 
the quantum Fourier transform on one qubit.
Now on one qubit,
you have 1 over root 2, because k is just 1.
And then you can either proceed
around the unit circle 0 steps at the time,
staying at one, or one step at the time but missing this i.
So, you would just go from 1 to minus 1.
And if you can find a circuit decomposition for that,
we may have already discussed it in the course,
then you are well underway to 
understanding the quantum Fourier transform.
