ExpModuloExtension ExpModulo Method (QuantumComputer, Register, Register, Int32, Int32)A Sandcastle Documented Class Library

Performs (a^x) modulo N, for given integers a and N. The x (one value or a superposition) is given in the input register x.

After computation, the result (or results, when x stores superposition of multiple integers) is stored in register x1.

This method is a simple variant of ExpModulo(QuantumComputer, Register, Register, Register, Register, Register, Register, Int32, Int32). It allocates additional registers and frees them at the end. This variant has also requirements for the width of each given register but if they are not fullfilled, the exception is thrown.

Namespace: Quantum.Operations
Assembly: Quantum (in Quantum.dll) Version: (

public static void ExpModulo(
	this QuantumComputer comp,
	Register x,
	Register x1,
	int valueA,
	int valueN


Type: Quantum QuantumComputer
The QuantumComputer instance.
Type: Quantum Register
Register for x. Its initial value could be any integer or a superposition of multiple integers. Its width must equal 2 * WIDTH (See Remarks).
Type: Quantum Register
Output register. Its initial value must equal 1. Its width must equal WIDTH + 1 (See Remarks).
Type: System Int32
Integer value of a. (For computing (a^x) modulo N).
Type: System Int32
Integer value of N. (For computing (a^x) modulo N).

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type QuantumComputer. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

There are precise requirements for the width of each register given as argument. They result from a need for carry bits, overflow flag and a requirement for ensuring that the operation is inversible.

Let WIDTH equals the number of bits required to store N.

The width of x register must equal 2 * WIDTH. This value results from the requirements of Peter Shor's algorithm. Such a width ensures that the probability of getting the right result will be enough high.

See Also