math¶
A tiny math library which will be extended thoughout the next weeks. Right now, it only contains the math functions necessary to run Beauregard’s implementation of Shor’s algorithm.
Module contents¶
-
class
projectq.libs.math.
AddConstant
(a)¶ Add a constant to a quantum number represented by a quantum register, stored from low- to high-bit.
Example
qunum = eng.allocate_qureg(5) # 5-qubit number X | qunum[1] # qunum is now equal to 2 AddConstant(3) | qunum # qunum is now equal to 5
-
__init__
(a)¶ Initializes the gate to the number to add.
Parameters: a (int) – Number to add to a quantum register. It also initializes its base class, BasicMathGate, with the corresponding function, so it can be emulated efficiently.
-
get_inverse
()¶ Return the inverse gate (subtraction of the same constant).
-
-
class
projectq.libs.math.
AddConstantModN
(a, N)¶ Add a constant to a quantum number represented by a quantum register modulo N.
The number is stored from low- to high-bit, i.e., qunum[0] is the LSB.
Example
qunum = eng.allocate_qureg(5) # 5-qubit number X | qunum[1] # qunum is now equal to 2 AddConstantModN(3, 4) | qunum # qunum is now equal to 1
-
__init__
(a, N)¶ Initializes the gate to the number to add modulo N.
Parameters: - a (int) – Number to add to a quantum register (0 <= a < N).
- N (int) – Number modulo which the addition is carried out.
It also initializes its base class, BasicMathGate, with the corresponding function, so it can be emulated efficiently.
-
get_inverse
()¶ Return the inverse gate (subtraction of the same number a modulo the same number N).
-
-
class
projectq.libs.math.
MultiplyByConstantModN
(a, N)¶ Multiply a quantum number represented by a quantum register by a constant modulo N.
The number is stored from low- to high-bit, i.e., qunum[0] is the LSB.
Example
qunum = eng.allocate_qureg(5) # 5-qubit number X | qunum[2] # qunum is now equal to 4 MultiplyByConstantModN(3,5) | qunum # qunum is now 2.
-
__init__
(a, N)¶ Initializes the gate to the number to multiply with modulo N.
Parameters: - a (int) – Number by which to multiply a quantum register (0 <= a < N).
- N (int) – Number modulo which the multiplication is carried out.
It also initializes its base class, BasicMathGate, with the corresponding function, so it can be emulated efficiently.
-
-
projectq.libs.math.
SubConstant
(a)¶ Subtract a constant from a quantum number represented by a quantum register, stored from low- to high-bit.
Parameters: a (int) – Constant to subtract Example
qunum = eng.allocate_qureg(5) # 5-qubit number X | qunum[2] # qunum is now equal to 4 SubConstant(3) | qunum # qunum is now equal to 1
-
projectq.libs.math.
SubConstantModN
(a, N)¶ Subtract a constant from a quantum number represented by a quantum register modulo N.
The number is stored from low- to high-bit, i.e., qunum[0] is the LSB.
Parameters: - a (int) – Constant to add
- N (int) – Constant modulo which the addition of a should be carried out.
Example
qunum = eng.allocate_qureg(3) # 3-qubit number X | qunum[1] # qunum is now equal to 2 SubConstantModN(4,5) | qunum # qunum is now -2 = 6 = 1 (mod 5)