Use this file to discover all available pages before exploring further.
View on GitHub
Open this notebook in GitHub to run it yourself
The modular_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:∣x⟩∣power⟩=∣(apowermodn)⋅x⟩∣power⟩Specifically if at the input x=1, at the output x=apowermodn.
This example generates a quantum program that initializes a power 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 ⌈(log2(N)⌉, so it is first allocated with a fixed size, then initialized with the value ‘1’.