<h1>Quantum Fourier Transform</h1>


```
%load_ext sympyprinting
```


```
from sympy import sqrt, symbols, Rational
from sympy import expand, Eq, Symbol, simplify, exp, sin
from sympy.physics.quantum import *
from sympy.physics.quantum.qubit import *
from sympy.physics.quantum.gate import *
from sympy.physics.quantum.grover import *
from sympy.physics.quantum.qft import QFT, IQFT, Fourier
from sympy.physics.quantum.circuitplot import circuit_plot
```

QFT is useful for a quantum algorithm for factoring numbers which is exponentially faster than what is thought to be possible on a classical machine.<br>
The transform does a DFT on the state of a quantum system<br>
There is a simple decomposition of the QFT in terms of a few elementary gates.

<h2>QFT Gate and Circuit</h2>

Build a 3 qubit QFT and decompose it into primitive gates.


```
fourier = QFT(0,3).decompose(); fourier

```


```
circuit_plot(fourier, nqubits=3)
```

The QFT circuit can be represented in various symbolic forms.


```
m = represent(fourier, nqubits=3)
```


```
m
```




$$\left(\begin{smallmatrix}\frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2}\\\frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} e^{\frac{1}{4} \mathbf{\imath} \pi} & \frac{1}{4} \sqrt{2} \mathbf{\imath} & \frac{1}{4} \sqrt{2} \mathbf{\imath} e^{\frac{1}{4} \mathbf{\imath} \pi} & - \frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} e^{\frac{1}{4} \mathbf{\imath} \pi} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} e^{\frac{1}{4} \mathbf{\imath} \pi}\\\frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} \mathbf{\imath} & - \frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} & \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} \mathbf{\imath} & - \frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} \mathbf{\imath}\\\frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} \mathbf{\imath} e^{\frac{1}{4} \mathbf{\imath} \pi} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} & \frac{1}{4} \sqrt{2} e^{\frac{1}{4} \mathbf{\imath} \pi} & - \frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} e^{\frac{1}{4} \mathbf{\imath} \pi} & \frac{1}{4} \sqrt{2} \mathbf{\imath} & - \frac{1}{4} \sqrt{2} e^{\frac{1}{4} \mathbf{\imath} \pi}\\\frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2}\\\frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} e^{\frac{1}{4} \mathbf{\imath} \pi} & \frac{1}{4} \sqrt{2} \mathbf{\imath} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} e^{\frac{1}{4} \mathbf{\imath} \pi} & - \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} e^{\frac{1}{4} \mathbf{\imath} \pi} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} & \frac{1}{4} \sqrt{2} \mathbf{\imath} e^{\frac{1}{4} \mathbf{\imath} \pi}\\\frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} & - \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} \mathbf{\imath} & \frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} & - \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} \mathbf{\imath}\\\frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} e^{\frac{1}{4} \mathbf{\imath} \pi} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} & - \frac{1}{4} \sqrt{2} e^{\frac{1}{4} \mathbf{\imath} \pi} & - \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} \mathbf{\imath} e^{\frac{1}{4} \mathbf{\imath} \pi} & \frac{1}{4} \sqrt{2} \mathbf{\imath} & \frac{1}{4} \sqrt{2} e^{\frac{1}{4} \mathbf{\imath} \pi}\end{smallmatrix}\right)$$




```
represent(Fourier(0,3), nqubits=3)*4/sqrt(2)

```




$$\left(\begin{smallmatrix}1 & 1 & 1 & 1 & 1 & 1 & 1 & 1\\1 & \omega & \omega^{2} & \omega^{3} & \omega^{4} & \omega^{5} & \omega^{6} & \omega^{7}\\1 & \omega^{2} & \omega^{4} & \omega^{6} & 1 & \omega^{2} & \omega^{4} & \omega^{6}\\1 & \omega^{3} & \omega^{6} & \omega & \omega^{4} & \omega^{7} & \omega^{2} & \omega^{5}\\1 & \omega^{4} & 1 & \omega^{4} & 1 & \omega^{4} & 1 & \omega^{4}\\1 & \omega^{5} & \omega^{2} & \omega^{7} & \omega^{4} & \omega & \omega^{6} & \omega^{3}\\1 & \omega^{6} & \omega^{4} & \omega^{2} & 1 & \omega^{6} & \omega^{4} & \omega^{2}\\1 & \omega^{7} & \omega^{6} & \omega^{5} & \omega^{4} & \omega^{3} & \omega^{2} & \omega\end{smallmatrix}\right)$$



<h2>QFT in Action</h2>

Build a 3 qubit state to take the QFT of.


```
state = (Qubit('000') + Qubit('010') + Qubit('100') + Qubit('110'))/sqrt(4); state

```

Perform the QFT.


```
qapply(fourier*state)

```

9a74d60dd82411b006e98c39946a2a5209b612ed
ipynb
Jupyter Notebook
docs/examples/notebooks/qft.ipynb
tinyclues/ipython
71e32606b0242772b81c9be0d40751ba47d95f2c
BSD-3-Clause-Clear
2016-05-26T10:57:18.000Z
2016-05-26T10:57:18.000Z
docs/examples/notebooks/qft.ipynb
adgaudio/ipython
a924f50c0f7b84127391f1c396326258c2b303e2
BSD-3-Clause-Clear
docs/examples/notebooks/qft.ipynb
adgaudio/ipython
a924f50c0f7b84127391f1c396326258c2b303e2
BSD-3-Clause-Clear
Qwen/Qwen-72B
1. YES
2. YES