Modular exponentiation
modular_exponentiation
Functions:
Name | Description |
---|---|
qft_space_add_const |
[Qmod Classiq-library function] |
cc_modular_add |
[Qmod Classiq-library function] |
c_modular_multiply |
[Qmod Classiq-library function] |
multiswap |
[Qmod Classiq-library function] |
inplace_c_modular_multiply |
[Qmod Classiq-library function] |
modular_exp |
[Qmod Classiq-library function] |
qft_space_add_const
qft_space_add_const(
value: CInt, phi_b: QArray[QBit]
) -> None
[Qmod Classiq-library function]
Adds a constant to a quantum number (in the Fourier space) using the Quantum Fourier Transform (QFT) Adder algorithm.
Assuming that the input phi_b
has n
qubits, the result will be \(\phi_b+=value \mod 2^n\).
To perform the full algorithm, use: within_apply(lambda: QFT(phi_b), qft_space_add_const(value, phi_b))
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
CInt
|
The constant to add to the quantum number. |
required |
phi_b
|
QArray[QBit]
|
The quantum number (at the aft space) to which the constant is added. |
required |
cc_modular_add
cc_modular_add(
n: CInt,
a: CInt,
phi_b: QArray[QBit],
c1: QBit,
c2: QBit,
) -> None
[Qmod Classiq-library function]
Adds a constant a
to a quantum number phi_b
modulo the constant n
, controlled by 2 qubits.
The quantum number phi_b
and the constant a
are assumed to be in the QFT space.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
CInt
|
The modulo number. |
required |
a
|
CInt
|
The constant to add to the quantum number. |
required |
phi_b
|
QArray[QBit]
|
The quantum number to which the constant is added. |
required |
c1
|
QBit
|
a control qubit. |
required |
c2
|
QBit
|
a control qubit. |
required |
c_modular_multiply
c_modular_multiply(
n: CInt,
a: CInt,
b: QArray[QBit],
x: QArray[QBit],
ctrl: QBit,
) -> None
[Qmod Classiq-library function]
Performs out-of-place multiplication of a quantum number x
by a classical number a
modulo classical number n
,
controlled by a quantum bit ctrl
and adds the result to a quantum array b
. Applies \(b += xa \mod n\) if ctrl=1
, and the identity otherwise.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
CInt
|
The modulo number. Should be non-negative. |
required |
a
|
CInt
|
The classical factor. Should be non-negative. |
required |
b
|
QArray[QBit]
|
The quantum number added to the multiplication result. Stores the result of the multiplication. |
required |
x
|
QArray[QBit]
|
The quantum factor. |
required |
ctrl
|
QBit
|
The control bit. |
required |
multiswap
multiswap(x: QArray[QBit], y: QArray[QBit]) -> None
[Qmod Classiq-library function]
Swaps the qubit states between two arrays. Qubits of respective indices are swapped, and additional qubits in the longer array are left unchanged.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
QArray[QBit]
|
The first array |
required |
y
|
QArray[QBit]
|
The second array |
required |
inplace_c_modular_multiply
inplace_c_modular_multiply(
n: CInt, a: CInt, x: QArray[QBit], ctrl: QBit
) -> None
[Qmod Classiq-library function]
Performs multiplication of a quantum number x
by a classical number a
modulo classical number n
,
controlled by a quantum bit ctrl
. Applies \(x=xa \mod n\) if ctrl=1
, and the identity otherwise.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
CInt
|
The modulo number. Should be non-negative. |
required |
a
|
CInt
|
The classical factor. Should be non-negative. |
required |
x
|
QArray[QBit]
|
The quantum factor. |
required |
ctrl
|
QBit
|
The control bit. |
required |
modular_exp
modular_exp(
n: CInt, a: CInt, x: QArray[QBit], power: QArray[QBit]
) -> None
[Qmod Classiq-library function]
Raises a classical integer a
to the power of a quantum number power
modulo classical integer n
times a quantum number x
. Performs \(x=(a^{power} \mod n)*x\) in-place.
(and specifically if at the input \(x=1\), at the output \(x=a^{power} \mod n\)).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
CInt
|
The modulus number. Should be non-negative. |
required |
a
|
CInt
|
The base of the exponentiation. Should be non-negative. |
required |
x
|
QArray[QBit]
|
A quantum number that multiplies the modular exponentiation and holds the output. It should be at least the size of \(\lceil \log(n) ceil\). |
required |
power
|
QArray[QBit]
|
The power of the exponentiation. |
required |