# Simon's problem

In computational complexity theory and quantum computing, Simon's problem is a computational problem that is proven to be solved exponentially faster on a quantum computer than on a classical (that is, traditional) computer. The quantum algorithm solving Simon's problem, usually called Simon's algorithm, served as the inspiration for Shor's algorithm.[1] Both problems are special cases of the abelian hidden subgroup problem, which is now known to have efficient quantum algorithms.

The problem is set in the model of decision tree complexity or query complexity and was conceived by Daniel Simon in 1994.[2] Simon exhibited a quantum algorithm that solves Simon's problem exponentially faster and with exponentially fewer queries than the best probabilistic (or deterministic) classical algorithm. In particular, Simon's algorithm uses a linear number of queries and any classical probabilistic algorithm must use an exponential number of queries.

This problem yields an oracle separation between the complexity classes BPP (bounded-error classical query complexity) and BQP (bounded-error quantum query complexity).[3] This is the same separation that the Bernstein–Vazirani algorithm achieves, and different from the separation provided by the Deutsch–Jozsa algorithm, which separates P and EQP. Unlike the Bernstein–Vazirani algorithm, Simon's algorithm's separation is exponential.

Because this problem assumes the existence of a highly-structured "black box" oracle to achieve its speedup, this problem has little practical value.[4] However, without such an oracle, exponential speedups cannot easily be proven, since this would prove that P is different from PSPACE.

## Problem description

Given a function (implemented by a black box or oracle) ${\displaystyle f:\{0,1\}^{n}\rightarrow \{0,1\}^{n}}$ with the promise that, for some unknown ${\displaystyle s\in \{0,1\}^{n}}$, for all ${\displaystyle x,y\in \{0,1\}^{n}}$,

${\displaystyle f(x)=f(y)}$ if and only if ${\displaystyle x\oplus y\in \{0^{n},s\}}$,

where ${\displaystyle \oplus }$ denotes bitwise XOR. The goal is to identify ${\displaystyle s}$ by making as few queries to ${\displaystyle f(x)}$ as possible. Note that

${\displaystyle a\oplus b=0^{n}}$ if and only if ${\displaystyle a=b}$

Furthermore, for some ${\displaystyle x}$ and ${\displaystyle s}$ in ${\displaystyle x\oplus y=s}$, ${\displaystyle y}$ is unique (not equal to ${\displaystyle x}$) if and only if ${\displaystyle s\neq 0^{n}}$. This means that ${\displaystyle f}$ is two-to-one when ${\displaystyle s\neq 0^{n}}$, and one-to-one when ${\displaystyle s=0^{n}}$. It is also the case that ${\displaystyle x\oplus y=s}$ implies ${\displaystyle y=s\oplus x}$, meaning that

${\displaystyle f(x)=f(y)=f(x\oplus {s})}$
which shows how ${\displaystyle f}$ is periodic.

The associated decision problem formulation of Simon's problem is to distinguish when ${\displaystyle s=0^{n}}$ (${\displaystyle f}$ is one-to-one), and when ${\displaystyle s\neq 0^{n}}$ (${\displaystyle f}$ is two-to-one).

### Example

The following function is an example of a function that satisfies the required property for ${\displaystyle n=3}$:

${\displaystyle x}$ ${\displaystyle f(x)}$
000 101
001 010
010 000
011 110
100 000
101 110
110 101
111 010

In this case, ${\displaystyle s=110}$ (i.e. the solution). Every output of ${\displaystyle f}$ occurs twice, and the two input strings corresponding to any one given output have bitwise XOR equal to ${\displaystyle s=110}$.

For example, the input strings ${\displaystyle 010}$ and ${\displaystyle 100}$ are both mapped (by ${\displaystyle f}$) to the same output string ${\displaystyle 000}$. That is, ${\displaystyle {\displaystyle f(010)=000}}$ and ${\displaystyle {\displaystyle f(100)=000}}$. Applying XOR to 010 and 100 obtains 110, that is ${\displaystyle {\displaystyle 010\oplus 100=110=s}.}$

${\displaystyle s=110}$ can also be verified using input strings 001 and 111 that are both mapped (by f) to the same output string 010. Applying XOR to 001 and 111 obtains 110, that is ${\displaystyle 001\oplus 111=110=s}$. This gives the same solution ${\displaystyle s=110}$ as before.

In this example the function f is indeed a two-to-one function where ${\displaystyle {\displaystyle s\neq 0^{n}}}$.

### Problem hardness

Intuitively, this is a hard problem to solve in a "classical" way, even if one uses randomness and accepts a small probability of error. The intuition behind the hardness is reasonably simple: if you want to solve the problem classically, you need to find two different inputs ${\displaystyle x}$ and ${\displaystyle y}$ for which ${\displaystyle f(x)=f(y)}$. There is not necessarily any structure in the function ${\displaystyle f}$ that would help us to find two such inputs: more specifically, we can discover something about ${\displaystyle f}$ (or what it does) only when, for two different inputs, we obtain the same output. In any case, we would need to guess ${\displaystyle {\displaystyle \Omega ({\sqrt {2^{n}}})}}$ different inputs before being likely to find a pair on which ${\displaystyle f}$ takes the same output, as per the birthday problem. Since, classically to find s with a 100% certainty it would require checking up to ${\displaystyle 2^{n-1}+1}$ inputs, Simon's problem seeks to find s using fewer queries than this classical method.

## Simon's algorithm

Quantum circuit representing/implementing Simon's algorithm

The algorithm as a whole uses a subroutine to execute the following two steps:

1. Run the quantum subroutine an expected ${\displaystyle O(n)}$ times to get a list of linearly independent bitstrings ${\displaystyle y_{1},...,y_{n-1}}$.
2. Each ${\displaystyle y_{k}}$ satisfies ${\displaystyle y_{k}\cdot s=0}$, so we can solve the system of equations this produces to get ${\displaystyle s}$.

### Quantum subroutine

The quantum circuit (see the picture) is the implementation of the quantum part of Simon's algorithm. The quantum subroutine of the algorithm makes use of the Hadamard transform

${\displaystyle H^{\otimes n}|k\rangle ={\frac {1}{\sqrt {2^{n}}}}\sum _{j=0}^{2^{n}-1}(-1)^{k\cdot j}|j\rangle }$
where ${\displaystyle k\cdot j=k_{1}j_{1}\oplus \ldots \oplus k_{n}j_{n}}$, where ${\displaystyle \oplus }$ denotes XOR.

First, the algorithm starts with two registers, initialized to ${\displaystyle |0\rangle ^{\otimes n}|0\rangle ^{\otimes n}}$. Then, we apply the Hadamard transform to the first register, which gives the state

${\displaystyle {\frac {1}{\sqrt {2^{n}}}}\sum _{k=0}^{2^{n}-1}|k\rangle |0\rangle ^{\otimes n}.}$

Query the oracle ${\displaystyle U_{f}}$ to get the state

${\displaystyle {\frac {1}{\sqrt {2^{n}}}}\sum _{k=0}^{2^{n}-1}|k\rangle |f(k)\rangle }$.

Apply another Hadamard transform to the first register. This will produce the state

${\displaystyle {\frac {1}{\sqrt {2^{n}}}}\sum _{k=0}^{2^{n}-1}\left[{\frac {1}{\sqrt {2^{n}}}}\sum _{j=0}^{2^{n}-1}(-1)^{j\cdot k}|j\rangle \right]|f(k)\rangle =\sum _{j=0}^{2^{n}-1}|j\rangle \left[{\frac {1}{2^{n}}}\sum _{k=0}^{2^{n}-1}(-1)^{j\cdot k}|f(k)\rangle \right].}$

Finally, we measure the first register (the algorithm also works if the second register is measured before the first, but this is unnecessary). The probability of measuring a state ${\displaystyle |j\rangle }$ is

${\displaystyle \left|\left|{\frac {1}{2^{n}}}\sum _{k=0}^{2^{n}-1}(-1)^{j\cdot k}|f(k)\rangle \right|\right|^{2}}$
This is due to the fact that taking the magnitude of this vector and squaring it sums up all the probabilities of all the possible measurements of the second register that must have the first register as ${\displaystyle |j\rangle }$. There are two cases for our measurement:

1. ${\displaystyle s=0^{n}}$ and ${\displaystyle f}$ is one-to-one.
2. ${\displaystyle s\neq 0^{n}}$ and ${\displaystyle f}$ is two-to-one.

For the first case, since

${\displaystyle \left|\left|{\frac {1}{2^{n}}}\sum _{k=0}^{2^{n}-1}(-1)^{j\cdot k}|f(k)\rangle \right|\right|^{2}={\frac {1}{2^{n}}}}$
since in this case, ${\displaystyle f}$ is one-to-one, implying that the range of ${\displaystyle f}$ is ${\displaystyle \{0,1\}^{n}}$, meaning that the summation is over every basis vector. For the second case, note that there exist two strings, ${\displaystyle x_{1}}$ and ${\displaystyle x_{2}}$, such that ${\displaystyle f(x_{1})=f(x_{2})=z}$, where ${\displaystyle z\in \mathrm {range} (f)}$. Thus,
${\displaystyle \left|\left|{\frac {1}{2^{n}}}\sum _{k=0}^{2^{n}-1}(-1)^{j\cdot k}|f(k)\rangle \right|\right|^{2}=\left|\left|{\frac {1}{2^{n}}}\sum _{z\,\in \,\mathrm {range} (f)}((-1)^{j\cdot x_{1}}+(-1)^{j\cdot x_{2}})|z\rangle \right|\right|^{2}}$
Furthermore, since ${\displaystyle x_{1}\oplus x_{2}=s}$, ${\displaystyle x_{2}=x_{1}\oplus s}$, and so
{\displaystyle {\begin{aligned}\left|\left|{\frac {1}{2^{n}}}\sum _{z\,\in \,\mathrm {range} (f)}((-1)^{j\cdot x_{1}}+(-1)^{j\cdot x_{2}})|z\rangle \right|\right|^{2}&=\left|\left|{\frac {1}{2^{n}}}\sum _{z\,\in \,\mathrm {range} (f)}((-1)^{j\cdot x_{1}}+(-1)^{j\cdot (x_{1}\oplus s)})|z\rangle \right|\right|^{2}\\&=\left|\left|{\frac {1}{2^{n}}}\sum _{z\,\in \,\mathrm {range} (f)}((-1)^{j\cdot x_{1}}+(-1)^{j\cdot x_{1}\oplus j\cdot s})|z\rangle \right|\right|^{2}\\&=\left|\left|{\frac {1}{2^{n}}}\sum _{z\,\in \,\mathrm {range} (f)}(-1)^{j\cdot x_{1}}(1+(-1)^{j\cdot s})|z\rangle \right|\right|^{2}\end{aligned}}}
This expression is now easy to evaluate. Recall that we are measuring ${\displaystyle j}$. When ${\displaystyle j\cdot s=1}$, then this expression will evaluate to ${\displaystyle 0}$, and when ${\displaystyle j\cdot s=0}$, then this expression will be ${\displaystyle 2^{-n+1}}$.

Thus, both when ${\displaystyle s=0^{n}}$ and when ${\displaystyle s\neq 0^{n}}$, our measured ${\displaystyle j}$ satisfies ${\displaystyle j\cdot s=0}$.

### Classical post-processing

We run the quantum part of the algorithm until we have a linearly independent list of bitstrings ${\displaystyle y_{1},\ldots ,y_{n-1}}$, and each ${\displaystyle y_{k}}$ satisfies ${\displaystyle y_{k}\cdot s=0}$. Thus, we can efficiently solve this system of equations classically to find ${\displaystyle s}$.

The probability that ${\displaystyle y_{1},y_{2},\dots ,y_{n-1}}$ are linearly independent is at least

${\displaystyle \prod _{k=1}^{\infty }\left(1-{\frac {1}{2^{k}}}\right)=0.288788\dots }$
Once we solve the system of equations, and produce a solution ${\displaystyle s'}$, we can test if ${\displaystyle f(0^{n})=f(s')}$. If this is true, then we know ${\displaystyle s'=s}$, since ${\displaystyle f(0^{n})=f(0^{n}\oplus s)=f(s)}$. If it is the case that ${\displaystyle f(0^{n})\neq f(s')}$, then that means that ${\displaystyle s=0^{n}}$, and ${\displaystyle f(0^{n})\neq f(s')}$ since ${\displaystyle f}$ is one-to-one.

We can repeat Simon's algorithm a constant number of times to increase the probability of success arbitrarily, while still having the same time complexity.

## Explicit examples of Simon's algorithm for few qubits

### ${\displaystyle n=1}$

Consider the simplest instance of the algorithm, with ${\displaystyle n=1}$. In this case evolving the input state through an Hadamard gate and the oracle results in the state (up to renormalization):

${\displaystyle |0\rangle |f(0)\rangle +|1\rangle |f(1)\rangle .}$

If ${\displaystyle s=1}$, that is, ${\displaystyle f(0)=f(1)}$, then measuring the second register always gives the outcome ${\displaystyle |f(0)\rangle }$, and always results in the first register collapsing to the state (up to renormalization):

${\displaystyle |0\rangle +|1\rangle .}$

Thus applying an Hadamard and measuring the first register always gives the outcome ${\displaystyle |0\rangle }$. On the other hand, if ${\displaystyle f}$ is one-to-one, that is, ${\displaystyle s=0}$, then measuring the first register after the second Hadamard can result in both ${\displaystyle |0\rangle }$ and ${\displaystyle |1\rangle }$, with equal probability.

We recover ${\displaystyle s}$ from the measurement outcomes by looking at whether we measured always ${\displaystyle |0\rangle }$, in which case ${\displaystyle s=1}$, or we measured both ${\displaystyle |0\rangle }$ and ${\displaystyle |1\rangle }$ with equal probability, in which case we infer that ${\displaystyle s=0}$. This scheme will fail if ${\displaystyle s=0}$ but we nonetheless always found the outcome ${\displaystyle |0\rangle }$, but the probability of this event is ${\displaystyle 2^{-N}}$ with ${\displaystyle N}$ the number of performed measurements, and can thus be made exponentially small by increasing the statistics.

### ${\displaystyle n=2}$

Consider now the case with ${\displaystyle n=2}$. The initial part of the algorithm results in the state (up to renormalization):

${\displaystyle |00\rangle |f(00)\rangle +|01\rangle |f(01)\rangle +|10\rangle |f(10)\rangle +|11\rangle |f(11)\rangle .}$
If ${\displaystyle s=(00)}$, meaning ${\displaystyle f}$ is injective, then finding ${\displaystyle |f(x)\rangle }$ on the second register always collapses the first register to ${\displaystyle |x\rangle }$, for all ${\displaystyle x\in \{0,1\}^{2}}$. In other words, applying Hadamard gates and measuring the first register the four outcomes ${\displaystyle 00,01,10,11}$ are thus found with equal probability.

Suppose on the other hand ${\displaystyle s\neq (00)}$, for example, ${\displaystyle s=(01)}$. Then measuring ${\displaystyle |f(00)\rangle }$ on the second register collapses the first register to the state ${\displaystyle |00\rangle +|10\rangle }$. And more generally, measuring ${\displaystyle |f(xy)\rangle }$ gives ${\displaystyle |x,y\rangle +|x,y\oplus 1\rangle =|x\rangle (|0\rangle +|1\rangle )}$ on the first register. Applying Hadamad gates and measuring on the first register can thus result in the outcomes ${\displaystyle 00}$ and ${\displaystyle 10}$ with equal probabilities.

Similar reasoning applies to the other cases: if ${\displaystyle s=(10)}$ then the possible outcomes are ${\displaystyle 00}$ and ${\displaystyle 01}$, while if ${\displaystyle s=(11)}$ the possible outcomes are ${\displaystyle 00}$ and ${\displaystyle 11}$, compatibly with the ${\displaystyle j\cdot s=0}$ rule discussed in the general case.

To recover ${\displaystyle s}$ we thus only need to distinguish between these four cases, collecting enough statistics to ensure that the probability of mistaking one outcome probability distribution for another is sufficiently small.

## Complexity

Simon's algorithm requires ${\displaystyle O(n)}$ queries to the black box, whereas a classical algorithm would need at least ${\displaystyle \Omega (2^{n/2})}$ queries. It is also known that Simon's algorithm is optimal in the sense that any quantum algorithm to solve this problem requires ${\displaystyle \Omega (n)}$ queries.[5][6]