QUBO++ Library with QUBO Solver APIs
Author: Koji Nakano, License: Non-commercial research and evaluation purposes without any guarantees.
Classes | Functions
qbpp::factorization Namespace Reference

Namespace for factorization using QUBO++ library. More...

Classes

class  SolHolder
 Solution holder to store the best solution of factorization. More...
 
class  ABS2Callback
 Class to define ABS2 callback function for factorization. More...
 
class  GRB_Callback
 Class to define Gurobi callback function for factorization. More...
 

Functions

Expr and_gate (const Expr &a, const Expr &b, Var x, MapList &opt_sol)
 Function to generate a QUBO expression Expr object for the AND gate. More...
 
Expr half_adder (const Expr &x, const Expr &y, Var s, Var c, MapList &opt_sol)
 Function to generates a QUBO expression Expr object for the Half Adder. More...
 
Expr full_adder (const Expr &x, const Expr &y, const Expr &z, Var s, Var c, MapList &opt_sol)
 Function to generate a QUBO expression Expr object for the Full Adder. More...
 
template<typename T , typename U >
Expr adder (const qbpp::Vector< T > &x, const qbpp::Vector< U > &y, const qbpp::Vector< Var > &s, const qbpp::Vector< Var > &c, MapList &opt_sol)
 function to generate QUBO expression for n-bit adder More...
 
template<typename T , typename U >
Expr multiplier (const qbpp::Vector< T > &x, const qbpp::Vector< U > &y, const qbpp::Vector< Var > &z, MapList &opt_sol)
 Function to generate QUBO expression for multiplier. More...
 
std::string toBinaryString (uint64_t num)
 Converts a number to a binary string. More...
 
uint64_t as_uint64 (const qbpp::Sol &sol, const qbpp::Vector< qbpp::Var > &var, bool fix_lsb)
 Converts a vector of Var in a solution to a 64-bit unsigned integer. More...
 
uint64_t as_uint64 (const qbpp::SolHolder &sol_holder, const qbpp::Vector< qbpp::Var > &var, bool fix_lsb)
 Converts a vector of Var in a solution holder to a 64-bit unsigned integer. More...
 
bool is_prime (uint32_t num)
 
uint32_t rand_prime (int size)
 Generates a random prime number of the specified size. More...
 

Detailed Description

Namespace for factorization using QUBO++ library.

Function Documentation

◆ and_gate()

Expr qbpp::factorization::and_gate ( const Expr a,
const Expr b,
Var  x,
MapList opt_sol 
)
inline

Function to generate a QUBO expression Expr object for the AND gate.

Parameters
aThe Expr object of the input.
bThe Expr object of the input.
xThe Var object of the output.
opt_solThe MapList object of the optimal solution.
Returns
Expr satisfying x = a & b

Expr is a binary expression taking the minimum value 0 if x = a & b

Note
opt_sol[x] is determined by opt_sol[a] and opt_sol[b]

Definition at line 26 of file qbpp_multiplier.hpp.

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

◆ half_adder()

Expr qbpp::factorization::half_adder ( const Expr x,
const Expr y,
Var  s,
Var  c,
MapList opt_sol 
)
inline

Function to generates a QUBO expression Expr object for the Half Adder.

Parameters
xThe Expr object of the input.
yThe Expr object of the input.
sThe Var object of the sum output.
cThe Var object of the carry output.
opt_solThe MapList object of the optimal solution.
Returns
Expr satisfying s = x ^ y and c = x & y

Expr is a binary expression taking the minimum value 0 if x, y, s, c satisfy s = x ^ y and c = x & y

Note
opt_sol[s] and opt_sol[c] are determined by opt_sol[x] and opt_sol[y]

Definition at line 43 of file qbpp_multiplier.hpp.

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

◆ full_adder()

Expr qbpp::factorization::full_adder ( const Expr x,
const Expr y,
const Expr z,
Var  s,
Var  c,
MapList opt_sol 
)
inline

Function to generate a QUBO expression Expr object for the Full Adder.

Parameters
xThe Expr object of the input.
yThe Expr object of the input.
zThe Expr object of the input.
sThe Var object of the sum output.
cThe Var object of the carry output.
opt_soloptimal solution of the QUBO expression to be updated
Returns
Expr satisfying s = x ^ y ^ z and c = x & y + y & z + z & x

Expr is a binary expression taking the minimum value 0 if x, y, z, s, satisfy s = x ^ y ^ z and c = x & y + y & z + z & x

Note
opt_sol[s] and opt_sol[c] are determined by opt_sol[x], opt_sol[y] and opt_sol[z]

Definition at line 66 of file qbpp_multiplier.hpp.

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

◆ adder()

template<typename T , typename U >
Expr qbpp::factorization::adder ( const qbpp::Vector< T > &  x,
const qbpp::Vector< U > &  y,
const qbpp::Vector< Var > &  s,
const qbpp::Vector< Var > &  c,
MapList opt_sol 
)

function to generate QUBO expression for n-bit adder

Template Parameters
Tinput type of x: Var or Expr.
Uinput type of y: Var or Expr.
Parameters
xThe input vector of T object.
yThe input vector of U object.
sThe output vector of Var object.
cThe carry vector of Var object.
opt_soloptimal solution of the QUBO expression to be updated.
Returns
Expr satisfying s = x + y and c are carry bits

Expr is a binary expression taking the minimum value 0 if x, y, s, c satisfy s = x + y and c are carry bits

Note
opt_sol[s] and opt_sol[c] are determined by opt_sol[x] and opt_sol[y]. The QUBO expression is generated by the following function calls: full_adder(x[0],y[0],0,s[0],c[0]), full_adder(x[1],y[1],c[0],s[1],c[1]),..., full_adder(x[n-1],y[n-1],c[n-2],s[n-1],c[n-1])

Definition at line 95 of file qbpp_multiplier.hpp.

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

◆ multiplier()

template<typename T , typename U >
Expr qbpp::factorization::multiplier ( const qbpp::Vector< T > &  x,
const qbpp::Vector< U > &  y,
const qbpp::Vector< Var > &  z,
MapList opt_sol 
)

Function to generate QUBO expression for multiplier.

Template Parameters
Tinput type of input vector x: Var or Expr
Uinput type of input vector y: Var or Expr
Parameters
xinput vector of T
yinput vector of U
zinput vector of Var
opt_soloptimal solution of the QUBO expression to be updated
Returns
Expr taking minimum value of 0 if z = x * y

Expr is a binary expression taking the minimum value 0 if z = x * y

Note
opt_sol[z] is determined by opt_sol[x] and opt_sol[y]

Definition at line 122 of file qbpp_multiplier.hpp.

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

◆ toBinaryString()

std::string qbpp::factorization::toBinaryString ( uint64_t  num)

Converts a number to a binary string.

Parameters
numThe number to be easyerted.
Returns
std::string The binary string.

Definition at line 40 of file factorization.cpp.

Here is the caller graph for this function:

◆ as_uint64() [1/2]

uint64_t qbpp::factorization::as_uint64 ( const qbpp::Sol sol,
const qbpp::Vector< qbpp::Var > &  var,
bool  fix_lsb 
)

Converts a vector of Var in a solution to a 64-bit unsigned integer.

Parameters
solThe solution.
varThe vector of Var.
fix_lsbTrue if the LSBs of x, y, and z are fixed to 1.
Returns
uint64_t The 64-bit unsigned integer.

Definition at line 55 of file factorization.cpp.

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

◆ as_uint64() [2/2]

uint64_t qbpp::factorization::as_uint64 ( const qbpp::SolHolder sol_holder,
const qbpp::Vector< qbpp::Var > &  var,
bool  fix_lsb 
)

Converts a vector of Var in a solution holder to a 64-bit unsigned integer.

Parameters
sol_holderThe solution holder.
varThe vector of Var.
fix_lsbTrue if the LSBs of x, y, and z are fixed to 1.
Returns
uint64_t The 64-bit unsigned integer.

Definition at line 75 of file factorization.cpp.

Here is the call graph for this function:

◆ is_prime()

bool qbpp::factorization::is_prime ( uint32_t  num)

Definition at line 80 of file factorization.cpp.

Here is the caller graph for this function:

◆ rand_prime()

uint32_t qbpp::factorization::rand_prime ( int  size)

Generates a random prime number of the specified size.

Parameters
sizeThe number of bits of the prime number.
Returns
uint32_t Random prime number. The MSB is 1.
Note
The prime number is generated by the Miller-Rabin primality test.

Definition at line 89 of file factorization.cpp.

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