QNLP  v1.0
QNLP::Arithmetic< SimulatorType > Class Template Reference

Class definition for bit-wise summation and subtraction of qubits. More...

#include <arithmetic.hpp>

Collaboration diagram for QNLP::Arithmetic< SimulatorType >:
Collaboration graph

Public Types

using CST = const std::size_t
 

Static Public Member Functions

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 calling, or overflow will occur. More...
 
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 continuing from |11..1>. More...
 

Detailed Description

template<class SimulatorType>
class QNLP::Arithmetic< SimulatorType >

Class definition for bit-wise summation and subtraction of qubits.

Template Parameters
SimulatorType

Definition at line 22 of file arithmetic.hpp.

Member Typedef Documentation

◆ CST

template<class SimulatorType >
using QNLP::Arithmetic< SimulatorType >::CST = const std::size_t

Definition at line 24 of file arithmetic.hpp.

Member Function Documentation

◆ sub_reg()

template<class SimulatorType >
static void QNLP::Arithmetic< SimulatorType >::sub_reg ( SimulatorType &  qReg,
const unsigned int  r1_min,
const unsigned int  r1_max,
const unsigned int  r2_min,
const unsigned int  r2_max 
)
inlinestatic

Implements |r1>|r2> -> |r1>|r1-r2>. If r1 < r2 the state will underflow, with the subtraction continuing from |11..1>.

Parameters
qRegThe quantum register holding the bitstring to remain unmodified
r1_minThe lowest bounded r1 index to perform Fourier transform on.
r1_maxThe highest bounded r1 index to perform Fourier transform on.
r2_minThe lowest bounded r2 index to perform Fourier transform on.
r2_maxThe highest bounded r2 index to perform Fourier transform on.

Definition at line 64 of file arithmetic.hpp.

64  {
65  std::size_t num_qubits_r1 = r1_max - r1_min;
66  std::size_t num_qubits_r2 = r2_max - r2_min;
67 
68  assert( num_qubits_r1 == num_qubits_r2 );
69 
70  //Flip all states in r1
71  for(int i = r1_min; i < r1_max; i++){
72  qReg.applyGateX(i);
73  }
74  sum_reg(qReg, r1_min, r1_max, r2_min, r2_max);
75  //Flip states to return the sum
76  for(int i = r2_min; i < r2_max; i++){
77  qReg.applyGateX(i);
78  }
79  //Return all qubits in r1 to original state
80  for(int i = r1_min; i < r1_max; i++){
81  qReg.applyGateX(i);
82  }
83  }
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...
Definition: arithmetic.hpp:34

References QNLP::Arithmetic< SimulatorType >::sum_reg().

Referenced by TEST_CASE().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sum_reg()

template<class SimulatorType >
static void QNLP::Arithmetic< SimulatorType >::sum_reg ( SimulatorType &  qSim,
CST  r1_min,
CST  r1_max,
CST  r2_min,
CST  r2_max 
)
inlinestatic

Implements |r1>|r2> -> |r1>|r1+r2>. Required bits to represent |r1+r2> should be available prior to calling, or overflow will occur.

Parameters
qRegThe quantum register holding the bitstrings r1,r2
r1_minThe lowest bounded r1 index to perform Fourier transform on.
r1_maxThe highest bounded r1 index to perform Fourier transform on.
r2_minThe lowest bounded r2 index to perform Fourier transform on.
r2_maxThe highest bounded r2 index to perform Fourier transform on.

Definition at line 34 of file arithmetic.hpp.

34  {
35  std::size_t num_qubits_r1 = r1_max - r1_min;
36  std::size_t num_qubits_r2 = r2_max - r2_min;
37 
38  assert( num_qubits_r1 == num_qubits_r2 );
39 
40  qSim.applyQFT(r2_min, r2_max);
41  double theta = 0.0;
42 
43  //Targets
44  for(int i = r2_max; i >= (int) r2_min; i--){
45  //Controls
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);
49  }
50  }
51 
52  qSim.applyIQFT(r2_min, r2_max);
53  }

Referenced by QNLP::Arithmetic< SimulatorType >::sub_reg(), and TEST_CASE().

Here is the caller graph for this function:

The documentation for this class was generated from the following file: