Functions:
modular_add_inplace
modular_add_inplace(
modulus: CInt,
x: Const[QNum],
y: QNum
) -> None
[Qmod Classiq-library function]
Performs the transformation |x>``|y> -> |x>|(x + y mod modulus)>.
Note:
\|x> and \|y> should have values smaller than modulus.
The modulus should satisfy 1 < modulus < 2**n, where n is the size of |x> and |y>.
Implementation based on: https://arxiv.org/pdf/1706.06752 Chapter 3.2 Fig 3
Parameters:
modular_negate_inplace
modular_negate_inplace(
modulus: CInt,
x: QNum
) -> None
[Qmod Classiq-library function]
Performs the transformation |x> -> |(-x mod modulus)>.
Note:
\|x> should have values smaller than modulus.
The modulus should satisfy 1 < modulus < 2**n, where n is the size of |x>.
Parameters:
modular_subtract_inplace
modular_subtract_inplace(
modulus: CInt,
x: Const[QNum],
y: QNum
) -> None
[Qmod Classiq-library function]
Performs the transformation |x>``|y> -> |x>|(x - y mod modulus)>.
Note:
\|x> and \|y> should have values smaller than modulus.
The modulus should satisfy 1 < modulus < 2**n, where n is the size of |x> and |y>.
Parameters:
modular_double_inplace
modular_double_inplace(
modulus: CInt,
x: QNum
) -> None
[Qmod Classiq-library function]
Performs the transformation |x> -> |(2x mod modulus)>.
Note:
\|x> should have a value smaller than modulus.
The modulus must be a constant odd integer.
The modulus should satisfy 1 < modulus < 2**n, where n is the size of |x>.
Implementation based on: https://arxiv.org/pdf/1706.06752 Chapter 3.2 Fig 4
Parameters:
modular_add_constant_inplace
modular_add_constant_inplace(
modulus: CInt,
a: CInt,
x: QNum
) -> None
[Qmod Classiq-library function]
Performs the transformation |x> -> |(x + a mod modulus)>.
Note:
\|x> and a should have values smaller than modulus.
The modulus should satisfy 1 < modulus < 2**n, where n is the size of |x>.
Implementation is based on the logic in: https://arxiv.org/pdf/1706.06752 Chapter 3.2 Fig 3
Parameters:
modular_multiply
modular_multiply(
modulus: CInt,
x: Const[QArray[QBit]],
y: Const[QArray[QBit]],
z: QArray[QBit]
) -> None
[Qmod Classiq-library function]
Performs the transformation |x>``|y>``|0> -> |x>``|y>|(x*y mod modulus)>
Note:
\|x>, \|y> should have the same size and have values smaller than modulus.
The modulus must be a constant odd integer.
The modulus should satisfy 1 < modulus < 2**n, where n is the size of |x> and |y>.
The output register z must be pre-allocated with the same size as x and y.
Implementation is based on the logic in: https://arxiv.org/pdf/1706.06752 Chapter 3.2 Fig 5
Parameters:
modular_square
modular_square(
modulus: CInt,
x: Const[QArray[QBit]],
z: QArray[QBit]
) -> None
[Qmod Classiq-library function]
Performs the transformation |x>``|0> -> |x>|(x^2 mod modulus)>.
Note:
\|x> should have the same size and have values smaller than modulus.
The modulus must be a constant odd integer.
The modulus should satisfy 1 < modulus < 2**n, where n is the size of |x>.
The output register z must be pre-allocated with the same size as x.
Implementation is based on: https://arxiv.org/pdf/1706.06752 Chapter 3.2 Fig 6
Parameters:
modular_multiply_constant
modular_multiply_constant(
modulus: CInt,
x: Const[QNum],
a: CInt,
y: QNum
) -> None
[Qmod Classiq-library function]
Performs the transformation |x>``|y> -> |x>|(x * a mod modulus)>.
Note:
\|x> and \|y> should have values smaller than modulus.
The modulus must be a constant odd integer.
The modulus should satisfy 1 < modulus < 2**n, where n is the size of |x> and |y>.
Parameters:
modular_multiply_constant_inplace
modular_multiply_constant_inplace(
modulus: CInt,
a: CInt,
x: QNum
) -> None
[Qmod Classiq-library function]
In-place modular multiplication of x by a classical constant modulo a symbolic modulus.
Performs |x> -> |(x * a mod modulus)>.
Note:
\|x> should have values smaller than modulus.
The modulus should satisfy 1 < modulus < 2**n, where n is the size of |x>.
The constant a should have an inverse modulo modulus, i.e. gcd(a, modulus) = 1.
The constant a should satisfy 0 <= a < modulus.
Parameters:
modular_to_montgomery_inplace
modular_to_montgomery_inplace(
modulus: CInt,
x: QNum
) -> None
[Qmod Classiq-library function]
Converts a quantum integer |x> into its Montgomery representation modulo modulus in place.
The Montgomery factor is R = 2n, where n = x.size (the number of qubits in |x>).
This function performs the transformation |x> -> |(x * R mod modulus)>.
Note:
\|x> should have values smaller than modulus.
The modulus should satisfy 1 < modulus < 2n, where n is the size of |x>.
The modulus must be odd so that R = 2**n is invertible modulo modulus (gcd(R, modulus) = 1).
Parameters:
modular_montgomery_to_standard_inplace
modular_montgomery_to_standard_inplace(
modulus: CInt,
x: QNum
) -> None
[Qmod Classiq-library function]
Converts quantum integer |x> from Montgomery representation to standard form in place modulo modulus.
The Montgomery factor is R = 2n, where n = x.size (the number of qubits in |x>).
This function performs the transformation |x> -> |(x * R^-1 mod modulus)>.
Note:
\|x> should have values smaller than modulus.
The modulus should satisfy 1 < modulus < 2n, where n is the size of |x>.
The modulus must be odd so that R = 2**n is invertible modulo modulus (gcd(R, modulus) = 1).
Parameters:
modular_inverse_inplace
modular_inverse_inplace(
modulus: CInt,
v: QNum,
m: Output[QArray[QBit]]
) -> None
[Qmod Classiq-library function]
Computes the modular inverse of a quantum number |v> modulo modulus in place, using the Kaliski algorithm.
Performs the transformation |v> -> |(v^-1 mod modulus)>.
Based on: https://arxiv.org/pdf/2302.06639 Chapter 5
Note:
\|v> should have values smaller than modulus.
If |v> = 0, the output will be 0 (although 0 does not have an inverse modulo modulus).
The modulus should be prime OR at least gcd(v, modulus) = 1.
The modulus must be a constant odd integer.
The modulus should satisfy 1 < modulus < 2**n, where n is the size of |v>.
The ancilla qubits m are provided as Output, will be allocated to length 2*n.
Parameters:
kaliski_iteration
kaliski_iteration(
modulus: CInt,
i: CInt,
v: QNum,
m: QArray[QBit],
u: QNum,
r: QNum,
s: QNum,
a: QBit,
b: QBit,
f: QBit
) -> None
Single iteration of the Kaliski modular inverse algorithm main loop.
Based on: https://arxiv.org/pdf/2302.06639 Figure 15
Note:
Assumes the global inversion constraints (odd modulus, 1 < modulus < 2**n).
Called with 0 <= v < modulus; per-iteration ancilla bit is m[i].
Parameters:
modular_rsub_inplace
modular_rsub_inplace(
modulus: CInt,
a: CInt,
x: QNum
) -> None
[Qmod Classiq-library function]
Performs the in-place modular right-subtraction |x> -> |(a - x mod modulus)>.
Note:
\|x> should have values smaller than modulus.
The modulus should satisfy 1 < modulus < 2**n, where n is the size of |x>.
The classical constant a should be in the range 0 <= a < modulus.
Parameters: