Implementing the QFT using Silq
In this section, you are going to learn how to implement the QFT algorithm from the very beginning, considering all the mathematics that we have gone through in the Exploring the QFT section.
In Figure 10.2, you can see a diagram of the QFT. This diagram is a generalized version of the QFT circuit that you saw for the three-qubits case in Figure 10.1 in the preceding section:
Our code for the QFT will be based on Figure 10.2. The Silq implementation of the QFT is fairly intuitive and is very concise in size. Using Hadamard and controlled phasing, we generate the state corresponding to the circuit with the qubits in reverse order. Thus, the reversing of the qubits is done in anticipation at the beginning of the function so that, after applying Hadamard and phasing them, the qubits are outputted in the correct order. The code is as follows:
def QFT[n:!](: int[n])mfree: int[n]...