View on GitHub
Open this notebook in GitHub to run it yourself
Simon’s algorithm [1], [2] is a basic quantum algorithm that demonstrates an exponential speed-up over its classical counterpart in the oracle complexity setting. The algorithm solves the so-called Simon’s problem: The algorithm treats the following problem:Complexity: The Simon’s problem is hard to solve with classical deterministic or probabalistic approaches. This can be understood as follows: determining requires finding a collision , as . What is the minimum number of calls for measuring a collision? If we take the deterministic approach, in the worst case we need calls. A probablistic approach, in the spirit of the one that solves the birthday problem [3], has slightly better scaling of queries. The quantum approach requires queries, thus introducing an exponential speedup. The exponential speedup is in the oracle complexity setting. It only refers to deterministic classical machines.
- Input: A function .
- Promise: There is a secret binary string such that f(x) = f(y) \iff y = x\oplus s\tag{1}~~, where is a bitwise xor operation.
- Output: The secret string , using a minimal number of queries of .
Keywords: Foundational quantum algorithm, Exponential speedup, Function evaluation, Oracle problem, Oracle/Query complexity.

Building the Algorithm with Classiq
Quantum Part
The quantum part of the algorithm is rather simple, calling the quantum implementation of , between two calls of the hadamard transform. The call of is done out-of-place, onto a quantum variable , whereas only the final state of is relevant to the classical postprocess to follow.Classical Postprocess
The classical part of the algorithm includes the following postprocessing steps:- Finding samples of that are linearly independent, . It is guaranteed that this can be achieved with high probability (see the technical details below).
- Finding the string such that , where refers to a dot-product (polynomial complexity in ).
Example: Arithmetic Simon’s Function
An example of a valid function that satisfies the condition in Eq. (1): Clearly, we have that .Implementing the Simon’s Function
We define the function, as well as a model that applies it on all computational basis states to illustrate that it is a two-to-one function.Output:

Running the Simon’s Algorithm
Taking number of shots guarantees getting a set of independent strings with high probability (assuming a noiseless quantum computer) (see technical explanation below). Moreover, increasing the number of shots by a constant factor provides an exponential improvement. Here we take shots.Output:
Example: Shallow Simon’s Function
In the second example we take a Simon’s function that was presented in a recent paper [4]: Take a secret string of the form and define the 2-to-1 function: The function operates as follows: for the first elements, we simply “copy” the data, whereas for the last elements we apply a xor with the element. A simple proof that this is indeed a 2-to-1 function is given in Ref. [4]. Comment: Ref. [4] employed further reduction of the function implementation (reducing the -sized Simon’s problem to an -sized problem), added a classical postprocess of randomly permutating over the result of to increase the hardness of the problem, and also included some NISQ analysis. These steps were taken to show an algorithmic speedup on real quantum hardware.Implementing the Simon’s Function
The first “classical copies”, , can be implemented by gates. The xor operations, , can be implemented by two operations, one to form a “classical copy” of , followed by another operation, implementing a xor with .Output:

Running the Simon’s Algorithm
As in the first example, we take shots.Output:
Output: