10 Discrete Fourier Transformation
In Chapter 11, we will discuss Shor’s algorithm, which requires the Discrete Fourier Transformation (DFT). Generally, a Fourier transformation is a mathematical technique that decomposes a function into its constituent frequencies. We use the DFT to find the period of a vector.
10.1 Definition of the DFT
The DFT is defined as follows:
It applies \(\omega^N=1\) and \(\omega^i \neq 1\) for all \(0 < i < N\).
This transformation is best imagined as a process that takes a periodic vector as an input and outputs the period of that vector. The DFT has some important properties which will help us later on.
10.2 Constructing the DFT
So far we have described everything necessary for Shor’s algorithm, but only described the matrix representation of the \(\operatorname{DFT}_N\). We will now take a closer look into implementing the \(\operatorname{DFT}_M\) as a quantum circuit. Since we only use the \(\operatorname{DFT}_N\) for Shor’s algorithm so far, we will only look at \(N=2^n\), which is the \(\operatorname{DFT}\) applied on \(n\) qubits.
To start the circuit, we recall the definition of the \(\operatorname{DFT}_N\) from Definition 10.1: \(\operatorname{DFT}_N \coloneqq \frac{1}{\sqrt{{2^n}}} (\omega^{kl})_{kl}\) with \(\omega \coloneqq e^{2\pi i / 2^n}\). To apply the \(\operatorname{DFT}_N\) to a quantum state \(\ket{j}\) we calculate \[ \begin{aligned} \operatorname{DFT}_{N}\ket{j} =& \frac{1}{\sqrt{N}} \sum_{k=0}^{N-1} \omega^{jk} \ket{k}\\ =& \frac{1}{\sqrt{N}} \sum_{k=0}^{N-1} e^{2\pi i j k / N} \ket{k}\\ =& \frac{1}{\sqrt{N}} \sum_{k_1 \in \{0,1\}} \dots \sum_{k_n \in \{0,1\}} e^{2\pi i j (\sum_{l=1}^n k_l 2^{-l})} \ket{k_1 \dots k_n}\\ =& \frac{1}{\sqrt{N}} \sum_{k_1 \in \{0,1\}} \dots \sum_{k_n \in \{0,1\}} \bigotimes_{l=1}^n e^{2\pi i j k_l 2^{-l}} \ket{k_l}\\ =& \frac{1}{\sqrt{N}} \bigotimes_{l=1}^n \sum_{k_l \in \{0,1\}} e^{2\pi i j k_l 2^{-l}} \ket{k_l}\\ =& \frac{1}{\sqrt{N}} \bigotimes_{l=1}^n (\ket{0} + e^{2\pi i j 2^{-l}} \ket{1})\\ =& \frac{1}{\sqrt{N}} \bigotimes_{l=1}^n (\ket{0} + e^{2\pi i 0.j_{n-l+1} \dots j_{n}} \ket{1}). \end{aligned} \] The expression \(0.j\) expresses a binary fraction (e.g. \(0.101 = \frac{1}{2} + \frac{1}{8} = \frac{5}{8}\)).
With this we have shown, that we can write \(\operatorname{DFT}_N \ket{j}\) as the following tensor product of quantum states
\[ \frac{1}{\sqrt{2}}(\ket{0} + e^{2\pi i 0.j_n} \ket{1}) \otimes \frac{1}{\sqrt{2}}(\ket{0} + e^{2\pi i 0.j_{n-1}j_n} \ket{1}) \otimes \dots \otimes \frac{1}{\sqrt{2}}(\ket{0} + e^{2\pi i 0.j_1\dots j_n} \ket{1}). \]
From this rewritten tensor product, we can get an idea on how to construct the quantum circuit for the \(\operatorname{DFT}_N\). Namely, we can construct a quantum circuit for each element of the tensor product and from this build the general circuit.
For this, we segment the tensor product into different elements \(\psi\) as follows:
\[ \underbrace{\frac{1}{\sqrt{2}}(\ket{0} + e^{2\pi i 0.j_n} \ket{1})}_{\psi_1} \otimes \underbrace{\frac{1}{\sqrt{2}}(\ket{0} + e^{2\pi i 0.j_{n-1}j_n} \ket{1})}_{\psi_2} \otimes \dots \otimes \underbrace{\frac{1}{\sqrt{2}}(\ket{0} + e^{2\pi i 0.j_1\dots j_n} \ket{1})}_{\psi_n}. \]
We also introduce a new gate \(R_k\) which is defined by the following matrix:
\[ R_k:=\begin{pmatrix} 1 & 0 \\ 0 & e^{2 \pi i / 2^k} \end{pmatrix}. \]
To understand the construction of the circuit from these elements, we will look at an example for \(n=3\) first:
The more general approach to construct the \(\operatorname{DFT}_N\) as a quantum circuit with \(n\) qubits (\(N = 2^n\)) works as follows:
- Initialize wires with input \(\ket{j}\), so that \(\ket{j_1}\) is on the top wire and \(\ket{j_n}\) is on the bottom wire. Note, that this is not part of the circuit yet.
- Start with the top wire. For each wire \(j_i\) do the following:
- Apply a Hadamad-gate on the wire \(j_i\).
- For each wire \(j_k\) below the current wire \(j_i\) (with \(i < k \leq n\)), add a \(R_{k-i+1}\)-gate controlled by \(j_k\). Start with \(k = i+1\) (if \(i<n\), else stop).
- Perform a \(\operatorname{SWAP}\) to flip all the wires. This means, that the first wire is swapped with the last wire, the second wire is swapped with the second to last wire and so on.
Note: If the the output of the DFT circuit is measured right after applying it (as in Shor’s algorithm) or if the rest of the algorithm allows for it, it is more efficient to perform the \(\operatorname{SWAP}\) classically, since this is considered to be the cheaper operation.
The more general layout of the quantum circuit for the \(\operatorname{DFT_N}\) with the \(\operatorname{SWAP}\) is shown in this figure.