12 #ifndef QNLP_ARITHMETIC 13 #define QNLP_ARITHMETIC 21 template <
class SimulatorType>
24 using CST =
const std::size_t;
35 std::size_t num_qubits_r1 = r1_max - r1_min;
36 std::size_t num_qubits_r2 = r2_max - r2_min;
38 assert( num_qubits_r1 == num_qubits_r2 );
40 qSim.applyQFT(r2_min, r2_max);
44 for(
int i = r2_max; i >= (int) r2_min; i--){
46 for(
int j = r1_max - (r2_max - i); j >= (int) r1_min; j--){
47 theta = 2.0*M_PI / (std::size_t) (1<<(1 + (i-j)));
48 qSim.applyGateCPhaseShift(theta, j, i);
52 qSim.applyIQFT(r2_min, r2_max);
64 static void sub_reg(SimulatorType& qReg,
const unsigned int r1_min,
const unsigned int r1_max,
const unsigned int r2_min,
const unsigned int r2_max){
65 std::size_t num_qubits_r1 = r1_max - r1_min;
66 std::size_t num_qubits_r2 = r2_max - r2_min;
68 assert( num_qubits_r1 == num_qubits_r2 );
71 for(
int i = r1_min; i < r1_max; i++){
74 sum_reg(qReg, r1_min, r1_max, r2_min, r2_max);
76 for(
int i = r2_min; i < r2_max; i++){
80 for(
int i = r1_min; i < r1_max; i++){
static void sum_reg(SimulatorType &qSim, CST r1_min, CST r1_max, CST r2_min, CST r2_max)
Implements |r1>|r2> -> |r1>|r1+r2>. Required bits to represent |r1+r2> should be available prior to c...
Class definition for bit-wise summation and subtraction of qubits.
static void sub_reg(SimulatorType &qReg, const unsigned int r1_min, const unsigned int r1_max, const unsigned int r2_min, const unsigned int r2_max)
Implements |r1>|r2> -> |r1>|r1-r2>. If r1 < r2 the state will underflow, with the subtraction continu...