View on GitHub
Open this notebook in GitHub to run it yourself
Modulo
The modulo operation (denoted as ’%’) returns the remainder (called “modulus”) of a division. Given two numbers and , the result of () is the remainder of the division of a by n. The modulo operation is supported only for for an integer , its result is the least significant bits. For example, the binary representation of the number is . The expression () equals , because , which means only accounting for the least significant bits of .Implementation in Expressions
If an expression is defined using a modulo operation, the output size is set recursively to all of its subexpressions. But if for some sub-expressions, another modulo operation is used, the sub-expression’s output_size is determined by the minimal value between the output_size of the sub-expression and the expression. See this example: . The result of expression is saved on a two-qubit register, and the results of expressions and are saved using three qubits each.Example
This example generates a quantum program that adds two five-qubit arguments: a on qubits 0-4, and b on qubits 5-- The adder result should have been calculated on a 6-qubit register. However, the modulo operation decides that the output register of the adder only contains its two least significant qubits. Thus, the adder result is written to a two-qubit register, on qubits 10-
Output: