QNLP  v1.0
qft.hpp
Go to the documentation of this file.
1 
11 #ifndef QNLP_QFT
12 #define QNLP_QFT
13 
14 #include <cmath>
15 
16 namespace QNLP{
22  template <class SimulatorType>
23  class QFT{
24  public:
32  static void applyQFT(SimulatorType& qSim, const unsigned int minIdx, const unsigned int maxIdx){
33  double theta=0;
34 
35  //target lines
36  for(int i = maxIdx; i >= (int) minIdx; i--){
37  qSim.applyGateH(i);
38 
39  //Control lines:
40  for(int j = i-1; j >= (int) minIdx; j--){
41  theta = 2.0*M_PI / (std::size_t) (0b1<<(1+(i-j)));
42  qSim.applyGateCPhaseShift(theta, j, i);
43  }
44  }
45  qSim.InvertRegister(minIdx, maxIdx);
46  }
47 
55  static void applyIQFT(SimulatorType& qSim, const unsigned int minIdx, const unsigned int maxIdx){
56  double theta=0;
57  qSim.InvertRegister(minIdx, maxIdx);
58 
59  //Target lines
60  for(int i = minIdx; i <= (int) maxIdx; i++){
61 
62  //Control lines:
63  for(int j = minIdx; j < i; j++){
64  theta = -2.0*M_PI / (std::size_t) (0b1<<(1+(i-j)));
65  qSim.applyGateCPhaseShift(theta, j, i);
66  }
67  qSim.applyGateH( i );
68  }
69  }
70  };
71 }
72 #endif
static void applyIQFT(SimulatorType &qSim, const unsigned int minIdx, const unsigned int maxIdx)
Applies the inverse QFT on the given register.
Definition: qft.hpp:55
Class definition for performing quantum forward and inverse Fourier transforms.
Definition: qft.hpp:23
static void applyQFT(SimulatorType &qSim, const unsigned int minIdx, const unsigned int maxIdx)
Applies the forward QFT on the given register.
Definition: qft.hpp:32