View on GitHub
Open this notebook in GitHub to run it yourself
Modular Exponentiation
Themodular_exp function raises a classical integer a to the power of a quantum number power modulo classical integer n, times a quantum number x.
The function performs:
Specifically if at the input , at the output .
Example
This example generates a quantum program that initializes apower variable with a uniform superposition, and exponentiate the classical value A with power as the exponent, in superposition.
The result is calculated inplace to the variable x module N.
Notice that x should have size of at least , so it is first allocated with a fixed size, then initialized with the value ‘1’.
Output: